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
|
@ -13,6 +13,12 @@ public class RMContextPath {
|
|||
public static final String CONTEXT_ROOT = "context";
|
||||
|
||||
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.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
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.context.CreateRequest;
|
||||
import org.gcube.resourcemanagement.manager.webapp.context.ResponseFromResourceRegistry;
|
||||
|
@ -21,7 +22,7 @@ import org.slf4j.LoggerFactory;
|
|||
* @author Manuele Simi (ISTI-CNR)
|
||||
*
|
||||
*/
|
||||
@Path(RMContextPath.CONTEXT_ROOT)
|
||||
@Path(CONTEXT_ROOT)
|
||||
public class RMContext {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(RMContext.class);
|
||||
|
@ -31,11 +32,12 @@ public class RMContext {
|
|||
*/
|
||||
@POST
|
||||
@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("Force URL: " + rrURL);
|
||||
Response response;
|
||||
ContextHolder holder = new ContextHolder(json);
|
||||
ResponseFromResourceRegistry returned = CreateRequest.fromHolder(holder).forceURL("").submit();
|
||||
ResponseFromResourceRegistry returned = CreateRequest.fromHolder(holder).forceURL(rrURL).submit();
|
||||
if (returned.wasSuccessful()) {
|
||||
response = Response.status(Status.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.utils.ISMapper;
|
||||
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.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.test.JerseyTest;
|
||||
|
@ -67,7 +68,9 @@ public class RMContextTest extends JerseyTest {
|
|||
Context newContext = new ContextImpl(contextName);
|
||||
try {
|
||||
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"));
|
||||
|
||||
assertNotNull(create);
|
||||
|
|
Reference in New Issue