From cd225edb42c4d3db7f991ad270747ea63a2fb789 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 4 Nov 2016 11:55:33 +0000 Subject: [PATCH] Added token based instead of scope git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-publisher@133896 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../publisher/EntityManagementTest.java | 7 ++- .../publisher/RRClientTest.java | 7 ++- .../publisher/ScopedTest.java | 45 +++++++++++++++++++ 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 src/test/java/org/gcube/informationsystem/resourceregistry/publisher/ScopedTest.java 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(); + } + +}