Migrating library to new IS model

This commit is contained in:
Luca Frosini 2019-11-15 12:06:01 +01:00
parent 24e68f02db
commit 5c539ab5a7
10 changed files with 71 additions and 100 deletions

View File

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

View File

@ -6,11 +6,11 @@ import java.util.UUID;
import org.gcube.common.resources.gcore.GenericResource; import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.GenericResource.Profile; 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.impl.relations.IsIdentifiedByImpl;
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; 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.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsIdentifiedBy; import org.gcube.informationsystem.model.reference.relations.IsIdentifiedBy;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;

View File

@ -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.ServiceEndpoint.Runtime;
import org.gcube.common.resources.gcore.common.Platform; import org.gcube.common.resources.gcore.common.Platform;
import org.gcube.common.resources.gcore.utils.Group; 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.EncryptedImpl;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl; import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
import org.gcube.informationsystem.model.impl.relations.IsIdentifiedByImpl; import org.gcube.informationsystem.model.impl.relations.IsIdentifiedByImpl;
import org.gcube.informationsystem.model.reference.entities.Facet; import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource; import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.properties.Encrypted; 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.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsIdentifiedBy; import org.gcube.informationsystem.model.reference.relations.IsIdentifiedBy;
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException; import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;

View File

@ -10,7 +10,10 @@ import java.util.Properties;
import org.gcube.common.authorization.client.Constants; import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound; import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry; 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.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactorySetter; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactorySetter;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactorySetter; import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactorySetter;
@ -21,97 +24,76 @@ import org.slf4j.LoggerFactory;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*
*/ */
public class ContextTest { public class ContextTest {
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class); 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 DEFAULT_TEST_SCOPE_NAME;
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;
static { static {
Properties properties = new Properties();
InputStream input = ContextTest.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;
properties = new Properties(); properties = new Properties();
input = ContextTest.class.getClassLoader().getResourceAsStream(REGISTRY_PROPERTIES_FILENAME); InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
try { try {
// load the properties file // load the properties file
properties.load(input); properties.load(input);
} catch(IOException e) {
throw new RuntimeException(e);
}
//DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE";
DEFAULT_TEST_SCOPE_NAME = "/gcube/devNext/NextNext";
try {
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) { } catch (IOException e) {
throw new RuntimeException(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); AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext(); String context = authorizationEntry.getContext();
logger.info("Context of token {} is {}", token, context); logger.info("Context of token {} is {}", token, context);
return 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); 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)); ScopeProvider.instance.set(getCurrentScope(token));
} }
@BeforeClass @BeforeClass
public static void beforeClass() throws Exception{ public static void beforeClass() throws Exception {
setContext(DEFAULT_TEST_SCOPE); setContextByName(DEFAULT_TEST_SCOPE_NAME);
} }
@AfterClass @AfterClass
public static void afterClass() throws Exception{ public static void afterClass() throws Exception {
SecurityTokenProvider.instance.reset(); SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset(); ScopeProvider.instance.reset();
} }

View File

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

View File

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

View File

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

1
src/test/resources/.gitignore vendored Normal file
View File

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

View File

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

View File

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