Improving tests

This commit is contained in:
Luca Frosini 2021-03-08 13:09:18 +01:00
parent 8cec58eae8
commit b37cbb0020
3 changed files with 200 additions and 289 deletions

View File

@ -3,9 +3,6 @@
*/ */
package org.gcube.informationsystem.resourceregistry.instances; package org.gcube.informationsystem.resourceregistry.instances;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
@ -16,8 +13,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
import org.gcube.common.authorization.library.provider.AuthorizationProvider; import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.informationsystem.base.reference.Element; import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.base.reference.IdentifiableElement;
@ -34,8 +29,8 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.ContextTest; import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
@ -286,7 +281,7 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(clz==gotClz); Assert.assertTrue(clz==gotClz);
} }
protected static <R extends Resource> void testResource(R resource, R gotResource) throws Exception { protected static <R extends Resource> void checkResource(R resource, R gotResource) throws Exception {
Assert.assertTrue(resource.getClass() == gotResource.getClass()); Assert.assertTrue(resource.getClass() == gotResource.getClass());
checkHeader(resource, gotResource); checkHeader(resource, gotResource);
@ -306,19 +301,31 @@ public class ERManagementTest extends ContextTest {
} }
public static EService createEService() throws Exception { public static <R extends Resource> ResourceManagement getResourceManagement(R r) throws Exception {
EService eService = ERManagementTest.instantiateValidEService();
ResourceManagement resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME); resourceManagement.setElementType(Utility.getTypeName(r));
resourceManagement.setJson(ElementMapper.marshal(eService)); resourceManagement.setJson(ElementMapper.marshal(r));
if(r.getHeader()!=null && r.getHeader().getUUID()!=null) {
resourceManagement.setUUID(r.getHeader().getUUID());
}
return resourceManagement;
}
public static <R extends Resource> R createResource(R r) throws Exception {
ResourceManagement resourceManagement = getResourceManagement(r);
String json = resourceManagement.create(); String json = resourceManagement.create();
EService createdEService = ElementMapper.unmarshal(EService.class, json); @SuppressWarnings("unchecked")
R createdR = (R) ElementMapper.unmarshal(r.getClass(), json);
testResource(eService, createdEService); checkResource(r, createdR);
return createdEService; return createdR;
}
public static EService createEService() throws Exception {
EService eService = ERManagementTest.instantiateValidEService();
return createResource(eService);
} }
public static HostingNode createHostingNode() throws Exception { public static HostingNode createHostingNode() throws Exception {
@ -334,17 +341,7 @@ public class ERManagementTest extends ContextTest {
propagationConstraint); propagationConstraint);
hostingNode.attachResource(activates); hostingNode.attachResource(activates);
} }
return createResource(hostingNode);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(HostingNode.NAME);
resourceManagement.setJson(ElementMapper.marshal(hostingNode));
String json = resourceManagement.create();
HostingNode createdHostingNode = ElementMapper.unmarshal(HostingNode.class, json);
testResource(hostingNode, createdHostingNode);
return createdHostingNode;
} }
public static Map<String, Resource> createHostingNodeAndEService() throws Exception { public static Map<String, Resource> createHostingNodeAndEService() throws Exception {
@ -359,6 +356,13 @@ public class ERManagementTest extends ContextTest {
return map; return map;
} }
public static <R extends Resource> void deleteResource(R r) throws Exception {
if(r!=null) {
ResourceManagement resourceManagement = getResourceManagement(r);
resourceManagement.delete();
}
}
@Test @Test
public void testCreateEService() throws Exception { public void testCreateEService() throws Exception {
@ -366,12 +370,7 @@ public class ERManagementTest extends ContextTest {
try { try {
eService = createEService(); eService = createEService();
}finally { }finally {
if(eService!=null) { deleteResource(eService);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setUUID(eService.getHeader().getUUID());
resourceManagement.delete();
}
} }
} }
@ -402,12 +401,7 @@ public class ERManagementTest extends ContextTest {
try { try {
hostingNode = createHostingNode(); hostingNode = createHostingNode();
}finally { }finally {
if(hostingNode!=null) { deleteResource(hostingNode);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(HostingNode.NAME);
resourceManagement.setUUID(hostingNode.getHeader().getUUID());
resourceManagement.delete();
}
} }
} }
@ -415,105 +409,98 @@ public class ERManagementTest extends ContextTest {
@Test @Test
public void testCreateHostingNodeAndEService() throws Exception { public void testCreateHostingNodeAndEService() throws Exception {
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService(); Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
deleteResource(map.get(EService.NAME));
ResourceManagement resourceManagement = new ResourceManagement(); deleteResource(map.get(HostingNode.NAME));
resourceManagement.setUUID(map.get(EService.NAME).getHeader().getUUID());
resourceManagement.delete();
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(map.get(HostingNode.NAME).getHeader().getUUID());
resourceManagement.delete();
} }
@Test @Test
public void testCreateReadUpdateDeleteFacet() throws Exception { public void testCreateReadUpdateDeleteFacet() throws Exception {
EService eService = instantiateValidEService(); EService eService = createEService();
ResourceManagement resourceManagement = new ResourceManagement(); try {
resourceManagement.setElementType(EService.NAME); CPUFacet cpuFacet = new CPUFacetImpl();
resourceManagement.setJson(ElementMapper.marshal(eService)); cpuFacet.setClockSpeed("1 GHz");
String createdEServiceString = resourceManagement.create(); cpuFacet.setModel("Opteron");
EService createdEService = ElementMapper.unmarshal(EService.class, createdEServiceString); cpuFacet.setVendor("AMD");
ConsistsOf<EService, CPUFacet> consistsOf = new ConsistsOfImpl<EService, CPUFacet>(eService, cpuFacet);
CPUFacet cpuFacet = new CPUFacetImpl(); ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
cpuFacet.setClockSpeed("1 GHz"); consistsOfManagement.setElementType(Utility.getTypeName(consistsOf));
cpuFacet.setModel("Opteron"); consistsOfManagement.setJson(ElementMapper.marshal(consistsOf));
cpuFacet.setVendor("AMD"); String createdConsistsOfString = consistsOfManagement.create();
ConsistsOf<EService, CPUFacet> consistsOf = new ConsistsOfImpl<EService, CPUFacet>(createdEService, cpuFacet); @SuppressWarnings("unchecked")
ConsistsOf<EService, CPUFacet> createdConsistsOf = ElementMapper.unmarshal(ConsistsOf.class, createdConsistsOfString);
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement(); CPUFacet createdCpuFacet = createdConsistsOf.getTarget();
consistsOfManagement.setElementType(ConsistsOf.NAME);
consistsOfManagement.setJson(ElementMapper.marshal(consistsOf));
String createdConsistsOfString = consistsOfManagement.create();
@SuppressWarnings("unchecked") Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed()) == 0);
ConsistsOf<EService, CPUFacet> createdConsistsOf = ElementMapper.unmarshal(ConsistsOf.class, createdConsistsOfString); Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0);
CPUFacet createdCpuFacet = createdConsistsOf.getTarget(); UUID uuid = createdCpuFacet.getHeader().getUUID();
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed()) == 0); FacetManagement facetManagement = new FacetManagement();
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0); facetManagement.setElementType(Utility.getTypeName(createdCpuFacet));
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0); facetManagement.setUUID(uuid);
UUID uuid = createdCpuFacet.getHeader().getUUID(); String readJson = facetManagement.read().toString();
CPUFacet readCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readJson);
logger.debug("Read:\nRaw Json : {}\nUnmarshalled : {}", readJson, readCpuFacet);
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.getHeader().getUUID()) == 0);
FacetManagement facetManagement = new FacetManagement(); String newVendor = "Intel";
facetManagement.setUUID(uuid); String newClockSpeed = "2 GHz";
readCpuFacet.setVendor(newVendor);
readCpuFacet.setClockSpeed(newClockSpeed);
String readJson = facetManagement.read().toString(); String additionPropertyKey = "My";
CPUFacet readCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readJson); String additionPropertyValue = "Test";
logger.debug("Read:\nRaw Json : {}\nUnmarshalled : {}", readJson, readCpuFacet); readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
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.getHeader().getUUID()) == 0);
String newVendor = "Intel"; facetManagement = new FacetManagement();
String newClockSpeed = "2 GHz"; facetManagement.setElementType(Utility.getTypeName(readCpuFacet));
readCpuFacet.setVendor(newVendor); facetManagement.setUUID(uuid);
readCpuFacet.setClockSpeed(newClockSpeed); facetManagement.setJson(ElementMapper.marshal(readCpuFacet));
String additionPropertyKey = "My"; String updatedJson = facetManagement.update();
String additionPropertyValue = "Test"; CPUFacet updatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, updatedJson);
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue); logger.debug("Updated:\nRaw Json : {}\nUnmarshalled : {}", updatedJson, updatedCpuFacet);
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(newClockSpeed) == 0);
Assert.assertTrue(readCpuFacet.getModel().compareTo(updatedCpuFacet.getModel()) == 0);
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(newVendor) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
String user = AuthorizationProvider.instance.get().getClient().getId();
Assert.assertTrue(updatedCpuFacet.getHeader().getLastUpdateBy().compareTo(user) == 0);
facetManagement = new FacetManagement(); facetManagement = new FacetManagement();
facetManagement.setUUID(uuid); facetManagement.setElementType(Utility.getTypeName(updatedCpuFacet));
facetManagement.setJson(ElementMapper.marshal(readCpuFacet)); facetManagement.setUUID(uuid);
String updatedJson = facetManagement.update(); String readUpdatedJson = facetManagement.read().toString();
CPUFacet updatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, updatedJson); CPUFacet readUpdatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readUpdatedJson);
logger.debug("Updated:\nRaw Json : {}\nUnmarshalled : {}", updatedJson, updatedCpuFacet); logger.debug("Read Updated:\nRaw Json : {}\nUnmarshalled : {}", readUpdatedJson, readUpdatedCpuFacet);
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(newClockSpeed) == 0); Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(readUpdatedCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(readCpuFacet.getModel().compareTo(updatedCpuFacet.getModel()) == 0); Assert.assertTrue(updatedCpuFacet.getModel().compareTo(readUpdatedCpuFacet.getModel()) == 0);
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(newVendor) == 0); Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0);
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey)) Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0); .compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0); Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
String user = AuthorizationProvider.instance.get().getClient().getId();
Assert.assertTrue(updatedCpuFacet.getHeader().getLastUpdateBy().compareTo(user) == 0);
facetManagement = new FacetManagement(); facetManagement = new FacetManagement();
facetManagement.setUUID(uuid); facetManagement.setElementType(Utility.getTypeName(readCpuFacet));
facetManagement.setUUID(uuid);
String readUpdatedJson = facetManagement.read().toString(); facetManagement.delete();
CPUFacet readUpdatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readUpdatedJson); } finally {
logger.debug("Read Updated:\nRaw Json : {}\nUnmarshalled : {}", readUpdatedJson, readUpdatedCpuFacet); deleteResource(eService);
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.getHeader().getUUID()) == 0);
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
facetManagement.delete();
resourceManagement.delete();
} }
@Test @Test
@ -550,16 +537,7 @@ public class ERManagementTest extends ContextTest {
String marshalled = ElementMapper.marshal(configuration); String marshalled = ElementMapper.marshal(configuration);
logger.debug(marshalled); logger.debug(marshalled);
ResourceManagement resourceManagement = new ResourceManagement(); Configuration createdConfiguration = createResource(configuration);
resourceManagement.setElementType(Configuration.NAME);
String json = ElementMapper.marshal(configuration);
logger.debug("{}", json);
resourceManagement.setJson(json);
String configurationJsonString = resourceManagement.create();
Configuration createdConfiguration = ElementMapper.unmarshal(Configuration.class, configurationJsonString);
logger.debug("Created:\nRaw Json : {}\nUnmarshalled : {}", configurationJsonString, createdConfiguration);
AccessPointFacet apf = configuration.getFacets(AccessPointFacet.class).get(0); AccessPointFacet apf = configuration.getFacets(AccessPointFacet.class).get(0);
@ -572,7 +550,7 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(decryptedValue.compareTo(plainValue) == 0); Assert.assertTrue(decryptedValue.compareTo(plainValue) == 0);
Assert.assertTrue(((String) apf.getAdditionalProperty(additionlaPropertyKey)).compareTo(additionlaPropertyValue) == 0); Assert.assertTrue(((String) apf.getAdditionalProperty(additionlaPropertyKey)).compareTo(additionlaPropertyValue) == 0);
resourceManagement.delete(); deleteResource(createdConfiguration);
} }
@ -655,9 +633,7 @@ public class ERManagementTest extends ContextTest {
List<Resource> resourceList = resources.get(HostingNode.NAME); List<Resource> resourceList = resources.get(HostingNode.NAME);
for (Resource r : resourceList) { for (Resource r : resourceList) {
resourceManagement = new ResourceManagement(); deleteResource(r);
resourceManagement.setUUID(r.getHeader().getUUID());
resourceManagement.delete();
} }
} }
@ -799,55 +775,47 @@ public class ERManagementTest extends ContextTest {
resourceManagement.delete(); resourceManagement.delete();
} }
public static final String TEST_RESOURCE = "test-resource.json"; // public static final String TEST_RESOURCE = "test-resource.json";
//
// @Test // // @Test
public void testUpdateResourceFromFile() // public void testUpdateResourceFromFile()
throws JsonParseException, JsonMappingException, IOException, ResourceRegistryException { // throws JsonParseException, JsonMappingException, IOException, ResourceRegistryException {
File file = new File("src/test/resources/" + TEST_RESOURCE); // File file = new File("src/test/resources/" + TEST_RESOURCE);
//
logger.debug("{}", file.getAbsolutePath()); // logger.debug("{}", file.getAbsolutePath());
//
FileInputStream fileInputStream = new FileInputStream(file); // FileInputStream fileInputStream = new FileInputStream(file);
EService eService = ElementMapper.unmarshal(EService.class, fileInputStream); // EService eService = ElementMapper.unmarshal(EService.class, fileInputStream);
//
ResourceManagement resourceManagement = new ResourceManagement(); // ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID()); // resourceManagement.setUUID(eService.getHeader().getUUID());
resourceManagement.setJson(ElementMapper.marshal(eService)); // resourceManagement.setJson(ElementMapper.marshal(eService));
//
resourceManagement.update(); // resourceManagement.update();
//
} // }
@Test @Test
public void testCreateUpdateDeleteEService() throws Exception { public void testUpdateFacetValue() throws Exception {
EService eService = ERManagementTest.instantiateValidEService(); EService eService =null;
try {
eService = createEService();
ResourceManagement resourceManagement = new ResourceManagement(); final String newVersion = "1.2.0";
resourceManagement.setElementType(EService.NAME); eService.getFacets(SoftwareFacet.class).get(0).setVersion(newVersion);
resourceManagement.setJson(ElementMapper.marshal(eService));
String json = resourceManagement.create();
logger.trace("Created {}", json); ResourceManagement resourceManagement = getResourceManagement(eService);
eService = ElementMapper.unmarshal(EService.class, json); String json = resourceManagement.update();
final String newVersion = "1.2.0"; EService updatedEService = ElementMapper.unmarshal(EService.class, json);
eService.getFacets(SoftwareFacet.class).get(0).setVersion(newVersion);
resourceManagement = new ResourceManagement(); checkResource(eService, updatedEService);
resourceManagement.setUUID(eService.getHeader().getUUID());
resourceManagement.setJson(ElementMapper.marshal(eService));
json = resourceManagement.update(); Assert.assertTrue(updatedEService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo(newVersion) == 0);
logger.trace("Updated {}", json);
eService = ElementMapper.unmarshal(EService.class, json);
Assert.assertTrue(eService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo(newVersion) == 0); }finally {
deleteResource(eService);
resourceManagement = new ResourceManagement(); }
resourceManagement.setUUID(eService.getHeader().getUUID());
resourceManagement.delete();
} }
} }

