diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/contexts/ContextManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/contexts/ContextManagementTest.java index d810092..d825d04 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/contexts/ContextManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/contexts/ContextManagementTest.java @@ -6,6 +6,7 @@ import java.util.Map; import java.util.UUID; import org.gcube.com.fasterxml.jackson.core.JsonProcessingException; +import org.gcube.informationsystem.base.reference.IdentifiableElement; import org.gcube.informationsystem.context.impl.entities.ContextImpl; import org.gcube.informationsystem.context.reference.entities.Context; import org.gcube.informationsystem.context.reference.relations.IsParentOf; @@ -21,7 +22,7 @@ import org.gcube.informationsystem.resourceregistry.contexts.security.ContextSec import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode; import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.SecurityType; -import org.gcube.informationsystem.resourceregistry.tobereviewed.FacetManagementTest; +import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility; import org.gcube.informationsystem.utils.ElementMapper; import org.junit.Assert; import org.junit.Test; @@ -44,13 +45,32 @@ public class ContextManagementTest extends ContextTest { public static final String CTX_NAME_B = "B"; public static final String CTX_NAME_C = "C"; + public static void checkHeader(IdentifiableElement er, UUID uuid, boolean create) { + Assert.assertTrue(er.getHeader() != null); + Assert.assertTrue(er.getHeader().getUUID() != null); + + if(uuid != null) { + Assert.assertTrue(er.getHeader().getUUID().compareTo(uuid) == 0); + } + + String user = HeaderUtility.getUser(); + Assert.assertTrue(er.getHeader().getLastUpdateBy().compareTo(user) == 0); + + if(create) { + Assert.assertTrue(er.getHeader().getCreatedBy().compareTo(user) == 0); + Assert.assertTrue(er.getHeader().getCreationTime().compareTo(er.getHeader().getLastUpdateTime()) == 0); + } else { + Assert.assertTrue(er.getHeader().getCreationTime().before(er.getHeader().getLastUpdateTime())); + } + } + protected void assertions(Context pre, Context post, boolean checkParent, boolean create) throws ResourceRegistryException { if(checkParent) { if(pre.getHeader() != null) { - FacetManagementTest.checkHeader(post, pre.getHeader().getUUID(), create); + checkHeader(post, pre.getHeader().getUUID(), create); } else { - FacetManagementTest.checkHeader(post, null, create); + checkHeader(post, null, create); } } 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 4f3fec1..1706583 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/ERManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/ERManagementTest.java @@ -5,7 +5,6 @@ package org.gcube.informationsystem.resourceregistry.instances; import java.net.URI; import java.net.URL; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; @@ -27,15 +26,11 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra 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; -import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; import org.gcube.informationsystem.resourceregistry.ContextTest; -import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.utils.Utility; -import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; import org.gcube.informationsystem.resourceregistry.instances.model.entities.FacetManagement; import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement; import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement; -import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement; import org.gcube.informationsystem.resourceregistry.utils.HeaderUtility; import org.gcube.informationsystem.utils.ElementMapper; import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl; @@ -68,9 +63,7 @@ import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFace import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet; import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration; import org.gcube.resourcemanagement.model.reference.entities.resources.EService; -import org.gcube.resourcemanagement.model.reference.entities.resources.GCubeResource; import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; -import org.gcube.resourcemanagement.model.reference.entities.resources.Service; 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; @@ -81,8 +74,6 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.orientechnologies.orient.core.record.ODirection; - /** * @author Luca Frosini (ISTI - CNR) */ @@ -90,6 +81,25 @@ public class ERManagementTest extends ContextTest { private static Logger logger = LoggerFactory.getLogger(ERManagementTest.class); + public static final String GROUP = "InformationSystem"; + public static final String NAME = "resource-registry"; + public static final String VERSION = "1.0.0"; + public static final String NEW_VERSION = "2.0.0"; + + public static SoftwareFacet getSoftwareFacet() { + SoftwareFacet softwareFacet = new SoftwareFacetImpl(); + softwareFacet.setGroup(GROUP); + softwareFacet.setName(NAME); + softwareFacet.setVersion(VERSION); + return softwareFacet; + } + + public static void checkSoftwareFacetAssertion(SoftwareFacet softwareFacet, SoftwareFacet gotSoftwareFacet) { + Assert.assertTrue(gotSoftwareFacet.getGroup().compareTo(softwareFacet.getGroup()) == 0); + Assert.assertTrue(gotSoftwareFacet.getName().compareTo(softwareFacet.getName()) == 0); + Assert.assertTrue(gotSoftwareFacet.getVersion().compareTo(softwareFacet.getVersion()) == 0); + } + public static Configuration instantiateValidConfiguration() throws Exception { Configuration configuration = new ConfigurationImpl(); @@ -108,10 +118,7 @@ public class ERManagementTest extends ContextTest { public static EService instantiateValidEService() throws Exception { EService eService = new EServiceImpl(); - SoftwareFacet softwareFacet = new SoftwareFacetImpl(); - softwareFacet.setGroup("InformationSystem"); - softwareFacet.setName("resource-registry"); - softwareFacet.setVersion("1.1.0"); + SoftwareFacet softwareFacet = getSoftwareFacet(); IsIdentifiedBy isIdentifiedBy = new IsIdentifiedByImpl(eService, softwareFacet, null); @@ -279,6 +286,10 @@ public class ERManagementTest extends ContextTest { Class clz = facet.getClass(); Class gotClz = gotFacet.getClass(); Assert.assertTrue(clz==gotClz); + + if(clz == SoftwareFacet.class) { + checkSoftwareFacetAssertion((SoftwareFacet) facet, (SoftwareFacet) gotFacet); + } } protected static void checkResource(R resource, R gotResource) throws Exception { @@ -555,225 +566,30 @@ public class ERManagementTest extends ContextTest { @Test - public void testGetAll() throws Exception { - Map> resources = new HashMap<>(); - - final int MAX = 5; - int typeNumber = 0; - - for (int i = 0; i < MAX; i++) { - Map map = ERManagementTest.createHostingNodeAndEService(); - if (typeNumber == 0) { - typeNumber = map.size(); - } - for (String key : map.keySet()) { - if (!resources.containsKey(key)) { - resources.put(key, new ArrayList()); - } - resources.get(key).add(map.get(key)); - } - } - - /* Getting all instances of created specific Resources */ - for (String key : resources.keySet()) { - ResourceManagement resourceManagement = (ResourceManagement) ElementManagementUtility.getERManagement(key); - String json = resourceManagement.all(false); - - List list = ElementMapper.unmarshalList(Resource.class, json); - logger.debug("{} are {} : {} ", key, list.size(), list); - Assert.assertTrue(list.size() == MAX); - } - - /* Getting all Resources polymorphic and non polymorphic */ - - ResourceManagement resourceManagement = (ResourceManagement) ElementManagementUtility - .getERManagement(Resource.NAME); - - String json = resourceManagement.all(true); - List list = ElementMapper.unmarshalList(Resource.class, json); - logger.debug("{} are {} : {} ", Resource.NAME, list.size(), list); - Assert.assertTrue(list.size() == (MAX * typeNumber)); - - json = resourceManagement.all(false); - list = ElementMapper.unmarshalList(Resource.class, json); - Assert.assertTrue(list.size() == 0); - - /* Getting all IsRelatedTo polymorphic and non polymorphic */ - - IsRelatedToManagement isRelatedToManagement = (IsRelatedToManagement) ElementManagementUtility - .getERManagement(IsRelatedTo.NAME); - - json = isRelatedToManagement.all(true); - - List resourcesList = ElementMapper.unmarshalList(Resource.class, json); - logger.debug("{} are {} : {} ", IsRelatedTo.NAME, resourcesList.size(), resourcesList); - Assert.assertTrue(resourcesList.size() == MAX); - - json = isRelatedToManagement.all(false); - resourcesList = ElementMapper.unmarshalList(Resource.class, json); - Assert.assertTrue(resourcesList.size() == 0); - - /* Getting all ConsistsOf polymorphic and non polymorphic */ - - ConsistsOfManagement consistsOfManagement = (ConsistsOfManagement) ElementManagementUtility - .getERManagement(ConsistsOf.NAME); - - json = consistsOfManagement.all(true); - List consistsOfPolimorphicList = ElementMapper.unmarshalList(Resource.class, json); - logger.debug("{} are {} : {} ", IsRelatedTo.NAME, consistsOfPolimorphicList.size(), consistsOfPolimorphicList); - - json = consistsOfManagement.all(false); - List consistsOfNonPolimorphicList = ElementMapper.unmarshalList(Resource.class, json); - logger.debug("{} are {} : {} ", IsRelatedTo.NAME, consistsOfNonPolimorphicList.size(), - consistsOfNonPolimorphicList); - - Assert.assertTrue(consistsOfPolimorphicList.size() >= consistsOfNonPolimorphicList.size()); - - /* Removing created Entity and Relation to have a clean DB */ - - List resourceList = resources.get(HostingNode.NAME); - for (Resource r : resourceList) { - deleteResource(r); + public void testUpdateFacetValue() throws Exception { + EService eService =null; + try { + eService = createEService(); + + final String newVersion = "1.2.0"; + eService.getFacets(SoftwareFacet.class).get(0).setVersion(newVersion); + + ResourceManagement resourceManagement = getResourceManagement(eService); + + String json = resourceManagement.update(); + EService updatedEService = ElementMapper.unmarshal(EService.class, json); + + checkResource(eService, updatedEService); + + SoftwareFacet softwareFacet = updatedEService.getFacets(SoftwareFacet.class).get(0); + Assert.assertTrue(softwareFacet.getVersion().compareTo(newVersion) == 0); + + }finally { + deleteResource(eService); } } + - @Test - public void testGetAllFrom() throws Exception { - - Map map = ERManagementTest.createHostingNodeAndEService(); - - EService eService = (EService) map.get(EService.NAME); - UUID eServiceUUID = eService.getHeader().getUUID(); - - HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME); - UUID hostingNodeUUID = hostingNode.getHeader().getUUID(); - - 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, 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, - 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, - includeRelation); - resourceList = ElementMapper.unmarshalList(Resource.class, json); - Assert.assertTrue(resourceList.size() == 0); - - 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, - includeRelation); - resourceList = ElementMapper.unmarshalList(Resource.class, json); - Assert.assertTrue(resourceList.size() == 0); - 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 */ - - /* Getting EService */ - 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, - includeRelation); - resourceList = ElementMapper.unmarshalList(Resource.class, json); - Assert.assertTrue(resourceList.size() == 0); - - 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, includeRelation); - resourceList = ElementMapper.unmarshalList(Resource.class, json); - Assert.assertTrue(resourceList.size() == 0); - - 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, - includeRelation); - resourceList = ElementMapper.unmarshalList(Resource.class, json); - Assert.assertTrue(resourceList.size() == 0); - /* END Getting HostingNode */ - - Facet identificationFacet = eService.getIdentificationFacets().get(0); - UUID identificationFacetUUID = identificationFacet.getHeader().getUUID(); - - /* EService --ConsistsOf--> SoftwareFacet */ - try { - 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, includeRelation); - resourceList = ElementMapper.unmarshalList(Resource.class, json); - Assert.assertTrue(resourceList.size() == 1); - resource = resourceList.get(0); - Facet targetIdentificationFacet = ((GCubeResource) resource).getIdentificationFacets().get(0); - Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0); - Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID) == 0); - - try { - 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, includeRelation); - } catch (InvalidQueryException e) { - // Ok expected - } - - 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, includeRelation); - } catch (InvalidQueryException e) { - // Ok expected - } - - /* END EService --ConsistsOf--> SoftwareFacet */ - - /* Removing created Entity and Relation to have a clean DB */ - resourceManagement = new ResourceManagement(); - resourceManagement.setUUID(hostingNode.getHeader().getUUID()); - resourceManagement.delete(); - } // public static final String TEST_RESOURCE = "test-resource.json"; // @@ -795,27 +611,8 @@ public class ERManagementTest extends ContextTest { // // } - @Test - public void testUpdateFacetValue() throws Exception { - EService eService =null; - try { - eService = createEService(); - - final String newVersion = "1.2.0"; - eService.getFacets(SoftwareFacet.class).get(0).setVersion(newVersion); - ResourceManagement resourceManagement = getResourceManagement(eService); - String json = resourceManagement.update(); - EService updatedEService = ElementMapper.unmarshal(EService.class, json); - - checkResource(eService, updatedEService); - - Assert.assertTrue(updatedEService.getFacets(SoftwareFacet.class).get(0).getVersion().compareTo(newVersion) == 0); - - }finally { - deleteResource(eService); - } - } + } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/QueryTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/QueryTest.java new file mode 100644 index 0000000..bc19f43 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/instances/QueryTest.java @@ -0,0 +1,458 @@ +package org.gcube.informationsystem.resourceregistry.instances; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import org.gcube.common.authorization.client.exceptions.ObjectNotFound; +import org.gcube.informationsystem.model.reference.entities.Facet; +import org.gcube.informationsystem.model.reference.entities.Resource; +import org.gcube.informationsystem.model.reference.relations.ConsistsOf; +import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; +import org.gcube.informationsystem.resourceregistry.ContextTest; +import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; +import org.gcube.informationsystem.resourceregistry.api.utils.Utility; +import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; +import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; +import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement; +import org.gcube.informationsystem.resourceregistry.instances.model.relations.ConsistsOfManagement; +import org.gcube.informationsystem.resourceregistry.instances.model.relations.IsRelatedToManagement; +import org.gcube.informationsystem.utils.ElementMapper; +import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetImpl; +import org.gcube.resourcemanagement.model.impl.entities.facets.SimplePropertyFacetImpl; +import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl; +import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; +import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet; +import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType; +import org.gcube.resourcemanagement.model.reference.entities.facets.SimplePropertyFacet; +import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet; +import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration; +import org.gcube.resourcemanagement.model.reference.entities.resources.ConfigurationTemplate; +import org.gcube.resourcemanagement.model.reference.entities.resources.EService; +import org.gcube.resourcemanagement.model.reference.entities.resources.GCubeResource; +import org.gcube.resourcemanagement.model.reference.entities.resources.HostingNode; +import org.gcube.resourcemanagement.model.reference.entities.resources.Service; +import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; +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 QueryTest extends ContextTest { + + private static Logger logger = LoggerFactory.getLogger(QueryTest.class); + + private static final String EXTRA = "EXTRA"; + + + @Test + public void testGetAll() throws Exception { + Map> resources = new HashMap<>(); + + try { + final int MAX = 5; + int typeNumber = 0; + + for (int i = 0; i < MAX; i++) { + Map map = ERManagementTest.createHostingNodeAndEService(); + if (typeNumber == 0) { + typeNumber = map.size(); + } + for (String key : map.keySet()) { + if (!resources.containsKey(key)) { + resources.put(key, new ArrayList()); + } + resources.get(key).add(map.get(key)); + } + } + + /* Getting all instances of created specific Resources */ + for (String key : resources.keySet()) { + ResourceManagement resourceManagement = (ResourceManagement) ElementManagementUtility.getERManagement(key); + String json = resourceManagement.all(false); + + List list = ElementMapper.unmarshalList(Resource.class, json); + logger.debug("{} are {} : {} ", key, list.size(), list); + Assert.assertTrue(list.size() == MAX); + } + + /* Getting all Resources polymorphic and non polymorphic */ + + ResourceManagement resourceManagement = (ResourceManagement) ElementManagementUtility + .getERManagement(Resource.NAME); + + String json = resourceManagement.all(true); + List list = ElementMapper.unmarshalList(Resource.class, json); + logger.debug("{} are {} : {} ", Resource.NAME, list.size(), list); + Assert.assertTrue(list.size() == (MAX * typeNumber)); + + json = resourceManagement.all(false); + list = ElementMapper.unmarshalList(Resource.class, json); + Assert.assertTrue(list.size() == 0); + + /* Getting all IsRelatedTo polymorphic and non polymorphic */ + + IsRelatedToManagement isRelatedToManagement = (IsRelatedToManagement) ElementManagementUtility + .getERManagement(IsRelatedTo.NAME); + + json = isRelatedToManagement.all(true); + + List resourcesList = ElementMapper.unmarshalList(Resource.class, json); + logger.debug("{} are {} : {} ", IsRelatedTo.NAME, resourcesList.size(), resourcesList); + Assert.assertTrue(resourcesList.size() == MAX); + + json = isRelatedToManagement.all(false); + resourcesList = ElementMapper.unmarshalList(Resource.class, json); + Assert.assertTrue(resourcesList.size() == 0); + + /* Getting all ConsistsOf polymorphic and non polymorphic */ + + ConsistsOfManagement consistsOfManagement = (ConsistsOfManagement) ElementManagementUtility + .getERManagement(ConsistsOf.NAME); + + json = consistsOfManagement.all(true); + List consistsOfPolimorphicList = ElementMapper.unmarshalList(Resource.class, json); + logger.debug("{} are {} : {} ", IsRelatedTo.NAME, consistsOfPolimorphicList.size(), consistsOfPolimorphicList); + + json = consistsOfManagement.all(false); + List consistsOfNonPolimorphicList = ElementMapper.unmarshalList(Resource.class, json); + logger.debug("{} are {} : {} ", IsRelatedTo.NAME, consistsOfNonPolimorphicList.size(), + consistsOfNonPolimorphicList); + + Assert.assertTrue(consistsOfPolimorphicList.size() >= consistsOfNonPolimorphicList.size()); + } finally { + /* Removing created Entity and Relation to have a clean DB */ + + List resourceList = resources.get(HostingNode.NAME); + for (Resource r : resourceList) { + ERManagementTest.deleteResource(r); + } + } + } + + @Test + public void testGetAllFrom() throws Exception { + + Map map = ERManagementTest.createHostingNodeAndEService(); + EService eService = (EService) map.get(EService.NAME); + HostingNode hostingNode = (HostingNode) map.get(HostingNode.NAME); + + try { + UUID eServiceUUID = eService.getHeader().getUUID(); + UUID hostingNodeUUID = hostingNode.getHeader().getUUID(); + + 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, 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, + 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, + includeRelation); + resourceList = ElementMapper.unmarshalList(Resource.class, json); + Assert.assertTrue(resourceList.size() == 0); + + 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, + includeRelation); + resourceList = ElementMapper.unmarshalList(Resource.class, json); + Assert.assertTrue(resourceList.size() == 0); + 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 */ + + /* Getting EService */ + 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, + includeRelation); + resourceList = ElementMapper.unmarshalList(Resource.class, json); + Assert.assertTrue(resourceList.size() == 0); + + 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, includeRelation); + resourceList = ElementMapper.unmarshalList(Resource.class, json); + Assert.assertTrue(resourceList.size() == 0); + + 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, + includeRelation); + resourceList = ElementMapper.unmarshalList(Resource.class, json); + Assert.assertTrue(resourceList.size() == 0); + /* END Getting HostingNode */ + + Facet identificationFacet = eService.getIdentificationFacets().get(0); + UUID identificationFacetUUID = identificationFacet.getHeader().getUUID(); + + /* EService --ConsistsOf--> SoftwareFacet */ + try { + 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, includeRelation); + resourceList = ElementMapper.unmarshalList(Resource.class, json); + Assert.assertTrue(resourceList.size() == 1); + resource = resourceList.get(0); + Facet targetIdentificationFacet = ((GCubeResource) resource).getIdentificationFacets().get(0); + Assert.assertTrue(resource.getHeader().getUUID().compareTo(eServiceUUID) == 0); + Assert.assertTrue(targetIdentificationFacet.getHeader().getUUID().compareTo(identificationFacetUUID) == 0); + + try { + json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, ODirection.IN, + true, null, includeRelation); + throw new Exception("Expected InvalidQueryException"); + } catch (InvalidQueryException e) { + // Ok expected + } + + try { + json = resourceManagement.query(ConsistsOf.NAME, SoftwareFacet.NAME, identificationFacetUUID, + ODirection.BOTH, false, null, includeRelation); + throw new Exception("Expected InvalidQueryException"); + } catch (InvalidQueryException e) { + // Ok expected + } + + 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, includeRelation); + throw new Exception("Expected InvalidQueryException"); + } catch (InvalidQueryException e) { + // Ok expected + } + + /* END EService --ConsistsOf--> SoftwareFacet */ + + } finally { + ERManagementTest.deleteResource(eService); + ERManagementTest.deleteResource(hostingNode); + } + + } + + @Test + public void testQuery() throws ResourceRegistryException { + String relationType = ConsistsOf.NAME; + String facetType = SoftwareFacet.NAME; + + Map constraint = new HashMap<>(); + constraint.put(SoftwareFacet.GROUP_PROPERTY, "Gis"); + constraint.put(SoftwareFacet.NAME_PROPERTY, "Thredds"); + + String type = Service.NAME; + + @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, includeRelation); + logger.debug("Result of query for {}polymorphic {} --{}--> {} with constaint {} is {}", bool ? "" : "NOT ", + type, relationType, facetType, constraint, ret); + } + } + + + } + + protected Configuration createConfiguration(String name, Object value) throws Exception { + Configuration configuration = new ConfigurationImpl(); + + IdentifierFacet identifierFacet = new IdentifierFacetImpl(); + identifierFacet.setValue(name); + identifierFacet.setType(IdentificationType.STRING); + if(value!=null) { + identifierFacet.setAdditionalProperty(EXTRA, value); + } + + IsIdentifiedBy isIdentifiedBy = new IsIdentifiedByImpl(configuration, identifierFacet); + configuration.addFacet(isIdentifiedBy); + + SimplePropertyFacet simplePropertyFacet = new SimplePropertyFacetImpl(); + simplePropertyFacet.setName("test"); + simplePropertyFacet.setValue("test"); + configuration.addFacet(simplePropertyFacet); + + return ERManagementTest.createResource(configuration); + } + + + @Test + public void getAllResourcesHavingFacet() throws ObjectNotFound, Exception { + + String[] names = new String[]{"MyTest", "MyTest", "Aux", "MyID", "MyID"}; + Object[] additionalProperties = new Object[] {5, 5.0, false, "test", null}; + + List createdConfigurations = new ArrayList<>(); + + for(int i=0; i expectedUUIDFor2Results = new HashSet<>(); + expectedUUIDFor2Results.add(createdConfigurations.get(3).getHeader().getUUID()); + expectedUUIDFor2Results.add(createdConfigurations.get(4).getHeader().getUUID()); + + for(int i=0; i constraint = new HashMap<>(); + constraint.put(IdentifierFacet.VALUE_PROPERTY, names[i]); + if(additionalProperties[i]!=null) { + constraint.put(EXTRA, additionalProperties[i].toString()); + } + + logger.debug("Going to query for {}polymorphic {} --{}--> {} with constaints {}", polymorphic ? "" : "NOT ", + resourceType, relationType, referenceType, constraint); + + String ret = resourceManagement.query(relationType, referenceType, refereceUUID, directionEnum, + polymorphic, constraint, includeRelation); + + List list = ElementMapper.unmarshalList(Configuration.class, ret); + Assert.assertTrue(list.size()==expectedSize); + if(expectedSize==1) { + Configuration configuration = list.get(0); + UUID gotUUID = configuration.getHeader().getUUID(); + Assert.assertTrue(gotUUID.compareTo(expectedUUID)==0); + }else { + Set gotUUIDs = new HashSet<>(); + for(Configuration c : list) { + gotUUIDs.add(c.getHeader().getUUID()); + } + + Assert.assertTrue(gotUUIDs.containsAll(expectedUUIDFor2Results)); + Assert.assertTrue(expectedUUIDFor2Results.containsAll(gotUUIDs)); + + } + + + if(polymorphic) { + + logger.debug("Going to query for polymorphic {} --{}--> {} with constaints {}", + parentResourceType, relationType, referenceType, constraint); + + String retPolimorphic = parentResourceManagement.query(relationType, referenceType, refereceUUID, directionEnum, + polymorphic, constraint, includeRelation); + List listPolimorphic = ElementMapper.unmarshalList(ConfigurationTemplate.class, retPolimorphic); + Assert.assertTrue(listPolimorphic.size()==expectedSize); + + if(expectedSize==1) { + ConfigurationTemplate configurationTemplate = listPolimorphic.get(0); + Assert.assertTrue(configurationTemplate instanceof Configuration); + UUID gotPolimorphicUUID = configurationTemplate.getHeader().getUUID(); + Assert.assertTrue(gotPolimorphicUUID.compareTo(expectedUUID)==0); + }else { + Set gotUUIDs = new HashSet<>(); + for(ConfigurationTemplate c : listPolimorphic) { + Assert.assertTrue(c instanceof Configuration); + gotUUIDs.add(c.getHeader().getUUID()); + } + + Assert.assertTrue(gotUUIDs.containsAll(expectedUUIDFor2Results)); + Assert.assertTrue(expectedUUIDFor2Results.containsAll(gotUUIDs)); + + + } + + + + } + + } + } + } finally { + for(Configuration configuration : createdConfigurations) { + ERManagementTest.deleteResource(configuration); + } + } + + } + +} 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 deleted file mode 100644 index 0e319e4..0000000 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/instances/model/entity/ResourceManagementTest.java +++ /dev/null @@ -1,328 +0,0 @@ -package org.gcube.informationsystem.resourceregistry.instances.model.entity; - -import java.io.IOException; -import java.net.URI; -import java.net.URL; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -import org.gcube.common.authorization.client.exceptions.ObjectNotFound; -import org.gcube.informationsystem.model.reference.entities.Facet; -import org.gcube.informationsystem.model.reference.relations.ConsistsOf; -import org.gcube.informationsystem.resourceregistry.ContextTest; -import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.api.utils.Utility; -import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement; -import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility; -import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement; -import org.gcube.informationsystem.resourceregistry.tobereviewed.FacetManagementTest; -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.IdentifierFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.LicenseFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.SimplePropertyFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl; -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.IdentifierFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.LicenseFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.SimplePropertyFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType; -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.Configuration; -import org.gcube.resourcemanagement.model.reference.entities.resources.ConfigurationTemplate; -import org.gcube.resourcemanagement.model.reference.entities.resources.EService; -import org.gcube.resourcemanagement.model.reference.entities.resources.Service; -import org.gcube.resourcemanagement.model.reference.properties.ValueSchema; -import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; -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 ResourceManagementTest extends ContextTest { - - private static Logger logger = LoggerFactory.getLogger(ResourceManagementTest.class); - - public static void checkAssertion(EService eService, UUID eServiceUUID, boolean create) { - FacetManagementTest.checkHeader(eService, eServiceUUID, create); - - SoftwareFacet softwareFacet = eService.getFacets(SoftwareFacet.class).get(0); - FacetManagementTest.checkAssertion(softwareFacet, null, create); - } - - - @Test - public void createUpdateReadDelete() throws Exception { - - /* Creating EService*/ - EService eService = new EServiceImpl(); - - SoftwareFacet softwareFacet = FacetManagementTest.getSoftwareFacet(); - IsIdentifiedBy isIdentifiedBy = new IsIdentifiedByImpl( - eService, softwareFacet, null); - 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.trace("Created {}", json); - eService = ElementMapper.unmarshal(EService.class, json); - - checkAssertion(eService, null, true); - FacetManagementTest.checkSoftwareFacetAssertion(softwareFacet, FacetManagementTest.VERSION); - - UUID uuid = eService.getHeader().getUUID(); - softwareFacet = eService.getFacets(SoftwareFacet.class).get(0); - - - /* Updating a Facet of the EService via EServcie update */ - softwareFacet.setVersion(FacetManagementTest.NEW_VERSION); - - resourceManagement = new ResourceManagement(); - resourceManagement.setUUID(eService.getHeader().getUUID()); - resourceManagement.setJson(ElementMapper.marshal(eService)); - - json = resourceManagement.update(); - logger.trace("Updated {}", json); - eService = ElementMapper.unmarshal(EService.class, json); - - checkAssertion(eService, uuid, false); - softwareFacet = eService.getFacets(SoftwareFacet.class).get(0); - FacetManagementTest.checkSoftwareFacetAssertion(softwareFacet, FacetManagementTest.NEW_VERSION); - - - resourceManagement = new ResourceManagement(); - resourceManagement.setUUID(eService.getHeader().getUUID()); - - resourceManagement.delete(); - } - - - @Test - public void testQuery() throws ResourceRegistryException { - String relationType = ConsistsOf.NAME; - String facetType = SoftwareFacet.NAME; - - Map constraint = new HashMap<>(); - constraint.put(SoftwareFacet.GROUP_PROPERTY, "Gis"); - constraint.put(SoftwareFacet.NAME_PROPERTY, "Thredds"); - - String type = Service.NAME; - - @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, includeRelation); - logger.debug("Result of query for {}polymorphic {} --{}--> {} with constaint {} is {}", bool ? "" : "NOT ", - type, relationType, facetType, constraint, ret); - } - } - - - } - - private static final String EXTRA = "EXTRA"; - - protected Configuration createConfiguration(String name, Object value) throws ResourceRegistryException, IOException { - Configuration configuration = new ConfigurationImpl(); - - IdentifierFacet identifierFacet = new IdentifierFacetImpl(); - identifierFacet.setValue(name); - identifierFacet.setType(IdentificationType.STRING); - if(value!=null) { - identifierFacet.setAdditionalProperty(EXTRA, value); - } - - IsIdentifiedBy isIdentifiedBy = new IsIdentifiedByImpl(configuration, identifierFacet); - configuration.addFacet(isIdentifiedBy); - - SimplePropertyFacet simplePropertyFacet = new SimplePropertyFacetImpl(); - simplePropertyFacet.setName("test"); - simplePropertyFacet.setValue("test"); - configuration.addFacet(simplePropertyFacet); - - ResourceManagement resourceManagement = new ResourceManagement(); - resourceManagement.setElementType(Configuration.NAME); - resourceManagement.setJson(ElementMapper.marshal(configuration)); - String json = resourceManagement.create(); - logger.trace("Created {}", json); - configuration = ElementMapper.unmarshal(Configuration.class, json); - - return configuration; - } - - - @Test - public void getAllResourcesHavingFacet() throws ObjectNotFound, Exception { - - String[] names = new String[]{"MyTest", "MyTest", "Aux", "MyID", "MyID"}; - Object[] additionalProperties = new Object[] {5, 5.0, false, "test", null}; - - List createdConfigurations = new ArrayList<>(); - - for(int i=0; i expectedUUIDFor2Results = new HashSet<>(); - expectedUUIDFor2Results.add(createdConfigurations.get(3).getHeader().getUUID()); - expectedUUIDFor2Results.add(createdConfigurations.get(4).getHeader().getUUID()); - - for(int i=0; i constraint = new HashMap<>(); - constraint.put(IdentifierFacet.VALUE_PROPERTY, names[i]); - if(additionalProperties[i]!=null) { - constraint.put(EXTRA, additionalProperties[i].toString()); - } - - logger.debug("Going to query for {}polymorphic {} --{}--> {} with constaints {}", polymorphic ? "" : "NOT ", - resourceType, relationType, referenceType, constraint); - - String ret = resourceManagement.query(relationType, referenceType, refereceUUID, directionEnum, - polymorphic, constraint, includeRelation); - - List list = ElementMapper.unmarshalList(Configuration.class, ret); - Assert.assertTrue(list.size()==expectedSize); - if(expectedSize==1) { - Configuration configuration = list.get(0); - UUID gotUUID = configuration.getHeader().getUUID(); - Assert.assertTrue(gotUUID.compareTo(expectedUUID)==0); - }else { - Set gotUUIDs = new HashSet<>(); - for(Configuration c : list) { - gotUUIDs.add(c.getHeader().getUUID()); - } - - Assert.assertTrue(gotUUIDs.containsAll(expectedUUIDFor2Results)); - Assert.assertTrue(expectedUUIDFor2Results.containsAll(gotUUIDs)); - - } - - - if(polymorphic) { - - logger.debug("Going to query for polymorphic {} --{}--> {} with constaints {}", - parentResourceType, relationType, referenceType, constraint); - - String retPolimorphic = parentResourceManagement.query(relationType, referenceType, refereceUUID, directionEnum, - polymorphic, constraint, includeRelation); - List listPolimorphic = ElementMapper.unmarshalList(ConfigurationTemplate.class, retPolimorphic); - Assert.assertTrue(listPolimorphic.size()==expectedSize); - - if(expectedSize==1) { - ConfigurationTemplate configurationTemplate = listPolimorphic.get(0); - Assert.assertTrue(configurationTemplate instanceof Configuration); - UUID gotPolimorphicUUID = configurationTemplate.getHeader().getUUID(); - Assert.assertTrue(gotPolimorphicUUID.compareTo(expectedUUID)==0); - }else { - Set gotUUIDs = new HashSet<>(); - for(ConfigurationTemplate c : listPolimorphic) { - Assert.assertTrue(c instanceof Configuration); - gotUUIDs.add(c.getHeader().getUUID()); - } - - Assert.assertTrue(gotUUIDs.containsAll(expectedUUIDFor2Results)); - Assert.assertTrue(expectedUUIDFor2Results.containsAll(gotUUIDs)); - - - } - - - - } - - } - } - - for(Configuration configuration : createdConfigurations) { - ResourceManagement rManagement = new ResourceManagement(); - rManagement.setElementType(resourceType); - rManagement.setUUID(configuration.getHeader().getUUID()); - rManagement.delete(); - } - - } - -} diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/tobereviewed/FacetManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/tobereviewed/FacetManagementTest.java index 224d9fd..0300325 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/tobereviewed/FacetManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/tobereviewed/FacetManagementTest.java @@ -21,47 +21,8 @@ public class FacetManagementTest extends ContextTest { // private static Logger logger = LoggerFactory.getLogger(ERManagementTest.class); - public static final String GROUP = "InformationSystem"; - public static final String NAME = "resource-registry"; - public static final String VERSION = "1.0.0"; - public static final String NEW_VERSION = "2.0.0"; - public static SoftwareFacet getSoftwareFacet() { - SoftwareFacet softwareFacet = new SoftwareFacetImpl(); - softwareFacet.setGroup(GROUP); - softwareFacet.setName(NAME); - softwareFacet.setVersion(VERSION); - return softwareFacet; - } - public static void checkSoftwareFacetAssertion(SoftwareFacet softwareFacet, String version) { - Assert.assertTrue(softwareFacet.getGroup().compareTo(GROUP) == 0); - Assert.assertTrue(softwareFacet.getName().compareTo(NAME) == 0); - Assert.assertTrue(softwareFacet.getVersion().compareTo(version) == 0); - } - - public static void checkHeader(IdentifiableElement er, UUID uuid, boolean create) { - Assert.assertTrue(er.getHeader() != null); - Assert.assertTrue(er.getHeader().getUUID() != null); - - if(uuid != null) { - Assert.assertTrue(er.getHeader().getUUID().compareTo(uuid) == 0); - } - - String user = HeaderUtility.getUser(); - Assert.assertTrue(er.getHeader().getLastUpdateBy().compareTo(user) == 0); - - if(create) { - Assert.assertTrue(er.getHeader().getCreatedBy().compareTo(user) == 0); - Assert.assertTrue(er.getHeader().getCreationTime().compareTo(er.getHeader().getLastUpdateTime()) == 0); - } else { - Assert.assertTrue(er.getHeader().getCreationTime().before(er.getHeader().getLastUpdateTime())); - } - } - - public static void checkAssertion(Facet facet, UUID uuid, boolean create) { - checkHeader(facet, uuid, create); - } // // protected F create(F facet) throws Exception { // FacetManagement facetManagement = new FacetManagement();