changed the way to get the token in ScopedTest

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@141762 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-01-25 11:52:53 +00:00
parent 59f9fb2e98
commit 184cb662cb
3 changed files with 81 additions and 13 deletions

View File

@ -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);
}

View File

@ -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();
}

View File

@ -0,0 +1,7 @@
GCUBE_DEVNEXT=
GCUBE_DEVNEXT_NEXTNEXT=
GCUBE_DEVSEC=
GCUBE_DEVSEC_DEVVRE=