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;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
@ -16,8 +13,6 @@ import java.util.List;
import java.util.Map;
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.informationsystem.base.reference.Element;
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.IsRelatedTo;
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.utils.Utility;
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.ResourceManagement;
@ -286,7 +281,7 @@ public class ERManagementTest extends ContextTest {
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());
checkHeader(resource, gotResource);
@ -306,19 +301,31 @@ public class ERManagementTest extends ContextTest {
}
public static EService createEService() throws Exception {
EService eService = ERManagementTest.instantiateValidEService();
public static <R extends Resource> ResourceManagement getResourceManagement(R r) throws Exception {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
resourceManagement.setElementType(Utility.getTypeName(r));
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();
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 {
@ -334,17 +341,7 @@ public class ERManagementTest extends ContextTest {
propagationConstraint);
hostingNode.attachResource(activates);
}
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;
return createResource(hostingNode);
}
public static Map<String, Resource> createHostingNodeAndEService() throws Exception {
@ -359,6 +356,13 @@ public class ERManagementTest extends ContextTest {
return map;
}
public static <R extends Resource> void deleteResource(R r) throws Exception {
if(r!=null) {
ResourceManagement resourceManagement = getResourceManagement(r);
resourceManagement.delete();
}
}
@Test
public void testCreateEService() throws Exception {
@ -366,12 +370,7 @@ public class ERManagementTest extends ContextTest {
try {
eService = createEService();
}finally {
if(eService!=null) {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setUUID(eService.getHeader().getUUID());
resourceManagement.delete();
}
deleteResource(eService);
}
}
@ -402,12 +401,7 @@ public class ERManagementTest extends ContextTest {
try {
hostingNode = createHostingNode();
}finally {
if(hostingNode!=null) {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(HostingNode.NAME);
resourceManagement.setUUID(hostingNode.getHeader().getUUID());
resourceManagement.delete();
}
deleteResource(hostingNode);
}
}
@ -415,105 +409,98 @@ public class ERManagementTest extends ContextTest {
@Test
public void testCreateHostingNodeAndEService() throws Exception {
Map<String, Resource> map = ERManagementTest.createHostingNodeAndEService();
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(map.get(EService.NAME).getHeader().getUUID());
resourceManagement.delete();
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(map.get(HostingNode.NAME).getHeader().getUUID());
resourceManagement.delete();
deleteResource(map.get(EService.NAME));
deleteResource(map.get(HostingNode.NAME));
}
@Test
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);
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
ConsistsOf<EService, CPUFacet> consistsOf = new ConsistsOfImpl<EService, CPUFacet>(createdEService, cpuFacet);
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(ConsistsOf.NAME);
consistsOfManagement.setJson(ElementMapper.marshal(consistsOf));
String createdConsistsOfString = consistsOfManagement.create();
@SuppressWarnings("unchecked")
ConsistsOf<EService, CPUFacet> createdConsistsOf = ElementMapper.unmarshal(ConsistsOf.class, createdConsistsOfString);
CPUFacet createdCpuFacet = createdConsistsOf.getTarget();
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
FacetManagement facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
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);
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
readCpuFacet.setVendor(newVendor);
readCpuFacet.setClockSpeed(newClockSpeed);
String additionPropertyKey = "My";
String additionPropertyValue = "Test";
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
facetManagement.setJson(ElementMapper.marshal(readCpuFacet));
String updatedJson = facetManagement.update();
CPUFacet updatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, updatedJson);
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.setUUID(uuid);
String readUpdatedJson = facetManagement.read().toString();
CPUFacet readUpdatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readUpdatedJson);
logger.debug("Read Updated:\nRaw Json : {}\nUnmarshalled : {}", readUpdatedJson, readUpdatedCpuFacet);
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();
try {
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
ConsistsOf<EService, CPUFacet> consistsOf = new ConsistsOfImpl<EService, CPUFacet>(eService, cpuFacet);
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
consistsOfManagement.setElementType(Utility.getTypeName(consistsOf));
consistsOfManagement.setJson(ElementMapper.marshal(consistsOf));
String createdConsistsOfString = consistsOfManagement.create();
@SuppressWarnings("unchecked")
ConsistsOf<EService, CPUFacet> createdConsistsOf = ElementMapper.unmarshal(ConsistsOf.class, createdConsistsOfString);
CPUFacet createdCpuFacet = createdConsistsOf.getTarget();
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed()) == 0);
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
Assert.assertTrue(cpuFacet.getVendor().compareTo(createdCpuFacet.getVendor()) == 0);
UUID uuid = createdCpuFacet.getHeader().getUUID();
FacetManagement facetManagement = new FacetManagement();
facetManagement.setElementType(Utility.getTypeName(createdCpuFacet));
facetManagement.setUUID(uuid);
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);
String newVendor = "Intel";
String newClockSpeed = "2 GHz";
readCpuFacet.setVendor(newVendor);
readCpuFacet.setClockSpeed(newClockSpeed);
String additionPropertyKey = "My";
String additionPropertyValue = "Test";
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
facetManagement = new FacetManagement();
facetManagement.setElementType(Utility.getTypeName(readCpuFacet));
facetManagement.setUUID(uuid);
facetManagement.setJson(ElementMapper.marshal(readCpuFacet));
String updatedJson = facetManagement.update();
CPUFacet updatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, updatedJson);
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.setElementType(Utility.getTypeName(updatedCpuFacet));
facetManagement.setUUID(uuid);
String readUpdatedJson = facetManagement.read().toString();
CPUFacet readUpdatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readUpdatedJson);
logger.debug("Read Updated:\nRaw Json : {}\nUnmarshalled : {}", readUpdatedJson, readUpdatedCpuFacet);
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.setElementType(Utility.getTypeName(readCpuFacet));
facetManagement.setUUID(uuid);
facetManagement.delete();
} finally {
deleteResource(eService);
}
}
@Test
@ -550,16 +537,7 @@ public class ERManagementTest extends ContextTest {
String marshalled = ElementMapper.marshal(configuration);
logger.debug(marshalled);
ResourceManagement resourceManagement = new ResourceManagement();
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);
Configuration createdConfiguration = createResource(configuration);
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(((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);
for (Resource r : resourceList) {
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(r.getHeader().getUUID());
resourceManagement.delete();
deleteResource(r);
}
}
@ -799,55 +775,47 @@ public class ERManagementTest extends ContextTest {
resourceManagement.delete();
}
public static final String TEST_RESOURCE = "test-resource.json";
// @Test
public void testUpdateResourceFromFile()
throws JsonParseException, JsonMappingException, IOException, ResourceRegistryException {
File file = new File("src/test/resources/" + TEST_RESOURCE);
logger.debug("{}", file.getAbsolutePath());
FileInputStream fileInputStream = new FileInputStream(file);
EService eService = ElementMapper.unmarshal(EService.class, fileInputStream);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID());
resourceManagement.setJson(ElementMapper.marshal(eService));
resourceManagement.update();
}
// public static final String TEST_RESOURCE = "test-resource.json";
//
// // @Test
// public void testUpdateResourceFromFile()
// throws JsonParseException, JsonMappingException, IOException, ResourceRegistryException {
// File file = new File("src/test/resources/" + TEST_RESOURCE);
//
// logger.debug("{}", file.getAbsolutePath());
//
// FileInputStream fileInputStream = new FileInputStream(file);
// EService eService = ElementMapper.unmarshal(EService.class, fileInputStream);
//
// ResourceManagement resourceManagement = new ResourceManagement();
// resourceManagement.setUUID(eService.getHeader().getUUID());
// resourceManagement.setJson(ElementMapper.marshal(eService));
//
// resourceManagement.update();
//
// }
@Test
public void testCreateUpdateDeleteEService() throws Exception {
EService eService = ERManagementTest.instantiateValidEService();
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";
eService.getFacets(SoftwareFacet.class).get(0).setVersion(newVersion);
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID());
resourceManagement.setJson(ElementMapper.marshal(eService));
json = resourceManagement.update();
logger.trace("Updated {}", json);
eService = ElementMapper.unmarshal(EService.class, json);
Assert.assertTrue(eService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo(newVersion) == 0);
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID());
resourceManagement.delete();
public void testUpdateFacetValue() throws Exception {
EService eService =null;
try {
eService = createEService();
final String newVersion = "1.2.0";
eService.getFacets(SoftwareFacet.class).get(0).setVersion(newVersion);
ResourceManagement resourceManagement = getResourceManagement(eService);
String json = resourceManagement.update();
EService updatedEService = ElementMapper.unmarshal(EService.class, json);
checkResource(eService, updatedEService);
Assert.assertTrue(updatedEService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo(newVersion) == 0);
}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.api.exceptions.ResourceRegistryException;
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.ResourceManagement;
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);
runningPlugin.addFacet(isIdentifiedBy);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(RunningPlugin.NAME);
resourceManagement.setJson(ElementMapper.marshal(runningPlugin));
resourceManagement.create();
ERManagementTest.createResource(runningPlugin);
}
@Test(expected = ResourceRegistryException.class)
@ -153,50 +150,36 @@ public class InvalidInstancesTest extends ContextTest {
logger.debug("Created : {}", json);
} finally {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eService.getHeader().getUUID());
resourceManagement.delete();
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNode.getHeader().getUUID());
resourceManagement.delete();
ERManagementTest.deleteResource(eService);
ERManagementTest.deleteResource(hostingNode);
}
}
@Test(expected = SchemaViolationException.class)
public void testCreateEServiceAndDeleteRequiredConsistsOf() throws Exception {
EService eService = ERManagementTest.instantiateValidEService();
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());
EService eService = null;
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();
}finally {
resourceManagement.delete();
ERManagementTest.deleteResource(eService);
}
}
@Test(expected = SchemaViolationException.class)
public void testCreateEServiceAndDeleteRequiredFacet() throws Exception {
EService eService = ERManagementTest.instantiateValidEService();
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
String createEServiceString = resourceManagement.create();
EService createEService = ElementMapper.unmarshal(EService.class, createEServiceString);
EService eService = ERManagementTest.createEService();
@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());
@ -209,7 +192,7 @@ public class InvalidInstancesTest extends ContextTest {
try {
facetManagement.delete();
}finally {
resourceManagement.delete();
ERManagementTest.deleteResource(eService);
}
}
@ -240,13 +223,8 @@ public class InvalidInstancesTest extends ContextTest {
consistsOfManagement.create();
throw new Exception("A ConsistsOf has been created between two resoures. This should not happen");
} finally {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID);
resourceManagement.delete();
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNodeUUID);
resourceManagement.delete();
ERManagementTest.deleteResource(map.get(EService.NAME));
ERManagementTest.deleteResource(map.get(HostingNode.NAME));
}
}

