|
17 | 17 |
|
18 | 18 | import static org.assertj.core.api.Assertions.*;
|
19 | 19 |
|
20 | | -import java.util.Map; |
21 | | - |
22 | 20 | import io.r2dbc.postgresql.codec.Json;
|
23 | 21 | import io.r2dbc.spi.ConnectionFactory;
|
24 | 22 | import lombok.AllArgsConstructor;
|
25 | 23 | import reactor.core.publisher.Flux;
|
26 | 24 | import reactor.core.publisher.Mono;
|
27 | 25 | import reactor.test.StepVerifier;
|
28 | 26 |
|
| 27 | +import java.util.Collections; |
| 28 | +import java.util.Map; |
| 29 | + |
29 | 30 | import javax.sql.DataSource;
|
30 | 31 |
|
31 | 32 | import org.junit.jupiter.api.Test;
|
|
55 | 56 | * Integration tests for {@link LegoSetRepository} using {@link R2dbcRepositoryFactory} against Postgres.
|
56 | 57 | *
|
57 | 58 | * @author Mark Paluch
|
| 59 | + * @author Jose Luis Leon |
58 | 60 | */
|
59 | 61 | @ExtendWith(SpringExtension.class)
|
60 | 62 | @ContextConfiguration
|
61 | 63 | public class PostgresR2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIntegrationTests {
|
62 | 64 |
|
63 | 65 | @RegisterExtension public static final ExternalDatabase database = PostgresTestSupport.database();
|
64 | 66 |
|
65 | | - @Autowired JsonPersonRepositoryjsonPersonRepository; |
| 67 | + @Autowired WithJsonRepositorywithJsonRepository; |
66 | 68 |
|
67 | | - @Autowired HStorePersonRepositoryhstorePersonRepository; |
| 69 | + @Autowired WithHStoreRepositoryhstoreRepositoryWith; |
68 | 70 |
|
69 | 71 | @Configuration
|
70 | 72 | @EnableR2dbcRepositories(considerNestedRepositories = true,
|
71 | | - includeFilters = @Filter(classes = { PostgresLegoSetRepository.class, JsonPersonRepository.class, |
72 | | - HStorePersonRepository.class }, type = FilterType.ASSIGNABLE_TYPE)) |
| 73 | + includeFilters = @Filter( |
| 74 | + classes = { PostgresLegoSetRepository.class, WithJsonRepository.class, WithHStoreRepository.class }, |
| 75 | + type = FilterType.ASSIGNABLE_TYPE)) |
73 | 76 | static class IntegrationTestConfiguration extends AbstractR2dbcConfiguration {
|
74 | 77 |
|
75 | 78 | @Bean
|
@@ -136,66 +139,64 @@ void shouldSaveAndLoadJson() {
|
136 | 139 |
|
137 | 140 | JdbcTemplate template = new JdbcTemplate(createDataSource());
|
138 | 141 |
|
139 | | - template.execute("DROP TABLE IF EXISTS json_person"); |
140 | | - template.execute("CREATE TABLE json_person (\n" // |
| 142 | + template.execute("DROP TABLE IF EXISTS with_json"); |
| 143 | + template.execute("CREATE TABLE with_json (\n" // |
141 | 144 | + " id SERIAL PRIMARY KEY,\n" //
|
142 | 145 | + " json_value JSONB NOT NULL" //
|
143 | 146 | + ");");
|
144 | 147 |
|
145 | | - JsonPerson person = new JsonPerson(null, Json.of("{\"hello\": \"world\"}")); |
146 | | - jsonPersonRepository.save(person).as(StepVerifier::create).expectNextCount(1).verifyComplete(); |
| 148 | + WithJson person = new WithJson(null, Json.of("{\"hello\": \"world\"}")); |
| 149 | + withJsonRepository.save(person).as(StepVerifier::create).expectNextCount(1).verifyComplete(); |
147 | 150 |
|
148 | | - jsonPersonRepository.findAll().as(StepVerifier::create).consumeNextWith(actual -> { |
| 151 | + withJsonRepository.findAll().as(StepVerifier::create).consumeNextWith(actual -> { |
149 | 152 |
|
150 | 153 | assertThat(actual.jsonValue).isNotNull();
|
151 | 154 | assertThat(actual.jsonValue.asString()).isEqualTo("{\"hello\": \"world\"}");
|
152 | 155 | }).verifyComplete();
|
153 | 156 | }
|
154 | 157 |
|
155 | | - @Test |
| 158 | + @Test// gh-492 |
156 | 159 | void shouldSaveAndLoadHStore() {
|
157 | 160 |
|
158 | 161 | JdbcTemplate template = new JdbcTemplate(createDataSource());
|
159 | 162 |
|
160 | | - template.execute("DROP TABLE IF EXISTS hstore_person"); |
| 163 | + template.execute("DROP TABLE IF EXISTS with_hstore"); |
161 | 164 | template.execute("CREATE EXTENSION IF NOT EXISTS hstore;");
|
162 | | - template.execute("CREATE TABLE hstore_person (\n" // |
163 | | - + " id SERIAL PRIMARY KEY,\n" // |
164 | | - + " hstore_value HSTORE NOT NULL" // |
165 | | - + ");"); |
| 165 | + template.execute("CREATE TABLE with_hstore (" // |
| 166 | + + " id SERIAL PRIMARY KEY," // |
| 167 | + + " hstore_value HSTORE NOT NULL);"); |
166 | 168 |
|
167 | | - HStorePerson person = new HStorePerson(null, Map.of("hello", "world")); |
168 | | - hstorePersonRepository.save(person).as(StepVerifier::create).expectNextCount(1).verifyComplete(); |
| 169 | + WithHStore person = new WithHStore(null, Collections.singletonMap("hello", "world")); |
| 170 | + hstoreRepositoryWith.save(person).as(StepVerifier::create).expectNextCount(1).verifyComplete(); |
169 | 171 |
|
170 | | - hstorePersonRepository.findAll().as(StepVerifier::create).consumeNextWith(actual -> { |
| 172 | + hstoreRepositoryWith.findAll().as(StepVerifier::create).consumeNextWith(actual -> { |
171 | 173 |
|
172 | | - assertThat(actual.hstoreValue).isNotNull(); |
173 | | - assertThat(actual.hstoreValue).containsEntry("hello", "world"); |
| 174 | + assertThat(actual.hstoreValue).isNotNull().containsEntry("hello", "world"); |
174 | 175 | }).verifyComplete();
|
175 | 176 | }
|
176 | 177 |
|
177 | 178 | @AllArgsConstructor
|
178 | | - static class JsonPerson { |
| 179 | + static class WithJson { |
179 | 180 |
|
180 | 181 | @Id Long id;
|
181 | 182 |
|
182 | 183 | Json jsonValue;
|
183 | 184 | }
|
184 | 185 |
|
185 | | - interface JsonPersonRepository extends ReactiveCrudRepository<JsonPerson, Long> { |
| 186 | + interface WithJsonRepository extends ReactiveCrudRepository<WithJson, Long> { |
186 | 187 |
|
187 | 188 | }
|
188 | 189 |
|
189 | 190 | @AllArgsConstructor
|
190 | | - @Table("hstore_person") |
191 | | - static class HStorePerson { |
| 191 | + @Table("with_hstore") |
| 192 | + static class WithHStore { |
192 | 193 |
|
193 | 194 | @Id Long id;
|
194 | 195 |
|
195 | 196 | Map<String, String> hstoreValue;
|
196 | 197 | }
|
197 | 198 |
|
198 | | - interface HStorePersonRepository extends ReactiveCrudRepository<HStorePerson, Long> { |
| 199 | + interface WithHStoreRepository extends ReactiveCrudRepository<WithHStore, Long> { |
199 | 200 |
|
200 | 201 | }
|
201 | 202 | }
|
0 commit comments