Migrating library to new IS model

model-reorganization
Luca Frosini 4 years ago
parent 24e68f02db
commit 5c539ab5a7

@ -19,9 +19,9 @@ import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.resources.gcore.Resources;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.base.reference.ISConstants;
import org.gcube.informationsystem.exporter.mapper.exception.CreateException;
import org.gcube.informationsystem.exporter.mapper.exception.UpdateException;
import org.gcube.informationsystem.model.reference.ISConstants;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;

@ -6,11 +6,11 @@ import java.util.UUID;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.GenericResource.Profile;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.base.impl.properties.HeaderImpl;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.model.impl.relations.IsIdentifiedByImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsIdentifiedBy;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;

@ -11,14 +11,14 @@ import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
import org.gcube.common.resources.gcore.ServiceEndpoint.Runtime;
import org.gcube.common.resources.gcore.common.Platform;
import org.gcube.common.resources.gcore.utils.Group;
import org.gcube.informationsystem.base.impl.properties.HeaderImpl;
import org.gcube.informationsystem.base.reference.properties.Header;
import org.gcube.informationsystem.model.impl.properties.EncryptedImpl;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.impl.relations.IsIdentifiedByImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Encrypted;
import org.gcube.informationsystem.model.reference.properties.Header;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsIdentifiedBy;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;

