|
|
@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.data.mongo;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.After;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
|
|
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
|
|
|
|
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
|
|
|
|
import org.springframework.boot.autoconfigure.data.alt.mongo.CityMongoDbRepository;
|
|
|
|
import org.springframework.boot.autoconfigure.data.alt.mongo.CityMongoDbRepository;
|
|
|
@ -55,26 +56,16 @@ public class MongoRepositoriesAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testDefaultRepositoryConfiguration() throws Exception {
|
|
|
|
public void testDefaultRepositoryConfiguration() throws Exception {
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
prepareApplicationContext(TestConfiguration.class);
|
|
|
|
this.context.register(TestConfiguration.class, MongoAutoConfiguration.class,
|
|
|
|
|
|
|
|
MongoDataAutoConfiguration.class,
|
|
|
|
|
|
|
|
MongoRepositoriesAutoConfiguration.class,
|
|
|
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
|
|
|
assertNotNull(this.context.getBean(CityRepository.class));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertNotNull(this.context.getBean(CityRepository.class));
|
|
|
|
Mongo mongo = this.context.getBean(Mongo.class);
|
|
|
|
Mongo mongo = this.context.getBean(Mongo.class);
|
|
|
|
assertThat(mongo, is(instanceOf(MongoClient.class)));
|
|
|
|
assertThat(mongo, is(instanceOf(MongoClient.class)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testNoRepositoryConfiguration() throws Exception {
|
|
|
|
public void testNoRepositoryConfiguration() throws Exception {
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
prepareApplicationContext(EmptyConfiguration.class);
|
|
|
|
this.context.register(EmptyConfiguration.class, MongoAutoConfiguration.class,
|
|
|
|
|
|
|
|
MongoDataAutoConfiguration.class,
|
|
|
|
|
|
|
|
MongoRepositoriesAutoConfiguration.class,
|
|
|
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mongo mongo = this.context.getBean(Mongo.class);
|
|
|
|
Mongo mongo = this.context.getBean(Mongo.class);
|
|
|
|
assertThat(mongo, is(instanceOf(MongoClient.class)));
|
|
|
|
assertThat(mongo, is(instanceOf(MongoClient.class)));
|
|
|
@ -82,13 +73,26 @@ public class MongoRepositoriesAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
|
|
|
|
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
|
|
|
|
|
|
|
|
prepareApplicationContext(CustomizedConfiguration.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertNotNull(this.context.getBean(CityMongoDbRepository.class));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = NoSuchBeanDefinitionException.class)
|
|
|
|
|
|
|
|
public void autoConfigurationShouldNotKickInEvenIfManualConfigDidNotCreateAnyRepositories() {
|
|
|
|
|
|
|
|
prepareApplicationContext(SortOfInvalidCustomConfiguration.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.context.getBean(CityRepository.class);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void prepareApplicationContext(Class<?>... configurationClasses) {
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context.register(CustomizedConfiguration.class,
|
|
|
|
this.context.register(configurationClasses);
|
|
|
|
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class,
|
|
|
|
this.context.register(MongoAutoConfiguration.class,
|
|
|
|
|
|
|
|
MongoDataAutoConfiguration.class,
|
|
|
|
MongoRepositoriesAutoConfiguration.class,
|
|
|
|
MongoRepositoriesAutoConfiguration.class,
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
assertNotNull(this.context.getBean(CityMongoDbRepository.class));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
@ -109,4 +113,12 @@ public class MongoRepositoriesAutoConfigurationTests {
|
|
|
|
protected static class CustomizedConfiguration {
|
|
|
|
protected static class CustomizedConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
|
|
|
// To not find any repositories
|
|
|
|
|
|
|
|
@EnableMongoRepositories("foo.bar")
|
|
|
|
|
|
|
|
@TestAutoConfigurationPackage(MongoRepositoriesAutoConfigurationTests.class)
|
|
|
|
|
|
|
|
protected static class SortOfInvalidCustomConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|