View File

@ -11,6 +11,7 @@ import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.resourceregistry.ContextTest; import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement;
@ -110,11 +111,7 @@ public class InvalidInstancesTest extends ContextTest {
IsIdentifiedBy<RunningPlugin, SoftwareFacet> isIdentifiedBy = new IsIdentifiedByImpl<>(runningPlugin, softwareFacet); IsIdentifiedBy<RunningPlugin, SoftwareFacet> isIdentifiedBy = new IsIdentifiedByImpl<>(runningPlugin, softwareFacet);
runningPlugin.addFacet(isIdentifiedBy); runningPlugin.addFacet(isIdentifiedBy);
ResourceManagement resourceManagement = new ResourceManagement(); ERManagementTest.createResource(runningPlugin);
resourceManagement.setElementType(RunningPlugin.NAME);
resourceManagement.setJson(ElementMapper.marshal(runningPlugin));
resourceManagement.create();
} }
@Test(expected = ResourceRegistryException.class) @Test(expected = ResourceRegistryException.class)
@ -153,50 +150,36 @@ public class InvalidInstancesTest extends ContextTest {
logger.debug("Created : {}", json); logger.debug("Created : {}", json);
} finally { } finally {
ResourceManagement resourceManagement = new ResourceManagement(); ERManagementTest.deleteResource(eService);
resourceManagement.setUUID(eService.getHeader().getUUID()); ERManagementTest.deleteResource(hostingNode);
resourceManagement.delete();
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNode.getHeader().getUUID());
resourceManagement.delete();
} }
} }
@Test(expected = SchemaViolationException.class) @Test(expected = SchemaViolationException.class)
public void testCreateEServiceAndDeleteRequiredConsistsOf() throws Exception { public void testCreateEServiceAndDeleteRequiredConsistsOf() throws Exception {
EService eService = ERManagementTest.instantiateValidEService(); EService eService = null;
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
String createEServiceString = resourceManagement.create();
EService createEService = ElementMapper.unmarshal(EService.class, createEServiceString);
@SuppressWarnings("unchecked")
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) createEService.getConsistsOf(IsIdentifiedBy.class).get(0);
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(IsIdentifiedBy.NAME);
consistsOfManagement.setUUID(isIdentifiedBy.getHeader().getUUID());
try { try {
eService = ERManagementTest.createEService();
@SuppressWarnings("unchecked")
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) eService.getConsistsOf(IsIdentifiedBy.class).get(0);
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(Utility.getTypeName(isIdentifiedBy));
consistsOfManagement.setUUID(isIdentifiedBy.getHeader().getUUID());
consistsOfManagement.delete(); consistsOfManagement.delete();
}finally { }finally {
resourceManagement.delete(); ERManagementTest.deleteResource(eService);
} }
} }
@Test(expected = SchemaViolationException.class) @Test(expected = SchemaViolationException.class)
public void testCreateEServiceAndDeleteRequiredFacet() throws Exception { public void testCreateEServiceAndDeleteRequiredFacet() throws Exception {
EService eService = ERManagementTest.instantiateValidEService(); EService eService = ERManagementTest.createEService();
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
String createEServiceString = resourceManagement.create();
EService createEService = ElementMapper.unmarshal(EService.class, createEServiceString);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) createEService.getConsistsOf(IsIdentifiedBy.class).get(0); IsIdentifiedBy<EService, SoftwareFacet> isIdentifiedBy = (IsIdentifiedBy<EService, SoftwareFacet>) eService.getConsistsOf(IsIdentifiedBy.class).get(0);
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement(); ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(IsIdentifiedBy.NAME); consistsOfManagement.setElementType(IsIdentifiedBy.NAME);
consistsOfManagement.setUUID(isIdentifiedBy.getHeader().getUUID()); consistsOfManagement.setUUID(isIdentifiedBy.getHeader().getUUID());
@ -209,7 +192,7 @@ public class InvalidInstancesTest extends ContextTest {
try { try {
facetManagement.delete(); facetManagement.delete();
}finally { }finally {
resourceManagement.delete(); ERManagementTest.deleteResource(eService);
} }
} }
@ -240,13 +223,8 @@ public class InvalidInstancesTest extends ContextTest {
consistsOfManagement.create(); consistsOfManagement.create();
throw new Exception("A ConsistsOf has been created between two resoures. This should not happen"); throw new Exception("A ConsistsOf has been created between two resoures. This should not happen");
} finally { } finally {
ResourceManagement resourceManagement = new ResourceManagement(); ERManagementTest.deleteResource(map.get(EService.NAME));
resourceManagement.setUUID(eServiceUUID); ERManagementTest.deleteResource(map.get(HostingNode.NAME));
resourceManagement.delete();
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNodeUUID);
resourceManagement.delete();
} }
} }

