Add a query parameter to context creation to force use a given RR instance. Mainly for testing purposes. Adjust the test accordingly.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@160622 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f4e1170f78
commit
b95522d5ac
|
@ -14,6 +14,12 @@ public class RMContextPath {
|
||||||
|
|
||||||
public static final String CREATE_PATH_PART = "create";
|
public static final String CREATE_PATH_PART = "create";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force the service to use the ResourceRegistry instance at the given URL.
|
||||||
|
*/
|
||||||
|
public static final String FORCE_RRURL_PARAM = "rrURL";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,12 @@ package org.gcube.resourcemanagement.manager.webapp.rs;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.gcube.informationsystem.model.entity.Context;
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
import org.gcube.resourcemanagement.manager.io.rs.RMContextPath;
|
import static org.gcube.resourcemanagement.manager.io.rs.RMContextPath.*;
|
||||||
import org.gcube.resourcemanagement.manager.webapp.ResourceInitializer;
|
import org.gcube.resourcemanagement.manager.webapp.ResourceInitializer;
|
||||||
import org.gcube.resourcemanagement.manager.webapp.context.CreateRequest;
|
import org.gcube.resourcemanagement.manager.webapp.context.CreateRequest;
|
||||||
import org.gcube.resourcemanagement.manager.webapp.context.ResponseFromResourceRegistry;
|
import org.gcube.resourcemanagement.manager.webapp.context.ResponseFromResourceRegistry;
|
||||||
|
@ -21,7 +22,7 @@ import org.slf4j.LoggerFactory;
|
||||||
* @author Manuele Simi (ISTI-CNR)
|
* @author Manuele Simi (ISTI-CNR)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Path(RMContextPath.CONTEXT_ROOT)
|
@Path(CONTEXT_ROOT)
|
||||||
public class RMContext {
|
public class RMContext {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(RMContext.class);
|
private static Logger logger = LoggerFactory.getLogger(RMContext.class);
|
||||||
|
@ -31,11 +32,12 @@ public class RMContext {
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||||
public Response create(String json) {
|
public Response create(String json, @QueryParam(FORCE_RRURL_PARAM) String rrURL) {
|
||||||
logger.info("Requested to create context {} with json {}", Context.NAME, json);
|
logger.info("Requested to create context {} with json {}", Context.NAME, json);
|
||||||
|
logger.info("Force URL: " + rrURL);
|
||||||
Response response;
|
Response response;
|
||||||
ContextHolder holder = new ContextHolder(json);
|
ContextHolder holder = new ContextHolder(json);
|
||||||
ResponseFromResourceRegistry returned = CreateRequest.fromHolder(holder).forceURL("").submit();
|
ResponseFromResourceRegistry returned = CreateRequest.fromHolder(holder).forceURL(rrURL).submit();
|
||||||
if (returned.wasSuccessful()) {
|
if (returned.wasSuccessful()) {
|
||||||
response = Response.status(Status.CREATED)
|
response = Response.status(Status.CREATED)
|
||||||
.entity(returned.getMessage().map(m -> m).orElse("Context successfully created."))
|
.entity(returned.getMessage().map(m -> m).orElse("Context successfully created."))
|
||||||
|
|
|
@ -13,6 +13,7 @@ import javax.ws.rs.core.Response.Status;
|
||||||
import org.gcube.informationsystem.impl.entity.ContextImpl;
|
import org.gcube.informationsystem.impl.entity.ContextImpl;
|
||||||
import org.gcube.informationsystem.impl.utils.ISMapper;
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||||
import org.gcube.informationsystem.model.entity.Context;
|
import org.gcube.informationsystem.model.entity.Context;
|
||||||
|
import org.gcube.resourcemanagement.manager.io.rs.RMContextPath;
|
||||||
import org.gcube.resourcemanagement.manager.webapp.rs.RMContext;
|
import org.gcube.resourcemanagement.manager.webapp.rs.RMContext;
|
||||||
import org.glassfish.jersey.server.ResourceConfig;
|
import org.glassfish.jersey.server.ResourceConfig;
|
||||||
import org.glassfish.jersey.test.JerseyTest;
|
import org.glassfish.jersey.test.JerseyTest;
|
||||||
|
@ -67,7 +68,9 @@ public class RMContextTest extends JerseyTest {
|
||||||
Context newContext = new ContextImpl(contextName);
|
Context newContext = new ContextImpl(contextName);
|
||||||
try {
|
try {
|
||||||
System.out.print(ISMapper.marshal(newContext));
|
System.out.print(ISMapper.marshal(newContext));
|
||||||
Response create = target("context").request()
|
Response create = target("context")
|
||||||
|
.queryParam(RMContextPath.FORCE_RRURL_PARAM, "http://manuele-registry.dev.d4science.org/resource-registry")
|
||||||
|
.request()
|
||||||
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
|
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
|
||||||
|
|
||||||
assertNotNull(create);
|
assertNotNull(create);
|
||||||
|
|
Reference in New Issue