From 58d7aa93c3b03bd94eab8755035bf9e612e94cd3 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 28 Jan 2021 22:53:10 +0100 Subject: [PATCH] Implemented #20555 #20530 --- .../contexts/ContextUtility.java | 2 +- .../instances/base/ElementManagement.java | 2 +- .../base/ElementManagementUtility.java | 6 +- .../model/entities/EntityManagement.java | 23 ++++++-- .../resourceregistry/rest/Access.java | 5 +- .../resourceregistry/ContextTest.java | 8 ++- .../instances/ERManagementTest.java | 38 ++++++------ .../model/entity/ResourceManagementTest.java | 12 ++-- .../instances/multicontext/BasicTest.java | 58 ++++++++++--------- 9 files changed, 90 insertions(+), 64 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java index fd1e73b..b54d0ce 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ContextUtility.java @@ -114,7 +114,7 @@ public class ContextUtility { contexts.put(securityContext.getUUID(), securityContext); } - private synchronized SecurityContext getSecurityContextByFullName(String fullName) throws ContextException { + public synchronized SecurityContext getSecurityContextByFullName(String fullName) throws ContextException { try { SecurityContext securityContext = null; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java index 112d4af..a4c6c55 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagement.java @@ -780,7 +780,7 @@ public abstract class ElementManagement { return affectedInstances; } catch(ResourceRegistryException e) { - logger.error("Unable to add {} with UUID {} to Context with UUID {} - Cause is {}", elementType, uuid, contextUUID, e.getMessage()); + logger.error("Unable to add {} with UUID {} to Context with UUID {} - Reason is {}", elementType, uuid, contextUUID, e.getMessage()); if(oDatabaseDocument != null) { oDatabaseDocument.rollback(); } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java index 98160f9..c48ab16 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/base/ElementManagementUtility.java @@ -111,12 +111,12 @@ public class ElementManagementUtility { } } - private static OElement getAnyElementByUUID(ODatabaseDocument orientGraph, UUID uuid) + public static OElement getAnyElementByUUID(ODatabaseDocument oDatabaseDocument, UUID uuid) throws NotFoundException, ResourceRegistryException { try { - return Utility.getElementByUUID(orientGraph, null, uuid, OVertex.class); + return Utility.getElementByUUID(oDatabaseDocument, null, uuid, OVertex.class); } catch(NotFoundException e) { - return Utility.getElementByUUID(orientGraph, null, uuid, OEdge.class); + return Utility.getElementByUUID(oDatabaseDocument, null, uuid, OEdge.class); } catch(ResourceRegistryException e) { throw e; } catch(Exception e) { diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java index 7c4d91b..f45c6c4 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java @@ -298,14 +298,14 @@ public abstract class EntityManagement extends EntityEl } public String reallyQuery(String relationType, String referenceType, UUID referenceUUID, ODirection direction, - boolean polymorphic, Map constraint) throws ResourceRegistryException { + boolean polymorphic, Map constraint, boolean includeRelationInResult) throws ResourceRegistryException { ObjectMapper objectMapper = new ObjectMapper(); ArrayNode arrayNode = objectMapper.createArrayNode(); Iterable references = null; if(referenceUUID != null) { - OElement element = ElementManagementUtility.getAnyElementByUUID(referenceUUID); + OElement element = ElementManagementUtility.getAnyElementByUUID(oDatabaseDocument, referenceUUID); if(element instanceof OVertex) { @SuppressWarnings("unchecked") EntityManagement entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(), @@ -415,14 +415,27 @@ public abstract class EntityManagement extends EntityEl } } + + @SuppressWarnings("rawtypes") EntityManagement entityManagement = ElementManagementUtility.getEntityManagement(getWorkingContext(), oDatabaseDocument, vertex); + try { if(referenceUUID!=null && entityManagement.getUUID().compareTo(referenceUUID) == 0) { continue; } - JsonNode jsonNode = entityManagement.serializeAsJson(); + + JsonNode jsonNode; + if(includeRelationInResult) { + @SuppressWarnings("rawtypes") + RelationManagement relationManagement = ElementManagementUtility.getRelationManagement(getWorkingContext(), + oDatabaseDocument, edge); + jsonNode = relationManagement.serializeAsJson(); + }else { + jsonNode = entityManagement.serializeAsJson(); + } + arrayNode.add(jsonNode); } catch(ResourceRegistryException e) { logger.error("Unable to correctly serialize {}. It will be excluded from results. {}", @@ -547,7 +560,7 @@ public abstract class EntityManagement extends EntityEl } public String query(String relationType, String referenceType, UUID referenceUUID, ODirection direction, - boolean polymorphic, Map constraint) throws ResourceRegistryException { + boolean polymorphic, Map constraint, boolean includeRelationInResult) throws ResourceRegistryException { try { oDatabaseDocument = getWorkingContext().getDatabaseDocument(PermissionMode.READER); @@ -601,7 +614,7 @@ public abstract class EntityManagement extends EntityEl break; } - return reallyQuery(relationType, referenceType, referenceUUID, direction, polymorphic, constraint); + return reallyQuery(relationType, referenceType, referenceUUID, direction, polymorphic, constraint, includeRelationInResult); } catch(ResourceRegistryException e) { throw e; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java index fe76fd9..6062486 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/rest/Access.java @@ -333,7 +333,7 @@ public class Access extends BaseRest { * All the EService identified By a SoftwareFacet : * GET /access/query/EService/isIdentifiedBy/SoftwareFacet?polymorphic=true&direction=out * - * The Eservice identified By the SoftwareFacet with UUID 7bc997c3-d005-40ff-b9ed-c4b6a35851f1 : + * All the EService identified By the SoftwareFacet with UUID 7bc997c3-d005-40ff-b9ed-c4b6a35851f1 : * GET /access/query/EService/isIdentifiedBy/SoftwareFacet?reference=7bc997c3-d005-40ff-b9ed-c4b6a35851f1&polymorphic=true&direction=out * * All the Resources identified By a ContactFacet : @@ -362,6 +362,7 @@ public class Access extends BaseRest { @QueryParam(AccessPath.REFERENCE_PARAM) String reference, @QueryParam(AccessPath.POLYMORPHIC_PARAM) @DefaultValue("false") Boolean polymorphic, @QueryParam(AccessPath.DIRECTION_PARAM) @DefaultValue("out") String direction, + @QueryParam(AccessPath.INCLUDE_RELATION_PARAM) @DefaultValue("false") Boolean includeRelation, @Context UriInfo uriInfo) throws ResourceRegistryException { logger.info("Requested {} instances having a(n) {} ({}={}} with {} ({}={})", resourcetype, relationType, @@ -417,7 +418,7 @@ public class Access extends BaseRest { } return ((ResourceManagement) erManagement).query(relationType, referenceType, refereceUUID, directionEnum, - polymorphic, constraint); + polymorphic, constraint, includeRelation); } String error = String.format("%s is not a %s type", resourcetype, Resource.NAME); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/ContextTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/ContextTest.java index ded295e..5a0baf4 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/ContextTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/ContextTest.java @@ -65,7 +65,11 @@ public class ContextTest { } } - public static String getCurrentScope(String token) throws ObjectNotFound, Exception { + public static String getCurrentContextFullName() throws ObjectNotFound, Exception { + return getContextFullNameByToken(SecurityTokenProvider.instance.get()); + } + + public static String getContextFullNameByToken(String token) throws ObjectNotFound, Exception { AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token); String context = authorizationEntry.getContext(); logger.info("Context of token {} is {}", token, context); @@ -85,7 +89,7 @@ public class ContextTest { String qualifier = authorizationEntry.getQualifier(); Caller caller = new Caller(clientInfo, qualifier); AuthorizationProvider.instance.set(caller); - ScopeProvider.instance.set(getCurrentScope(token)); + ScopeProvider.instance.set(getContextFullNameByToken(token)); } @BeforeClass diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/ERManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/ERManagementTest.java index 5ee528d..94b1af2 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/ERManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/ERManagementTest.java @@ -711,32 +711,34 @@ public class ERManagementTest extends ContextTest { ResourceManagement resourceManagement = new ResourceManagement(); resourceManagement.setElementType(Service.NAME); + boolean includeRelation = false; + /* Getting Hosting Node */ - String json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.BOTH, true, null); + String json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.BOTH, true, null, includeRelation); List resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==1); Resource resource = resourceList.get(0); Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID)==0); - json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.OUT, true, null); + json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.OUT, true, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==1); resource = resourceList.get(0); Assert.assertTrue(resource.getHeader().getUUID().compareTo(hostingNodeUUID)==0); - json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.IN, true, null); + json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.IN, true, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==0); - json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.BOTH, false, null); + json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.BOTH, false, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==0); - json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.OUT, false, null); + json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.OUT, false, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==0); - json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.IN, false, null); + json = resourceManagement.query(IsRelatedTo.NAME, EService.NAME, eServiceUUID, ODirection.IN, false, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==0); /* END Getting Hosting Node */ @@ -744,29 +746,29 @@ public class ERManagementTest extends ContextTest { /* Getting EService */ - json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.BOTH, true, null); + json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.BOTH, true, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==1); Assert.assertTrue(resourceList.get(0).getHeader().getUUID().compareTo(eServiceUUID)==0); - json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.OUT, true, null); + json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.OUT, true, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==0); - json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.IN, true, null); + json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.IN, true, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==1); Assert.assertTrue(resourceList.get(0).getHeader().getUUID().compareTo(eServiceUUID)==0); - json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.BOTH, false, null); + json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.BOTH, false, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==0); - json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.OUT, false, null); + json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.OUT, false, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==0); - json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.IN, false, null); + json = resourceManagement.query(IsRelatedTo.NAME, HostingNode.NAME, hostingNodeUUID, ODirection.IN, false, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==0); /* END Getting HostingNode */ @@ -777,12 +779,12 @@ public class ERManagementTest extends ContextTest { /* EService --ConsistsOf--> SoftwareFacet*/ try { - json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.BOTH, true, null); + json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.BOTH, true, null, includeRelation); }catch(InvalidQueryException e) { // Ok expected } - json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.OUT, true, null); + json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.OUT, true, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==1); resource = resourceList.get(0); @@ -791,24 +793,24 @@ public class ERManagementTest extends ContextTest { Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID)==0); try { - json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN, true, null); + json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN, true, null, includeRelation); }catch(InvalidQueryException e) { // Ok expected } try { - json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.BOTH, false, null); + json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.BOTH, false, null, includeRelation); }catch(InvalidQueryException e) { // Ok expected } - json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.OUT, false, null); + json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.OUT, false, null, includeRelation); resourceList = ElementMapper.unmarshalList(Resource.class, json); Assert.assertTrue(resourceList.size()==0); try { - json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN, false, null); + json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN, false, null, includeRelation); }catch(InvalidQueryException e) { // Ok expected } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/ResourceManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/ResourceManagementTest.java index 4c0810c..e65bb20 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/ResourceManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/ResourceManagementTest.java @@ -117,10 +117,12 @@ public class ResourceManagementTest extends ContextTest { @SuppressWarnings("rawtypes") ElementManagement erManagement = ElementManagementUtility.getERManagement(type); + boolean includeRelation = false; + if (erManagement instanceof ResourceManagement) { boolean[] booleans = new boolean[] {true, false}; for(boolean bool : booleans) { - String ret = ((ResourceManagement) erManagement).query(relationType, facetType, null, ODirection.OUT, bool, constraint); + String ret = ((ResourceManagement) erManagement).query(relationType, facetType, null, ODirection.OUT, bool, constraint, includeRelation); logger.debug("Result of query for {}polymorphic {} --{}--> {} with constaint {} is {}", bool ? "" : "NOT ", type, relationType, facetType, constraint, ret); } @@ -199,7 +201,9 @@ public class ResourceManagementTest extends ContextTest { Configuration expected = createdConfigurations.get(i); UUID expectedUUID = expected.getHeader().getUUID(); - + + boolean includeRelation = false; + for(Boolean polymorphic : polymorphics) { @@ -213,7 +217,7 @@ public class ResourceManagementTest extends ContextTest { resourceType, relationType, referenceType, constraint); String ret = resourceManagement.query(relationType, referenceType, refereceUUID, directionEnum, - polymorphic, constraint); + polymorphic, constraint, includeRelation); List list = ElementMapper.unmarshalList(Configuration.class, ret); Assert.assertTrue(list.size()==expectedSize); @@ -239,7 +243,7 @@ public class ResourceManagementTest extends ContextTest { parentResourceType, relationType, referenceType, constraint); String retPolimorphic = parentResourceManagement.query(relationType, referenceType, refereceUUID, directionEnum, - polymorphic, constraint); + polymorphic, constraint, includeRelation); List listPolimorphic = ElementMapper.unmarshalList(ConfigurationTemplate.class, retPolimorphic); Assert.assertTrue(listPolimorphic.size()==expectedSize); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/BasicTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/BasicTest.java index 1b6258c..0589c35 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/BasicTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/BasicTest.java @@ -220,11 +220,8 @@ public class BasicTest extends ContextTest { /*------------------------------------------------------------------------*/ - logger.debug("Switching to another context"); - ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE); - try { - addToContextThenTestIfBehaveProperly(eService, true); + addToContextThenTestIfBehaveProperly(eService, true, ALTERNATIVE_TEST_SCOPE); }finally { UUID eServiceUUID = eService.getHeader().getUUID(); resourceManagement = new ResourceManagement(); @@ -307,15 +304,19 @@ public class BasicTest extends ContextTest { public boolean mustBeAdded(Relation r); + public boolean mustBeRemoved(Relation r); + } protected Resource getAndAddIsRelatedTo(Resource r, RelationConstraint relationConstraint) throws ResourceRegistryException, Exception { ResourceManagement resourceManagement = new ResourceManagement(); + resourceManagement.setElementType(Resource.NAME); + String resourceType = TypeMapper.getType(r); - // resourceManagement.setElementType(resourceType); UUID resourceUUID = r.getHeader().getUUID(); + // resourceManagement.setUUID(resourceUUID); - String ret = resourceManagement.query(IsRelatedTo.NAME, resourceType, resourceUUID, ODirection.OUT, true, new HashMap<>()); + String ret = resourceManagement.query(IsRelatedTo.NAME, resourceType, resourceUUID, ODirection.IN, true, new HashMap<>(), true); @SuppressWarnings("rawtypes") List isRelatedToList = ElementMapper.unmarshalList(IsRelatedTo.class, ret); for(@SuppressWarnings("rawtypes") IsRelatedTo isRelatedTo : isRelatedToList) { @@ -342,6 +343,11 @@ public class BasicTest extends ContextTest { public boolean mustBeAdded(Relation r) { return r.getPropagationConstraint().getAddConstraint() == AddConstraint.propagate; } + + @Override + public boolean mustBeRemoved(Relation r) { + throw new UnsupportedOperationException(); + } }; @@ -363,14 +369,15 @@ public class BasicTest extends ContextTest { return expected; } - protected void addToContextThenTestIfBehaveProperly(Resource r, boolean dryRun) throws ResourceRegistryException, Exception { + protected void addToContextThenTestIfBehaveProperly(Resource r, boolean dryRun, String targetContextFullName) throws ResourceRegistryException, Exception { + Map expectedInstances = getAddedExpectedInstances(r); ResourceManagement resourceManagement = new ResourceManagement(); resourceManagement.setElementType(TypeMapper.getType(r)); resourceManagement.setUUID(r.getHeader().getUUID()); resourceManagement.setDryRunContextSharing(dryRun); - UUID contextUUID = ContextUtility.getCurrentSecurityContext().getUUID(); + UUID contextUUID = ContextUtility.getInstance().getSecurityContextByFullName(targetContextFullName).getUUID(); Map affectedInstances = resourceManagement.addToContext(contextUUID); SortedSet expectedInstancesUUID = new TreeSet<>(expectedInstances.keySet()); @@ -490,8 +497,11 @@ public class BasicTest extends ContextTest { hostingNode, disk, null); hostingNode.addFacet(hasPersistentMemory); + PropagationConstraint propagationConstraint = new PropagationConstraintImpl(); + propagationConstraint.setAddConstraint(AddConstraint.unpropagate); + propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade); Activates activates = new ActivatesImpl( - hostingNode, eService, null); + hostingNode, eService, propagationConstraint); UUID activatedUUID = UUID.randomUUID(); activates.setHeader(new HeaderImpl(activatedUUID)); hostingNode.attachResource(activates); @@ -515,27 +525,16 @@ public class BasicTest extends ContextTest { hostingNodeInstances.put(consistsOf.getTarget().getHeader().getUUID(), consistsOf.getTarget()); } - /* - IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement(); - isRelatedToManagement.setElementType(Activates.NAME); - isRelatedToManagement.setUUID(activatedUUID); - String activatesString = isRelatedToManagement.read(); - - - @SuppressWarnings("unchecked") - Activates unmarshalledActivates = ElementMapper.unmarshal(Activates.class, activatesString); - // An intermediate variable has been used to suppress warning here and not to the whole test function - activates = unmarshalledActivates; - - hostingNode.attachResource(activates); - */ - /* ------------------------------------------------------------------ */ - logger.debug("Switching to another context"); - ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE); + String currentContextFulName = ContextTest.getCurrentContextFullName(); + String targetContextFullName = ALTERNATIVE_TEST_SCOPE; + + addToContextThenTestIfBehaveProperly(hostingNode, true, targetContextFullName); + + logger.debug("Switching to the target context"); + ContextTest.setContextByName(targetContextFullName); - addToContextThenTestIfBehaveProperly(hostingNode, true); UUID contextUUID = ContextUtility.getCurrentSecurityContext().getUUID(); try { @@ -548,7 +547,10 @@ public class BasicTest extends ContextTest { // OK } - addToContextThenTestIfBehaveProperly(hostingNode, false); + logger.debug("Switching back to the target context"); + ContextTest.setContextByName(currentContextFulName); + + addToContextThenTestIfBehaveProperly(hostingNode, false, targetContextFullName); resourceManagement = new ResourceManagement(); resourceManagement.setUUID(hostingNodeUUID);