preliminary check for multi-valued enumerations and some assert cleanup

This commit is contained in:
Joshua Darnell 2020-02-28 11:53:49 -08:00
parent 0784c2e693
commit e9e6eecd1f
4 changed files with 46 additions and 19 deletions

Binary file not shown.

View File

@ -436,11 +436,11 @@
<Request
TestDescription="Support Multi Value Lookups (2)"
RequirementId="REQ-WA103-QM8"
RequirementId="REQ-WA103-QM8.2"
MetallicLevel="Bronze"
Capability="Query functions"
WebAPIReference="2.4.10"
OutputFile="REQ-WA103-QM8_Enum_MVL_Multi.json"
OutputFile="REQ-WA103-QM8.2.json"
Url="*ClientSettings_WebAPIURI*/*Parameter_EndpointResource*?$top=*Parameter_TopCount*&amp;$select=*Parameter_KeyOrKeyNumericField*,*Parameter_MultipleValueLookupField*&amp;$filter=*Parameter_MultipleValueLookupField* ne null and *Parameter_MultipleValueLookupField* has *Parameter_MultipleValueLookupValue1* and *Parameter_MultipleValueLookupField* has *Parameter_MultipleValueLookupValue2**Parameter_RequiredParameters*"
/>

View File

@ -188,4 +188,12 @@ Feature: Web API Server 1.0.2 Certification
Then the server responds with a status code of 200
And the response is valid JSON
And the response has results
And Data in "Parameter_SingleValueLookupField" has "Parameter_SingleLookupValue"
And Single Valued Enumeration Data in "Parameter_SingleValueLookupField" has "Parameter_SingleLookupValue"
@REQ-WA103-QM8 @bronze @2.4.10 @queryability-endorsement
Scenario: Support Multi Value Lookups
When a GET request is made to the resolved Url in "REQ-WA103-QM8"
Then the server responds with a status code of 200
And the response is valid JSON
And the response has results
And Multiple Valued Enumeration Data in "Parameter_MultipleValueLookupField" has "Parameter_MultipleLookupValue1"

View File

@ -1,6 +1,7 @@
package org.reso.certification.stepdefs;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.POJONode;
import io.cucumber.java8.En;
import io.restassured.response.Response;
@ -77,10 +78,12 @@ public class WebAPIServer_1_0_2 implements En {
*/
/*
* Resets the local instance state used during test time. TODO: refactor into collection of AtomicReference<T>
* Resets the local instance state used during test time.
* NOTE: you should add any local variables you need reset between tests here.
*
* TODO: refactor into collection of AtomicReference<T>
*/
Runnable resetState = () -> {
commander.set(null);
Runnable resetRequestState = () -> {
oDataRawResponse.set(null);
request.set(null);
responseCode.set(null);
@ -105,6 +108,7 @@ public class WebAPIServer_1_0_2 implements En {
oDataRawResponse.set(rawRequest.get().execute());
responseData.set(Utils.convertInputStreamToString(oDataRawResponse.get().getRawResponse()));
serverODataHeaderVersion.set(oDataRawResponse.get().getHeader(HEADER_ODATA_VERSION).toString());
responseCode.set(oDataRawResponse.get().getStatusCode());
LOG.info("Request succeeded..." + responseData.get().getBytes().length + " bytes received.");
} catch (ODataClientErrorException cex) {
LOG.debug("OData Client Error Exception caught. Check subsequent test output for asserted conditions...");
@ -120,11 +124,6 @@ public class WebAPIServer_1_0_2 implements En {
* Background
*/
Given("^a RESOScript file was provided$", () -> {
/* NOTE: this item is the first step in the Background */
//Reset ALL local state variables prior to each run.
resetState.run();
if (pathToRESOScript == null) {
pathToRESOScript = System.getProperty("pathToRESOScript");
}
@ -300,6 +299,9 @@ public class WebAPIServer_1_0_2 implements En {
* GET request by requirementId (see generic.resoscript)
*/
When("^a GET request is made to the resolved Url in \"([^\"]*)\"$", (String requirementId) -> {
//reset local state each time a get request is run
resetRequestState.run();
URI requestUri = Commander.prepareURI(Settings.resolveParameters(settings.getRequests().get(requirementId), settings).getUrl());
executeGetRequest.apply(requestUri);
});
@ -308,12 +310,9 @@ public class WebAPIServer_1_0_2 implements En {
* Assert response code
*/
Then("^the server responds with a status code of (\\d+)$", (Integer assertedResponseCode) -> {
responseCode.set(oDataClientErrorException.get() != null
? oDataClientErrorException.get().getStatusLine().getStatusCode()
: oDataRawResponse.get().getStatusCode());
LOG.info("Asserted Response Code: " + assertedResponseCode + ", " + "Server Response Code: " + responseCode);
assertEquals(responseCode.get().intValue(), assertedResponseCode.intValue());
LOG.info("Server Response Code: " + responseCode + ", " + "Asserted Response Code: " + assertedResponseCode);
assertTrue(responseCode.get() > 0 && assertedResponseCode > 0);
assertEquals(assertedResponseCode.intValue(), responseCode.get().intValue());
});
/*
@ -510,9 +509,9 @@ public class WebAPIServer_1_0_2 implements En {
});
/*
* Lookups
* Single-Valued enumerations
*/
And("^Data in \"([^\"]*)\" has \"([^\"]*)\"$", (String parameterFieldName, String parameterAssertedValue) -> {
And("^Single Valued Enumeration Data in \"([^\"]*)\" has \"([^\"]*)\"$", (String parameterFieldName, String parameterAssertedValue) -> {
String fieldName = Settings.resolveParametersString(parameterFieldName, settings);
AtomicReference<String> fieldValue = new AtomicReference<>();
AtomicReference<String> assertedValue = new AtomicReference<>();
@ -529,6 +528,26 @@ public class WebAPIServer_1_0_2 implements En {
assertTrue(result.get());
});
});
And("^Multiple Valued Enumeration Data in \"([^\"]*)\" has \"([^\"]*)\"$", (String parameterFieldName, String parameterAssertedValue) -> {
String fieldName = Settings.resolveParametersString(parameterFieldName, settings);
AtomicReference<String> fieldValue = new AtomicReference<>();
AtomicReference<String> assertedValue = new AtomicReference<>();
AtomicBoolean result = new AtomicBoolean(false);
assertedValue.set(Settings.resolveParametersString(parameterAssertedValue, settings));
LOG.info("Asserted value is: " + assertedValue.get());
from(responseData.get()).getList(JSON_VALUE_PATH, ObjectNode.class).forEach(item -> {
fieldValue.set(item.get(fieldName).toString());
result.set(fieldValue.get().contains(assertedValue.get()));
LOG.info("Assert True: " + fieldValue.get() + " has " + assertedValue.get() + " ==> " + result.get());
assertTrue(result.get());
});
});
}
/**