resource-registry/src/test/java/org/gcube/informationsystem/resourceregistry/instances/multicontext/BasicTest.java

1073 lines
47 KiB
Java
Raw Normal View History

/**
*
*/
package org.gcube.informationsystem.resourceregistry.instances.multicontext;
2020-11-05 15:58:30 +01:00
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;
2020-11-05 15:58:30 +01:00
import java.util.List;
2021-01-25 17:38:19 +01:00
import java.util.Map;
2020-11-05 15:58:30 +01:00
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.UUID;
2021-01-25 17:38:19 +01:00
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.informationsystem.base.reference.Element;
import org.gcube.informationsystem.base.reference.IdentifiableElement;
2020-11-05 15:58:30 +01:00
import org.gcube.informationsystem.context.reference.entities.Context;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.reference.entities.Entity;
import org.gcube.informationsystem.model.reference.entities.Facet;
2021-01-26 17:35:08 +01:00
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.AddConstraint;
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
2021-01-26 17:35:08 +01:00
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.model.reference.relations.Relation;
import org.gcube.informationsystem.resourceregistry.ContextTest;
2020-11-05 15:58:30 +01:00
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
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.facet.FacetAvailableInAnotherContextException;
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.relation.RelationAvailableInAnotherContextException;
2020-11-05 15:58:30 +01:00
import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
2020-01-27 17:07:37 +01:00
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
2020-11-05 15:58:30 +01:00
import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement;
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.FacetManagement;
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
2019-11-06 12:14:27 +01:00
import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement;
import org.gcube.informationsystem.types.TypeMapper;
import org.gcube.informationsystem.utils.ElementMapper;
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.CPUFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.MemoryFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.NetworkingFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
2020-12-21 23:09:57 +01:00
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
2020-12-21 23:09:57 +01:00
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasPersistentMemoryImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.HasVolatileMemoryImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.CPUFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.MemoryFacet.MemoryUnit;
import org.gcube.resourcemanagement.model.reference.entities.facets.NetworkingFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
2020-12-21 23:09:57 +01:00
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
2020-12-21 23:09:57 +01:00
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasPersistentMemory;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.HasVolatileMemory;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.orientechnologies.orient.core.record.ODirection;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class BasicTest extends ContextTest {
private static Logger logger = LoggerFactory
.getLogger(BasicTest.class);
@Test
public void testDifferentScopes() throws Exception {
2020-11-05 17:03:05 +01:00
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
FacetManagement facetManagement = new FacetManagement();
facetManagement.setJson(ElementMapper.marshal(cpuFacet));
facetManagement.setElementType(CPUFacet.NAME);
String json = facetManagement.create();
logger.debug("Created : {}", json);
CPUFacet createdCPUFacet = ElementMapper.unmarshal(CPUFacet.class, json);
UUID uuid = createdCPUFacet.getHeader().getUUID();
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
String readJson = facetManagement.read();
logger.debug("Read : {}", readJson);
/* ------------------------------------------------------------------ */
logger.debug("Switching to another scope");
ContextTest.setContextByName(PARENT_DEFAULT_TEST_SCOPE);
try {
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
readJson = facetManagement.read();
logger.debug("You should not be able to read Facet with UUID {}",
uuid);
throw new Exception(
"You should not be able to read Facet with UUID " + uuid);
} catch (FacetAvailableInAnotherContextException e) {
logger.debug("Good the facet created in the default context is not visible in an alternative context");
}
/* ---------------- entering hierarchic mode */
2020-10-27 15:12:11 +01:00
ContextUtility.getHierarchicalMode().set(true);
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
readJson = facetManagement.read();
logger.debug("You should be able to read it {}", readJson);
2020-10-27 15:12:11 +01:00
ContextUtility.getHierarchicalMode().set(false);
/* ---------------- leaving hierarchic mode */
cpuFacet.setAdditionalProperty("My", "Test");
try {
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
facetManagement.setJson(ElementMapper.marshal(cpuFacet));
readJson = facetManagement.update();
logger.debug("You should not be able to update Facet with UUID {}",
uuid);
throw new Exception(
"You should not be able to read Facet with UUID " + uuid);
} catch (FacetAvailableInAnotherContextException e) {
logger.debug("Good the Facet created in the default context cannot be updated in an alternative context");
}
/* ------------------------------------------------------------------ */
logger.debug("Setting back default scope");
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
facetManagement.setJson(ElementMapper.marshal(cpuFacet));
readJson = facetManagement.update();
logger.debug("Updated : {}", readJson);
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
readJson = facetManagement.read();
logger.debug("Read Updated : {}", readJson);
facetManagement = new FacetManagement();
facetManagement.setUUID(uuid);
boolean deleted = facetManagement.delete();
Assert.assertTrue(deleted);
}
@Test(expected = ResourceRegistryException.class)
public void testResourceWithOnlyOneFacet() throws Exception {
EService eService = new EServiceImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(
eService, softwareFacet, propagationConstraint);
eService.addFacet(isIdentifiedBy);
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);
/*------------------------------------------------------------------------*/
try {
2021-01-28 22:53:10 +01:00
addToContextThenTestIfBehaveProperly(eService, true, ALTERNATIVE_TEST_SCOPE);
}finally {
UUID eServiceUUID = eService.getHeader().getUUID();
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID);
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
}
}
protected Map<UUID, Element> getRemovedExpectedInstances(Resource r) {
2021-01-26 17:35:08 +01:00
Map<UUID, Element> expected = new HashMap<>();
expected.put(r.getHeader().getUUID(), r);
// TODO query
for(IsRelatedTo<? extends Resource, ? extends Resource> isRelatedTo : r.getIsRelatedTo()) {
// TODO
if(isRelatedTo.getPropagationConstraint().getRemoveConstraint() == RemoveConstraint.cascade) {
expected.put(isRelatedTo.getHeader().getUUID(), isRelatedTo);
expected.putAll(getRemovedExpectedInstances(isRelatedTo.getTarget()));
// TODO
}
if(isRelatedTo.getPropagationConstraint().getRemoveConstraint() == RemoveConstraint.cascadeWhenOrphan) {
expected.put(isRelatedTo.getHeader().getUUID(), isRelatedTo);
expected.putAll(getRemovedExpectedInstances(isRelatedTo.getTarget()));
// TODO
// TODO
}
}
for(ConsistsOf<? extends Resource, ? extends Facet> consistsOf : r.getConsistsOf()) {
if(consistsOf.getPropagationConstraint().getRemoveConstraint() == RemoveConstraint.cascade || consistsOf.getPropagationConstraint().getRemoveConstraint() == RemoveConstraint.cascadeWhenOrphan ) {
expected.put(consistsOf.getHeader().getUUID(), consistsOf);
Facet facet = consistsOf.getTarget();
expected.put(facet.getHeader().getUUID(), facet);
}
}
return expected;
}
protected void removeFromContextThenTestIfBehaveProperly(Resource r, boolean dryRun) throws ResourceRegistryException {
Map<UUID, Element> expectedInstances = getRemovedExpectedInstances(r);
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(TypeMapper.getType(r.getClass()));
resourceManagement.setUUID(r.getHeader().getUUID());
resourceManagement.setDryRunContextSharing(dryRun);
UUID contextUUID = ContextUtility.getCurrentSecurityContext().getUUID();
Map<UUID, JsonNode> affectedInstances = resourceManagement.removeFromContext(contextUUID);
SortedSet<UUID> expectedInstancesUUID = new TreeSet<>(expectedInstances.keySet());
SortedSet<UUID> affectedInstancesUUID = new TreeSet<>(affectedInstances.keySet());
logger.trace("Expected Instances are {} : {}", expectedInstancesUUID.size(), expectedInstancesUUID);
logger.trace("Affected Instances are {} : {}", affectedInstancesUUID.size(), affectedInstancesUUID);
Assert.assertTrue(expectedInstancesUUID.size()==affectedInstancesUUID.size());
Assert.assertTrue(expectedInstancesUUID.containsAll(affectedInstancesUUID));
Assert.assertTrue(affectedInstancesUUID.containsAll(expectedInstancesUUID));
for(UUID uuid : affectedInstances.keySet()) {
Element element = expectedInstances.get(uuid);
String expectedType = TypeMapper.getType(element.getClass());
JsonNode affectedJsonNode = affectedInstances.get(uuid);
String affectedType = affectedJsonNode.get(Element.CLASS_PROPERTY).asText();
Assert.assertTrue(affectedType.compareTo(expectedType)==0);
}
}
interface RelationConstraint {
public boolean mustBeAdded(Relation<Resource, Entity> r);
2021-01-28 22:53:10 +01:00
public boolean mustBeRemoved(Relation<Resource, Entity> r);
}
protected Resource getAndAddIsRelatedTo(Resource r, RelationConstraint relationConstraint) throws ResourceRegistryException, Exception {
ResourceManagement resourceManagement = new ResourceManagement();
2021-01-28 22:53:10 +01:00
resourceManagement.setElementType(Resource.NAME);
String resourceType = TypeMapper.getType(r);
UUID resourceUUID = r.getHeader().getUUID();
2021-01-28 22:53:10 +01:00
// resourceManagement.setUUID(resourceUUID);
2021-01-28 22:53:10 +01:00
String ret = resourceManagement.query(IsRelatedTo.NAME, resourceType, resourceUUID, ODirection.IN, true, new HashMap<>(), true);
@SuppressWarnings("rawtypes")
List<IsRelatedTo> isRelatedToList = ElementMapper.unmarshalList(IsRelatedTo.class, ret);
for(@SuppressWarnings("rawtypes") IsRelatedTo isRelatedTo : isRelatedToList) {
@SuppressWarnings("unchecked")
boolean mustBeAdded = relationConstraint.mustBeAdded(isRelatedTo);
if(mustBeAdded) {
@SuppressWarnings("unchecked")
IsRelatedTo<EService, Resource> irt = (IsRelatedTo<EService, Resource>) isRelatedTo;
r.attachResource(irt);
}
}
return r;
}
protected Map<UUID, Element> getAddedExpectedInstances(Resource r) throws ResourceRegistryException, Exception {
Map<UUID, Element> expected = new HashMap<>();
expected.put(r.getHeader().getUUID(), r);
RelationConstraint propagateConstraint = new RelationConstraint() {
@Override
public boolean mustBeAdded(Relation<Resource, Entity> r) {
return r.getPropagationConstraint().getAddConstraint() == AddConstraint.propagate;
}
2021-01-28 22:53:10 +01:00
@Override
public boolean mustBeRemoved(Relation<Resource, Entity> r) {
throw new UnsupportedOperationException();
}
};
r = getAndAddIsRelatedTo(r, propagateConstraint);
2021-01-26 17:35:08 +01:00
for(IsRelatedTo<? extends Resource, ? extends Resource> isRelatedTo : r.getIsRelatedTo()) {
if(isRelatedTo.getPropagationConstraint().getAddConstraint() == AddConstraint.propagate) {
expected.put(isRelatedTo.getHeader().getUUID(), isRelatedTo);
expected.putAll(getAddedExpectedInstances(isRelatedTo.getTarget()));
}
}
2021-01-26 17:35:08 +01:00
for(ConsistsOf<? extends Resource, ? extends Facet> consistsOf : r.getConsistsOf()) {
if(consistsOf.getPropagationConstraint().getAddConstraint() == AddConstraint.propagate) {
expected.put(consistsOf.getHeader().getUUID(), consistsOf);
Facet facet = consistsOf.getTarget();
expected.put(facet.getHeader().getUUID(), facet);
}
}
2021-01-26 17:35:08 +01:00
return expected;
}
2021-01-28 22:53:10 +01:00
protected void addToContextThenTestIfBehaveProperly(Resource r, boolean dryRun, String targetContextFullName) throws ResourceRegistryException, Exception {
2021-01-26 17:35:08 +01:00
Map<UUID, Element> expectedInstances = getAddedExpectedInstances(r);
2021-01-26 17:35:08 +01:00
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setElementType(TypeMapper.getType(r));
2021-01-26 17:35:08 +01:00
resourceManagement.setUUID(r.getHeader().getUUID());
resourceManagement.setDryRunContextSharing(dryRun);
2021-01-28 22:53:10 +01:00
UUID contextUUID = ContextUtility.getInstance().getSecurityContextByFullName(targetContextFullName).getUUID();
Map<UUID, JsonNode> affectedInstances = resourceManagement.addToContext(contextUUID);
2021-01-26 17:35:08 +01:00
SortedSet<UUID> expectedInstancesUUID = new TreeSet<>(expectedInstances.keySet());
SortedSet<UUID> affectedInstancesUUID = new TreeSet<>(affectedInstances.keySet());
2021-01-26 17:35:08 +01:00
logger.trace("Expected Instances are {} : {}", expectedInstancesUUID.size(), expectedInstancesUUID);
logger.trace("Affected Instances are {} : {}", affectedInstancesUUID.size(), affectedInstancesUUID);
2021-01-26 17:35:08 +01:00
Assert.assertTrue(expectedInstancesUUID.size()==affectedInstancesUUID.size());
2021-01-26 17:35:08 +01:00
Assert.assertTrue(expectedInstancesUUID.containsAll(affectedInstancesUUID));
Assert.assertTrue(affectedInstancesUUID.containsAll(expectedInstancesUUID));
for(UUID uuid : affectedInstances.keySet()) {
2021-01-26 17:35:08 +01:00
Element element = expectedInstances.get(uuid);
String expectedType = TypeMapper.getType(element.getClass());
JsonNode affectedJsonNode = affectedInstances.get(uuid);
String affectedType = affectedJsonNode.get(Element.CLASS_PROPERTY).asText();
2021-01-26 17:35:08 +01:00
Assert.assertTrue(affectedType.compareTo(expectedType)==0);
}
}
@Test
public void testCreateEServiceHostingNode() throws Exception {
EService eService = new EServiceImpl();
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup("InformationSystem");
softwareFacet.setName("resource-registry");
softwareFacet.setVersion("1.1.0");
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(
eService, softwareFacet, null);
eService.addFacet(isIdentifiedBy);
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
accessPointFacet.setEndpoint(new URI("http://localhost"));
accessPointFacet.setEntryName("port1");
eService.addFacet(accessPointFacet);
EventFacet eventFacet = new EventFacetImpl();
eventFacet.setDate(Calendar.getInstance().getTime());
2020-12-21 23:09:57 +01:00
ValueSchema event = new ValueSchemaImpl();
event.setValue("Created");
eventFacet.setEvent(event);
eService.addFacet(eventFacet);
2020-12-21 23:09:57 +01:00
StateFacet stateFacet = new StateFacetImpl();
stateFacet.setValue("ready");
eService.addFacet(stateFacet);
LicenseFacet licenseFacet = new LicenseFacetImpl();
licenseFacet.setName("EUPL");
licenseFacet
.setTextURL(new URL(
"https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11"));
eService.addFacet(licenseFacet);
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<>();
eServiceInstances.put(eService.getHeader().getUUID(), eService);
for(ConsistsOf<?,?> consistsOf : eService.getConsistsOf()) {
eServiceInstances.put(consistsOf.getHeader().getUUID(), consistsOf);
eServiceInstances.put(consistsOf.getTarget().getHeader().getUUID(), consistsOf.getTarget());
}
HostingNode hostingNode = new HostingNodeImpl();
NetworkingFacet networkingFacet = new NetworkingFacetImpl();
networkingFacet.setIPAddress("146.48.87.183");
networkingFacet.setHostName("pc-frosini.isti.cnr.it");
networkingFacet.setDomainName("isti.cnr.it");
networkingFacet.setMask("255.255.248.0");
networkingFacet.setBroadcastAddress("146.48.87.255");
IsIdentifiedBy<HostingNode, NetworkingFacet> isIdentifiedByHNNF = new IsIdentifiedByImpl<HostingNode, NetworkingFacet>(
hostingNode, networkingFacet, null);
hostingNode.addFacet(isIdentifiedByHNNF);
CPUFacet cpuFacet = new CPUFacetImpl();
cpuFacet.setClockSpeed("1 GHz");
cpuFacet.setModel("Opteron");
cpuFacet.setVendor("AMD");
hostingNode.addFacet(cpuFacet);
MemoryFacet ram = new MemoryFacetImpl();
ram.setSize(8);
ram.setUnit(MemoryUnit.GB);
ram.setUsed(2);
HasVolatileMemory<HostingNode, MemoryFacet> hasVolatileMemory = new HasVolatileMemoryImpl<HostingNode, MemoryFacet>(
hostingNode, ram, null);
hostingNode.addFacet(hasVolatileMemory);
MemoryFacet disk = new MemoryFacetImpl();
disk.setSize(256);
disk.setUnit(MemoryUnit.GB);
disk.setUsed(120);
HasPersistentMemory<HostingNode, MemoryFacet> hasPersistentMemory = new HasPersistentMemoryImpl<HostingNode, MemoryFacet>(
hostingNode, disk, null);
hostingNode.addFacet(hasPersistentMemory);
2021-01-28 22:53:10 +01:00
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint.setAddConstraint(AddConstraint.unpropagate);
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
Activates<HostingNode, EService> activates = new ActivatesImpl<HostingNode, EService>(
2021-01-28 22:53:10 +01:00
hostingNode, eService, propagationConstraint);
UUID activatedUUID = UUID.randomUUID();
activates.setHeader(new HeaderImpl(activatedUUID));
hostingNode.attachResource(activates);
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();
Map<UUID, IdentifiableElement> hostingNodeInstances = new HashMap<>();
hostingNodeInstances.put(hostingNodeUUID, hostingNode);
for(ConsistsOf<?,?> consistsOf : hostingNode.getConsistsOf()) {
hostingNodeInstances.put(consistsOf.getHeader().getUUID(), consistsOf);
hostingNodeInstances.put(consistsOf.getTarget().getHeader().getUUID(), consistsOf.getTarget());
}
2021-01-28 22:53:10 +01:00
/* ------------------------------------------------------------------ */
2021-01-26 17:35:08 +01:00
2021-01-28 22:53:10 +01:00
String currentContextFulName = ContextTest.getCurrentContextFullName();
String targetContextFullName = ALTERNATIVE_TEST_SCOPE;
2021-01-28 22:53:10 +01:00
addToContextThenTestIfBehaveProperly(hostingNode, true, targetContextFullName);
2021-01-28 22:53:10 +01:00
logger.debug("Switching to the target context");
ContextTest.setContextByName(targetContextFullName);
UUID contextUUID = ContextUtility.getCurrentSecurityContext().getUUID();
try {
2021-01-26 17:35:08 +01:00
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNodeUUID);
resourceManagement.read();
logger.debug("You should not be able to read {} with UUID {} in {} with UUID {} (i.e., {})",
HostingNode.NAME, hostingNodeUUID.toString(), Context.NAME, contextUUID, ContextUtility.getCurrentContextFullName());
}catch (AvailableInAnotherContextException e) {
// OK
}
2021-01-25 17:38:19 +01:00
2021-01-28 22:53:10 +01:00
logger.debug("Switching back to the target context");
ContextTest.setContextByName(currentContextFulName);
addToContextThenTestIfBehaveProperly(hostingNode, false, targetContextFullName);
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hostingNodeUUID);
String hnString = resourceManagement.read();
HostingNode readHN = ElementMapper.unmarshal(HostingNode.class, hnString);
Assert.assertTrue(readHN.getHeader().getUUID().compareTo(hostingNodeUUID) == 0);
UUID eServiceUUID = eService.getHeader().getUUID();
try {
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID);
resourceManagement.read();
} catch (ResourceAvailableInAnotherContextException e) {
logger.debug("Resource with {} Not Found as Expected",
eServiceUUID);
}
/* Commented because the behavior has been changed
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);
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
/* ------------------------------------------------------------------ */
logger.debug("Setting back default scope");
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
2021-01-29 17:29:49 +01:00
try {
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID);
deleted = resourceManagement.delete();
}catch (ResourceNotFoundException e) {
// OK
}
}
// @Test
public void addTest() throws ResourceNotFoundException,
ContextNotFoundException, ResourceRegistryException {
ResourceManagement resourceManagement = new ResourceManagement();
resourceManagement.setUUID(UUID.fromString(""));
resourceManagement.addToContext(ContextUtility.getCurrentSecurityContext().getUUID());
}
@Test
public void testAddAndRemoveFromContext() throws Exception {
/* Creating HostingNode */
ResourceManagement resourceManagement = new ResourceManagement();
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 */
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 */
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint
.setRemoveConstraint(RemoveConstraint.cascade);
propagationConstraint
.setAddConstraint(AddConstraint.propagate);
Activates<HostingNode, EService> activates = new ActivatesImpl<>(hostingNode, eService,
propagationConstraint);
IsRelatedToManagement isRelatedToManagement = new IsRelatedToManagement();
isRelatedToManagement.setElementType(Activates.NAME);
String activatesJson = ElementMapper.marshal(activates);
isRelatedToManagement.setJson(activatesJson);
String createdActivatesJson = isRelatedToManagement.create();
logger.debug("Created : {}", createdActivatesJson);
@SuppressWarnings("unchecked")
Activates<HostingNode, EService> createdActivates = ElementMapper.unmarshal(Activates.class, createdActivatesJson);
UUID activatesUUID = createdActivates.getHeader().getUUID();
/* ------------------------------------------------------------------ */
/*
* 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.setUUID(activatesUUID);
2021-01-29 17:29:49 +01:00
UUID contextUUID = ContextUtility.getInstance().getSecurityContextByFullName(ALTERNATIVE_TEST_SCOPE).getUUID();
isRelatedToManagement.addToContext(contextUUID);
logger.debug("Switching to alternative scope");
ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE);
/* The addTocontext on the relation adds the source and target too.
* So that I MUST be able to read HostinNode and EService
*/
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hnUUID);
resourceManagement.read();
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID);
resourceManagement.read();
/* ------------------------------------------------------------------ */
logger.debug("Setting back default scope");
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hnUUID);
Map<UUID,JsonNode> affectedInstances = resourceManagement.removeFromContext(ContextUtility.getCurrentSecurityContext().getUUID());
2021-01-29 17:29:49 +01:00
logger.debug("Remove from Context affects the following instances {}", affectedInstances.values());
// Assert.assertTrue(affectedInstaces);
/* The cascading MUST remove the relation and the target so that
* I MUST not be able to read Activates relation and EService
*/
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(eServiceUUID);
try {
resourceManagement.read();
String error = String.format("{} with UUID {} should not be visible.", EService.NAME, eServiceUUID);
logger.trace(error);
throw new Exception(error);
}catch (ResourceAvailableInAnotherContextException e) {
// OK
}
isRelatedToManagement = new IsRelatedToManagement();
isRelatedToManagement.setUUID(activatesUUID);
try {
isRelatedToManagement.read();
String error = String.format("{} with UUID {} should not be visible.", Activates.NAME, activatesUUID);
logger.trace(error);
throw new Exception(error);
}catch (RelationAvailableInAnotherContextException e) {
// OK
}
/* ------------------------------------------------------------------ */
logger.debug("Switching to alternative scope again");
ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE);
// TODO checks here
resourceManagement = new ResourceManagement();
resourceManagement.setUUID(hnUUID);
boolean deleted = resourceManagement.delete();
Assert.assertTrue(deleted);
}
2020-11-05 15:58:30 +01:00
// @Test
public void testGetInstanceContexts() throws ObjectNotFound, Exception {
2020-11-05 15:58:30 +01:00
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);
}
2020-11-05 15:58:30 +01:00
protected ContextCacheRenewal contextCacheRenewal= new ContextCacheRenewal() {
@Override
public List<Context> renew() throws ResourceRegistryException {
ContextManagement contextManagement = new ContextManagement();
String contextsJsonString = contextManagement.allFromServer(false);
List<Context> contexts = null;
try {
contexts = ElementMapper.unmarshalList(contextsJsonString);
} catch (IOException e) {
logger.error("Unable to read context from server", e);
}
return contexts;
}
};
@Test
public void testGetInstancesContexts() throws ResourceRegistryException, Exception {
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
/* Creating HostingNode */
ContextCache contextCache = ContextCache.getInstance();
contextCache.setContextCacheRenewal(contextCacheRenewal);
ResourceManagement hostingNodeManagement = new ResourceManagement();
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 */
ResourceManagement eServiceManagement = new ResourceManagement();
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 */
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint
.setRemoveConstraint(RemoveConstraint.cascade);
propagationConstraint
.setAddConstraint(AddConstraint.unpropagate);
Activates<HostingNode, EService> activates = new ActivatesImpl<>(hostingNode, eService,
propagationConstraint);
IsRelatedToManagement activatesManagement = new IsRelatedToManagement();
activatesManagement.setElementType(Activates.NAME);
String activatesJson = ElementMapper.marshal(activates);
activatesManagement.setJson(activatesJson);
String createdActivatesJson = activatesManagement.create();
logger.debug("Created : {}", createdActivatesJson);
@SuppressWarnings("unchecked")
Activates<HostingNode, EService> createdActivates = ElementMapper.unmarshal(Activates.class, createdActivatesJson);
logger.debug("UnMarshalled {}", createdActivates);
/* ------------------------------------------------------------------ */
2021-01-29 17:29:49 +01:00
addToContextThenTestIfBehaveProperly(hostingNode, false, ALTERNATIVE_TEST_SCOPE);
2020-11-05 15:58:30 +01:00
logger.debug("Switching to alternative scope");
ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE);
hostingNodeManagement = new ResourceManagement();
hostingNodeManagement.setUUID(hostingNode.getHeader().getUUID());
hostingNodeManagement.setElementType(Utility.getTypeName(hostingNode.getClass()));
2021-01-29 17:29:49 +01:00
2020-11-05 15:58:30 +01:00
String hostingNodeContexts = hostingNodeManagement.getContexts();
logger.debug("Contexts of {} with UUID {} have the following UUID {}", HostingNode.NAME, hostingNodeManagement.getUUID(), hostingNodeContexts);
Set<UUID> hostingNodeContextsUUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(hostingNodeContexts);
Assert.assertTrue(hostingNodeContextsUUID.size()==2);
Set<String> hostingNodeContextFullNames = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(hostingNodeContextsUUID);
Assert.assertTrue(hostingNodeContextFullNames.size()==2);
logger.debug("Contexts of {} with UUID {} are {}", HostingNode.NAME, hostingNodeManagement.getUUID(), hostingNodeContextFullNames);
for(Facet facet : hostingNode.getFacets()) {
FacetManagement facetManagement = new FacetManagement();
facetManagement.setUUID(facet.getHeader().getUUID());
String typeName = Utility.getTypeName(facet.getClass());
facetManagement.setElementType(typeName);
String facetContexts = facetManagement.getContexts();
logger.debug("Contexts of {} with UUID {} have the following UUID {}", typeName, facetManagement.getUUID(), facetContexts);
Set<UUID> facetContextsUUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(facetContexts);
Assert.assertTrue(hostingNodeContextsUUID.size()==2);
Assert.assertTrue(facetContextsUUID.containsAll(hostingNodeContextsUUID));
Assert.assertTrue(hostingNodeContextsUUID.containsAll(facetContextsUUID));
Set<String> facetContextFullNames = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(facetContextsUUID);
Assert.assertTrue(facetContextFullNames.size()==2);
logger.debug("Contexts of {} with UUID {} are {}", typeName, facetManagement.getUUID(), facetContextFullNames);
}
activatesManagement = new IsRelatedToManagement();
activatesManagement.setUUID(createdActivates.getHeader().getUUID());
activatesManagement.setElementType(Utility.getTypeName(createdActivates.getClass()));
String isRelatedToContexts = activatesManagement.getContexts();
logger.debug("Contexts of {} with UUID {} have the following UUID {}", Activates.NAME, activatesManagement.getUUID(), isRelatedToContexts);
Set<UUID> activatesContextsUUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(isRelatedToContexts);
Assert.assertTrue(activatesContextsUUID.size()==1);
Assert.assertFalse(activatesContextsUUID.containsAll(hostingNodeContextsUUID));
Assert.assertTrue(hostingNodeContextsUUID.containsAll(activatesContextsUUID));
Set<String> activatesContextFullNames = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(activatesContextsUUID);
Assert.assertTrue(activatesContextFullNames.size()==1);
logger.debug("Contexts of {} with UUID {} are {}", Activates.NAME, activatesManagement.getUUID(), activatesContextFullNames);
eServiceManagement = new ResourceManagement();
eServiceManagement.setUUID(eService.getHeader().getUUID());
eServiceManagement.setElementType(Utility.getTypeName(eService.getClass()));
String eServiceContexts = eServiceManagement.getContexts();
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);
Assert.assertTrue(eServiceContextsUUID.size()==1);
Assert.assertFalse(eServiceContextsUUID.containsAll(hostingNodeContextsUUID));
Assert.assertTrue(hostingNodeContextsUUID.containsAll(eServiceContextsUUID));
Set<String> eServiceContextFullNames = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(eServiceContextsUUID);
Assert.assertTrue(eServiceContextFullNames.size()==1);
logger.debug("Contexts of {} with UUID {} are {}", EService.NAME, eServiceManagement.getUUID(), eServiceContextFullNames);
boolean deleted = hostingNodeManagement.delete();
Assert.assertTrue(deleted);
}
@Test
public void testGetContextsInInstances() throws ResourceRegistryException, Exception {
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
/* Creating HostingNode */
ContextCache contextCache = ContextCache.getInstance();
contextCache.setContextCacheRenewal(contextCacheRenewal);
ResourceManagement hostingNodeManagement = new ResourceManagement();
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 */
ResourceManagement eServiceManagement = new ResourceManagement();
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 */
PropagationConstraint propagationConstraint = new PropagationConstraintImpl();
propagationConstraint
.setRemoveConstraint(RemoveConstraint.cascade);
propagationConstraint
.setAddConstraint(AddConstraint.unpropagate);
Activates<HostingNode, EService> activates = new ActivatesImpl<>(hostingNode, eService,
propagationConstraint);
IsRelatedToManagement activatesManagement = new IsRelatedToManagement();
activatesManagement.setElementType(Activates.NAME);
String activatesJson = ElementMapper.marshal(activates);
activatesManagement.setJson(activatesJson);
String createdActivatesJson = activatesManagement.create();
logger.debug("Created : {}", createdActivatesJson);
@SuppressWarnings("unchecked")
Activates<HostingNode, EService> createdActivates = ElementMapper.unmarshal(Activates.class, createdActivatesJson);
logger.debug("UnMarshalled {}", createdActivates);
/* ------------------------------------------------------------------ */
logger.debug("Switching to alternative scope");
ContextTest.setContextByName(ALTERNATIVE_TEST_SCOPE);
hostingNodeManagement = new ResourceManagement();
hostingNodeManagement.setUUID(hostingNode.getHeader().getUUID());
hostingNodeManagement.setElementType(Utility.getTypeName(hostingNode.getClass()));
hostingNodeManagement.addToContext(ContextUtility.getCurrentSecurityContext().getUUID());
ContextUtility.getIncludeInstanceContexts().set(true);
String hostingNodeJson = hostingNodeManagement.read();
HostingNode hostingNodeRead = ElementMapper.unmarshal(HostingNode.class, hostingNodeJson);
logger.debug("Unmarshalled {} {}", HostingNode.NAME, hostingNodeRead);
@SuppressWarnings("unchecked")
Collection<String> contextsCollection = (Collection<String>) hostingNodeRead.getHeader().getAdditionalProperty(Header.__CONTEXTS);
Assert.assertTrue(contextsCollection.size()==2);
Set<UUID> hostingNodeContextsUUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(contextsCollection);
Assert.assertTrue(hostingNodeContextsUUID.size()==2);
Set<String> hostingNodeContextFullNames = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(hostingNodeContextsUUID);
Assert.assertTrue(hostingNodeContextFullNames.size()==2);
logger.debug("Contexts of {} with UUID {} are {}", HostingNode.NAME, hostingNodeManagement.getUUID(), hostingNodeContextFullNames);
for(Facet facet : hostingNode.getFacets()) {
FacetManagement facetManagement = new FacetManagement();
facetManagement.setUUID(facet.getHeader().getUUID());
String typeName = Utility.getTypeName(facet.getClass());
facetManagement.setElementType(typeName);
String facetJson = facetManagement.read();
Facet facetRead = ElementMapper.unmarshal(Facet.class, facetJson);
logger.debug("Unmarshalled {} {}", Utility.getTypeName(facetRead.getClass()), facetRead);
@SuppressWarnings("unchecked")
Collection<String> facetContextsCollection = (Collection<String>) facetRead.getHeader().getAdditionalProperty(Header.__CONTEXTS);
Assert.assertTrue(contextsCollection.size()==2);
Set<UUID> facetContextsUUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(facetContextsCollection);
Assert.assertTrue(hostingNodeContextsUUID.size()==2);
Assert.assertTrue(facetContextsUUID.containsAll(hostingNodeContextsUUID));
Assert.assertTrue(hostingNodeContextsUUID.containsAll(facetContextsUUID));
Set<String> facetContextFullNames = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(facetContextsUUID);
Assert.assertTrue(facetContextFullNames.size()==2);
logger.debug("Contexts of {} with UUID {} are {}", typeName, facetManagement.getUUID(), facetContextFullNames);
}
activatesManagement = new IsRelatedToManagement();
activatesManagement.setUUID(createdActivates.getHeader().getUUID());
activatesManagement.setElementType(Utility.getTypeName(createdActivates.getClass()));
try {
activatesManagement.read();
String error = String.format("It should not be possible to read %s in %s. A %s should be raised instead", Activates.NAME, ALTERNATIVE_TEST_SCOPE, AvailableInAnotherContextException.class.getSimpleName());
throw new Exception(error);
}catch (AvailableInAnotherContextException e) {
// This is what we expect
}
// Restoring DEFAULT TEST SCOPE otherwise is not possible to read activates relation
// which is not available in ALTERNATIVE_TEST_SCOPE
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
activatesManagement = new IsRelatedToManagement();
activatesManagement.setUUID(createdActivates.getHeader().getUUID());
activatesManagement.setElementType(Utility.getTypeName(createdActivates.getClass()));
// reading again
String activatesReadJson = activatesManagement.read();
@SuppressWarnings("unchecked")
Activates<HostingNode, EService> activatesRead = ElementMapper.unmarshal(Activates.class, activatesReadJson);
logger.debug("Unmarshalled {} {}", Utility.getTypeName(activatesRead.getClass()), activatesRead);
@SuppressWarnings("unchecked")
Collection<String> activatesContextsCollection = (Collection<String>) activatesRead.getHeader().getAdditionalProperty(Header.__CONTEXTS);
logger.debug("Contexts of {} with UUID {} have the following UUID {}", Activates.NAME, activatesManagement.getUUID(), activatesContextsCollection);
Set<UUID> activatesContextsUUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(activatesContextsCollection);
Assert.assertTrue(activatesContextsUUID.size()==1);
Assert.assertFalse(activatesContextsUUID.containsAll(hostingNodeContextsUUID));
Assert.assertTrue(hostingNodeContextsUUID.containsAll(activatesContextsUUID));
Set<String> activatesContextFullNames = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(activatesContextsUUID);
Assert.assertTrue(activatesContextFullNames.size()==1);
logger.debug("Contexts of {} with UUID {} are {}", Activates.NAME, activatesManagement.getUUID(), activatesContextFullNames);
eServiceManagement = new ResourceManagement();
eServiceManagement.setUUID(eService.getHeader().getUUID());
eServiceManagement.setElementType(Utility.getTypeName(eService.getClass()));
String eServiceReadJson = eServiceManagement.read();
EService eServiceRead = ElementMapper.unmarshal(EService.class, eServiceReadJson);
logger.debug("Unmarshalled {} {}", Utility.getTypeName(eServiceRead.getClass()), eServiceRead);
@SuppressWarnings("unchecked")
Collection<String> eServiceContextsCollection = (Collection<String>) eServiceRead.getHeader().getAdditionalProperty(Header.__CONTEXTS);
logger.debug("Contexts of {} with UUID {} have the following UUID {}", EService.NAME, eServiceManagement.getUUID(), eServiceContextsCollection);
Set<UUID> eServiceContextsUUID = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextUUIDSet(eServiceContextsCollection);
Assert.assertTrue(eServiceContextsUUID.size()==1);
Assert.assertFalse(eServiceContextsUUID.containsAll(hostingNodeContextsUUID));
Assert.assertTrue(hostingNodeContextsUUID.containsAll(eServiceContextsUUID));
Set<String> eServiceContextFullNames = org.gcube.informationsystem.resourceregistry.api.contexts.ContextUtility.getContextFullNameSet(eServiceContextsUUID);
Assert.assertTrue(eServiceContextFullNames.size()==1);
logger.debug("Contexts of {} with UUID {} are {}", EService.NAME, eServiceManagement.getUUID(), eServiceContextFullNames);
boolean deleted = hostingNodeManagement.delete();
Assert.assertTrue(deleted);
}
}