First contract test
This commit is contained in:
21
MIGRATION.md
21
MIGRATION.md
@@ -2,10 +2,29 @@
|
||||
|
||||
- Added Maven wrapper
|
||||
|
||||
```
|
||||
```bash
|
||||
$ mvn -N io.takari:maven:wrapper
|
||||
$ git add .
|
||||
$ git add -f .mvn
|
||||
$ git commit -m "Added maven wrapper"
|
||||
```
|
||||
|
||||
- Updated `manifest.yml`
|
||||
- Added `sc-pipelines.yml`
|
||||
- provided which module is the main one
|
||||
- added database as a required service
|
||||
- Created cloud foundry spaces
|
||||
|
||||
```bash
|
||||
$ cf login -o ... -a ...
|
||||
$ cf create-space sc-pipelines-test-dddbyexamples-factory
|
||||
$ cf create-space sc-pipelines-stage-dddbyexamples-factory
|
||||
$ cf create-space sc-pipelines-prod
|
||||
```
|
||||
|
||||
- Added contract tests (`shortages-prediction-adapters/src/test/groovy/io/dddbyexamples/factory/shortages/prediction/monitoring/persistence/ShortagesDaoTest.groovy`)
|
||||
- Added stub jar generation in `app-monolith` (in the output stubs jar each module has its own folder)
|
||||
- Added base class for rollback tests
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,14 @@
|
||||
<version>2.0.0.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<!-- SPRING CLOUD PIPELINES -->
|
||||
<distribution.management.release.id>artifactory-local</distribution.management.release.id>
|
||||
<distribution.management.release.url>http://localhost:8081/artifactory/libs-release-local</distribution.management.release.url>
|
||||
<repo.with.binaries>http://localhost:8081/artifactory/libs-release-local</repo.with.binaries>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>pl.com.dddbyexamples</groupId>
|
||||
@@ -129,10 +137,6 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@@ -155,6 +159,7 @@
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>addTestSources</goal>
|
||||
<goal>compileTests</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
@@ -171,6 +176,26 @@
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>stub</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<inherited>false</inherited>
|
||||
<configuration>
|
||||
<attach>true</attach>
|
||||
<descriptors>
|
||||
${basedir}/src/assembly/stub.xml
|
||||
</descriptors>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
28
app-monolith/src/assembly/stub.xml
Normal file
28
app-monolith/src/assembly/stub.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
|
||||
<id>stubs</id>
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<fileSets>
|
||||
<!-- We need file sets per each module, then they will be moved to separate services -->
|
||||
<!-- Shortages prediction adapters -->
|
||||
<fileSet>
|
||||
<directory>${project.basedir}/../shortages-prediction-adapters/target/generated-snippets/stubs</directory>
|
||||
<outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/shortages-prediction-adapters/mappings</outputDirectory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}/../shortages-prediction-adapters/target/generated-snippets/contracts</directory>
|
||||
<outputDirectory>META-INF/${project.groupId}/${project.artifactId}/${project.version}/shortages-prediction-adapters/contracts</outputDirectory>
|
||||
<includes>
|
||||
<include>**/*.groovy</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
@@ -82,6 +82,19 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
<artifactId>gmavenplus-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>addTestSources</goal>
|
||||
<goal>compileTests</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
|
||||
@@ -8,7 +8,7 @@ import io.dddbyexamples.factory.delivery.planning.definition.DeliveryPlannerDefi
|
||||
import spock.lang.Specification
|
||||
|
||||
import static java.time.LocalTime.of as time
|
||||
import static DeliveryPlannerDefinition.of
|
||||
import static io.dddbyexamples.factory.delivery.planning.definition.DeliveryPlannerDefinition.of
|
||||
import static io.dddbyexamples.factory.demand.forecasting.Demand.Schema.*
|
||||
|
||||
@SpringBootTest
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
applications:
|
||||
- name: factory
|
||||
memory: 800M
|
||||
- name: dddbyexamples-app-monolith
|
||||
timeout: 120
|
||||
services:
|
||||
- fortune-db
|
||||
env:
|
||||
JAVA_OPTS: -Djava.security.egd=file:///dev/urandom
|
||||
TRUST_CERTS: api.run.pivotal.io
|
||||
4
pom.xml
4
pom.xml
@@ -9,6 +9,10 @@
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<main.basedir>${project.basedir}</main.basedir>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
<module>app-monolith</module>
|
||||
<module>adapter-commons</module>
|
||||
|
||||
@@ -77,6 +77,19 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
<artifactId>gmavenplus-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>addTestSources</goal>
|
||||
<goal>compileTests</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package io.dddbyexamples.factory.product.management
|
||||
|
||||
import spock.lang.Ignore
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import spock.lang.Specification
|
||||
|
||||
import static java.util.Collections.singletonList
|
||||
|
||||
// TODO: Unignore
|
||||
@Ignore
|
||||
@SpringBootTest
|
||||
class ProductDescriptionPersistenceSpec extends Specification {
|
||||
|
||||
|
||||
10
sc-pipelines.yml
Normal file
10
sc-pipelines.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
build:
|
||||
main-module: app-monolith
|
||||
test:
|
||||
# list of required services
|
||||
services:
|
||||
- name: fortune-db
|
||||
type: broker
|
||||
broker: cleardb
|
||||
plan: spark
|
||||
useExisting: true
|
||||
@@ -68,21 +68,56 @@
|
||||
<version>1.7.9</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.restdocs</groupId>
|
||||
<artifactId>spring-restdocs-mockmvc</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.197</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
<artifactId>gmavenplus-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>addTestSources</goal>
|
||||
<goal>compileTests</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package io.dddbyexamples.factory.shortages.prediction.monitoring.persistence
|
||||
|
||||
import groovy.transform.CompileStatic
|
||||
import org.mockito.Mockito
|
||||
import spock.lang.Specification
|
||||
|
||||
import org.springframework.beans.BeansException
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.cloud.contract.wiremock.restdocs.SpringCloudContractRestDocs
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation
|
||||
import org.springframework.test.web.servlet.MockMvc
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
|
||||
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.MOCK
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = MOCK, classes = ShortagesDaoTest.Config)
|
||||
@AutoConfigureMockMvc
|
||||
// would love to get rid of this
|
||||
@AutoConfigureTestDatabase
|
||||
@AutoConfigureRestDocs
|
||||
class ShortagesDaoTest extends Specification {
|
||||
|
||||
@Autowired ShortagesDao shortagesDao
|
||||
@Autowired MockMvc mockMvc
|
||||
|
||||
def "should find ref by no"() {
|
||||
given:
|
||||
ShortagesEntity entity = new ShortagesEntity("1")
|
||||
entity.id = 1L
|
||||
entity.version = 1L
|
||||
Mockito.doReturn([entity]).when(shortagesDao).findAll()
|
||||
expect:
|
||||
mockMvc.perform(get("/shortages?refNo=1"))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk())
|
||||
.andDo(MockMvcRestDocumentation.document("find_ref_by_no",
|
||||
SpringCloudContractRestDocs.dslContract()))
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan("io.dddbyexamples.factory.shortages.prediction.persistence")
|
||||
@CompileStatic
|
||||
static class Config {
|
||||
|
||||
// https://github.com/spring-projects/spring-boot/issues/7033
|
||||
@Bean
|
||||
BeanPostProcessor shortagesBeanPostProcessor() {
|
||||
return new BeanPostProcessor() {
|
||||
@Override
|
||||
Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof ShortagesDao) {
|
||||
return Mockito.mock(ShortagesDao)
|
||||
}
|
||||
return bean
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user