diff --git a/build/libs/web-api-commander.jar b/build/libs/web-api-commander.jar index f6e45cb..340ef77 100644 Binary files a/build/libs/web-api-commander.jar and b/build/libs/web-api-commander.jar differ diff --git a/src/main/java/org/reso/auth/OAuth2HttpClientFactory.java b/src/main/java/org/reso/auth/OAuth2HttpClientFactory.java index 916a82e..c05ca7f 100644 --- a/src/main/java/org/reso/auth/OAuth2HttpClientFactory.java +++ b/src/main/java/org/reso/auth/OAuth2HttpClientFactory.java @@ -29,10 +29,10 @@ import java.util.List; public class OAuth2HttpClientFactory extends AbstractHttpClientFactory { + final static String EXPIRES_IN = "expires_in"; + final static String ACCESS_TOKEN = "access_token"; private static final Logger LOG = LogManager.getLogger(OAuth2HttpClientFactory.class); - HttpClientConnectionManager connectionManager = null; - private String clientId; private String clientSecret; private String tokenUri; @@ -40,15 +40,13 @@ public class OAuth2HttpClientFactory extends AbstractHttpClientFactory { private String accessToken; private Integer expiresIn; - final static String EXPIRES_IN = "expires_in"; - final static String ACCESS_TOKEN = "access_token"; - /** * Creates an OAuth2 client for making HTTP requests using Client Credentials - * @param clientId the client Id of the consumer + * + * @param clientId the client Id of the consumer * @param clientSecret the client secret of the consumer - * @param tokenUri the token uri of the server to connect to - * @param scope (optional) scope + * @param tokenUri the token uri of the server to connect to + * @param scope (optional) scope */ public OAuth2HttpClientFactory(String clientId, String clientSecret, String tokenUri, String scope) { this.clientId = clientId; @@ -96,7 +94,7 @@ public class OAuth2HttpClientFactory extends AbstractHttpClientFactory { if (responseData.get(ACCESS_TOKEN) != null) { accessToken = responseData.get(ACCESS_TOKEN).asText(); } - assert(accessToken != null); + assert (accessToken != null); if (responseData.get(EXPIRES_IN) != null) { expiresIn = responseData.get(EXPIRES_IN).asInt(); @@ -110,7 +108,7 @@ public class OAuth2HttpClientFactory extends AbstractHttpClientFactory { @Override public CloseableHttpClient create(HttpMethod method, URI uri) { - assert(accessToken != null); + assert (accessToken != null); BasicHeader authHeader = new BasicHeader("Authorization", "Bearer " + accessToken); List
headers = new ArrayList<>(); @@ -126,7 +124,7 @@ public class OAuth2HttpClientFactory extends AbstractHttpClientFactory { @Override public void close(HttpClient httpClient) { try { - connectionManager.shutdown(); + if (connectionManager != null) connectionManager.shutdown(); } catch (Exception ex) { LOG.error(ex.toString()); } diff --git a/src/main/java/org/reso/auth/TokenHttpClientFactory.java b/src/main/java/org/reso/auth/TokenHttpClientFactory.java index f4f1956..aad1754 100644 --- a/src/main/java/org/reso/auth/TokenHttpClientFactory.java +++ b/src/main/java/org/reso/auth/TokenHttpClientFactory.java @@ -20,14 +20,13 @@ import java.util.List; * Extends AbstractHttpClientFactory with one that can accept tokens passed in to make requests. */ public class TokenHttpClientFactory extends AbstractHttpClientFactory { - String token; - private static final Logger LOG = LogManager.getLogger(TokenHttpClientFactory.class); - + String token; HttpClientConnectionManager connectionManager = null; /** * Constructor for use with tokens. + * * @param token the token to be used for server requests. */ public TokenHttpClientFactory(String token) { diff --git a/src/main/java/org/reso/certification/features/web-api/web-api-server-1.0.2.feature b/src/main/java/org/reso/certification/features/web-api/web-api-server-1.0.2.feature index d86842b..c29316a 100644 --- a/src/main/java/org/reso/certification/features/web-api/web-api-server-1.0.2.feature +++ b/src/main/java/org/reso/certification/features/web-api/web-api-server-1.0.2.feature @@ -7,8 +7,8 @@ Feature: Web API Server 1.0.2 Certification Background: Given a RESOScript file was provided And Client Settings and Parameters were read from the file - And an OData client was successfully created from the given RESOScript - And the OData client uses authorization_code or client_credentials for authentication + And a test environment was successfully created from the given RESOScript + And the test environment uses an authorization_code or client_credentials for authentication ####################################### @@ -16,12 +16,13 @@ Feature: Web API Server 1.0.2 Certification ####################################### @REQ-WA103-END3 @core @2.4.1 @core-endorsement @metadata Scenario: REQ-WA103-END3 - Request and Validate Server Metadata - When a GET request is made to the resolved Url in "REQ-WA103-END3" + When XML Metadata are requested from the service root in "ClientSettings_WebAPIURI" Then the server responds with a status code of 200 - And the response is valid XML And the XML metadata returned by the server are valid - And a default entity container exists for the service root in "ClientSettings_WebAPIURI" + And Edm metadata are requested from the service root in "ClientSettings_WebAPIURI" + Then the server responds with a status code of 200 And the Edm metadata returned by the server are valid + And the metadata contains a valid service document And the metadata contains the "Parameter_EndpointResource" resource And the given "Parameter_EndpointResource" resource exists within "Parameter_DD17_WellKnownResourceList" And the metadata contains at least one resource from "Parameter_WebAPI102_RequiredResourceList" diff --git a/src/main/java/org/reso/certification/stepdefs/WebAPIServer_1_0_2.java b/src/main/java/org/reso/certification/stepdefs/WebAPIServer_1_0_2.java index 114b11b..6032eab 100644 --- a/src/main/java/org/reso/certification/stepdefs/WebAPIServer_1_0_2.java +++ b/src/main/java/org/reso/certification/stepdefs/WebAPIServer_1_0_2.java @@ -12,12 +12,9 @@ import org.apache.http.HttpStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.olingo.client.api.communication.ODataClientErrorException; -import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.data.ResWrap; import org.apache.olingo.client.api.domain.ClientEntitySet; -import org.apache.olingo.client.api.edm.xml.XMLMetadata; import org.apache.olingo.commons.api.data.EntityCollection; -import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainer; import org.apache.olingo.commons.api.edm.provider.CsdlNavigationProperty; @@ -25,10 +22,9 @@ import org.apache.olingo.commons.api.edm.provider.CsdlProperty; import org.apache.olingo.commons.api.format.ContentType; import org.reso.commander.Commander; import org.reso.commander.TestUtils; -import org.reso.models.ClientSettings; +import org.reso.commander.certfication.containers.WebApiTestContainer; import org.reso.models.Settings; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.InputStream; import java.sql.Time; @@ -54,85 +50,49 @@ public class WebAPIServer_1_0_2 implements En { private static final String SHOW_RESPONSES = "showResponses"; private static final boolean showResponses = Boolean.parseBoolean(System.getProperty(SHOW_RESPONSES)); - private static Settings settings; - - //container to hold retrieved metadata for later comparisons - private static AtomicReference xmlMetadata = new AtomicReference<>(); - private static AtomicReference edm = new AtomicReference<>(); - - private String serviceRoot, bearerToken, clientId, clientSecret, authorizationUri, tokenUri, redirectUri, scope; - private String pathToRESOScript; - /* - * Used to store a static instance of the TestContainer class + * Used to store a static instance of the WebApiTestContainer class */ - private static AtomicReference container = new AtomicReference<>(new TestContainer()); + private static final AtomicReference container = new AtomicReference<>(new WebApiTestContainer()); /** * Entry point to the Web API Server tests */ public WebAPIServer_1_0_2() { - + /* * Background */ Given("^a RESOScript file was provided$", () -> { - if (pathToRESOScript == null) { - pathToRESOScript = System.getProperty("pathToRESOScript"); + if (getTestContainer().getPathToRESOScript() == null) { + getTestContainer().setPathToRESOScript(System.getProperty("pathToRESOScript")); } - assertNotNull("ERROR: pathToRESOScript must be present in command arguments, see README", pathToRESOScript); - LOG.info("Using RESOScript: " + pathToRESOScript); + assertNotNull("ERROR: pathToRESOScript must be present in command arguments, see README", getTestContainer().getPathToRESOScript()); + LOG.info("Using RESOScript: " + getTestContainer().getPathToRESOScript()); }); And("^Client Settings and Parameters were read from the file$", () -> { - if (settings == null) { - settings = Settings.loadFromRESOScript(new File(System.getProperty("pathToRESOScript"))); + if (getTestContainer().getSettings() == null) { + getTestContainer().setSettings(Settings.loadFromRESOScript(new File(System.getProperty("pathToRESOScript")))); } - assertNotNull("ERROR: Settings could not be loaded.", settings); + assertNotNull("ERROR: Settings could not be loaded.", getTestContainer().getSettings()); LOG.info("RESOScript loaded successfully!"); }); - Given("^an OData client was successfully created from the given RESOScript$", () -> { - serviceRoot = settings.getClientSettings().get(ClientSettings.WEB_API_URI); - //TODO: add base64 un-encode when applicable - bearerToken = settings.getClientSettings().get(ClientSettings.BEARER_TOKEN); - if (bearerToken != null && bearerToken.length() > 0) { - LOG.info("Bearer token loaded... first 4 characters: " + bearerToken.substring(0, 4)); - } - - clientId = settings.getClientSettings().get(ClientSettings.CLIENT_IDENTIFICATION); - clientSecret = settings.getClientSettings().get(ClientSettings.CLIENT_SECRET); - authorizationUri = settings.getClientSettings().get(ClientSettings.AUTHORIZATION_URI); - tokenUri = settings.getClientSettings().get(ClientSettings.TOKEN_URI); - redirectUri = settings.getClientSettings().get(ClientSettings.REDIRECT_URI); - scope = settings.getClientSettings().get(ClientSettings.CLIENT_SCOPE); - - LOG.info("Service root is: " + serviceRoot); - - if (container.get().commander.get() == null) { - //create Commander instance - container.get().commander.set(new Commander.Builder() - .clientId(clientId) - .clientSecret(clientSecret) - .tokenUri(tokenUri) - .scope(scope) - .serviceRoot(serviceRoot) - .bearerToken(bearerToken) - .useEdmEnabledClient(true) - .build()); - } + Given("^a test environment was successfully created from the given RESOScript$", () -> { + getTestContainer().initialize(); }); /* * Ensures that the client either uses Authorization Codes or Client Credentials */ - And("^the OData client uses authorization_code or client_credentials for authentication$", () -> { - assertNotNull(container.get().commander.get()); + And("^the test environment uses an authorization_code or client_credentials for authentication$", () -> { + assertNotNull(getTestContainer().getCommander()); assertTrue("ERROR: Commander must either have a valid Authorization Code or Client Credentials configuration.", - container.get().commander.get().isTokenClient() || (container.get().commander.get().isOAuthClient() && container.get().commander.get().hasValidAuthConfig())); + getTestContainer().getCommander().isTokenClient() || (getTestContainer().getCommander().isOAuthClient() && getTestContainer().getCommander().hasValidAuthConfig())); - if (container.get().commander.get().isTokenClient()) { + if (getTestContainer().getCommander().isTokenClient()) { LOG.info("Authentication Type: authorization_code"); - } else if (container.get().commander.get().isOAuthClient()) { + } else if (getTestContainer().getCommander().isOAuthClient()) { LOG.info("Authentication Type: client_credentials"); } }); @@ -141,7 +101,7 @@ public class WebAPIServer_1_0_2 implements En { * REQ-WA103-END2 - validate DataSystem endpoint, if present. */ And("^the results match the expected DataSystem JSON schema$", () -> { - if (container.get().responseCode.get() == HttpStatus.SC_OK && container.get().responseData.get() != null) { + if (getTestContainer().getResponseCode() == HttpStatus.SC_OK && getTestContainer().getResponseData() != null) { try { JsonSchemaFactory factory = JsonSchemaFactory.getInstance(); InputStream is = Thread.currentThread().getContextClassLoader() @@ -149,7 +109,7 @@ public class WebAPIServer_1_0_2 implements En { JsonSchema schema = factory.getSchema(is); ObjectMapper mapper = new ObjectMapper(); - JsonNode node = mapper.readTree(container.get().responseData.get()); + JsonNode node = mapper.readTree(getTestContainer().getResponseData()); if (node.findPath(JSON_VALUE_PATH).size() > 0) { Set errors = schema.validate(node); @@ -161,7 +121,7 @@ public class WebAPIServer_1_0_2 implements En { LOG.info("DataSystem response matches reference schema!"); } } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } } }); @@ -170,46 +130,60 @@ public class WebAPIServer_1_0_2 implements En { * Edm Metadata Validator */ And("^the Edm metadata returned by the server are valid$", () -> { - assertNotNull("ERROR: No Entity Data Model (Edm) Exists!", edm.get()); + assertNotNull("ERROR: No Entity Data Model (Edm) Exists!", getTestContainer().getEdm()); try { - boolean isValid = container.get().commander.get().validateMetadata(edm.get()); + boolean isValid = getTestContainer().getCommander().validateMetadata(getTestContainer().getEdm()); LOG.info("Edm Metadata is " + (isValid ? "valid" : "invalid") + "!"); - assertTrue("Edm Metadata at the given service root is not valid! " + serviceRoot, isValid); + assertTrue("Edm Metadata at the given service root is not valid! " + getTestContainer().getServiceRoot(), isValid); } catch (Exception ex) { - fail("ERROR: could not validate Edm Metadata!\n" + ex.getMessage()); + fail("ERROR: could not validate Edm Metadata!\n" + ex.toString()); } }); - /* - * XMLMetadata Validator + * XML Metadata Validator */ And("^the XML metadata returned by the server are valid$", () -> { - assertNotNull("ERROR: No Response Data exists to convert to XML Metadata!", container.get().responseData.get()); + assertNotNull("ERROR: XML Metadata (EDMX) Exists!", getTestContainer().getXMLMetadata()); try { - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(container.get().responseData.get().getBytes()); - xmlMetadata.set(container.get().commander.get().getClient().getDeserializer(ContentType.APPLICATION_XML).toMetadata(byteArrayInputStream)); - - if (showResponses) LOG.info("XML Metadata is \n" + container.get().responseData.get()); - - boolean isValid = container.get().commander.get().validateMetadata(xmlMetadata.get()); + boolean isValid = getTestContainer().getCommander().validateMetadata(getTestContainer().getXMLMetadata()); LOG.info("XML Metadata is " + (isValid ? "valid" : "invalid") + "!"); - assertTrue("ERROR: XML Metadata at the given service root is not valid! " + serviceRoot, isValid); + assertTrue("XML Metadata at the given service root is not valid! " + getTestContainer().getServiceRoot(), isValid); } catch (Exception ex) { - fail("ERROR: could not validate XML Metadata!\n" + ex.getMessage()); + fail("ERROR: could not validate XML Metadata!\n" + ex.toString()); } }); +// /* +// * XMLMetadata Validator +// */ +// And("^the XML metadata returned by the server are valid$", () -> { +// assertNotNull("ERROR: No Response Data exists to convert to XML Metadata!", getTestContainer().responseData.get()); +// +// try { +// ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(getTestContainer().responseData.get().getBytes()); +// xmlMetadata.set(getTestContainer().commander.get().getClient().getDeserializer(ContentType.APPLICATION_XML).toMetadata(byteArrayInputStream)); +// +// if (showResponses) LOG.info("XML Metadata is: \n" + getTestContainer().responseData.get()); +// +// boolean isValid = getTestContainer().commander.get().validateMetadata(getTestContainer().getXmlMetadata()); +// LOG.info("XML Metadata is " + (isValid ? "valid" : "invalid") + "!"); +// assertTrue("ERROR: XML Metadata at the given service root is not valid! " + serviceRoot, isValid); +// } catch (Exception ex) { +// fail("ERROR: could not validate XML Metadata!\n" + ex.toString()); +// } +// }); + /* * REQ-WA103-QR1 */ And("^the provided \"([^\"]*)\" is returned in \"([^\"]*)\"$", (String parameterUniqueIdValue, String parameterUniqueId) -> { try { - String expectedValueAsString = Settings.resolveParametersString(parameterUniqueIdValue, settings), resolvedValueAsString = null; - Object resolvedValue = from(container.get().responseData.get()).get(Settings.resolveParametersString(parameterUniqueId, settings)); + String expectedValueAsString = Settings.resolveParametersString(parameterUniqueIdValue, getTestContainer().getSettings()); + Object resolvedValue = from(getTestContainer().getResponseData()).get(Settings.resolveParametersString(parameterUniqueId, getTestContainer().getSettings())); //both of the inputs should be present assertNotNull(expectedValueAsString); @@ -228,7 +202,7 @@ public class WebAPIServer_1_0_2 implements En { assertEquals("ERROR: the given String value is not equal to the value found on the server!", expectedValueAsString, resolvedValue.toString()); } } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -238,11 +212,11 @@ public class WebAPIServer_1_0_2 implements En { And("^data are present in fields contained within \"([^\"]*)\"$", (String parameterSelectList) -> { try { AtomicInteger numFieldsWithData = new AtomicInteger(); - List fieldList = new ArrayList<>(Arrays.asList(Settings.resolveParametersString(parameterSelectList, settings).split(FIELD_SEPARATOR))); + List fieldList = new ArrayList<>(Arrays.asList(Settings.resolveParametersString(parameterSelectList, getTestContainer().getSettings()).split(FIELD_SEPARATOR))); AtomicInteger numResults = new AtomicInteger(); //iterate over the items and count the number of fields with data to determine whether there are data present - from(container.get().responseData.get()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> { + from(getTestContainer().getResponseData()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> { if (item != null) { numResults.getAndIncrement(); fieldList.forEach(field -> { @@ -261,9 +235,9 @@ public class WebAPIServer_1_0_2 implements En { } else { LOG.info("Percent Fill: 0% - no fields with data found!"); } - assertTrue("ERROR: no fields with data could be found from the given $select list!",numFieldsWithData.get() > 0); + assertTrue("ERROR: no fields with data could be found from the given $select list!", numFieldsWithData.get() > 0); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -274,16 +248,16 @@ public class WebAPIServer_1_0_2 implements En { */ And("^the results contain at most \"([^\"]*)\" records$", (String parameterTopCount) -> { try { - List items = from(container.get().responseData.get()).getList(JSON_VALUE_PATH); + List items = from(getTestContainer().getResponseData()).getList(JSON_VALUE_PATH); AtomicInteger numResults = new AtomicInteger(items.size()); - int topCount = Integer.parseInt(Settings.resolveParametersString(parameterTopCount, settings)); + int topCount = Integer.parseInt(Settings.resolveParametersString(parameterTopCount, getTestContainer().getSettings())); LOG.info("Number of values returned: " + numResults.get() + ", top count is: " + topCount); assertTrue("ERROR: results count must be greater than zero and less than " + parameterTopCount + "!", numResults.get() > 0 && numResults.get() <= topCount); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -294,24 +268,24 @@ public class WebAPIServer_1_0_2 implements En { */ And("^a GET request is made to the resolved Url in \"([^\"]*)\" with \\$skip=\"([^\"]*)\"$", (String requirementId, String parameterTopCount) -> { try { - int skipCount = Integer.parseInt(Settings.resolveParametersString(parameterTopCount, settings)); + int skipCount = Integer.parseInt(Settings.resolveParametersString(parameterTopCount, getTestContainer().getSettings())); LOG.info("Skip count is: " + skipCount); //preserve initial response data for later comparisons - container.get().initialResponseData.set(container.get().responseData.get()); + getTestContainer().setInitialResponseData(getTestContainer().getResponseData()); //TODO: convert to OData filter factory - container.get().requestUri.set(Commander.prepareURI(Settings.resolveParameters(settings.getRequestById(requirementId), settings).getUrl() - + "&" + Commander.ODATA_QUERY_OPTIONS.SKIP +"=" + skipCount)); - container.set(executeGetRequest(container.get().requestUri.get(), container.get())); + getTestContainer().setRequestUri(Commander.prepareURI(Settings.resolveParameters(getTestContainer().getSettings().getRequestById(requirementId), getTestContainer().getSettings()).getUrl() + + "&" + Commander.ODATA_QUERY_OPTIONS.SKIP + "=" + skipCount)); + getTestContainer().executePreparedGetRequest(); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); And("^data in the \"([^\"]*)\" fields are different in the second request than in the first$", (String parameterUniqueId) -> { try { - List l1 = from(container.get().initialResponseData.get()).getJsonObject(JSON_VALUE_PATH); - List l2 = from(container.get().responseData.get()).getJsonObject(JSON_VALUE_PATH); + List l1 = from(getTestContainer().getInitialResponseData()).getJsonObject(JSON_VALUE_PATH); + List l2 = from(getTestContainer().getResponseData()).getJsonObject(JSON_VALUE_PATH); int combinedCount = l1.size() + l2.size(); Set combined = new LinkedHashSet<>(l1); @@ -325,7 +299,7 @@ public class WebAPIServer_1_0_2 implements En { assertEquals("ERROR: repeated data found, expected unique data on each page!", combinedCount, combined.size()); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -339,11 +313,12 @@ public class WebAPIServer_1_0_2 implements En { When("^a GET request is made to the resolved Url in \"([^\"]*)\"$", (String requestId) -> { try { //reset local state each time a get request is run - container.get().resetState(); + getTestContainer().resetState(); LOG.info("Request ID: " + requestId); - container.get().requestUri.set(Commander.prepareURI(Settings.resolveParameters(settings.getRequestById(requestId), settings).getUrl())); - container.set(executeGetRequest(container.get().requestUri.get(), container.get())); + getTestContainer().setRequestUri(Commander.prepareURI(Settings.resolveParameters( + getTestContainer().getSettings().getRequestById(requestId), getTestContainer().getSettings()).getUrl())); + getTestContainer().executePreparedGetRequest(); } catch (Exception ex) { LOG.debug("Exception was thrown in " + this.getClass() + ": " + ex.toString()); } @@ -354,13 +329,13 @@ public class WebAPIServer_1_0_2 implements En { */ Then("^the server responds with a status code of (\\d+)$", (Integer assertedResponseCode) -> { try { - LOG.info("Asserted Response Code: " + assertedResponseCode + ", Server Response Code: " + container.get().responseCode); - assertTrue(container.get().responseCode.get() > 0 && assertedResponseCode > 0); + LOG.info("Asserted Response Code: " + assertedResponseCode + ", Server Response Code: " + getTestContainer().getResponseCode()); + assertTrue(getTestContainer().getResponseCode() > 0 && assertedResponseCode > 0); assertEquals("ERROR: asserted response code does not match the one returned from the server!", - assertedResponseCode.intValue(), container.get().responseCode.get().intValue()); + assertedResponseCode.intValue(), getTestContainer().getResponseCode().intValue()); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -369,10 +344,10 @@ public class WebAPIServer_1_0_2 implements En { */ And("^the response is valid XML$", () -> { try { - assertTrue("ERROR: invalid XML response!", Commander.validateXML(container.get().responseData.get())); + assertTrue("ERROR: invalid XML response!", Commander.validateXML(getTestContainer().getXMLMetadata())); LOG.info("Response is valid XML!"); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -381,12 +356,13 @@ public class WebAPIServer_1_0_2 implements En { */ And("^the response is valid JSON$", () -> { try { - assertTrue("ERROR: invalid JSON response!", TestUtils.isValidJson(container.get().responseData.get())); + assertTrue("ERROR: invalid JSON response!", TestUtils.isValidJson(getTestContainer().getResponseData())); LOG.info("Response is valid JSON!"); - if (showResponses) LOG.info("Response: " + new ObjectMapper().readTree(container.get().responseData.get()).toPrettyString()); + if (showResponses) + LOG.info("Response: " + new ObjectMapper().readTree(getTestContainer().getResponseData()).toPrettyString()); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -397,13 +373,13 @@ public class WebAPIServer_1_0_2 implements En { */ Then("^the server responds with a status code of (\\d+) if the server headers report OData version \"([^\"]*)\"$", (Integer assertedHttpResponseCode, String assertedODataVersion) -> { try { - boolean versionsMatch = container.get().serverODataHeaderVersion.get().equals(assertedODataVersion), - responseCodesMatch = container.get().responseCode.get().intValue() == assertedHttpResponseCode.intValue(); + boolean versionsMatch = getTestContainer().getServerODataHeaderVersion().equals(assertedODataVersion), + responseCodesMatch = getTestContainer().getResponseCode().intValue() == assertedHttpResponseCode.intValue(); - LOG.info("Asserted OData Version: " + assertedODataVersion + ", Server Version: " + container.get().serverODataHeaderVersion.get()); + LOG.info("Asserted OData Version: " + assertedODataVersion + ", Server Version: " + getTestContainer().getServerODataHeaderVersion()); if (versionsMatch) { - LOG.info("Asserted Response Code: " + assertedHttpResponseCode + ", Response code: " + container.get().responseCode.get()); + LOG.info("Asserted Response Code: " + assertedHttpResponseCode + ", Response code: " + getTestContainer().getResponseCode()); assertTrue("ERROR: asserted response code does not match the one returned from the server!", responseCodesMatch); } } catch (Exception ex) { @@ -419,25 +395,24 @@ public class WebAPIServer_1_0_2 implements En { */ And("^Integer data in \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\"$", (String parameterFieldName, String op, String parameterAssertedValue) -> { try { - String fieldName = Settings.resolveParametersString(parameterFieldName, settings); - int assertedValue = Integer.parseInt(Settings.resolveParametersString(parameterAssertedValue, settings)); + String fieldName = Settings.resolveParametersString(parameterFieldName, getTestContainer().getSettings()); + int assertedValue = Integer.parseInt(Settings.resolveParametersString(parameterAssertedValue, getTestContainer().getSettings())); LOG.info("fieldName: " + fieldName + ", op: " + op + ", assertedValue: " + assertedValue); //subsequent value comparisons are and-ed together while iterating over the list of items, so init to true AtomicBoolean result = new AtomicBoolean(true); - AtomicReference fieldValue = new AtomicReference<>(); //iterate through response data and ensure that with data, the statement fieldName "op" assertValue is true - from(container.get().responseData.get()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> { + from(getTestContainer().getResponseData()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> { fieldValue.set(Integer.parseInt(item.get(fieldName).toString())); result.set(result.get() && TestUtils.compare(fieldValue.get(), op, assertedValue)); }); assertTrue(result.get()); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -446,11 +421,11 @@ public class WebAPIServer_1_0_2 implements En { */ And("^the response has results$", () -> { try { - int count = from(container.get().responseData.get()).getList(JSON_VALUE_PATH, HashMap.class).size(); + int count = from(getTestContainer().getResponseData()).getList(JSON_VALUE_PATH, HashMap.class).size(); LOG.info("Results count is: " + count); assertTrue("ERROR: no results returned from the server!", count > 0); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -459,13 +434,13 @@ public class WebAPIServer_1_0_2 implements En { */ And("^the response has singleton results in \"([^\"]*)\"", (String parameterFieldName) -> { try { - String value = Settings.resolveParametersString(parameterFieldName, settings); - boolean isPresent = from(container.get().responseData.get()).get() != null; - LOG.info("Response value is: " + value); - LOG.info("IsPresent: " + isPresent); + String value = Settings.resolveParametersString(parameterFieldName, getTestContainer().getSettings()); + boolean isPresent = from(getTestContainer().getResponseData()).get() != null; assertTrue("ERROR: singleton results not found for '" + value + "'!", isPresent); + LOG.info("Response value is: " + value); + LOG.info("Is Present: " + isPresent); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -474,12 +449,12 @@ public class WebAPIServer_1_0_2 implements En { */ And("^the number of results is less than or equal to \"([^\"]*)\"$", (String limitField) -> { try { - int count = from(container.get().responseData.get()).getList(JSON_VALUE_PATH, HashMap.class).size(), - limit = Integer.parseInt(Settings.resolveParametersString(limitField, settings)); + int count = from(getTestContainer().getResponseData()).getList(JSON_VALUE_PATH, HashMap.class).size(), + limit = Integer.parseInt(Settings.resolveParametersString(limitField, getTestContainer().getSettings())); LOG.info("Results count is: " + count + ", Limit is: " + limit); assertTrue("ERROR: number of results exceeds that specified in '" + limitField + "'!", count <= limit); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -488,9 +463,9 @@ public class WebAPIServer_1_0_2 implements En { */ And("^Integer data in \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\"$", (String parameterFieldName, String opLhs, String parameterAssertedLhsValue, String andOrOp, String opRhs, String parameterAssertedRhsValue) -> { try { - String fieldName = Settings.resolveParametersString(parameterFieldName, settings); - Integer assertedLhsValue = Integer.parseInt(Settings.resolveParametersString(parameterAssertedLhsValue, settings)), - assertedRhsValue = Integer.parseInt(Settings.resolveParametersString(parameterAssertedRhsValue, settings)); + String fieldName = Settings.resolveParametersString(parameterFieldName, getTestContainer().getSettings()); + Integer assertedLhsValue = Integer.parseInt(Settings.resolveParametersString(parameterAssertedLhsValue, getTestContainer().getSettings())), + assertedRhsValue = Integer.parseInt(Settings.resolveParametersString(parameterAssertedRhsValue, getTestContainer().getSettings())); String op = andOrOp.toLowerCase(); boolean isAndOp = op.contains(AND); @@ -504,7 +479,7 @@ public class WebAPIServer_1_0_2 implements En { rhsValue = new AtomicReference<>(); //iterate through response data and ensure that with data, the statement fieldName "op" assertValue is true - from(container.get().responseData.get()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> { + from(getTestContainer().getResponseData()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> { lhsValue.set(Integer.parseInt(item.get(fieldName).toString())); rhsValue.set(Integer.parseInt(item.get(fieldName).toString())); @@ -523,7 +498,7 @@ public class WebAPIServer_1_0_2 implements En { } }); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -532,14 +507,14 @@ public class WebAPIServer_1_0_2 implements En { */ And("^Date data in \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\"$", (String parameterFieldName, String op, String parameterAssertedValue) -> { try { - String fieldName = Settings.resolveParametersString(parameterFieldName, settings); + String fieldName = Settings.resolveParametersString(parameterFieldName, getTestContainer().getSettings()); AtomicReference fieldValue = new AtomicReference<>(); AtomicReference assertedValue = new AtomicReference<>(); - assertedValue.set(TestUtils.parseDateFromEdmDateString(Settings.resolveParametersString(parameterAssertedValue, settings))); + assertedValue.set(TestUtils.parseDateFromEdmDateString(Settings.resolveParametersString(parameterAssertedValue, getTestContainer().getSettings()))); LOG.info("Asserted value is: " + assertedValue.get().toString()); - from(container.get().responseData.get()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> { + from(getTestContainer().getResponseData()).getList(JSON_VALUE_PATH, HashMap.class).forEach(item -> { try { fieldValue.set(TestUtils.parseDateFromEdmDateTimeOffsetString(item.get(fieldName).toString())); assertTrue(TestUtils.compare(fieldValue.get(), op, assertedValue.get())); @@ -548,7 +523,7 @@ public class WebAPIServer_1_0_2 implements En { } }); } catch (Exception ex) { - fail(ex.getMessage()); + fail(ex.toString()); } }); @@ -557,23 +532,23 @@ public class WebAPIServer_1_0_2 implements En { */ And("^TimeOfDay data in \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\"$", (String parameterFieldName, String op, String parameterAssertedValue) -> { try { - String fieldName = Settings.resolveParametersString(parameterFieldName, settings); + String fieldName = Settings.resolveParametersString(parameterFieldName, getTestContainer().getSettings()); AtomicReference