From 5c539ab5a72161c2fa4ac617e65479c90d1fc727 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 15 Nov 2019 12:06:01 +0100 Subject: [PATCH] Migrating library to new IS model --- .../exporter/mapper/GCoreResourceMapper.java | 2 +- .../mapper/GenericResourceExporter.java | 4 +- .../mapper/ServiceEndpointExporter.java | 4 +- .../exporter/ContextTest.java | 98 ++++++++----------- .../exporter/ISExporterPluginTest.java | 45 ++++----- .../mapper/GCoreResourceMapperTest.java | 12 +-- .../mapper/ServiceEndpointExporterTest.java | 2 +- src/test/resources/.gitignore | 1 + src/test/resources/registry.properties | 1 + src/test/resources/registry.properties.test | 2 +- 10 files changed, 71 insertions(+), 100 deletions(-) create mode 100644 src/test/resources/.gitignore create mode 100644 src/test/resources/registry.properties diff --git a/src/main/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapper.java b/src/main/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapper.java index ba88d52..fff4255 100644 --- a/src/main/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapper.java +++ b/src/main/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapper.java @@ -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; diff --git a/src/main/java/org/gcube/informationsystem/exporter/mapper/GenericResourceExporter.java b/src/main/java/org/gcube/informationsystem/exporter/mapper/GenericResourceExporter.java index 7f39c5e..369c6a3 100644 --- a/src/main/java/org/gcube/informationsystem/exporter/mapper/GenericResourceExporter.java +++ b/src/main/java/org/gcube/informationsystem/exporter/mapper/GenericResourceExporter.java @@ -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; diff --git a/src/main/java/org/gcube/informationsystem/exporter/mapper/ServiceEndpointExporter.java b/src/main/java/org/gcube/informationsystem/exporter/mapper/ServiceEndpointExporter.java index b45c5c6..5a61fdf 100644 --- a/src/main/java/org/gcube/informationsystem/exporter/mapper/ServiceEndpointExporter.java +++ b/src/main/java/org/gcube/informationsystem/exporter/mapper/ServiceEndpointExporter.java @@ -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; diff --git a/src/test/java/org/gcube/informationsystem/exporter/ContextTest.java b/src/test/java/org/gcube/informationsystem/exporter/ContextTest.java index 95fd120..332e5c1 100644 --- a/src/test/java/org/gcube/informationsystem/exporter/ContextTest.java +++ b/src/test/java/org/gcube/informationsystem/exporter/ContextTest.java @@ -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(); - 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(); - input = ContextTest.class.getClassLoader().getResourceAsStream(REGISTRY_PROPERTIES_FILENAME); - + InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME); + try { // load the properties file 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) { 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(); } diff --git a/src/test/java/org/gcube/informationsystem/exporter/ISExporterPluginTest.java b/src/test/java/org/gcube/informationsystem/exporter/ISExporterPluginTest.java index cade6cc..200ae54 100644 --- a/src/test/java/org/gcube/informationsystem/exporter/ISExporterPluginTest.java +++ b/src/test/java/org/gcube/informationsystem/exporter/ISExporterPluginTest.java @@ -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 inputs = new HashMap(); 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(); diff --git a/src/test/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapperTest.java b/src/test/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapperTest.java index 2bb6fd2..4cd6047 100644 --- a/src/test/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapperTest.java +++ b/src/test/java/org/gcube/informationsystem/exporter/mapper/GCoreResourceMapperTest.java @@ -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); diff --git a/src/test/java/org/gcube/informationsystem/exporter/mapper/ServiceEndpointExporterTest.java b/src/test/java/org/gcube/informationsystem/exporter/mapper/ServiceEndpointExporterTest.java index bcc955e..a8bb378 100644 --- a/src/test/java/org/gcube/informationsystem/exporter/mapper/ServiceEndpointExporterTest.java +++ b/src/test/java/org/gcube/informationsystem/exporter/mapper/ServiceEndpointExporterTest.java @@ -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(); diff --git a/src/test/resources/.gitignore b/src/test/resources/.gitignore new file mode 100644 index 0000000..a8e4366 --- /dev/null +++ b/src/test/resources/.gitignore @@ -0,0 +1 @@ +/token.properties diff --git a/src/test/resources/registry.properties b/src/test/resources/registry.properties new file mode 100644 index 0000000..6b3141f --- /dev/null +++ b/src/test/resources/registry.properties @@ -0,0 +1 @@ +url=http://pc-frosini.isti.cnr.it:8080/resource-registry \ No newline at end of file diff --git a/src/test/resources/registry.properties.test b/src/test/resources/registry.properties.test index cd70085..6b3141f 100644 --- a/src/test/resources/registry.properties.test +++ b/src/test/resources/registry.properties.test @@ -1 +1 @@ -RESOURCE_REGISTRY_URL=http://pc-frosini.isti.cnr.it:8080/resource-registry \ No newline at end of file +url=http://pc-frosini.isti.cnr.it:8080/resource-registry \ No newline at end of file