diff --git a/pom.xml b/pom.xml index 5d971f5..cae97de 100644 --- a/pom.xml +++ b/pom.xml @@ -86,6 +86,11 @@ 1.0.13 test + + org.gcube.common + authorization-client + test + diff --git a/src/test/java/org/gcube/informationsystem/sweeper/ISSweeperPluginTest.java b/src/test/java/org/gcube/informationsystem/sweeper/ISSweeperPluginTest.java new file mode 100644 index 0000000..e93110b --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/sweeper/ISSweeperPluginTest.java @@ -0,0 +1,36 @@ +package org.gcube.informationsystem.sweeper; + +import org.gcube.common.authorization.client.exceptions.ObjectNotFound; +import org.gcube.common.scope.api.ScopeProvider; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ISSweeperPluginTest { + + private static Logger logger = LoggerFactory.getLogger(ISSweeperPluginTest.class); + + @Test + public void testLaunch() throws ObjectNotFound, Exception{ + String[] tokens = { + ScopedTest.GCUBE, + ScopedTest.GCUBE_DEVSEC, + ScopedTest.GCUBE_DEVSEC_DEVVRE, + ScopedTest.GCUBE_DEVNEXT, + ScopedTest.GCUBE_DEVNEXT_NEXTNEXT + }; + + for(String token : tokens){ + logger.info("\n\n\n-------------------------------------------------------------------------"); + ScopedTest.setContext(token); + try{ + ISSweeperPlugin isExporterPlugin = new ISSweeperPlugin(new ISSweeperPluginDeclaration()); + isExporterPlugin.launch(null); + }catch (Exception e) { + logger.error("Sweeper error on {}", ScopeProvider.instance.get(), e); + } + logger.info("\n\n\n"); + } + } + +} diff --git a/src/test/java/org/gcube/informationsystem/sweeper/ScopedTest.java b/src/test/java/org/gcube/informationsystem/sweeper/ScopedTest.java new file mode 100644 index 0000000..6828ee7 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/sweeper/ScopedTest.java @@ -0,0 +1,96 @@ +/** + * + */ +package org.gcube.informationsystem.sweeper; + +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.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; + + 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_DEVSEC; + ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC_DEVVRE; + + } + + 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(); + } + +}