Improving tests
This commit is contained in:
parent
8cec58eae8
commit
b37cbb0020
|
@ -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();
|
|
||||||
cpuFacet.setClockSpeed("1 GHz");
|
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
||||||
cpuFacet.setModel("Opteron");
|
consistsOfManagement.setElementType(Utility.getTypeName(consistsOf));
|
||||||
cpuFacet.setVendor("AMD");
|
consistsOfManagement.setJson(ElementMapper.marshal(consistsOf));
|
||||||
|
String createdConsistsOfString = consistsOfManagement.create();
|
||||||
ConsistsOf<EService, CPUFacet> consistsOf = new ConsistsOfImpl<EService, CPUFacet>(createdEService, cpuFacet);
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
ConsistsOfManagement consistsOfManagement = new ConsistsOfManagement();
|
ConsistsOf<EService, CPUFacet> createdConsistsOf = ElementMapper.unmarshal(ConsistsOf.class, createdConsistsOfString);
|
||||||
consistsOfManagement.setElementType(ConsistsOf.NAME);
|
|
||||||
consistsOfManagement.setJson(ElementMapper.marshal(consistsOf));
|
CPUFacet createdCpuFacet = createdConsistsOf.getTarget();
|
||||||
String createdConsistsOfString = consistsOfManagement.create();
|
|
||||||
|
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(createdCpuFacet.getClockSpeed()) == 0);
|
||||||
@SuppressWarnings("unchecked")
|
Assert.assertTrue(cpuFacet.getModel().compareTo(createdCpuFacet.getModel()) == 0);
|
||||||
ConsistsOf<EService, CPUFacet> createdConsistsOf = ElementMapper.unmarshal(ConsistsOf.class, createdConsistsOfString);
|
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);
|
||||||
FacetManagement facetManagement = new FacetManagement();
|
logger.debug("Read:\nRaw Json : {}\nUnmarshalled : {}", readJson, readCpuFacet);
|
||||||
facetManagement.setUUID(uuid);
|
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0);
|
||||||
|
Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0);
|
||||||
String readJson = facetManagement.read().toString();
|
Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0);
|
||||||
CPUFacet readCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readJson);
|
Assert.assertTrue(uuid.compareTo(readCpuFacet.getHeader().getUUID()) == 0);
|
||||||
logger.debug("Read:\nRaw Json : {}\nUnmarshalled : {}", readJson, readCpuFacet);
|
|
||||||
Assert.assertTrue(cpuFacet.getClockSpeed().compareTo(readCpuFacet.getClockSpeed()) == 0);
|
String newVendor = "Intel";
|
||||||
Assert.assertTrue(cpuFacet.getModel().compareTo(readCpuFacet.getModel()) == 0);
|
String newClockSpeed = "2 GHz";
|
||||||
Assert.assertTrue(cpuFacet.getVendor().compareTo(readCpuFacet.getVendor()) == 0);
|
readCpuFacet.setVendor(newVendor);
|
||||||
Assert.assertTrue(uuid.compareTo(readCpuFacet.getHeader().getUUID()) == 0);
|
readCpuFacet.setClockSpeed(newClockSpeed);
|
||||||
|
|
||||||
String newVendor = "Intel";
|
String additionPropertyKey = "My";
|
||||||
String newClockSpeed = "2 GHz";
|
String additionPropertyValue = "Test";
|
||||||
readCpuFacet.setVendor(newVendor);
|
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
|
||||||
readCpuFacet.setClockSpeed(newClockSpeed);
|
|
||||||
|
facetManagement = new FacetManagement();
|
||||||
String additionPropertyKey = "My";
|
facetManagement.setElementType(Utility.getTypeName(readCpuFacet));
|
||||||
String additionPropertyValue = "Test";
|
facetManagement.setUUID(uuid);
|
||||||
readCpuFacet.setAdditionalProperty(additionPropertyKey, additionPropertyValue);
|
facetManagement.setJson(ElementMapper.marshal(readCpuFacet));
|
||||||
|
|
||||||
facetManagement = new FacetManagement();
|
String updatedJson = facetManagement.update();
|
||||||
facetManagement.setUUID(uuid);
|
CPUFacet updatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, updatedJson);
|
||||||
facetManagement.setJson(ElementMapper.marshal(readCpuFacet));
|
logger.debug("Updated:\nRaw Json : {}\nUnmarshalled : {}", updatedJson, updatedCpuFacet);
|
||||||
|
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(newClockSpeed) == 0);
|
||||||
String updatedJson = facetManagement.update();
|
Assert.assertTrue(readCpuFacet.getModel().compareTo(updatedCpuFacet.getModel()) == 0);
|
||||||
CPUFacet updatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, updatedJson);
|
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(newVendor) == 0);
|
||||||
logger.debug("Updated:\nRaw Json : {}\nUnmarshalled : {}", updatedJson, updatedCpuFacet);
|
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
|
||||||
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(newClockSpeed) == 0);
|
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
|
||||||
Assert.assertTrue(readCpuFacet.getModel().compareTo(updatedCpuFacet.getModel()) == 0);
|
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
|
||||||
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(newVendor) == 0);
|
String user = AuthorizationProvider.instance.get().getClient().getId();
|
||||||
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
|
Assert.assertTrue(updatedCpuFacet.getHeader().getLastUpdateBy().compareTo(user) == 0);
|
||||||
.compareTo((String) readCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
|
|
||||||
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
|
facetManagement = new FacetManagement();
|
||||||
String user = AuthorizationProvider.instance.get().getClient().getId();
|
facetManagement.setElementType(Utility.getTypeName(updatedCpuFacet));
|
||||||
Assert.assertTrue(updatedCpuFacet.getHeader().getLastUpdateBy().compareTo(user) == 0);
|
facetManagement.setUUID(uuid);
|
||||||
|
|
||||||
facetManagement = new FacetManagement();
|
String readUpdatedJson = facetManagement.read().toString();
|
||||||
facetManagement.setUUID(uuid);
|
CPUFacet readUpdatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readUpdatedJson);
|
||||||
|
logger.debug("Read Updated:\nRaw Json : {}\nUnmarshalled : {}", readUpdatedJson, readUpdatedCpuFacet);
|
||||||
String readUpdatedJson = facetManagement.read().toString();
|
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(readUpdatedCpuFacet.getClockSpeed()) == 0);
|
||||||
CPUFacet readUpdatedCpuFacet = ElementMapper.unmarshal(CPUFacet.class, readUpdatedJson);
|
Assert.assertTrue(updatedCpuFacet.getModel().compareTo(readUpdatedCpuFacet.getModel()) == 0);
|
||||||
logger.debug("Read Updated:\nRaw Json : {}\nUnmarshalled : {}", readUpdatedJson, readUpdatedCpuFacet);
|
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0);
|
||||||
Assert.assertTrue(updatedCpuFacet.getClockSpeed().compareTo(readUpdatedCpuFacet.getClockSpeed()) == 0);
|
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
|
||||||
Assert.assertTrue(updatedCpuFacet.getModel().compareTo(readUpdatedCpuFacet.getModel()) == 0);
|
.compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
|
||||||
Assert.assertTrue(updatedCpuFacet.getVendor().compareTo(readUpdatedCpuFacet.getVendor()) == 0);
|
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
|
||||||
Assert.assertTrue(((String) updatedCpuFacet.getAdditionalProperty(additionPropertyKey))
|
|
||||||
.compareTo((String) readUpdatedCpuFacet.getAdditionalProperty(additionPropertyKey)) == 0);
|
facetManagement = new FacetManagement();
|
||||||
Assert.assertTrue(uuid.compareTo(updatedCpuFacet.getHeader().getUUID()) == 0);
|
facetManagement.setElementType(Utility.getTypeName(readCpuFacet));
|
||||||
|
facetManagement.setUUID(uuid);
|
||||||
facetManagement = new FacetManagement();
|
|
||||||
facetManagement.setUUID(uuid);
|
facetManagement.delete();
|
||||||
|
} finally {
|
||||||
facetManagement.delete();
|
deleteResource(eService);
|
||||||
|
}
|
||||||
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 {
|
||||||
ResourceManagement resourceManagement = new ResourceManagement();
|
eService = createEService();
|
||||||
resourceManagement.setElementType(EService.NAME);
|
|
||||||
resourceManagement.setJson(ElementMapper.marshal(eService));
|
final String newVersion = "1.2.0";
|
||||||
String json = resourceManagement.create();
|
eService.getFacets(SoftwareFacet.class).get(0).setVersion(newVersion);
|
||||||
|
|
||||||
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);
|
|
||||||
|
checkResource(eService, updatedEService);
|
||||||
resourceManagement = new ResourceManagement();
|
|
||||||
resourceManagement.setUUID(eService.getHeader().getUUID());
|
Assert.assertTrue(updatedEService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo(newVersion) == 0);
|
||||||
resourceManagement.setJson(ElementMapper.marshal(eService));
|
|
||||||
|
}finally {
|
||||||
json = resourceManagement.update();
|
deleteResource(eService);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
|
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";
|
public static final String MEMORY_TYPE = "memoryType";
|
||||||
|
|
Loading…
Reference in New Issue