Fixing tests

This commit is contained in:
Luca Frosini 2021-03-08 16:56:35 +01:00
parent cdd6c121e1
commit df3d81d2bd
7 changed files with 62 additions and 420 deletions

View File

@ -239,10 +239,6 @@ public class ERManagementTest extends ContextTest {
Assert.assertTrue(lastUpdateBy.compareTo(HeaderUtility.getUser())==0); Assert.assertTrue(lastUpdateBy.compareTo(HeaderUtility.getUser())==0);
} }
if(header.getCreationTime()!=null) {
Assert.assertTrue(creationTime.equals(header.getCreationTime()));
}
if(header.getLastUpdateTime()!=null) { if(header.getLastUpdateTime()!=null) {
Assert.assertTrue(lastUpdateTime.after(header.getLastUpdateTime())); Assert.assertTrue(lastUpdateTime.after(header.getLastUpdateTime()));
} }
@ -355,6 +351,11 @@ public class ERManagementTest extends ContextTest {
return createResource(hostingNode); return createResource(hostingNode);
} }
public static Configuration createConfiguration() throws Exception {
Configuration configuration = ERManagementTest.instantiateValidConfiguration();
return createResource(configuration);
}
public static Map<String, Resource> createHostingNodeAndEService() throws Exception { public static Map<String, Resource> createHostingNodeAndEService() throws Exception {
Map<String, Resource> map = new HashMap<>(); Map<String, Resource> map = new HashMap<>();

View File

@ -10,6 +10,7 @@ import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf; 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.entity.resource.ResourceAlreadyPresentException;
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.api.utils.Utility;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
@ -38,33 +39,22 @@ import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class InvalidInstancesTest extends ContextTest { public class InvalidOperationTest extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(InvalidInstancesTest.class); private static Logger logger = LoggerFactory.getLogger(InvalidOperationTest.class);
public static final String ESERVICE = SmartgearResourcesTest.ESERVICE; public static final String ACTIVATES = "{\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascade\"},\"@class\":\"Activates\",\"source\":{\"header\":{\"@class\":\"Header\",\"uuid\":\"CONFIGURATION_UUID\"},\"@class\":\"Configuration\"},\"target\":{\"header\":{\"@class\":\"Header\",\"uuid\":\"ESERVICE_UUID\"},\"@class\":\"EService\"}}";
public static final String ACTIVATES = "{\"header\": {\"@class\": \"Header\",\"creator\": \"luca.frosini\",\"creationTime\": \"2021-02-23 16:45:58.358 +0100\",\"modifiedBy\": \"luca.frosini\",\"uuid\": \"83e9ece1-326c-4d24-a515-0fc6e68f31ef\",\"lastUpdateTime\": \"2021-02-23 16:45:58.358 +0100\"},\"propagationConstraint\": {\"@class\": \"PropagationConstraint\",\"add\": \"propagate\",\"remove\": \"cascade\"},\"@class\": \"Activates\",\"@superClasses\": [\"IsRelatedTo\"],\"source\": {\"header\": {\"@class\": \"Header\",\"creator\": \"luca.frosini\",\"creationTime\": \"2021-02-23 16:45:58.297 +0100\",\"modifiedBy\": \"luca.frosini\",\"uuid\": \"bf665e49-7c54-4984-bafe-a021757a7423\",\"lastUpdateTime\": \"2021-02-23 16:45:58.297 +0100\"},\"@class\": \"Configuration\"},\"target\": {\"header\": {\"@class\": \"Header\",\"creator\": \"luca.frosini\",\"creationTime\": \"2021-02-23 16:45:58.128 +0100\",\"modifiedBy\": \"luca.frosini\",\"uuid\": \"3ace4bd0-e5cd-49a3-97a8-a0a9468ce6d4\",\"lastUpdateTime\": \"2021-02-23 16:45:58.128 +0100\"},\"@class\": \"EService\"}}";
public static final String CONFIGURATION = "{\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.382 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"bf665e49-7c54-4984-bafe-a021757a7423\",\"lastUpdateTime\":\"2021-02-23 16:45:58.382 +0100\"},\"@class\":\"Configuration\",\"@superClasses\":[\"ConfigurationTemplate\",\"GCubeResource\",\"Resource\"],\"consistsOf\":[{\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.378 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"2233f303-497f-433d-9338-6ca16de34c1a\",\"lastUpdateTime\":\"2021-02-23 16:45:58.378 +0100\"},\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascadeWhenOrphan\"},\"@class\":\"IsIdentifiedBy\",\"@superClasses\":[\"ConsistsOf\"],\"source\":{\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.382 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"bf665e49-7c54-4984-bafe-a021757a7423\",\"lastUpdateTime\":\"2021-02-23 16:45:58.382 +0100\"},\"@class\":\"Configuration\",\"@superClasses\":[\"ConfigurationTemplate\",\"GCubeResource\",\"Resource\"]},\"target\":{\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.375 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"5efc4c1f-f784-4682-a694-896bd7a3f321\",\"lastUpdateTime\":\"2021-02-23 16:45:58.375 +0100\"},\"type\":\"STRING\",\"persistent\":\"false\",\"value\":\"TEST\",\"@class\":\"IdentifierFacet\",\"@superClasses\":[\"ConsistsOf\"]}},{\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.381 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"15055c47-32a1-412c-b6d8-c0d4c831cb95\",\"lastUpdateTime\":\"2021-02-23 16:45:58.381 +0100\"},\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"add\":\"propagate\",\"remove\":\"cascadeWhenOrphan\"},\"@class\":\"ConsistsOf\",\"@superClasses\":[\"ConsistsOf\"],\"source\":{\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.382 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"bf665e49-7c54-4984-bafe-a021757a7423\",\"lastUpdateTime\":\"2021-02-23 16:45:58.382 +0100\"},\"@class\":\"Configuration\",\"@superClasses\":[\"ConfigurationTemplate\",\"GCubeResource\",\"Resource\"]},\"target\":{\"name\":\"test\",\"header\":{\"@class\":\"Header\",\"creator\":\"luca.frosini\",\"creationTime\":\"2021-02-23 16:45:58.380 +0100\",\"modifiedBy\":\"luca.frosini\",\"uuid\":\"9b71f04c-6f5d-4133-87aa-f37445e206b6\",\"lastUpdateTime\":\"2021-02-23 16:45:58.380 +0100\"},\"value\":\"test\",\"@class\":\"SimplePropertyFacet\",\"@superClasses\":[\"ConsistsOf\"]}}]}";
public static final String ACTOR = "{\"@class\":\"Actor\",\"header\":null,\"consistsOf\":[{\"@class\":\"IsIdentifiedBy\",\"header\":null,\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"remove\":\"cascadeWhenOrphan\",\"add\":\"propagate\"},\"source\":{\"@class\":\"Actor\",\"header\":null},\"target\":{\"@class\":\"ContactFacet\",\"header\":null,\"title\":\"Dr.\",\"name\":\"Frosini\",\"middleName\":null,\"surname\":null,\"eMail\":\"luca.frosini@isti.cnr.it\"}}],\"isRelatedTo\":[]}"; public static final String ACTOR = "{\"@class\":\"Actor\",\"header\":null,\"consistsOf\":[{\"@class\":\"IsIdentifiedBy\",\"header\":null,\"propagationConstraint\":{\"@class\":\"PropagationConstraint\",\"remove\":\"cascadeWhenOrphan\",\"add\":\"propagate\"},\"source\":{\"@class\":\"Actor\",\"header\":null},\"target\":{\"@class\":\"ContactFacet\",\"header\":null,\"title\":\"Dr.\",\"name\":\"Frosini\",\"middleName\":null,\"surname\":null,\"eMail\":\"luca.frosini@isti.cnr.it\"}}],\"isRelatedTo\":[]}";
@Test(expected = SchemaViolationException.class) @Test(expected = SchemaViolationException.class)
public void createInvalidIsRealtedTo() throws Exception { public void createInvalidIsRealtedTo() throws Exception {
Configuration configuration = ERManagementTest.createConfiguration();
ResourceManagement configurationManagement = new ResourceManagement(); EService eService = ERManagementTest.createEService();
ResourceManagement eServiceManagement = new ResourceManagement();
try { try {
configurationManagement.setElementType(Configuration.NAME);
configurationManagement.setJson(CONFIGURATION);
configurationManagement.create();
eServiceManagement.setElementType(EService.NAME);
eServiceManagement.setJson(ESERVICE);
eServiceManagement.create();
/* /*
* Trying to create a relation activates between a Configuration and EService * Trying to create a relation activates between a Configuration and EService
* The creation MUST fails raising SchemaViolationException because the * The creation MUST fails raising SchemaViolationException because the
* Activates relation is between two Service * Activates relation is between two Service isntaces
* *
* The only way to try to create it is using static string because Java classes * The only way to try to create it is using static string because Java classes
* already deny to create and instance of Activates * already deny to create and instance of Activates
@ -73,15 +63,27 @@ public class InvalidInstancesTest extends ContextTest {
*/ */
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement(); IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
isRelatedToManagement.setElementType(Activates.NAME); isRelatedToManagement.setElementType(Activates.NAME);
isRelatedToManagement.setJson(ACTIVATES); String json = ACTIVATES.replace("CONFIGURATION_UUID", configuration.getHeader().getUUID().toString());
json = json.replace("ESERVICE_UUID", eService.getHeader().getUUID().toString());
isRelatedToManagement.setJson(json);
isRelatedToManagement.create(); isRelatedToManagement.create();
}finally { }finally {
configurationManagement.delete(); ERManagementTest.deleteResource(configuration);
eServiceManagement.delete(); ERManagementTest.deleteResource(eService);
} }
} }
@Test(expected = ResourceAlreadyPresentException.class)
public void testRecreate() throws Exception {
EService eService = ERManagementTest.createEService();
try {
ERManagementTest.createResource(eService);
}finally {
ERManagementTest.deleteResource(eService);
}
}
@Test(expected = SchemaViolationException.class) @Test(expected = SchemaViolationException.class)
public void testCreateStandAloneFacet() throws Exception { public void testCreateStandAloneFacet() throws Exception {
CPUFacet cpuFacet = new CPUFacetImpl(); CPUFacet cpuFacet = new CPUFacetImpl();

View File

@ -8,7 +8,6 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.base.reference.IdentifiableElement;
import org.gcube.informationsystem.context.reference.entities.Context; import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl; import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
@ -18,16 +17,11 @@ 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.resourceregistry.ContextTest; import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException; import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationAvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.RelationAvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility; import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest; import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest;
import org.gcube.informationsystem.resourceregistry.instances.SmartgearResourcesTest;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
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.IsRelatedToManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
import org.gcube.informationsystem.utils.ElementMapper; import org.gcube.informationsystem.utils.ElementMapper;
@ -170,16 +164,7 @@ public class BasicTest extends MultiContextTest {
@Test @Test
public void testCreateEServiceHostingNode() throws Exception { public void testCreateEServiceHostingNode() throws Exception {
EService eService = ERManagementTest.instantiateValidEService(); EService eService = ERManagementTest.createEService();
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
String json = resourceManagement.create();
logger.debug("Created : {}", json);
eService = ElementMapper.unmarshal(EService.class, json);
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
Map<UUID, IdentifiableElement> eServiceInstances = new HashMap<>(); Map<UUID, IdentifiableElement> eServiceInstances = new HashMap<>();
eServiceInstances.put(eService.getHeader().getUUID(), eService); eServiceInstances.put(eService.getHeader().getUUID(), eService);
@ -188,16 +173,7 @@ public class BasicTest extends MultiContextTest {
eServiceInstances.put(consistsOf.getTarget().getHeader().getUUID(), consistsOf.getTarget()); eServiceInstances.put(consistsOf.getTarget().getHeader().getUUID(), consistsOf.getTarget());
} }
HostingNode hostingNode = ERManagementTest.instantiateValidHostingNode(); HostingNode hostingNode = ERManagementTest.createHostingNode();
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 hostingNodeUUID = hostingNode.getHeader().getUUID(); UUID hostingNodeUUID = hostingNode.getHeader().getUUID();
@ -222,11 +198,9 @@ public class BasicTest extends MultiContextTest {
UUID contextUUID = ContextUtility.getCurrentSecurityContext().getUUID(); UUID contextUUID = ContextUtility.getCurrentSecurityContext().getUUID();
try { try {
resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = ERManagementTest.getResourceManagement(hostingNode);
resourceManagement.setUUID(hostingNodeUUID);
resourceManagement.read(); resourceManagement.read();
logger.debug("You should not be able to read {} with UUID {} in {} with UUID {} (i.e., {})", throw new Exception("You should not be able to read " + HostingNode.NAME + " with UUID " + hostingNodeUUID.toString() + " in " + Context.NAME + " with UUID " + contextUUID.toString()+ " (i.e., " + ContextUtility.getCurrentContextFullName() +")");
HostingNode.NAME, hostingNodeUUID.toString(), Context.NAME, contextUUID, ContextUtility.getCurrentContextFullName());
}catch (AvailableInAnotherContextException e) { }catch (AvailableInAnotherContextException e) {
// OK // OK
} }
@ -236,39 +210,21 @@ public class BasicTest extends MultiContextTest {
addToContextThenTestIfBehaveProperly(hostingNode, false, targetContextFullName); addToContextThenTestIfBehaveProperly(hostingNode, false, targetContextFullName);
resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = ERManagementTest.getResourceManagement(hostingNode);
resourceManagement.setUUID(hostingNodeUUID); String hnString = resourceManagement.read();
String hnString = resourceManagement.read().toString();
HostingNode readHN = ElementMapper.unmarshal(HostingNode.class, hnString); HostingNode readHN = ElementMapper.unmarshal(HostingNode.class, hnString);
Assert.assertTrue(readHN.getHeader().getUUID().compareTo(hostingNodeUUID) == 0); Assert.assertTrue(readHN.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
UUID eServiceUUID = eService.getHeader().getUUID(); UUID eServiceUUID = eService.getHeader().getUUID();
try { try {
resourceManagement = new ResourceManagement(); resourceManagement = ERManagementTest.getResourceManagement(eService);
resourceManagement.setUUID(eServiceUUID);
resourceManagement.read(); resourceManagement.read();
throw new Exception("You should not be able to read " + EService.NAME + " with UUID " + eServiceUUID.toString() + " in " + Context.NAME + " with UUID " + contextUUID.toString()+ " (i.e., " + ContextUtility.getCurrentContextFullName() +")");
} catch (ResourceAvailableInAnotherContextException e) { } catch (ResourceAvailableInAnotherContextException e) {
logger.debug("Resource with {} Not Found as Expected", logger.debug("Resource with {} Not Found as Expected", eServiceUUID);
eServiceUUID);
} }
/* Commented because the behavior has been changed resourceManagement = ERManagementTest.getResourceManagement(eService);
try {
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID);
resourceManagement.delete();
logger.debug("You should not be able to delete EService with UUID {}",
uuid);
throw new Exception(
"You should not be able to delete EService with UUID " + uuid);
} catch (ResourceAvailableInAnotherContextException e) {
logger.debug("Resource with {} Not Deleted as Expected",
eServiceUUID);
}
*/
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNodeUUID);
resourceManagement.delete(); resourceManagement.delete();
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
@ -280,52 +236,22 @@ public class BasicTest extends MultiContextTest {
resourceManagement = new ResourceManagement(); resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID); resourceManagement.setUUID(eServiceUUID);
resourceManagement.delete(); resourceManagement.delete();
throw new Exception("The" + EService.NAME + " with UUID " + eServiceUUID.toString() + " should be already deleted");
}catch (ResourceNotFoundException e) { }catch (ResourceNotFoundException e) {
// OK // OK
} }
} }
// @Test
public void addTest() throws ResourceNotFoundException,
ContextNotFoundException, ResourceRegistryException {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString(""));
resourceManagement.addToContext(ContextUtility.getCurrentSecurityContext().getUUID());
}
@Test @Test
public void testAddAndRemoveFromContext() throws Exception { public void testAddAndRemoveFromContext() throws Exception {
/* Creating HostingNode */ /* Creating HostingNode */
ResourceManagement resourceManagement = new ResourceManagement(); HostingNode hostingNode = ERManagementTest.createHostingNode();
resourceManagement.setElementType(HostingNode.NAME);
resourceManagement.setJson(SmartgearResourcesTest.HOSTING_NODE);
String hnJson = resourceManagement.create();
logger.debug("Created : {}", hnJson);
HostingNode hostingNode = ElementMapper.unmarshal(HostingNode.class, hnJson);
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
UUID hnUUID = hostingNode.getHeader().getUUID();
/* Creating EService */ /* Creating EService */
EService eService = ERManagementTest.createEService();
resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(SmartgearResourcesTest.ESERVICE);
String eservicejson = resourceManagement.create();
logger.debug("Created : {}", eservicejson);
EService eService = ElementMapper.unmarshal(EService.class, eservicejson);
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
UUID eServiceUUID = eService.getHeader().getUUID();
/* Creating Activates Relation */ /* Creating Activates Relation */
PropagationConstraint propagationConstraint = new PropagationConstraintImpl(); PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint propagationConstraint
.setRemoveConstraint(RemoveConstraint.cascade); .setRemoveConstraint(RemoveConstraint.cascade);
@ -341,7 +267,7 @@ public class BasicTest extends MultiContextTest {
String activatesJson = ElementMapper.marshal(activates); String activatesJson = ElementMapper.marshal(activates);
isRelatedToManagement.setJson(activatesJson); isRelatedToManagement.setJson(activatesJson);
String createdActivatesJson = isRelatedToManagement.create(); String createdActivatesJson = isRelatedToManagement.create();
logger.debug("Created : {}", createdActivatesJson);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Activates<HostingNode, EService> createdActivates = ElementMapper.unmarshal(Activates.class, createdActivatesJson); Activates<HostingNode, EService> createdActivates = ElementMapper.unmarshal(Activates.class, createdActivatesJson);
@ -350,21 +276,6 @@ public class BasicTest extends MultiContextTest {
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
/*
* resourceManagement = new ResourceManagement();
* resourceManagement.setUUID(hnUUID);
* resourceManagement.addToContext();
* resourceManagement = new ResourceManagement();
* resourceManagement.setUUID(eServiceUUID);
* resourceManagement.addToContext();
*
* This code is commented because the addToContext
* on relation enforce addToContext both on source
* and target
*
*/
isRelatedToManagement = new IsRelatedToManagement(); isRelatedToManagement = new IsRelatedToManagement();
isRelatedToManagement.setUUID(activatesUUID); isRelatedToManagement.setUUID(activatesUUID);
UUID contextUUID = ContextUtility.getInstance().getSecurityContextByFullName(ALTERNATIVE_TEST_SCOPE).getUUID(); UUID contextUUID = ContextUtility.getInstance().getSecurityContextByFullName(ALTERNATIVE_TEST_SCOPE).getUUID();
@ -377,20 +288,17 @@ public class BasicTest extends MultiContextTest {
* So that I MUST be able to read HostinNode and EService * So that I MUST be able to read HostinNode and EService
*/ */
resourceManagement = new ResourceManagement(); ResourceManagement resourceManagement = ERManagementTest.getResourceManagement(hostingNode);
resourceManagement.setUUID(hnUUID);
resourceManagement.read(); resourceManagement.read();
resourceManagement = new ResourceManagement(); resourceManagement = ERManagementTest.getResourceManagement(eService);
resourceManagement.setUUID(eServiceUUID);
resourceManagement.read(); resourceManagement.read();
/* ------------------------------------------------------------------ */ /* ------------------------------------------------------------------ */
logger.debug("Setting back default scope"); logger.debug("Setting back default scope");
ContextTest.setContextByName(DEFAULT_TEST_SCOPE); ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
resourceManagement = new ResourceManagement(); resourceManagement = ERManagementTest.getResourceManagement(hostingNode);
resourceManagement.setUUID(hnUUID);
resourceManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID()); resourceManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
Map<UUID,JsonNode> affectedInstances = resourceManagement.getAffectedInstances(); Map<UUID,JsonNode> affectedInstances = resourceManagement.getAffectedInstances();
@ -402,11 +310,10 @@ public class BasicTest extends MultiContextTest {
* I MUST not be able to read Activates relation and EService * I MUST not be able to read Activates relation and EService
*/ */
resourceManagement = new ResourceManagement(); resourceManagement = ERManagementTest.getResourceManagement(eService);
resourceManagement.setUUID(eServiceUUID);
try { try {
resourceManagement.read(); resourceManagement.read();
String error = String.format("{} with UUID {} should not be visible.", EService.NAME, eServiceUUID); String error = String.format("{} with UUID {} should not be visible.", EService.NAME, eService.getHeader().getUUID());
logger.trace(error); logger.trace(error);
throw new Exception(error); throw new Exception(error);
}catch (ResourceAvailableInAnotherContextException e) { }catch (ResourceAvailableInAnotherContextException e) {
@ -430,29 +337,8 @@ public class BasicTest extends MultiContextTest {
ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE); ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE);
// TODO checks here // TODO checks here
resourceManagement = new ResourceManagement(); resourceManagement = ERManagementTest.getResourceManagement(hostingNode);
resourceManagement.setUUID(hnUUID);
resourceManagement.delete(); resourceManagement.delete();
} }
// @Test
public void testGetInstanceContexts() throws ObjectNotFound, Exception {
String type = "HostingNode";
String instanceId = "f0460614-9ffb-4ecd-bf52-d91e8d81d604";
@SuppressWarnings("rawtypes")
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
UUID uuid = null;
try {
uuid = UUID.fromString(instanceId);
} catch(Exception e) {
throw new ResourceRegistryException(e);
}
erManagement.setUUID(uuid);
String contexts = erManagement.getContexts();
logger.debug("{}", contexts);
}
} }

View File

@ -11,8 +11,9 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra
import org.gcube.informationsystem.resourceregistry.ContextTest; import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache; import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.utils.Utility; import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
import org.gcube.informationsystem.resourceregistry.instances.SmartgearResourcesTest; import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest;
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.IsRelatedToManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
@ -38,28 +39,13 @@ public class ComplexTest extends MultiContextTest {
contextCache.setContextCacheRenewal(contextCacheRenewal); contextCache.setContextCacheRenewal(contextCacheRenewal);
/* Creating HostingNode */ /* Creating HostingNode */
ResourceManagement hostingNodeManagement = new ResourceManagement(); HostingNode hostingNode = ERManagementTest.createHostingNode();
hostingNodeManagement.setElementType(HostingNode.NAME);
hostingNodeManagement.setJson(SmartgearResourcesTest.HOSTING_NODE);
String hnJson = hostingNodeManagement.create();
logger.debug("Created : {}", hnJson);
HostingNode hostingNode = ElementMapper.unmarshal(HostingNode.class, hnJson);
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNode);
/* Creating EService */ /* Creating EService */
ResourceManagement eServiceManagement = new ResourceManagement(); EService eService = ERManagementTest.createEService();
eServiceManagement.setElementType(EService.NAME);
eServiceManagement.setJson(SmartgearResourcesTest.ESERVICE);
String eservicejson = eServiceManagement.create();
logger.debug("Created : {}", eservicejson);
EService eService = ElementMapper.unmarshal(EService.class, eservicejson);
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
/* Creating Activates Relation */ /* Creating Activates Relation */
PropagationConstraint propagationConstraint = new PropagationConstraintImpl(); PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint propagationConstraint
.setRemoveConstraint(RemoveConstraint.cascade); .setRemoveConstraint(RemoveConstraint.cascade);
@ -88,10 +74,7 @@ public class ComplexTest extends MultiContextTest {
logger.debug("Switching to alternative scope"); logger.debug("Switching to alternative scope");
ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE); ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE);
hostingNodeManagement = new ResourceManagement(); ResourceManagement hostingNodeManagement = ERManagementTest.getResourceManagement(hostingNode);
hostingNodeManagement.setUUID(hostingNode.getHeader().getUUID());
hostingNodeManagement.setElementType(Utility.getTypeName(hostingNode.getClass()));
String hostingNodeContexts = hostingNodeManagement.getContexts(); String hostingNodeContexts = hostingNodeManagement.getContexts();
logger.debug("Contexts of {} with UUID {} have the following UUID {}", HostingNode.NAME, hostingNodeManagement.getUUID(), hostingNodeContexts); logger.debug("Contexts of {} with UUID {} have the following UUID {}", HostingNode.NAME, hostingNodeManagement.getUUID(), hostingNodeContexts);
@ -131,9 +114,7 @@ public class ComplexTest extends MultiContextTest {
logger.debug("Contexts of {} with UUID {} are {}", Activates.NAME, activatesManagement.getUUID(), activatesContextFullNames); logger.debug("Contexts of {} with UUID {} are {}", Activates.NAME, activatesManagement.getUUID(), activatesContextFullNames);
eServiceManagement = new ResourceManagement(); ResourceManagement eServiceManagement = ERManagementTest.getResourceManagement(eService);
eServiceManagement.setUUID(eService.getHeader().getUUID());
eServiceManagement.setElementType(Utility.getTypeName(eService.getClass()));
String eServiceContexts = eServiceManagement.getContexts(); String eServiceContexts = eServiceManagement.getContexts();
logger.debug("Contexts of {} with UUID {} have the following UUID {}", EService.NAME, eServiceManagement.getUUID(), eServiceContexts); logger.debug("Contexts of {} with UUID {} have the following UUID {}", EService.NAME, eServiceManagement.getUUID(), eServiceContexts);
Set<UUID> eServiceContextsUUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(eServiceContexts); Set<UUID> eServiceContextsUUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(eServiceContexts);
@ -144,7 +125,14 @@ public class ComplexTest extends MultiContextTest {
Assert.assertTrue(eServiceContextFullNames.size()==1); Assert.assertTrue(eServiceContextFullNames.size()==1);
logger.debug("Contexts of {} with UUID {} are {}", EService.NAME, eServiceManagement.getUUID(), eServiceContextFullNames); logger.debug("Contexts of {} with UUID {} are {}", EService.NAME, eServiceManagement.getUUID(), eServiceContextFullNames);
hostingNodeManagement.delete(); ERManagementTest.deleteResource(hostingNode);
try {
ERManagementTest.deleteResource(eService);
throw new Exception(EService.NAME + " should be already deleted giving the cascade");
}catch (ResourceNotFoundException e) {
// As expected
}
} }
} }

View File

@ -1,77 +0,0 @@
/**
*
*/
package org.gcube.informationsystem.resourceregistry.instances.multicontext;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest;
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagementUtility;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class EnhancedTest extends MultiContextTest {
private static Logger logger = LoggerFactory
.getLogger(EnhancedTest.class);
@Test
public void testNoFollows() throws Exception {
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
EService eService = ERManagementTest.instantiateValidEService();
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
String json = resourceManagement.create();
logger.debug("Created : {}", json);
eService = ElementMapper.unmarshal(EService.class, json);
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
JsonNode jsonNode = ElementMapper.getObjectMapper().readTree(json);
Map<UUID, JsonNode> expectedInstances = new HashMap<>();
expectedInstances.put(eService.getHeader().getUUID(), jsonNode);
UUID contextUUID = ContextUtility.getInstance().getSecurityContextByFullName(ALTERNATIVE_TEST_SCOPE).getUUID();
try {
ERManagementUtility.addToContextNoPropagationConstraint(expectedInstances, contextUUID, true);
}catch (ResourceRegistryException e) {
logger.debug("As expected {}", e.getMessage());
}
@SuppressWarnings("unchecked")
IsIdentifiedBy<EService, Facet> gotIsIdentifiedBy = (IsIdentifiedBy<EService, Facet>) eService.getConsistsOf(IsIdentifiedBy.class).get(0);
JsonNode gotIsIdentifiedByJsonNode = ElementMapper.getObjectMapper().readTree(ElementMapper.marshal(gotIsIdentifiedBy));
expectedInstances.put(gotIsIdentifiedBy.getHeader().getUUID(), gotIsIdentifiedByJsonNode);
try {
ERManagementUtility.addToContextNoPropagationConstraint(expectedInstances, contextUUID, true);
}catch (ResourceRegistryException e) {
// as expected
logger.debug("As expected {}", e.getMessage());
}finally {
resourceManagement.delete();
}
}
}

View File

@ -1,117 +0,0 @@
package org.gcube.informationsystem.resourceregistry.instances.multicontext;
import java.util.UUID;
import org.gcube.informationsystem.resourceregistry.ContextTest;
import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceAlreadyPresentException;
import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class RuleTest extends ContextTest {
private static Logger logger = LoggerFactory
.getLogger(RuleTest.class);
public EService createEservice() throws Exception {
EService eService = ERManagementTest.instantiateValidEService();
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(EService.NAME);
resourceManagement.setJson(ElementMapper.marshal(eService));
String json = resourceManagement.create();
logger.debug("Created : {}", json);
eService = ElementMapper.unmarshal(EService.class, json);
logger.debug("Unmarshalled {} {}", EService.NAME, eService);
return eService;
}
public UUID checkEServiceCreation(EService eService) throws Exception{
UUID eServiceUUID = eService.getHeader().getUUID();
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID);
String json = resourceManagement.read().toString();
EService readEService = ElementMapper.unmarshal(EService.class, json);
Assert.assertTrue(readEService.getHeader().getUUID().compareTo(eServiceUUID) == 0);
return eServiceUUID;
}
public UUID checkFacetCreation(EService eService) throws Exception {
UUID softwareFacetUUID = eService.getIdentificationFacets().get(0).getHeader().getUUID();
FacetManagement facetManagement = new FacetManagement();
facetManagement.setUUID(softwareFacetUUID);
String json = facetManagement.read().toString();
SoftwareFacet readSoftwareFacet = ElementMapper.unmarshal(SoftwareFacet.class, json);
Assert.assertTrue(readSoftwareFacet.getHeader().getUUID().compareTo(softwareFacetUUID) == 0);
return softwareFacetUUID;
}
@Test
public void test() throws Exception {
EService eService = createEservice();
@SuppressWarnings("unused")
UUID eServiceUUID = checkEServiceCreation(eService);
@SuppressWarnings("unused")
UUID softwareFacetUUID = checkFacetCreation(eService);
// SoftwareFacet softwareFacet = (SoftwareFacet) eService.getIdentificationFacets().get(0);
// String softwareFacetString = ElementMapper.marshal(softwareFacet);
//
// // Trying to recreate SoftwareFacet
// FacetManagement softwareFacetManagement = new FacetManagement();
// softwareFacetManagement.setElementType(SoftwareFacet.NAME);
// softwareFacetManagement.setJson(softwareFacetString);
// try{
// softwareFacetManagement.create();
// }catch (FacetAlreadyPresentException e) {
// // OK
// logger.debug("As expected {} cannot be recreated", softwareFacetString, e);
// }catch (Exception e) {
// throw e;
// }
// Trying to recreate EService
String eServiceString = ElementMapper.marshal(eService);
ResourceManagement eServiceManagement = new ResourceManagement();
eServiceManagement.setElementType(EService.NAME);
eServiceManagement.setJson(eServiceString);
try{
eServiceManagement.create();
}catch (ResourceAlreadyPresentException e) {
// OK
logger.debug("As expected {} cannot be recreated", eServiceString, e);
}catch (Exception e) {
throw e;
}
// TODO continue with checks
eServiceManagement = new ResourceManagement();
eServiceManagement.setElementType(EService.NAME);
eServiceManagement.setJson(eServiceString);
eServiceManagement.delete();
}
}