Skip to content

Commit eb6abde

Browse files
authored
Merge pull request #161 from zonkyio/2.0.x
2.0.0
2 parents 5eba4e0 + 8dac6f3 commit eb6abde

File tree

178 files changed

+13442
-3993
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+13442
-3993
lines changed

.github/workflows/gradle.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
runs-on: ubuntu-latest
77
strategy:
88
matrix:
9-
java: [8]
9+
java: [8, 11, 15]
1010
steps:
1111
- name: Checkout project
1212
uses: actions/checkout@v1
@@ -23,5 +23,10 @@ jobs:
2323
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
2424
restore-keys: |
2525
${{ runner.os }}-gradle-
26+
- name: Accept third party licence
27+
env:
28+
ACCEPT_LICENCE: ${{ secrets.ACCEPT_LICENCE }}
29+
if: env.ACCEPT_LICENCE == 'true'
30+
run: ./accept-third-party-license.sh
2631
- name: Build with Gradle
2732
run: ./gradlew build

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ build/
2525
hs_err_pid*
2626

2727
# Gradle wrapper files
28-
!gradle/wrapper/gradle-wrapper.jar
28+
!gradle/wrapper/gradle-wrapper.jar
29+
30+
# Prevent license accepting file to get accidentially commited to git
31+
container-license-acceptance.txt

README.md

Lines changed: 334 additions & 244 deletions
Large diffs are not rendered by default.

accept-third-party-license.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
{
4+
echo "mcr.microsoft.com/mssql/server:2019-latest"
5+
echo "mcr.microsoft.com/mssql/server:2017-latest"
6+
echo "mcr.microsoft.com/mssql/server:2017-CU20"
7+
} > embedded-database-spring-test/src/test/resources/container-license-acceptance.txt

build.gradle

Lines changed: 291 additions & 102 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# ContextCustomizerFactories for the Spring TestContext Framework
22
org.springframework.test.context.ContextCustomizerFactory = \
3-
io.zonky.test.db.postgres.EmbeddedPostgresContextCustomizerFactory
3+
io.zonky.test.db.EmbeddedDatabaseContextCustomizerFactory
44

