aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp
diff options
context:
space:
mode:
authorRob Daugherty <rd472p@att.com>2018-05-15 13:23:01 -0400
committerRob Daugherty <rd472p@att.com>2018-05-15 13:58:10 -0400
commitd2e69c0d689596033a9c35aa98d37a44e2cc88cb (patch)
treebe29159a319f63c9e5c242da6354c1ef0133363a /mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp
parentb4d4cb8703842aee6df6c9a5d2a0fd6617539233 (diff)
WorkflowResponse json issues
This commit adds some robustness to the interface between the API-H and BPMN, specifically, in how the response is handled. I don't have proof, but there appears to be some randomness to the json provider behavior when used with the jax-rs. Sometimes, the serializer is adding the root element, and sometimes it is not. Maybe there's something wrong with the configuration. Maybe we have competing json providers. I couldn't pin this down. I'm almost certain it is the presence of the root element in the content that causes the API-H code to fail parsing of the BPMN response. This doesn't kill the request, as you might expect, but rather, the API-H passes the BPMN response through to the client (VID, or policy, or whatever). The original problem (SO-586) was "fixed" by "removing the wrapper". This "wrapper" is a needed feature of the interface between BPMN and the API-H. We shouldn't have removed it. The fact that the "fix" appeared to work is due to the behavior I described in the previous paragraph. The API-H chokes on the message, and it passes it through unchanged. Not really what we want. So, I don't know why the jackson/json behavior is flaky and different now, but I can (and did) modify the API-H so it can parse a json message whether or not it has a root element. Note that WorkflowResponse.java (in BPMN) and CamundaResponse.java (in the API-H) are basically the same bean representing the message format. Seems less than ideal to have two different classes. Also note that I changed the name of the "response" attribute of the WorkflowResponse and CamundaResponse classes to "content". Got tired of seeing this nonsense everywhere in the code: response.getResponse() Change-Id: Icaf70f8457de99e493cf882170fe778c620308c9 Issue-ID: SO-586 Issue-ID: SO-618 Signed-off-by: Rob Daugherty <rd472p@att.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-common/src/test/java/org/openecomp')
-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());
}