2016-09-14 18:08:46 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.informationsystem.resourceregistry.publisher;
|
|
|
|
|
2016-09-16 12:36:06 +02:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2016-09-14 18:08:46 +02:00
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2016-09-16 12:36:06 +02:00
|
|
|
import org.gcube.informationsystem.impl.entity.facet.CPUFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.NetworkingFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.facet.SoftwareFacetImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.resource.EServiceImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.resource.HostingNodeImpl;
|
|
|
|
import org.gcube.informationsystem.impl.relation.IsIdentifiedByImpl;
|
|
|
|
import org.gcube.informationsystem.impl.relation.isrelatedto.HostsImpl;
|
2016-09-16 18:38:12 +02:00
|
|
|
import org.gcube.informationsystem.impl.utils.Entities;
|
2016-09-15 14:57:14 +02:00
|
|
|
import org.gcube.informationsystem.model.entity.Facet;
|
2016-09-16 12:36:06 +02:00
|
|
|
import org.gcube.informationsystem.model.entity.Resource;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.CPUFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.NetworkingFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.facet.SoftwareFacet;
|
|
|
|
import org.gcube.informationsystem.model.entity.resource.EService;
|
|
|
|
import org.gcube.informationsystem.model.entity.resource.HostingNode;
|
|
|
|
import org.gcube.informationsystem.model.relation.IsIdentifiedBy;
|
|
|
|
import org.gcube.informationsystem.model.relation.isrelatedto.Hosts;
|
2016-09-14 18:08:46 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.publisher.proxy.ResourceRegistryPublisher;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.publisher.proxy.ResourceRegistryPublisherFactory;
|
2016-09-16 12:36:06 +02:00
|
|
|
import org.junit.Assert;
|
2016-09-15 14:57:14 +02:00
|
|
|
import org.junit.Before;
|
2016-09-14 18:08:46 +02:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ResourceRegistryPublisherTest {
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ResourceRegistryPublisherTest.class);
|
|
|
|
|
2016-09-15 14:57:14 +02:00
|
|
|
|
|
|
|
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void before(){
|
|
|
|
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
|
|
|
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
|
|
|
}
|
|
|
|
|
2016-09-14 18:08:46 +02:00
|
|
|
@Test
|
2016-09-16 12:36:06 +02:00
|
|
|
public void testCreateUpdateDeleteFacet() throws Exception {
|
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
|
|
|
|
|
|
|
logger.debug("Going to create: {}", cpuFacet);
|
|
|
|
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(CPUFacet.class, cpuFacet);
|
|
|
|
logger.debug("Created: {}", createdCpuFacet);
|
|
|
|
|
|
|
|
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
|
|
|
|
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
|
|
|
|
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
|
|
|
|
|
|
|
|
UUID uuid = createdCpuFacet.getHeader().getUUID();
|
|
|
|
|
|
|
|
String newVendor = "Intel";
|
|
|
|
String newClockSpeed = "2 GHz";
|
|
|
|
createdCpuFacet.setVendor(newVendor);
|
|
|
|
createdCpuFacet.setClockSpeed(newClockSpeed);
|
|
|
|
|
|
|
|
String additionPropertyKey = "My";
|
|
|
|
String additionPropertyValue = "Test";
|
|
|
|
createdCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
|
|
|
|
|
|
|
|
logger.debug("Going to update: {}", cpuFacet);
|
|
|
|
CPUFacet updatedCpuFacet = resourceRegistryPublisher.updateFacet(CPUFacet.class, createdCpuFacet);
|
|
|
|
logger.debug("Updated: {}", updatedCpuFacet);
|
|
|
|
Assert.assertTrue(createdCpuFacet.getClockSpeed().compareTo(updatedCpuFacet.getClockSpeed())==0);
|
|
|
|
Assert.assertTrue(createdCpuFacet.getModel().compareTo(updatedCpuFacet.getModel())==0);
|
|
|
|
Assert.assertTrue(createdCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor())==0);
|
|
|
|
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)).compareTo((String) createdCpuFacet.getAdditionalProperty(additionPropertyKey))==0);
|
|
|
|
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID())==0);
|
|
|
|
|
|
|
|
boolean deleted = resourceRegistryPublisher.deleteFacet(updatedCpuFacet);
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCreateDeleteResources() throws Exception {
|
|
|
|
|
|
|
|
EService eService = new EServiceImpl();
|
|
|
|
|
|
|
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
|
|
|
softwareFacet.setGroup("InformationSystem");
|
|
|
|
softwareFacet.setName("resource-registry");
|
|
|
|
softwareFacet.setVersion("1.1.0");
|
|
|
|
|
2016-09-16 18:38:12 +02:00
|
|
|
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedByESSF = new IsIdentifiedByImpl<>(eService, softwareFacet, null);
|
|
|
|
eService.addFacet(isIdentifiedByESSF);
|
|
|
|
|
|
|
|
Entities.registerSubtypes(IsIdentifiedBy.class, SoftwareFacet.class, EService.class);
|
2016-09-16 12:36:06 +02:00
|
|
|
|
|
|
|
logger.debug("Going to create : {}", eService);
|
|
|
|
EService createdEService = resourceRegistryPublisher.createResource(EService.class, eService);
|
|
|
|
logger.debug("Created : {}", createdEService);
|
|
|
|
|
2016-09-16 13:39:26 +02:00
|
|
|
SoftwareFacet createdSoftwareFacet = (SoftwareFacet) createdEService.getIdentificationFacets().get(0);
|
|
|
|
logger.debug("Created : {}", softwareFacet);
|
|
|
|
|
|
|
|
|
2016-09-16 18:38:12 +02:00
|
|
|
|
|
|
|
|
2016-09-16 12:36:06 +02:00
|
|
|
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
|
|
|
|
networkingFacet.setIPAddress("146.48.87.183");
|
|
|
|
networkingFacet.setHostName("pc-frosini.isti.cnr.it");
|
|
|
|
networkingFacet.setDomainName("isti.cnr.it");
|
|
|
|
networkingFacet.setMask("255.255.248.0");
|
|
|
|
networkingFacet.setBroadcastAddress("146.48.87.255");
|
|
|
|
|
2016-09-16 18:38:12 +02:00
|
|
|
|
2016-09-16 12:36:06 +02:00
|
|
|
logger.debug("Going to create : {}", networkingFacet);
|
|
|
|
NetworkingFacet createdNetworkingFacet = resourceRegistryPublisher.createFacet(NetworkingFacet.class, networkingFacet);
|
|
|
|
logger.debug("Created : {}", createdNetworkingFacet);
|
|
|
|
|
|
|
|
|
|
|
|
HostingNode hostingNode = new HostingNodeImpl();
|
|
|
|
|
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
|
|
|
|
|
|
|
hostingNode.addFacet(cpuFacet);
|
|
|
|
|
2016-09-16 18:38:12 +02:00
|
|
|
IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedByHNNF = new IsIdentifiedByImpl<>(hostingNode, createdNetworkingFacet, null);
|
|
|
|
hostingNode.attachFacet(isIdentifiedByHNNF);
|
2016-09-16 12:36:06 +02:00
|
|
|
|
|
|
|
Hosts<HostingNode, EService> hosts = new HostsImpl<HostingNode, EService>(hostingNode, eService, null);
|
|
|
|
|
|
|
|
hostingNode.attachResource(hosts);
|
|
|
|
|
2016-09-16 18:38:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
Entities.registerSubtypes(HostingNode.class, CPUFacet.class);
|
|
|
|
|
2016-09-16 12:36:06 +02:00
|
|
|
logger.debug("Going to create : {}", hostingNode);
|
|
|
|
HostingNode createdHostingNode = resourceRegistryPublisher.createResource(HostingNode.class, hostingNode);
|
|
|
|
logger.debug("Created : {}", createdHostingNode);
|
|
|
|
|
|
|
|
|
2016-09-16 13:39:26 +02:00
|
|
|
CPUFacet createdCPUFacet = (CPUFacet) createdHostingNode.getIdentificationFacets().get(0);
|
|
|
|
logger.debug("Created : {}", createdCPUFacet);
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug("Going to delete : {}", createdHostingNode);
|
|
|
|
boolean deleted = resourceRegistryPublisher.deleteResource(createdHostingNode);
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
|
|
|
logger.debug("Going to delete : {}", createdCPUFacet);
|
|
|
|
deleted = resourceRegistryPublisher.deleteFacet(createdCPUFacet);
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
|
|
|
logger.debug("Going to delete : {}", createdNetworkingFacet);
|
|
|
|
deleted = resourceRegistryPublisher.deleteFacet(createdNetworkingFacet);
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug("Going to delete : {}", createdSoftwareFacet);
|
|
|
|
deleted = resourceRegistryPublisher.deleteFacet(createdSoftwareFacet);
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug("Going to delete : {}", createdEService);
|
|
|
|
deleted = resourceRegistryPublisher.deleteResource(createdEService);
|
2016-09-16 12:36:06 +02:00
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCreateAndDeleteEntitiesAndRelations() throws Exception {
|
|
|
|
EService eService = new EServiceImpl();
|
|
|
|
|
|
|
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
|
|
|
softwareFacet.setGroup("InformationSystem");
|
|
|
|
softwareFacet.setName("resource-registry");
|
|
|
|
softwareFacet.setVersion("1.1.0");
|
|
|
|
|
|
|
|
IsIdentifiedBy<Resource, Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(eService, softwareFacet, null);
|
|
|
|
eService.addFacet(isIdentifiedBy);
|
|
|
|
|
|
|
|
logger.debug("Going to create : {}", eService);
|
|
|
|
EService createdEService = resourceRegistryPublisher.createResource(EService.class, eService);
|
|
|
|
logger.debug("Created : {}", createdEService);
|
|
|
|
|
|
|
|
|
|
|
|
HostingNode hostingNode = new HostingNodeImpl();
|
|
|
|
|
|
|
|
logger.debug("Going to create : {}", hostingNode);
|
|
|
|
HostingNode createdHostingNode = resourceRegistryPublisher.createResource(HostingNode.class, hostingNode);
|
|
|
|
logger.debug("Created : {}", createdHostingNode);
|
|
|
|
|
|
|
|
|
|
|
|
CPUFacet cpuFacet = new CPUFacetImpl();
|
|
|
|
cpuFacet.setClockSpeed("1 GHz");
|
|
|
|
cpuFacet.setModel("Opteron");
|
|
|
|
cpuFacet.setVendor("AMD");
|
|
|
|
|
|
|
|
logger.debug("Going to create: {}", cpuFacet);
|
|
|
|
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(CPUFacet.class, cpuFacet);
|
|
|
|
logger.debug("Created: {}", createdCpuFacet);
|
|
|
|
|
|
|
|
|
|
|
|
IsIdentifiedBy<HostingNode, CPUFacet> isIdentifiedByCPUFacet = new IsIdentifiedByImpl<>(createdHostingNode, createdCpuFacet, null);
|
|
|
|
logger.debug("Going to create : {}", isIdentifiedByCPUFacet);
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
IsIdentifiedBy<HostingNode, CPUFacet> createdIsIdentifiedByCPUFacet = resourceRegistryPublisher.createConsistsOf(IsIdentifiedBy.class, isIdentifiedByCPUFacet);
|
|
|
|
logger.debug("Created : {}", createdIsIdentifiedByCPUFacet);
|
|
|
|
|
|
|
|
|
|
|
|
Hosts<HostingNode, EService> hosts = new HostsImpl<>(createdHostingNode, createdEService, null);
|
|
|
|
logger.debug("Going to create : {}", hosts);
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
Hosts<HostingNode, EService> createdHosts = resourceRegistryPublisher.createIsRelatedTo(Hosts.class, hosts);
|
|
|
|
logger.debug("Created : {}", createdHosts);
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug("Going to delete : {}", createdIsIdentifiedByCPUFacet);
|
2016-09-16 18:38:12 +02:00
|
|
|
boolean deleted = resourceRegistryPublisher.deleteConsistsOf(createdIsIdentifiedByCPUFacet);
|
2016-09-16 12:36:06 +02:00
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug("Going to delete : {}", createdCpuFacet);
|
|
|
|
deleted = resourceRegistryPublisher.deleteFacet(createdCpuFacet);
|
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug("Going to delete : {}", createdHosts);
|
2016-09-16 18:38:12 +02:00
|
|
|
deleted = resourceRegistryPublisher.deleteIsRelatedTo(createdHosts);
|
2016-09-16 12:36:06 +02:00
|
|
|
Assert.assertTrue(deleted);
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug("Going to delete : {}", createdHostingNode);
|
|
|
|
deleted = resourceRegistryPublisher.deleteResource(createdHostingNode);
|
|
|
|
Assert.assertTrue(deleted);
|
2016-09-15 14:57:14 +02:00
|
|
|
}
|
2016-09-16 12:36:06 +02:00
|
|
|
|
2016-09-15 14:57:14 +02:00
|
|
|
|
2016-09-14 18:08:46 +02:00
|
|
|
}
|