bootSimple integratio test converted from gradle
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -18,7 +18,6 @@
|
||||
<mavenVersion>3.2.5</mavenVersion>
|
||||
<mavenPluginPluginVersion>3.4</mavenPluginPluginVersion>
|
||||
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ public class GenerateSpecsMojo extends AbstractMojo {
|
||||
@Parameter(property = "basePackageForTests", defaultValue = "io.codearte.accurest.tests")
|
||||
private String basePackageForTests;
|
||||
|
||||
@Parameter(property = "baseClassForTests", required = true)
|
||||
private String baseClassForTests;
|
||||
|
||||
public GenerateSpecsMojo() {
|
||||
}
|
||||
|
||||
@@ -42,9 +45,11 @@ public class GenerateSpecsMojo extends AbstractMojo {
|
||||
config.setContractsDslDir(new File(baseDir, contractsDir));
|
||||
config.setBasePackageForTests(basePackageForTests);
|
||||
config.setGeneratedTestSourcesDir(new File(projectBuildDirectory, generatedTestSourcesDir));
|
||||
config.setBaseClassForTests(baseClassForTests);
|
||||
|
||||
getLog().info("Accurest Plugin: Invoking test sources generation");
|
||||
getLog().info(format("Using %s as test source directory", config.getGeneratedTestSourcesDir()));
|
||||
getLog().info(format("Using %s as base class for tests", config.getBaseClassForTests()));
|
||||
|
||||
try {
|
||||
TestGenerator generator = new TestGenerator(config);
|
||||
|
||||
@@ -40,4 +40,13 @@ public class PluginIntegrationTest {
|
||||
.execute("package")
|
||||
.assertLogText("Accurest Plugin: Invoking test sources generation");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBuildAndTestSimpleBootProject() throws Exception {
|
||||
File basedir = resources.getBasedir("bootSimple");
|
||||
maven.forProject(basedir)
|
||||
.execute("package")
|
||||
.assertErrorFreeLog()
|
||||
.assertLogText("Accurest Plugin: Invoking test sources generation");
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,9 @@
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<baseClassForTests>com.ofg.twitter.place.BaseMockMvcSpec</baseClassForTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
@@ -74,6 +77,12 @@
|
||||
</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>
|
||||
|
||||
153
src/test/projects/bootSimple/pom.xml
Normal file
153
src/test/projects/bootSimple/pom.xml
Normal file
@@ -0,0 +1,153 @@
|
||||
<?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>io.codearte.sample</groupId>
|
||||
<artifactId>sample-simple-boot</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<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>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<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>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
</dependency>
|
||||
<!--TODO: Replace this stuff with import accurest-test dependency-->
|
||||
|
||||
<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.github.tomakehurst</groupId>
|
||||
<artifactId>wiremock</artifactId>
|
||||
<version>2.0.4-beta</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.toomuchcoding.jsonassert</groupId>
|
||||
<artifactId>jsonassert</artifactId>
|
||||
<version>0.2.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<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>${it-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generateStubs</goal>
|
||||
<goal>generateSpecs</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<baseClassForTests>com.ofg.twitter.place.BaseMockMvcSpec</baseClassForTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
<artifactId>gmavenplus-plugin</artifactId>
|
||||
<version>1.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>addSources</goal>
|
||||
<goal>addTestSources</goal>
|
||||
<goal>generateStubs</goal>
|
||||
<goal>compile</goal>
|
||||
<goal>testGenerateStubs</goal>
|
||||
<goal>testCompile</goal>
|
||||
<goal>removeStubs</goal>
|
||||
<goal>removeTestStubs</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>
|
||||
@@ -0,0 +1,36 @@
|
||||
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
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ofg.twitter.place;
|
||||
|
||||
public class Tweet {
|
||||
private String text;
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
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 AcceptanceSpec 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())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.ofg.twitter.place
|
||||
|
||||
import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc
|
||||
import com.ofg.twitter.place.PairIdController
|
||||
import spock.lang.Specification
|
||||
|
||||
abstract class BaseMockMvcSpec extends Specification {
|
||||
|
||||
def setup() {
|
||||
RestAssuredMockMvc.standaloneSetup(new PairIdController())
|
||||
}
|
||||
|
||||
void isProperCorrelationId(Integer correlationId) {
|
||||
assert correlationId == 123456
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
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() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
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)
|
||||
@@ -0,0 +1,18 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user