From 0935bfc1f766a4ddac6b0b124c6093212f7365fd Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 4 Nov 2016 15:52:41 +0000 Subject: [PATCH] Changing the tests git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry-client@133913 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../proxy/ResourceRegistryClientImpl.java | 2 +- .../proxy/ResourceRegistryClientTest.java | 12 ++--- .../client/proxy/ScopedTest.java | 45 +++++++++++++++++++ 3 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ScopedTest.java diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientImpl.java b/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientImpl.java index b1c9f00..9ab3d1b 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientImpl.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientImpl.java @@ -202,7 +202,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient { } connection.setDoOutput(true); - connection.setRequestProperty("Content-type", "text/plain"); + connection.setRequestProperty("Content-type", "application/json"); connection.setRequestProperty("User-Agent", ResourceRegistryClient.class.getSimpleName()); connection.setRequestMethod(method.toString()); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientTest.java index 0d91edd..41a566a 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ResourceRegistryClientTest.java @@ -3,10 +3,9 @@ */ package org.gcube.informationsystem.resourceregistry.client.proxy; -import org.gcube.common.scope.api.ScopeProvider; import org.gcube.informationsystem.resourceregistry.api.exceptions.InvalidQueryException; import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaNotFoundException; -import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,9 +21,12 @@ public class ResourceRegistryClientTest { protected ResourceRegistryClient resourceRegistryClient; - @Before - public void before(){ - ScopeProvider.instance.set("/gcube/devNext/NextNext"); + @BeforeClass + public static void beforeClass() throws Exception { + ScopedTest.beforeClass(); + } + + public ResourceRegistryClientTest(){ resourceRegistryClient = ResourceRegistryClientFactory.create(); } diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ScopedTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ScopedTest.java new file mode 100644 index 0000000..e85a816 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/client/proxy/ScopedTest.java @@ -0,0 +1,45 @@ +/** + * + */ +package org.gcube.informationsystem.resourceregistry.client.proxy; + +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.AfterClass; +import org.junit.BeforeClass; +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; + } + + @BeforeClass + public static void beforeClass() throws Exception{ + SecurityTokenProvider.instance.set(TOKEN); + ScopeProvider.instance.set(getCurrentScope()); + } + + @AfterClass + public static void afterClass() throws Exception{ + SecurityTokenProvider.instance.reset(); + ScopeProvider.instance.reset(); + } + +}