Configure the jersey tests for RMContext resource with authorization permission.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@160671 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2017-12-19 03:52:21 +00:00
parent b95522d5ac
commit 76183b49f2
2 changed files with 34 additions and 2 deletions

View File

@ -3,7 +3,6 @@
<name>resource-manager</name>
<comment></comment>
<projects>
<project>resource-registry-context-client</project>
</projects>
<buildSpec>
<buildCommand>

View File

@ -10,6 +10,11 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
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.gcube.informationsystem.impl.entity.ContextImpl;
import org.gcube.informationsystem.impl.utils.ISMapper;
import org.gcube.informationsystem.model.entity.Context;
@ -17,6 +22,8 @@ import org.gcube.resourcemanagement.manager.io.rs.RMContextPath;
import org.gcube.resourcemanagement.manager.webapp.rs.RMContext;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -36,7 +43,33 @@ import com.fasterxml.jackson.core.JsonProcessingException;
public class RMContextTest extends JerseyTest {
private final static String contextName = "firstContext";
private final static String RR = "";
public static final String DEFAULT_TEST_SCOPE ="";
@BeforeClass
public static void beforeClass() throws Exception{
setContext(DEFAULT_TEST_SCOPE);
}
public static void setContext(String token) throws ObjectNotFound, Exception{
SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(getCurrentScope(token));
}
public static String getCurrentScope(String token) throws ObjectNotFound, Exception{
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
return context;
}
@AfterClass
public static void afterClass() throws Exception{
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
}
@Override
protected Application configure() {
return new ResourceConfig(RMContext.class);
@ -69,7 +102,7 @@ public class RMContextTest extends JerseyTest {
try {
System.out.print(ISMapper.marshal(newContext));
Response create = target("context")
.queryParam(RMContextPath.FORCE_RRURL_PARAM, "http://manuele-registry.dev.d4science.org/resource-registry")
.queryParam(RMContextPath.FORCE_RRURL_PARAM, RR)
.request()
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));