15
15
*/
16
16
package org .springframework .data .jdbc .core ;
17
17
18
- import static java .util .Collections .*;
19
- import static org .assertj .core .api .Assertions .*;
20
-
21
- import lombok .Value ;
22
- import lombok .experimental .Wither ;
18
+ import static java .util .Collections .singletonList ;
19
+ import static org .assertj .core .api .Assertions .assertThat ;
20
+ import static org .assertj .core .api .Assertions .tuple ;
23
21
24
22
import org .assertj .core .api .SoftAssertions ;
23
+ import org .junit .Assume ;
25
24
import org .junit .ClassRule ;
26
25
import org .junit .Rule ;
27
26
import org .junit .Test ;
31
30
import org .springframework .context .annotation .Configuration ;
32
31
import org .springframework .context .annotation .Import ;
33
32
import org .springframework .data .annotation .Id ;
33
+ import org .springframework .data .jdbc .testing .DatabaseProfileValueSource ;
34
34
import org .springframework .data .jdbc .testing .TestConfiguration ;
35
35
import org .springframework .data .relational .core .conversion .RelationalConverter ;
36
36
import org .springframework .data .relational .core .mapping .RelationalMappingContext ;
37
+ import org .springframework .test .annotation .ProfileValueSourceConfiguration ;
38
+ import org .springframework .test .annotation .ProfileValueUtils ;
37
39
import org .springframework .test .context .ContextConfiguration ;
38
40
import org .springframework .test .context .junit4 .rules .SpringClassRule ;
39
41
import org .springframework .test .context .junit4 .rules .SpringMethodRule ;
40
42
import org .springframework .transaction .annotation .Transactional ;
41
43
44
+ import lombok .Value ;
45
+ import lombok .experimental .Wither ;
46
+
42
47
/**
43
48
* Integration tests for {@link JdbcAggregateTemplate} and it's handling of immutable entities.
44
49
*
45
50
* @author Jens Schauder
46
51
*/
47
52
@ ContextConfiguration
48
53
@ Transactional
54
+ @ ProfileValueSourceConfiguration (DatabaseProfileValueSource .class )
49
55
public class ImmutableAggregateTemplateHsqlIntegrationTests {
50
56
51
57
@ ClassRule public static final SpringClassRule classRule = new SpringClassRule ();
@@ -55,6 +61,8 @@ public class ImmutableAggregateTemplateHsqlIntegrationTests {
55
61
@ Test // DATAJDBC-241
56
62
public void saveWithGeneratedIdCreatesNewInstance () {
57
63
64
+ preamble ();
65
+
58
66
LegoSet legoSet = createLegoSet (createManual ());
59
67
60
68
LegoSet saved = template .save (legoSet );
@@ -75,6 +83,8 @@ public void saveWithGeneratedIdCreatesNewInstance() {
75
83
@ Test // DATAJDBC-241
76
84
public void saveAndLoadAnEntityWithReferencedEntityById () {
77
85
86
+ preamble ();
87
+
78
88
LegoSet saved = template .save (createLegoSet (createManual ()));
79
89
80
90
assertThat (saved .manual .id ).describedAs ("id of stored manual" ).isNotNull ();
@@ -96,6 +106,8 @@ public void saveAndLoadAnEntityWithReferencedEntityById() {
96
106
@ Test // DATAJDBC-241
97
107
public void saveAndLoadManyEntitiesWithReferencedEntity () {
98
108
109
+ preamble ();
110
+
99
111
LegoSet legoSet = createLegoSet (createManual ());
100
112
101
113
LegoSet savedLegoSet = template .save (legoSet );
@@ -109,6 +121,8 @@ public void saveAndLoadManyEntitiesWithReferencedEntity() {
109
121
@ Test // DATAJDBC-241
110
122
public void saveAndLoadManyEntitiesByIdWithReferencedEntity () {
111
123
124
+ preamble ();
125
+
112
126
LegoSet saved = template .save (createLegoSet (createManual ()));
113
127
114
128
Iterable <LegoSet > reloadedLegoSets = template .findAllById (singletonList (saved .getId ()), LegoSet .class );
@@ -120,6 +134,8 @@ public void saveAndLoadManyEntitiesByIdWithReferencedEntity() {
120
134
@ Test // DATAJDBC-241
121
135
public void saveAndLoadAnEntityWithReferencedNullEntity () {
122
136
137
+ preamble ();
138
+
123
139
LegoSet saved = template .save (createLegoSet (null ));
124
140
125
141
LegoSet reloadedLegoSet = template .findById (saved .getId (), LegoSet .class );
@@ -130,6 +146,8 @@ public void saveAndLoadAnEntityWithReferencedNullEntity() {
130
146
@ Test // DATAJDBC-241
131
147
public void saveAndDeleteAnEntityWithReferencedEntity () {
132
148
149
+ preamble ();
150
+
133
151
LegoSet legoSet = createLegoSet (createManual ());
134
152
135
153
LegoSet saved = template .save (legoSet );
@@ -147,6 +165,8 @@ public void saveAndDeleteAnEntityWithReferencedEntity() {
147
165
@ Test // DATAJDBC-241
148
166
public void saveAndDeleteAllWithReferencedEntity () {
149
167
168
+ preamble ();
169
+
150
170
template .save (createLegoSet (createManual ()));
151
171
152
172
template .deleteAll (LegoSet .class );
@@ -162,6 +182,8 @@ public void saveAndDeleteAllWithReferencedEntity() {
162
182
@ Test // DATAJDBC-241
163
183
public void updateReferencedEntityFromNull () {
164
184
185
+ preamble ();
186
+
165
187
LegoSet saved = template .save (createLegoSet (null ));
166
188
167
189
LegoSet changedLegoSet = new LegoSet (saved .id , saved .name , new Manual (23L , "Some content" ));
@@ -176,6 +198,8 @@ public void updateReferencedEntityFromNull() {
176
198
@ Test // DATAJDBC-241
177
199
public void updateReferencedEntityToNull () {
178
200
201
+ preamble ();
202
+
179
203
LegoSet saved = template .save (createLegoSet (null ));
180
204
181
205
LegoSet changedLegoSet = new LegoSet (saved .id , saved .name , null );
@@ -195,6 +219,8 @@ public void updateReferencedEntityToNull() {
195
219
@ Test // DATAJDBC-241
196
220
public void replaceReferencedEntity () {
197
221
222
+ preamble ();
223
+
198
224
LegoSet saved = template .save (createLegoSet (null ));
199
225
200
226
LegoSet changedLegoSet = new LegoSet (saved .id , saved .name , new Manual (null , "other content" ));
@@ -214,6 +240,8 @@ public void replaceReferencedEntity() {
214
240
@ Test // DATAJDBC-241
215
241
public void changeReferencedEntity () {
216
242
243
+ preamble ();
244
+
217
245
LegoSet saved = template .save (createLegoSet (createManual ()));
218
246
219
247
LegoSet changedLegoSet = saved .withManual (saved .manual .withContent ("new content" ));
@@ -227,6 +255,19 @@ public void changeReferencedEntity() {
227
255
assertThat (manual .content ).isEqualTo ("new content" );
228
256
}
229
257
258
+ private static void preamble () {
259
+
260
+ // Skip tests if the active DB is not the HSQL database
261
+ assume ("hsqldb" );
262
+ }
263
+
264
+ private static void assume (String dbProfileName ) {
265
+
266
+ Assume .assumeTrue ("true"
267
+ .equalsIgnoreCase (ProfileValueUtils .retrieveProfileValueSource (ImmutableAggregateTemplateHsqlIntegrationTests .class )
268
+ .get ("current.database.is." + dbProfileName )));
269
+ }
270
+
230
271
private static LegoSet createLegoSet (Manual manual ) {
231
272
232
273
return new LegoSet (null , "Star Destroyer" , manual );
0 commit comments