diff --git a/webapp/src/test/java/org/gcube/resourcemanagement/manager/webapp/context/RMContextTest.java b/webapp/src/test/java/org/gcube/resourcemanagement/manager/webapp/context/RMContextTest.java index d239272..d34c7e7 100644 --- a/webapp/src/test/java/org/gcube/resourcemanagement/manager/webapp/context/RMContextTest.java +++ b/webapp/src/test/java/org/gcube/resourcemanagement/manager/webapp/context/RMContextTest.java @@ -45,13 +45,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; @FixMethodOrder(MethodSorters.NAME_ASCENDING) 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"; public static final String DEFAULT_TEST_SCOPE =""; - public static final UUID uuid = UUID.fromString("5f86dc81-2f59-486b-8aa9-3ab5486313c4"); private static boolean skipTest = false; @@ -91,10 +92,13 @@ public class RMContextTest extends JerseyTest { */ @Test public void step0_Context() { - Context newContext = new ContextImpl(contextName); - // newContext.setParent(new ContextImpl("parent")); + Context newContext = new ContextImpl(context1Name); + newContext.getHeader().setUUID(context1UUID); 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) { e.printStackTrace(); assertFalse("Failed to unmarshal the context.", false); @@ -104,13 +108,13 @@ public class RMContextTest extends JerseyTest { /** * 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 public void step1_Create() { if (skipTest) return; - Context newContext = new ContextImpl(contextName, uuid); + Context newContext = new ContextImpl(context1Name, context1UUID); System.out.println(newContext.getHeader().getUUID().toString()); try { 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 * {@link org.gcube.resourcemanagement.manager.webapp.rs.RMContext#create(java.lang.String)} * when the parent does not exist. */ @Test - public void step1_CreateWithInvalidParent() { + public void step2_CreateWithInvalidParent() { if (skipTest) return; - Context newContext = new ContextImpl(contextName); + Context newContext = new ContextImpl(context1Name); newContext.setParent(new ContextImpl("DoNotExist")); try { Response create = target("context").request()