From bbdff1a5bfeb5b7694800f01fe73c452a2281631 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 14 Nov 2017 17:49:02 +0100 Subject: [PATCH] Polish "Add support for reactive Spring Data Couchbase" Closes gh-10812 --- ...ReactiveRepositoriesAutoConfiguration.java | 1 + ...ootCouchbaseReactiveDataConfiguration.java | 4 +- .../ReactiveCityCouchbaseRepository.java | 1 + ...ingRepositoriesAutoConfigurationTests.java | 101 ++++++++++++++++++ ...aseReactiveDataAutoConfigurationTests.java | 10 +- .../city/ReactiveCityRepository.java | 2 + .../main/asciidoc/spring-boot-features.adoc | 6 +- 7 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveAndBlockingRepositoriesAutoConfigurationTests.java diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveRepositoriesAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveRepositoriesAutoConfiguration.java index 9de42979ad..d651a786f3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveRepositoriesAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveRepositoriesAutoConfiguration.java @@ -45,4 +45,5 @@ import org.springframework.data.couchbase.repository.support.ReactiveCouchbaseRe @Import(CouchbaseReactiveRepositoriesAutoConfigureRegistrar.class) @AutoConfigureAfter(CouchbaseReactiveDataAutoConfiguration.class) public class CouchbaseReactiveRepositoriesAutoConfiguration { + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseReactiveDataConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseReactiveDataConfiguration.java index e00db28c48..cd0bbd9e22 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseReactiveDataConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/couchbase/SpringBootCouchbaseReactiveDataConfiguration.java @@ -36,7 +36,8 @@ import org.springframework.data.couchbase.repository.config.ReactiveRepositoryOp @Configuration @ConditionalOnMissingBean(AbstractReactiveCouchbaseDataConfiguration.class) @ConditionalOnBean(CouchbaseConfigurer.class) -class SpringBootCouchbaseReactiveDataConfiguration extends AbstractReactiveCouchbaseDataConfiguration { +class SpringBootCouchbaseReactiveDataConfiguration + extends AbstractReactiveCouchbaseDataConfiguration { private final CouchbaseDataProperties properties; @@ -71,4 +72,5 @@ class SpringBootCouchbaseReactiveDataConfiguration extends AbstractReactiveCouch public ReactiveRepositoryOperationsMapping reactiveRepositoryOperationsMapping(RxJavaCouchbaseTemplate reactiveCouchbaseTemplate) throws Exception { return super.reactiveRepositoryOperationsMapping(reactiveCouchbaseTemplate); } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/couchbase/ReactiveCityCouchbaseRepository.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/couchbase/ReactiveCityCouchbaseRepository.java index 4fd710643e..3d0d1751ea 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/couchbase/ReactiveCityCouchbaseRepository.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/couchbase/ReactiveCityCouchbaseRepository.java @@ -25,4 +25,5 @@ public interface ReactiveCityCouchbaseRepository extends Repository Mono save(City city); Mono findById(Long id); + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveAndBlockingRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveAndBlockingRepositoriesAutoConfigurationTests.java new file mode 100644 index 0000000000..5ae970260f --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveAndBlockingRepositoriesAutoConfigurationTests.java @@ -0,0 +1,101 @@ +/* + * Copyright 2012-2017 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 + * + * http://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.boot.autoconfigure.data.couchbase; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.After; +import org.junit.Test; + +import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; +import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration; +import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfigurationTests; +import org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer; +import org.springframework.boot.autoconfigure.data.couchbase.city.CityRepository; +import org.springframework.boot.autoconfigure.data.couchbase.city.ReactiveCityRepository; +import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.ImportSelector; +import org.springframework.core.type.AnnotationMetadata; +import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories; +import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link CouchbaseRepositoriesAutoConfiguration} and + * {@link CouchbaseReactiveRepositoriesAutoConfiguration}. + * + * @author Stephane Nicoll + */ +public class CouchbaseReactiveAndBlockingRepositoriesAutoConfigurationTests { + + private AnnotationConfigApplicationContext context; + + @After + public void close() { + this.context.close(); + } + + @Test + public void shouldCreateInstancesForReactiveAndBlockingRepositories() + throws Exception { + this.context = new AnnotationConfigApplicationContext(); + TestPropertyValues.of("spring.datasource.initialization-mode:never") + .applyTo(this.context); + this.context.register(BlockingAndReactiveConfiguration.class, + BaseConfiguration.class); + this.context.refresh(); + assertThat(this.context.getBean(CityRepository.class)).isNotNull(); + assertThat(this.context.getBean(ReactiveCityRepository.class)).isNotNull(); + } + + @Configuration + @TestAutoConfigurationPackage(CouchbaseAutoConfigurationTests.class) + @EnableCouchbaseRepositories(basePackageClasses = CityRepository.class) + @EnableReactiveCouchbaseRepositories(basePackageClasses = ReactiveCityRepository.class) + protected static class BlockingAndReactiveConfiguration { + + } + + @Configuration + @Import({ CouchbaseTestConfigurer.class, Registrar.class }) + protected static class BaseConfiguration { + + } + + protected static class Registrar implements ImportSelector { + + @Override + public String[] selectImports(AnnotationMetadata importingClassMetadata) { + List names = new ArrayList<>(); + for (Class type : new Class[] { CouchbaseAutoConfiguration.class, + CouchbaseDataAutoConfiguration.class, + CouchbaseRepositoriesAutoConfiguration.class, + CouchbaseReactiveDataAutoConfiguration.class, + CouchbaseReactiveRepositoriesAutoConfiguration.class }) { + names.add(type.getName()); + } + return names.toArray(new String[0]); + } + + } + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveDataAutoConfigurationTests.java index c8ca7a7eda..9f6f3542fa 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/CouchbaseReactiveDataAutoConfigurationTests.java @@ -74,13 +74,15 @@ public class CouchbaseReactiveDataAutoConfigurationTests { public void customConfiguration() { load(CustomCouchbaseConfiguration.class); RxJavaCouchbaseTemplate rxJavaCouchbaseTemplate = this.context.getBean(RxJavaCouchbaseTemplate.class); - assertThat(rxJavaCouchbaseTemplate.getDefaultConsistency()).isEqualTo(Consistency.STRONGLY_CONSISTENT); + assertThat(rxJavaCouchbaseTemplate.getDefaultConsistency()) + .isEqualTo(Consistency.STRONGLY_CONSISTENT); } @Test public void validatorIsPresent() { load(CouchbaseTestConfigurer.class); - assertThat(this.context.getBeansOfType(ValidatingCouchbaseEventListener.class)).hasSize(1); + assertThat(this.context.getBeansOfType( + ValidatingCouchbaseEventListener.class)).hasSize(1); } @Test @@ -97,7 +99,8 @@ public class CouchbaseReactiveDataAutoConfigurationTests { @Test public void customConversions() { load(CustomConversionsConfig.class); - RxJavaCouchbaseTemplate template = this.context.getBean(RxJavaCouchbaseTemplate.class); + RxJavaCouchbaseTemplate template = this.context.getBean( + RxJavaCouchbaseTemplate.class); assertThat(template.getConverter().getConversionService() .canConvert(CouchbaseProperties.class, Boolean.class)).isTrue(); } @@ -155,6 +158,7 @@ public class CouchbaseReactiveDataAutoConfigurationTests { public Boolean convert(CouchbaseProperties value) { return true; } + } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/city/ReactiveCityRepository.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/city/ReactiveCityRepository.java index 4163264874..695fd453f0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/city/ReactiveCityRepository.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/couchbase/city/ReactiveCityRepository.java @@ -22,5 +22,7 @@ import org.springframework.data.repository.Repository; public interface ReactiveCityRepository extends Repository { Mono save(City city); + Mono findById(Long id); + } diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 9a3b80c1d4..af571a02d1 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -4053,9 +4053,9 @@ http://docs.spring.io/spring-data/cassandra/docs/[reference documentation]. http://www.couchbase.com/[Couchbase] is an open-source, distributed multi-model NoSQL document-oriented database that is optimized for interactive applications. Spring Boot offers auto-configuration for Couchbase and the abstractions on top of it provided by -https://github.com/spring-projects/spring-data-couchbase[Spring Data Couchbase]. There is -a `spring-boot-starter-data-couchbase` '`Starter`' for collecting the dependencies in a -convenient way. +https://github.com/spring-projects/spring-data-couchbase[Spring Data Couchbase]. There are +a `spring-boot-starter-data-couchbase` and `spring-boot-starter-data-couchbase-reactive` +'`Starters`' for collecting the dependencies in a convenient way.