From 97c810e1267b764b0fc03558dfe922c819ab8cbb Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 18 Dec 2017 14:37:22 +0000 Subject: [PATCH] Refs #10248: Create Resource Registry Schema Client Task-Url: https://support.d4science.org/issues/10248 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-schema-client@160650 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../ResourceRegistrySchemaClient.java | 2 +- .../ResourceRegistrySchemaClientFactory.java | 2 +- .../ResourceRegistrySchemaClientImpl.java | 2 +- .../ResourceRegistrySchemaClientTest.java | 11 ++ .../resourceregistry/schema/ScopedTest.java | 119 ++++++++++++++++++ 5 files changed, 133 insertions(+), 3 deletions(-) rename src/main/java/org/gcube/informationsystem/resourceregistry/{context => schema}/ResourceRegistrySchemaClient.java (94%) rename src/main/java/org/gcube/informationsystem/resourceregistry/{context => schema}/ResourceRegistrySchemaClientFactory.java (98%) rename src/main/java/org/gcube/informationsystem/resourceregistry/{context => schema}/ResourceRegistrySchemaClientImpl.java (98%) create mode 100644 src/test/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientTest.java create mode 100644 src/test/java/org/gcube/informationsystem/resourceregistry/schema/ScopedTest.java diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ResourceRegistrySchemaClient.java b/src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClient.java similarity index 94% rename from src/main/java/org/gcube/informationsystem/resourceregistry/context/ResourceRegistrySchemaClient.java rename to src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClient.java index 2410751..6837e65 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ResourceRegistrySchemaClient.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClient.java @@ -1,4 +1,4 @@ -package org.gcube.informationsystem.resourceregistry.context; +package org.gcube.informationsystem.resourceregistry.schema; import java.util.List; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ResourceRegistrySchemaClientFactory.java b/src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientFactory.java similarity index 98% rename from src/main/java/org/gcube/informationsystem/resourceregistry/context/ResourceRegistrySchemaClientFactory.java rename to src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientFactory.java index 7b5669a..22dbb53 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ResourceRegistrySchemaClientFactory.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientFactory.java @@ -1,4 +1,4 @@ -package org.gcube.informationsystem.resourceregistry.context; +package org.gcube.informationsystem.resourceregistry.schema; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ResourceRegistrySchemaClientImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientImpl.java similarity index 98% rename from src/main/java/org/gcube/informationsystem/resourceregistry/context/ResourceRegistrySchemaClientImpl.java rename to src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientImpl.java index 455c9c2..7ac369a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/context/ResourceRegistrySchemaClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientImpl.java @@ -1,4 +1,4 @@ -package org.gcube.informationsystem.resourceregistry.context; +package org.gcube.informationsystem.resourceregistry.schema; import java.io.StringWriter; import java.net.MalformedURLException; diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientTest.java new file mode 100644 index 0000000..758e00f --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/schema/ResourceRegistrySchemaClientTest.java @@ -0,0 +1,11 @@ +package org.gcube.informationsystem.resourceregistry.schema; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ResourceRegistrySchemaClientTest extends ScopedTest { + + private static Logger logger = LoggerFactory.getLogger(ResourceRegistrySchemaClientTest.class); + + +} diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/schema/ScopedTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/schema/ScopedTest.java new file mode 100644 index 0000000..74c040e --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/schema/ScopedTest.java @@ -0,0 +1,119 @@ +/** + * + */ +package org.gcube.informationsystem.resourceregistry.schema; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.gcube.common.authorization.client.Constants; +import org.gcube.common.authorization.client.exceptions.ObjectNotFound; +import org.gcube.common.authorization.library.AuthorizationEntry; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.informationsystem.resourceregistry.schema.ResourceRegistrySchemaClientFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Luca Frosini (ISTI - CNR) + * + */ +public class ScopedTest { + + private static final Logger logger = LoggerFactory.getLogger(ScopedTest.class); + + protected static final String PROPERTIES_FILENAME = "token.properties"; + + 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 GCUBE_VARNAME = "GCUBE"; + public static final String GCUBE; + + + public static final String DEFAULT_TEST_SCOPE; + public static final String ALTERNATIVE_TEST_SCOPE; + + + protected static final String REGISTRY_PROPERTIES_FILENAME = "registry.properties"; + public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL"; + public static final String RESOURCE_REGISTRY_URL; + + static { + Properties properties = new Properties(); + InputStream input = ScopedTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME); + + try { + // load the properties file + properties.load(input); + } catch (IOException e) { + throw new RuntimeException(e); + } + + 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); + + GCUBE = properties.getProperty(GCUBE_VARNAME); + + DEFAULT_TEST_SCOPE = GCUBE_DEVNEXT_NEXTNEXT; + ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC_DEVVRE; + + + properties = new Properties(); + input = ScopedTest.class.getClassLoader().getResourceAsStream(REGISTRY_PROPERTIES_FILENAME); + try { + // load the properties file + properties.load(input); + } catch (IOException e) { + throw new RuntimeException(e); + } + + RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY); + + if(RESOURCE_REGISTRY_URL!=null){ + ResourceRegistrySchemaClientFactory.forceToURL(RESOURCE_REGISTRY_URL); + } + + } + + 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); + 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{ + setContext(DEFAULT_TEST_SCOPE); + } + + @AfterClass + public static void afterClass() throws Exception{ + SecurityTokenProvider.instance.reset(); + ScopeProvider.instance.reset(); + } + +}