From 9ae0a2a5224cb38e2f174ad2bac8e40d7eca9023 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 4 Nov 2020 19:15:49 +0100 Subject: [PATCH] Added contexts tests --- .../client/ResourceRegistryClientTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTest.java index 50c5f0b..e3075a1 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/client/ResourceRegistryClientTest.java @@ -9,10 +9,13 @@ import java.util.Map; import java.util.UUID; import org.gcube.com.fasterxml.jackson.core.JsonProcessingException; +import org.gcube.informationsystem.context.reference.entities.Context; +import org.gcube.informationsystem.context.reference.relations.IsParentOf; import org.gcube.informationsystem.model.impl.properties.HeaderImpl; import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.properties.Header; import org.gcube.informationsystem.model.reference.relations.IsRelatedTo; +import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; import org.gcube.informationsystem.types.reference.Type; @@ -25,6 +28,7 @@ import org.gcube.resourcemanagement.model.reference.entities.resources.EService; 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; @@ -155,5 +159,50 @@ public class ResourceRegistryClientTest extends ContextTest { } } + @Test + public void testGetAllContexts() throws Exception { + List contexts = resourceRegistryClient.getAllContext(); + logger.debug("{}", contexts); + + contexts = resourceRegistryClient.getAllContext(); + logger.debug("{}", contexts); + + ContextCache contextCache = ContextCache.getInstance(); + Map uuidToContextFullName = contextCache.getUUIDToContextFullNameAssociation(); + logger.debug("{}", uuidToContextFullName); + + + for(Context c : contexts) { + UUID uuid = c.getHeader().getUUID(); + if(c.getParent()!=null) { + IsParentOf isParentOf = c.getParent(); + Context parentContext = isParentOf.getSource(); + UUID parentUUID = parentContext.getHeader().getUUID(); + Assert.assertEquals(parentContext, contextCache.getContextByUUID(parentUUID)); + List children = parentContext.getChildren(); + boolean found = false; + for(IsParentOf ipo : children) { + if(ipo.equals(isParentOf)) { + found = true; + break; + } + } + Assert.assertTrue(found); + logger.debug("{} : {} (parent {} : {})", c.getHeader().getUUID(), contextCache.getContextFullNameByUUID(uuid), parentUUID, contextCache.getContextFullNameByUUID(parentUUID)); + }else { + logger.debug("{} : {}", c.getHeader().getUUID(), contextCache.getContextFullNameByUUID(uuid)); + } + } + + Context currentContext = resourceRegistryClient.getCurrentContext(); + logger.debug("Current context : {}", currentContext); + + for(Context c : contexts) { + UUID uuid = c.getHeader().getUUID(); + Context context = resourceRegistryClient.getContext(uuid); + String fullName = ContextCache.getInstance().getContextFullNameByUUID(uuid); + logger.debug("{} - {} : {}", uuid, fullName, context); + } + } }