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,36 +409,24 @@ 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();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
String createdEServiceString = resourceManagement.create();
EService createdEService = ElementMapper.unmarshal(EService.class, createdEServiceString);
try {
CPUFacet cpuFacet = new CPUFacetImpl(); CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz"); cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron"); cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD"); cpuFacet.setVendor("AMD");
ConsistsOf<EService, CPUFacet> consistsOf = new ConsistsOfImpl<EService, CPUFacet>(createdEService, cpuFacet); ConsistsOf<EService, CPUFacet> consistsOf = new ConsistsOfImpl<EService, CPUFacet>(eService, cpuFacet);
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement(); ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(ConsistsOf.NAME); consistsOfManagement.setElementType(Utility.getTypeName(consistsOf));
consistsOfManagement.setJson(ElementMapper.marshal(consistsOf)); consistsOfManagement.setJson(ElementMapper.marshal(consistsOf));
String createdConsistsOfString = consistsOfManagement.create(); String createdConsistsOfString = consistsOfManagement.create();
@ -460,6 +442,7 @@ public class ERManagementTest extends ContextTest {
UUID uuid = createdCpuFacet.getHeader().getUUID(); UUID uuid = createdCpuFacet.getHeader().getUUID();
FacetManagement facetManagement = new FacetManagement(); FacetManagement facetManagement = new FacetManagement();
facetManagement.setElementType(Utility.getTypeName(createdCpuFacet));
facetManagement.setUUID(uuid); facetManagement.setUUID(uuid);
String readJson = facetManagement.read().toString(); String readJson = facetManagement.read().toString();
@ -480,6 +463,7 @@ public class ERManagementTest extends ContextTest {
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue); readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
facetManagement = new FacetManagement(); facetManagement = new FacetManagement();
facetManagement.setElementType(Utility.getTypeName(readCpuFacet));
facetManagement.setUUID(uuid); facetManagement.setUUID(uuid);
facetManagement.setJson(ElementMapper.marshal(readCpuFacet)); facetManagement.setJson(ElementMapper.marshal(readCpuFacet));
@ -496,6 +480,7 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(updatedCpuFacet.getHeader().getLastUpdateBy().compareTo(user) == 0); Assert.assertTrue(updatedCpuFacet.getHeader().getLastUpdateBy().compareTo(user) == 0);
facetManagement = new FacetManagement(); facetManagement = new FacetManagement();
facetManagement.setElementType(Utility.getTypeName(updatedCpuFacet));
facetManagement.setUUID(uuid); facetManagement.setUUID(uuid);
String readUpdatedJson = facetManagement.read().toString(); String readUpdatedJson = facetManagement.read().toString();
@ -509,11 +494,13 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0); Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
facetManagement = new FacetManagement(); facetManagement = new FacetManagement();
facetManagement.setElementType(Utility.getTypeName(readCpuFacet));
facetManagement.setUUID(uuid); facetManagement.setUUID(uuid);
facetManagement.delete(); facetManagement.delete();
} finally {
resourceManagement.delete(); deleteResource(eService);
}
} }
@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();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
String json = resourceManagement.create();
logger.trace("Created {}", json);
eService = ElementMapper.unmarshal(EService.class, json);
final String newVersion = "1.2.0"; final String newVersion = "1.2.0";
eService.getFacets(SoftwareFacet.class).get(0).setVersion(newVersion); eService.getFacets(SoftwareFacet.class).get(0).setVersion(newVersion);
resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = getResourceManagement(eService);
resourceManagement.setUUID(eService.getHeader().getUUID());
resourceManagement.setJson(ElementMapper.marshal(eService));
json = resourceManagement.update(); String json = resourceManagement.update();
logger.trace("Updated {}", json); EService updatedEService = ElementMapper.unmarshal(EService.class, json);
eService = ElementMapper.unmarshal(EService.class, json);
Assert.assertTrue(eService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo(newVersion) == 0); checkResource(eService, updatedEService);
resourceManagement = new ResourceManagement(); Assert.assertTrue(updatedEService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo(newVersion) == 0);
resourceManagement.setUUID(eService.getHeader().getUUID());
resourceManagement.delete(); }finally {
deleteResource(eService);
}
} }
} }

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(); try {
resourceManagement.setElementType(EService.NAME); eService = ERManagementTest.createEService();
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.setElementType(IsIdentifiedBy.NAME);
consistsOfManagement.setUUID(isIdentifiedBy.getHeader().getUUID());
try { 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();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ESERVICE);
String json = resourceManagement.create();
EService eService = ElementMapper.unmarshal(EService.class, json);
logger.debug("Created {} {}", EService.NAME, eService);
try {
UUID eServiceUUID = eService.getHeader().getUUID(); UUID eServiceUUID = eService.getHeader().getUUID();
resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = ERManagementTest.getResourceManagement(eService);
resourceManagement.setUUID(eServiceUUID);
String read = resourceManagement.read().toString(); String read = resourceManagement.read().toString();
logger.debug("Read {} {}", EService.NAME, read);
EService readEService = ElementMapper.unmarshal(EService.class, read); EService readEService = ElementMapper.unmarshal(EService.class, read);
Assert.assertTrue(eServiceUUID.compareTo(readEService.getHeader() Assert.assertTrue(eServiceUUID.compareTo(readEService.getHeader()
.getUUID()) == 0); .getUUID()) == 0);
}finally {
resourceManagement = new ResourceManagement(); ERManagementTest.deleteResource(eService);
resourceManagement.setUUID(eServiceUUID); }
resourceManagement.delete();
} }
public static final String MEMORY_TYPE = "memoryType"; public static final String MEMORY_TYPE = "memoryType";