Skip to content

Commit cca38b4

Browse files
mp911deschauder
authored andcommitted
#90 - Add additional subclasses to test against H2.
We now run all of our integration test also against H2. Original pull request: #90.
1 parent 652facb commit cca38b4

File tree

3 files changed

+149
-3
lines changed

3 files changed

+149
-3
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2019 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+
*/
16+
package org.springframework.data.r2dbc.function;
17+
18+
import io.r2dbc.spi.ConnectionFactory;
19+
20+
import javax.sql.DataSource;
21+
22+
import org.junit.Ignore;
23+
24+
import org.springframework.data.r2dbc.testing.H2TestSupport;
25+
26+
/**
27+
* Integration tests for {@link DatabaseClient} against H2.
28+
*
29+
* @author Mark Paluch
30+
*/
31+
public class H2DatabaseClientIntegrationTests extends AbstractDatabaseClientIntegrationTests {
32+
33+
@Override
34+
protected DataSource createDataSource() {
35+
return H2TestSupport.createDataSource();
36+
}
37+
38+
@Override
39+
protected ConnectionFactory createConnectionFactory() {
40+
return H2TestSupport.createConnectionFactory();
41+
}
42+
43+
@Override
44+
protected String getCreateTableStatement() {
45+
return H2TestSupport.CREATE_TABLE_LEGOSET;
46+
}
47+
48+
@Override
49+
@Ignore("See https://github.com/r2dbc/r2dbc-h2/issues/66")
50+
public void shouldTranslateDuplicateKeyException() {}
51+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,16 @@ public void shouldInsertItemsTransactional() {
188188
Flux<Map<String, Object>> transactional = client.inTransaction(db -> {
189189

190190
return transactionalRepository.save(legoSet1) //
191-
.map(it -> jdbc.queryForMap("SELECT count(*) FROM legoset"));
191+
.map(it -> jdbc.queryForMap("SELECT count(*) as count FROM legoset"));
192192
});
193193

194194
Mono<Map<String, Object>> nonTransactional = transactionalRepository.save(legoSet2) //
195-
.map(it -> jdbc.queryForMap("SELECT count(*) FROM legoset"));
195+
.map(it -> jdbc.queryForMap("SELECT count(*) as count FROM legoset"));
196196

197197
transactional.as(StepVerifier::create).expectNext(Collections.singletonMap("count", 0L)).verifyComplete();
198198
nonTransactional.as(StepVerifier::create).expectNext(Collections.singletonMap("count", 2L)).verifyComplete();
199199

200-
Map<String, Object> count = jdbc.queryForMap("SELECT count(*) FROM legoset");
200+
Map<String, Object> count = jdbc.queryForMap("SELECT count(*) as count FROM legoset");
201201
assertThat(count).containsEntry("count", 2L);
202202
}
203203

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2019 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+
*/
16+
package org.springframework.data.r2dbc.repository;
17+
18+
import io.r2dbc.spi.ConnectionFactory;
19+
import reactor.core.publisher.Flux;
20+
import reactor.core.publisher.Mono;
21+
22+
import javax.sql.DataSource;
23+
24+
import org.junit.runner.RunWith;
25+
26+
import org.springframework.context.annotation.ComponentScan.Filter;
27+
import org.springframework.context.annotation.Configuration;
28+
import org.springframework.context.annotation.FilterType;
29+
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
30+
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
31+
import org.springframework.data.r2dbc.repository.query.Query;
32+
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
33+
import org.springframework.data.r2dbc.testing.H2TestSupport;
34+
import org.springframework.test.context.ContextConfiguration;
35+
import org.springframework.test.context.junit4.SpringRunner;
36+
37+
/**
38+
* Integration tests for {@link LegoSetRepository} using {@link R2dbcRepositoryFactory} against H2.
39+
*
40+
* @author Mark Paluch
41+
*/
42+
@RunWith(SpringRunner.class)
43+
@ContextConfiguration
44+
public class H2R2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIntegrationTests {
45+
46+
@Configuration
47+
@EnableR2dbcRepositories(considerNestedRepositories = true,
48+
includeFilters = @Filter(classes = H2LegoSetRepository.class, type = FilterType.ASSIGNABLE_TYPE))
49+
static class IntegrationTestConfiguration extends AbstractR2dbcConfiguration {
50+
51+
@Override
52+
public ConnectionFactory connectionFactory() {
53+
return H2TestSupport.createConnectionFactory();
54+
}
55+
}
56+
57+
@Override
58+
protected DataSource createDataSource() {
59+
return H2TestSupport.createDataSource();
60+
}
61+
62+
@Override
63+
protected ConnectionFactory createConnectionFactory() {
64+
return H2TestSupport.createConnectionFactory();
65+
}
66+
67+
@Override
68+
protected String getCreateTableStatement() {
69+
return H2TestSupport.CREATE_TABLE_LEGOSET_WITH_ID_GENERATION;
70+
}
71+
72+
@Override
73+
protected Class<? extends LegoSetRepository> getRepositoryInterfaceType() {
74+
return H2LegoSetRepository.class;
75+
}
76+
77+
interface H2LegoSetRepository extends LegoSetRepository {
78+
79+
@Override
80+
@Query("SELECT * FROM legoset WHERE name like $1")
81+
Flux<LegoSet> findByNameContains(String name);
82+
83+
@Override
84+
@Query("SELECT * FROM legoset")
85+
Flux<Named> findAsProjection();
86+
87+
@Override
88+
@Query("SELECT * FROM legoset WHERE manual = :manual")
89+
Mono<LegoSet> findByManual(int manual);
90+
91+
@Override
92+
@Query("SELECT id FROM legoset")
93+
Flux<Integer> findAllIds();
94+
}
95+
}

0 commit comments

Comments
 (0)