parent
1370e9dbaf
commit
568cd6472b
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.couchbase.client.java.Bucket;
|
||||||
|
import reactor.core.publisher.Flux;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.couchbase.repository.ReactiveCouchbaseRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Reactive Couchbase
|
||||||
|
* support.
|
||||||
|
*
|
||||||
|
* @author Alex Derkach
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnClass({Bucket.class, ReactiveCouchbaseRepository.class, Flux.class})
|
||||||
|
@AutoConfigureAfter(CouchbaseDataAutoConfiguration.class)
|
||||||
|
@Import(SpringBootCouchbaseReactiveDataConfiguration.class)
|
||||||
|
public class CouchbaseReactiveDataAutoConfiguration {
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* 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 com.couchbase.client.java.Bucket;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.couchbase.repository.ReactiveCouchbaseRepository;
|
||||||
|
import org.springframework.data.couchbase.repository.config.ReactiveRepositoryOperationsMapping;
|
||||||
|
import org.springframework.data.couchbase.repository.support.ReactiveCouchbaseRepositoryFactoryBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data's Couchbase
|
||||||
|
* Reactive Repositories.
|
||||||
|
*
|
||||||
|
* @author Alex Derkach
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnClass({Bucket.class, ReactiveCouchbaseRepository.class})
|
||||||
|
@ConditionalOnProperty(prefix = "spring.data.couchbase.reactive-repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||||
|
@ConditionalOnBean(ReactiveRepositoryOperationsMapping.class)
|
||||||
|
@ConditionalOnMissingBean(ReactiveCouchbaseRepositoryFactoryBean.class)
|
||||||
|
@Import(CouchbaseReactiveRepositoriesAutoConfigureRegistrar.class)
|
||||||
|
@AutoConfigureAfter(CouchbaseReactiveDataAutoConfiguration.class)
|
||||||
|
public class CouchbaseReactiveRepositoriesAutoConfiguration {
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.annotation.Annotation;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport;
|
||||||
|
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
|
||||||
|
import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories;
|
||||||
|
import org.springframework.data.couchbase.repository.config.ReactiveCouchbaseRepositoryConfigurationExtension;
|
||||||
|
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ImportBeanDefinitionRegistrar} used to auto-configure Spring Data Couchbase
|
||||||
|
* Reactive Repositories.
|
||||||
|
*
|
||||||
|
* @author Alex Derkach
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public class CouchbaseReactiveRepositoriesAutoConfigureRegistrar
|
||||||
|
extends AbstractRepositoryConfigurationSourceSupport {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<? extends Annotation> getAnnotation() {
|
||||||
|
return EnableReactiveCouchbaseRepositories.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Class<?> getConfiguration() {
|
||||||
|
return EnableReactiveCouchbaseRepositoriesConfiguration.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected RepositoryConfigurationExtension getRepositoryConfigurationExtension() {
|
||||||
|
return new ReactiveCouchbaseRepositoryConfigurationExtension();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EnableReactiveCouchbaseRepositories
|
||||||
|
private static class EnableReactiveCouchbaseRepositoriesConfiguration {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.couchbase.config.AbstractReactiveCouchbaseDataConfiguration;
|
||||||
|
import org.springframework.data.couchbase.config.BeanNames;
|
||||||
|
import org.springframework.data.couchbase.config.CouchbaseConfigurer;
|
||||||
|
import org.springframework.data.couchbase.core.RxJavaCouchbaseTemplate;
|
||||||
|
import org.springframework.data.couchbase.core.query.Consistency;
|
||||||
|
import org.springframework.data.couchbase.repository.config.ReactiveRepositoryOperationsMapping;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure Spring Data's reactive couchbase support.
|
||||||
|
*
|
||||||
|
* @author Alex Derkach
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnMissingBean(AbstractReactiveCouchbaseDataConfiguration.class)
|
||||||
|
@ConditionalOnBean(CouchbaseConfigurer.class)
|
||||||
|
class SpringBootCouchbaseReactiveDataConfiguration extends AbstractReactiveCouchbaseDataConfiguration {
|
||||||
|
|
||||||
|
private final CouchbaseDataProperties properties;
|
||||||
|
|
||||||
|
private final CouchbaseConfigurer couchbaseConfigurer;
|
||||||
|
|
||||||
|
SpringBootCouchbaseReactiveDataConfiguration(CouchbaseDataProperties properties,
|
||||||
|
CouchbaseConfigurer couchbaseConfigurer) {
|
||||||
|
this.properties = properties;
|
||||||
|
this.couchbaseConfigurer = couchbaseConfigurer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CouchbaseConfigurer couchbaseConfigurer() {
|
||||||
|
return this.couchbaseConfigurer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Consistency getDefaultConsistency() {
|
||||||
|
return this.properties.getConsistency();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@ConditionalOnMissingBean(name = BeanNames.RXJAVA1_COUCHBASE_TEMPLATE)
|
||||||
|
@Bean(name = BeanNames.RXJAVA1_COUCHBASE_TEMPLATE)
|
||||||
|
public RxJavaCouchbaseTemplate reactiveCouchbaseTemplate() throws Exception {
|
||||||
|
return super.reactiveCouchbaseTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@ConditionalOnMissingBean(name = BeanNames.REACTIVE_COUCHBASE_OPERATIONS_MAPPING)
|
||||||
|
@Bean(name = BeanNames.REACTIVE_COUCHBASE_OPERATIONS_MAPPING)
|
||||||
|
public ReactiveRepositoryOperationsMapping reactiveRepositoryOperationsMapping(RxJavaCouchbaseTemplate reactiveCouchbaseTemplate) throws Exception {
|
||||||
|
return super.reactiveRepositoryOperationsMapping(reactiveCouchbaseTemplate);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* 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.alt.couchbase;
|
||||||
|
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.data.couchbase.city.City;
|
||||||
|
import org.springframework.data.repository.Repository;
|
||||||
|
|
||||||
|
public interface ReactiveCityCouchbaseRepository extends Repository<City, Long> {
|
||||||
|
Mono<City> save(City city);
|
||||||
|
|
||||||
|
Mono<City> findById(Long id);
|
||||||
|
}
|
@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
* 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.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties;
|
||||||
|
import org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer;
|
||||||
|
import org.springframework.boot.autoconfigure.data.couchbase.city.City;
|
||||||
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
|
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
|
||||||
|
import org.springframework.boot.test.util.TestPropertyValues;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
import org.springframework.data.couchbase.config.AbstractReactiveCouchbaseDataConfiguration;
|
||||||
|
import org.springframework.data.couchbase.config.BeanNames;
|
||||||
|
import org.springframework.data.couchbase.config.CouchbaseConfigurer;
|
||||||
|
import org.springframework.data.couchbase.core.RxJavaCouchbaseTemplate;
|
||||||
|
import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversions;
|
||||||
|
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
|
||||||
|
import org.springframework.data.couchbase.core.mapping.event.ValidatingCouchbaseEventListener;
|
||||||
|
import org.springframework.data.couchbase.core.query.Consistency;
|
||||||
|
import org.springframework.data.couchbase.repository.support.IndexManager;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link CouchbaseReactiveDataAutoConfiguration}.
|
||||||
|
*
|
||||||
|
* @author Alex Derkach
|
||||||
|
*/
|
||||||
|
public class CouchbaseReactiveDataAutoConfigurationTests {
|
||||||
|
|
||||||
|
private AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void close() {
|
||||||
|
if (this.context != null) {
|
||||||
|
this.context.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void disabledIfCouchbaseIsNotConfigured() {
|
||||||
|
load(null);
|
||||||
|
assertThat(this.context.getBeansOfType(IndexManager.class)).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void customConfiguration() {
|
||||||
|
load(CustomCouchbaseConfiguration.class);
|
||||||
|
RxJavaCouchbaseTemplate rxJavaCouchbaseTemplate = this.context.getBean(RxJavaCouchbaseTemplate.class);
|
||||||
|
assertThat(rxJavaCouchbaseTemplate.getDefaultConsistency()).isEqualTo(Consistency.STRONGLY_CONSISTENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void validatorIsPresent() {
|
||||||
|
load(CouchbaseTestConfigurer.class);
|
||||||
|
assertThat(this.context.getBeansOfType(ValidatingCouchbaseEventListener.class)).hasSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void entityScanShouldSetInitialEntitySet() throws Exception {
|
||||||
|
load(EntityScanConfig.class);
|
||||||
|
CouchbaseMappingContext mappingContext = this.context
|
||||||
|
.getBean(CouchbaseMappingContext.class);
|
||||||
|
Set<Class<?>> initialEntitySet = (Set<Class<?>>) ReflectionTestUtils
|
||||||
|
.getField(mappingContext, "initialEntitySet");
|
||||||
|
assertThat(initialEntitySet).containsOnly(City.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void customConversions() {
|
||||||
|
load(CustomConversionsConfig.class);
|
||||||
|
RxJavaCouchbaseTemplate template = this.context.getBean(RxJavaCouchbaseTemplate.class);
|
||||||
|
assertThat(template.getConverter().getConversionService()
|
||||||
|
.canConvert(CouchbaseProperties.class, Boolean.class)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load(Class<?> config, String... environment) {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
|
TestPropertyValues.of(environment).applyTo(context);
|
||||||
|
if (config != null) {
|
||||||
|
context.register(config);
|
||||||
|
}
|
||||||
|
context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||||
|
ValidationAutoConfiguration.class, CouchbaseAutoConfiguration.class,
|
||||||
|
CouchbaseDataAutoConfiguration.class, CouchbaseReactiveDataAutoConfiguration.class);
|
||||||
|
context.refresh();
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class CustomCouchbaseConfiguration extends AbstractReactiveCouchbaseDataConfiguration {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CouchbaseConfigurer couchbaseConfigurer() {
|
||||||
|
return new CouchbaseTestConfigurer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Consistency getDefaultConsistency() {
|
||||||
|
return Consistency.STRONGLY_CONSISTENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Import(CouchbaseTestConfigurer.class)
|
||||||
|
static class CustomConversionsConfig {
|
||||||
|
|
||||||
|
@Bean(BeanNames.COUCHBASE_CUSTOM_CONVERSIONS)
|
||||||
|
public CouchbaseCustomConversions myCustomConversions() {
|
||||||
|
return new CouchbaseCustomConversions(
|
||||||
|
Collections.singletonList(new MyConverter()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EntityScan("org.springframework.boot.autoconfigure.data.couchbase.city")
|
||||||
|
@Import(CustomCouchbaseConfiguration.class)
|
||||||
|
static class EntityScanConfig {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MyConverter implements Converter<CouchbaseProperties, Boolean> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean convert(CouchbaseProperties value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
|
||||||
|
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration;
|
||||||
|
import org.springframework.boot.autoconfigure.couchbase.CouchbaseTestConfigurer;
|
||||||
|
import org.springframework.boot.autoconfigure.data.alt.couchbase.CityCouchbaseRepository;
|
||||||
|
import org.springframework.boot.autoconfigure.data.alt.couchbase.ReactiveCityCouchbaseRepository;
|
||||||
|
import org.springframework.boot.autoconfigure.data.couchbase.city.City;
|
||||||
|
import org.springframework.boot.autoconfigure.data.couchbase.city.ReactiveCityRepository;
|
||||||
|
import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage;
|
||||||
|
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.data.mongodb.repository.config.EnableMongoRepositories;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link CouchbaseReactiveRepositoriesAutoConfiguration}.
|
||||||
|
*
|
||||||
|
* @author Alex Derkach
|
||||||
|
*/
|
||||||
|
public class CouchbaseReactiveRepositoriesAutoConfigurationTests {
|
||||||
|
|
||||||
|
private AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void close() {
|
||||||
|
if (this.context != null) {
|
||||||
|
this.context.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void couchbaseNotAvailable() throws Exception {
|
||||||
|
load(null);
|
||||||
|
assertThat(this.context.getBeansOfType(ReactiveCityRepository.class)).hasSize(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void defaultRepository() throws Exception {
|
||||||
|
load(DefaultConfiguration.class);
|
||||||
|
assertThat(this.context.getBeansOfType(ReactiveCityRepository.class)).hasSize(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void disableReactiveRepository() {
|
||||||
|
load(DefaultConfiguration.class,
|
||||||
|
"spring.data.couchbase.reactive-repositories.enabled=false",
|
||||||
|
"spring.data.couchbase.repositories.enabled=false");
|
||||||
|
assertThat(this.context.getBeansOfType(ReactiveCityRepository.class)).hasSize(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void noRepositoryAvailable() throws Exception {
|
||||||
|
load(NoRepositoryConfiguration.class);
|
||||||
|
assertThat(this.context.getBeansOfType(ReactiveCityRepository.class)).hasSize(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
|
||||||
|
load(CouchbaseReactiveRepositoriesAutoConfigurationTests.CustomizedConfiguration.class);
|
||||||
|
assertThat(this.context.getBeansOfType(ReactiveCityCouchbaseRepository.class))
|
||||||
|
.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load(Class<?> config, String... environment) {
|
||||||
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
|
TestPropertyValues.of(environment).applyTo(context);
|
||||||
|
if (config != null) {
|
||||||
|
context.register(config);
|
||||||
|
}
|
||||||
|
context.register(PropertyPlaceholderAutoConfiguration.class,
|
||||||
|
CouchbaseAutoConfiguration.class,
|
||||||
|
CouchbaseDataAutoConfiguration.class,
|
||||||
|
CouchbaseRepositoriesAutoConfiguration.class,
|
||||||
|
CouchbaseReactiveDataAutoConfiguration.class,
|
||||||
|
CouchbaseReactiveRepositoriesAutoConfiguration.class
|
||||||
|
);
|
||||||
|
context.refresh();
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@TestAutoConfigurationPackage(City.class)
|
||||||
|
@Import(CouchbaseTestConfigurer.class)
|
||||||
|
static class DefaultConfiguration {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@TestAutoConfigurationPackage(EmptyDataPackage.class)
|
||||||
|
@Import(CouchbaseTestConfigurer.class)
|
||||||
|
protected static class NoRepositoryConfiguration {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@TestAutoConfigurationPackage(CouchbaseReactiveRepositoriesAutoConfigurationTests.class)
|
||||||
|
@EnableMongoRepositories(basePackageClasses = CityCouchbaseRepository.class)
|
||||||
|
protected static class CustomizedConfiguration {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* 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.city;
|
||||||
|
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.Repository;
|
||||||
|
|
||||||
|
public interface ReactiveCityRepository extends Repository<City, Long> {
|
||||||
|
Mono<City> save(City city);
|
||||||
|
Mono<City> findById(Long id);
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<artifactId>spring-boot-starters</artifactId>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<version>${revision}</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>spring-boot-starter-data-couchbase-reactive</artifactId>
|
||||||
|
<name>Spring Boot Data Couchbase Reactive Starter</name>
|
||||||
|
<description>Starter for using Couchbase document-oriented database and Spring Data
|
||||||
|
Couchbase Reactive</description>
|
||||||
|
<properties>
|
||||||
|
<main.basedir>${basedir}/../../..</main.basedir>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.data</groupId>
|
||||||
|
<artifactId>spring-data-couchbase</artifactId>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>com.couchbase.mock</groupId>
|
||||||
|
<artifactId>CouchbaseMock</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.projectreactor</groupId>
|
||||||
|
<artifactId>reactor-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1 @@
|
|||||||
|
provides: spring-data-couchbase
|
Loading…
Reference in New Issue