Polishing.
Make count assertions case-insensitive regarding the count column name. Add missing license headers. Support DatabaseContainer without a database name. See #230
This commit is contained in:
@@ -34,10 +34,10 @@ import org.junit.jupiter.api.Test;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class SingleConnectionConnectionFactoryUnitTests {
|
||||
class SingleConnectionConnectionFactoryUnitTests {
|
||||
|
||||
@Test // gh-204
|
||||
public void shouldAllocateSameConnection() {
|
||||
void shouldAllocateSameConnection() {
|
||||
|
||||
SingleConnectionConnectionFactory factory = new SingleConnectionConnectionFactory("r2dbc:h2:mem:///foo", false);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class SingleConnectionConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // gh-204
|
||||
public void shouldApplyAutoCommit() {
|
||||
void shouldApplyAutoCommit() {
|
||||
|
||||
SingleConnectionConnectionFactory factory = new SingleConnectionConnectionFactory("r2dbc:h2:mem:///foo", false);
|
||||
factory.setAutoCommit(false);
|
||||
@@ -71,7 +71,7 @@ public class SingleConnectionConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // gh-204
|
||||
public void shouldSuppressClose() {
|
||||
void shouldSuppressClose() {
|
||||
|
||||
SingleConnectionConnectionFactory factory = new SingleConnectionConnectionFactory("r2dbc:h2:mem:///foo", true);
|
||||
|
||||
@@ -87,7 +87,7 @@ public class SingleConnectionConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // gh-204
|
||||
public void shouldNotSuppressClose() {
|
||||
void shouldNotSuppressClose() {
|
||||
|
||||
SingleConnectionConnectionFactory factory = new SingleConnectionConnectionFactory("r2dbc:h2:mem:///foo", false);
|
||||
|
||||
@@ -101,7 +101,7 @@ public class SingleConnectionConnectionFactoryUnitTests {
|
||||
}
|
||||
|
||||
@Test // gh-204
|
||||
public void releaseConnectionShouldCloseUnrelatedConnection() {
|
||||
void releaseConnectionShouldCloseUnrelatedConnection() {
|
||||
|
||||
Connection connectionMock = mock(Connection.class);
|
||||
Connection otherConnection = mock(Connection.class);
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2019-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.r2dbc.dialect;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2019-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.r2dbc.dialect;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@@ -28,7 +28,6 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@@ -214,7 +213,7 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
|
||||
.verifyComplete();
|
||||
|
||||
Map<String, Object> count = jdbc.queryForMap("SELECT count(*) AS count FROM legoset");
|
||||
assertThat(count).hasEntrySatisfying("count", numberOf(1));
|
||||
assertThat(getCount(count)).satisfies(numberOf(1));
|
||||
}
|
||||
|
||||
@Test // gh-335
|
||||
@@ -293,11 +292,13 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
|
||||
Mono<Map<String, Object>> nonTransactional = repository.save(legoSet2) //
|
||||
.map(it -> jdbc.queryForMap("SELECT count(*) AS count FROM legoset"));
|
||||
|
||||
transactional.as(StepVerifier::create).expectNext(Collections.singletonMap("count", 0L)).verifyComplete();
|
||||
nonTransactional.as(StepVerifier::create).expectNext(Collections.singletonMap("count", 2L)).verifyComplete();
|
||||
transactional.as(StepVerifier::create).assertNext(actual -> assertThat(getCount(actual)).satisfies(numberOf(0)))
|
||||
.verifyComplete();
|
||||
nonTransactional.as(StepVerifier::create).assertNext(actual -> assertThat(getCount(actual)).satisfies(numberOf(2)))
|
||||
.verifyComplete();
|
||||
|
||||
Map<String, Object> count = jdbc.queryForMap("SELECT count(*) AS count FROM legoset");
|
||||
assertThat(count).hasEntrySatisfying("count", numberOf(2));
|
||||
Map<String, Object> map = jdbc.queryForMap("SELECT count(*) AS count FROM legoset");
|
||||
assertThat(getCount(map)).satisfies(numberOf(2));
|
||||
}
|
||||
|
||||
@Test // gh-363
|
||||
@@ -353,6 +354,10 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
private static Object getCount(Map<String, Object> map) {
|
||||
return map.getOrDefault("count", map.get("COUNT"));
|
||||
}
|
||||
|
||||
private Condition<? super Object> numberOf(int expected) {
|
||||
return new Condition<>(it -> {
|
||||
return it instanceof Number && ((Number) it).intValue() == expected;
|
||||
|
||||
@@ -138,7 +138,6 @@ public abstract class ExternalDatabase implements BeforeAllCallback {
|
||||
.port(container.getFirstMappedPort()) //
|
||||
.username(container.getUsername()) //
|
||||
.password(container.getPassword()) //
|
||||
.database(container.getDatabaseName()) //
|
||||
.jdbcUrl(container.getJdbcUrl());
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ public class H2TestSupport {
|
||||
dataSource.setUsername("sa");
|
||||
dataSource.setPassword("");
|
||||
dataSource.setUrl("jdbc:h2:mem:r2dbc;DB_CLOSE_DELAY=-1");
|
||||
dataSource.setDriverClassName("org.h2.Driver");
|
||||
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class MariaDbTestSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a locally provided database at {@code postgres:@localhost:5432/postgres}.
|
||||
* Returns a locally provided database .
|
||||
*/
|
||||
private static ExternalDatabase local() {
|
||||
|
||||
@@ -112,6 +112,7 @@ public class MariaDbTestSupport {
|
||||
|
||||
testContainerDatabase = ProvidedDatabase.builder(container) //
|
||||
.username("root") //
|
||||
.database(container.getDatabaseName()) //
|
||||
.build();
|
||||
} catch (IllegalStateException ise) {
|
||||
// docker not available.
|
||||
|
||||
@@ -57,7 +57,7 @@ public class MySqlTestSupport {
|
||||
+ ") ENGINE=InnoDB;";
|
||||
|
||||
/**
|
||||
* Returns a database either hosted locally at {@code postgres:@localhost:5432/postgres} or running inside Docker.
|
||||
* Returns a database either hosted locally or running inside Docker.
|
||||
*
|
||||
* @return information about the database. Guaranteed to be not {@literal null}.
|
||||
*/
|
||||
@@ -88,7 +88,7 @@ public class MySqlTestSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a locally provided database at {@code postgres:@localhost:5432/postgres}.
|
||||
* Returns a locally provided database.
|
||||
*/
|
||||
private static ExternalDatabase local() {
|
||||
|
||||
@@ -114,6 +114,7 @@ public class MySqlTestSupport {
|
||||
container.start();
|
||||
|
||||
testContainerDatabase = ProvidedDatabase.builder(container) //
|
||||
.database(container.getDatabaseName()) //
|
||||
.username("root") //
|
||||
.build();
|
||||
} catch (IllegalStateException ise) {
|
||||
|
||||
@@ -97,7 +97,7 @@ public class PostgresTestSupport {
|
||||
PostgreSQLContainer.IMAGE + ":" + PostgreSQLContainer.DEFAULT_TAG);
|
||||
container.start();
|
||||
|
||||
testContainerDatabase = ProvidedDatabase.from(container);
|
||||
testContainerDatabase = ProvidedDatabase.builder(container).database(container.getDatabaseName()).build();
|
||||
|
||||
} catch (IllegalStateException ise) {
|
||||
// docker not available.
|
||||
|
||||
Reference in New Issue
Block a user