Skip to content

Commit 5f5866a

Browse files
committed
DATAJDBC-346: Fixed test failures when using MSSQL database
1 parent 913238a commit 5f5866a

File tree

21 files changed

+194
-8
lines changed

21 files changed

+194
-8
lines changed

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/ImmutableAggregateTemplateHsqlIntegrationTests.java

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
*/
1616
package org.springframework.data.jdbc.core;
1717

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;
2321

2422
import org.assertj.core.api.SoftAssertions;
23+
import org.junit.Assume;
2524
import org.junit.ClassRule;
2625
import org.junit.Rule;
2726
import org.junit.Test;
@@ -31,21 +30,28 @@
3130
import org.springframework.context.annotation.Configuration;
3231
import org.springframework.context.annotation.Import;
3332
import org.springframework.data.annotation.Id;
33+
import org.springframework.data.jdbc.testing.DatabaseProfileValueSource;
3434
import org.springframework.data.jdbc.testing.TestConfiguration;
3535
import org.springframework.data.relational.core.conversion.RelationalConverter;
3636
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
37+
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
38+
import org.springframework.test.annotation.ProfileValueUtils;
3739
import org.springframework.test.context.ContextConfiguration;
3840
import org.springframework.test.context.junit4.rules.SpringClassRule;
3941
import org.springframework.test.context.junit4.rules.SpringMethodRule;
4042
import org.springframework.transaction.annotation.Transactional;
4143

