Skip to content

Commit

Permalink
Merge pull request #76 from opengeospatial/issue#55
Browse files Browse the repository at this point in the history
Closes #55
  • Loading branch information
dstenger committed Dec 14, 2023
2 parents 66cb503 + 524a625 commit 9df01e6
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/main/java/org/opengis/cite/ogcapiprocesses10/jobs/Jobs.java
Expand Up @@ -86,6 +86,9 @@ public class Jobs extends CommonFixture {
private static final String GEOTIFF_URL = "https://raw.githubusercontent.com/opengeospatial/ets-ogcapi-processes10/master/src/main/resources/org/opengis/cite/testdata/testgeotiff.tiff";
private static final Object TYPE_DEFINITION_ARRAY = "array";
private static final CharSequence ISSUE_54_MESSAGE_TEXT = "More than 1 schema is valid.";
private int attempts = 0;
private static final int MAX_ATTEMPTS = 4;
private static final int ASYNC_LOOP_WAITING_PERIOD = 5000;

private OpenApi3 openApi3;

Expand Down Expand Up @@ -171,7 +174,7 @@ public void setup(ITestContext testContext) {
getResultValidator = new OperationValidator(openApi3, getResultPath, getResultOperation);
getJobsListURL = new URL(jobsListEndpointString);
getProcessesListURL = new URL(processListEndpointString);
getInvalidJobURL = new URL(processListEndpointString + "/invalid-job-" + UUID.randomUUID());
getInvalidJobURL = new URL(jobsListEndpointString + "/invalid-job-" + UUID.randomUUID());
getInvalidJobResultURL = new URL(jobsListEndpointString + "/invalid-job-" + UUID.randomUUID() + "/results");
clientBuilder = HttpClientBuilder.create();
} catch (Exception e) {
Expand Down Expand Up @@ -1724,7 +1727,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, true);
Expand Down Expand Up @@ -2316,44 +2319,56 @@ private boolean loopOverStatusReturnsFailed(JsonNode responseNode){

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");

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);
this.rspEntity = responseNode.asText();

// 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;
}

}

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;
}
}
// 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) {
Expand Down Expand Up @@ -2389,7 +2404,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);
Expand Down Expand Up @@ -2428,14 +2443,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);
Expand Down

0 comments on commit 9df01e6

Please sign in to comment.