diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/EntityManagementTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/EntityManagementTest.java index cb3f76c..73f9381 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/EntityManagementTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/EntityManagementTest.java @@ -6,7 +6,6 @@ package org.gcube.informationsystem.resourceregistry.publisher; import java.util.List; import java.util.UUID; -import org.gcube.common.scope.api.ScopeProvider; import org.gcube.informationsystem.impl.entity.facet.CPUFacetImpl; import org.gcube.informationsystem.impl.entity.facet.NetworkingFacetImpl; import org.gcube.informationsystem.impl.entity.facet.SoftwareFacetImpl; @@ -35,7 +34,7 @@ import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) */ -public class EntityManagementTest { +public class EntityManagementTest extends ScopedTest { private static final Logger logger = LoggerFactory.getLogger(EntityManagementTest.class); @@ -43,8 +42,8 @@ public class EntityManagementTest { protected ResourceRegistryPublisher resourceRegistryPublisher; @Before - public void before(){ - ScopeProvider.instance.set("/gcube/devNext/NextNext"); + public void before() throws Exception { + super.before(); resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/RRClientTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/RRClientTest.java index 884d5ac..f9af18f 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/RRClientTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/RRClientTest.java @@ -6,7 +6,6 @@ package org.gcube.informationsystem.resourceregistry.publisher; import java.util.List; import java.util.UUID; -import org.gcube.common.scope.api.ScopeProvider; import org.gcube.informationsystem.impl.entity.facet.CPUFacetImpl; import org.gcube.informationsystem.impl.entity.facet.SoftwareFacetImpl; import org.gcube.informationsystem.impl.entity.resource.EServiceImpl; @@ -34,7 +33,7 @@ import org.slf4j.LoggerFactory; * @author Luca Frosini (ISTI - CNR) * */ -public class RRClientTest { +public class RRClientTest extends ScopedTest { private static final Logger logger = LoggerFactory.getLogger(EntityManagementTest.class); @@ -42,8 +41,8 @@ public class RRClientTest { protected ResourceRegistryClient resourceRegistryClient; @Before - public void before() { - ScopeProvider.instance.set("/gcube/devNext/NextNext"); + public void before() throws Exception { + super.before(); resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); resourceRegistryClient = ResourceRegistryClientFactory.create(); logger.trace("{} and {} created", diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ScopedTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ScopedTest.java new file mode 100644 index 0000000..1b84866 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ScopedTest.java @@ -0,0 +1,45 @@ +/** + * + */ +package org.gcube.informationsystem.resourceregistry.publisher; + +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Luca Frosini (ISTI - CNR) + * + */ +public class ScopedTest { + + private static final Logger logger = LoggerFactory.getLogger(ScopedTest.class); + + private static final String TOKEN = ""; + + private static String getCurrentScope() throws ObjectNotFound, Exception{ + AuthorizationEntry authorizationEntry = Constants.authorizationService().get(TOKEN); + String context = authorizationEntry.getContext(); + logger.info("Context of token {} is {}", TOKEN, context); + return context; + } + + @Before + public void before() throws Exception{ + SecurityTokenProvider.instance.set(TOKEN); + ScopeProvider.instance.set(getCurrentScope()); + } + + @After + public void after() throws Exception{ + SecurityTokenProvider.instance.reset(); + ScopeProvider.instance.reset(); + } + +}