44+
import lombok.Value;
45+
import lombok.experimental.Wither;
46+
4247
/**
4348
* Integration tests for {@link JdbcAggregateTemplate} and it's handling of immutable entities.
4449
*
4550
* @author Jens Schauder
4651
*/
4752
@ContextConfiguration
4853
@Transactional
54+
@ProfileValueSourceConfiguration(DatabaseProfileValueSource.class)
4955
public class ImmutableAggregateTemplateHsqlIntegrationTests {
5056

5157
@ClassRule public static final SpringClassRule classRule = new SpringClassRule();
@@ -55,6 +61,8 @@ public class ImmutableAggregateTemplateHsqlIntegrationTests {
5561
@Test // DATAJDBC-241
5662
public void saveWithGeneratedIdCreatesNewInstance() {
5763

64+
preamble();
65+
5866
LegoSet legoSet = createLegoSet(createManual());
5967

6068
LegoSet saved = template.save(legoSet);
@@ -75,6 +83,8 @@ public void saveWithGeneratedIdCreatesNewInstance() {
7583
@Test // DATAJDBC-241
7684
public void saveAndLoadAnEntityWithReferencedEntityById() {
7785

86+
preamble();
87+
7888
LegoSet saved = template.save(createLegoSet(createManual()));
7989

8090
assertThat(saved.manual.id).describedAs("id of stored manual").isNotNull();
@@ -96,6 +106,8 @@ public void saveAndLoadAnEntityWithReferencedEntityById() {
96106
@Test // DATAJDBC-241
97107
public void saveAndLoadManyEntitiesWithReferencedEntity() {
98108

109+
preamble();
110+
99111
LegoSet legoSet = createLegoSet(createManual());
100112

101113
LegoSet savedLegoSet = template.save(legoSet);
@@ -109,6 +121,8 @@ public void saveAndLoadManyEntitiesWithReferencedEntity() {
109121
@Test // DATAJDBC-241
110122
public void saveAndLoadManyEntitiesByIdWithReferencedEntity() {
111123

124+
preamble();
125+
112126
LegoSet saved = template.save(createLegoSet(createManual()));
113127

114128
Iterable<LegoSet> reloadedLegoSets = template.findAllById(singletonList(saved.getId()), LegoSet.class);
@@ -120,6 +134,8 @@ public void saveAndLoadManyEntitiesByIdWithReferencedEntity() {
120134
@Test // DATAJDBC-241
121135
public void saveAndLoadAnEntityWithReferencedNullEntity() {
122136

137+
preamble();
138+
123139
LegoSet saved = template.save(createLegoSet(null));
124140

125141
LegoSet reloadedLegoSet = template.findById(saved.getId(), LegoSet.class);
@@ -130,6 +146,8 @@ public void saveAndLoadAnEntityWithReferencedNullEntity() {
130146
@Test // DATAJDBC-241
131147
public void saveAndDeleteAnEntityWithReferencedEntity() {
132148

149+
preamble();
150+
133151
LegoSet legoSet = createLegoSet(createManual());
134152

135153
LegoSet saved = template.save(legoSet);
@@ -147,6 +165,8 @@ public void saveAndDeleteAnEntityWithReferencedEntity() {
147165
@Test // DATAJDBC-241
148166
public void saveAndDeleteAllWithReferencedEntity() {
149167

168+
preamble();
169+
150170
template.save(createLegoSet(createManual()));
151171

152172
template.deleteAll(LegoSet.class);
@@ -162,6 +182,8 @@ public void saveAndDeleteAllWithReferencedEntity() {
162182
@Test // DATAJDBC-241
163183
public void updateReferencedEntityFromNull() {
164184

185+
preamble();
186+
165187
LegoSet saved = template.save(createLegoSet(null));
166188

167189
LegoSet changedLegoSet = new LegoSet(saved.id, saved.name, new Manual(23L, "Some content"));
@@ -176,6 +198,8 @@ public void updateReferencedEntityFromNull() {
176198
@Test // DATAJDBC-241
177199
public void updateReferencedEntityToNull() {
178200

201+
preamble();
202+
179203
LegoSet saved = template.save(createLegoSet(null));
180204

181205
LegoSet changedLegoSet = new LegoSet(saved.id, saved.name, null);
@@ -195,6 +219,8 @@ public void updateReferencedEntityToNull() {
195219
@Test // DATAJDBC-241
196220
public void replaceReferencedEntity() {
197221

222+
preamble();
223+
198224
LegoSet saved = template.save(createLegoSet(null));
199225

200226
LegoSet changedLegoSet = new LegoSet(saved.id, saved.name, new Manual(null, "other content"));
@@ -214,6 +240,8 @@ public void replaceReferencedEntity() {
214240
@Test // DATAJDBC-241
215241
public void changeReferencedEntity() {
216242

243+
preamble();
244+
217245
LegoSet saved = template.save(createLegoSet(createManual()));
218246

219247
LegoSet changedLegoSet = saved.withManual(saved.manual.withContent("new content"));
@@ -227,6 +255,19 @@ public void changeReferencedEntity() {
227255
assertThat(manual.content).isEqualTo("new content");
228256
}
229257

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+
230271
private static LegoSet createLegoSet(Manual manual) {
231272

232273
return new LegoSet(null, "Star Destroyer", manual);

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryCrossAggregateHsqlIntegrationTests.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
*/
1616
package org.springframework.data.jdbc.repository;
1717

18-
import static org.assertj.core.api.Assertions.*;
18+
import static org.assertj.core.api.Assertions.assertThat;
1919

20+
import org.junit.Assume;
2021
import org.junit.ClassRule;
2122
import org.junit.Rule;
2223
import org.junit.Test;
@@ -25,14 +26,18 @@
2526
import org.springframework.context.annotation.Configuration;
2627
import org.springframework.context.annotation.Import;
2728
import org.springframework.data.annotation.Id;
29+
import org.springframework.data.jdbc.core.ImmutableAggregateTemplateHsqlIntegrationTests;
2830
import org.springframework.data.jdbc.core.mapping.AggregateReference;
2931
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
3032
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
33+
import org.springframework.data.jdbc.testing.DatabaseProfileValueSource;
3134
import org.springframework.data.jdbc.testing.TestConfiguration;
3235
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
3336
import org.springframework.data.repository.CrudRepository;
3437
import org.springframework.jdbc.core.JdbcTemplate;
3538
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
39+
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
40+
import org.springframework.test.annotation.ProfileValueUtils;
3641
import org.springframework.test.context.ContextConfiguration;
3742
import org.springframework.test.context.junit4.rules.SpringClassRule;
3843
import org.springframework.test.context.junit4.rules.SpringMethodRule;
@@ -46,6 +51,7 @@
4651
*/
4752
@ContextConfiguration
4853
@Transactional
54+
@ProfileValueSourceConfiguration(DatabaseProfileValueSource.class)
4955
public class JdbcRepositoryCrossAggregateHsqlIntegrationTests {
5056

5157
private static final long TWO_ID = 23L;
@@ -74,6 +80,8 @@ Class<?> testClass() {
7480
@Test // DATAJDBC-221
7581
public void savesAndRead() {
7682

83+
preamble();
84+
7785
AggregateOne one = new AggregateOne();
7886
one.name = "Aggregate - 1";
7987
one.two = AggregateReference.to(TWO_ID);
@@ -87,6 +95,8 @@ public void savesAndRead() {
8795
@Test // DATAJDBC-221
8896
public void savesAndUpdate() {
8997

98+
preamble();
99+
90100
AggregateOne one = new AggregateOne();
91101
one.name = "Aggregate - 1";
92102
one.two = AggregateReference.to(42L);
@@ -104,6 +114,19 @@ public void savesAndUpdate() {
104114
).isEqualTo(1);
105115
}
106116

117+
private static void preamble() {
118+
119+
// Skip tests if the active DB is not the HSQL database
120+
assume("hsqldb");
121+
}
122+
123+
private static void assume(String dbProfileName) {
124+
125+
Assume.assumeTrue("true"
126+
.equalsIgnoreCase(ProfileValueUtils.retrieveProfileValueSource(ImmutableAggregateTemplateHsqlIntegrationTests.class)
127+
.get("current.database.is." + dbProfileName)));
128+
}
129+
107130
interface Ones extends CrudRepository<AggregateOne, Long> {}
108131

109132
static class AggregateOne {

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsAndManuallyAssignedIdHsqlIntegrationTests.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.Set;
2727
import java.util.concurrent.atomic.AtomicLong;
2828

29+
import org.junit.Assume;
2930
import org.junit.ClassRule;
3031
import org.junit.Rule;
3132
import org.junit.Test;
@@ -35,11 +36,15 @@
3536
import org.springframework.context.annotation.Configuration;
3637
import org.springframework.context.annotation.Import;
3738
import org.springframework.data.annotation.Id;
39+
import org.springframework.data.jdbc.core.ImmutableAggregateTemplateHsqlIntegrationTests;
3840
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
41+
import org.springframework.data.jdbc.testing.DatabaseProfileValueSource;
3942
import org.springframework.data.jdbc.testing.TestConfiguration;
4043
import org.springframework.data.relational.core.mapping.event.BeforeSaveEvent;
4144
import org.springframework.data.repository.CrudRepository;
4245
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
46+
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
47+
import org.springframework.test.annotation.ProfileValueUtils;
4348
import org.springframework.test.context.ContextConfiguration;
4449
import org.springframework.test.context.junit4.rules.SpringClassRule;
4550
import org.springframework.test.context.junit4.rules.SpringMethodRule;
@@ -52,6 +57,7 @@
5257
*/
5358
@ContextConfiguration
5459
@Transactional
60+
@ProfileValueSourceConfiguration(DatabaseProfileValueSource.class)
5561
public class JdbcRepositoryWithCollectionsAndManuallyAssignedIdHsqlIntegrationTests {
5662

5763
static AtomicLong id = new AtomicLong(0);
@@ -101,6 +107,8 @@ private void setIds(DummyEntity dummyEntity) {
101107
@Test // DATAJDBC-113
102108
public void saveAndLoadEmptySet() {
103109

110+
preamble();
111+
104112
DummyEntity entity = repository.save(createDummyEntity());
105113

106114
assertThat(entity.id).isNotNull();
@@ -115,6 +123,8 @@ public void saveAndLoadEmptySet() {
115123
@Test // DATAJDBC-113
116124
public void saveAndLoadNonEmptySet() {
117125

126+
preamble();
127+
118128
Element element1 = new Element();
119129
Element element2 = new Element();
120130

@@ -138,6 +148,8 @@ public void saveAndLoadNonEmptySet() {
138148
@Test // DATAJDBC-113
139149
public void findAllLoadsCollection() {
140150

151+
preamble();
152+
141153
Element element1 = new Element();
142154
Element element2 = new Element();
143155

@@ -160,6 +172,8 @@ public void findAllLoadsCollection() {
160172
@Test // DATAJDBC-113
161173
public void updateSet() {
162174

175+
preamble();
176+
163177
Element element1 = createElement("one");
164178
Element element2 = createElement("two");
165179
Element element3 = createElement("three");
@@ -197,6 +211,8 @@ public void updateSet() {
197211
@Test // DATAJDBC-113
198212
public void deletingWithSet() {
199213

214+
preamble();
215+
200216
Element element1 = createElement("one");
201217
Element element2 = createElement("two");
202218

@@ -221,6 +237,19 @@ private Element createElement(String content) {
221237
return element;
222238
}
223239

240+
private static void preamble() {
241+
242+
// Skip tests if the active DB is not the HSQL database
243+
assume("hsqldb");
244+
}
245+
246+
private static void assume(String dbProfileName) {
247+
248+
Assume.assumeTrue("true"
249+
.equalsIgnoreCase(ProfileValueUtils.retrieveProfileValueSource(ImmutableAggregateTemplateHsqlIntegrationTests.class)
250+
.get("current.database.is." + dbProfileName)));
251+
}
252+
224253
private static DummyEntity createDummyEntity() {
225254

226255
DummyEntity entity = new DummyEntity();

0 commit comments

Comments
 (0)