Skip to content

Commit

Permalink
First api draft
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Desigaud committed Feb 8, 2017
0 parents commit f59ac09
Show file tree
Hide file tree
Showing 11 changed files with 1,026 additions and 0 deletions.
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#REST API integration testing framework based on cucumber.js and Spring

#Stack
- Spring Boot
- Cucumber
- Cucumber-Spring
- Jayway JsonPath
- Rest template (Spring web framework)

#Description
- Predefined steps
- Handle RESTFUL requests
- Possibility to set request headers or parameters
- Possibility to test response headers
- Possibility to test response status code
- Possibility to test the body response using a json path

#Feature template
- In order to successfully use this library, you need to respect the following template for your .feature files
(an example file can be found under src/test/resources/template_feature)
- The template was inspired by the [apickli project](https://github.com/apickli/apickli)



- GIVEN
* I set (.*) header to (.*)
* I set body to (.*)
* I pipe contents of file (.*) to body
* I have basic authentication credentials (.*) and (.*)
* I set bearer token
* I set query parameters to (data table with headers |parameter|value|)
* I set headers to (data table with headers |name|value|)

- WHEN
* I GET $resource
* I POST to $resource
* I PUT $resource
* I DELETE $resource
* I PATCH $resource
* I request OPTIONS for $resource
* I request HEAD for $resource

- THEN
* response code should be (\d+)
* response code should not be (\d+)
* response header (.*) should exist
* response header (.*) should not exist
* response header (.*) should be (.*)
* response header (.*) should not be (.*)
* response body should be valid (xml|json)
* response body should contain (.*)
* response body should not contain (.*)
* response body path (.*) should be (.*)
* response body path (.*) should not be (.*)
* response body path (.*) should be of type array
* response body path (.*) should be of type array with length (\d+)
* response body should be valid according to schema file (.*)
* response body should be valid according to swagger definition (.*) in file (.*)
* I store the value of body path (.*) as access token
* I store the value of response header (.*) as (.*) in scenario scope
* I store the value of body path (.*) as (.*) in scenario scope
* value of scenario variable (.*) should be (.*)
* I store the value of response header (.*) as (.*) in global scope
* I store the value of body path (.*) as (.*) in global scope


#Examples
Two example feature files are available under src/test/resources/features folder

#How to use in my existing project ?


#To run Java unit tests
````bash
$ mvn test
````

It will run two features and test two kind of apis:
- An external one: Swagger petstore api
- An internal one: A spring rest api declared in the project using @RestController
113 changes: 113 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fr.redfroggy.test.bdd</groupId>
<artifactId>cucumber-gherkin</artifactId>
<version>1.0-SNAPSHOT</version>

<name>Cucumber Spring rest Api</name>
<description>Predefined steps to consume rest API</description>

<organization>
<name>RedFroggy</name>
<url>http://www.redfroggy.fr</url>
</organization>

<scm>
<url>https://github.com/spring-projects/spring-boot</url>
</scm>
<developers>
<developer>
<id>mdesigaud</id>
<name>Michael Desigaud</name>
<email>michael.desigaud at redfroggy.fr</email>
<organization>RedFroggy</organization>
<organizationUrl>http://www.redfroggy.fr</organizationUrl>
<roles>
<role>Developer</role>
</roles>
</developer>
</developers>

<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>

<properties>
<cucumber-version>1.2.5</cucumber-version>
<jsonpath-version>2.2.0</jsonpath-version>
</properties>

<dependencies>

<!-- Spring web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Cucumber java implementation -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber-version}</version>
</dependency>

<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber-version}</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber-version}</version>
</dependency>

<!-- Json path library -->
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>${jsonpath-version}</version>
</dependency>

<!-- Spring test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>

<!-- Junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading

0 comments on commit f59ac09

Please sign in to comment.