94 lines
2.5 KiB
Java
94 lines
2.5 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.informationsystem.resourceregistry;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.util.Properties;
|
|
|
|
import org.gcube.common.security.providers.SecretManagerProvider;
|
|
import org.gcube.common.security.secrets.CredentialSecret;
|
|
import org.gcube.common.security.secrets.Secret;
|
|
import org.junit.AfterClass;
|
|
import org.junit.BeforeClass;
|
|
|
|
/**
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
*/
|
|
public class ContextTest {
|
|
|
|
protected static final String CONFIG_INI_FILENAME = "config.ini";
|
|
|
|
public static final String PARENT_DEFAULT_TEST_SCOPE;
|
|
public static final String DEFAULT_TEST_SCOPE;
|
|
public static final String ALTERNATIVE_TEST_SCOPE;
|
|
|
|
public static final String GCUBE;
|
|
public static final String DEVNEXT;
|
|
public static final String NEXTNEXT;
|
|
public static final String DEVSEC;
|
|
public static final String DEVVRE;
|
|
|
|
protected static final Properties properties;
|
|
|
|
protected static final String CLIENT_ID_PROPERTY_KEY = "client_id";
|
|
protected static final String CLIENT_SECRET_PROPERTY_KEY = "client_secret";
|
|
|
|
protected static final String clientID;
|
|
protected static final String clientSecret;
|
|
|
|
static {
|
|
GCUBE = "/gcube";
|
|
DEVNEXT = GCUBE + "/devNext";
|
|
NEXTNEXT = DEVNEXT + "/NextNext";
|
|
DEVSEC = GCUBE + "/devsec";
|
|
DEVVRE = DEVSEC + "/devVRE";
|
|
|
|
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
|
DEFAULT_TEST_SCOPE = DEVNEXT;
|
|
ALTERNATIVE_TEST_SCOPE = NEXTNEXT;
|
|
|
|
properties = new Properties();
|
|
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(CONFIG_INI_FILENAME);
|
|
try {
|
|
// load the properties file
|
|
properties.load(input);
|
|
|
|
clientID = properties.getProperty(CLIENT_ID_PROPERTY_KEY);
|
|
clientSecret = properties.getProperty(CLIENT_SECRET_PROPERTY_KEY);
|
|
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
|
|
}
|
|
|
|
public static void set(Secret secret) throws Exception {
|
|
SecretManagerProvider.instance.reset();
|
|
SecretManagerProvider.instance.set(secret);
|
|
}
|
|
|
|
public static void setContextByName(String fullContextName) throws Exception {
|
|
Secret secret = getSecretByContextName(fullContextName);
|
|
set(secret);
|
|
}
|
|
|
|
|
|
private static Secret getSecretByContextName(String fullContextName) throws Exception {
|
|
CredentialSecret credentialSecret = new CredentialSecret(clientID, clientSecret, fullContextName);
|
|
return credentialSecret;
|
|
}
|
|
|
|
@BeforeClass
|
|
public static void beforeClass() throws Exception {
|
|
setContextByName(DEFAULT_TEST_SCOPE);
|
|
}
|
|
|
|
@AfterClass
|
|
public static void afterClass() throws Exception {
|
|
SecretManagerProvider.instance.reset();
|
|
}
|
|
|
|
}
|