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
This commit is contained in:
parent
6a0ce9c5e7
commit
8ebad38cae
|
@ -140,10 +140,11 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Test Dependency -->
|
<!-- Test Dependency -->
|
||||||
|
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.11</version>
|
<version>4.12</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.test-framework.providers/jersey-test-framework-provider-simple -->
|
<!-- 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;
|
package org.gcube.resourcemanagement.manager.webapp.context;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.informationsystem.model.reference.entities.Context;
|
import org.gcube.informationsystem.model.reference.entities.Context;
|
||||||
import org.gcube.informationsystem.model.reference.entities.Resource;
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
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.ResourceRegistryClient;
|
||||||
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient;
|
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
|
* @param context
|
||||||
* @return
|
* @return {@code true} if the provided context exists
|
||||||
*/
|
* otherwise {@code false}
|
||||||
|
* */
|
||||||
protected boolean contextExists(UUID context) {
|
protected boolean contextExists(UUID context) {
|
||||||
try {
|
try {
|
||||||
return this.cclient.read(context) != null;
|
Context results = this.cclient.read(context);
|
||||||
} catch (ResourceRegistryException e) {
|
return Objects.nonNull(results);
|
||||||
logger.warn("Failed to query the Resource Registry: " + e.getMessage());
|
} catch (ContextNotFoundException e) {
|
||||||
|
logger.warn("Context not found: " + e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}catch (RuntimeException e) {
|
} catch (Exception e) {
|
||||||
logger.warn("Failed to query the Resource Registry: " + e.getMessage());
|
logger.warn("Failed to query the Resource Registry: " + e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class GXRestTest extends JerseyTest {
|
||||||
setContext(DEFAULT_TEST_SCOPE);
|
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()) {
|
if (DEFAULT_TEST_SCOPE.isEmpty()) {
|
||||||
skipTest = true;
|
skipTest = true;
|
||||||
return;
|
return;
|
||||||
|
@ -90,14 +90,14 @@ public class GXRestTest extends JerseyTest {
|
||||||
ScopeProvider.instance.set(getCurrentScope(token));
|
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);
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||||
String context = authorizationEntry.getContext();
|
String context = authorizationEntry.getContext();
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClass() throws Exception {
|
public static void afterClass() {
|
||||||
SecurityTokenProvider.instance.reset();
|
SecurityTokenProvider.instance.reset();
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import java.util.Properties;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.gcube.common.authorization.client.Constants;
|
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.AuthorizationEntry;
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
@ -68,7 +67,7 @@ public class QueriesTest {
|
||||||
setContext(DEFAULT_TEST_SCOPE);
|
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()) {
|
if (DEFAULT_TEST_SCOPE.isEmpty()) {
|
||||||
skipTest = true;
|
skipTest = true;
|
||||||
return;
|
return;
|
||||||
|
@ -77,14 +76,14 @@ public class QueriesTest {
|
||||||
ScopeProvider.instance.set(getCurrentScope(token));
|
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);
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||||
String context = authorizationEntry.getContext();
|
String context = authorizationEntry.getContext();
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClass() throws Exception {
|
public static void afterClass() {
|
||||||
SecurityTokenProvider.instance.reset();
|
SecurityTokenProvider.instance.reset();
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class RMContextTest extends JerseyTest {
|
||||||
setContext(DEFAULT_TEST_SCOPE);
|
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()) {
|
if (DEFAULT_TEST_SCOPE.isEmpty()) {
|
||||||
skipTest = true;
|
skipTest = true;
|
||||||
return;
|
return;
|
||||||
|
@ -108,14 +108,14 @@ public class RMContextTest extends JerseyTest {
|
||||||
ScopeProvider.instance.set(getCurrentScope(token));
|
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);
|
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||||
String context = authorizationEntry.getContext();
|
String context = authorizationEntry.getContext();
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void afterClass() throws Exception {
|
public static void afterClass() {
|
||||||
SecurityTokenProvider.instance.reset();
|
SecurityTokenProvider.instance.reset();
|
||||||
ScopeProvider.instance.reset();
|
ScopeProvider.instance.reset();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue