summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-common/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-common/src/test')
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaResponseTest.java55
-rw-r--r--mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/ResponseHandlerTest.java26
2 files changed, 53 insertions, 28 deletions
diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaResponseTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaResponseTest.java
index 9b36a984b1..7fc2815b4b 100644
--- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaResponseTest.java
+++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/CamundaResponseTest.java
@@ -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
diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/ResponseHandlerTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/ResponseHandlerTest.java
index d0031f3946..e04aba0ede 100644
--- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/ResponseHandlerTest.java
+++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp/mso/camunda/tests/ResponseHandlerTest.java
@@ -47,13 +47,15 @@ public class ResponseHandlerTest {
@Test
public void tesParseCamundaResponse () throws JsonGenerationException, JsonMappingException, IOException {
- // String body
- // ="{\"links\":[{\"method\":\"GET\",\"href\":\"http://localhost:9080/engine-rest/process-instance/2047c658-37ae-11e5-9505-7a1020524153\",\"rel\":\"self\"}],\"id\":\"2047c658-37ae-11e5-9505-7a1020524153\",\"definitionId\":\"dummy:10:73298961-37ad-11e5-9505-7a1020524153\",\"businessKey\":null,\"caseInstanceId\":null,\"ended\":true,\"suspended\":false}";
- String body = "{ \"response\": \"<xml>xml</xml>\"," + "\"messageCode\": 200,"
- + "\"message\": \"Successfully started the process\"}";
+ String content = "{\"WorkflowResponse\":{"
+ + "\"messageCode\":202"
+ + ",\"message\":\"Successfully started the process\""
+ + ",\"content\":\"<xml>xml</xml>\""
+ + ",\"processInstanceId\":\"4d3b3201a7ce\""
+ + "}}";
- HttpResponse response = createResponse (200, body, "application/json");
+ HttpResponse response = createResponse (200, content, "application/json");
ResponseHandler respHandler = new ResponseHandler (response, 1);
@@ -81,7 +83,7 @@ public class ResponseHandlerTest {
int status = respHandler.getStatus ();
assertEquals (status, HttpStatus.SC_ACCEPTED);
- assertTrue (respHandler.getResponseBody () != null);
+ assertTrue (respHandler.getContent() != null);
}
@Test
@@ -100,17 +102,21 @@ public class ResponseHandlerTest {
@Test
public void tesGenricErrorResponse () throws JsonGenerationException, JsonMappingException, IOException {
- String body = "{ \"response\": \"<xml>xml</xml>\"," + "\"messageCode\": 500,"
- + "\"message\": \"Something went wrong\"}";
+ String content = "{\"WorkflowResponse\":{"
+ + "\"messageCode\":500"
+ + ",\"message\":\"Something went wrong\""
+ + ",\"content\":\"<xml>xml</xml>\""
+ + ",\"processInstanceId\":\"4d3b3201a7ce\""
+ + "}}";
- HttpResponse response = createResponse (500, body, "application/json");
+ HttpResponse response = createResponse (500, content, "application/json");
ResponseHandler respHandler = new ResponseHandler (response, 1);
int status = respHandler.getStatus ();
assertEquals (HttpStatus.SC_BAD_GATEWAY, status);
assertEquals (respHandler.getResponse ().getMessage (), "Something went wrong");
- System.out.println (respHandler.getResponseBody ());
+ System.out.println (respHandler.getContent());
}