Fix the test case with the invalid parent scope.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@158932 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3683a3d602
commit
f841ccffa6
|
@ -10,7 +10,7 @@ import javax.ws.rs.core.Response;
|
|||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||
import org.gcube.resourcemanagement.manager.io.rs.*;
|
||||
import org.gcube.resourcemanagement.manager.io.rs.ContextPath;
|
||||
import org.gcube.resourcemanagement.manager.webapp.ResourceInitializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -34,13 +34,13 @@ public class Context {
|
|||
*/
|
||||
@POST
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public Response create(String json) throws JsonParseException, JsonMappingException, IOException
|
||||
public Response create(String json) throws JsonParseException, JsonMappingException, IOException, IllegalArgumentException
|
||||
{
|
||||
logger.info("Requested to create context {} with json {}",
|
||||
org.gcube.informationsystem.model.entity.Context.NAME, json);
|
||||
org.gcube.informationsystem.model.entity.Context inputContext = ISMapper.unmarshal(org.gcube.informationsystem.model.entity.Context.class, json);
|
||||
if (Objects.isNull(inputContext.getParent()))
|
||||
throw new IllegalArgumentException("Unsupported parent context");
|
||||
if (Objects.nonNull(inputContext.getParent()))
|
||||
return Response.status(Status.BAD_REQUEST).build();
|
||||
String response = "All good";
|
||||
//TODO
|
||||
return Response.status(Status.CREATED).entity(response).
|
||||
|
|
|
@ -64,9 +64,8 @@ public class ContextTest extends JerseyTest {
|
|||
@Test
|
||||
public void step1_Create() {
|
||||
org.gcube.informationsystem.model.entity.Context newContext = new ContextImpl(contextName);
|
||||
Response create;
|
||||
try {
|
||||
create = target("context").request()
|
||||
Response create = target("context").request()
|
||||
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
|
||||
|
||||
assertNotNull(create);
|
||||
|
@ -82,17 +81,18 @@ public class ContextTest extends JerseyTest {
|
|||
* Test method for
|
||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.Context#create(java.lang.String)} when the parent does not exist.
|
||||
*/
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void step1_CreateNoParent() {
|
||||
@Test
|
||||
public void step1_CreateWithInvalidParent() {
|
||||
org.gcube.informationsystem.model.entity.Context newContext = new ContextImpl(contextName);
|
||||
newContext.setParent(new ContextImpl("DoNotExist"));
|
||||
try {
|
||||
target("context").request()
|
||||
Response create = target("context").request()
|
||||
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
|
||||
|
||||
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
|
||||
Status.BAD_REQUEST.getStatusCode(), create.getStatus());
|
||||
} catch (JsonProcessingException e) {
|
||||
assertFalse("Failed to marshal the context.", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue