RMContextTest: extend step0 to check the validity of UUID and name.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@162339 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Manuele Simi 2018-01-19 03:13:34 +00:00
parent f08c550f1d
commit 53f07d6d61
1 changed files with 32 additions and 9 deletions

View File

@ -45,13 +45,14 @@ import com.fasterxml.jackson.core.JsonProcessingException;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RMContextTest extends JerseyTest { public class RMContextTest extends JerseyTest {
private final static String contextName = "firstContext7"; private final static String context1Name = "AContext";
public static final UUID context1UUID = UUID.fromString("5f86dc81-2f59-486b-8aa9-3ab5486313c4");
private final static String RR = "http://manuele-registry.dev.d4science.org/resource-registry"; 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 ="";
public static final UUID uuid = UUID.fromString("5f86dc81-2f59-486b-8aa9-3ab5486313c4");
private static boolean skipTest = false; private static boolean skipTest = false;
@ -91,10 +92,13 @@ public class RMContextTest extends JerseyTest {
*/ */
@Test @Test
public void step0_Context() { public void step0_Context() {
Context newContext = new ContextImpl(contextName); Context newContext = new ContextImpl(context1Name);
// newContext.setParent(new ContextImpl("parent")); newContext.getHeader().setUUID(context1UUID);
try { try {
ISMapper.unmarshal(Context.class, ISMapper.marshal(newContext)); Context uContext = ISMapper.unmarshal(Context.class, ISMapper.marshal(newContext));
assertNotNull(uContext);
assertEquals("Invalid context name", context1Name, uContext.getName());
assertEquals("Invalid context UUID", context1UUID, uContext.getHeader().getUUID());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
assertFalse("Failed to unmarshal the context.", false); assertFalse("Failed to unmarshal the context.", false);
@ -104,13 +108,13 @@ public class RMContextTest extends JerseyTest {
/** /**
* Test method for * Test method for
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)}. * {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(String)}.
*/ */
@Test @Test
public void step1_Create() { public void step1_Create() {
if (skipTest) if (skipTest)
return; return;
Context newContext = new ContextImpl(contextName, uuid); Context newContext = new ContextImpl(context1Name, context1UUID);
System.out.println(newContext.getHeader().getUUID().toString()); System.out.println(newContext.getHeader().getUUID().toString());
try { try {
System.out.print(ISMapper.marshal(newContext)); System.out.print(ISMapper.marshal(newContext));
@ -133,16 +137,35 @@ public class RMContextTest extends JerseyTest {
} }
} }
/**
* Test method for
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#delete(String, String)}
*/
@Test
public void step2_Delete() {
if (skipTest)
return;
Context newContext = new ContextImpl(context1Name);
try {
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);
}
}
/** /**
* Test method for * Test method for
* {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)} * {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)}
* when the parent does not exist. * when the parent does not exist.
*/ */
@Test @Test
public void step1_CreateWithInvalidParent() { public void step2_CreateWithInvalidParent() {
if (skipTest) if (skipTest)
return; return;
Context newContext = new ContextImpl(contextName); Context newContext = new ContextImpl(context1Name);
newContext.setParent(new ContextImpl("DoNotExist")); newContext.setParent(new ContextImpl("DoNotExist"));
try { try {
Response create = target("context").request() Response create = target("context").request()