From 610d98c8740686141ffb3da3447fb991ca98b9c2 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 12 Jan 2017 15:39:53 +0000 Subject: [PATCH] Aligned client with new REST interface git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-client@141530 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 5 + .../client/proxy/Direction.java | 14 + .../client/proxy/ResourceRegistryClient.java | 40 +- .../proxy/ResourceRegistryClientImpl.java | 367 ++++++++++-------- .../client/proxy/ResourceRegistryQuery.java | 2 +- .../proxy/ResourceRegistryClientTest.java | 23 +- .../client/proxy/ScopedTest.java | 42 +- 7 files changed, 283 insertions(+), 210 deletions(-) create mode 100644 src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/Direction.java diff --git a/pom.xml b/pom.xml index e4319a4..0816a75 100644 --- a/pom.xml +++ b/pom.xml @@ -79,6 +79,11 @@ 1.0.13 test + + org.gcube.information-system + gcube-resources + test + diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/Direction.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/Direction.java new file mode 100644 index 0000000..3c183f6 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/Direction.java @@ -0,0 +1,14 @@ +/** + * + */ +package org.gcube.informationsystem.resourceregistry.client.proxy; + +/** + * @author Luca Frosini (ISTI - CNR) + * + */ +public enum Direction { + + in, out, both; + +} diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClient.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClient.java index 610c626..36d77b4 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClient.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClient.java @@ -1,37 +1,39 @@ package org.gcube.informationsystem.resourceregistry.client.proxy; +import java.util.List; import java.util.UUID; -import org.gcube.informationsystem.model.entity.Facet; -import org.gcube.informationsystem.model.entity.Resource; -import org.gcube.informationsystem.resourceregistry.api.exceptions.InvalidQueryException; +import org.gcube.informationsystem.model.ER; +import org.gcube.informationsystem.model.entity.Entity; +import org.gcube.informationsystem.model.relation.Relation; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; +import org.gcube.informationsystem.types.TypeBinder.TypeDefinition; /** * @author Luca Frosini (ISTI - CNR) */ public interface ResourceRegistryClient { - public Facet getFacet(UUID uuid) - throws FacetNotFoundException, ResourceRegistryException; + public ERType getInstance( + Class clazz, UUID uuid) throws ERNotFoundException, + ResourceRegistryException; - public F getFacet(Class clazz, UUID uuid) - throws FacetNotFoundException, ResourceRegistryException; + public List getInstances( + Class clazz, Boolean polymorphic) throws + ERException, SchemaException, ResourceRegistryException; - public String getFacetSchema(String facetType) - throws SchemaNotFoundException; - + public > List getInstancesFromEntity( + Class clazz, Boolean polymorphic, + UUID reference, Direction direction) throws + ERException, SchemaException, ResourceRegistryException; - public Resource getResource(UUID uuid) - throws ResourceNotFoundException, ResourceRegistryException; - - public R getResource(Class clazz, UUID uuid) - throws ResourceNotFoundException, ResourceRegistryException; - - public String getResourceSchema(String resourceType) + public List getSchema( + Class clazz, Boolean polymorphic) throws SchemaNotFoundException; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientImpl.java index 28f7a16..f346058 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientImpl.java @@ -12,8 +12,10 @@ import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.UUID; import javax.xml.ws.EndpointReference; @@ -25,120 +27,126 @@ import org.gcube.common.clients.delegates.AsyncProxyDelegate; import org.gcube.common.clients.delegates.ProxyDelegate; import org.gcube.common.scope.api.ScopeProvider; import org.gcube.informationsystem.impl.utils.Entities; -import org.gcube.informationsystem.model.entity.Facet; -import org.gcube.informationsystem.model.entity.Resource; -import org.gcube.informationsystem.resourceregistry.api.exceptions.InvalidQueryException; +import org.gcube.informationsystem.model.ER; +import org.gcube.informationsystem.model.entity.Entity; +import org.gcube.informationsystem.model.relation.Relation; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.facet.FacetNotFoundException; -import org.gcube.informationsystem.resourceregistry.api.exceptions.entity.resource.ResourceNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.er.ERNotFoundException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath; +import org.gcube.informationsystem.types.TypeBinder; +import org.gcube.informationsystem.types.TypeBinder.TypeDefinition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) - * + * */ public class ResourceRegistryClientImpl implements ResourceRegistryClient { private static final Logger logger = LoggerFactory .getLogger(ResourceRegistryClientImpl.class); - + private final AsyncProxyDelegate delegate; public static final String PATH_SEPARATOR = "/"; - - public final class RREntry implements Map.Entry { - + + public final class RREntry implements Entry { + private final K key; - private V value; + private V value; - public RREntry(K key, V value) { - this.key = key; - this.value = value; - } + public RREntry(K key, V value) { + this.key = key; + this.value = value; + } - @Override - public K getKey() { - return key; - } + @Override + public K getKey() { + return key; + } - @Override - public V getValue() { - return value; - } + @Override + public V getValue() { + return value; + } - @Override - public V setValue(V value) { - V old = this.value; - this.value = value; - return old; - } + @Override + public V setValue(V value) { + V old = this.value; + this.value = value; + return old; + } } - + public ResourceRegistryClientImpl(ProxyDelegate config) { this.delegate = new AsyncProxyDelegate(config); } - + protected enum HTTPMETHOD { GET, POST, PUT, DELETE; - + @Override - public String toString(){ + public String toString() { return this.name(); } } class HTTPInputs { - + public static final String PARAM_STARTER = "?"; public static final String PARAM_EQUALS = "="; public static final String PARAM_SEPARATOR = "&"; public static final String UTF8 = "UTF-8"; - - + protected final String path; protected final HTTPMETHOD method; protected final String urlParameters; - - protected String getParametersDataString(List> parameters) throws UnsupportedEncodingException { - if(parameters==null){ - return null; - } - + + protected String getParametersDataString( + List> parameters) + throws UnsupportedEncodingException { + if (parameters == null) { + return null; + } + StringBuilder result = new StringBuilder(); - boolean first = true; - for(Map.Entry entry : parameters){ - if (first) { - first = false; - } else { - result.append(PARAM_SEPARATOR); - } + boolean first = true; + for (Entry entry : parameters) { + if (first) { + first = false; + } else { + result.append(PARAM_SEPARATOR); + } - result.append(URLEncoder.encode(entry.getKey(), UTF8)); - result.append(PARAM_EQUALS); - result.append(URLEncoder.encode(entry.getValue(), UTF8)); + result.append(URLEncoder.encode(entry.getKey(), UTF8)); + result.append(PARAM_EQUALS); + result.append(URLEncoder.encode(entry.getValue(), UTF8)); - } + } + + return result.toString(); + } - return result.toString(); - } - /** * @param path * @param method * @param requestProperties - * @throws UnsupportedEncodingException + * @throws UnsupportedEncodingException */ public HTTPInputs(String path, HTTPMETHOD method, - List> parameters) throws UnsupportedEncodingException { + List> parameters) + throws UnsupportedEncodingException { super(); this.path = path; this.method = method; this.urlParameters = getParametersDataString(parameters); } - + /** * @return the path */ @@ -159,9 +167,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { public String getUrlParameters() { return urlParameters; } - + } - + class ResourceRegistryCall implements Call { protected final Class clazz; @@ -182,11 +190,12 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { protected HttpURLConnection getConnection(URL url, HTTPMETHOD method) throws Exception { /* - if(method!=HTTPMETHOD.POST && httpInputs.getUrlParameters()!=null){ - */ + * if(method!=HTTPMETHOD.POST && + * httpInputs.getUrlParameters()!=null){ + */ url = new URL(url + "?" + httpInputs.getUrlParameters()); - //} - + // } + HttpURLConnection connection = (HttpURLConnection) url .openConnection(); if (SecurityTokenProvider.instance.get() == null) { @@ -201,22 +210,21 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { SecurityTokenProvider.instance.get()); } connection.setDoOutput(true); - + connection.setRequestProperty("Content-type", "application/json"); - connection.setRequestProperty("User-Agent", ResourceRegistryClient.class.getSimpleName()); - + connection.setRequestProperty("User-Agent", + ResourceRegistryClient.class.getSimpleName()); + connection.setRequestMethod(method.toString()); - + /* - if(method==HTTPMETHOD.POST){ - connection.setDoOutput(true); - DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); - wr.writeBytes(httpInputs.getUrlParameters()); - wr.flush(); - wr.close(); - }*/ - - + * if(method==HTTPMETHOD.POST){ connection.setDoOutput(true); + * DataOutputStream wr = new + * DataOutputStream(connection.getOutputStream()); + * wr.writeBytes(httpInputs.getUrlParameters()); wr.flush(); + * wr.close(); } + */ + return connection; } @@ -229,10 +237,9 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { URL url = new URL(callUrl.toString()); HttpURLConnection connection = getConnection(url, httpInputs.method); - - logger.debug("Response code for {} is {} : {}", - connection.getURL(), - connection.getResponseCode(), + + logger.debug("Response code for {} is {} : {}", + connection.getURL(), connection.getResponseCode(), connection.getResponseMessage()); if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { @@ -249,141 +256,163 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { } } - String res = result.toString(); + String res = result.toString(); logger.trace("Server returned content : {}", res); - - if(String.class.isAssignableFrom(clazz)){ + + if (String.class.isAssignableFrom(clazz)) { return (C) res; } - + return Entities.unmarshal(clazz, res); } } - + @Override - public Facet getFacet(UUID uuid) - throws FacetNotFoundException, ResourceRegistryException { - return getFacet(Facet.class, uuid); - } - - @Override - public F getFacet(Class clazz, UUID uuid) - throws FacetNotFoundException, ResourceRegistryException { + public ERType getInstance(Class clazz, UUID uuid) + throws ERNotFoundException, ResourceRegistryException { + String type = clazz.getSimpleName(); try { - logger.info("Going to get {} ({}) with UUID {}", Facet.NAME, clazz.getSimpleName(), uuid); + logger.info("Going to get {} with UUID {}", type, uuid); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(AccessPath.ACCESS_PATH_PART); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(AccessPath.FACET_PATH_PART); - stringWriter.append(PATH_SEPARATOR); stringWriter.append(AccessPath.INSTANCE_PATH_PART); stringWriter.append(PATH_SEPARATOR); + stringWriter.append(type); + stringWriter.append(PATH_SEPARATOR); stringWriter.append(uuid.toString()); - HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(), HTTPMETHOD.GET, null); - - ResourceRegistryCall call = new ResourceRegistryCall<>(clazz, httpInputs); - - F f = delegate.make(call); - logger.info("Got {} ({}) with UUID {} is {}", Facet.NAME, clazz.getSimpleName(), uuid, f); - return f; - + HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(), + HTTPMETHOD.GET, null); + + ResourceRegistryCall call = new ResourceRegistryCall<>( + clazz, httpInputs); + + ERType erType = delegate.make(call); + logger.info("Got {} with UUID {} is {}", type, uuid, erType); + return erType; + } catch (Exception e) { - logger.error("Error getting {} with UUID {}", Facet.class.getSimpleName(), uuid, e); + logger.error("Error while getting {} with UUID {}", type, uuid, e); throw new ResourceRegistryException(e); } } @Override - public String getFacetSchema(String facetType) - throws SchemaNotFoundException { + public List getInstances(Class clazz, + Boolean polymorphic) throws ERNotFoundException, + ResourceRegistryException { + String type = clazz.getSimpleName(); try { - logger.info("Going to get {} schema", facetType); + logger.info("Going to get all instances of {} ", type); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(AccessPath.ACCESS_PATH_PART); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(AccessPath.FACET_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(AccessPath.SCHEMA_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(facetType); - - HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(), HTTPMETHOD.GET, null); - - ResourceRegistryCall call = new ResourceRegistryCall<>(String.class, httpInputs); - String schema = delegate.make(call); - logger.info("Got schema for {} is {}", facetType, schema); - return schema; - } catch (Exception e) { - logger.error("Error getting {} Schema for {}", Facet.class.getSimpleName(), facetType, e); - throw new SchemaNotFoundException(e); - } - } - - @Override - public Resource getResource(UUID uuid) - throws ResourceNotFoundException, ResourceRegistryException { - return getResource(Resource.class, uuid); - } - - @Override - public R getResource(Class clazz, UUID uuid) - throws ResourceNotFoundException, ResourceRegistryException { - try { - logger.info("Going to get {} ({}) with UUID {}", Resource.NAME, clazz.getSimpleName(), uuid); - StringWriter stringWriter = new StringWriter(); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(AccessPath.ACCESS_PATH_PART); - stringWriter.append(PATH_SEPARATOR); - stringWriter.append(AccessPath.RESOURCE_PATH_PART); - stringWriter.append(PATH_SEPARATOR); stringWriter.append(AccessPath.INSTANCE_PATH_PART); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(uuid.toString()); + stringWriter.append(type); + + List> parameters = new ArrayList<>(); + parameters.add(new RREntry( + AccessPath.POLYMORPHIC_PARAM, polymorphic.toString())); + + HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(), + HTTPMETHOD.GET, parameters); + + ResourceRegistryCall call = new ResourceRegistryCall<>( + String.class, httpInputs); + + String ret = delegate.make(call); + logger.info("Got instances of {} are {}", type, ret); + + return Entities.unmarshalList(clazz, ret); - HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(), HTTPMETHOD.GET, null); - - ResourceRegistryCall call = new ResourceRegistryCall<>(clazz, httpInputs); - - - R r = delegate.make(call); - logger.info("Got {} ({}) with UUID {} is {}", Resource.NAME, clazz.getSimpleName(), uuid, r); - return r; - } catch (Exception e) { - logger.error("Error getting {} with UUID {}", Resource.class.getSimpleName(), uuid, e); + logger.error("Error while getting {} instances", type, e); throw new ResourceRegistryException(e); } } @Override - public String getResourceSchema(String resourceType) - throws SchemaNotFoundException { + public > List getInstancesFromEntity( + Class clazz, Boolean polymorphic, UUID reference, + Direction direction) throws ERException, SchemaException, + ResourceRegistryException { + String type = clazz.getSimpleName(); try { - logger.info("Going to get {} schema", resourceType); + logger.info("Going to get all instances of {} from/to {}", type, + reference.toString()); StringWriter stringWriter = new StringWriter(); stringWriter.append(PATH_SEPARATOR); stringWriter.append(AccessPath.ACCESS_PATH_PART); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(AccessPath.RESOURCE_PATH_PART); + stringWriter.append(AccessPath.INSTANCE_PATH_PART); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(type); + + List> parameters = new ArrayList<>(); + parameters.add(new RREntry( + AccessPath.POLYMORPHIC_PARAM, polymorphic.toString())); + parameters.add(new RREntry(AccessPath.REFERENCE, + reference.toString())); + parameters.add(new RREntry(AccessPath.DIRECTION, + direction.toString())); + + HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(), + HTTPMETHOD.GET, parameters); + + ResourceRegistryCall call = new ResourceRegistryCall<>( + String.class, httpInputs); + + String ret = delegate.make(call); + logger.info("Got instances of {} from/to {} are {}", type, + reference.toString(), ret); + + return Entities.unmarshalList(clazz, ret); + + } catch (Exception e) { + logger.error("Error while getting instances of {} from/to {}", type, e); + throw new ResourceRegistryException(e); + } + } + + @Override + public List getSchema( + Class clazz, Boolean polymorphic) + throws SchemaNotFoundException { + + String type = clazz.getSimpleName(); + try { + logger.info("Going to get {} schema", type); + StringWriter stringWriter = new StringWriter(); + stringWriter.append(PATH_SEPARATOR); + stringWriter.append(AccessPath.ACCESS_PATH_PART); stringWriter.append(PATH_SEPARATOR); stringWriter.append(AccessPath.SCHEMA_PATH_PART); stringWriter.append(PATH_SEPARATOR); - stringWriter.append(resourceType); + stringWriter.append(type); - HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(), HTTPMETHOD.GET, null); - - ResourceRegistryCall call = new ResourceRegistryCall<>(String.class, httpInputs); - + List> parameters = new ArrayList<>(); + parameters.add(new RREntry( + AccessPath.POLYMORPHIC_PARAM, polymorphic.toString())); + + HTTPInputs httpInputs = new HTTPInputs(stringWriter.toString(), + HTTPMETHOD.GET, parameters); + + ResourceRegistryCall call = new ResourceRegistryCall<>( + String.class, httpInputs); String schema = delegate.make(call); - logger.info("Got schema for {} is {}", resourceType, schema); - return schema; - + logger.info("Got schema for {} is {}", type, schema); + + return TypeBinder.deserializeTypeDefinitions(schema); + } catch (Exception e) { - logger.error("Error getting {} Schema for {}", Resource.class.getSimpleName(), resourceType, e); + logger.error("Error while getting {}schema for {}", + polymorphic ? AccessPath.POLYMORPHIC_PARAM + " " : "", + type, e); throw new SchemaNotFoundException(e); } } diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryQuery.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryQuery.java index 38b4fe7..83ed1fe 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryQuery.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryQuery.java @@ -21,7 +21,7 @@ import org.gcube.common.clients.delegates.AsyncProxyDelegate; import org.gcube.common.clients.delegates.ProxyDelegate; import org.gcube.common.clients.exceptions.ServiceException; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.informationsystem.resourceregistry.api.exceptions.InvalidQueryException; +import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientTest.java index 41a566a..8bbb4d2 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientTest.java @@ -3,9 +3,13 @@ */ package org.gcube.informationsystem.resourceregistry.client.proxy; -import org.gcube.informationsystem.resourceregistry.api.exceptions.InvalidQueryException; +import java.util.List; + +import org.gcube.informationsystem.model.entity.facet.ContactFacet; +import org.gcube.informationsystem.model.entity.resource.HostingNode; +import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; -import org.junit.BeforeClass; +import org.gcube.informationsystem.types.TypeBinder.TypeDefinition; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,18 +18,13 @@ import org.slf4j.LoggerFactory; * @author Luca Frosini (ISTI - CNR) * */ -public class ResourceRegistryClientTest { +public class ResourceRegistryClientTest extends ScopedTest { private static Logger logger = LoggerFactory .getLogger(ResourceRegistryClientTest.class); protected ResourceRegistryClient resourceRegistryClient; - @BeforeClass - public static void beforeClass() throws Exception { - ScopedTest.beforeClass(); - } - public ResourceRegistryClientTest(){ resourceRegistryClient = ResourceRegistryClientFactory.create(); } @@ -39,14 +38,14 @@ public class ResourceRegistryClientTest { @Test public void testGetFacetSchema() throws SchemaNotFoundException { - String res = resourceRegistryClient.getFacetSchema("ContactFacet"); - logger.trace(res); + List typeDefinitions = resourceRegistryClient.getSchema(ContactFacet.class, true); + logger.trace("{}", typeDefinitions); } @Test public void testGetResourceSchema() throws SchemaNotFoundException { - String res = resourceRegistryClient.getResourceSchema("HostingNode"); - logger.trace(res); + List typeDefinitions = resourceRegistryClient.getSchema(HostingNode.class, true); + logger.trace("{}", typeDefinitions); } } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ScopedTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ScopedTest.java index f8990e2..26e1e0c 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ScopedTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ScopedTest.java @@ -25,10 +25,22 @@ public class ScopedTest { private static final Logger logger = LoggerFactory.getLogger(ScopedTest.class); - protected static final String PROPERTIES_FILENAME = "config.properties"; + protected static final String PROPERTIES_FILENAME = "token.properties"; - private static final String TOKEN_VARNAME = "TOKEN"; - private static final String TOKEN; + private static final String GCUBE_DEVNEXT_VARNAME = "GCUBE_DEVNEXT"; + public static final String GCUBE_DEVNEXT; + + private static final String GCUBE_DEVNEXT_NEXTNEXT_VARNAME = "GCUBE_DEVNEXT_NEXTNEXT"; + public static final String GCUBE_DEVNEXT_NEXTNEXT; + + public static final String GCUBE_DEVSEC_VARNAME = "GCUBE_DEVSEC"; + public static final String GCUBE_DEVSEC; + + public static final String GCUBE_DEVSEC_DEVVRE_VARNAME = "GCUBE_DEVSEC_DEVVRE"; + public static final String GCUBE_DEVSEC_DEVVRE; + + public static final String DEFAULT_TEST_SCOPE; + public static final String ALTERNATIVE_TEST_SCOPE; static { Properties properties = new Properties(); @@ -41,20 +53,32 @@ public class ScopedTest { throw new RuntimeException(e); } - TOKEN = properties.getProperty(TOKEN_VARNAME); + GCUBE_DEVNEXT = properties.getProperty(GCUBE_DEVNEXT_VARNAME); + GCUBE_DEVNEXT_NEXTNEXT = properties.getProperty(GCUBE_DEVNEXT_NEXTNEXT_VARNAME); + + GCUBE_DEVSEC = properties.getProperty(GCUBE_DEVSEC_VARNAME); + GCUBE_DEVSEC_DEVVRE = properties.getProperty(GCUBE_DEVSEC_DEVVRE_VARNAME); + + DEFAULT_TEST_SCOPE = GCUBE_DEVSEC; + ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC_DEVVRE; } - private static String getCurrentScope() throws ObjectNotFound, Exception{ - AuthorizationEntry authorizationEntry = Constants.authorizationService().get(TOKEN); + public static String getCurrentScope(String token) throws ObjectNotFound, Exception{ + AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token); String context = authorizationEntry.getContext(); - logger.info("Context of token {} is {}", TOKEN, context); + logger.info("Context of token {} is {}", token, context); return context; } + + public static void setContext(String token) throws ObjectNotFound, Exception{ + SecurityTokenProvider.instance.set(token); + ScopeProvider.instance.set(getCurrentScope(token)); + } + @BeforeClass public static void beforeClass() throws Exception{ - SecurityTokenProvider.instance.set(TOKEN); - ScopeProvider.instance.set(getCurrentScope()); + setContext(DEFAULT_TEST_SCOPE); } @AfterClass