plugin documentation

[ci skip]
This commit is contained in:
Mariusz Smykula
2016-04-24 18:46:47 +02:00
parent f660250bcf
commit 268f10f848
25 changed files with 321 additions and 405 deletions

View File

@@ -3,91 +3,9 @@
Accurate REST Maven Plugin
====
Converting [Accurest](https://github.com/Codearte/accurest/wiki/1.-Introduction) GroovyDSL into WireMock stub mappings:
Documentation
---
mvn io.codearte.accurest:accurest-maven-plugin:convert
or shortly <sup>*</sup>
mvn accurest:convert
For more information please go to the [Accurest Wiki](https://github.com/Codearte/accurest/wiki/2.2-Maven-Project) or [Plugin Documentation Site](http://codearte.github.io/accurest-maven-plugin/plugin-info.html).
* [Accurest Wiki](https://github.com/Codearte/accurest/)
* [Accurest Maven Plugin Documentation Site](http://codearte.github.io/accurest-maven-plugin/plugin-info.html)
Accurest Stub Runner
---
Run stubs mappings from current directory:
mvn io.codearte.accurest:accurest-maven-plugin:run
or shortly <sup>*</sup>
mvn accurest:run
Running stubs from repository:
mvn accurest:run -Dstubs="org.springframework:gs-rest-service"
where `org.springframework:gs-rest-service` is artifact with `stubs` classifier contains wiremock mappings.
Project configuration
----
```xml
<plugin>
<groupId>io.codearte.accurest</groupId>
<artifactId>accurest-maven-plugin</artifactId>
<version>0.5.7</version>
<executions>
<execution>
<goals>
<goal>convert</goal>
<goal>generateStubs</goal>
<goal>generateTests</goal>
</goals>
</execution>
</executions>
<configuration>
<baseClassForTests>foobar.BaseAccurestTest</baseClassForTests>
</configuration>
</plugin>
```
Sample `BaseAccurateTest.java`
```java
package foobar;
import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc;
import org.junit.Before;
public class BaseAccurestTest {
@Before
public void setup() {
RestAssuredMockMvc.standaloneSetup(new FoobarController());
}
}
```
---
<sup>*</sup> Additional configuration inside `~/.m2/settings.xml` is required.
```xml
<settings>
...
<pluginGroups>
<pluginGroup>io.codearte.accurest</pluginGroup>
</pluginGroups>
...
</settings>
```

View File

@@ -0,0 +1,29 @@
== Java Project with JUnit Tests
Sample minimal configuration for Java Project with JUnit tests.
=== Test dependencies for generated contract verification tests
[source,xml]
----
include::../../../src/test/projects/spring-boot-java/pom.xml[tags=dependencies]
----
=== Project configuration for Accurest with JUnit tests and stub publishing
[source,xml]
----
include::../../../src/test/projects/spring-boot-java/pom.xml[tags=plugin]
----
=== Base Test class
[source,java]
----
include::../../../src/test/projects/spring-boot-java/src/test/java/hello/BaseAccurest.java[]
----
=== Project source code
https://github.com/Codearte/accurest-maven-plugin/tree/master/src/test/projects/spring-boot-java

View File

@@ -0,0 +1,29 @@
== Groovy Project with Spock Specifications
Sample minimal configuration for Groovy Project with Spock Specification
=== Test dependencies for generated contract verification tests
[source,xml]
----
include::../../../src/test/projects/spring-boot-groovy/pom.xml[tags=dependencies]
----
=== Project configuration for Accurest, Groovy and Spock specifications and stub publishing
[source,xml]
----
include::../../../src/test/projects/spring-boot-groovy/pom.xml[tags=plugin]
----
=== Base Specification class
[source,java]
----
include::../../../src/test/projects/spring-boot-groovy/src/test/groovy/hello/BaseAccurest.groovy[]
----
=== Project source code
https://github.com/Codearte/accurest-maven-plugin/tree/master/src/test/projects/spring-boot-groovy

View File

@@ -1,24 +1,35 @@
== Usage
= Usage
Sample minimal configuration for project with Java source code.
== Converting Accurest GroovyDSL into WireMock stub mappings
mvn io.codearte.accurest:accurest-maven-plugin:convert
or shortly footnoteref:[prefix,Additional configuration inside `~/.m2/settings.xml` is required: `<pluginGroups><pluginGroup>io.codearte.accurest</pluginGroup></pluginGroups>`.]
mvn accurest:convert
For more information please go to the Accurest Wiki or Plugin Documentation Site.
== Accurest Stub Runner
Run stubs mappings from current directory:
mvn io.codearte.accurest:accurest-maven-plugin:run
or shortly footnoteref:[prefix]
mvn accurest:run
== Running stubs from repository
mvn accurest:run -Dstubs="org.springframework:gs-rest-service"
where `org.springframework:gs-rest-service` is artifact with stubs classifier contains wiremock mappings.
== Project configuration
[source,xml]
----
<plugin>
<groupId>io.codearte.accurest</groupId>
<artifactId>accurest-maven-plugin</artifactId>
<version>0.5.8</version> <!-- use latest release -->
<executions>
<execution>
<goals>
<goal>convert</goal>
<goal>generateStubs</goal>
<goal>generateTests</goal>
</goals>
</execution>
</executions>
<configuration>
<baseClassForTests>foobar.AccurestBaseTest</baseClassForTests>
</configuration>
</plugin>
include::../../../src/test/projects/spring-boot-java/pom.xml[tags=plugin]
----

View File

@@ -28,6 +28,8 @@
<item name="Introduction" href="index.html"/>
<item name="Usage" href="usage.html"/>
<item name="Goals" href="plugin-info.html"/>
<item name="Accurest with JUnit" href="junit.html"/>
<item name="Accurest with Spock" href="spock.html"/>
</menu>
<menu name="Related Projects">
<item name="Accurate REST" href="https://github.com/Codearte/accurest"/>

View File

@@ -37,7 +37,7 @@ public class PluginIT {
.assertLogText("Generated 1 test classes.")
.assertLogText("Converting from accurest contracts written in GroovyDSL to WireMock stubs mappings")
.assertLogText("Creating new json")
.assertLogText("Compiled 3 files.") // groovy test classes
.assertLogText("Running io.codearte.accurest.tests.AccurestSpec")
.assertErrorFreeLog();
}
@@ -51,7 +51,7 @@ public class PluginIT {
.assertLogText("Generated 1 test classes.")
.assertLogText("Converting from accurest contracts written in GroovyDSL to WireMock stubs mappings")
.assertLogText("Creating new json")
.assertLogText("Compiling 2 source files")
.assertLogText("Running io.codearte.accurest.tests.AccurestTest")
.assertErrorFreeLog();
}

View File

@@ -1,137 +1,128 @@
<?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>
<modelVersion>4.0.0</modelVersion>
<groupId>io.codearte.sample</groupId>
<artifactId>sample-simple-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<groupId>org.springframework</groupId>
<artifactId>gs-rest-service</artifactId>
<version>0.1.0</version>
<name>sample-simple-boot</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<accurest.version>${it-plugin.version}</accurest.version>
</properties>
<!-- accurest test dependencies -->
<!-- tag::dependencies[] -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.toomuchcoding.jsonassert</groupId>
<artifactId>jsonassert</artifactId>
<version>0.3.0</version>
<scope>test</scope>
<!-- end::dependencies[] -->
</dependency>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</dependency>
<properties>
<java.version>1.8</java.version>
<accurest-plugin.version>${it-plugin.version}</accurest-plugin.version>
</properties>
<!-- accurest test dependencies -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.toomuchcoding.jsonassert</groupId>
<artifactId>jsonassert</artifactId>
<version>0.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::plugin[] -->
<plugin>
<groupId>io.codearte.accurest</groupId>
<artifactId>accurest-maven-plugin</artifactId>
<version>${accurest-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>convert</goal>
<goal>generateStubs</goal>
<goal>generateTests</goal>
</goals>
</execution>
</executions>
<configuration>
<baseClassForTests>hello.BaseAccurest</baseClassForTests>
<testFramework>SPOCK</testFramework>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<testSources>
<testSource>
<directory>${project.basedir}/src/test/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</testSource>
<testSource>
<directory>${project.build.directory}/generated-test-sources/accurest</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</testSource>
</testSources>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<includes>
<include>**/*Spec.java</include>
</includes>
</configuration>
</plugin>
<!-- end::plugin[] -->
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.codearte.accurest</groupId>
<artifactId>accurest-maven-plugin</artifactId>
<version>${accurest.version}</version>
<executions>
<execution>
<goals>
<goal>convert</goal>
<goal>generateStubs</goal>
<goal>generateTests</goal>
</goals>
</execution>
</executions>
<configuration>
<baseClassForTests>com.ofg.twitter.place.BaseMockMvcTest</baseClassForTests>
<contractsDirectory>src/test/resources/stubs</contractsDirectory>
<testFramework>SPOCK</testFramework>
<nameSuffixForTests>Test</nameSuffixForTests>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<testSources>
<testSource>
<directory>${project.basedir}/src/test/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</testSource>
<testSource>
<directory>${project.build.directory}/generated-test-sources/accurest</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</testSource>
</testSources>
</configuration>
</plugin>
<!-- <plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<includes>
<include>**/*Spec.java</include>
</includes>
</configuration>
</plugin>-->
</plugins>
</build>
</project>

View File

@@ -1,36 +0,0 @@
package com.ofg.twitter.place
import groovy.transform.TypeChecked
import groovy.util.logging.Slf4j
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import static org.springframework.web.bind.annotation.RequestMethod.PUT
@Slf4j
@RestController
@RequestMapping('/api')
@TypeChecked
class PairIdController {
@RequestMapping(
value = '{pairId}',
method = PUT,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
String getPlacesFromTweets(@PathVariable long pairId, @RequestBody List<com.ofg.twitter.place.Tweet> tweets) {
log.info("Inside PairIdController, doing very important logic")
if (tweets?.text != ["Gonna see you at Warsaw"]) {
throw new IllegalArgumentException("Wrong text in tweet: ${tweets?.text}")
}
return """
{
"path" : "/api/$pairId",
"correlationId" : 123456
}
"""
}
}

View File

@@ -1,13 +0,0 @@
package com.ofg.twitter.place;
public class Tweet {
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}

View File

@@ -0,0 +1,12 @@
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@@ -0,0 +1,20 @@
package hello;
public class Greeting {
private final long id;
private final String content;
public Greeting(long id, String content) {
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}

View File

@@ -0,0 +1,19 @@
package hello;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}

View File

@@ -1,12 +0,0 @@
package io.codearte.sample;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SampleSimpleBootApplication {
public static void main(String[] args) {
SpringApplication.run(SampleSimpleBootApplication.class, args);
}
}

View File

@@ -0,0 +1,21 @@
io.codearte.accurest.dsl.GroovyDsl.make {
priority 2
request {
method 'GET'
urlPath('/greeting') {
queryParameters {
parameter 'name': 'Something'
}
}
headers {
header 'Content-Type': 'application/json'
}
}
response {
status 200
body (
id: 1,
content: "Hello, Something!"
)
}
}

View File

@@ -0,0 +1,17 @@
io.codearte.accurest.dsl.GroovyDsl.make {
priority 2
request {
method 'GET'
url('/greeting')
headers {
header 'Content-Type': 'application/json'
}
}
response {
status 200
body (
id: 1,
content: "Hello, World!"
)
}
}

View File

@@ -1,23 +0,0 @@
package com.ofg.twitter.place
import com.ofg.twitter.place.PairIdController
import org.springframework.http.MediaType
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import spock.lang.Specification
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
class AcceptanceTest extends Specification {
def "should have controller up and running"() {
given:
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new PairIdController()).build()
expect:
mockMvc.perform(put("/api/${1}").
contentType(MediaType.APPLICATION_JSON).
content("""[{"text":"Gonna see you at Warsaw"}]""")).
andExpect(status().isOk())
}
}

View File

@@ -1,16 +0,0 @@
package com.ofg.twitter.place
import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc
import com.ofg.twitter.place.PairIdController
import spock.lang.Specification
abstract class BaseMockMvcTest extends Specification {
def setup() {
RestAssuredMockMvc.standaloneSetup(new PairIdController())
}
void isProperCorrelationId(Integer correlationId) {
assert correlationId == 123456
}
}

View File

@@ -0,0 +1,12 @@
package hello
import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc
import spock.lang.Specification
public class BaseAccurest extends Specification {
def setup() {
RestAssuredMockMvc.standaloneSetup(new GreetingController())
}
}

View File

@@ -1,16 +0,0 @@
package io.codearte.sample;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SampleSimpleBootApplication.class)
public class SampleSimpleBootApplicationTests {
@Test
public void contextLoads() {
}
}

View File

@@ -1,14 +0,0 @@
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.core.ConsoleAppender
String console = "CONSOLE"
String logPattern = "%d{yyyy-MM-dd HH:mm:ss.SSSZ, Europe/Warsaw} | %-5level | %X{correlationId} | %thread | %logger{1} | %m%n"
appender(console, ConsoleAppender) {
encoder(PatternLayoutEncoder) {
pattern = logPattern
}
}
root(INFO, [console])
logger("com.ofg", DEBUG)

View File

@@ -1,18 +0,0 @@
io.codearte.accurest.dsl.GroovyDsl.make {
priority 2
request {
method 'PUT'
url '/api/12'
headers {
header 'Content-Type': 'application/json'
}
body '''\
[{
"text": "Gonna see you at Warsaw"
}]
'''
}
response {
status 200
}
}

View File

@@ -1,21 +0,0 @@
io.codearte.accurest.dsl.GroovyDsl.make {
request {
method 'PUT'
url $(client(regex('^/api/[0-9]{2}$')), server('/api/12'))
headers {
header 'Content-Type': 'application/json'
}
body '''\
[{
"text": "Gonna see you at Warsaw"
}]
'''
}
response {
body (
path: $(client('/api/12'), server(regex('^/api/[0-9]{2}$'))),
correlationId: $(client('1223456'), server(execute('isProperCorrelationId($it)')))
)
status 200
}
}

View File

@@ -29,6 +29,7 @@
</dependency>
<!-- accurest test dependencies -->
<!-- tag::dependencies[] -->
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
@@ -53,10 +54,12 @@
<version>2.3.0</version>
<scope>test</scope>
</dependency>
<!-- end::dependencies[] -->
</dependencies>
<properties>
<java.version>1.8</java.version>
<accurest-plugin.version>${it-plugin.version}</accurest-plugin.version>
</properties>
<build>
@@ -65,10 +68,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- tag::plugin[] -->
<plugin>
<groupId>io.codearte.accurest</groupId>
<artifactId>accurest-maven-plugin</artifactId>
<version>${it-plugin.version}</version>
<version>${accurest-plugin.version}</version>
<executions>
<execution>
<goals>
@@ -79,10 +83,10 @@
</execution>
</executions>
<configuration>
<basePackageForTests>hello</basePackageForTests>
<baseClassForTests>hello.BaseMockMvcTest</baseClassForTests>
<baseClassForTests>hello.BaseAccurest</baseClassForTests>
</configuration>
</plugin>
<!-- end::plugin[] -->
</plugins>
</build>
</project>

View File

@@ -3,7 +3,7 @@ package hello;
import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc;
import org.junit.Before;
public class BaseMockMvcTest {
public class BaseAccurest {
@Before
public void setup() {