Skip to content

Commit

Permalink
Fix gherkin description and send mockserver query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
osvaldjr committed Jul 25, 2019
1 parent 7cf6b86 commit 16feb48
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 13 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<groupId>io.github.osvaldjr</groupId>
<artifactId>easy-cucumber</artifactId>
<packaging>jar</packaging>
<version>0.0.7</version>
<version>0.0.8</version>
<name>io.github.osvaldjr:easy-cucumber</name>
<description>Easy Cucumber JVM Testing</description>

Expand Down Expand Up @@ -208,6 +208,7 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Parameter> getQueryParameters(Map<String, String> queryParams) {
List<Parameter> parameters = new ArrayList<>();
queryParams.forEach((key, value) -> parameters.add(new Parameter(key, value)));
return parameters;
}

private List<Header> getHeaders(Map<String, String> headersMap) {
List<Header> headers = new ArrayList<>();
headersMap.forEach((key, value) -> headers.add(new Header(key, value)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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()));
Expand All @@ -64,4 +67,13 @@ private void assertHeaders(Map<String, String> headersMap, Headers headers) {
assertThat(headers.getFirstValue(k), equalTo(v));
});
}

private void assertQueryParams(Map<String, String> parametersMap, Parameters parameters) {

parametersMap.forEach(
(k, v) -> {
assertTrue(parameters.containsEntry(k));
assertThat(parameters.getFirstValue(k), equalTo(v));
});
}
}
4 changes: 2 additions & 2 deletions src/test/resources/features/hooks/cleanStubby.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/test/resources/features/hooks/disableFeatures.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/test/resources/features/hooks/enableFeatures.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions src/test/resources/features/integration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 16feb48

Please sign in to comment.