55
# TestExecutionListeners for the Spring TestContext Framework
66
org.springframework.test.context.TestExecutionListener = \
7-
io.zonky.test.db.flyway.OptimizedFlywayTestExecutionListener
7+
io.zonky.test.db.EmbeddedDatabaseTestExecutionListener,\
8+
io.zonky.test.db.event.EventPublishingTestExecutionListener,\
9+
io.zonky.test.db.flyway.OptimizedFlywayTestExecutionListener
Lines changed: 104 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,8 +31,7 @@
3131
* <p>
3232
* This annotation may be used as a <em>meta-annotation</em> to create custom <em>composed annotations</em>.
3333
*
34-
* @see io.zonky.test.db.postgres.EmbeddedPostgresContextCustomizerFactory
35-
* @see io.zonky.test.db.flyway.OptimizedFlywayTestExecutionListener
34+
* @see EmbeddedDatabaseContextCustomizerFactory
3635
*/
3736
@Documented
3837
@Inherited
@@ -42,98 +41,169 @@
4241
public @interface AutoConfigureEmbeddedDatabase {
4342

4443
/**
45-
* The bean name to be used to identify the data source that will be replaced.
46-
* It is only necessary if there is no existing DataSource
47-
* or the context contains multiple DataSource beans.
44+
* The bean name to identify the data source to be associated with the embedded database.
4845
*
49-
* @return the name to identify the DataSource bean
46+
* <p>It is required only if the application context contains multiple DataSource beans.
47+
*
48+
* @return the bean name to identify the DataSource bean
5049
*/
5150
String beanName() default "";
5251

5352
/**
54-
* Determines what type of existing DataSource beans can be replaced.
53+
* Determines the refresh mode of the embedded database.
5554
*
56-
* @return the type of existing DataSource to replace
55+
* <p>This feature allows for reset the database to its initial state that existed before the test began.
56+
* It is based on the use of template databases and does not rely on the rollback of the current transaction,
57+
* so it is possible to save and commit data within the test without any consequences.
58+
*
59+
* <p>The refresh mode may also be configured via the {@code zonky.test.database.refresh} configuration property.
60+
*
61+
* @return the type of refresh mode to be used for database reset
5762
*/
58-
Replace replace() default Replace.ANY;
63+
RefreshMode refresh() default RefreshMode.NEVER;
5964

6065
/**
61-
* The type of an embedded database to be initialized
62-
* when {@link #replace() replacing} the data source.
66+
* The type of embedded database to be created when {@link #replace() replacing} the data source.
67+
* By default will attempt to detect the database type based on the classpath.
6368
*
64-
* @return the type of an embedded database
69+
* <p>The database type may also be configured via the {@code zonky.test.database.type} configuration property.
70+
*
71+
* @return the type of embedded database
6572
*/
66-
EmbeddedDatabaseType type() default EmbeddedDatabaseType.POSTGRES;
73+
DatabaseType type() default DatabaseType.AUTO;
6774

6875
/**
69-
* Provider used to create the underlying embedded database,
70-
* see the documentation for the comparision matrix.
71-
* Note that the provider can also be configured
72-
* through {@code zonky.test.database.provider} property.
76+
* Provider to be used to create the underlying embedded database, see the documentation for the comparison matrix.
77+
*
78+
* <p>The provider may also be configured via the {@code zonky.test.database.provider} configuration property.
7379
*
74-
* @return the provider of an embedded database
80+
* @return the provider to create the embedded database
7581
*/
7682
DatabaseProvider provider() default DatabaseProvider.DEFAULT;
7783

7884
/**
79-
* What the test database can replace.
85+
* Determines what type of existing DataSource beans can be replaced.
86+
*
87+
* <p>It may also be configured via the {@code zonky.test.database.replace} configuration property.
88+
*
89+
* @return the type of existing DataSource to replace
8090
*/
81-
enum Replace {
91+
Replace replace() default Replace.ANY;
92+
93+
/**
94+
* The supported refresh modes.
95+
*/
96+
enum RefreshMode {
8297

8398
/**
84-
* Replace any DataSource bean (auto-configured or manually defined).
99+
* The database will not be reset at all.
85100
*/
86-
ANY,
101+
NEVER,
87102

88103
/**
89-
* Don't replace the application default DataSource.
104+
* The database will be reset to its initial state before the test class.
90105
*/
91-
NONE
106+
BEFORE_CLASS,
107+
108+
/**
109+
* The database will be reset to its initial state before each test method in the class.
110+
*/
111+
BEFORE_EACH_TEST_METHOD,
112+
113+
/**
114+
* The database will be reset to its initial state after each test method in the class.
115+
*/
116+
AFTER_EACH_TEST_METHOD,
117+
118+
/**
119+
* The database will be reset to its initial state after the test class.
120+
*/
121+
AFTER_CLASS
92122

93123
}
94124

95125
/**
96126
* The supported types of embedded databases.
97127
*/
98-
enum EmbeddedDatabaseType {
128+
enum DatabaseType {
129+
130+
/**
131+
* Database is detected automatically based on the classpath.
132+
*/
133+
AUTO,
99134

100135
/**
101136
* PostgreSQL Database
102137
*/
103-
POSTGRES
138+
POSTGRES,
139+
140+
/**
141+
* Microsoft SQL Server
142+
*/
143+
MSSQL,
144+
145+
/**
146+
* MySQL Database
147+
*/
148+
MYSQL,
149+
150+
/**
151+
* MariaDB Database
152+
*/
153+
MARIADB
104154

105155
}
106156

107157
/**
108-
* The supported providers of embedded databases.
158+
* The supported providers for creating embedded databases.
109159
*/
110160
enum DatabaseProvider {
111161

112162
/**
113-
* Default typically equals to {@link #ZONKY} provider,
114-
* unless a different default has been configured by externalized configuration.
163+
* Default typically equals to {@link #DOCKER} provider,
164+
* unless a different default has been configured by configuration properties.
115165
*/
116166
DEFAULT,
117167

118168
/**
119-
* Run the embedded database in a Docker container.
169+
* Run the embedded database in Docker as a container.
120170
*/
121171
DOCKER,
122172

123173
/**
124-
* Use Zonky's fork of OpenTable Embedded PostgreSQL Component to create the embedded database (https://github.com/zonkyio/embedded-postgres).
174+
* Use Zonky's fork of OpenTable Embedded PostgreSQL Component to create the embedded database
175+
* (<a href="https://github.com/zonkyio/embedded-postgres">https://github.com/zonkyio/embedded-postgres</a>).
125176
*/
126177
ZONKY,
127178

128179
/**
129-
* Use OpenTable Embedded PostgreSQL Component to create the embedded database (https://github.com/opentable/otj-pg-embedded).
180+
* Use OpenTable Embedded PostgreSQL Component to create the embedded database
181+
* (<a href="https://github.com/opentable/otj-pg-embedded">https://github.com/opentable/otj-pg-embedded</a>).
130182
*/
131183
OPENTABLE,
132184

133185
/**
134-
* Use Yandex's Embedded PostgreSQL Server to create the embedded database (https://github.com/yandex-qatools/postgresql-embedded).
186+
* Use Yandex's Embedded PostgreSQL Server to create the embedded database
187+
* (<a href="https://github.com/yandex-qatools/postgresql-embedded">https://github.com/yandex-qatools/postgresql-embedded</a>).
135188
*/
136189
YANDEX,
137190

138191
}
192+
193+
/**
194+
* What the test database can replace.
195+
*/
196+
enum Replace {
197+
198+
/**
199+
* Replace any DataSource bean (auto-configured or manually defined).
200+
*/
201+
ANY,
202+
203+
/**
204+
* Don't replace the application default DataSource.
205+
*/
206+
NONE
207+
208+
}
139209
}

embedded-database-spring-test/src/main/java/io/zonky/test/db/AutoConfigureEmbeddedDatabases.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original author or authors.
2+
* Copyright 2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)