Fixed bug and tests
This commit is contained in:
parent
2485f43510
commit
d58dcc20cf
|
@ -184,8 +184,16 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
protected OClass getOClass() throws SchemaException, ResourceRegistryException {
|
protected OClass getOClass() throws SchemaException, ResourceRegistryException {
|
||||||
if(oClass == null) {
|
if(oClass == null) {
|
||||||
if(element != null) {
|
if(element != null) {
|
||||||
|
try {
|
||||||
oClass = ElementManagementUtility.getOClass(element);
|
oClass = ElementManagementUtility.getOClass(element);
|
||||||
getCachedType().setOClass(oClass);
|
getCachedType().setOClass(oClass);
|
||||||
|
}catch (ResourceRegistryException e) {
|
||||||
|
try {
|
||||||
|
oClass = getCachedType().getOClass();
|
||||||
|
}catch (Exception e1) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
oClass = getCachedType().getOClass();
|
oClass = getCachedType().getOClass();
|
||||||
AccessType gotAccessType = cachedType.getAccessType();
|
AccessType gotAccessType = cachedType.getAccessType();
|
||||||
|
|
|
@ -0,0 +1,135 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.informationsystem.resourceregistry.instances.multicontext;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Calendar;
|
||||||
|
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.impl.properties.PropagationConstraintImpl;
|
||||||
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
|
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.resourceregistry.ContextTest;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||||
|
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.impl.entities.facets.AccessPointFacetImpl;
|
||||||
|
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.SoftwareFacetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.resources.EServiceImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
|
||||||
|
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.SoftwareFacet;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
|
||||||
|
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 AnotherEnhancedTest extends MultiContextTest {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory
|
||||||
|
.getLogger(AnotherEnhancedTest.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoFollows() throws Exception {
|
||||||
|
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
|
||||||
|
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.propagate);
|
||||||
|
propagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
|
||||||
|
|
||||||
|
IsIdentifiedBy<EService, Facet> isIdentifiedBy = new IsIdentifiedByImpl<EService, Facet>(
|
||||||
|
eService, softwareFacet, propagationConstraint);
|
||||||
|
eService.addFacet(isIdentifiedBy);
|
||||||
|
|
||||||
|
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
|
||||||
|
accessPointFacet.setEndpoint(new URI("https://localhost"));
|
||||||
|
accessPointFacet.setEntryName("port1");
|
||||||
|
eService.addFacet(accessPointFacet);
|
||||||
|
|
||||||
|
EventFacet eventFacet = new EventFacetImpl();
|
||||||
|
eventFacet.setDate(Calendar.getInstance().getTime());
|
||||||
|
ValueSchema event = new ValueSchemaImpl();
|
||||||
|
event.setValue("Created");
|
||||||
|
event.setSchema(new URI(""));
|
||||||
|
eventFacet.setEvent(event);
|
||||||
|
eService.addFacet(eventFacet);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -6,30 +6,21 @@ package org.gcube.informationsystem.resourceregistry.instances.multicontext;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
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.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Facet;
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint;
|
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.AddConstraint;
|
||||||
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
import org.gcube.informationsystem.model.reference.properties.PropagationConstraint.RemoveConstraint;
|
||||||
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.exceptions.AvailableInAnotherContextException;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.SmartgearResourcesTest;
|
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagementUtility;
|
import org.gcube.informationsystem.resourceregistry.instances.model.ERManagementUtility;
|
||||||
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.utils.ElementMapper;
|
import org.gcube.informationsystem.utils.ElementMapper;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
|
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
|
||||||
|
@ -39,18 +30,14 @@ 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.EServiceImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
|
import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl;
|
||||||
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
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.AccessPointFacet;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet;
|
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.LicenseFacet;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
|
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.EService;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode;
|
|
||||||
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
|
import org.gcube.resourcemanagement.model.reference.properties.ValueSchema;
|
||||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
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.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -145,164 +132,4 @@ public class EnhancedTest extends MultiContextTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetContextsInInstances() throws ResourceRegistryException, Exception {
|
|
||||||
ContextTest.setContextByName(DEFAULT_TEST_SCOPE);
|
|
||||||
|
|
||||||
ContextCache contextCache = ContextCache.getInstance();
|
|
||||||
contextCache.setContextCacheRenewal(contextCacheRenewal);
|
|
||||||
|
|
||||||
/* Creating HostingNode */
|
|
||||||
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);
|
|
||||||
|
|
||||||
hostingNodeManagement = new ResourceManagement();
|
|
||||||
hostingNodeManagement.setUUID(hostingNode.getHeader().getUUID());
|
|
||||||
hostingNodeManagement.setElementType(Utility.getTypeName(hostingNode.getClass()));
|
|
||||||
String hostingNodeJson = hostingNodeManagement.read().toString();
|
|
||||||
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().toString();
|
|
||||||
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().toString();
|
|
||||||
|
|
||||||
@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().toString();
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -322,6 +322,21 @@ public class SchemaManagementImplTest extends ContextTest {
|
||||||
@Test
|
@Test
|
||||||
public void createUpdateDeleteFacetType() throws Exception {
|
public void createUpdateDeleteFacetType() throws Exception {
|
||||||
|
|
||||||
|
SchemaManagement schemaManagement = new SchemaManagement();
|
||||||
|
String typeName = TestFacet.NAME;
|
||||||
|
schemaManagement.setTypeName(typeName);
|
||||||
|
try {
|
||||||
|
logger.info("Going to delete {}", typeName);
|
||||||
|
schemaManagement.delete(AccessType.FACET);
|
||||||
|
logger.info("Deleted {}", typeName);
|
||||||
|
} catch (SchemaNotFoundException e) {
|
||||||
|
// Removing the test type in case of a previous failure on test occurred
|
||||||
|
// In case no failure occurred the type was not found
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Class<? extends Facet>[] classes = new Class[]{TestFacet.class, TestFacet1_0_1.class, TestFacet1_0_2.class};
|
Class<? extends Facet>[] classes = new Class[]{TestFacet.class, TestFacet1_0_1.class, TestFacet1_0_2.class};
|
||||||
|
@ -353,8 +368,8 @@ public class SchemaManagementImplTest extends ContextTest {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
SchemaManagement schemaManagement = new SchemaManagement();
|
schemaManagement = new SchemaManagement();
|
||||||
String typeName = TestFacet.NAME;
|
typeName = TestFacet.NAME;
|
||||||
schemaManagement.setTypeName(typeName);
|
schemaManagement.setTypeName(typeName);
|
||||||
try {
|
try {
|
||||||
logger.info("Going to delete {}", typeName);
|
logger.info("Going to delete {}", typeName);
|
||||||
|
|
Loading…
Reference in New Issue