Skip to content

Commit 055baaf

Browse files
committed
Polishing.
Make count assertions case-insensitive regarding the count column name. Add missing license headers. Support DatabaseContainer without a database name. See #230
1 parent b7a7c2c commit 055baaf

9 files changed

+54
-17
lines changed

src/test/java/org/springframework/data/r2dbc/connectionfactory/SingleConnectionConnectionFactoryUnitTests.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
*
3535
* @author Mark Paluch
3636
*/
37-
public class SingleConnectionConnectionFactoryUnitTests {
37+
class SingleConnectionConnectionFactoryUnitTests {
3838

3939
@Test // gh-204
40-
public void shouldAllocateSameConnection() {
40+
void shouldAllocateSameConnection() {
4141

4242
SingleConnectionConnectionFactory factory = new SingleConnectionConnectionFactory("r2dbc:h2:mem:///foo", false);
4343

@@ -52,7 +52,7 @@ public void shouldAllocateSameConnection() {
5252
}
5353

5454
@Test // gh-204
55-
public void shouldApplyAutoCommit() {
55+
void shouldApplyAutoCommit() {
5656

5757
SingleConnectionConnectionFactory factory = new SingleConnectionConnectionFactory("r2dbc:h2:mem:///foo", false);
5858
factory.setAutoCommit(false);
@@ -71,7 +71,7 @@ public void shouldApplyAutoCommit() {
7171
}
7272

7373
@Test // gh-204
74-
public void shouldSuppressClose() {
74+
void shouldSuppressClose() {
7575

7676
SingleConnectionConnectionFactory factory = new SingleConnectionConnectionFactory("r2dbc:h2:mem:///foo", true);
7777

@@ -87,7 +87,7 @@ public void shouldSuppressClose() {
8787
}
8888

8989
@Test // gh-204
90-
public void shouldNotSuppressClose() {
90+
void shouldNotSuppressClose() {
9191

9292
SingleConnectionConnectionFactory factory = new SingleConnectionConnectionFactory("r2dbc:h2:mem:///foo", false);
9393

@@ -101,7 +101,7 @@ public void shouldNotSuppressClose() {
101101
}
102102

103103
@Test // gh-204
104-
public void releaseConnectionShouldCloseUnrelatedConnection() {
104+
void releaseConnectionShouldCloseUnrelatedConnection() {
105105

106106
Connection connectionMock = mock(Connection.class);
107107
Connection otherConnection = mock(Connection.class);

src/test/java/org/springframework/data/r2dbc/dialect/PostgresDialectUnitTests.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2019-2021 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+
* https://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+
*/
116
package org.springframework.data.r2dbc.dialect;
217

318
import static org.assertj.core.api.Assertions.*;

src/test/java/org/springframework/data/r2dbc/dialect/SqlServerDialectUnitTests.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2019-2021 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+
* https://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+
*/
116
package org.springframework.data.r2dbc.dialect;
217

318
import static org.assertj.core.api.Assertions.*;

src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryIntegrationTests.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import reactor.test.StepVerifier;
2929

3030
import java.util.Arrays;
31-
import java.util.Collections;
3231
import java.util.Map;
3332
import java.util.stream.IntStream;
3433

@@ -214,7 +213,7 @@ void shouldDeleteUsingQueryMethod() {
214213
.verifyComplete();
215214

216215
Map<String, Object> count = jdbc.queryForMap("SELECT count(*) AS count FROM legoset");
217-
assertThat(count).hasEntrySatisfying("count", numberOf(1));
216+
assertThat(getCount(count)).satisfies(numberOf(1));
218217
}
219218

220219
@Test // gh-335
@@ -293,11 +292,13 @@ public void shouldInsertItemsTransactional() {
293292
Mono<Map<String, Object>> nonTransactional = repository.save(legoSet2) //
294293
.map(it -> jdbc.queryForMap("SELECT count(*) AS count FROM legoset"));
295294

296-
transactional.as(StepVerifier::create).expectNext(Collections.singletonMap("count", 0L)).verifyComplete();
297-
nonTransactional.as(StepVerifier::create).expectNext(Collections.singletonMap("count", 2L)).verifyComplete();
295+
transactional.as(StepVerifier::create).assertNext(actual -> assertThat(getCount(actual)).satisfies(numberOf(0)))
296+
.verifyComplete();
297+
nonTransactional.as(StepVerifier::create).assertNext(actual -> assertThat(getCount(actual)).satisfies(numberOf(2)))
298+
.verifyComplete();
298299

299-
Map<String, Object> count = jdbc.queryForMap("SELECT count(*) AS count FROM legoset");
300-
assertThat(count).hasEntrySatisfying("count", numberOf(2));
300+
Map<String, Object> map = jdbc.queryForMap("SELECT count(*) AS count FROM legoset");
301+
assertThat(getCount(map)).satisfies(numberOf(2));
301302
}
302303

303304
@Test // gh-363
@@ -353,6 +354,10 @@ void shouldDeleteAllAndReturnCount() {
353354
.verifyComplete();
354355
}
355356

357+
private static Object getCount(Map<String, Object> map) {
358+
return map.getOrDefault("count", map.get("COUNT"));
359+
}
360+
356361
private Condition<? super Object> numberOf(int expected) {
357362
return new Condition<>(it -> {
358363
return it instanceof Number && ((Number) it).intValue() == expected;

src/test/java/org/springframework/data/r2dbc/testing/ExternalDatabase.java

-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ public static ProvidedDatabaseBuilder builder(JdbcDatabaseContainer container) {
138138
.port(container.getFirstMappedPort()) //
139139
.username(container.getUsername()) //
140140
.password(container.getPassword()) //
141-
.database(container.getDatabaseName()) //
142141
.jdbcUrl(container.getJdbcUrl());
143142
}
144143

src/test/java/org/springframework/data/r2dbc/testing/H2TestSupport.java

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public static DataSource createDataSource() {
6969
dataSource.setUsername("sa");
7070
dataSource.setPassword("");
7171
dataSource.setUrl("jdbc:h2:mem:r2dbc;DB_CLOSE_DELAY=-1");
72+
dataSource.setDriverClassName("org.h2.Driver");
7273

7374
return dataSource;
7475
}

src/test/java/org/springframework/data/r2dbc/testing/MariaDbTestSupport.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private static ExternalDatabase getFirstWorkingDatabase(Supplier<ExternalDatabas
8585
}
8686

8787
/**
88-
* Returns a locally provided database at {@code postgres:@localhost:5432/postgres}.
88+
* Returns a locally provided database .
8989
*/
9090
private static ExternalDatabase local() {
9191

@@ -112,6 +112,7 @@ private static ExternalDatabase testContainer() {
112112

113113
testContainerDatabase = ProvidedDatabase.builder(container) //
114114
.username("root") //
115+
.database(container.getDatabaseName()) //
115116
.build();
116117
} catch (IllegalStateException ise) {
117118
// docker not available.

src/test/java/org/springframework/data/r2dbc/testing/MySqlTestSupport.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class MySqlTestSupport {
5757
+ ") ENGINE=InnoDB;";
5858

5959
/**
60-
* Returns a database either hosted locally at {@code postgres:@localhost:5432/postgres} or running inside Docker.
60+
* Returns a database either hosted locally or running inside Docker.
6161
*
6262
* @return information about the database. Guaranteed to be not {@literal null}.
6363
*/
@@ -88,7 +88,7 @@ private static ExternalDatabase getFirstWorkingDatabase(Supplier<ExternalDatabas
8888
}
8989

9090
/**
91-
* Returns a locally provided database at {@code postgres:@localhost:5432/postgres}.
91+
* Returns a locally provided database.
9292
*/
9393
private static ExternalDatabase local() {
9494

@@ -114,6 +114,7 @@ private static ExternalDatabase testContainer() {
114114
container.start();
115115

116116
testContainerDatabase = ProvidedDatabase.builder(container) //
117+
.database(container.getDatabaseName()) //
117118
.username("root") //
118119
.build();
119120
} catch (IllegalStateException ise) {

src/test/java/org/springframework/data/r2dbc/testing/PostgresTestSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static ExternalDatabase testContainer() {
9898
PostgreSQLContainer.IMAGE + ":" + PostgreSQLContainer.DEFAULT_TAG);
9999
container.start();
100100

101-
testContainerDatabase = ProvidedDatabase.from(container);
101+
testContainerDatabase = ProvidedDatabase.builder(container).database(container.getDatabaseName()).build();
102102

103103
} catch (IllegalStateException ise) {
104104
// docker not available.

0 commit comments

Comments
 (0)