Skip to content

Commit 567b96f

Browse files
FlorianFlorianGWE
authored andcommitted
#92 provide a sping-boot test with explizit initialization
1 parent 5e4b63d commit 567b96f

File tree

12 files changed

+692
-0
lines changed

12 files changed

+692
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (C) 2011-2020 the original author or authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<groupId>org.flywaydb.flyway-test-extensions.samples</groupId>
26+
<artifactId>flyway-test-samples-parent</artifactId>
27+
<version>7.0.0-SNAPSHOT</version>
28+
<relativePath>../../../flyway-test-samples-parent/pom.xml</relativePath>
29+
</parent>
30+
31+
<artifactId>flyway-test-sample-spring-boot-2-ext</artifactId>
32+
<name>Sample Flyway-Test-Extension Spring Boot 2 with Flyway Migration initializer</name>
33+
<description>Sample Flyway-Test-Extension with Spring Boot 2.x</description>
34+
<properties>
35+
<spring.boot.version>2.3.4.RELEASE</spring.boot.version>
36+
<spring.version>5.2.7.RELEASE</spring.version>
37+
</properties>
38+
<dependencies>
39+
40+
<dependency>
41+
<groupId>org.flywaydb.flyway-test-extensions</groupId>
42+
<artifactId>flyway-spring-test</artifactId>
43+
<version>7.0.0-SNAPSHOT</version>
44+
<scope>test</scope>
45+
<exclusions>
46+
<exclusion>
47+
<groupId>org.springframework</groupId>
48+
<artifactId>spring-test</artifactId>
49+
</exclusion>
50+
</exclusions>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.springframework</groupId>
55+
<artifactId>spring-core</artifactId>
56+
<version>${spring.version}</version>
57+
<exclusions>
58+
<exclusion>
59+
<artifactId>commons-logging</artifactId>
60+
<groupId>commons-logging</groupId>
61+
</exclusion>
62+
</exclusions>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.springframework</groupId>
66+
<artifactId>spring-context</artifactId>
67+
<version>${spring.version}</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.springframework</groupId>
71+
<artifactId>spring-orm</artifactId>
72+
<version>${spring.version}</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.springframework</groupId>
76+
<artifactId>spring-test</artifactId>
77+
<version>${spring.version}</version>
78+
</dependency>
79+
80+
<dependency>
81+
<groupId>org.springframework.boot</groupId>
82+
<artifactId>spring-boot-starter-log4j2</artifactId>
83+
<version>${spring.boot.version}</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.springframework.boot</groupId>
87+
<artifactId>spring-boot-starter-data-jpa</artifactId>
88+
<version>${spring.boot.version}</version>
89+
<exclusions>
90+
<exclusion>
91+
<groupId>org.springframework</groupId>
92+
<artifactId>spring-aspects</artifactId>
93+
</exclusion>
94+
<exclusion>
95+
<groupId>ch.qos.logback</groupId>
96+
<artifactId>logback-classic</artifactId>
97+
</exclusion>
98+
</exclusions>
99+
</dependency>
100+
101+
<dependency>
102+
<groupId>org.flywaydb</groupId>
103+
<artifactId>flyway-core</artifactId>
104+
<scope>provided</scope>
105+
</dependency>
106+
<dependency>
107+
<groupId>org.hsqldb</groupId>
108+
<artifactId>hsqldb</artifactId>
109+
<version>2.4.1</version>
110+
<scope>runtime</scope>
111+
</dependency>
112+
<dependency>
113+
<groupId>org.springframework.boot</groupId>
114+
<artifactId>spring-boot-starter-test</artifactId>
115+
<version>${spring.boot.version}</version>
116+
<scope>test</scope>
117+
<exclusions>
118+
<exclusion>
119+
<groupId>org.springframework</groupId>
120+
<artifactId>spring-test</artifactId>
121+
</exclusion>
122+
<exclusion>
123+
<groupId>org.springframework.boot</groupId>
124+
<artifactId>spring-boot-starter-logging</artifactId>
125+
</exclusion>
126+
</exclusions>
127+
128+
</dependency>
129+
</dependencies>
130+
<build>
131+
<plugins>
132+
<plugin>
133+
<groupId>org.springframework.boot</groupId>
134+
<artifactId>spring-boot-maven-plugin</artifactId>
135+
<version>${spring.boot.version}</version>
136+
</plugin>
137+
138+
<plugin>
139+
<groupId>org.apache.maven.plugins</groupId>
140+
<artifactId>maven-surefire-plugin</artifactId>
141+
<configuration>
142+
<includes>
143+
<include>**/*Tests.java</include>
144+
</includes>
145+
<excludes>
146+
<exclude>**/Abstract*.java</exclude>
147+
</excludes>
148+
<systemPropertyVariables>
149+
<java.security.egd>file:/dev/./urandom</java.security.egd>
150+
<java.awt.headless>true</java.awt.headless>
151+
</systemPropertyVariables>
152+
</configuration>
153+
</plugin>
154+
</plugins>
155+
</build>
156+
157+
<profiles>
158+
<profile>
159+
<id>default</id>
160+
<activation>
161+
<activeByDefault>true</activeByDefault>
162+
</activation>
163+
<repositories>
164+
<!-- Repositories to allow snapshot and milestone BOM imports during
165+
development. This section is stripped out when a full release is prepared. -->
166+
<repository>
167+
<id>spring-milestones</id>
168+
<name>Spring Milestones</name>
169+
<url>https://repo.spring.io/milestone</url>
170+
<snapshots>
171+
<enabled>false</enabled>
172+
</snapshots>
173+
</repository>
174+
<repository>
175+
<id>spring-snapshots</id>
176+
<name>Spring Snapshots</name>
177+
<url>https://repo.spring.io/snapshot</url>
178+
<snapshots>
179+
<enabled>true</enabled>
180+
</snapshots>
181+
</repository>
182+
</repositories>
183+
</profile>
184+
<profile>
185+
<id>integration-test</id>
186+
</profile>
187+
</profiles>
188+
189+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.flywaydb.sample.test.spring.boot2ext;
2+
3+
import org.flywaydb.core.Flyway;
4+
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
5+
6+
public class FlywayMigrationStrategyHandler implements FlywayMigrationStrategy {
7+
@Override
8+
public void migrate(Flyway flyway) {
9+
flyway.migrate();
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* Copyright (C) 2011-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.flywaydb.sample.test.spring.boot2ext;
17+
18+
import javax.persistence.Entity;
19+
import javax.persistence.GeneratedValue;
20+
import javax.persistence.Id;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.boot.CommandLineRunner;
24+
import org.springframework.boot.SpringApplication;
25+
import org.springframework.boot.autoconfigure.SpringBootApplication;
26+
import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy;
27+
import org.springframework.data.repository.CrudRepository;
28+
import org.springframework.stereotype.Repository;
29+
import org.springframework.context.annotation.Bean;
30+
31+
@SpringBootApplication
32+
public class SampleFlywayApplication implements CommandLineRunner {
33+
34+
@Autowired
35+
private PersonRepository repository;
36+
37+
@Override
38+
public void run(String... args) throws Exception {
39+
System.err.println(this.repository.findAll());
40+
}
41+
42+
public static void main(String[] args) throws Exception {
43+
SpringApplication.run(SampleFlywayApplication.class, args);
44+
}
45+
@Bean
46+
public FlywayMigrationStrategy flywayMigrationStrategy() {
47+
return new FlywayMigrationStrategyHandler();
48+
}
49+
}
50+
51+
@Repository
52+
interface PersonRepository extends CrudRepository<Person, Long> {
53+
54+
}
55+
56+
@Entity
57+
class Person {
58+
@Id
59+
@GeneratedValue
60+
private Long id;
61+
private String firstName;
62+
private String lastName;
63+
64+
public String getFirstName() {
65+
return this.firstName;
66+
}
67+
68+
public void setFirstName(String firstName) {
69+
this.firstName = firstName;
70+
}
71+
72+
public String getLastName() {
73+
return this.lastName;
74+
}
75+
76+
public void setLastName(String lastname) {
77+
this.lastName = lastname;
78+
}
79+
80+
@Override
81+
public String toString() {
82+
return "Person [firstName=" + this.firstName + ", lastName=" + this.lastName
83+
+ "]";
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Copyright (C) 2011-2020 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
spring.jpa.hibernate.ddl-auto: none
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--
2+
-- Copyright (C) 2011-2020 the original author or authors.
3+
--
4+
-- Licensed under the Apache License, Version 2.0 (the "License");
5+
-- you may not use this file except in compliance with the License.
6+
-- You may obtain a copy of the License at
7+
--
8+
-- http://www.apache.org/licenses/LICENSE-2.0
9+
--
10+
-- Unless required by applicable law or agreed to in writing, software
11+
-- distributed under the License is distributed on an "AS IS" BASIS,
12+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
-- See the License for the specific language governing permissions and
14+
-- limitations under the License.
15+
--
16+
17+
CREATE TABLE PERSON (
18+
id BIGINT GENERATED BY DEFAULT AS IDENTITY ,
19+
first_name varchar(255) not null,
20+
last_name varchar(255) not null
21+
);
22+
23+
insert into PERSON (first_name, last_name) values ('Dave', 'Syer');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright (C) 2011-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.flywaydb.sample.test.spring.boot2ext;
17+
18+
import org.junit.Test;
19+
import org.junit.runner.RunWith;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
import org.springframework.boot.test.context.SpringBootTest;
22+
import org.springframework.jdbc.core.JdbcTemplate;
23+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
24+
25+
import static org.hamcrest.CoreMatchers.is;
26+
import static org.hamcrest.MatcherAssert.assertThat;
27+
28+
@RunWith(SpringJUnit4ClassRunner.class)
29+
@SpringBootTest(classes = SampleFlywayApplication.class)
30+
public class SampleFlywayApplicationTests {
31+
32+
@Autowired
33+
private JdbcTemplate template;
34+
35+
@Test
36+
public void testDefaultSettings() throws Exception {
37+
assertThat(template.queryForObject(
38+
"SELECT COUNT(*) from PERSON", Integer.class),
39+
is(3));
40+
}
41+
42+
}

0 commit comments

Comments
 (0)