Skip to content

Commit

Permalink
BODY # rawBody
Browse files Browse the repository at this point in the history
  • Loading branch information
nirmalchandra committed Dec 20, 2017
1 parent 33cb0d2 commit 0037523
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public ApiSpec deserialize(final JsonParser jp, final DeserializationContext ctx
final JsonNode jsonBodyNode = apiNode.get("response").get("body");
String responseBody = jsonBodyNode != null? jsonBodyNode.toString() : null;

final JsonNode stringBodyNode = apiNode.get("response").get("stringBody");
final JsonNode rawBodyNode = apiNode.get("response").get("rawBody");
// ------------------------------------------------------------
// Do not read as JSONNode and then toString etc. Not the same
// ------------------------------------------------------------
String stringBody = stringBodyNode != null? stringBodyNode.asText() : null;
String rawBody = rawBodyNode != null? rawBodyNode.asText() : null;

final JsonNode xmlBodyNode = apiNode.get("response").get("xmlBody");
String xmlBody = xmlBodyNode != null ? xmlBodyNode.asText() : null; //TODO- Think how to handle for SOAP xml response
Expand All @@ -58,7 +58,7 @@ public ApiSpec deserialize(final JsonParser jp, final DeserializationContext ctx
String responseHeaders = (null != jsonHeaderNode) ? jsonHeaderNode.toString() : "";

Api api = new Api(apiName, operation, url, body, ignoreBody, headers,
new RestResponse(responseHeaders, responseStatus, responseBody, stringBody, xmlBody));
new RestResponse(responseHeaders, responseStatus, responseBody, rawBody, xmlBody));
apis.add(api);
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/jsmart/simulator/domain/RestResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ public class RestResponse {
private final String headers;
private final int status;
private final String body; //JSON body
private final String stringBody; //non-json body
private final String rawBody; //non-json body
private final String xmlBody; //TODO- For SOAP responses

public RestResponse(String headers, int status, String body, String stringBody, String xmlBody) {
public RestResponse(String headers, int status, String body, String rawBody, String xmlBody) {
this.headers = headers;
this.status = status;
this.body = body;
this.stringBody = stringBody;
this.rawBody = rawBody;
this.xmlBody = xmlBody;
}

Expand All @@ -30,8 +30,8 @@ public String getBody() {
return body;
}

public String getStringBody() {
return stringBody;
public String getrawBody() {
return rawBody;
}

public String getXmlBody() {
Expand All @@ -44,7 +44,7 @@ public String toString() {
"headers='" + headers + '\'' +
", status=" + status +
", body='" + body + '\'' +
", stringBody='" + stringBody + '\'' +
", rawBody='" + rawBody + '\'' +
", xmlBody='" + xmlBody + '\'' +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ private void matchRequestHeaders(CharSequence headerCharSequence, String apiHead
}

private String responseBodyFromInputJson(RestResponse response) {
if (!StringUtils.isEmpty(response.getStringBody())) {
return response.getStringBody();
if (!StringUtils.isEmpty(response.getrawBody())) {
return response.getrawBody();

} else if (!StringUtils.isEmpty(response.getXmlBody())) {
return response.getXmlBody();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/simulators/customers-simulator.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"url": "/nonjson/1",
"response": {
"status": 200,
"stringBody": "non-json-123{}"
"rawBody": "non-json-123{}"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public void willRespondToPOSTAndIgnoreTheRequestBodyAsTrue() throws ClientProtoc
}

@Test
public void willRespondToGet_nonJsonStringBody() throws IOException, SAXException {
public void willRespondToGet_nonJsonrawBody() throws IOException, SAXException {
String endpoint = "/nonjsontest";
Boolean ignoreBody = true;
Api api = new Api(
Expand Down Expand Up @@ -600,7 +600,7 @@ public void willRespondToGet_nonJsonStringBody() throws IOException, SAXExceptio
}

@Test
public void willRespondWith_nonJsonSTringBody() throws Exception {
public void willRespondWith_nonJsonrawBody() throws Exception {
String url = String.format("http://localhost:%d/nonjson/1", simulator.getPort());

HttpClient client = new DefaultHttpClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public final void willDeserializeAndReadResponseJsonUsingJsonPath() throws Exce
}

@Test
public final void willDeserializeNonJsonResponse_StringBody() throws Exception {
public final void willDeserializeNonJsonResponse_rawBody() throws Exception {
final String json = "{\n"
+ " \"name\": \"Micro-Service-Function-Simulator\",\n"
+ " \"apis\": [{\n"
Expand All @@ -193,7 +193,7 @@ public final void willDeserializeNonJsonResponse_StringBody() throws Exception
+ " \"response\": {\n"
+ " \"header\": {},\n"
+ " \"status\": 200,\n"
+ " \"stringBody\": \"non-json{}\"\n"
+ " \"rawBody\": \"non-json{}\"\n"
+ " }\n"
+ " }]\n"
+ " }";
Expand All @@ -205,7 +205,7 @@ public final void willDeserializeNonJsonResponse_StringBody() throws Exception

final ApiSpec readValue = mapper.readValue(json, ApiSpec.class);

assertThat(readValue.getApis().get(0).getResponse().getStringBody(), is("non-json{}"));
assertThat(readValue.getApis().get(0).getResponse().getrawBody(), is("non-json{}"));
}

@Test
Expand Down

0 comments on commit 0037523

Please sign in to comment.