|
|
|
@ -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;
|
|
|
|
@ -37,6 +44,32 @@ 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"));
|
|
|
|
|
|
|
|
|
|