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
|
|
|
|
2017-11-13 12:46:08 +01:00
|
|
|
import org.gcube.informationsystem.impl.embedded.HeaderImpl;
|
|
|
|
import org.gcube.informationsystem.impl.entity.resource.HostingNodeImpl;
|
2017-11-02 14:42:31 +01:00
|
|
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
2017-11-13 12:46:08 +01:00
|
|
|
import org.gcube.informationsystem.model.embedded.Header;
|
2017-01-12 16:39:53 +01:00
|
|
|
import org.gcube.informationsystem.model.entity.facet.ContactFacet;
|
2017-11-02 14:42:31 +01:00
|
|
|
import org.gcube.informationsystem.model.entity.facet.SoftwareFacet;
|
2017-03-30 12:34:38 +02:00
|
|
|
import org.gcube.informationsystem.model.entity.resource.EService;
|
2017-01-12 16:39:53 +01:00
|
|
|
import org.gcube.informationsystem.model.entity.resource.HostingNode;
|
2017-02-23 17:08:04 +01:00
|
|
|
import org.gcube.informationsystem.model.entity.resource.Service;
|
2017-11-02 14:42:31 +01:00
|
|
|
import org.gcube.informationsystem.model.relation.IsIdentifiedBy;
|
2017-02-24 12:01:33 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
2016-10-27 17:51:22 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException;
|
2017-01-12 16:39:53 +01:00
|
|
|
import org.gcube.informationsystem.types.TypeBinder.TypeDefinition;
|
2016-09-14 18:09:03 +02:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2017-11-02 14:42:31 +01:00
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
2016-09-14 18:09:03 +02:00
|
|
|
/**
|
2016-10-12 14:35:20 +02:00
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
2016-09-14 18:09:03 +02:00
|
|
|
*/
|
2017-01-12 16:39:53 +01:00
|
|
|
public class ResourceRegistryClientTest extends ScopedTest {
|
2016-09-14 18:09:03 +02:00
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory
|
|
|
|
.getLogger(ResourceRegistryClientTest.class);
|
|
|
|
|
2016-10-18 10:52:05 +02:00
|
|
|
protected ResourceRegistryClient resourceRegistryClient;
|
|
|
|
|
2016-11-04 16:52:41 +01:00
|
|
|
public ResourceRegistryClientTest(){
|
2016-10-18 10:52:05 +02:00
|
|
|
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
|
|
|
}
|
|
|
|
|
2016-09-14 18:09:03 +02:00
|
|
|
@Test
|
2017-04-03 18:44:47 +02:00
|
|
|
public void testQuery() throws ResourceRegistryException{
|
2016-10-18 10:52:05 +02:00
|
|
|
String res = resourceRegistryClient.query("SELECT FROM V", 0, null);
|
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 {
|
2017-01-12 16:39:53 +01:00
|
|
|
List<TypeDefinition> typeDefinitions = resourceRegistryClient.getSchema(ContactFacet.class, true);
|
|
|
|
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 {
|
2017-01-12 16:39:53 +01:00
|
|
|
List<TypeDefinition> typeDefinitions = resourceRegistryClient.getSchema(HostingNode.class, true);
|
|
|
|
logger.trace("{}", typeDefinitions);
|
2016-10-27 17:51:22 +02:00
|
|
|
}
|
|
|
|
|
2017-02-23 17:08:04 +01:00
|
|
|
interface Aux extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-24 11:00:12 +01:00
|
|
|
@Test(expected=SchemaNotFoundException.class)
|
2017-02-24 12:01:33 +01:00
|
|
|
public void testException() throws SchemaNotFoundException, ResourceRegistryException {
|
2017-02-24 11:00:12 +01:00
|
|
|
resourceRegistryClient.getSchema(Aux.class, true);
|
2017-02-23 17:08:04 +01:00
|
|
|
}
|
|
|
|
|
2017-10-30 14:01:59 +01:00
|
|
|
@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");
|
2017-11-13 12:46:08 +01:00
|
|
|
resourceRegistryClient.exists(EService.NAME, uuid);
|
2017-03-30 12:34:38 +02:00
|
|
|
}
|
2017-02-23 17:08:04 +01:00
|
|
|
|
2017-10-30 14:01:59 +01:00
|
|
|
@Test
|
2017-11-13 12:46:08 +01:00
|
|
|
public void testExistsByClass() throws ResourceRegistryException {
|
2017-10-30 14:01:59 +01:00
|
|
|
UUID uuid = UUID.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
|
|
|
|
resourceRegistryClient.exists(EService.class, uuid);
|
|
|
|
}
|
|
|
|
|
2017-11-13 12:46:08 +01:00
|
|
|
@Test
|
|
|
|
public void testGetInstance() throws ResourceRegistryException {
|
|
|
|
UUID uuid = UUID.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
|
|
|
|
String eService = resourceRegistryClient.getInstance(EService.NAME, uuid);
|
|
|
|
logger.trace("{}", eService);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetInstanceByClass() throws ResourceRegistryException {
|
|
|
|
UUID uuid = UUID.fromString("bdaccb35-7f27-45a6-8ca9-11d467cb9233");
|
|
|
|
EService eService = resourceRegistryClient.getInstance(EService.class, uuid);
|
|
|
|
logger.trace("{}", eService);
|
|
|
|
}
|
|
|
|
|
2017-10-30 14:01:59 +01:00
|
|
|
@Test
|
|
|
|
public void testGetInstances() throws ResourceRegistryException {
|
2017-11-13 12:46:08 +01:00
|
|
|
String eServices = resourceRegistryClient.getInstances(EService.NAME, true);
|
|
|
|
logger.trace("{}", eServices);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
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
|
|
|
|
2017-11-13 12:46:08 +01:00
|
|
|
@Test
|
|
|
|
public void testGetInstancesFromEntity() throws ResourceRegistryException {
|
|
|
|
UUID uuid = UUID.fromString("b0d15e45-62af-4221-b785-7d014f10e631");
|
|
|
|
String eServices = resourceRegistryClient.getInstancesFromEntity(EService.NAME, true, uuid, Direction.out);
|
|
|
|
logger.trace("{}", eServices);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetInstancesFromEntityByClass() throws ResourceRegistryException {
|
|
|
|
UUID uuid = UUID.fromString("b0d15e45-62af-4221-b785-7d014f10e631");
|
|
|
|
List<EService> eServices = resourceRegistryClient.getInstancesFromEntity(EService.class, true, uuid, Direction.out);
|
|
|
|
logger.trace("{}", eServices);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetInstancesFromEntityByClasses() throws ResourceRegistryException {
|
|
|
|
UUID uuid = UUID.fromString("b0d15e45-62af-4221-b785-7d014f10e631");
|
|
|
|
HostingNode hostingNode = new HostingNodeImpl();
|
|
|
|
Header header = new HeaderImpl(uuid);
|
|
|
|
hostingNode.setHeader(header);
|
|
|
|
List<EService> eServices = resourceRegistryClient.getInstancesFromEntity(EService.class, true, hostingNode, Direction.out);
|
|
|
|
logger.trace("{}", eServices);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-02 14:42:31 +01:00
|
|
|
@Test
|
|
|
|
public void testGetFilteredResources() throws ResourceRegistryException, JsonProcessingException {
|
2017-11-13 12:46:08 +01:00
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
map.put("group", "VREManagement");
|
|
|
|
map.put("name", "SmartExecutor");
|
|
|
|
String json = resourceRegistryClient.getFilteredResources(EService.NAME, IsIdentifiedBy.NAME, SoftwareFacet.NAME, true, map);
|
|
|
|
logger.trace(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testGetFilteredResourcesByClasses() throws ResourceRegistryException, JsonProcessingException {
|
2017-11-02 14:42:31 +01:00
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
map.put("group", "VREManagement");
|
|
|
|
map.put("name", "SmartExecutor");
|
|
|
|
List<EService> eServices = resourceRegistryClient.getFilteredResources(EService.class, IsIdentifiedBy.class, SoftwareFacet.class, true, map);
|
|
|
|
for(EService eService : eServices) {
|
|
|
|
logger.trace("{}", ISMapper.marshal(eService));
|
|
|
|
}
|
|
|
|
}
|
2017-11-13 12:46:08 +01:00
|
|
|
|
2016-09-14 18:09:03 +02:00
|
|
|
}
|