Added contexts tests
This commit is contained in:
parent
5477715aa1
commit
9ae0a2a522
|
@ -9,10 +9,13 @@ import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
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.impl.properties.HeaderImpl;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||||
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
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.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
||||||
import org.gcube.informationsystem.types.reference.Type;
|
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.HostingNode;
|
||||||
import org.gcube.resourcemanagement.model.reference.entities.resources.Service;
|
import org.gcube.resourcemanagement.model.reference.entities.resources.Service;
|
||||||
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||||
|
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;
|
||||||
|
@ -155,5 +159,50 @@ public class ResourceRegistryClientTest extends ContextTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAllContexts() throws Exception {
|
||||||
|
List<Context> contexts = resourceRegistryClient.getAllContext();
|
||||||
|
logger.debug("{}", contexts);
|
||||||
|
|
||||||
|
contexts = resourceRegistryClient.getAllContext();
|
||||||
|
logger.debug("{}", contexts);
|
||||||
|
|
||||||
|
ContextCache contextCache = ContextCache.getInstance();
|
||||||
|
Map<UUID, String> 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<IsParentOf> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue