From 016251ca0472ce3c67f3d0fa3a355ec9d75a1aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Pro=C3=9F?= Date: Wed, 9 Aug 2023 11:50:26 +0200 Subject: [PATCH 1/2] Enhance parsing of result value --- .../org/opengis/cite/ogcapiprocesses10/jobs/Jobs.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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..9f78c00 100644 --- a/src/main/java/org/opengis/cite/ogcapiprocesses10/jobs/Jobs.java +++ b/src/main/java/org/opengis/cite/ogcapiprocesses10/jobs/Jobs.java @@ -2036,18 +2036,16 @@ private void loopOverStatus(JsonNode responseNode){ boolean hasMonitorOrResultLink=false; for (JsonNode currentJsonNode : linksArrayNode) { // Fetch result document - - if(currentJsonNode.get("rel").asText()=="http://www.opengis.net/def/rel/ogc/1.0/results"){ + if(currentJsonNode.get("rel").asText().equals("http://www.opengis.net/def/rel/ogc/1.0/results")){ HttpUriRequest request = new HttpGet(currentJsonNode.get("href").asText()); - request.setHeader("Accept", "application/json"); HttpResponse httpResponse = client.execute(request); - JsonNode resultNode = parseResponse(httpResponse); + String resultString = parseRawResponse(httpResponse); // May be more generic here - Assert.assertEquals(responseNode.asText(), TEST_STRING_INPUT); + Assert.assertTrue(resultString.contains(TEST_STRING_INPUT), "Response does not contain " + TEST_STRING_INPUT + "\n" + resultString); hasMonitorOrResultLink=true; } @@ -2066,6 +2064,9 @@ private void loopOverStatus(JsonNode responseNode){ hasMonitorOrResultLink=true; } } + // if the code gets to this position, no result or monitor link were found + // imho we need to throw an exception + throw new AssertionError("No result (rel='http://www.opengis.net/def/rel/ogc/1.0/results') or monitor (rel='monitor') links were found in response."); } catch (Exception e) { From ba775807e65eb8caa0fa4cc34c7e1e44b8c51feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Pro=C3=9F?= Date: Tue, 12 Dec 2023 10:15:13 +0100 Subject: [PATCH 2/2] Fix execute request and possibility to stop status loop --- .../cite/ogcapiprocesses10/jobs/Jobs.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) 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 9f78c00..ba80b1a 100644 --- a/src/main/java/org/opengis/cite/ogcapiprocesses10/jobs/Jobs.java +++ b/src/main/java/org/opengis/cite/ogcapiprocesses10/jobs/Jobs.java @@ -85,6 +85,9 @@ public class Jobs extends CommonFixture { private static final String EXCEPTION_SCHEMA_URL = "https://schemas.opengis.net/ogcapi/processes/part1/1.0/openapi/schemas/exception.yaml"; private static final String STATUS_SCHEMA_URL = "https://schemas.opengis.net/ogcapi/processes/part1/1.0/openapi/schemas/statusInfo.yaml"; private static final String ASYNC_MODE_NOT_SUPPORTED_MESSAGE = "This test is skipped because the server has not declared support for asynchronous execution mode."; + private int attempts = 0; + private static final int MAX_ATTEMPTS = 4; + private static final int ASYNC_LOOP_WAITING_PERIOD = 5000; private OpenApi3 openApi3; @@ -1494,7 +1497,7 @@ public void testJobCreationSyncRawValueMulti() { public void testJobCreationSyncRawValueOne() { // create job - JsonNode executeNode = createExecuteJsonNodeOneInput(echoProcessId, RESPONSE_VALUE_RAW); + JsonNode executeNode = createExecuteJsonNodeOneOutput(echoProcessId, RESPONSE_VALUE_RAW); try { HttpResponse httpResponse = sendPostRequestSync(executeNode); @@ -2029,7 +2032,11 @@ public void testJobResultsAsyncRawValueMulti() { private void loopOverStatus(JsonNode responseNode){ try{ - + + if(attempts >= MAX_ATTEMPTS) { + throw new Exception(String.format("Server did not return result in %d seconds.", MAX_ATTEMPTS * ASYNC_LOOP_WAITING_PERIOD / 1000)); + } + HttpClient client = HttpClientBuilder.create().build(); ArrayNode linksArrayNode = (ArrayNode) responseNode.get("links"); @@ -2053,13 +2060,20 @@ private void loopOverStatus(JsonNode responseNode){ if(!hasMonitorOrResultLink) for (JsonNode currentJsonNode : linksArrayNode) { + String relString = currentJsonNode.get("rel").asText(); // Fetch status document - if(currentJsonNode.get("rel").asText()=="monitor"){ + if(relString.equals("monitor") || relString.equals("status")){ HttpUriRequest request = new HttpGet(currentJsonNode.get("href").asText()); request.setHeader("Accept", "application/json"); HttpResponse httpResponse = client.execute(request); JsonNode resultNode = parseResponse(httpResponse); + try { + Thread.sleep(ASYNC_LOOP_WAITING_PERIOD); + } catch (Exception e) { + TestSuiteLogger.log(Level.WARNING, e.getMessage()); + } + attempts++; loopOverStatus(resultNode); hasMonitorOrResultLink=true; } @@ -2102,7 +2116,7 @@ public void testJobResultsAsyncRawValueOne() { if(echoProcessSupportsAsync()) { // create job - JsonNode executeNode = createExecuteJsonNodeOneInput(echoProcessId, RESPONSE_VALUE_RAW); + JsonNode executeNode = createExecuteJsonNodeOneOutput(echoProcessId, RESPONSE_VALUE_RAW); try { HttpResponse httpResponse = sendPostRequestASync(executeNode); @@ -2139,14 +2153,16 @@ public void testJobResultsAsyncRawValueOne() { } } - private JsonNode createExecuteJsonNodeOneInput(String echoProcessId, String responseValue) { + private JsonNode createExecuteJsonNodeOneOutput(String echoProcessId, String responseValue) { ObjectNode executeNode = objectMapper.createObjectNode(); ObjectNode inputsNode = objectMapper.createObjectNode(); ObjectNode outputsNode = objectMapper.createObjectNode(); //executeNode.set("id", new TextNode(echoProcessId)); Input inputOne = inputs.get(0); String inputId = inputOne.getId(); - addInput(inputOne, inputsNode); + for (Input input : inputs) { + addInput(input, inputsNode); + } for (Output output : outputs) { if(output.getId().equals(inputId)) { addOutput(output, outputsNode);