integration test hooked to build

This commit is contained in:
Michał Michaluk
2018-03-11 15:26:59 +01:00
parent 179793cc43
commit e579cffbac
8 changed files with 58 additions and 23 deletions

View File

@@ -28,6 +28,11 @@
<artifactId>jackson-datatype-jsr310</artifactId> <artifactId>jackson-datatype-jsr310</artifactId>
<version>2.8.5</version> <version>2.8.5</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<properties> <properties>

View File

@@ -0,0 +1,18 @@
package pl.com.bottega.tools;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.annotation.AliasFor;
import org.springframework.test.context.ActiveProfiles;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@SpringBootTest
@ActiveProfiles
public @interface IntegrationTest {
@AliasFor(annotation = ActiveProfiles.class, attribute = "profiles") String[] activeProfiles() default {"test"};
}

View File

@@ -131,6 +131,29 @@
</compilerArgs> </compilerArgs>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<useFile>false</useFile>
<includes>
<include>**/*Spec.java</include>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>

View File

@@ -1,4 +1,4 @@
package src.test.pl.com.bottega.factory package pl.com.bottega.factory
import pl.com.bottega.factory.demand.forecasting.Demand import pl.com.bottega.factory.demand.forecasting.Demand
import pl.com.bottega.factory.demand.forecasting.Document import pl.com.bottega.factory.demand.forecasting.Document
@@ -13,7 +13,6 @@ import java.time.ZoneOffset
trait ProductTrait { trait ProductTrait {
DocumentEntity documentFor(String refNo, LocalDate date, long ... levels) { DocumentEntity documentFor(String refNo, LocalDate date, long ... levels) {
Document document = document(refNo, date, levels) Document document = document(refNo, date, levels)
return new DocumentEntity("uri", "storedUri", document) return new DocumentEntity("uri", "storedUri", document)

View File

@@ -1,4 +1,4 @@
package src.test.pl.com.bottega.factory.integration package pl.com.bottega.factory.integration
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest import org.springframework.boot.test.context.SpringBootTest
@@ -10,11 +10,12 @@ import org.springframework.hateoas.Resources
import org.springframework.http.HttpMethod import org.springframework.http.HttpMethod
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import pl.com.bottega.factory.AppConfiguration import pl.com.bottega.factory.AppConfiguration
import pl.com.bottega.factory.ProductTrait
import pl.com.bottega.factory.demand.forecasting.persistence.DocumentEntity import pl.com.bottega.factory.demand.forecasting.persistence.DocumentEntity
import pl.com.bottega.factory.demand.forecasting.projection.CurrentDemandEntity import pl.com.bottega.factory.demand.forecasting.projection.CurrentDemandEntity
import pl.com.bottega.factory.product.management.ProductDescriptionEntity import pl.com.bottega.factory.product.management.ProductDescriptionEntity
import pl.com.bottega.tools.IntegrationTest
import spock.lang.Specification import spock.lang.Specification
import src.test.pl.com.bottega.factory.ProductTrait
import java.time.Clock import java.time.Clock
import java.time.LocalDate import java.time.LocalDate
@@ -23,11 +24,12 @@ import java.time.ZoneId
import static java.time.Instant.from import static java.time.Instant.from
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
@IntegrationTest
@SpringBootTest(webEnvironment = RANDOM_PORT, classes = AppConfiguration) @SpringBootTest(webEnvironment = RANDOM_PORT, classes = AppConfiguration)
class CallOffDocumentIntegrationSpec extends Specification implements ProductTrait { class CallOffDocumentIntegrationSpec extends Specification implements ProductTrait {
public static final String PRODUCT_REF_NO = "refNum" public static final String PRODUCT_REF_NO = "3009000"
public static final LocalDate ANY_DATE = LocalDate.of(2019, 1, 1) public static final LocalDate ANY_DATE = LocalDate.now()
@Autowired TestRestTemplate restTemplate @Autowired TestRestTemplate restTemplate
@@ -44,7 +46,6 @@ class CallOffDocumentIntegrationSpec extends Specification implements ProductTra
thereIsDemand(demands, ANY_DATE, 100) thereIsDemand(demands, ANY_DATE, 100)
thereIsDemand(demands, ANY_DATE.plusDays(1), 200) thereIsDemand(demands, ANY_DATE.plusDays(1), 200)
thereIsDemand(demands, ANY_DATE.plusDays(2), 300) thereIsDemand(demands, ANY_DATE.plusDays(2), 300)
} }
void productDescriptionIsSuccessfullyCreated(String refNo) { void productDescriptionIsSuccessfullyCreated(String refNo) {
@@ -65,10 +66,9 @@ class CallOffDocumentIntegrationSpec extends Specification implements ProductTra
HttpMethod.GET, HttpMethod.GET,
null, null,
new ParameterizedTypeReference<Resources<CurrentDemandEntity>>() {}, new ParameterizedTypeReference<Resources<CurrentDemandEntity>>() {},
["refNo": refNo, "date" : date]) ["refNo": refNo, "date": date])
assert res.statusCode.is2xxSuccessful() assert res.statusCode.is2xxSuccessful()
return res.getBody().getContent() return res.getBody().getContent()
} }
void thereIsDemand(Collection<CurrentDemandEntity> demands, LocalDate date, long expectedLevel) { void thereIsDemand(Collection<CurrentDemandEntity> demands, LocalDate date, long expectedLevel) {
@@ -81,9 +81,6 @@ class CallOffDocumentIntegrationSpec extends Specification implements ProductTra
@Bean @Bean
Clock clock() { Clock clock() {
return Clock.fixed(from(ANY_DATE), ZoneId.systemDefault()) return Clock.fixed(from(ANY_DATE), ZoneId.systemDefault())
} }
} }
} }

View File

@@ -0,0 +1,4 @@
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=sa
spring.datasource.driver-class-name=org.h2.Driver

View File

@@ -1,10 +0,0 @@
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
spring.datasource.username=sa
spring.datasource.password=sa
spring.main.banner-mode=off
spring.jpa.database=default
spring.jpa.generate-ddl=false
liquibase.change-log=classpath:/schema/db.changelog.xml

View File

@@ -27,4 +27,3 @@ public class Document {
return refNo; return refNo;
} }
} }