cucumber parallel features

This commit is contained in:
DOHA 2018-10-10 20:39:45 +03:00
parent 22c9996047
commit ee1e3eea89
3 changed files with 72 additions and 19 deletions

View File

@ -106,6 +106,46 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<parallel>classes</parallel>
<threadCount>4</threadCount>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>generate-test-sources</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<glue>
<package>com.baeldung.rest.cucumber</package>
</glue>
<featuresDirectory>src/test/resources/Feature/</featuresDirectory>
<parallelScheme>SCENARIO</parallelScheme>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@ -1,19 +1,5 @@
package com.baeldung.rest.cucumber;
import com.github.tomakehurst.wiremock.WireMockServer;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
@ -25,10 +11,27 @@ import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import com.github.tomakehurst.wiremock.WireMockServer;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
public class StepDefinition {
private static final String CREATE_PATH = "/create";
@ -37,20 +40,20 @@ public class StepDefinition {
private final InputStream jsonInputStream = this.getClass().getClassLoader().getResourceAsStream("cucumber.json");
private final String jsonString = new Scanner(jsonInputStream, "UTF-8").useDelimiter("\\Z").next();
private final WireMockServer wireMockServer = new WireMockServer();
private final WireMockServer wireMockServer = new WireMockServer(options().dynamicPort());
private final CloseableHttpClient httpClient = HttpClients.createDefault();
@When("^users upload data on a project$")
public void usersUploadDataOnAProject() throws IOException {
wireMockServer.start();
configureFor("localhost", 8080);
configureFor("localhost", wireMockServer.port());
stubFor(post(urlEqualTo(CREATE_PATH))
.withHeader("content-type", equalTo(APPLICATION_JSON))
.withRequestBody(containing("testing-framework"))
.willReturn(aResponse().withStatus(200)));
HttpPost request = new HttpPost("http://localhost:8080/create");
HttpPost request = new HttpPost("http://localhost:" + wireMockServer.port() + "/create");
StringEntity entity = new StringEntity(jsonString);
request.addHeader("content-type", APPLICATION_JSON);
request.setEntity(entity);
@ -67,11 +70,11 @@ public class StepDefinition {
public void usersGetInformationOnAProject(String projectName) throws IOException {
wireMockServer.start();
configureFor("localhost", 8080);
configureFor("localhost", wireMockServer.port());
stubFor(get(urlEqualTo("/projects/cucumber")).withHeader("accept", equalTo(APPLICATION_JSON))
.willReturn(aResponse().withBody(jsonString)));
HttpGet request = new HttpGet("http://localhost:8080/projects/" + projectName.toLowerCase());
HttpGet request = new HttpGet("http://localhost:" + wireMockServer.port() + "/projects/" + projectName.toLowerCase());
request.addHeader("accept", APPLICATION_JSON);
HttpResponse httpResponse = httpClient.execute(request);
String responseString = convertResponseToString(httpResponse);

View File

@ -0,0 +1,10 @@
Feature: Testing a REST API
Users should be able to submit GET and POST requests to a web service, represented by WireMock
Scenario: Data Upload to a web service
When users upload data on a project
Then the server should handle it and return a success status
Scenario: Data retrieval from a web service
When users want to get information on the Cucumber project
Then the requested data is returned