Fixed tests
This commit is contained in:
parent
cff16573dd
commit
caf354617a
|
@ -91,6 +91,8 @@ public class ERManagementTest extends ContextTest {
|
|||
}else {
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
}
|
||||
resourceRegistryPublisher.setIncludeMeta(true);
|
||||
resourceRegistryPublisher.setAllMeta(true);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,10 +9,9 @@ import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
|
|||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
|
||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||
import org.gcube.informationsystem.utils.UUIDManager;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
||||
|
@ -22,11 +21,13 @@ import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentified
|
|||
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.Actor;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPlugin;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -35,7 +36,7 @@ public class InvalidOperationTest extends ERManagementTest {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(InvalidOperationTest.class);
|
||||
|
||||
public static final String ACTIVATES = "{\"propagationConstraint\":{\"" + Element.TYPE_PROPERTY + "\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascade\",\"delete\":\"cascade\"},\"" + Element.TYPE_PROPERTY + "\":\"Activates\",\"source\":{\"" + Element.TYPE_PROPERTY + "\":\"Configuration\",\"uuid\":\"CONFIGURATION_UUID\"},\"target\":{\"" + IdentifiableElement.ID_PROPERTY + "\":\"ESERVICE_UUID\",\"" + Element.TYPE_PROPERTY + "\":\"EService\"}}";
|
||||
public static final String ACTIVATES = "{\"propagationConstraint\":{\"" + Element.TYPE_PROPERTY + "\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascade\",\"delete\":\"cascade\"},\"" + Element.TYPE_PROPERTY + "\":\"Activates\",\"source\":{\"" + Element.TYPE_PROPERTY + "\":\"Configuration\",\"" + IdentifiableElement.ID_PROPERTY + "\":\"CONFIGURATION_UUID\"},\"target\":{\"" + IdentifiableElement.ID_PROPERTY + "\":\"ESERVICE_UUID\",\"" + Element.TYPE_PROPERTY + "\":\"EService\"}}";
|
||||
public static final String ACTOR = "{\"" + Element.TYPE_PROPERTY + "\":\"Actor\",\"metadata\":null,\"consistsOf\":[{\"" + Element.TYPE_PROPERTY + "\":\"IsIdentifiedBy\",\"metadata\":null,\"propagationConstraint\":{\"" + Element.TYPE_PROPERTY + "\":\"PropagationConstraint\",\"remove\":\"cascade\",\"delete\":\"cascade\",\"add\":\"propagate\"},\"source\":{\"" + Element.TYPE_PROPERTY + "\":\"Actor\",\"metadata\":null},\"target\":{\"" + Element.TYPE_PROPERTY + "\":\"ContactFacet\",\"metadata\":null,\"title\":\"Dr.\",\"name\":\"Frosini\",\"middleName\":null,\"surname\":null,\"eMail\":\"luca.frosini@isti.cnr.it\"}}],\"isRelatedTo\":[]}";
|
||||
|
||||
@Test(expected = SchemaViolationException.class)
|
||||
|
@ -58,7 +59,7 @@ public class InvalidOperationTest extends ERManagementTest {
|
|||
String json = ACTIVATES.replace("CONFIGURATION_UUID", configuration.getID().toString());
|
||||
json = json.replace("ESERVICE_UUID", eService.getID().toString());
|
||||
|
||||
resourceRegistryPublisher.create(json);
|
||||
((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(Activates.NAME, json, UUIDManager.getInstance().generateValidUUID());
|
||||
|
||||
}finally {
|
||||
resourceRegistryPublisher.delete(configuration);
|
||||
|
@ -66,17 +67,6 @@ public class InvalidOperationTest extends ERManagementTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(expected = ResourceAlreadyPresentException.class)
|
||||
public void testRecreate() throws Exception {
|
||||
EService eService = createEService();
|
||||
try {
|
||||
resourceRegistryPublisher.create(eService);
|
||||
}finally {
|
||||
resourceRegistryPublisher.delete(eService);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = SchemaViolationException.class)
|
||||
public void testCreateStandAloneFacet() throws Exception {
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
|
@ -102,15 +92,9 @@ public class InvalidOperationTest extends ERManagementTest {
|
|||
resourceRegistryPublisher.create(runningPlugin);
|
||||
}
|
||||
|
||||
@Test(expected = ResourceRegistryException.class)
|
||||
public void testCreateAnEntityDifferentFromDeclared() throws Exception {
|
||||
EService eService = ERManagementTest.instantiateValidEService();
|
||||
resourceRegistryPublisher.create(eService);
|
||||
}
|
||||
|
||||
@Test(expected = SchemaViolationException.class)
|
||||
public void testCreateAbstractEntity() throws Exception {
|
||||
resourceRegistryPublisher.create(ACTOR);
|
||||
((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(Actor.NAME, ACTOR, UUIDManager.getInstance().generateValidUUID());
|
||||
}
|
||||
|
||||
@Test(expected = SchemaViolationException.class)
|
||||
|
@ -184,7 +168,7 @@ public class InvalidOperationTest extends ERManagementTest {
|
|||
String json = ElementMapper.marshal(consistsOf);
|
||||
json = json.replaceAll(SimpleFacet.NAME, EService.NAME);
|
||||
|
||||
resourceRegistryPublisher.create(json);
|
||||
((ResourceRegistryPublisherImpl)resourceRegistryPublisher).create(ConsistsOf.NAME, json, UUIDManager.getInstance().generateValidUUID());
|
||||
throw new Exception("A ConsistsOf has been created between two resoures. This should not happen");
|
||||
} finally {
|
||||
resourceRegistryPublisher.delete(map.get(EService.NAME));
|
||||
|
|
|
@ -26,8 +26,8 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra
|
|||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaViolationException;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl;
|
||||
|
@ -40,23 +40,30 @@ import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetI
|
|||
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasVolatileMemoryImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.GCubeResource;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
|
||||
import org.junit.Assert;
|
||||
|
@ -89,6 +96,7 @@ public class ERManagementTest extends ContextTest {
|
|||
@Test
|
||||
public void testEncrypted() throws Exception {
|
||||
EService eService = new EServiceImpl();
|
||||
|
||||
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
||||
URL endpoint = new URL("https://d4science.org:443");
|
||||
accessPointFacet.setEndpoint(endpoint.toURI());
|
||||
|
@ -97,9 +105,28 @@ public class ERManagementTest extends ContextTest {
|
|||
accessPointFacet.setAdditionalProperty(PASSWORD, encrypted);
|
||||
eService.addFacet(accessPointFacet);
|
||||
|
||||
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);
|
||||
|
||||
EventFacet eventFacet = new EventFacetImpl();
|
||||
eventFacet.setDate(Calendar.getInstance().getTime());
|
||||
eventFacet.setEvent("Created");
|
||||
eService.addFacet(eventFacet);
|
||||
|
||||
StateFacet stateFacet = new StateFacetImpl();
|
||||
stateFacet.setValue("ready");
|
||||
eService.addFacet(stateFacet);
|
||||
|
||||
ResourceRegistryPublisher resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
EService receivedEservice = resourceRegistryPublisher.create(eService);
|
||||
AccessPointFacet receivedFacet = (AccessPointFacet) receivedEservice.getFacets().get(0);
|
||||
|
||||
AccessPointFacet receivedFacet = (AccessPointFacet) receivedEservice.getFacets(AccessPointFacet.class).get(0);
|
||||
UUID eServiceUUID = receivedEservice.getID();
|
||||
UUID facetUUID = receivedFacet.getID();
|
||||
|
||||
|
@ -117,7 +144,7 @@ public class ERManagementTest extends ContextTest {
|
|||
UUID receivedEServiceUUID = receivedEservice.getID();
|
||||
Assert.assertTrue(eServiceUUID.compareTo(receivedEServiceUUID)==0);
|
||||
|
||||
receivedFacet = (AccessPointFacet) receivedEservice.getFacets().get(0);
|
||||
receivedFacet = (AccessPointFacet) receivedEservice.getFacets(AccessPointFacet.class).get(0);
|
||||
UUID receivedFacetUUID = receivedFacet.getID();
|
||||
Assert.assertTrue(facetUUID.compareTo(receivedFacetUUID)==0);
|
||||
|
||||
|
@ -300,56 +327,6 @@ public class ERManagementTest extends ContextTest {
|
|||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateReadDeleteFacet() throws Exception {
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
cpuFacet.setClockSpeed("1 GHz");
|
||||
cpuFacet.setModel("Opteron");
|
||||
cpuFacet.setVendor("AMD");
|
||||
|
||||
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
|
||||
|
||||
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.getID();
|
||||
|
||||
CPUFacet readCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);
|
||||
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0);
|
||||
Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0);
|
||||
Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0);
|
||||
Assert.assertTrue(uuid.compareTo(readCpuFacet.getID()) == 0);
|
||||
|
||||
String newVendor = "Intel";
|
||||
String newClockSpeed = "2 GHz";
|
||||
readCpuFacet.setVendor(newVendor);
|
||||
readCpuFacet.setClockSpeed(newClockSpeed);
|
||||
|
||||
String additionPropertyKey = "My";
|
||||
String additionPropertyValue = "Test";
|
||||
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
|
||||
|
||||
CPUFacet updatedCpuFacet = resourceRegistryPublisher.updateFacet(readCpuFacet);
|
||||
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(updatedCpuFacet.getClockSpeed()) == 0);
|
||||
Assert.assertTrue(readCpuFacet.getModel().compareTo(updatedCpuFacet.getModel()) == 0);
|
||||
Assert.assertTrue(readCpuFacet.getVendor().compareTo(updatedCpuFacet.getVendor()) == 0);
|
||||
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
|
||||
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
|
||||
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID()) == 0);
|
||||
|
||||
CPUFacet readUpdatedCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);
|
||||
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(readUpdatedCpuFacet.getClockSpeed()) == 0);
|
||||
Assert.assertTrue(updatedCpuFacet.getModel().compareTo(readUpdatedCpuFacet.getModel()) == 0);
|
||||
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0);
|
||||
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
|
||||
.compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
|
||||
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getID()) == 0);
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteFacet(readUpdatedCpuFacet);
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
public Map<String,Resource> createHostingNodeAndEService() throws Exception {
|
||||
Map<String,Resource> map = new HashMap<>();
|
||||
|
||||
|
@ -364,29 +341,71 @@ public class ERManagementTest extends ContextTest {
|
|||
null);
|
||||
eService.addFacet(isIdentifiedBy);
|
||||
|
||||
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
||||
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
||||
accessPointFacet.setEntryName("port1");
|
||||
eService.addFacet(accessPointFacet);
|
||||
|
||||
EventFacet eventFacet = new EventFacetImpl();
|
||||
eventFacet.setDate(Calendar.getInstance().getTime());
|
||||
eventFacet.setEvent("Created");
|
||||
eService.addFacet(eventFacet);
|
||||
|
||||
StateFacet stateFacet = new StateFacetImpl();
|
||||
stateFacet.setValue("ready");
|
||||
eService.addFacet(stateFacet);
|
||||
|
||||
eService = resourceRegistryPublisher.createResource(eService);
|
||||
map.put(EService.NAME, eService);
|
||||
|
||||
// networkingFacet = resourceRegistryPublisher.createFacet(networkingFacet);
|
||||
// logger.debug("Unmarshalled {} {}", NetworkingFacet.NAME, networkingFacet);
|
||||
|
||||
HostingNode hostingNode = new HostingNodeImpl();
|
||||
|
||||
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");
|
||||
|
||||
networkingFacet = resourceRegistryPublisher.createFacet(networkingFacet);
|
||||
logger.debug("Unmarshalled {} {}", NetworkingFacet.NAME, networkingFacet);
|
||||
|
||||
HostingNode hostingNode = new HostingNodeImpl();
|
||||
|
||||
|
||||
isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(hostingNode, networkingFacet, null);
|
||||
hostingNode.addFacet(isIdentifiedBy);
|
||||
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
cpuFacet.setClockSpeed("1 GHz");
|
||||
cpuFacet.setModel("Opteron");
|
||||
cpuFacet.setVendor("AMD");
|
||||
hostingNode.addFacet(cpuFacet);
|
||||
|
||||
isIdentifiedBy = new IsIdentifiedByImpl<Resource,Facet>(hostingNode, networkingFacet, null);
|
||||
hostingNode.addFacet(isIdentifiedBy);
|
||||
MemoryFacet ram = new MemoryFacetImpl();
|
||||
ram.setSize(8);
|
||||
ram.setUnit(MemoryUnit.GB);
|
||||
ram.setUsed(2);
|
||||
|
||||
HasVolatileMemory<HostingNode, MemoryFacet> hasVolatileMemory =
|
||||
new HasVolatileMemoryImpl<HostingNode, MemoryFacet>(hostingNode, ram, null);
|
||||
hostingNode.addFacet(hasVolatileMemory);
|
||||
|
||||
|
||||
MemoryFacet disk = new MemoryFacetImpl();
|
||||
disk.setSize(256);
|
||||
disk.setUnit(MemoryUnit.GB);
|
||||
disk.setUsed(120);
|
||||
|
||||
HasPersistentMemory<HostingNode, MemoryFacet> hasPersistentMemory =
|
||||
new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(hostingNode, disk, null);
|
||||
hostingNode.addFacet(hasPersistentMemory);
|
||||
|
||||
StateFacet hnStateFacet = new StateFacetImpl();
|
||||
hnStateFacet.setValue("certified");
|
||||
hostingNode.addFacet(hnStateFacet);
|
||||
|
||||
EventFacet hnEventFacet = new EventFacetImpl();
|
||||
hnEventFacet.setDate(Calendar.getInstance().getTime());
|
||||
hnEventFacet.setEvent("Created");
|
||||
hostingNode.addFacet(hnEventFacet);
|
||||
|
||||
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
||||
propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade);
|
||||
|
@ -425,55 +444,25 @@ public class ERManagementTest extends ContextTest {
|
|||
Facet shared = hostingNode.getConsistsOf().get(0).getTarget();
|
||||
UUID sharedFacetUUID = shared.getID();
|
||||
|
||||
ConsistsOf<EService,Facet> consistsOf = new ConsistsOfImpl<EService,Facet>(eService, shared, null);
|
||||
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(map.get(EService.NAME));
|
||||
Assert.assertTrue(deleted);
|
||||
|
||||
deleted = resourceRegistryPublisher.deleteResource(map.get(HostingNode.NAME));
|
||||
Assert.assertTrue(deleted);
|
||||
|
||||
try {
|
||||
resourceRegistryClient.getInstance(Facet.class, sharedFacetUUID);
|
||||
throw new Exception(String.format("Shared Facet %s was not deleted", shared));
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.debug("Shared Facet was not foud as expected");
|
||||
ConsistsOf<EService,Facet> consistsOf = new ConsistsOfImpl<EService,Facet>(eService, shared, null);
|
||||
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
|
||||
} catch (SchemaViolationException e) {
|
||||
logger.debug("As expected ", e);
|
||||
} finally {
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(map.get(EService.NAME));
|
||||
Assert.assertTrue(deleted);
|
||||
|
||||
deleted = resourceRegistryPublisher.deleteResource(map.get(HostingNode.NAME));
|
||||
Assert.assertTrue(deleted);
|
||||
|
||||
try {
|
||||
resourceRegistryClient.getInstance(Facet.class, sharedFacetUUID);
|
||||
throw new Exception(String.format("Shared Facet %s was not deleted", shared));
|
||||
} catch(ResourceRegistryException e) {
|
||||
logger.debug("Shared Facet was not found as expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateResourceAndFacet() throws Exception {
|
||||
|
||||
HostingNode hostingNode = new HostingNodeImpl();
|
||||
hostingNode = resourceRegistryPublisher.createResource(hostingNode);
|
||||
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
cpuFacet.setClockSpeed("1 GHz");
|
||||
cpuFacet.setModel("Opteron");
|
||||
cpuFacet.setVendor("AMD");
|
||||
|
||||
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
|
||||
|
||||
ConsistsOf<HostingNode,Facet> consistsOf = new ConsistsOfImpl<HostingNode,Facet>(hostingNode, createdCpuFacet,
|
||||
null);
|
||||
consistsOf = resourceRegistryPublisher.createConsistsOf(consistsOf);
|
||||
|
||||
UUID consistOfUUID = consistsOf.getID();
|
||||
|
||||
boolean detached = resourceRegistryPublisher.deleteConsistsOf(consistsOf);
|
||||
|
||||
if(detached) {
|
||||
logger.trace("{} {} with uuid {} removed successfully", ConsistsOf.NAME, Relation.NAME, consistOfUUID);
|
||||
} else {
|
||||
String error = String.format("Unable to remove %s %s with uuid %s", ConsistsOf.NAME, Relation.NAME,
|
||||
consistOfUUID);
|
||||
logger.error(error);
|
||||
throw new Exception(error);
|
||||
}
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(hostingNode);
|
||||
Assert.assertTrue(deleted);
|
||||
|
||||
}
|
||||
|
||||
|
@ -653,39 +642,13 @@ public class ERManagementTest extends ContextTest {
|
|||
@Test
|
||||
public void testCreateHostingNodeThenActivatesWithEService() throws Exception {
|
||||
|
||||
HostingNode hostingNode = new HostingNodeImpl();
|
||||
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
cpuFacet.setClockSpeed("1 GHz");
|
||||
cpuFacet.setModel("Opteron");
|
||||
cpuFacet.setVendor("AMD");
|
||||
hostingNode.addFacet(cpuFacet);
|
||||
|
||||
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");
|
||||
|
||||
IsIdentifiedBy<HostingNode,NetworkingFacet> hnIsIdentifiedBy = new IsIdentifiedByImpl<HostingNode,NetworkingFacet>(
|
||||
hostingNode, networkingFacet, null);
|
||||
hostingNode.addFacet(hnIsIdentifiedBy);
|
||||
HostingNode hostingNode = org.gcube.informationsystem.resourceregistry.publisher.ERManagementTest.instantiateValidHostingNode();
|
||||
|
||||
hostingNode = resourceRegistryPublisher.createResource(hostingNode);
|
||||
|
||||
/* -------- */
|
||||
|
||||
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);
|
||||
EService eService = org.gcube.informationsystem.resourceregistry.publisher.ERManagementTest.instantiateValidEService();
|
||||
|
||||
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
|
||||
propagationConstraint.setDeleteConstraint(DeleteConstraint.cascade);
|
||||
|
|
|
@ -72,7 +72,7 @@ public class MultiContextTest extends ContextTest {
|
|||
protected ResourceRegistryClient resourceRegistryClient;
|
||||
|
||||
public MultiContextTest() throws Exception {
|
||||
ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE);
|
||||
// ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE);
|
||||
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
|
@ -127,7 +127,6 @@ public class MultiContextTest extends ContextTest {
|
|||
IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedByHNNF = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(hostingNode, networkingFacet, null);
|
||||
hostingNode.addFacet(isIdentifiedByHNNF);
|
||||
|
||||
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
cpuFacet.setClockSpeed("1 GHz");
|
||||
cpuFacet.setModel("Opteron");
|
||||
|
@ -154,23 +153,29 @@ public class MultiContextTest extends ContextTest {
|
|||
new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(hostingNode, disk, null);
|
||||
hostingNode.addFacet(hasPersistentMemory);
|
||||
|
||||
StateFacet hnStateFacet = new StateFacetImpl();
|
||||
hnStateFacet.setValue("certified");
|
||||
hostingNode.addFacet(hnStateFacet);
|
||||
|
||||
EventFacet hnEventFacet = new EventFacetImpl();
|
||||
hnEventFacet.setDate(Calendar.getInstance().getTime());
|
||||
hnEventFacet.setEvent("Created");
|
||||
hostingNode.addFacet(hnEventFacet);
|
||||
|
||||
|
||||
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(hostingNode, createdEService, null);
|
||||
hostingNode.attachResource(activates);
|
||||
|
||||
HostingNode createdHN = resourceRegistryPublisher.createResource(hostingNode);
|
||||
logger.debug("Created : {}", createdHN);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
logger.debug("Changing token to test add to scope");
|
||||
ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE);
|
||||
|
||||
|
||||
UUID hostingNodeUUID = createdHN.getID();
|
||||
UUID eServiceUUID = createdEService.getID();
|
||||
|
||||
UUID alternativeContextUUID = ContextCache.getInstance().getUUIDByFullName(ALTERNATIVE_TEST_SCOPE);
|
||||
|
||||
resourceRegistryPublisher.addResourceToContext(createdHN, alternativeContextUUID, false);
|
||||
|
||||
logger.debug("Changing token to test add to scope");
|
||||
ContextTest.setContextByName(ContextTest.ALTERNATIVE_TEST_SCOPE);
|
||||
|
||||
|
|
|
@ -1,142 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.informationsystem.resourceregistry.publisher.old;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.facet.FacetNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.entities.resource.ResourceNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientImpl;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ContextTest;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
|
||||
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
||||
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public class RRClientTest extends ContextTest {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(EntityManagementTest.class);
|
||||
|
||||
protected ResourceRegistryPublisher resourceRegistryPublisher;
|
||||
protected ResourceRegistryClient resourceRegistryClient;
|
||||
|
||||
public RRClientTest(){
|
||||
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
|
||||
resourceRegistryPublisher = new ResourceRegistryPublisherImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
||||
}else {
|
||||
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
||||
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||
}
|
||||
logger.trace("{} and {} created",
|
||||
ResourceRegistryPublisher.class.getSimpleName(),
|
||||
ResourceRegistryClient.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFacet() throws FacetNotFoundException, ResourceRegistryException{
|
||||
CPUFacet cpuFacet = new CPUFacetImpl();
|
||||
cpuFacet.setClockSpeed("1 GHz");
|
||||
cpuFacet.setModel("Opteron");
|
||||
cpuFacet.setVendor("AMD");
|
||||
|
||||
CPUFacet createdCpuFacet = resourceRegistryPublisher.createFacet(cpuFacet);
|
||||
|
||||
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.getID();
|
||||
|
||||
Facet f = resourceRegistryClient.getInstance(Facet.class, uuid);
|
||||
Assert.assertTrue(f instanceof CPUFacet);
|
||||
|
||||
CPUFacet readCpuFacet = (CPUFacet) f;
|
||||
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
|
||||
Assert.assertTrue(readCpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
|
||||
Assert.assertTrue(readCpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
|
||||
|
||||
|
||||
readCpuFacet = resourceRegistryClient.getInstance(CPUFacet.class, uuid);
|
||||
Assert.assertTrue(readCpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed())==0);
|
||||
Assert.assertTrue(readCpuFacet.getModel().compareTo(createdCpuFacet.getModel())==0);
|
||||
Assert.assertTrue(readCpuFacet.getVendor().compareTo(createdCpuFacet.getVendor())==0);
|
||||
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteFacet(createdCpuFacet);
|
||||
Assert.assertTrue(deleted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResource() throws ResourceNotFoundException, ResourceRegistryException{
|
||||
EService eService = new EServiceImpl();
|
||||
|
||||
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
||||
softwareFacet.setGroup("InformationSystem");
|
||||
softwareFacet.setName("resource-registry");
|
||||
softwareFacet.setVersion("1.1.0");
|
||||
|
||||
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedByESSF = new IsIdentifiedByImpl<>(eService, softwareFacet, null);
|
||||
eService.addFacet(isIdentifiedByESSF);
|
||||
|
||||
EService createdEService = resourceRegistryPublisher.createResource(eService);
|
||||
|
||||
List<? extends Facet> idenficationFacets = createdEService.getIdentificationFacets();
|
||||
Assert.assertTrue(idenficationFacets!=null);
|
||||
Assert.assertTrue(idenficationFacets.size()==1);
|
||||
Facet f = idenficationFacets.get(0);
|
||||
Assert.assertTrue(f!=null);
|
||||
Assert.assertTrue(f instanceof SoftwareFacet);
|
||||
SoftwareFacet createdSoftwareFacet = (SoftwareFacet) f;
|
||||
Assert.assertTrue(createdSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup())==0);
|
||||
Assert.assertTrue(createdSoftwareFacet.getName().compareTo(softwareFacet.getName())==0);
|
||||
Assert.assertTrue(createdSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion())==0);
|
||||
|
||||
|
||||
Resource resource = resourceRegistryClient.getInstance(Resource.class, createdEService.getID());
|
||||
Assert.assertTrue(resource.getID().compareTo(createdEService.getID())==0);
|
||||
Assert.assertTrue(resource instanceof EService);
|
||||
|
||||
EService readEService = resourceRegistryClient.getInstance(EService.class, createdEService.getID());
|
||||
Assert.assertTrue(readEService.getID().compareTo(createdEService.getID())==0);
|
||||
List<? extends Facet> idFacets = readEService.getIdentificationFacets();
|
||||
Assert.assertTrue(idFacets!=null);
|
||||
Assert.assertTrue(idFacets.size()==1);
|
||||
f = idFacets.get(0);
|
||||
Assert.assertTrue(f!=null);
|
||||
Assert.assertTrue(f instanceof SoftwareFacet);
|
||||
SoftwareFacet readSoftwareFacet = (SoftwareFacet) f;
|
||||
Assert.assertTrue(readSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup())==0);
|
||||
Assert.assertTrue(readSoftwareFacet.getName().compareTo(softwareFacet.getName())==0);
|
||||
Assert.assertTrue(readSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion())==0);
|
||||
Assert.assertTrue(readSoftwareFacet.getID().compareTo(createdSoftwareFacet.getID())==0);
|
||||
|
||||
|
||||
boolean deleted = resourceRegistryPublisher.deleteResource(createdEService);
|
||||
Assert.assertTrue(deleted);
|
||||
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue