Backward compatibility of HAL is working - still in offline mode - need to change it to remote

This commit is contained in:
Marcin Grzejszczak
2018-05-30 19:24:29 +02:00
parent 102f96d338
commit dc44873966
6 changed files with 282 additions and 27 deletions

View File

@@ -22,8 +22,10 @@ $ cf create-space sc-pipelines-stage-dddbyexamples-factory
$ cf create-space sc-pipelines-prod
```
- Added `<distributionManagement>` section
- 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 `<profiles>` for all types of tests
- Added base class for rollback tests

View File

@@ -16,12 +16,27 @@
<properties>
<java.version>1.8</java.version>
<!-- SPRING CLOUD PIPELINES -->
<!-- [PIPELINE] -->
<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>
<distribution.management.snapshot.url>http://localhost:8081/artifactory/libs-snapshot-local</distribution.management.snapshot.url>
<repo.with.binaries>http://localhost:8081/artifactory/libs-release-local</repo.with.binaries>
</properties>
<!-- [PIPELINE] -->
<distributionManagement>
<repository>
<id>${distribution.management.release.id}</id>
<name>Release Repository</name>
<url>${distribution.management.release.url}</url>
</repository>
<snapshotRepository>
<id>${distribution.management.release.id}</id>
<name>Snapshot Repository</name>
<url>${distribution.management.snapshot.url}</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>pl.com.dddbyexamples</groupId>

View File

@@ -73,6 +73,11 @@
<artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
@@ -101,6 +106,7 @@
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.BUILD-SNAPSHOT</spring-cloud.version>
<spring-cloud-contract.version>2.0.0.BUILD-SNAPSHOT</spring-cloud-contract.version>
</properties>
<build>
@@ -153,4 +159,182 @@
</plugins>
</build>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<includes>
<include>**/*Tests.java</include>
<include>**/*Test.java</include>
<include>**/*Spec.groovy</include>
</includes>
<excludes>
<exclude>**/smoke/**</exclude>
<exclude>**/e2e/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!-- [PIPELINE] -->
<profile>
<id>apicompatibility</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<includes>
<include>**/contracttests/**/*Tests.java</include>
<include>**/contracttests/**/*Test.java</include>
<include>**/contracttests/**/*Spec.groovy</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-contract-maven-plugin</artifactId>
<version>${spring-cloud-contract.version}</version>
<extensions>true</extensions>
<configuration>
<!-- Will be injected by the pipeline -->
<!--<contractsRepositoryUrl>${repo.with.binaries}</contractsRepositoryUrl>-->
<!--<contractsMode>REMOTE</contractsMode>-->
<contractsMode>LOCAL</contractsMode>
<deleteStubsAfterTest>false</deleteStubsAfterTest>
<contractDependency>
<groupId>${project.groupId}</groupId>
<artifactId>app-monolith</artifactId>
<classifier>stubs</classifier>
<version>${latest.production.version}</version>
</contractDependency>
<testFramework>SPOCK</testFramework>
<testMode>EXPLICIT</testMode>
<baseClassForTests>io.dddbyexamples.factory.shortages.prediction.monitoring.persistence.BaseClass</baseClassForTests>
<basePackageForTests>io.dddbyexamples.contracttests</basePackageForTests>
<contractsPath>META-INF/${project.groupId}/app-monolith/${latest.production.version}/shortages-prediction-adapters/contracts</contractsPath>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!-- [PIPELINE] -->
<profile>
<id>smoke</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<includes>
<include>smoke/**/*Tests.java</include>
<include>smoke/**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!-- [PIPELINE] -->
<profile>
<id>e2e</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<includes>
<include>e2e/**/*Tests.java</include>
<include>e2e/**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>spring</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>https://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</project>

View File

@@ -0,0 +1,33 @@
package io.dddbyexamples.factory.shortages.prediction.monitoring.persistence
import groovy.transform.CompileStatic
import io.restassured.RestAssured
import io.restassured.module.mockmvc.RestAssuredMockMvc
import spock.lang.Specification
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.web.context.WebApplicationContext
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.MOCK
/**
* @author Marcin Grzejszczak
*/
@CompileStatic
// TODO: Migrate to MockMvc - need to know how to set a port
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
properties = ["server.port=8080"],
classes = Config)
@AutoConfigureTestDatabase
abstract class BaseClass extends Specification {
@Autowired WebApplicationContext context
@Autowired ShortagesDao shortagesDao
def setup() {
RestAssured.baseURI = "http://localhost:8080"
Config.defaultStubbing(shortagesDao)
}
}

View File

@@ -0,0 +1,45 @@
package io.dddbyexamples.factory.shortages.prediction.monitoring.persistence
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.mockito.Mockito
import org.springframework.beans.BeansException
import org.springframework.beans.factory.config.BeanPostProcessor
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
/**
* @author Marcin Grzejszczak
*/
@Configuration
@EnableAutoConfiguration
@ComponentScan("io.dddbyexamples.factory.shortages.prediction.persistence")
@CompileStatic
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
}
}
}
@CompileDynamic
static ShortagesDao defaultStubbing(ShortagesDao dao) {
ShortagesEntity entity = new ShortagesEntity("1")
entity.id = 1L
entity.version = 1L
Mockito.doReturn([entity]).when(dao).findAll()
return dao
}
}

View File

@@ -26,7 +26,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
/**
* @author Marcin Grzejszczak
*/
@SpringBootTest(webEnvironment = MOCK, classes = ShortagesDaoTest.Config)
@SpringBootTest(webEnvironment = MOCK, classes = Config)
@AutoConfigureMockMvc
// would love to get rid of this
@AutoConfigureTestDatabase
@@ -38,35 +38,11 @@ class ShortagesDaoTest extends Specification {
def "should find ref by no"() {
given:
ShortagesEntity entity = new ShortagesEntity("1")
entity.id = 1L
entity.version = 1L
Mockito.doReturn([entity]).when(shortagesDao).findAll()
Config.defaultStubbing(shortagesDao)
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
}
}
}
}
}