From d94a7a44360b78f8071fe86ec5e301cf4ce02d9e Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 20 Jul 2018 14:14:33 +0000 Subject: [PATCH] Fixing project git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/resource-registry-database-creator@169892 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 6 +- .../resourceregistry/ScopedTest.java | 87 +++++++++++++++++++ .../context/ContextManagementTest.java | 8 +- src/test/resources/logback-test.xml | 2 +- src/test/resources/production-scopedata.xml | 53 ----------- 5 files changed, 98 insertions(+), 58 deletions(-) create mode 100644 src/test/java/org/gcube/informationsystem/resourceregistry/ScopedTest.java delete mode 100644 src/test/resources/production-scopedata.xml diff --git a/pom.xml b/pom.xml index 2ce09d2..15eac61 100644 --- a/pom.xml +++ b/pom.xml @@ -53,13 +53,15 @@ org.gcube.information-system gcube-resources - + + + org.gcube.common context-enumeration diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/ScopedTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/ScopedTest.java new file mode 100644 index 0000000..efcbae5 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/ScopedTest.java @@ -0,0 +1,87 @@ +/** + * + */ +package org.gcube.informationsystem.resourceregistry; + +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.AuthorizationProvider; +import org.gcube.common.authorization.library.provider.ClientInfo; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.authorization.library.utils.Caller; +import org.gcube.common.scope.api.ScopeProvider; +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_VARNAME = "GCUBE"; + public static final String GCUBE; + + private static final String PROD_VARNAME = "PROD"; + public static final String PROD; + + 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 = properties.getProperty(GCUBE_VARNAME); + + PROD = properties.getProperty(PROD_VARNAME); + + } + + 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); + AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token); + ClientInfo clientInfo = authorizationEntry.getClientInfo(); + logger.info("Owner of token is {}", clientInfo.getId()); + + String qualifier = authorizationEntry.getQualifier(); + Caller caller = new Caller(clientInfo, qualifier); + AuthorizationProvider.instance.set(caller); + ScopeProvider.instance.set(getCurrentScope(token)); + } + + @BeforeClass + public static void beforeClass() throws Exception{ + setContext(GCUBE); + } + + @AfterClass + public static void afterClass() throws Exception{ + SecurityTokenProvider.instance.reset(); + ScopeProvider.instance.reset(); + } + +} diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java index 7e70844..d955330 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementTest.java @@ -6,6 +6,7 @@ import java.util.UUID; import org.gcube.informationsystem.impl.entity.ContextImpl; import org.gcube.informationsystem.impl.utils.ISMapper; import org.gcube.informationsystem.model.entity.Context; +import org.gcube.informationsystem.resourceregistry.ScopedTest; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.junit.Test; import org.slf4j.Logger; @@ -48,11 +49,14 @@ public class ContextManagementTest { } @Test - public void createProductionContext() throws Exception { + public void createContexts() throws Exception { ContextCreator contextCreator = new ContextCreator(); contextCreator.all(); } - + @Test + public void testContext() throws Exception { + ScopedTest.setContext(ScopedTest.PROD); + } } diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml index fa86414..e8ffc3a 100644 --- a/src/test/resources/logback-test.xml +++ b/src/test/resources/logback-test.xml @@ -10,7 +10,7 @@ - + diff --git a/src/test/resources/production-scopedata.xml b/src/test/resources/production-scopedata.xml deleted file mode 100644 index a84d476..0000000 --- a/src/test/resources/production-scopedata.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - d4science - - - d4science - ServiceMap_d4science.research-infrastructures.eu.xml - /d4science.research-infrastructures.eu - - - d4science/D4Research - ServiceMap_D4Research.xml - /d4science.research-infrastructures.eu/D4Research - - - d4science/Edison - ServiceMap_Edison.xml - /d4science.research-infrastructures.eu/Edison - - - d4science/FARM - ServiceMap_FARM.xml - /d4science.research-infrastructures.eu/FARM - - - d4science/gCubeApps - ServiceMap_gCubeApps.xml - /d4science.research-infrastructures.eu/gCubeApps - - - d4science/OpenAIRE - ServiceMap_OpenAIRE.xml - /d4science.research-infrastructures.eu/OpenAIRE - - - d4science/ParthenosVO - ServiceMap_ParthenosVO.xml - /d4science.research-infrastructures.eu/ParthenosVO - - - d4science/SmartArea - ServiceMap_SmartArea.xml - /d4science.research-infrastructures.eu/SmartArea - - - d4science/SoBigData - ServiceMap_SoBigData.xml - /d4science.research-infrastructures.eu/SoBigData - - - -