From 16feb48982a65654d808c50ce9d22573ea420d4d Mon Sep 17 00:00:00 2001 From: osvaldjr Date: Thu, 25 Jul 2019 09:07:46 -0300 Subject: [PATCH] Fix gherkin description and send mockserver query parameter --- pom.xml | 3 ++- .../assemblers/ExpectationRequestAssembler.java | 8 ++++++++ .../osvaldjr/stepdefinitions/steps/DefaultSteps.java | 2 +- .../assemblers/ExpectationRequestAssemblerTest.java | 12 ++++++++++++ .../resources/features/hooks/cleanStubby.feature | 4 ++-- .../resources/features/hooks/disableFeatures.feature | 4 ++-- .../resources/features/hooks/enableFeatures.feature | 4 ++-- src/test/resources/features/integration.feature | 10 +++++----- 8 files changed, 34 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index df1b1d9..da9aa10 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ io.github.osvaldjr easy-cucumber jar - 0.0.7 + 0.0.8 io.github.osvaldjr:easy-cucumber Easy Cucumber JVM Testing @@ -208,6 +208,7 @@ org.postgresql postgresql ${postgresql.version} + test org.springframework.boot diff --git a/src/main/java/io/github/osvaldjr/gateways/mock/mockserver/assemblers/ExpectationRequestAssembler.java b/src/main/java/io/github/osvaldjr/gateways/mock/mockserver/assemblers/ExpectationRequestAssembler.java index 87b6255..a19a995 100644 --- a/src/main/java/io/github/osvaldjr/gateways/mock/mockserver/assemblers/ExpectationRequestAssembler.java +++ b/src/main/java/io/github/osvaldjr/gateways/mock/mockserver/assemblers/ExpectationRequestAssembler.java @@ -11,6 +11,7 @@ import org.mockserver.model.Header; import org.mockserver.model.HttpRequest; import org.mockserver.model.HttpResponse; +import org.mockserver.model.Parameter; import org.springframework.stereotype.Component; import gherkin.deps.com.google.gson.Gson; @@ -40,10 +41,17 @@ private HttpRequest getHttpRequest(StubbyRequest.RequestBody request) { .withMethod(request.getMethod()) .withPath("/" + request.getUrl()) .withHeaders(getHeaders(request.getHeaders())) + .withQueryStringParameters(getQueryParameters(request.getQueryParams())) .withBody(gson.toJson(request.getBody())); return httpRequest; } + private List getQueryParameters(Map queryParams) { + List parameters = new ArrayList<>(); + queryParams.forEach((key, value) -> parameters.add(new Parameter(key, value))); + return parameters; + } + private List
getHeaders(Map headersMap) { List
headers = new ArrayList<>(); headersMap.forEach((key, value) -> headers.add(new Header(key, value))); diff --git a/src/main/java/io/github/osvaldjr/stepdefinitions/steps/DefaultSteps.java b/src/main/java/io/github/osvaldjr/stepdefinitions/steps/DefaultSteps.java index d27c114..12ae695 100644 --- a/src/main/java/io/github/osvaldjr/stepdefinitions/steps/DefaultSteps.java +++ b/src/main/java/io/github/osvaldjr/stepdefinitions/steps/DefaultSteps.java @@ -92,7 +92,7 @@ public void iExpectAsResponse(String responsePayload) throws IOException, JSONEx JSONAssert.assertEquals(responseExpected, responseReceived, true); } - @Then("A have a mock ([^\"]*) for dependency ([^\"]*)") + @Then("I have a mock ([^\"]*) for dependency ([^\"]*)") public void aHaveAMockForDependency(String mockName, String serviceName) throws IOException { Object stubbyId = createStubbyUsecase.execute(scenarioName, serviceName, mockName); stubbyIdMap.put(getStubbyKey(scenarioName, serviceName, mockName), stubbyId); diff --git a/src/test/java/io/github/osvaldjr/unit/gateways/mock/mockserver/assemblers/ExpectationRequestAssemblerTest.java b/src/test/java/io/github/osvaldjr/unit/gateways/mock/mockserver/assemblers/ExpectationRequestAssemblerTest.java index a73724b..3e8c352 100644 --- a/src/test/java/io/github/osvaldjr/unit/gateways/mock/mockserver/assemblers/ExpectationRequestAssemblerTest.java +++ b/src/test/java/io/github/osvaldjr/unit/gateways/mock/mockserver/assemblers/ExpectationRequestAssemblerTest.java @@ -14,6 +14,7 @@ import org.mockserver.model.Headers; import org.mockserver.model.HttpRequest; import org.mockserver.model.HttpResponse; +import org.mockserver.model.Parameters; import gherkin.deps.com.google.gson.Gson; import io.github.glytching.junit.extension.random.Random; @@ -35,6 +36,7 @@ void shouldAssembleCorrectly( map.put("key", "value"); requestBody.setBody(map); requestBody.setHeaders(map); + requestBody.setQueryParams(map); Expectation expectation = expectationRequestAssembler.assemble(requestBody, responseBody, maxHits); @@ -44,6 +46,7 @@ void shouldAssembleCorrectly( assertThat(request, notNullValue()); assertHeaders(requestBody.getHeaders(), request.getHeaders()); + assertQueryParams(requestBody.getQueryParams(), request.getQueryStringParameters()); assertThat(request.getMethod(), equalTo(requestBody.getMethod())); assertThat(request.getBodyAsString(), equalTo(gson.toJson(requestBody.getBody()))); assertThat(request.getPath(), equalTo("/" + requestBody.getUrl())); @@ -64,4 +67,13 @@ private void assertHeaders(Map headersMap, Headers headers) { assertThat(headers.getFirstValue(k), equalTo(v)); }); } + + private void assertQueryParams(Map parametersMap, Parameters parameters) { + + parametersMap.forEach( + (k, v) -> { + assertTrue(parameters.containsEntry(k)); + assertThat(parameters.getFirstValue(k), equalTo(v)); + }); + } } diff --git a/src/test/resources/features/hooks/cleanStubby.feature b/src/test/resources/features/hooks/cleanStubby.feature index 43f06d4..a1c8d5a 100644 --- a/src/test/resources/features/hooks/cleanStubby.feature +++ b/src/test/resources/features/hooks/cleanStubby.feature @@ -3,11 +3,11 @@ Feature: CleanStubby This feature is to test hook CleanStubby Scenario: Create mock error and validate - Given A have a mock error for dependency integration + Given I have a mock error for dependency integration When I make a GET to /test Then I expect to receive a 500 status Scenario: Create mock successful and validate - Given A have a mock successful for dependency integration + Given I have a mock successful for dependency integration When I make a GET to /test Then I expect to receive a 200 status diff --git a/src/test/resources/features/hooks/disableFeatures.feature b/src/test/resources/features/hooks/disableFeatures.feature index bf9cd1b..58ee5e4 100644 --- a/src/test/resources/features/hooks/disableFeatures.feature +++ b/src/test/resources/features/hooks/disableFeatures.feature @@ -4,13 +4,13 @@ Feature: DisableFeatures Scenario: Enable feature toggle Given the feature delete-integration is ENABLE - And A have a mock successful for dependency integration + And I have a mock successful for dependency integration And I have a request with body body_request.json When I make a DELETE to /test Then I expect to receive a 200 status Scenario: Validate if feature toggle is disable - Given A have a mock successful for dependency integration + Given I have a mock successful for dependency integration And I have a request with body body_request.json When I make a DELETE to /test Then I expect to receive a 400 status diff --git a/src/test/resources/features/hooks/enableFeatures.feature b/src/test/resources/features/hooks/enableFeatures.feature index 3329e87..76b29f1 100644 --- a/src/test/resources/features/hooks/enableFeatures.feature +++ b/src/test/resources/features/hooks/enableFeatures.feature @@ -4,13 +4,13 @@ Feature: EnableFeatures Scenario: Disable feature toggle Given the feature delete-integration is DISABLE - And A have a mock successful for dependency integration + And I have a mock successful for dependency integration And I have a request with body body_request.json When I make a DELETE to /test Then I expect to receive a 400 status Scenario: Validate if feature toggle is enable - Given A have a mock successful for dependency integration + Given I have a mock successful for dependency integration And I have a request with body body_request.json When I make a DELETE to /test Then I expect to receive a 200 status \ No newline at end of file diff --git a/src/test/resources/features/integration.feature b/src/test/resources/features/integration.feature index 5d3c6c5..462941e 100644 --- a/src/test/resources/features/integration.feature +++ b/src/test/resources/features/integration.feature @@ -4,7 +4,7 @@ Feature: Integration Scenario: Validate the steps for feature toggle Given the feature delete-integration is ENABLE - And A have a mock http_delete_successful for dependency integration + And I have a mock http_delete_successful for dependency integration And I have a request with body http_delete_body_request.json When I make a DELETE to /test Then I expect to receive a 200 status @@ -26,20 +26,20 @@ Feature: Integration Then I expect to receive a 400 status Scenario: Validate a default steps without request - Given A have a mock http_get_successful for dependency integration + Given I have a mock http_get_successful for dependency integration When I make a GET to /test Then I expect to receive a 200 status And I expect mock http_get_successful for dependency integration to have been called 1 times And I expect http_get_body_response.json as response Scenario: Validate a default steps with request body - Given A have a mock http_post_successful for dependency integration + Given I have a mock http_post_successful for dependency integration And I have a request with body http_post_body_request.json When I make a POST to /test Then I expect to receive a 200 status with body http_post_body_response.json Scenario: Validate a default steps with request defined - Given A have a mock http_post_successful for dependency integration + Given I have a mock http_post_successful for dependency integration When I make a request defined in http_post_defined_body_request.json Then I expect to receive a 200 status @@ -48,7 +48,7 @@ Feature: Integration Then I expect to receive a 500 status with body http_get_body_error_response.json Scenario: Validate external target host configuration - Given A have a mock http_post_successful_complete_payload for dependency integration + Given I have a mock http_post_successful_complete_payload for dependency integration And my application host is http://localhost:9003 Then I make a GET to / Then I expect to receive a 200 status with body http_get_body_complete_response.json