Merge "Reorder modifiers"
[so.git] / mso-api-handlers / mso-api-handler-common / src / test / java / org / openecomp / mso / camunda / tests / CamundaResponseTest.java
index 9b36a98..7fc2815 100644 (file)
@@ -23,14 +23,10 @@ package org.openecomp.mso.camunda.tests;
 
 import static org.junit.Assert.assertEquals;
 
-import java.io.IOException;
-
 import org.junit.Test;
 import org.openecomp.mso.apihandler.camundabeans.CamundaResponse;
+import org.openecomp.mso.utils.RootIgnoringObjectMapper;
 
-import com.fasterxml.jackson.core.JsonGenerationException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
 /**
@@ -41,19 +37,42 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 public class CamundaResponseTest {
 
        @Test
-       public final void testDeserialization() throws JsonGenerationException,
-                       JsonMappingException, IOException {
-               ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
-               mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
-               
-               String responseBody = "{ \"response\": \"<xml>xml</xml>\","+
-                                 "\"messageCode\": 200,"+
-                                 "\"message\": \"Successfully started the process\"," +
-                                 "\"processInstanceID\":null,\"variables\":null}";
-       
-               CamundaResponse response = mapper.readValue(responseBody, CamundaResponse.class);
-               assertEquals(response.toString(), "CamundaResponse [response=<xml>xml</xml>, messageCode=200, message=Successfully started the process]");
+       public final void testDeserializationWithoutRootElement() throws Exception {
+
+               ObjectMapper mapper = new RootIgnoringObjectMapper<CamundaResponse>(CamundaResponse.class);
+
+               String content = "{"
+                       + "\"messageCode\":202"
+                       + ",\"message\":\"Successfully started the process\""
+                       + ",\"content\":\"<xml>xml</xml>\""
+                       + ",\"processInstanceId\":\"4d3b3201a7ce\""
+                       + ",\"variables\":null"
+                       + "}";
 
+               CamundaResponse response = mapper.readValue(content, CamundaResponse.class);
+
+               assertEquals(
+                       "CamundaResponse[processInstanceId=4d3b3201a7ce,messageCode=202,message=Successfully started the process,variables=null,content=<xml>xml</xml>]",
+                       response.toString());
        }
 
-}
+       @Test
+       public final void testDeserializationWithRootElement() throws Exception {
+
+               ObjectMapper mapper = new RootIgnoringObjectMapper<CamundaResponse>(CamundaResponse.class);
+
+               String content = "{\"WorkflowResponse\":{"
+                       + "\"messageCode\":202"
+                       + ",\"message\":\"Successfully started the process\""
+                       + ",\"content\":\"<xml>xml</xml>\""
+                       + ",\"processInstanceId\":\"4d3b3201a7ce\""
+                       + ",\"variables\":null"
+                       + "}}";
+
+               CamundaResponse response = mapper.readValue(content, CamundaResponse.class);
+
+               assertEquals(
+                       "CamundaResponse[processInstanceId=4d3b3201a7ce,messageCode=202,message=Successfully started the process,variables=null,content=<xml>xml</xml>]",
+                       response.toString());
+       }
+}
\ No newline at end of file