View File

@ -33,8 +33,6 @@ import javax.management.MalformedObjectNameException;
import javax.management.ObjectName; import javax.management.ObjectName;
import javax.management.ReflectionException; import javax.management.ReflectionException;
import org.gcube.com.fasterxml.jackson.core.JsonParseException;
import org.gcube.com.fasterxml.jackson.databind.JsonMappingException;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl; import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl; import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl; import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
@ -92,72 +90,39 @@ public class SmartgearResourcesTest extends ContextTest {
@Test @Test
public void testHostingNode() throws JsonParseException, public void testHostingNode() throws Exception {
JsonMappingException, IOException, ResourceRegistryException, URISyntaxException { HostingNode hostingNode = ElementMapper.unmarshal(HostingNode.class, HOSTING_NODE);
HostingNode hostingNode = ElementMapper.unmarshal(HostingNode.class, hostingNode = ERManagementTest.createResource(hostingNode);
HOSTING_NODE);
logger.debug("{}", hostingNode);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(HostingNode.NAME);
resourceManagement.setJson(ElementMapper.marshal(hostingNode));
String hnJson = resourceManagement.create();
logger.debug("Created : {}", hnJson);
hostingNode = ElementMapper.unmarshal(HostingNode.class, hnJson);
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
UUID hnUUID = hostingNode.getHeader().getUUID(); UUID hnUUID = hostingNode.getHeader().getUUID();
resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = ERManagementTest.getResourceManagement(hostingNode);
resourceManagement.setUUID(hnUUID);
String read = resourceManagement.read().toString(); String read = resourceManagement.read().toString();
HostingNode readHN = ElementMapper.unmarshal(HostingNode.class, read); HostingNode readHN = ElementMapper.unmarshal(HostingNode.class, read);
logger.debug("Read {} {}", HostingNode.NAME, readHN); logger.debug("Read {} {}", HostingNode.NAME, readHN);
Assert.assertTrue(hnUUID.compareTo(readHN.getHeader().getUUID()) == 0); Assert.assertTrue(hnUUID.compareTo(readHN.getHeader().getUUID()) == 0);
resourceManagement = new ResourceManagement(); ERManagementTest.deleteResource(readHN);
resourceManagement.setUUID(hnUUID);
resourceManagement.delete();
} }
public void deleteResource() throws Exception {
UUID uuid = UUID.fromString("");
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(uuid);
//resourceManagement.removeFromContext();
resourceManagement.delete();
}
@Test @Test
public void testEService() throws JsonParseException, JsonMappingException, public void testEService() throws Exception {
IOException, ResourceRegistryException, URISyntaxException { EService eService = ElementMapper.unmarshal(EService.class, ESERVICE);
eService = ERManagementTest.createResource(eService);
ResourceManagement resourceManagement = new ResourceManagement(); try {
resourceManagement.setElementType(EService.NAME); UUID eServiceUUID = eService.getHeader().getUUID();
resourceManagement.setJson(ESERVICE);
String json = resourceManagement.create(); ResourceManagement resourceManagement = ERManagementTest.getResourceManagement(eService);
EService eService = ElementMapper.unmarshal(EService.class, json); String read = resourceManagement.read().toString();
logger.debug("Created {} {}", EService.NAME, eService); EService readEService = ElementMapper.unmarshal(EService.class, read);
UUID eServiceUUID = eService.getHeader().getUUID();
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID);
String read = resourceManagement.read().toString();
logger.debug("Read {} {}", EService.NAME, read);
EService readEService = ElementMapper.unmarshal(EService.class, read);
Assert.assertTrue(eServiceUUID.compareTo(readEService.getHeader()
.getUUID()) == 0);
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID);
resourceManagement.delete();
Assert.assertTrue(eServiceUUID.compareTo(readEService.getHeader()
.getUUID()) == 0);
}finally {
ERManagementTest.deleteResource(eService);
}
} }
public static final String MEMORY_TYPE = "memoryType"; public static final String MEMORY_TYPE = "memoryType";