Temporary add a dummy resource (RMTestForGXRest) for testing purposes.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@165612 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d47c03c91c
commit
7aee1a7989
|
@ -7,7 +7,7 @@ package org.gcube.resourcemanagement.manager.io.rs;
|
|||
*
|
||||
*/
|
||||
public class RMContextPath {
|
||||
|
||||
|
||||
public static final String APPLICATION_PATH = "/resource-manager";
|
||||
|
||||
public static final String CONTEXT_ROOT = "context";
|
||||
|
@ -16,6 +16,9 @@ public class RMContextPath {
|
|||
|
||||
public static final String DELETE_PATH_PART = "delete";
|
||||
|
||||
public static final String GXREST_ROOT = "gxrest";
|
||||
|
||||
|
||||
|
||||
/* PARAMETERS FOR SOME REQUESTS*/
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import javax.ws.rs.core.MediaType;
|
|||
|
||||
import org.gcube.resourcemanagement.manager.io.rs.RMContextPath;
|
||||
import org.gcube.resourcemanagement.manager.webapp.rs.RMContext;
|
||||
import org.gcube.resourcemanagement.manager.webapp.rs.RMTestForGXRest;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +18,7 @@ public class ResourceInitializer extends ResourceConfig {
|
|||
|
||||
public ResourceInitializer(){
|
||||
//where jersey will find the operation's handler
|
||||
packages(RMContext.class.getPackage().toString());
|
||||
packages(RMContext.class.getPackage().toString(),RMTestForGXRest.class.getPackage().toString());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package org.gcube.resourcemanagement.manager.webapp.rs;
|
||||
|
||||
import static org.gcube.resourcemanagement.manager.io.rs.RMContextPath.GXREST_ROOT;
|
||||
import static org.gcube.resourcemanagement.manager.io.rs.RMContextPath.UUID_PARAM;
|
||||
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.gcube.common.gxrest.response.outbound.GXOutboundErrorResponse;
|
||||
import org.gcube.resourcemanagement.manager.io.rs.RMContextDoesNotExistException;
|
||||
import org.gcube.resourcemanagement.manager.webapp.ResourceInitializer;
|
||||
|
||||
/**
|
||||
* Tests for gxrest
|
||||
*
|
||||
* @author Manuele Simi (ISTI CNR)
|
||||
*
|
||||
*/
|
||||
@Path(GXREST_ROOT)
|
||||
public class RMTestForGXRest {
|
||||
|
||||
/** e.g. DELETE
|
||||
* /resource-manager/gxrest/UUID?rrURL=http://registry:port//resource-
|
||||
* registry
|
||||
*/
|
||||
@DELETE
|
||||
@Path("{" + UUID_PARAM + "}")
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public Response delete(@PathParam(UUID_PARAM) String uuid) {
|
||||
methodThree();
|
||||
return null;
|
||||
}
|
||||
|
||||
private void methodOne() {
|
||||
methodTwo();
|
||||
}
|
||||
|
||||
private void methodTwo() {
|
||||
|
||||
//something fails here
|
||||
|
||||
GXOutboundErrorResponse.throwExceptionWithTrace(new RMContextDoesNotExistException("Error in methodTwo"),3);
|
||||
}
|
||||
|
||||
private void methodThree() {
|
||||
|
||||
//something fails here
|
||||
|
||||
GXOutboundErrorResponse.throwException(new RMContextDoesNotExistException("Error in methodTwo"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
package org.gcube.resourcemanagement.manager.webapp.context;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.Application;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.core.Response.StatusType;
|
||||
|
||||
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.gxrest.response.inbound.GXInboundResponse;
|
||||
import org.gcube.common.gxrest.response.outbound.CodeFinder;
|
||||
import org.gcube.common.gxrest.response.outbound.ErrorCode;
|
||||
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;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClient;
|
||||
import org.gcube.informationsystem.resourceregistry.context.ResourceRegistryContextClientImpl;
|
||||
import org.gcube.resourcemanagement.manager.io.rs.RMCreateContextCode;
|
||||
import org.gcube.resourcemanagement.manager.io.rs.RMContextDoesNotExistException;
|
||||
import org.gcube.resourcemanagement.manager.io.rs.RMContextPath;
|
||||
import org.gcube.resourcemanagement.manager.webapp.rs.RMContext;
|
||||
import org.gcube.resourcemanagement.manager.webapp.rs.RMTestForGXRest;
|
||||
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;
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
/**
|
||||
* Test cases for the Context methods.
|
||||
*
|
||||
* @author Manuele Simi (ISTI-CNR)
|
||||
*/
|
||||
@RunWith(BlockJUnit4ClassRunner.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class GXRestTest extends JerseyTest {
|
||||
|
||||
private final static String context1 = "ContextA";
|
||||
|
||||
private final static String context2 = "ContextB";
|
||||
|
||||
private final static String context3 = "ContextC";
|
||||
|
||||
public static final UUID context1UUID = UUID.fromString("5f86dc81-2f59-486b-8aa9-3ab5486313c4");
|
||||
|
||||
public static final UUID context2UUID = UUID.fromString("6f86dc81-2f59-486b-8aa9-3ab5486313c4");
|
||||
|
||||
public static final UUID context3UUID = UUID.fromString("7f86dc81-2f59-486b-8aa9-3ab5486313c4");
|
||||
|
||||
private final static String RR = "http://manuele-registry.dev.d4science.org/resource-registry";
|
||||
|
||||
public static String DEFAULT_TEST_SCOPE = "";
|
||||
|
||||
private static boolean skipTest = false;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(GXRestTest.class);
|
||||
|
||||
static {
|
||||
Properties properties = new Properties();
|
||||
try (InputStream input = GXRestTest.class.getClassLoader().getResourceAsStream("token.properties")) {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
} catch (IOException e) {
|
||||
skipTest = true;
|
||||
// throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
DEFAULT_TEST_SCOPE = properties.getProperty("DEFAULT_SCOPE_TOKEN");
|
||||
if (DEFAULT_TEST_SCOPE.isEmpty())
|
||||
skipTest = true;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
setContext(DEFAULT_TEST_SCOPE);
|
||||
}
|
||||
|
||||
public static void setContext(String token) throws ObjectNotFound, Exception {
|
||||
if (DEFAULT_TEST_SCOPE.isEmpty()) {
|
||||
skipTest = true;
|
||||
return;
|
||||
}
|
||||
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(RMTestForGXRest.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#delete(String, String)}
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void step1_ExceptionWithStacktrace() throws Exception {
|
||||
if (skipTest)
|
||||
return;
|
||||
|
||||
Response delete = target(RMContextPath.GXREST_ROOT).path(context2UUID.toString()).request().delete();
|
||||
assertNotNull(delete);
|
||||
GXInboundResponse response = new GXInboundResponse(delete);
|
||||
if (response.hasOKCode()) {
|
||||
|
||||
} else {
|
||||
assertEquals("Unexpected returned code. Reason: " + response.getHTTPCode(),
|
||||
Status.NOT_ACCEPTABLE.getStatusCode(), delete.getStatus());
|
||||
if (response.hasException()) {
|
||||
try {
|
||||
response.getException().printStackTrace();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue