Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions modules/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</parent>

<artifactId>testserver-cucumber-core</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
Expand Down Expand Up @@ -45,8 +44,8 @@

<dependency>
<groupId>com.smartbear.readyapi</groupId>
<artifactId>ready-api-testserver-client</artifactId>
<version>1.2.2-SNAPSHOT</version>
<artifactId>readyapi4j-testserver-client</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.smartbear.readyapi.testserver.cucumber;

import com.google.common.collect.Lists;
import com.smartbear.readyapi.client.execution.Execution;
import com.smartbear.readyapi.client.model.ProjectResultReport;
import com.smartbear.readyapi.client.model.TestCase;
import com.smartbear.readyapi.client.model.TestStep;
import com.smartbear.readyapi4j.execution.Execution;
import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.runtime.java.guice.ScenarioScoped;
Expand Down Expand Up @@ -49,9 +49,9 @@ public void run(Scenario scenario) {
testCase.setTestSteps(testSteps);
Execution execution = executor.runTestCase(testCase, scenario);

if( assertResult && !executor.isAsync() ) {
if (assertResult && !executor.isAsync()) {
assertEquals(Arrays.toString(execution.getErrorMessages().toArray()),
ProjectResultReport.StatusEnum.FINISHED, execution.getCurrentStatus());
ProjectResultReport.StatusEnum.FINISHED, execution.getCurrentStatus());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.smartbear.readyapi.testserver.cucumber;

import com.smartbear.readyapi.client.ExecutionListener;
import com.smartbear.readyapi.client.TestRecipe;
import com.smartbear.readyapi.client.execution.Execution;
import com.smartbear.readyapi.client.execution.RecipeExecutor;
import com.smartbear.readyapi.client.execution.TestServerClient;
import com.smartbear.readyapi.client.model.TestCase;
import com.smartbear.readyapi4j.ExecutionListener;
import com.smartbear.readyapi4j.TestRecipe;
import com.smartbear.readyapi4j.execution.Execution;
import com.smartbear.readyapi4j.execution.RecipeExecutor;
import com.smartbear.readyapi4j.testserver.execution.TestServerClient;
import cucumber.api.Scenario;
import io.swagger.util.Json;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -40,15 +40,15 @@ public class CucumberRecipeExecutor {
public CucumberRecipeExecutor() throws MalformedURLException {
Map<String, String> env = System.getenv();
URL url = new URL(env.getOrDefault(TESTSERVER_ENDPOINT,
System.getProperty(TESTSERVER_ENDPOINT, DEFAULT_TESTSERVER_ENDPOINT)));
System.getProperty(TESTSERVER_ENDPOINT, DEFAULT_TESTSERVER_ENDPOINT)));

TestServerClient testServerClient = TestServerClient.fromUrl( url.toString() );
TestServerClient testServerClient = TestServerClient.fromUrl(url.toString());

String user = env.getOrDefault(TESTSERVER_USER,
System.getProperty(TESTSERVER_USER, DEFAULT_TESTSERVER_USER));
System.getProperty(TESTSERVER_USER, DEFAULT_TESTSERVER_USER));

String password = env.getOrDefault(TESTSERVER_PASSWORD,
System.getProperty(TESTSERVER_PASSWORD, DEFAULT_TESTSERVER_PASSWORD));
System.getProperty(TESTSERVER_PASSWORD, DEFAULT_TESTSERVER_PASSWORD));

testServerClient.setCredentials(user, password);
executor = testServerClient.createRecipeExecutor();
Expand All @@ -58,15 +58,15 @@ public CucumberRecipeExecutor() throws MalformedURLException {
* Executes the specified TestCase and returns the Execution. If a scenario
* is specified and the testserver.cucumber.logfolder system property is set,
* the generated recipe will be written to the specified folder.
*
* <p>
* It is possible to temporarily "bypass" recipe execution by specifying
* a testserver.cucumber.silent property - in which case testcases will not be
* submitted to the server, but still logged to the above folder.
*
* @param testCase the TestCase to execute
* @param scenario the Cucumber scenario used to generate the specified Recipe
* @return the TestServer Execution for the executed TestCase
* @throws com.smartbear.readyapi.client.execution.ApiException if recipe execution failes
* @throws com.smartbear.readyapi4j.testserver.execution.ApiException if recipe execution failes
*/

public Execution runTestCase(TestCase testCase, Scenario scenario) {
Expand All @@ -77,35 +77,35 @@ public Execution runTestCase(TestCase testCase, Scenario scenario) {
LOG.debug(testRecipe.toString());
}

String logFolder = System.getProperty( "testserver.cucumber.logfolder", null );
if( scenario != null && logFolder != null ){
String logFolder = System.getProperty("testserver.cucumber.logfolder", null);
if (scenario != null && logFolder != null) {
logScenarioToFile(testRecipe, scenario, logFolder);
}

return async ? executor.submitRecipe( testRecipe ) : executor.executeRecipe(testRecipe);
return async ? executor.submitRecipe(testRecipe) : executor.executeRecipe(testRecipe);
}

/**
* Writes the specified testRecipe to a folder/file name deducted from the
* specified scenario
*
* @param testRecipe the test recipe to log
* @param scenario the associated Cucumber scenario
* @param logFolder the root folder for generated folders and files
* @param scenario the associated Cucumber scenario
* @param logFolder the root folder for generated folders and files
*/

protected void logScenarioToFile(TestRecipe testRecipe, Scenario scenario, String logFolder) {
try {
File folder = new File( logFolder );
if( !folder.exists() || !folder.isDirectory()){
File folder = new File(logFolder);
if (!folder.exists() || !folder.isDirectory()) {
folder.mkdirs();
}

String[] pathSegments = scenario.getId().split(";");
File scenarioFolder = folder;
int fileIndex = 0;

if( pathSegments.length > 1 ) {
if (pathSegments.length > 1) {
scenarioFolder = new File(folder, pathSegments[0]);
if (scenarioFolder.exists() || !scenarioFolder.isDirectory()) {
scenarioFolder.mkdirs();
Expand All @@ -115,25 +115,25 @@ protected void logScenarioToFile(TestRecipe testRecipe, Scenario scenario, Strin
}

String filename = pathSegments[fileIndex];
for( int c = fileIndex+1; c < pathSegments.length; c++ ){
for (int c = fileIndex + 1; c < pathSegments.length; c++) {
String segment = pathSegments[c].trim();
if( !StringUtils.isBlank( segment )){
if (!StringUtils.isBlank(segment)) {
filename += "_" + segment;
}
}

filename += ".json";

File scenarioFile = new File( scenarioFolder, filename );
FileWriter writer = new FileWriter( scenarioFile );
File scenarioFile = new File(scenarioFolder, filename);
FileWriter writer = new FileWriter(scenarioFile);

LOG.info("Writing recipe to " + folder.getName() + File.separatorChar + scenarioFolder.getName() +
File.separatorChar + scenarioFile.getName());
File.separatorChar + scenarioFile.getName());

writer.write( Json.pretty(testRecipe) );
writer.write(Json.pretty(testRecipe));
writer.close();
} catch (Exception e) {
LOG.error("Failed to write recipe to logFolder [" + logFolder + "]", e );
LOG.error("Failed to write recipe to logFolder [" + logFolder + "]", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

import com.smartbear.readyapi.client.model.RestTestRequestStep;
import com.smartbear.readyapi.client.model.SoapRequestTestStep;
import com.smartbear.readyapi.client.teststeps.TestStepTypes;
import com.smartbear.readyapi4j.teststeps.TestStepTypes;

/**
* Utility class with static method for building various types of TestSteps
*/

public class TestSteps {

public static RestTestRequestStep restRequest( String method, String endpoint ){
public static RestTestRequestStep restRequest(String method, String endpoint) {
RestTestRequestStep testStep = new RestTestRequestStep();
testStep.setURI(endpoint);
testStep.setMethod(method);
testStep.setType(TestStepTypes.REST_REQUEST.getName());
return testStep;
}

public static SoapRequestTestStep soapRequest( String wsdl, String operation, String binding ){
public static SoapRequestTestStep soapRequest(String wsdl, String operation, String binding) {
SoapRequestTestStep testStep = new SoapRequestTestStep();
testStep.setWsdl( wsdl );
testStep.setBinding( binding );
testStep.setOperation( operation );
testStep.setType( TestStepTypes.SOAP_REQUEST.getName());
testStep.setWsdl(wsdl);
testStep.setBinding(binding);
testStep.setOperation(operation);
testStep.setType(TestStepTypes.SOAP_REQUEST.getName());
return testStep;
}
}
5 changes: 2 additions & 3 deletions modules/runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
</parent>

<artifactId>testserver-cucumber-runner</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.smartbear.readyapi.testserver.cucumber</groupId>
<artifactId>testserver-cucumber-core</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.smartbear.readyapi.testserver.cucumber</groupId>
<artifactId>testserver-cucumber-stepdefs</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Feature: SwaggerHub REST API
And the response type is json
And the response body contains
"""
"description":"<description>"
"title":"<title>"
"""
Examples:
| owner | api | version | description |
| swagger-hub | registry-api | 1.0.10 | The registry API for SwaggerHub |
| fehguy | sonos-api | 1.0.0 | A REST API for the Sonos platform |
| owner | api | version | title |
| swagger-hub | registry-api | 1.0.10 | SwaggerHub Registry API |
| smartbear | ready-api-testserver | 1.2.1 | Ready! API TestServer API |
3 changes: 1 addition & 2 deletions modules/stepdefs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
<description>the actual Cucumber API StepDefs</description>

<artifactId>testserver-cucumber-stepdefs</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.smartbear.readyapi.testserver.cucumber</groupId>
<artifactId>testserver-cucumber-core</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>${project.version}</version>
</dependency>
</dependencies>

Expand Down