|
1 | 1 | /* |
2 | | - * Copyright 2016 the original author or authors. |
| 2 | + * Copyright 2020 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
31 | 31 | * <p> |
32 | 32 | * This annotation may be used as a <em>meta-annotation</em> to create custom <em>composed annotations</em>. |
33 | 33 | * |
34 | | - * @see io.zonky.test.db.postgres.EmbeddedPostgresContextCustomizerFactory |
35 | | - * @see io.zonky.test.db.flyway.OptimizedFlywayTestExecutionListener |
| 34 | + * @see EmbeddedDatabaseContextCustomizerFactory |
36 | 35 | */ |
37 | 36 | @Documented |
38 | 37 | @Inherited |
|
42 | 41 | public @interface AutoConfigureEmbeddedDatabase { |
43 | 42 |
|
44 | 43 | /** |
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. |
48 | 45 | * |
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 |
50 | 49 | */ |
51 | 50 | String beanName() default ""; |
52 | 51 |
|
53 | 52 | /** |
54 | | - * Determines what type of existing DataSource beans can be replaced. |
| 53 | + * Determines the refresh mode of the embedded database. |
55 | 54 | * |
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 |
57 | 62 | */ |
58 | | - Replace replace() default Replace.ANY; |
| 63 | + RefreshMode refresh() default RefreshMode.NEVER; |
59 | 64 |
|
60 | 65 | /** |
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. |
63 | 68 | * |
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 |
65 | 72 | */ |
66 | | - EmbeddedDatabaseType type() default EmbeddedDatabaseType.POSTGRES; |
| 73 | + DatabaseType type() default DatabaseType.AUTO; |
67 | 74 |
|
68 | 75 | /** |
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. |
73 | 79 | * |
74 | | - * @return the provider of an embedded database |
| 80 | + * @return the provider to create the embedded database |
75 | 81 | */ |
76 | 82 | DatabaseProvider provider() default DatabaseProvider.DEFAULT; |
77 | 83 |
|
78 | 84 | /** |
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 |
80 | 90 | */ |
81 | | - enum Replace { |
| 91 | + Replace replace() default Replace.ANY; |
| 92 | + |
| 93 | + /** |
| 94 | + * The supported refresh modes. |
| 95 | + */ |
| 96 | + enum RefreshMode { |
82 | 97 |
|
83 | 98 | /** |
84 | | - * Replace any DataSource bean (auto-configured or manually defined). |
| 99 | + * The database will not be reset at all. |
85 | 100 | */ |
86 | | - ANY, |
| 101 | + NEVER, |
87 | 102 |
|
88 | 103 | /** |
89 | | - * Don't replace the application default DataSource. |
| 104 | + * The database will be reset to its initial state before the test class. |
90 | 105 | */ |
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 |
92 | 122 |
|
93 | 123 | } |
94 | 124 |
|
95 | 125 | /** |
96 | 126 | * The supported types of embedded databases. |
97 | 127 | */ |
98 | | - enum EmbeddedDatabaseType { |
| 128 | + enum DatabaseType { |
| 129 | + |
| 130 | + /** |
| 131 | + * Database is detected automatically based on the classpath. |
| 132 | + */ |
| 133 | + AUTO, |
99 | 134 |
|
100 | 135 | /** |
101 | 136 | * PostgreSQL Database |
102 | 137 | */ |
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 |
104 | 154 |
|
105 | 155 | } |
106 | 156 |
|
107 | 157 | /** |
108 | | - * The supported providers of embedded databases. |
| 158 | + * The supported providers for creating embedded databases. |
109 | 159 | */ |
110 | 160 | enum DatabaseProvider { |
111 | 161 |
|
112 | 162 | /** |
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. |
115 | 165 | */ |
116 | 166 | DEFAULT, |
117 | 167 |
|
118 | 168 | /** |
119 | | - * Run the embedded database in a Docker container. |
| 169 | + * Run the embedded database in Docker as a container. |
120 | 170 | */ |
121 | 171 | DOCKER, |
122 | 172 |
|
123 | 173 | /** |
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>). |
125 | 176 | */ |
126 | 177 | ZONKY, |
127 | 178 |
|
128 | 179 | /** |
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>). |
130 | 182 | */ |
131 | 183 | OPENTABLE, |
132 | 184 |
|
133 | 185 | /** |
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>). |
135 | 188 | */ |
136 | 189 | YANDEX, |
137 | 190 |
|
138 | 191 | } |
| 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 | + } |
139 | 209 | } |
0 commit comments