Update tests for create context with or without parent. Still some pitfalls to address.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@162408 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
eb900141e2
commit
4a7df8b36d
|
@ -45,13 +45,21 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class RMContextTest extends JerseyTest {
|
||||
|
||||
private final static String context1Name = "AContext";
|
||||
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 final String DEFAULT_TEST_SCOPE ="";
|
||||
public static final String DEFAULT_TEST_SCOPE ="71b9ef86-76ba-4346-b16e-9a1af203f6db-98187548";
|
||||
|
||||
|
||||
private static boolean skipTest = false;
|
||||
|
@ -92,12 +100,12 @@ public class RMContextTest extends JerseyTest {
|
|||
*/
|
||||
@Test
|
||||
public void step0_Context() {
|
||||
Context newContext = new ContextImpl(context1Name);
|
||||
Context newContext = new ContextImpl(context1);
|
||||
newContext.getHeader().setUUID(context1UUID);
|
||||
try {
|
||||
Context uContext = ISMapper.unmarshal(Context.class, ISMapper.marshal(newContext));
|
||||
assertNotNull(uContext);
|
||||
assertEquals("Invalid context name", context1Name, uContext.getName());
|
||||
assertEquals("Invalid context name", context1, uContext.getName());
|
||||
assertEquals("Invalid context UUID", context1UUID, uContext.getHeader().getUUID());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -114,7 +122,7 @@ public class RMContextTest extends JerseyTest {
|
|||
public void step1_Create() {
|
||||
if (skipTest)
|
||||
return;
|
||||
Context newContext = new ContextImpl(context1Name, context1UUID);
|
||||
Context newContext = new ContextImpl(context1, context1UUID);
|
||||
try {
|
||||
System.out.print(ISMapper.marshal(newContext));
|
||||
Response create = target("context").queryParam(RMContextPath.FORCE_RRURL_PARAM, RR).request()
|
||||
|
@ -136,12 +144,63 @@ public class RMContextTest extends JerseyTest {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)}
|
||||
* when the parent does not exist.
|
||||
*/
|
||||
@Test
|
||||
public void step2_CreateWithInvalidParent() {
|
||||
if (skipTest)
|
||||
return;
|
||||
Context newContext = new ContextImpl(context2, context2UUID);
|
||||
newContext.setParent(new ContextImpl("DoNotExist"));
|
||||
try {
|
||||
Response create = target(RMContextPath.CONTEXT_ROOT).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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)}
|
||||
* when the parent does not exist.
|
||||
*/
|
||||
@Test
|
||||
public void step3_CreateWithParent() {
|
||||
if (skipTest)
|
||||
return;
|
||||
Context newContext = new ContextImpl(context2, context2UUID);
|
||||
newContext.setParent(new ContextImpl(context1,context1UUID));
|
||||
try {
|
||||
Response create = target(RMContextPath.CONTEXT_ROOT).request()
|
||||
.post(Entity.entity(ISMapper.marshal(newContext), MediaType.APPLICATION_JSON + ";charset=UTF-8"));
|
||||
assertNotNull(create);
|
||||
if (create.getStatusInfo() == Status.CREATED) {
|
||||
String message = create.readEntity(String.class);
|
||||
System.out.println("RM says: " + message);
|
||||
}else {
|
||||
assertEquals("Unexpected returned code. Reason: " + create.getStatusInfo().getReasonPhrase(),
|
||||
Status.NOT_ACCEPTABLE.getStatusCode(), create.getStatus());
|
||||
SerializableErrorCode code = create.readEntity(SerializableErrorCode.class);
|
||||
RMCreateContextCode realCode = CodeFinder.findAndConvert(code, RMCreateContextCode.values());
|
||||
assertEquals(RMCreateContextCode.CONTEXT_ALREADY_EXISTS, realCode);
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
assertFalse("Failed to marshal the context.", false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#delete(String, String)}
|
||||
*/
|
||||
@Test
|
||||
public void step2_Delete() {
|
||||
public void step4_Delete() {
|
||||
if (skipTest)
|
||||
return;
|
||||
try {
|
||||
|
@ -156,25 +215,24 @@ public class RMContextTest extends JerseyTest {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)}
|
||||
* when the parent does not exist.
|
||||
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#delete(String, String)}
|
||||
*/
|
||||
@Test
|
||||
public void step2_CreateWithInvalidParent() {
|
||||
public void step5_DeleteParent() {
|
||||
if (skipTest)
|
||||
return;
|
||||
Context newContext = new ContextImpl(context1Name);
|
||||
newContext.setParent(new ContextImpl("DoNotExist"));
|
||||
try {
|
||||
Response create = target(RMContextPath.CONTEXT_ROOT).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);
|
||||
Response delete = target(RMContextPath.CONTEXT_ROOT).path(context2UUID.toString())
|
||||
.queryParam(RMContextPath.FORCE_RRURL_PARAM, RR)
|
||||
.request().delete();
|
||||
assertNotNull(delete);
|
||||
assertEquals("Unexpected returned code. Reason: " + delete.getStatusInfo().getReasonPhrase(),
|
||||
Status.OK.getStatusCode(), delete.getStatus());
|
||||
} catch (Exception e) {
|
||||
assertFalse("Failed to delete the context.", false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in New Issue