2016-09-14 18:09:03 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2017-04-03 18:44:47 +02:00
|
|
|
package org.gcube.informationsystem.resourceregistry.client;
|
2016-09-14 18:09:03 +02:00
|
|
|
|
2017-11-02 14:42:31 +01:00
|
|
|
import java.util.HashMap;
|
2017-01-12 16:39:53 +01:00
|
|
|
import java.util.List;
|
2017-11-02 14:42:31 +01:00
|
|
|
import java.util.Map;
|
2017-03-30 12:34:38 +02:00
|
|
|
import java.util.UUID;
|
2017-01-12 16:39:53 +01:00
|
|
|
|
2020-07-07 17:04:40 +02:00
|
|
|
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
2021-10-15 17:29:30 +02:00
|
|
|
import org.gcube.informationsystem.base.reference.Direction;
|
2021-10-25 11:38:58 +02:00
|
|
|
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
|
|
|
import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
|
2023-04-18 17:51:47 +02:00
|
|
|
import org.gcube.informationsystem.model.impl.properties.MetadataImpl;
|
2019-02-06 10:01:35 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
2023-04-18 17:51:47 +02:00
|
|
|
import org.gcube.informationsystem.model.reference.properties.Metadata;
|
2019-02-06 10:01:35 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
|
2020-11-04 19:15:49 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
2017-02-24 12:01:33 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
2021-10-25 10:59:44 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
|
2023-02-09 17:07:58 +01:00
|
|
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
2020-02-03 10:52:24 +01:00
|
|
|
import org.gcube.informationsystem.types.reference.Type;
|
2023-04-18 17:51:47 +02:00
|
|
|
import org.gcube.informationsystem.utils.UUIDManager;
|
2023-04-21 15:57:08 +02:00
|
|
|
import org.gcube.informationsystem.utils.UUIDUtility;
|
2019-02-06 10:18:06 +01:00
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.resources.HostingNodeImpl;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.ContactFacet;
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
|
|
|
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;
|
2019-12-05 12:13:45 +01:00
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
2020-11-04 19:15:49 +01:00
|
|
|
import org.junit.Assert;
|
2016-09-14 18:09:03 +02:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
2016-10-12 14:35:20 +02:00
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
2016-09-14 18:09:03 +02:00
|
|
|
*/
|
2019-02-13 12:29:22 +01:00
|
|
|
public class ResourceRegistryClientTest extends ContextTest {
|
2018-06-11 16:20:52 +02:00
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(ResourceRegistryClientTest.class);
|
2016-09-14 18:09:03 +02:00
|
|
|
|
2016-10-18 10:52:05 +02:00
|
|
|
protected ResourceRegistryClient resourceRegistryClient;
|
|
|
|
|
2018-06-11 16:20:52 +02:00
|
|
|
public ResourceRegistryClientTest() {
|
2022-07-25 11:07:32 +02:00
|
|
|
if(ContextTest.RESOURCE_REGISTRY_URL !=null && !ContextTest.RESOURCE_REGISTRY_URL.isEmpty()) {
|
|
|
|
resourceRegistryClient = new ResourceRegistryClientImpl(ContextTest.RESOURCE_REGISTRY_URL);
|
|
|
|
}else {
|
|
|
|
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
|
|
|
}
|
2023-05-17 18:11:56 +02:00
|
|
|
resourceRegistryClient.setIncludeMeta(true);
|
2016-10-18 10:52:05 +02:00
|
|
|
}
|
|
|
|
|
2016-09-14 18:09:03 +02:00
|
|
|
@Test
|
2018-06-11 16:20:52 +02:00
|
|
|
public void testQuery() throws ResourceRegistryException {
|
2022-07-19 14:04:26 +02:00
|
|
|
String res = resourceRegistryClient.rawQuery("SELECT FROM V");
|
2016-10-31 17:05:00 +01:00
|
|
|
logger.trace(res);
|
2016-09-14 18:09:03 +02:00
|
|
|
}
|
2016-10-18 10:52:05 +02:00
|
|
|
|
2016-10-27 17:51:22 +02:00
|
|
|
@Test
|
2017-02-24 12:01:33 +01:00
|
|
|
public void testGetFacetSchema() throws SchemaNotFoundException, ResourceRegistryException {
|
2022-02-09 13:20:48 +01:00
|
|
|
List<Type> typeDefinitions = resourceRegistryClient.getType(ContactFacet.class, true);
|
2017-01-12 16:39:53 +01:00
|
|
|
logger.trace("{}", typeDefinitions);
|
2016-10-27 17:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-02-24 12:01:33 +01:00
|
|
|
public void testGetResourceSchema() throws SchemaNotFoundException, ResourceRegistryException {
|
2022-02-09 13:20:48 +01:00
|
|
|
List<Type> typeDefinitions = resourceRegistryClient.getType(HostingNode.class, true);
|
2017-01-12 16:39:53 +01:00
|
|
|
logger.trace("{}", typeDefinitions);
|
2016-10-27 17:51:22 +02:00
|
|
|
}
|
|
|
|
|
2017-02-23 17:08:04 +01:00
|
|
|
interface Aux extends Service {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-11 16:20:52 +02:00
|
|
|
@Test(expected = SchemaNotFoundException.class)
|
2017-02-24 12:01:33 +01:00
|
|
|
public void testException() throws SchemaNotFoundException, ResourceRegistryException {
|
2023-05-17 18:11:56 +02:00
|
|
|
resourceRegistryClient.getType("Aux", true);
|
2017-02-23 17:08:04 +01:00
|
|
|
}
|
|
|
|
|
2018-06-12 19:13:34 +02:00
|
|
|
/* The following tests are commented because we need to create the instances for tests. this is done in
|
|
|
|
* resource registry publisher, which uses client APis to test the publishing as weel as this client.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// @Test
|
2017-11-13 12:46:08 +01:00
|
|
|
public void testExists() throws ResourceRegistryException {
|
2017-10-30 14:01:59 +01:00
|
|
|
UUID uuid = UUID.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
|
2022-02-09 13:20:48 +01:00
|
|
|
resourceRegistryClient.existInstance(EService.NAME, uuid);
|
2017-03-30 12:34:38 +02:00
|
|
|
}
|
2017-02-23 17:08:04 +01:00
|
|
|
|
2018-06-12 19:13:34 +02:00
|
|
|
// @Test
|
2023-04-21 15:57:08 +02:00
|
|
|
public void testExistsByClass() throws Exception {
|
|
|
|
UUID uuid = UUIDUtility.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
|
2022-02-09 13:20:48 +01:00
|
|
|
resourceRegistryClient.existInstance(EService.class, uuid);
|
2017-10-30 14:01:59 +01:00
|
|
|
}
|
|
|
|
|
2018-06-12 19:13:34 +02:00
|
|
|
// @Test
|
2023-04-21 15:57:08 +02:00
|
|
|
public void testGetInstance() throws Exception {
|
|
|
|
UUID uuid = UUIDUtility.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
|
2017-11-13 12:46:08 +01:00
|
|
|
String eService = resourceRegistryClient.getInstance(EService.NAME, uuid);
|
|
|
|
logger.trace("{}", eService);
|
|
|
|
}
|
|
|
|
|
2018-06-12 19:13:34 +02:00
|
|
|
// @Test
|
2023-04-21 15:57:08 +02:00
|
|
|
public void testGetInstanceByClass() throws Exception {
|
|
|
|
UUID uuid = UUIDUtility.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
|
2017-11-13 12:46:08 +01:00
|
|
|
EService eService = resourceRegistryClient.getInstance(EService.class, uuid);
|
|
|
|
logger.trace("{}", eService);
|
|
|
|
}
|
|
|
|
|
2019-01-17 12:01:16 +01:00
|
|
|
@Test
|
2017-10-30 14:01:59 +01:00
|
|
|
public void testGetInstances() throws ResourceRegistryException {
|
2017-11-13 12:46:08 +01:00
|
|
|
String eServices = resourceRegistryClient.getInstances(EService.NAME, true);
|
|
|
|
logger.trace("{}", eServices);
|
|
|
|
}
|
|
|
|
|
2019-01-17 12:01:16 +01:00
|
|
|
@Test
|
2017-11-13 12:46:08 +01:00
|
|
|
public void testGetInstancesByClass() throws ResourceRegistryException {
|
|
|
|
List<EService> eServices = resourceRegistryClient.getInstances(EService.class, true);
|
|
|
|
logger.trace("{}", eServices);
|
2017-10-30 14:01:59 +01:00
|
|
|
}
|
2017-11-02 14:42:31 +01:00
|
|
|
|
2019-01-17 12:01:16 +01:00
|
|
|
@Test
|
2018-06-11 16:20:52 +02:00
|
|
|
public void testGetRelatedResourcesByClasses() throws ResourceRegistryException {
|
|
|
|
List<EService> eServices = resourceRegistryClient.getRelatedResources(EService.class, IsRelatedTo.class,
|
2020-10-01 14:40:36 +02:00
|
|
|
Resource.class, Direction.OUT, true);
|
2017-11-13 12:46:08 +01:00
|
|
|
logger.trace("{}", eServices);
|
|
|
|
}
|
|
|
|
|
2018-06-12 19:13:34 +02:00
|
|
|
// @Test
|
2023-04-21 15:57:08 +02:00
|
|
|
public void testGetRelatedResourcesFromReferenceResourceByClasses() throws Exception {
|
|
|
|
UUID uuid = UUIDUtility.fromString("b0d15e45-62af-4221-b785-7d014f10e631");
|
2017-11-13 12:46:08 +01:00
|
|
|
HostingNode hostingNode = new HostingNodeImpl();
|
2023-04-28 11:45:23 +02:00
|
|
|
hostingNode.setID(uuid);
|
2023-04-18 17:51:47 +02:00
|
|
|
Metadata metadata = new MetadataImpl();
|
|
|
|
hostingNode.setMetadata(metadata);
|
2018-06-11 16:20:52 +02:00
|
|
|
List<EService> eServices = resourceRegistryClient.getRelatedResourcesFromReferenceResource(EService.class,
|
2021-07-07 17:35:49 +02:00
|
|
|
IsRelatedTo.class, hostingNode, Direction.OUT, true);
|
2017-11-13 12:46:08 +01:00
|
|
|
logger.trace("{}", eServices);
|
|
|
|
}
|
|
|
|
|
2019-01-17 12:01:16 +01:00
|
|
|
@Test
|
2018-06-11 16:20:52 +02:00
|
|
|
public void testGetFilteredResourcesByClasses() throws ResourceRegistryException, JsonProcessingException {
|
2019-01-17 11:18:02 +01:00
|
|
|
Map<String,String> map = new HashMap<>();
|
2017-11-13 12:46:08 +01:00
|
|
|
map.put("group", "VREManagement");
|
|
|
|
map.put("name", "SmartExecutor");
|
2018-06-11 16:20:52 +02:00
|
|
|
List<EService> eServices = resourceRegistryClient.getFilteredResources(EService.class, IsIdentifiedBy.class,
|
|
|
|
SoftwareFacet.class, true, map);
|
|
|
|
for(EService eService : eServices) {
|
2020-02-03 10:52:24 +01:00
|
|
|
logger.trace("{}", ElementMapper.marshal(eService));
|
2018-06-11 16:20:52 +02:00
|
|
|
}
|
2017-11-13 12:46:08 +01:00
|
|
|
}
|
|
|
|
|
2018-06-11 16:20:52 +02:00
|
|
|
|
2018-06-12 19:13:34 +02:00
|
|
|
// @Test
|
2018-06-11 16:20:52 +02:00
|
|
|
public void testGetResourcesFromReferenceFacet() throws ResourceRegistryException, JsonProcessingException {
|
|
|
|
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
|
2023-04-28 11:45:23 +02:00
|
|
|
softwareFacet.setID(UUIDManager.getInstance().generateValidUUID());
|
2023-04-18 17:51:47 +02:00
|
|
|
Metadata metadata = new MetadataImpl();
|
|
|
|
softwareFacet.setMetadata(metadata);
|
2021-07-07 17:35:49 +02:00
|
|
|
List<EService> eServices = resourceRegistryClient.getResourcesFromReferenceFacet(EService.class, IsIdentifiedBy.class, softwareFacet, true);
|
2017-11-02 14:42:31 +01:00
|
|
|
for(EService eService : eServices) {
|
2020-02-03 10:52:24 +01:00
|
|
|
logger.trace("{}", ElementMapper.marshal(eService));
|
2017-11-02 14:42:31 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-13 12:46:08 +01:00
|
|
|
|
2020-11-04 19:15:49 +01:00
|
|
|
@Test
|
|
|
|
public void testGetAllContexts() throws Exception {
|
|
|
|
List<Context> contexts = resourceRegistryClient.getAllContext();
|
|
|
|
logger.debug("{}", contexts);
|
|
|
|
|
|
|
|
ContextCache contextCache = ContextCache.getInstance();
|
|
|
|
Map<UUID, String> uuidToContextFullName = contextCache.getUUIDToContextFullNameAssociation();
|
|
|
|
logger.debug("{}", uuidToContextFullName);
|
|
|
|
|
|
|
|
|
|
|
|
for(Context c : contexts) {
|
2023-04-28 11:45:23 +02:00
|
|
|
UUID uuid = c.getID();
|
2020-11-04 19:15:49 +01:00
|
|
|
if(c.getParent()!=null) {
|
|
|
|
IsParentOf isParentOf = c.getParent();
|
|
|
|
Context parentContext = isParentOf.getSource();
|
2023-04-28 11:45:23 +02:00
|
|
|
UUID parentUUID = parentContext.getID();
|
2020-11-04 19:15:49 +01:00
|
|
|
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);
|
2023-04-28 11:45:23 +02:00
|
|
|
logger.debug("{} : {} (parent {} : {})", c.getID(), contextCache.getContextFullNameByUUID(uuid), parentUUID, contextCache.getContextFullNameByUUID(parentUUID));
|
2020-11-04 19:15:49 +01:00
|
|
|
}else {
|
2023-04-28 11:45:23 +02:00
|
|
|
logger.debug("{} : {}", c.getID(), contextCache.getContextFullNameByUUID(uuid));
|
2020-11-04 19:15:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Context currentContext = resourceRegistryClient.getCurrentContext();
|
|
|
|
logger.debug("Current context : {}", currentContext);
|
|
|
|
|
|
|
|
for(Context c : contexts) {
|
2023-04-28 11:45:23 +02:00
|
|
|
UUID uuid = c.getID();
|
2020-11-04 19:15:49 +01:00
|
|
|
Context context = resourceRegistryClient.getContext(uuid);
|
|
|
|
String fullName = ContextCache.getInstance().getContextFullNameByUUID(uuid);
|
|
|
|
logger.debug("{} - {} : {}", uuid, fullName, context);
|
|
|
|
}
|
|
|
|
}
|
2018-06-11 16:20:52 +02:00
|
|
|
|
2016-09-14 18:09:03 +02:00
|
|
|
}
|