View File

@ -33,8 +33,6 @@ import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
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.PropagationConstraintImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
@ -92,72 +90,39 @@ public class SmartgearResourcesTest extends ContextTest {
@Test
public void testHostingNode() throws JsonParseException,
JsonMappingException, IOException, ResourceRegistryException, URISyntaxException {
HostingNode hostingNode = ElementMapper.unmarshal(HostingNode.class,
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);
public void testHostingNode() throws Exception {
HostingNode hostingNode = ElementMapper.unmarshal(HostingNode.class, HOSTING_NODE);
hostingNode = ERManagementTest.createResource(hostingNode);
UUID hnUUID = hostingNode.getHeader().getUUID();
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hnUUID);
ResourceManagement resourceManagement = ERManagementTest.getResourceManagement(hostingNode);
String read = resourceManagement.read().toString();
HostingNode readHN = ElementMapper.unmarshal(HostingNode.class, read);
logger.debug("Read {} {}", HostingNode.NAME, readHN);
Assert.assertTrue(hnUUID.compareTo(readHN.getHeader().getUUID()) == 0);
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hnUUID);
resourceManagement.delete();
ERManagementTest.deleteResource(readHN);
}
public void deleteResource() throws Exception {
UUID uuid = UUID.fromString("");
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(uuid);
//resourceManagement.removeFromContext();
resourceManagement.delete();
}
@Test
public void testEService() throws JsonParseException, JsonMappingException,
IOException, ResourceRegistryException, URISyntaxException {
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);
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();
public void testEService() throws Exception {
EService eService = ElementMapper.unmarshal(EService.class, ESERVICE);
eService = ERManagementTest.createResource(eService);
try {
UUID eServiceUUID = eService.getHeader().getUUID();
ResourceManagement resourceManagement = ERManagementTest.getResourceManagement(eService);
String read = resourceManagement.read().toString();
EService readEService = ElementMapper.unmarshal(EService.class, read);
Assert.assertTrue(eServiceUUID.compareTo(readEService.getHeader()
.getUUID()) == 0);
}finally {
ERManagementTest.deleteResource(eService);
}
}
public static final String MEMORY_TYPE = "memoryType";