diff --git a/docs/modules/commons/pages/variables.adoc b/docs/modules/commons/pages/variables.adoc index 0816875b97..ebc160ca45 100644 --- a/docs/modules/commons/pages/variables.adoc +++ b/docs/modules/commons/pages/variables.adoc @@ -102,7 +102,7 @@ When I set request headers: \|name \|value \| \|Content-Type\|application/json\| When I execute HTTP POST request for resource with URL `${login-endpoint}` -Then the response code is equal to '200' +Then response code is equal to `200` ---- [WARNING] @@ -129,7 +129,7 @@ When I set request headers: \|name \|value \| \|Content-Type\|application/json\| When I execute HTTP POST request for resource with URL `/authenticate` -Then the response code is equal to '200' +Then response code is equal to `200` ---- |=== diff --git a/docs/modules/plugins/pages/plugin-excel.adoc b/docs/modules/plugins/pages/plugin-excel.adoc index 32cf9dd540..98a5d2a33e 100644 --- a/docs/modules/plugins/pages/plugin-excel.adoc +++ b/docs/modules/plugins/pages/plugin-excel.adoc @@ -166,7 +166,7 @@ Then `$excelDocument` contains excel sheet with name `$name` and records:$record [source,gherkin] ---- When I execute HTTP GET request for resource with URL `https://github.com/vividus-framework/vividus/blob/master/vividus-plugin-excel/src/test/resources/TestTemplate.xlsx?raw=true` -Then the response code is = '200' +Then response code is = `200` Then `${response-as-bytes}` contains excel sheet with name `Mapping` and records: {valueSeparator=!} |cellsRange|valueRegex | @@ -192,7 +192,7 @@ Then `$excelDocument` contains excel sheet with index `$index` and records:$reco [source,gherkin] ---- When I execute HTTP GET request for resource with URL `https://github.com/vividus-framework/vividus/blob/master/vividus-plugin-excel/src/test/resources/TestTemplate.xlsx?raw=true` -Then the response code is = '200' +Then response code is = `200` Then `${response-as-bytes}` contains excel sheet with index `0` and records: {valueSeparator=!} |cellsRange|valueRegex | diff --git a/docs/modules/plugins/pages/plugin-json.adoc b/docs/modules/plugins/pages/plugin-json.adoc index 5aeed6a2e1..f3d189fb76 100644 --- a/docs/modules/plugins/pages/plugin-json.adoc +++ b/docs/modules/plugins/pages/plugin-json.adoc @@ -19,7 +19,7 @@ ${json-context} .Validate the HTTP response matches the regular expression [source,gherkin] ---- -When I send HTTP GET to the relative URL '/get?productsPerPage=5' +When I execute HTTP GET request for resource with relative URL `/get?productsPerPage=5` Then number of JSON elements from `${json-context}` by JSON path `$.product` is equal to 5 ---- diff --git a/docs/modules/plugins/pages/plugin-rest-api.adoc b/docs/modules/plugins/pages/plugin-rest-api.adoc index 2e488dd1d5..9ba873573e 100644 --- a/docs/modules/plugins/pages/plugin-rest-api.adoc +++ b/docs/modules/plugins/pages/plugin-rest-api.adoc @@ -55,7 +55,7 @@ This expression allows to remove wrapping double quotes and use the value as is. [source,gherkin] ---- When I save a JSON element from '${response}' by JSON path '$.id' to story variable 'id' -When I send HTTP GET to the relative URL 'rest/#{removeWrappingDoubleQuotes(${id})}' +When I execute HTTP GET request for resource with relative URL `rest/#{removeWrappingDoubleQuotes(${id})}` ---- .Examples of the expressions removing wrapping double quotes @@ -160,7 +160,7 @@ ${response} .Validate the HTTP response matches the regular expression [source,gherkin] ---- -When I send HTTP GET to the relative URL '/get?name=Content' +When I execute HTTP GET request for resource with relative URL `/get?name=Content` Then `${response}` matches `.+Home.+` ---- @@ -194,7 +194,7 @@ ${response-code} .Validate the HTTP response code [source,gherkin] ---- -When I send HTTP GET to the relative URL '/get?name=Content' +When I execute HTTP GET request for resource with relative URL `/get?name=Content` Then `${response-code}` is equal to `200` ---- @@ -393,7 +393,7 @@ Given request body: #{loadBinaryResource(/data/image.png)} When I set request headers: |name |value | |Content-Type|image/png| -When I send HTTP POST to the relative URL '/upload/png' +When I execute HTTP POST request for resource with relative URL `/upload/png` ---- === Prepare multipart HTTP request @@ -807,8 +807,8 @@ When I wait for response code $responseCode for $duration duration retrying $ret [source,gherkin] ---- When I wait for response code `200` for `PT10S` duration retrying 3 times -|step | -|When I send HTTP GET to the relative URL '/delayed-resource'| +|step | +|When I execute HTTP GET request for resource with relative URL `/delayed-resource` | ---- === Validate content type of response body diff --git a/vividus-plugin-rest-api/src/main/java/org/vividus/steps/api/HttpResponseValidationSteps.java b/vividus-plugin-rest-api/src/main/java/org/vividus/steps/api/HttpResponseValidationSteps.java index 145ca3615f..120f4a32ee 100644 --- a/vividus-plugin-rest-api/src/main/java/org/vividus/steps/api/HttpResponseValidationSteps.java +++ b/vividus-plugin-rest-api/src/main/java/org/vividus/steps/api/HttpResponseValidationSteps.java @@ -32,15 +32,9 @@ import org.apache.hc.core5.http.HeaderElement; import org.apache.hc.core5.http.message.MessageSupport; import org.apache.tika.Tika; -import org.hamcrest.Matchers; -import org.jbehave.core.annotations.Alias; import org.jbehave.core.annotations.Then; import org.jbehave.core.annotations.When; import org.jbehave.core.model.ExamplesTable; -import org.jbehave.core.steps.Parameters; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.vividus.annotation.Replacement; import org.vividus.context.VariableContext; import org.vividus.http.ConnectionDetails; import org.vividus.http.HttpTestContext; @@ -58,8 +52,6 @@ public class HttpResponseValidationSteps { - private static final Logger LOGGER = LoggerFactory.getLogger(HttpResponseValidationSteps.class); - private static final String HTTP_RESPONSE_STATUS_CODE = "HTTP response status code"; private static final Tika TIKA = new Tika(); @@ -77,21 +69,6 @@ public HttpResponseValidationSteps(HttpTestContext httpTestContext, VariableCont this.jsonUtils = jsonUtils; } - /** - * @deprecated Please use step Then response does not contain body - *
- *
- * - * Validates that the HTTP response does not contain a body. - */ - @Deprecated(since = "0.5.0", forRemoval = true) - @Replacement(versionToRemoveStep = "0.6.0", replacementFormatPattern = "Then response does not contain body") - @Then("the response does not contain body") - public void doesResponseNotContainBody() - { - doesResponseContainNoBody(); - } - /** * Validates that the HTTP response does not contain a body. */ @@ -102,42 +79,6 @@ public void doesResponseContainNoBody() response -> softAssert.assertNull("The response does not contain body", response.getResponseBody())); } - /** - * @deprecated Please use step Then `$variable1` is $comparisonRule `$variable2` in conjunction with the - * ${response} dynamic variable - *
- *
- * - * Checks HTTP response body matches to the specified content according to the provided string validation rule - *

- * Actions performed at this step: - *

- * - *

Step can't be used without previous step with HTTP-method

- * - * @param comparisonRule The rule to match the variable value. The supported rules: - * - * @param content The body content part - */ - @Deprecated(since = "0.5.0", forRemoval = true) - @Then("the response body $comparisonRule '$content'") - public void doesResponseBodyMatch(StringComparisonRule comparisonRule, String content) - { - LOGGER.warn("The step: \"Then the response body $comparisonRule '$content'\" is deprecated and will be removed" - + " in VIVIDUS 0.6.0. Use ${response} dynamic variable with \"Then `$variable1` is $comparisonRule " - + "`$variable2`\" step"); - performIfHttpResponseIsPresent(response -> softAssert.assertThat("HTTP response body", - response.getResponseBodyAsString(), comparisonRule.createMatcher(content))); - } - /** * Checks content type of HTTP response body matches to the specified expected content type according to * the provided string validation rule @@ -168,24 +109,6 @@ public void assertContentTypeOfResponseBody(StringComparisonRule comparisonRule, }); } - /** - * @deprecated Please use step Then response body $validationRule resource at `$resourcePath` - *
- *
- * - * Compares the HTTP response body against the resource data according to the provided rule. - * - * @param validationRule The validation rule, either is equal to or is not equal to - * @param resourcePath The resource path - */ - @Deprecated(since = "0.5.0", forRemoval = true) - @Replacement(versionToRemoveStep = "0.6.0", replacementFormatPattern = "Then response body %1$s resource at `%2$s`") - @Then(value = "the response body $validationRule resource at '$resourcePath'", priority = 1) - public void doesResponseBodyMatchResource(ByteArrayValidationRule validationRule, String resourcePath) - { - compareResponseBodyAgainstResource(validationRule, resourcePath); - } - /** * Compares the HTTP response body against the resource data according to the provided rule. * @@ -221,34 +144,6 @@ public void doesDecompressedResponseBodySizeConfirmRule(ComparisonRule compariso comparisonRule.getComparisonRule(sizeInBytes))); } - /** - * @deprecated Please use step Then response code is $comparisonRule `$responseCode` - *
- *
- * - * Compares the HTTP response status code - * against the expected number. - * - * @param comparisonRule The rule to match the variable value. The supported rules: - * - * @param responseCode The expected HTTP - * response status code - */ - @Deprecated(since = "0.5.0", forRemoval = true) - @Replacement(versionToRemoveStep = "0.6.0", replacementFormatPattern = "Then response code is %1$s `%2$s`") - @Then("the response code is $comparisonRule '$responseCode'") - public void assertResponseCode(ComparisonRule comparisonRule, int responseCode) - { - validateResponseCode(comparisonRule, responseCode); - } - /** * Compares the HTTP response status code * against the expected number. @@ -272,26 +167,6 @@ public void validateResponseCode(ComparisonRule comparisonRule, int responseCode response.getStatusCode(), comparisonRule.getComparisonRule(responseCode))); } - /** - * @deprecated Please use step Then response time is $comparisonRule `$responseTime` milliseconds - *
- *
- * - * Validates that the HTTP response is less than the expected number in milliseconds. - * - * @param responseTimeThresholdMs The maximum response time in milliseconds - */ - @Deprecated(since = "0.5.0", forRemoval = true) - @Replacement(versionToRemoveStep = "0.6.0", - replacementFormatPattern = "Then response time is less than `%1$s` milliseconds") - @Then("the response time should be less than '$responseTimeThresholdMs' milliseconds") - public void thenTheResponseTimeShouldBeLessThan(long responseTimeThresholdMs) - { - performIfHttpResponseIsPresent( - response -> softAssert.assertThat("The response time is less than response time threshold.", - response.getResponseTimeInMs(), Matchers.lessThan(responseTimeThresholdMs))); - } - /** * Compares the HTTP response time against the expected number in milliseconds. * @@ -313,61 +188,6 @@ public void validateResponseTime(ComparisonRule comparisonRule, long responseTim response.getResponseTimeInMs(), comparisonRule.getComparisonRule(responseTime))); } - /** - * @deprecated Please use step Then response header `$headerName` contains elements:$elements - *
- *
- * - * Validates that the response header with the specified name contains elements. Might be useful to verify such - * HTTP headers as Set-Cookie that have values that can be decomposed into multiple elements. - *
- *
- * HTTP header with elements format: - *
- * - * header = [ element ] *( "," [ element ] ) - * - *
- *
- * Step example: - *
- * - * Then response header 'Set-Cookie' contains attribute: - *
- * |attribute| - *
- * |JSESSION | - *
- * |clientId | - *
- * - * @param httpHeaderName The - * HTTP response header name - * @param attributes The ExamplesTable with expected elements - */ - @Deprecated(since = "0.5.0", forRemoval = true) - @Then("response header '$httpHeaderName' contains attribute:$attributes") - public void assertHeaderContainsAttributes(String httpHeaderName, ExamplesTable attributes) - { - LOGGER.warn("The step \"Then response header '$httpHeaderName' contains attribute:$attributes\" " - + "is deprecated and will be removed in VIVIDUS 0.6.0. " - + "Please use step \"Then response header `$headerName` contains elements:$elements\""); - performIfHttpResponseIsPresent(response -> - { - getHeaderByName(response, httpHeaderName).ifPresent(header -> - { - List actualAttributes = extractHeaderElementsNames(header); - for (Parameters row : attributes.getRowsAsParameters(true)) - { - String expectedAttribute = row.valueAs("attribute", String.class); - softAssert.assertThat( - String.format("%s header contains %s attribute", httpHeaderName, expectedAttribute), - actualAttributes, contains(expectedAttribute)); - } - }); - }); - } - /** * Validates that the response header with the specified name contains elements. Might be useful to verify such * HTTP headers as Set-Cookie that have values that can be decomposed into multiple elements. @@ -410,34 +230,6 @@ public void checkHeaderContainsElements(String headerName, ExamplesTable element })); } - /** - * @deprecated Please use step Then value of response header `$headerName` $comparisonRule `$value` - *
- *
- * - * Compares the header value against the expected value according to the comparison rule. - * - * @param httpHeaderName The - * HTTP response header name - * @param comparisonRule The rule to match the variable value. The supported rules: - * - * @param value The expected HTTP header value - */ - @Deprecated(since = "0.5.0", forRemoval = true) - @Replacement(versionToRemoveStep = "0.6.0", - replacementFormatPattern = "Then value of response header `%1$s` %2$s `%3$s`") - @Then("the value of the response header '$httpHeaderName' $comparisonRule '$value'") - @Alias("the value of the response header \"$httpHeaderName\" $comparisonRule \"$value\"") - public void doesHeaderMatch(String httpHeaderName, StringComparisonRule comparisonRule, String value) - { - validateHeaderValue(httpHeaderName, comparisonRule, value); - } - /** * Compares the header value against the expected value according to the comparison rule. * @@ -460,38 +252,6 @@ public void validateHeaderValue(String headerName, StringComparisonRule comparis comparisonRule.createMatcher(value)))); } - /** - * @deprecated Please use step Then number of response headers with name `$headerName` is $comparisonRule - * $number - *
- *
- * - * Validates the number of HTTP response headers filtered by the specified name. - * - * @param headerName The - * HTTP response header name - * @param comparisonRule The rule to match the quantity of headers. The supported rules: - * - * @param value The expected number of headers - */ - @Deprecated(since = "0.5.0", forRemoval = true) - @Replacement(versionToRemoveStep = "0.6.0", - replacementFormatPattern = "Then number of response headers with name `%1$s` is %2$s %3$s") - @Then("the number of the response headers with the name '$headerName' is $comparisonRule $value") - public void isHeaderWithNameFound(String headerName, ComparisonRule comparisonRule, int value) - { - performIfHttpResponseIsPresent(response -> softAssert.assertThat( - String.format("The number of the response headers with the name '%s'", headerName), - (int) response.getHeadersByName(headerName).count(), comparisonRule.getComparisonRule(value))); - } - /** * Validates the number of HTTP response headers filtered by the specified name. * @@ -516,36 +276,6 @@ public void validateNumberOfResponseHeaders(String headerName, ComparisonRule co (int) response.getHeadersByName(headerName).count(), comparisonRule.getComparisonRule(number))); } - /** - * @deprecated Please use step When I save response header `$headerName` value to $scopes variable - * `$variableName` - *
- *
- * - * Saves the HTTP response header value into a variable. - * - * @param httpHeaderName The - * HTTP response header name - * @param scopes The set (comma separated list of scopes e.g.: STORY, NEXT_BATCHES) of the variable - * scopes.
- * Available scopes: - * - * @param variableName The variable name to store the header value. - */ - @Deprecated(since = "0.5.0", forRemoval = true) - @Replacement(versionToRemoveStep = "0.6.0", - replacementFormatPattern = "When I save response header `%1$s` value to %2$s variable `%3$s`") - @When("I save response header '$httpHeaderName' value to $scopes variable '$variableName'") - public void saveHeaderValue(String httpHeaderName, Set scopes, String variableName) - { - saveHeaderValueToVariable(httpHeaderName, scopes, variableName); - } - /** * Saves the HTTP response header value into a variable. * @@ -569,24 +299,6 @@ public void saveHeaderValueToVariable(String headerName, Set scop .ifPresent(value -> variableContext.putVariable(scopes, variableName, value))); } - /** - * @deprecated Please use step Then connection is secured using $securityProtocol protocol - *
- *
- * - * Validates that the HTTP connection is secured with the defined security protocol. - * - * @param securityProtocol The expected security protocol, e.g. TLSv1.2, TLSv1.3 - */ - @Deprecated(since = "0.5.0", forRemoval = true) - @Replacement(versionToRemoveStep = "0.6.0", - replacementFormatPattern = "Then connection is secured using %1$s protocol") - @Then("the connection is secured using $securityProtocol protocol") - public void isConnectionSecured(String securityProtocol) - { - validateConnectionIsSecured(securityProtocol); - } - /** * Validates that the HTTP connection is secured with the defined security protocol. * diff --git a/vividus-plugin-rest-api/src/main/resources/steps/defaults/composite.steps b/vividus-plugin-rest-api/src/main/resources/steps/defaults/composite.steps deleted file mode 100644 index 5d2c0c802c..0000000000 --- a/vividus-plugin-rest-api/src/main/resources/steps/defaults/composite.steps +++ /dev/null @@ -1,7 +0,0 @@ -Composite: When I send HTTP $httpMethod to the relative URL '$relativeURL' -!-- DEPRECATED: 0.6.0, When I execute HTTP %1$s request for resource with relative URL `%2$s` -When I execute HTTP request for resource with relative URL `` - -Composite: When I save response body to the $scopes variable '$variableName' -!-- DEPRECATED: 0.6.0, Given I initialize %1$s variable `%2$s` with value `${response}` -Given I initialize variable `` with value `${response}` diff --git a/vividus-plugin-rest-api/src/test/java/org/vividus/steps/api/HttpResponseValidationStepsTests.java b/vividus-plugin-rest-api/src/test/java/org/vividus/steps/api/HttpResponseValidationStepsTests.java index 038afac5fb..939493f444 100644 --- a/vividus-plugin-rest-api/src/test/java/org/vividus/steps/api/HttpResponseValidationStepsTests.java +++ b/vividus-plugin-rest-api/src/test/java/org/vividus/steps/api/HttpResponseValidationStepsTests.java @@ -16,10 +16,7 @@ package org.vividus.steps.api; -import static com.github.valfirst.slf4jtest.LoggingEvent.warn; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThan; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; @@ -38,11 +35,6 @@ import java.util.Optional; import java.util.Set; -import com.github.valfirst.slf4jtest.TestLogger; -import com.github.valfirst.slf4jtest.TestLoggerFactory; -import com.github.valfirst.slf4jtest.TestLoggerFactoryExtension; - -import org.apache.commons.lang3.StringUtils; import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.message.BasicHeader; import org.hamcrest.Matchers; @@ -67,12 +59,9 @@ import org.vividus.util.json.JsonUtils; import org.vividus.variable.VariableScope; -@ExtendWith({ MockitoExtension.class, TestLoggerFactoryExtension.class }) -@SuppressWarnings("checkstyle:MethodCount") +@ExtendWith(MockitoExtension.class) class HttpResponseValidationStepsTests { - private static final TestLogger LOGGER = TestLoggerFactory.getTestLogger(HttpResponseValidationSteps.class); - private static final String ACCEPT_ENCODING_HEADER_NAME = "Accept-Encoding"; private static final Header ACCEPT_ENCODING_HEADER = new BasicHeader(ACCEPT_ENCODING_HEADER_NAME, "deflate, gzip;q=1.0, *;q=0.5"); @@ -81,10 +70,7 @@ class HttpResponseValidationStepsTests private static final String HEADER_IS_PRESENT = " header is present"; private static final String RESPONSE_BODY = "testResponse"; - private static final String HTTP_RESPONSE_BODY = "HTTP response body"; private static final String VARIABLE_NAME = "variableName"; - private static final String NUMBER_RESPONSE_HEADERS_WITH_NAME = - "The number of the response headers with the name '%s'"; private static final String NUMBER_OF_RESPONSE_HEADERS = "Number of the response headers with name '%s'"; private static final String HTTP_RESPONSE_IS_NOT_NULL = "HTTP response is not null"; private static final String TLS_V1_3 = "TLSv1.3"; @@ -118,43 +104,6 @@ class HttpResponseValidationStepsTests private final HttpResponse httpResponse = new HttpResponse(); - @Test - void testGetHeaderAttributes() - { - mockHttpResponse(); - httpResponse.setResponseHeaders(ACCEPT_ENCODING_HEADER); - when(softAssert.assertTrue(ACCEPT_ENCODING_HEADER_NAME + HEADER_IS_PRESENT, true)).thenReturn(true); - ExamplesTable attributes = new ExamplesTable("|attribute|\n|gzip|"); - httpResponseValidationSteps.assertHeaderContainsAttributes(ACCEPT_ENCODING_HEADER_NAME, attributes); - verify(softAssert).assertThat( - eq(String.format("%s header contains %s attribute", ACCEPT_ENCODING_HEADER_NAME, HEADER_ELEMENT_NAME)), - eq(HEADER_ELEMENT_NAMES), - argThat(matcher -> matcher.toString().equals(Matchers.contains(HEADER_ELEMENT_NAME).toString()))); - assertThat(LOGGER.getLoggingEvents(), - is(List.of(warn("The step \"Then response header '$httpHeaderName' contains attribute:$attributes\" " - + "is deprecated and will be removed in VIVIDUS 0.6.0. " - + "Please use step \"Then response header `$headerName` contains elements:$elements\"")))); - } - - @Test - void testGetHeaderAttributesHeaderNotFound() - { - mockHttpResponse(); - Header header = mock(Header.class); - when(header.getName()).thenReturn("Vary"); - httpResponse.setResponseHeaders(header); - ExamplesTable attribute = new ExamplesTable("|attribute|\n|any|"); - httpResponseValidationSteps.assertHeaderContainsAttributes(ACCEPT_ENCODING_HEADER_NAME, attribute); - verify(softAssert).assertTrue(ACCEPT_ENCODING_HEADER_NAME + HEADER_IS_PRESENT, false); - } - - @Test - void testGetHeaderAttributesNoHttpResponse() - { - httpResponseValidationSteps.assertHeaderContainsAttributes(ACCEPT_ENCODING_HEADER_NAME, ExamplesTable.empty()); - verifyNoHttpResponse(); - } - @Test void shouldCheckThatHeaderWithNameContainsElements() { @@ -188,24 +137,6 @@ void shouldNotCheckHeaderElementsIfHttpCallWasNotPerformed() verifyNoHttpResponse(); } - @Test - void testThenTheResponseTimeShouldBeLessThan() - { - mockHttpResponse(); - long responseTime = 1000L; - httpResponse.setResponseTimeInMs(responseTime); - httpResponseValidationSteps.thenTheResponseTimeShouldBeLessThan(responseTime); - verify(softAssert).assertThat(eq("The response time is less than response time threshold."), - eq(responseTime), argThat(matcher -> lessThan(responseTime).toString().equals(matcher.toString()))); - } - - @Test - void testThenTheResponseTimeShouldBeLessThanNoHttpResponse() - { - httpResponseValidationSteps.thenTheResponseTimeShouldBeLessThan(1000L); - verifyNoHttpResponse(); - } - @Test void shouldValidateResponseTime() { @@ -244,24 +175,6 @@ void testDecompressedResponseBodySizeEqualTo() argThat(m -> "a value equal to <10>".equals(m.toString()))); } - @Test - void testThenTheResponseCodeShouldBeEqualTo() - { - mockHttpResponse(); - int validCode = 200; - httpResponse.setStatusCode(validCode); - httpResponseValidationSteps.assertResponseCode(ComparisonRule.EQUAL_TO, validCode); - verify(softAssert).assertThat(eq(HTTP_RESPONSE_STATUS_CODE), eq(validCode), argThat( - matcher -> matcher.toString().equals(ComparisonRule.EQUAL_TO.getComparisonRule(validCode).toString()))); - } - - @Test - void testThenTheResponseCodeShouldBeEqualToNoHttpResponse() - { - httpResponseValidationSteps.assertResponseCode(ComparisonRule.EQUAL_TO, 200); - verifyNoHttpResponse(); - } - @Test void shouldValidateResponseCode() { @@ -280,46 +193,6 @@ void shouldNotValidateResponseCodeIfHttpCallWasNotPerformed() verifyNoHttpResponse(); } - @Test - void testDoesResponseBodyEqualToContent() - { - mockHttpResponse(); - String body = RESPONSE_BODY; - httpResponse.setResponseBody(body.getBytes(StandardCharsets.UTF_8)); - httpResponseValidationSteps.doesResponseBodyMatch(IS_EQUAL_TO, body); - verify(softAssert).assertThat(eq(HTTP_RESPONSE_BODY), eq(body), - argThat(arg -> "\"testResponse\"".equals(arg.toString()))); - assertThat(LOGGER.getLoggingEvents(), is(List.of(warn( - "The step: \"Then the response body $comparisonRule '$content'\" is deprecated and will be removed in" - + " VIVIDUS 0.6.0. Use ${response} dynamic variable with \"Then `$variable1` is $comparisonRule " - + "`$variable2`\" step")))); - } - - @Test - void testDoesResponseBodyEqualToContentNoHttpResponse() - { - httpResponseValidationSteps.doesResponseBodyMatch(IS_EQUAL_TO, StringUtils.EMPTY); - verifyNoHttpResponse(); - } - - @Test - void testDoesResponseBodyMatchResource() - { - mockHttpResponse(); - when(softAssert.assertEquals(ARRAY_SIZE, 6, 6)).thenReturn(true); - httpResponse.setResponseBody(new byte[] { 123, 98, 111, 100, 121, 125 }); - httpResponseValidationSteps.doesResponseBodyMatchResource(ByteArrayValidationRule.IS_EQUAL_TO, - RESPONSE_BODY_TXT); - verify(softAssert).recordPassedAssertion(EQUAL_ARRAYS); - } - - @Test - void testDoesResponseBodyMatchResourceNoHttpResponse() - { - httpResponseValidationSteps.doesResponseBodyMatchResource(ByteArrayValidationRule.IS_EQUAL_TO, "body.txt"); - verifyNoHttpResponse(); - } - @Test void shouldCompareResponseBodyAgainstResourceByPath() { @@ -375,24 +248,6 @@ private void testContentTypeOfResponseBody(String contentType) argThat(matcher -> matcher.toString().contains(contentType))); } - @Test - void testSaveHeaderValue() - { - mockHttpResponse(); - String headerValue = mockHeaderRetrieval(); - Set scopes = Set.of(VariableScope.SCENARIO); - httpResponseValidationSteps.saveHeaderValue(ACCEPT_ENCODING_HEADER_NAME, scopes, VARIABLE_NAME); - verify(variableContext).putVariable(scopes, VARIABLE_NAME, headerValue); - } - - @Test - void testSaveHeaderValueNoHttpResponse() - { - httpResponseValidationSteps.saveHeaderValue(ACCEPT_ENCODING_HEADER_NAME, Set.of(VariableScope.SCENARIO), - VARIABLE_NAME); - verifyNoHttpResponse(); - } - @Test void shouldSaveHeaderValueToVariable() { @@ -411,27 +266,6 @@ void shouldNotSaveHeaderValueToVariableIfHttpCallWasNotPerformed() verifyNoHttpResponse(); } - @Test - void testDoesHeaderEqualToValue() - { - mockHttpResponse(); - String headerValue = mockHeaderRetrieval(); - httpResponseValidationSteps.doesHeaderMatch(ACCEPT_ENCODING_HEADER_NAME, IS_EQUAL_TO, - headerValue); - verify(softAssert).assertThat( - eq(String.format(HEADER_VALUE, ACCEPT_ENCODING_HEADER_NAME)), - eq(headerValue), - argThat(matcher -> matcher.toString().equals(equalTo(headerValue).toString())) - ); - } - - @Test - void testDoesHeaderEqualToValueNoHttpResponse() - { - httpResponseValidationSteps.doesHeaderMatch(ACCEPT_ENCODING_HEADER_NAME, IS_EQUAL_TO, "value"); - verifyNoHttpResponse(); - } - @Test void shouldValidateHeaderValue() { @@ -453,17 +287,6 @@ void shouldNotValidateHeaderValueIfHttpCallWasNotPerfor() verifyNoHttpResponse(); } - @Test - void testSaveHeaderValueHeaderNotFound() - { - mockHttpResponse(); - httpResponse.setResponseHeaders(); - httpResponseValidationSteps.saveHeaderValue(ACCEPT_ENCODING_HEADER_NAME, Set.of(VariableScope.SCENARIO), - VARIABLE_NAME); - verify(softAssert).assertTrue(ACCEPT_ENCODING_HEADER_NAME + HEADER_IS_PRESENT, false); - verifyNoInteractions(variableContext); - } - @Test void shouldNotSaveHeaderValueIfHeaderByNameIsNotFound() { @@ -475,15 +298,6 @@ void shouldNotSaveHeaderValueIfHeaderByNameIsNotFound() verifyNoInteractions(variableContext); } - @Test - void testDoesResponseNotContainBody() - { - mockHttpResponse(); - httpResponse.setResponseBody(null); - httpResponseValidationSteps.doesResponseNotContainBody(); - verify(softAssert).assertNull(RESPONSE_WITH_NO_BODY, null); - } - @Test void shouldCheckThatTheResponseDoesNotContainABody() { @@ -493,13 +307,6 @@ void shouldCheckThatTheResponseDoesNotContainABody() verify(softAssert).assertNull(RESPONSE_WITH_NO_BODY, null); } - @Test - void testDoesResponseNotContainBodyNoHttpResponse() - { - httpResponseValidationSteps.doesResponseNotContainBody(); - verifyNoHttpResponse(); - } - @Test void shouldNotCheckResponseIfHttpCallWasNotPerformed() { @@ -507,37 +314,6 @@ void shouldNotCheckResponseIfHttpCallWasNotPerformed() verifyNoHttpResponse(); } - @Test - void testResponseNotContainsHeadersWithName() - { - mockHttpResponse(); - httpResponse.setResponseHeaders(); - httpResponseValidationSteps.isHeaderWithNameFound(ACCEPT_ENCODING_HEADER_NAME, ComparisonRule.EQUAL_TO, 1); - verify(softAssert).assertThat(eq(String.format(NUMBER_RESPONSE_HEADERS_WITH_NAME, ACCEPT_ENCODING_HEADER_NAME)), - eq(0), - argThat(m -> ComparisonRule.EQUAL_TO.getComparisonRule(1).toString().equals(m.toString()))); - } - - @Test - void testResponseContainsHeadersWithName() - { - mockHttpResponse(); - Header header = mock(Header.class); - when(header.getName()).thenReturn(ACCEPT_ENCODING_HEADER_NAME); - httpResponse.setResponseHeaders(header, header); - httpResponseValidationSteps.isHeaderWithNameFound(ACCEPT_ENCODING_HEADER_NAME, ComparisonRule.EQUAL_TO, 2); - verify(softAssert).assertThat(eq(String.format(NUMBER_RESPONSE_HEADERS_WITH_NAME, ACCEPT_ENCODING_HEADER_NAME)), - eq(2), - argThat(m -> ComparisonRule.EQUAL_TO.getComparisonRule(2).toString().equals(m.toString()))); - } - - @Test - void testResponseContainsHeadersWithNameNoHttpResponse() - { - httpResponseValidationSteps.isHeaderWithNameFound(ACCEPT_ENCODING_HEADER_NAME, ComparisonRule.EQUAL_TO, 1); - verifyNoHttpResponse(); - } - @Test void shouldFailIfResponseDoesntContainDesiredNumberOfHeaders() { @@ -570,20 +346,6 @@ void shouldNotValidateNumberOfHeadersInResponseIfHttpCallWasNotPerformed() verifyNoHttpResponse(); } - @Test - void shouldValidateSecuredConnectionDeprecated() - { - boolean secure = true; - ConnectionDetails connectionDetails = new ConnectionDetails(); - connectionDetails.setSecure(secure); - connectionDetails.setSecurityProtocol(TLS_V1_3); - - when(httpTestContext.getConnectionDetails()).thenReturn(connectionDetails); - when(softAssert.assertTrue(CONNECTION_SECURE_ASSERTION, secure)).thenReturn(Boolean.TRUE); - httpResponseValidationSteps.isConnectionSecured(TLS_V1_3); - verify(softAssert).assertEquals(SECURITY_PROTOCOL, TLS_V1_3, TLS_V1_3); - } - @Test void shouldValidateNonSecuredConnectionDeprecated() { diff --git a/vividus-tests/src/main/resources/story/integration/ExcelSteps.story b/vividus-tests/src/main/resources/story/integration/ExcelSteps.story index 5b1e00b302..d855c5f899 100644 --- a/vividus-tests/src/main/resources/story/integration/ExcelSteps.story +++ b/vividus-tests/src/main/resources/story/integration/ExcelSteps.story @@ -5,7 +5,7 @@ Lifecycle: Before: Scope: STORY When I execute HTTP GET request for resource with URL `https://github.com/vividus-framework/vividus/blob/master/vividus-plugin-excel/src/test/resources/TestTemplate.xlsx?raw=true` -Then the response code is = '200' +Then response code is = `200` Scenario: Step verification 'Then `$excelDocument` contains excel sheet with index `$index` and records:$records' Then `${response-as-bytes}` contains excel sheet with index `0` and records: diff --git a/vividus-tests/src/main/resources/story/integration/HTTP.story b/vividus-tests/src/main/resources/story/integration/HTTP.story index f7ac20b80b..462ff08971 100644 --- a/vividus-tests/src/main/resources/story/integration/HTTP.story +++ b/vividus-tests/src/main/resources/story/integration/HTTP.story @@ -9,7 +9,7 @@ Then `${response-code}` is equal to `405` Scenario: Verify handling of plus character in URL query When I execute HTTP GET request for resource with relative URL `/get?birthDate=` -Then the response code is equal to '200' +Then response code is equal to `200` Then JSON element by JSON path `$.url` is equal to `${http-endpoint}get?birthDate=00:00:00%2B02:00` Then JSON element by JSON path `$.args.birthDate` is equal to `00:00:00+02:00` Examples: @@ -19,12 +19,12 @@ Examples: Scenario: Verify handling of ampersand character in URL path When I execute HTTP GET request for resource with relative URL `/anything/path-with-&-ampersand` -Then the response code is equal to '200' +Then response code is equal to `200` Then JSON element by JSON path `$.url` is equal to `${http-endpoint}anything/path-with-&-ampersand` Scenario: Verify handling of ampersand and space characters in URI query parameter When I execute HTTP GET request for resource with relative URL `/get?key=#{encodeUriQueryParameter(a & b)}` -Then the response code is equal to '200' +Then response code is equal to `200` Then JSON element by JSON path `$.url` is equal to `${http-endpoint}get?key=a%20%26%20b` Then JSON element by JSON path `$.args.length()` is equal to `1` Then JSON element by JSON path `$.args.key` is equal to `a & b` @@ -34,7 +34,7 @@ Given I initialize scenario variable `url` with value `https://user@vividus.dev: Given I initialize scenario variable `encodedUrl` with value `#{encodeUri(${url})}` Then `${encodedUrl}` is equal to `https%3A%2F%2Fuser%40vividus.dev%3Avividus.dev%2Fpath%2Fsegment%3Fa%26b%3Dc%23fragment` When I execute HTTP GET request for resource with relative URL `/get?key=https:%2F%2Fuser%40vividus.dev:vividus.dev%2Fpath%2Fsegment%3Fa%26b=c%23fragment` -Then the response code is equal to '200' +Then response code is equal to `200` Then JSON element by JSON path `$.url` is equal to `${http-endpoint}get?key=https://user@vividus.dev:vividus.dev/path/segment?a%26b=c%23fragment` Then JSON element by JSON path `$.args.length()` is equal to `1` Then JSON element by JSON path `$.args.key` is equal to `${url}` diff --git a/vividus-tests/src/main/resources/story/integration/HttpResponseValidationStepsTests.story b/vividus-tests/src/main/resources/story/integration/HttpResponseValidationStepsTests.story index ccb0461943..7ab9ef7256 100644 --- a/vividus-tests/src/main/resources/story/integration/HttpResponseValidationStepsTests.story +++ b/vividus-tests/src/main/resources/story/integration/HttpResponseValidationStepsTests.story @@ -4,21 +4,11 @@ Meta: Scenario: Verify step: "Then response does not contain body" When I execute HTTP GET request for resource with URL `${vividus-test-site-url}/api/no-content` Then response does not contain body -!-- Deprecated -Then the response does not contain body -Scenario: Verify deprecated steps: "Then the response body $comparisonRule '$content'" & "When I save response body to the $scopes variable '$variableName'" -When I execute HTTP GET request for resource with relative URL `/xml` -Then the response body contains 'Date of publication' -When I save response body to the scenario variable 'my-super-response' -Then `${my-super-response}` matches `.*Date of publication.*` - Scenario: Verify step: "Then response code is $comparisonRule `$responseCode`" When I execute HTTP GET request for resource with relative URL `/status/` Then response code is equal to `` -!-- Deprecated -Then the response code is equal to '' Examples: |statusCode| |200 | @@ -30,17 +20,12 @@ When I execute HTTP GET request for resource with relative URL `/image/png` Then size of decompressed response body is equal to `8090` Then response body is equal to resource at `/data/pig` Then content type of response body is equal to `image/png` -!-- Deprecated -Then the response body is equal to resource at '/data/pig' Scenario: Verify steps: "Then connection is secured using $securityProtocol protocol", "Then response time is $comparisonRule `$responseTime` milliseconds" When I execute HTTP GET request for resource with URL `${vividus-test-site-url}/index.html` Then connection is secured using TLSv1.3 protocol Then response time is less than `5000` milliseconds -!-- Deprecated -Then the connection is secured using TLSv1.3 protocol -Then the response time should be less than '5000' milliseconds Scenario: Verify step: "When I wait for response code `$responseCode` for `$duration` duration retrying $retryTimes times$stepsToExecute" @@ -52,7 +37,7 @@ When I wait for response code `200` for `PT2M` duration retrying 3 times Then `${responseCode}` is equal to `200` -Scenario: Verify steps: "Then number of response headers with name `$headerName` is $comparisonRule $number", "When I save response header `$headerName` value to $scopes variable `$variableName`", "Then value of response header `$headerName` $comparisonRule `$value`", "Then response header `$headerName` contains elements:$elements"; verify deprecated HTTP header steps: "Then the number of the response headers with the name '$headerName' is $comparisonRule $value", "When I save response header '$httpHeaderName' value to $scopes variable '$variableName'", "Then the value of the response header '$httpHeaderName' $comparisonRule '$value'", "Then the value of the response header "$httpHeaderName" $comparisonRule "$value"", "Then response header '$httpHeaderName' contains attribute: $attributes" +Scenario: Verify steps: "Then number of response headers with name `$headerName` is $comparisonRule $number", "When I save response header `$headerName` value to $scopes variable `$variableName`", "Then value of response header `$headerName` $comparisonRule `$value`", "Then response header `$headerName` contains elements:$elements" When I execute HTTP GET request for resource with relative URL `/html` Then number of response headers with name `content-type` is equal to 1 When I save response header `content-type` value to scenario variable `contentType` @@ -61,12 +46,3 @@ Then value of response header `content-type` is equal to `text/html; charset=utf Then response header `content-type` contains elements: |element | |text/html| -!-- Deprecated -Then the number of the response headers with the name 'content-type' is equal to 1 -When I save response header 'content-type' value to scenario variable 'contentType' -Then `${contentType}` is equal to `text/html; charset=utf-8` -Then the value of the response header 'content-type' is equal to 'text/html; charset=utf-8' -Then the value of the response header "content-type" is equal to "text/html; charset=utf-8" -Then response header 'content-type' contains attribute: -|attribute| -|text/html| diff --git a/vividus-tests/src/main/resources/story/integration/RestApiStepsTests.story b/vividus-tests/src/main/resources/story/integration/RestApiStepsTests.story index 8557554795..4ba6722c6d 100644 --- a/vividus-tests/src/main/resources/story/integration/RestApiStepsTests.story +++ b/vividus-tests/src/main/resources/story/integration/RestApiStepsTests.story @@ -17,7 +17,7 @@ When I set request headers: |Content-Type|application/json| After: Scope: SCENARIO -Then the response code is equal to '200' +Then response code is equal to `200` Then JSON element by JSON path `$.json` is equal to `${request-body}` Then JSON element by JSON path `$.headers.Content-Type` is equal to `"application/json"` @@ -25,10 +25,6 @@ Scenario: Verify steps "Given request body: $content" and "When I execute HTTP $ Given request body: ${request-body} When I execute HTTP PUT request for resource with relative URL `/put` -Scenario: Verify deprecated step "When I send HTTP $httpMethod to the relative URL '$relativeURL'" -Given request body: ${request-body} -When I send HTTP PUT to the relative URL '/put' - Scenario: Verify steps "Given request body: $content" and "When I execute HTTP $httpMethod request for resource with URL `$url`" Given request body: ${request-body} When I execute HTTP DELETE request for resource with URL `${http-endpoint}delete`