Improve tests on ResourceRegistryContextClient. Advance JUnit to 4.12.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@177251 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Manuele Simi 5 years ago
parent 6a0ce9c5e7
commit 8ebad38cae

@ -140,10 +140,11 @@
</dependency>
<!-- Test Dependency -->
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.test-framework.providers/jersey-test-framework-provider-simple -->

@ -1,10 +1,12 @@
package org.gcube.resourcemanagement.manager.webapp.context;
import java.util.Objects;
import java.util.UUID;
import org.gcube.informationsystem.model.reference.entities.Context;
import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextNotFoundException;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient;
@ -42,18 +44,21 @@ final class Queries {
}
/**
* Tests if the given context exists
* Returns {@code true} if the provided context exists
* otherwise returns {@code false}.
*
* @param context
* @return
*/
* @return {@code true} if the provided context exists
* otherwise {@code false}
* */
protected boolean contextExists(UUID context) {
try {
return this.cclient.read(context) != null;
} catch (ResourceRegistryException e) {
logger.warn("Failed to query the Resource Registry: " + e.getMessage());
Context results = this.cclient.read(context);
return Objects.nonNull(results);
} catch (ContextNotFoundException e) {
logger.warn("Context not found: " + e.getMessage());
return false;
}catch (RuntimeException e) {
} catch (Exception e) {
logger.warn("Failed to query the Resource Registry: " + e.getMessage());
return false;
}

@ -81,7 +81,7 @@ public class GXRestTest extends JerseyTest {
setContext(DEFAULT_TEST_SCOPE);
}
public static void setContext(String token) throws ObjectNotFound, Exception {
public static void setContext(String token) throws Exception {
if (DEFAULT_TEST_SCOPE.isEmpty()) {
skipTest = true;
return;
@ -90,14 +90,14 @@ public class GXRestTest extends JerseyTest {
ScopeProvider.instance.set(getCurrentScope(token));
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
public static String getCurrentScope(String token) throws Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
return context;
}
@AfterClass
public static void afterClass() throws Exception {
public static void afterClass() {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
}

@ -8,7 +8,6 @@ import java.util.Properties;
import java.util.UUID;
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;
@ -68,7 +67,7 @@ public class QueriesTest {
setContext(DEFAULT_TEST_SCOPE);
}
public static void setContext(String token) throws ObjectNotFound, Exception {
public static void setContext(String token) throws Exception {
if (DEFAULT_TEST_SCOPE.isEmpty()) {
skipTest = true;
return;
@ -77,14 +76,14 @@ public class QueriesTest {
ScopeProvider.instance.set(getCurrentScope(token));
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
public static String getCurrentScope(String token) throws Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
return context;
}
@AfterClass
public static void afterClass() throws Exception {
public static void afterClass() {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
}

@ -99,7 +99,7 @@ public class RMContextTest extends JerseyTest {
setContext(DEFAULT_TEST_SCOPE);
}
public static void setContext(String token) throws ObjectNotFound, Exception {
static void setContext(String token) throws Exception {
if (DEFAULT_TEST_SCOPE.isEmpty()) {
skipTest = true;
return;
@ -108,14 +108,14 @@ public class RMContextTest extends JerseyTest {
ScopeProvider.instance.set(getCurrentScope(token));
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception {
static String getCurrentScope(String token) throws Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
return context;
}
@AfterClass
public static void afterClass() throws Exception {
public static void afterClass() {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
}

Loading…
Cancel
Save