@ -10,7 +10,10 @@ 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.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactorySetter;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactorySetter;
@ -21,97 +24,76 @@ import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class ContextTest {
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
protected static final String PROPERTIES_FILENAME = "token.properties";
protected static Properties properties;
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;
protected static final String REGISTRY_PROPERTIES_FILENAME = "registry.properties";
public static final String RESOURCE_REGISTRY_URL_PROPERTY = "RESOURCE_REGISTRY_URL";
public static final String RESOURCE_REGISTRY_URL;
public static final String DEFAULT_TEST_SCOPE_NAME;
static {
Properties properties = new Properties();
properties = new Properties();
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
try {
// load the properties file
properties.load(input);
} catch (IOException e) {
} 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;
properties = new Properties();
input = ContextTest.class.getClassLoader().getResourceAsStream(REGISTRY_PROPERTIES_FILENAME);
//DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE";
DEFAULT_TEST_SCOPE_NAME = "/gcube/devNext/NextNext";
try {
// load the properties file
properties.load(input);
Properties registryProperties = new Properties();
InputStream registryInputStream = ContextTest.class.getClassLoader().getResourceAsStream("registry.properties");
registryProperties.load(registryInputStream);
String url = registryProperties.getProperty("url");
if(url!=null){
ResourceRegistryPublisherFactorySetter.forceToURL(url);
ResourceRegistryClientFactorySetter.forceToURL(url);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
RESOURCE_REGISTRY_URL = properties.getProperty(RESOURCE_REGISTRY_URL_PROPERTY);
if(RESOURCE_REGISTRY_URL!=null){
ResourceRegistryPublisherFactorySetter.forceToURL(RESOURCE_REGISTRY_URL);
ResourceRegistryClientFactorySetter.forceToURL(RESOURCE_REGISTRY_URL);
}
}
public static String getCurrentScope(String token) throws ObjectNotFound, 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 setContextByName(String fullContextName) throws ObjectNotFound, Exception {
String token = ContextTest.properties.getProperty(fullContextName);
setContext(token);
}
public static void setContext(String token) throws ObjectNotFound, Exception{
public static void setContext(String token) throws ObjectNotFound, Exception {
SecurityTokenProvider.instance.set(token);
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
ClientInfo clientInfo = authorizationEntry.getClientInfo();
logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
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(DEFAULT_TEST_SCOPE);
public static void beforeClass() throws Exception {
setContextByName(DEFAULT_TEST_SCOPE_NAME);
}
@AfterClass
public static void afterClass() throws Exception{
public static void afterClass() throws Exception {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
}

@ -14,40 +14,35 @@ public class ISExporterPluginTest {
private static Logger logger = LoggerFactory.getLogger(ISExporterPluginTest.class);
@Test
// @Test
public void testLaunch() throws ObjectNotFound, Exception {
String[] tokens = {
ContextTest.GCUBE,
ContextTest.GCUBE_DEVSEC,
ContextTest.GCUBE_DEVSEC_DEVVRE,
ContextTest.GCUBE_DEVNEXT,
ContextTest.GCUBE_DEVNEXT_NEXTNEXT
String[] contexts = {
"/gcube", "/gcube/devNext", "/gcube/devNext/NextNext" //, "/gcube/devsec", "/gcube/devsec/devVRE"
};
for(String token : tokens) {
for(String context : contexts) {
logger.info("\n\n\n-------------------------------------------------------------------------");
ContextTest.setContext(token);
ContextTest.setContextByName(context);
ISExporterPlugin isExporterPlugin = new ISExporterPlugin(new ISExporterPluginDeclaration());
Map<String,Object> inputs = new HashMap<String,Object>();
inputs.put(ISExporterPlugin.FILTERED_REPORT, true);
inputs.put(ISExporterPlugin.STATISTICS, true);
inputs.put(ISExporterPlugin.STATISTICS, false);
isExporterPlugin.launch(inputs);
logger.info("\n\n\n");
}
}
// @Test
@Test
public void export() throws ObjectNotFound, Exception {
String[] tokens = {
ContextTest.GCUBE,
ContextTest.GCUBE_DEVSEC,
ContextTest.GCUBE_DEVSEC_DEVVRE,
// ContextTest.GCUBE_DEVNEXT,
// ContextTest.GCUBE_DEVNEXT_NEXTNEXT
String[] contexts = {
// "/gcube", "/gcube/devNext",
"/gcube/devNext/NextNext" //,
// "/gcube/devsec", "/gcube/devsec/devVRE"
};
for(String token : tokens) {
ContextTest.setContext(token);
for(String context : contexts) {
ContextTest.setContextByName(context);
GenericResourceExporterTest genericResourceExporterTest = new GenericResourceExporterTest();
genericResourceExporterTest.export();
@ -59,16 +54,12 @@ public class ISExporterPluginTest {
//@Test
public void removeExported() throws ObjectNotFound, Exception {
String[] tokens = {
ContextTest.GCUBE,
ContextTest.GCUBE_DEVSEC,
ContextTest.GCUBE_DEVSEC_DEVVRE,
ContextTest.GCUBE_DEVNEXT,
ContextTest.GCUBE_DEVNEXT_NEXTNEXT
String[] contexts = {
"/gcube", "/gcube/devNext", "/gcube/devNext/NextNext", "/gcube/devsec", "/gcube/devsec/devVRE"
};
for(String token : tokens) {
ContextTest.setContext(token);
for(String context : contexts) {
ContextTest.setContextByName(context);
GenericResourceExporterTest genericResourceExporterTest = new GenericResourceExporterTest();
genericResourceExporterTest.removeExported();

@ -38,17 +38,13 @@ public class GCoreResourceMapperTest extends ContextTest {
//@Test
public void testWorkspace() throws Exception {
String[] tokens = {
ContextTest.GCUBE,
ContextTest.GCUBE_DEVSEC,
ContextTest.GCUBE_DEVSEC_DEVVRE,
ContextTest.GCUBE_DEVNEXT,
ContextTest.GCUBE_DEVNEXT_NEXTNEXT
String[] contexts = {
"/gcube", "/gcube/devNext", "/gcube/devNext/NextNext" //, "/gcube/devsec", "/gcube/devsec/devVRE"
};
for(String token : tokens){
for(String context : contexts) {
logger.info("\n\n\n-------------------------------------------------------------------------");
ContextTest.setContext(token);
ContextTest.setContextByName(context);
GenericResourceExporter gre = new GenericResourceExporter(false, false);
File file = getReportFile(gre);
logger.info("\n\n\n {}", file);

@ -67,7 +67,7 @@ public class ServiceEndpointExporterTest extends ContextTest{
// @Test
public void investigateSingleResource() throws Exception {
ContextTest.setContext(GCUBE_DEVSEC);
ContextTest.setContextByName("/gcube/devNext");
UUID uuid = UUID.fromString("");
//ResourceRegistryPublisher publisher = ResourceRegistryPublisherFactory.create();

@ -0,0 +1 @@
/token.properties

@ -0,0 +1 @@
url=http://pc-frosini.isti.cnr.it:8080/resource-registry

@ -1 +1 @@
RESOURCE_REGISTRY_URL=http://pc-frosini.isti.cnr.it:8080/resource-registry
url=http://pc-frosini.isti.cnr.it:8080/resource-registry
Loading…
Cancel
Save