mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish "Add support for reactive Spring Data Couchbase"
Closes gh-10812
This commit is contained in:
parent
568cd6472b
commit
bbdff1a5bf
@ -45,4 +45,5 @@ import org.springframework.data.couchbase.repository.support.ReactiveCouchbaseRe
|
||||
@Import(CouchbaseReactiveRepositoriesAutoConfigureRegistrar.class)
|
||||
@AutoConfigureAfter(CouchbaseReactiveDataAutoConfiguration.class)
|
||||
public class CouchbaseReactiveRepositoriesAutoConfiguration {
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,4 +25,5 @@ public interface ReactiveCityCouchbaseRepository extends Repository<City, Long>
|
||||
Mono<City> save(City city);
|
||||
|
||||
Mono<City> findById(Long id);
|
||||
|
||||
}
|
||||
|
@ -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<String> 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]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,5 +22,7 @@ import org.springframework.data.repository.Repository;
|
||||
|
||||
public interface ReactiveCityRepository extends Repository<City, Long> {
|
||||
Mono<City> save(City city);
|
||||
|
||||
Mono<City> findById(Long id);
|
||||
|
||||
}
|
||||
|
@ -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.
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user