-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4e6380
commit 365f402
Showing
11 changed files
with
542 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: java | ||
|
||
script: "mvn cobertura:cobertura" | ||
|
||
after_success: | ||
- bash <(curl -s https://codecov.io/bash) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,41 @@ | ||
# rest-assured-extension | ||
JUnit 5 extension for REST-assured. | ||
|
||
[![Build Status](https://travis-ci.org/JensPiegsa/rest-assured-extension.svg?branch=master)](https://travis-ci.org/JensPiegsa/rest-assured-extension) | ||
[![codecov](https://codecov.io/gh/JensPiegsa/rest-assured-extension/branch/master/graph/badge.svg)](https://codecov.io/gh/JensPiegsa/rest-assured-extension) | ||
[![](https://jitpack.io/v/JensPiegsa/rest-assured-extension.svg)](https://jitpack.io/#JensPiegsa/rest-assured-extension) | ||
|
||
The rest-assured-extension is a [JUnit 5](https://junit.org/junit5/) [extension](https://junit.org/junit5/docs/current/user-guide/#extensions) for [REST-assured](http://rest-assured.io/). | ||
|
||
|
||
## Usage | ||
|
||
### Step 1. Add the JitPack repository to your **pom.xml** file | ||
|
||
<repositories> | ||
<repository> | ||
<id>jitpack.io</id> | ||
<url>https://jitpack.io</url> | ||
</repository> | ||
</repositories> | ||
|
||
|
||
### Step 2. Add the rest-assured-extension dependency | ||
|
||
<dependency> | ||
<groupId>com.github.JensPiegsa</groupId> | ||
<artifactId>rest-assured-extension</artifactId> | ||
<version>0.1.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
### Step 3. Annotate test classes by `@ExtendsWith(RestAssuredExtension.class)` | ||
|
||
* see [`ExampleTest`](https://github.com/JensPiegsa/rest-assured-extension/blob/master/src/test/java/com/github/jenspiegsa/restassuredextension/ExampleTest.java) for further configuration and different use cases. | ||
|
||
## Contribute | ||
|
||
Feedback is welcome. The source is available on [Github](https://github.com/JensPiegsa/rest-assured-extension/). Please [report any issues](https://github.com/JensPiegsa/rest-assured-extension/issues). | ||
|
||
## About | ||
|
||
Plugin originally created by [Jens Piegsa](https://github.com/JensPiegsa). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?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>com.github.JensPiegsa</groupId> | ||
<artifactId>rest-assured-extension</artifactId> | ||
<version>0.1.0</version> | ||
|
||
<properties> | ||
<java.min.version>1.8</java.min.version> | ||
|
||
<junit.jupiter.version>5.4.0</junit.jupiter.version> | ||
<junit.platform.version>1.4.0</junit.platform.version> | ||
<mockito.version>2.24.5</mockito.version> | ||
<surefire.version>3.0.0-M3</surefire.version> | ||
<resteasy.version>3.0.19.Final</resteasy.version> | ||
|
||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
|
||
<maven.compiler.source>${java.min.version}</maven.compiler.source> | ||
<maven.compiler.target>${java.min.version}</maven.compiler.target> | ||
<maven.compiler.testSource>${java.min.version}</maven.compiler.testSource> | ||
<maven.compiler.testTarget>${java.min.version}</maven.compiler.testTarget> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${surefire.version}</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>cobertura-maven-plugin</artifactId> | ||
<version>2.7</version> | ||
<configuration> | ||
<formats> | ||
<format>html</format> | ||
<format>xml</format> | ||
</formats> | ||
<check /> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit</groupId> | ||
<artifactId>junit-bom</artifactId> | ||
<version>${junit.jupiter.version}</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<version>3.2.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>${junit.jupiter.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.json</groupId> | ||
<artifactId>javax.json-api</artifactId> | ||
<version>1.1.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.ws.rs</groupId> | ||
<artifactId>javax.ws.rs-api</artifactId> | ||
<version>2.1.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-jdk-http</artifactId> | ||
<version>3.5.1.Final</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>${junit.jupiter.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>3.12.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<version>${mockito.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-client</artifactId> | ||
<version>3.5.1.Final</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-json-p-provider</artifactId> | ||
<version>3.5.1.Final</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/github/jenspiegsa/restassuredextension/ConfigureRestAssured.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.github.jenspiegsa.restassuredextension; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* @author Jens Piegsa | ||
*/ | ||
@Documented | ||
@Target(FIELD) | ||
@Retention(RUNTIME) | ||
public @interface ConfigureRestAssured { | ||
|
||
String contextPath(); | ||
|
||
int port(); | ||
} |
41 changes: 41 additions & 0 deletions
41
...ain/java/com/github/jenspiegsa/restassuredextension/PostConstructPojoResourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.jenspiegsa.restassuredextension; | ||
|
||
import java.util.function.Consumer; | ||
import org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory; | ||
import org.jboss.resteasy.spi.HttpRequest; | ||
import org.jboss.resteasy.spi.HttpResponse; | ||
import org.jboss.resteasy.spi.ResourceFactory; | ||
import org.jboss.resteasy.spi.ResteasyProviderFactory; | ||
|
||
/** | ||
* This resource factory enhances RESTEasy's {@link POJOResourceFactory} by a post construction step. | ||
* | ||
* @author Jens Piegsa | ||
* | ||
* @param <E> | ||
* the resource class | ||
*/ | ||
public class PostConstructPojoResourceFactory<E> extends POJOResourceFactory { | ||
|
||
private final Consumer<E> postConstruct; | ||
|
||
public PostConstructPojoResourceFactory(final Class<E> scannableClass, final Consumer<E> postConstruct) { | ||
super(scannableClass); | ||
this.postConstruct = postConstruct; | ||
} | ||
|
||
@Override | ||
public Object createResource(final HttpRequest request, final HttpResponse response, final ResteasyProviderFactory factory) { | ||
@SuppressWarnings("unchecked") | ||
final E resource = (E) super.createResource(request, response, factory); | ||
postConstruct.accept(resource); | ||
return resource; | ||
} | ||
|
||
/** | ||
* Creates a {@link ResourceFactory} for a given JAX-RS POJO {@link Class} that is able to perform additional instance-level post construction steps utilizing the provided {@link Consumer}. | ||
*/ | ||
public static <T> ResourceFactory wired(final Class<T> scannableClass, final Consumer<T> postConstruct) { | ||
return new PostConstructPojoResourceFactory<>(scannableClass, postConstruct); | ||
} | ||
} |
Oops, something went wrong.