From cca38b44803e1c6a2445c1562f5b2612c62dffe3 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 15 Apr 2019 14:33:19 +0200 Subject: [PATCH] #90 - Add additional subclasses to test against H2. We now run all of our integration test also against H2. Original pull request: #90. --- .../H2DatabaseClientIntegrationTests.java | 51 ++++++++++ ...stractR2dbcRepositoryIntegrationTests.java | 6 +- .../H2R2dbcRepositoryIntegrationTests.java | 95 +++++++++++++++++++ 3 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 src/test/java/org/springframework/data/r2dbc/function/H2DatabaseClientIntegrationTests.java create mode 100644 src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryIntegrationTests.java diff --git a/src/test/java/org/springframework/data/r2dbc/function/H2DatabaseClientIntegrationTests.java b/src/test/java/org/springframework/data/r2dbc/function/H2DatabaseClientIntegrationTests.java new file mode 100644 index 00000000..0292ff1d --- /dev/null +++ b/src/test/java/org/springframework/data/r2dbc/function/H2DatabaseClientIntegrationTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2019 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.function; + +import io.r2dbc.spi.ConnectionFactory; + +import javax.sql.DataSource; + +import org.junit.Ignore; + +import org.springframework.data.r2dbc.testing.H2TestSupport; + +/** + * Integration tests for {@link DatabaseClient} against H2. + * + * @author Mark Paluch + */ +public class H2DatabaseClientIntegrationTests extends AbstractDatabaseClientIntegrationTests { + + @Override + protected DataSource createDataSource() { + return H2TestSupport.createDataSource(); + } + + @Override + protected ConnectionFactory createConnectionFactory() { + return H2TestSupport.createConnectionFactory(); + } + + @Override + protected String getCreateTableStatement() { + return H2TestSupport.CREATE_TABLE_LEGOSET; + } + + @Override + @Ignore("See https://github.com/r2dbc/r2dbc-h2/issues/66") + public void shouldTranslateDuplicateKeyException() {} +} diff --git a/src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryIntegrationTests.java index 84e27861..de75139e 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/AbstractR2dbcRepositoryIntegrationTests.java @@ -188,16 +188,16 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg Flux> transactional = client.inTransaction(db -> { return transactionalRepository.save(legoSet1) // - .map(it -> jdbc.queryForMap("SELECT count(*) FROM legoset")); + .map(it -> jdbc.queryForMap("SELECT count(*) as count FROM legoset")); }); Mono> nonTransactional = transactionalRepository.save(legoSet2) // - .map(it -> jdbc.queryForMap("SELECT count(*) FROM legoset")); + .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(); - Map count = jdbc.queryForMap("SELECT count(*) FROM legoset"); + Map count = jdbc.queryForMap("SELECT count(*) as count FROM legoset"); assertThat(count).containsEntry("count", 2L); } diff --git a/src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryIntegrationTests.java new file mode 100644 index 00000000..96257352 --- /dev/null +++ b/src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryIntegrationTests.java @@ -0,0 +1,95 @@ +/* + * Copyright 2019 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.repository; + +import io.r2dbc.spi.ConnectionFactory; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import javax.sql.DataSource; + +import org.junit.runner.RunWith; + +import org.springframework.context.annotation.ComponentScan.Filter; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; +import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration; +import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories; +import org.springframework.data.r2dbc.repository.query.Query; +import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory; +import org.springframework.data.r2dbc.testing.H2TestSupport; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * Integration tests for {@link LegoSetRepository} using {@link R2dbcRepositoryFactory} against H2. + * + * @author Mark Paluch + */ +@RunWith(SpringRunner.class) +@ContextConfiguration +public class H2R2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIntegrationTests { + + @Configuration + @EnableR2dbcRepositories(considerNestedRepositories = true, + includeFilters = @Filter(classes = H2LegoSetRepository.class, type = FilterType.ASSIGNABLE_TYPE)) + static class IntegrationTestConfiguration extends AbstractR2dbcConfiguration { + + @Override + public ConnectionFactory connectionFactory() { + return H2TestSupport.createConnectionFactory(); + } + } + + @Override + protected DataSource createDataSource() { + return H2TestSupport.createDataSource(); + } + + @Override + protected ConnectionFactory createConnectionFactory() { + return H2TestSupport.createConnectionFactory(); + } + + @Override + protected String getCreateTableStatement() { + return H2TestSupport.CREATE_TABLE_LEGOSET_WITH_ID_GENERATION; + } + + @Override + protected Class getRepositoryInterfaceType() { + return H2LegoSetRepository.class; + } + + interface H2LegoSetRepository extends LegoSetRepository { + + @Override + @Query("SELECT * FROM legoset WHERE name like $1") + Flux findByNameContains(String name); + + @Override + @Query("SELECT * FROM legoset") + Flux findAsProjection(); + + @Override + @Query("SELECT * FROM legoset WHERE manual = :manual") + Mono findByManual(int manual); + + @Override + @Query("SELECT id FROM legoset") + Flux findAllIds(); + } +}