Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JensPiegsa committed Feb 26, 2019
1 parent c4e6380 commit 365f402
Show file tree
Hide file tree
Showing 11 changed files with 542 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ buildNumber.properties

# Avoid ignoring Maven wrapper jar file (.jar files are usually ignored)
!/.mvn/wrapper/maven-wrapper.jar

/.idea
6 changes: 6 additions & 0 deletions .travis.yml
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)
41 changes: 40 additions & 1 deletion README.md
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).
131 changes: 131 additions & 0 deletions pom.xml
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>
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();
}
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);
}
}
Loading

0 comments on commit 365f402

Please sign in to comment.