diff --git a/src/test/java/org/gcube/informationsystem/sweeper/ISSweeperPluginSmartExecutorSchedulerTest.java b/src/test/java/org/gcube/informationsystem/sweeper/ISSweeperPluginSmartExecutorSchedulerTest.java index eabaab7..0e8fac9 100644 --- a/src/test/java/org/gcube/informationsystem/sweeper/ISSweeperPluginSmartExecutorSchedulerTest.java +++ b/src/test/java/org/gcube/informationsystem/sweeper/ISSweeperPluginSmartExecutorSchedulerTest.java @@ -30,9 +30,6 @@ public class ISSweeperPluginSmartExecutorSchedulerTest extends ScopedTest { @Before public void before() throws Exception{ - super.before(); - //ScopeProvider.instance.reset(); // Comment this to run the test. this line has been added to avoid unwanted launch - //ScopeProvider.instance.set("/gcube/devsec"); proxy = ExecutorPlugin.getExecutorProxy(ISSweeperPluginDeclaration.NAME).build(); Assert.assertNotNull(proxy); } @@ -44,7 +41,9 @@ public class ISSweeperPluginSmartExecutorSchedulerTest extends ScopedTest { inputs.put(ISSweeperPlugin.DEAD_DAYS_TIMEOUT, 3); LaunchParameter parameter = new LaunchParameter(ISSweeperPluginDeclaration.NAME, inputs); - parameter.setScheduling(scheduling); + if(scheduling!=null){ + parameter.setScheduling(scheduling); + } try { String uuidString = proxy.launch(parameter); @@ -56,11 +55,12 @@ public class ISSweeperPluginSmartExecutorSchedulerTest extends ScopedTest { } - @Test + //@Test public void cronExpPreviousMustBeTerminated() throws Exception { CronExpression cronExpression = new CronExpression("0 */10 * * * ?"); // every 10 minutes starting from now Scheduling scheduling = new Scheduling(cronExpression, true); scheduling.setGlobal(true); + UUID uuid = scheduleTest(scheduling); logger.debug("Launched with UUID : {}", uuid); } diff --git a/src/test/java/org/gcube/testutility/ScopedTest.java b/src/test/java/org/gcube/testutility/ScopedTest.java index d934c53..7a07e83 100644 --- a/src/test/java/org/gcube/testutility/ScopedTest.java +++ b/src/test/java/org/gcube/testutility/ScopedTest.java @@ -3,25 +3,86 @@ */ package org.gcube.testutility; +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.After; -import org.junit.Before; +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 DEFAULT_TEST_SCOPE; + public static final String ALTERNATIVE_TEST_SCOPE; + + static { + Properties properties = new Properties(); + InputStream input = ScopedTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME); - @Before - public void before() throws Exception{ - SecurityTokenProvider.instance.set(TestUtility.TOKEN); - ScopeProvider.instance.set("/gcube/devNext/NextNext"); + 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); + + DEFAULT_TEST_SCOPE = GCUBE_DEVNEXT; + ALTERNATIVE_TEST_SCOPE = GCUBE_DEVSEC; } - @After - public void after() throws Exception{ + 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(); } diff --git a/src/test/resources/token.properties.example b/src/test/resources/token.properties.example new file mode 100644 index 0000000..b1e5577 --- /dev/null +++ b/src/test/resources/token.properties.example @@ -0,0 +1,7 @@ +GCUBE_DEVNEXT= +GCUBE_DEVNEXT_NEXTNEXT= + +GCUBE_DEVSEC= +GCUBE_DEVSEC_DEVVRE= + +