cucumber parallel features
This commit is contained in:
parent
22c9996047
commit
ee1e3eea89
@ -107,6 +107,46 @@
|
|||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</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>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -1,19 +1,5 @@
|
|||||||
package com.baeldung.rest.cucumber;
|
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.aResponse;
|
||||||
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
|
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
|
||||||
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
|
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.stubFor;
|
||||||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
|
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
|
||||||
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
|
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.hamcrest.CoreMatchers.containsString;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
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 {
|
public class StepDefinition {
|
||||||
|
|
||||||
private static final String CREATE_PATH = "/create";
|
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 InputStream jsonInputStream = this.getClass().getClassLoader().getResourceAsStream("cucumber.json");
|
||||||
private final String jsonString = new Scanner(jsonInputStream, "UTF-8").useDelimiter("\\Z").next();
|
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();
|
private final CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||||
|
|
||||||
@When("^users upload data on a project$")
|
@When("^users upload data on a project$")
|
||||||
public void usersUploadDataOnAProject() throws IOException {
|
public void usersUploadDataOnAProject() throws IOException {
|
||||||
wireMockServer.start();
|
wireMockServer.start();
|
||||||
|
|
||||||
configureFor("localhost", 8080);
|
configureFor("localhost", wireMockServer.port());
|
||||||
stubFor(post(urlEqualTo(CREATE_PATH))
|
stubFor(post(urlEqualTo(CREATE_PATH))
|
||||||
.withHeader("content-type", equalTo(APPLICATION_JSON))
|
.withHeader("content-type", equalTo(APPLICATION_JSON))
|
||||||
.withRequestBody(containing("testing-framework"))
|
.withRequestBody(containing("testing-framework"))
|
||||||
.willReturn(aResponse().withStatus(200)));
|
.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);
|
StringEntity entity = new StringEntity(jsonString);
|
||||||
request.addHeader("content-type", APPLICATION_JSON);
|
request.addHeader("content-type", APPLICATION_JSON);
|
||||||
request.setEntity(entity);
|
request.setEntity(entity);
|
||||||
@ -67,11 +70,11 @@ public class StepDefinition {
|
|||||||
public void usersGetInformationOnAProject(String projectName) throws IOException {
|
public void usersGetInformationOnAProject(String projectName) throws IOException {
|
||||||
wireMockServer.start();
|
wireMockServer.start();
|
||||||
|
|
||||||
configureFor("localhost", 8080);
|
configureFor("localhost", wireMockServer.port());
|
||||||
stubFor(get(urlEqualTo("/projects/cucumber")).withHeader("accept", equalTo(APPLICATION_JSON))
|
stubFor(get(urlEqualTo("/projects/cucumber")).withHeader("accept", equalTo(APPLICATION_JSON))
|
||||||
.willReturn(aResponse().withBody(jsonString)));
|
.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);
|
request.addHeader("accept", APPLICATION_JSON);
|
||||||
HttpResponse httpResponse = httpClient.execute(request);
|
HttpResponse httpResponse = httpClient.execute(request);
|
||||||
String responseString = convertResponseToString(httpResponse);
|
String responseString = convertResponseToString(httpResponse);
|
||||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user