From 0f014f29725d3876fd8198cb05b4794d3f5c2c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Pro=C3=9F?= Date: Thu, 27 Jul 2023 08:46:03 +0200 Subject: [PATCH] Add response body to report --- .../cite/ogcapiprocesses10/conformance/Conformance.java | 1 + .../cite/ogcapiprocesses10/general/GeneralHttp.java | 1 + .../opengis/cite/ogcapiprocesses10/joblist/JobList.java | 6 ++++-- .../org/opengis/cite/ogcapiprocesses10/jobs/Jobs.java | 5 +++++ .../ogcprocessdescription/OGCProcessDescription.java | 8 ++++++++ .../opengis/cite/ogcapiprocesses10/process/Process.java | 3 +++ .../cite/ogcapiprocesses10/processlist/ProcessList.java | 6 +++++- 7 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/opengis/cite/ogcapiprocesses10/conformance/Conformance.java b/src/main/java/org/opengis/cite/ogcapiprocesses10/conformance/Conformance.java index 1b548ac..2123727 100644 --- a/src/main/java/org/opengis/cite/ogcapiprocesses10/conformance/Conformance.java +++ b/src/main/java/org/opengis/cite/ogcapiprocesses10/conformance/Conformance.java @@ -83,6 +83,7 @@ public void storeRequirementClassesInTestContext( ITestContext testContext ) { public void testValidateConformanceOperationAndResponse( TestPoint testPoint ) { String testPointUri = testPoint.getServerUrl() + testPoint.getPath(); Response response = init().baseUri( testPointUri ).accept( JSON ).when().request( GET ); + this.rspEntity = response.getBody().asInputStream(); validateConformanceOperationResponse( testPointUri, response ); } diff --git a/src/main/java/org/opengis/cite/ogcapiprocesses10/general/GeneralHttp.java b/src/main/java/org/opengis/cite/ogcapiprocesses10/general/GeneralHttp.java index dc93ba7..8a4a742 100644 --- a/src/main/java/org/opengis/cite/ogcapiprocesses10/general/GeneralHttp.java +++ b/src/main/java/org/opengis/cite/ogcapiprocesses10/general/GeneralHttp.java @@ -33,6 +33,7 @@ public class GeneralHttp extends CommonFixture { @Test(description = "Implements A.2.1.1. HTTP, Abstract Test 1 (Requirement /req/core/http)") public void testHttp() { Response response = init().baseUri( rootUri.toString() ).when().request( GET, "/" ); + this.rspEntity = response.getBody().asInputStream(); response.then().statusLine( containsString( "HTTP/1.1" ) ); } diff --git a/src/main/java/org/opengis/cite/ogcapiprocesses10/joblist/JobList.java b/src/main/java/org/opengis/cite/ogcapiprocesses10/joblist/JobList.java index 7d84125..797b04b 100644 --- a/src/main/java/org/opengis/cite/ogcapiprocesses10/joblist/JobList.java +++ b/src/main/java/org/opengis/cite/ogcapiprocesses10/joblist/JobList.java @@ -118,8 +118,9 @@ public void testJobList() { HttpResponse httpResponse = client.execute(request); StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); - IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); - String responsePayload = writer.toString(); + IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + String responsePayload = writer.toString(); + this.rspEntity = responsePayload; JsonNode responseNode = new ObjectMapper().readTree(responsePayload); ArrayNode arrayNode = (ArrayNode) responseNode.get("jobs"); Assert.assertTrue(arrayNode.size()>0,"No processes listed at "+getJobListURL.toString()); @@ -156,6 +157,7 @@ public void testJobListSuccess() { String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); String responsePayload = writer.toString(); + this.rspEntity = responsePayload; JsonNode responseNode = new ObjectMapper().readTree(responsePayload); Body body = Body.from(responseNode); Header contentType = httpResponse.getFirstHeader(CONTENT_TYPE); diff --git a/src/main/java/org/opengis/cite/ogcapiprocesses10/jobs/Jobs.java b/src/main/java/org/opengis/cite/ogcapiprocesses10/jobs/Jobs.java index 34e8ab8..1262634 100644 --- a/src/main/java/org/opengis/cite/ogcapiprocesses10/jobs/Jobs.java +++ b/src/main/java/org/opengis/cite/ogcapiprocesses10/jobs/Jobs.java @@ -862,6 +862,7 @@ public void testJobCreationInputRef() { } String responsePayload = writer.toString(); + this.rspEntity = responsePayload; if(!responsePayload.contains("Content-Type: multipart/related")) { JsonNode responseNode = null; @@ -954,6 +955,7 @@ public void testJobCreationInputValidation() { httpResponse = sendPostRequestSync(executeNode); responsePayload = parseRawResponse(httpResponse); + this.rspEntity = responsePayload; } catch(Exception ee) @@ -1001,6 +1003,7 @@ public void testJobCreationInputValidation() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(writer.toString()); Body body = Body.from(responseNode); responseContentType = httpResponse.getFirstHeader(CONTENT_TYPE); @@ -1317,6 +1320,7 @@ private JsonNode parseResponse(HttpResponse httpResponse) throws IOException { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); return new ObjectMapper().readTree(writer.toString()); } @@ -1422,6 +1426,7 @@ private void validateMultipartResponse(String responsePayload, JsonNode executeN boolean multipartIsValid = true; String errorMessage = ""; + this.rspEntity = responsePayload; try { diff --git a/src/main/java/org/opengis/cite/ogcapiprocesses10/ogcprocessdescription/OGCProcessDescription.java b/src/main/java/org/opengis/cite/ogcapiprocesses10/ogcprocessdescription/OGCProcessDescription.java index 5892a79..3847290 100644 --- a/src/main/java/org/opengis/cite/ogcapiprocesses10/ogcprocessdescription/OGCProcessDescription.java +++ b/src/main/java/org/opengis/cite/ogcapiprocesses10/ogcprocessdescription/OGCProcessDescription.java @@ -125,6 +125,7 @@ public void testOGCProcessDescriptionJSON() { StringWriter writer2 = new StringWriter(); String encoding2 = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse2.getEntity().getContent(), writer2, encoding2); + this.rspEntity = (this.rspEntity == null ? "" : this.rspEntity) + "\n" + writer2.toString(); JsonNode responseNode2 = new ObjectMapper().readTree(writer2.toString()); Body body2 = Body.from(responseNode2); Header contentType2 = httpResponse2.getFirstHeader(CONTENT_TYPE); @@ -145,6 +146,7 @@ public void testOGCProcessDescriptionJSON() { StringWriter writer2 = new StringWriter(); String encoding2 = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse2.getEntity().getContent(), writer2, encoding2); + this.rspEntity = writer2.toString(); JsonNode responseNode2 = new ObjectMapper().readTree(writer2.toString()); Body body2 = Body.from(responseNode2); Header contentType2 = httpResponse2.getFirstHeader(CONTENT_TYPE); @@ -192,6 +194,7 @@ public void testOGCProcessDescriptionInputsDef() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(writer.toString()); JsonNode processesNode = responseNode.get("processes"); if(processesNode.isArray()) { @@ -246,6 +249,7 @@ public void testOGCProcessDescriptionInputDef() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(writer.toString()); JsonNode processesNode = responseNode.get("processes"); if(processesNode.isArray()) { @@ -303,6 +307,7 @@ public void testOGCProcessDescriptionInputDefinitionOfMixedType() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(writer.toString()); JsonNode processesNode = responseNode.get("processes"); if(processesNode.isArray()) { @@ -361,6 +366,7 @@ public void testOGCProcessDescriptionOutputsDef() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(writer.toString()); JsonNode processesNode = responseNode.get("processes"); if(processesNode.isArray()) { @@ -415,6 +421,7 @@ public void testOGCProcessDescriptionOutputDef() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(writer.toString()); JsonNode processesNode = responseNode.get("processes"); if(processesNode.isArray()) { @@ -472,6 +479,7 @@ public void testOGCProcessDescriptionOutputDefinitionOfMixedType() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(writer.toString()); JsonNode processesNode = responseNode.get("processes"); if(processesNode.isArray()) { diff --git a/src/main/java/org/opengis/cite/ogcapiprocesses10/process/Process.java b/src/main/java/org/opengis/cite/ogcapiprocesses10/process/Process.java index 68ae8e4..974dab7 100644 --- a/src/main/java/org/opengis/cite/ogcapiprocesses10/process/Process.java +++ b/src/main/java/org/opengis/cite/ogcapiprocesses10/process/Process.java @@ -115,6 +115,7 @@ public void testProcessExceptionNoSuchProcess() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(writer.toString()); Body body = Body.from(responseNode); Header contentType = httpResponse.getFirstHeader(CONTENT_TYPE); @@ -153,6 +154,7 @@ public void testProcess() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(writer.toString()); Body body = Body.from(responseNode); Header contentType = httpResponse.getFirstHeader(CONTENT_TYPE); @@ -199,6 +201,7 @@ public void testProcessSuccess() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(writer.toString()); Body body = Body.from(responseNode); Header contentType = httpResponse.getFirstHeader(CONTENT_TYPE); diff --git a/src/main/java/org/opengis/cite/ogcapiprocesses10/processlist/ProcessList.java b/src/main/java/org/opengis/cite/ogcapiprocesses10/processlist/ProcessList.java index 1e6ad6e..1cd48fc 100644 --- a/src/main/java/org/opengis/cite/ogcapiprocesses10/processlist/ProcessList.java +++ b/src/main/java/org/opengis/cite/ogcapiprocesses10/processlist/ProcessList.java @@ -123,6 +123,7 @@ public void testPlLimitResponse() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(writer.toString()); JsonNode processesNode = responseNode.get("processes"); if(!(processesNode instanceof ArrayNode)) { @@ -160,6 +161,7 @@ public void testPlLinks() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(writer.toString()); JsonNode linksNode = responseNode.get("links"); if(!(linksNode instanceof ArrayNode)) { @@ -197,7 +199,8 @@ public void testProcessList() { HttpResponse httpResponse = client.execute(request); StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); - IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); String responsePayload = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(responsePayload); ArrayNode arrayNode = (ArrayNode) responseNode.get("processes"); @@ -241,6 +244,7 @@ public void testProcessListSuccess() { StringWriter writer = new StringWriter(); String encoding = StandardCharsets.UTF_8.name(); IOUtils.copy(httpResponse.getEntity().getContent(), writer, encoding); + this.rspEntity = writer.toString(); String responsePayload = writer.toString(); JsonNode responseNode = new ObjectMapper().readTree(responsePayload); Body body = Body.from(responseNode);