pull/11764/head
Phillip Webb 7 years ago
parent e53bef737f
commit ab6ad6aa4b

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class ScheduledTasksEndpointTests { public class ScheduledTasksEndpointTests {
private final ApplicationContextRunner runner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withUserConfiguration(BaseConfiguration.class); .withUserConfiguration(BaseConfiguration.class);
@Test @Test
@ -137,7 +137,7 @@ public class ScheduledTasksEndpointTests {
} }
private void run(Class<?> configuration, Consumer<ScheduledTasksReport> consumer) { private void run(Class<?> configuration, Consumer<ScheduledTasksReport> consumer) {
this.runner.withUserConfiguration(configuration).run((context) -> consumer this.contextRunner.withUserConfiguration(configuration).run((context) -> consumer
.accept(context.getBean(ScheduledTasksEndpoint.class).scheduledTasks())); .accept(context.getBean(ScheduledTasksEndpoint.class).scheduledTasks()));
} }

@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Vector; import java.util.Vector;
import java.util.function.Supplier;
import javax.servlet.FilterRegistration; import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
@ -47,6 +48,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.mock.web.MockServletConfig; import org.springframework.mock.web.MockServletConfig;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.reactive.config.EnableWebFlux;
@ -68,8 +70,8 @@ import static org.mockito.Mockito.mock;
*/ */
public class MappingsEndpointTests { public class MappingsEndpointTests {
@SuppressWarnings("unchecked")
@Test @Test
@SuppressWarnings("unchecked")
public void servletWebMappings() { public void servletWebMappings() {
ServletContext servletContext = mock(ServletContext.class); ServletContext servletContext = mock(ServletContext.class);
given(servletContext.getInitParameterNames()) given(servletContext.getInitParameterNames())
@ -82,49 +84,51 @@ public class MappingsEndpointTests {
ServletRegistration servletRegistration = mock(ServletRegistration.class); ServletRegistration servletRegistration = mock(ServletRegistration.class);
given((Map<String, ServletRegistration>) servletContext.getServletRegistrations()) given((Map<String, ServletRegistration>) servletContext.getServletRegistrations())
.willReturn(Collections.singletonMap("testServlet", servletRegistration)); .willReturn(Collections.singletonMap("testServlet", servletRegistration));
WebApplicationContextRunner runner = new WebApplicationContextRunner(() -> { Supplier<ConfigurableWebApplicationContext> contextSupplier = () -> {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setServletContext(servletContext); context.setServletContext(servletContext);
return context; return context;
}).withUserConfiguration(EndpointConfiguration.class, };
ServletWebConfiguration.class); new WebApplicationContextRunner(contextSupplier)
runner.run((context) -> { .withUserConfiguration(EndpointConfiguration.class,
ContextMappings contextMappings = contextMappings(context); ServletWebConfiguration.class)
assertThat(contextMappings.getParentId()).isNull(); .run((context) -> {
assertThat(contextMappings.getMappings()) ContextMappings contextMappings = contextMappings(context);
.containsOnlyKeys("dispatcherServlets", "servletFilters", "servlets"); assertThat(contextMappings.getParentId()).isNull();
Map<String, List<DispatcherServletMappingDescription>> dispatcherServlets = mappings( assertThat(contextMappings.getMappings()).containsOnlyKeys(
contextMappings, "dispatcherServlets"); "dispatcherServlets", "servletFilters", "servlets");
assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet"); Map<String, List<DispatcherServletMappingDescription>> dispatcherServlets = mappings(
List<DispatcherServletMappingDescription> handlerMappings = dispatcherServlets contextMappings, "dispatcherServlets");
.get("dispatcherServlet"); assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet");
assertThat(handlerMappings).hasSize(1); List<DispatcherServletMappingDescription> handlerMappings = dispatcherServlets
List<ServletRegistrationMappingDescription> servlets = mappings( .get("dispatcherServlet");
contextMappings, "servlets"); assertThat(handlerMappings).hasSize(1);
assertThat(servlets).hasSize(1); List<ServletRegistrationMappingDescription> servlets = mappings(
List<FilterRegistrationMappingDescription> filters = mappings(contextMappings, contextMappings, "servlets");
"servletFilters"); assertThat(servlets).hasSize(1);
assertThat(filters).hasSize(1); List<FilterRegistrationMappingDescription> filters = mappings(
}); contextMappings, "servletFilters");
assertThat(filters).hasSize(1);
});
} }
@Test @Test
public void reactiveWebMappings() { public void reactiveWebMappings() {
ReactiveWebApplicationContextRunner runner = new ReactiveWebApplicationContextRunner() new ReactiveWebApplicationContextRunner()
.withUserConfiguration(EndpointConfiguration.class, .withUserConfiguration(EndpointConfiguration.class,
ReactiveWebConfiguration.class); ReactiveWebConfiguration.class)
runner.run((context) -> { .run((context) -> {
ContextMappings contextMappings = contextMappings(context); ContextMappings contextMappings = contextMappings(context);
assertThat(contextMappings.getParentId()).isNull(); assertThat(contextMappings.getParentId()).isNull();
assertThat(contextMappings.getMappings()) assertThat(contextMappings.getMappings())
.containsOnlyKeys("dispatcherHandlers"); .containsOnlyKeys("dispatcherHandlers");
Map<String, List<DispatcherHandlerMappingDescription>> dispatcherHandlers = mappings( Map<String, List<DispatcherHandlerMappingDescription>> dispatcherHandlers = mappings(
contextMappings, "dispatcherHandlers"); contextMappings, "dispatcherHandlers");
assertThat(dispatcherHandlers).containsOnlyKeys("webHandler"); assertThat(dispatcherHandlers).containsOnlyKeys("webHandler");
List<DispatcherHandlerMappingDescription> handlerMappings = dispatcherHandlers List<DispatcherHandlerMappingDescription> handlerMappings = dispatcherHandlers
.get("webHandler"); .get("webHandler");
assertThat(handlerMappings).hasSize(3); assertThat(handlerMappings).hasSize(3);
}); });
} }
private ContextMappings contextMappings(ApplicationContext context) { private ContextMappings contextMappings(ApplicationContext context) {

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,24 +30,24 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class ConditionalOnRepositoryTypeTests { public class ConditionalOnRepositoryTypeTests {
private final ApplicationContextRunner runner = new ApplicationContextRunner(); private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
@Test @Test
public void imperativeRepositoryMatchesWithNoConfiguredType() { public void imperativeRepositoryMatchesWithNoConfiguredType() {
this.runner.withUserConfiguration(ImperativeRepository.class) this.contextRunner.withUserConfiguration(ImperativeRepository.class)
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.hasSingleBean(ImperativeRepository.class)); .hasSingleBean(ImperativeRepository.class));
} }
@Test @Test
public void reactiveRepositoryMatchesWithNoConfiguredType() { public void reactiveRepositoryMatchesWithNoConfiguredType() {
this.runner.withUserConfiguration(ReactiveRepository.class).run( this.contextRunner.withUserConfiguration(ReactiveRepository.class).run(
(context) -> assertThat(context).hasSingleBean(ReactiveRepository.class)); (context) -> assertThat(context).hasSingleBean(ReactiveRepository.class));
} }
@Test @Test
public void imperativeRepositoryMatchesWithAutoConfiguredType() { public void imperativeRepositoryMatchesWithAutoConfiguredType() {
this.runner.withUserConfiguration(ImperativeRepository.class) this.contextRunner.withUserConfiguration(ImperativeRepository.class)
.withPropertyValues("spring.data.test.repositories.type:auto") .withPropertyValues("spring.data.test.repositories.type:auto")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.hasSingleBean(ImperativeRepository.class)); .hasSingleBean(ImperativeRepository.class));
@ -55,7 +55,7 @@ public class ConditionalOnRepositoryTypeTests {
@Test @Test
public void reactiveRepositoryMatchesWithAutoConfiguredType() { public void reactiveRepositoryMatchesWithAutoConfiguredType() {
this.runner.withUserConfiguration(ReactiveRepository.class) this.contextRunner.withUserConfiguration(ReactiveRepository.class)
.withPropertyValues("spring.data.test.repositories.type:auto") .withPropertyValues("spring.data.test.repositories.type:auto")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.hasSingleBean(ReactiveRepository.class)); .hasSingleBean(ReactiveRepository.class));
@ -63,7 +63,7 @@ public class ConditionalOnRepositoryTypeTests {
@Test @Test
public void imperativeRepositoryMatchesWithImperativeConfiguredType() { public void imperativeRepositoryMatchesWithImperativeConfiguredType() {
this.runner.withUserConfiguration(ImperativeRepository.class) this.contextRunner.withUserConfiguration(ImperativeRepository.class)
.withPropertyValues("spring.data.test.repositories.type:imperative") .withPropertyValues("spring.data.test.repositories.type:imperative")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.hasSingleBean(ImperativeRepository.class)); .hasSingleBean(ImperativeRepository.class));
@ -71,7 +71,7 @@ public class ConditionalOnRepositoryTypeTests {
@Test @Test
public void reactiveRepositoryMatchesWithReactiveConfiguredType() { public void reactiveRepositoryMatchesWithReactiveConfiguredType() {
this.runner.withUserConfiguration(ReactiveRepository.class) this.contextRunner.withUserConfiguration(ReactiveRepository.class)
.withPropertyValues("spring.data.test.repositories.type:reactive") .withPropertyValues("spring.data.test.repositories.type:reactive")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.hasSingleBean(ReactiveRepository.class)); .hasSingleBean(ReactiveRepository.class));
@ -79,7 +79,7 @@ public class ConditionalOnRepositoryTypeTests {
@Test @Test
public void imperativeRepositoryDoesNotMatchWithReactiveConfiguredType() { public void imperativeRepositoryDoesNotMatchWithReactiveConfiguredType() {
this.runner.withUserConfiguration(ImperativeRepository.class) this.contextRunner.withUserConfiguration(ImperativeRepository.class)
.withPropertyValues("spring.data.test.repositories.type:reactive") .withPropertyValues("spring.data.test.repositories.type:reactive")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(ImperativeRepository.class)); .doesNotHaveBean(ImperativeRepository.class));
@ -87,7 +87,7 @@ public class ConditionalOnRepositoryTypeTests {
@Test @Test
public void reactiveRepositoryDoesNotMatchWithImperativeConfiguredType() { public void reactiveRepositoryDoesNotMatchWithImperativeConfiguredType() {
this.runner.withUserConfiguration(ReactiveRepository.class) this.contextRunner.withUserConfiguration(ReactiveRepository.class)
.withPropertyValues("spring.data.test.repositories.type:imperative") .withPropertyValues("spring.data.test.repositories.type:imperative")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(ReactiveRepository.class)); .doesNotHaveBean(ReactiveRepository.class));
@ -95,7 +95,7 @@ public class ConditionalOnRepositoryTypeTests {
@Test @Test
public void imperativeRepositoryDoesNotMatchWithNoneConfiguredType() { public void imperativeRepositoryDoesNotMatchWithNoneConfiguredType() {
this.runner.withUserConfiguration(ImperativeRepository.class) this.contextRunner.withUserConfiguration(ImperativeRepository.class)
.withPropertyValues("spring.data.test.repositories.type:none") .withPropertyValues("spring.data.test.repositories.type:none")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(ImperativeRepository.class)); .doesNotHaveBean(ImperativeRepository.class));
@ -103,7 +103,7 @@ public class ConditionalOnRepositoryTypeTests {
@Test @Test
public void reactiveRepositoryDoesNotMatchWithNoneConfiguredType() { public void reactiveRepositoryDoesNotMatchWithNoneConfiguredType() {
this.runner.withUserConfiguration(ReactiveRepository.class) this.contextRunner.withUserConfiguration(ReactiveRepository.class)
.withPropertyValues("spring.data.test.repositories.type:none") .withPropertyValues("spring.data.test.repositories.type:none")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(ReactiveRepository.class)); .doesNotHaveBean(ReactiveRepository.class));
@ -111,7 +111,7 @@ public class ConditionalOnRepositoryTypeTests {
@Test @Test
public void failsFastWhenConfiguredTypeIsUnknown() { public void failsFastWhenConfiguredTypeIsUnknown() {
this.runner.withUserConfiguration(ReactiveRepository.class) this.contextRunner.withUserConfiguration(ReactiveRepository.class)
.withPropertyValues("spring.data.test.repositories.type:abcde") .withPropertyValues("spring.data.test.repositories.type:abcde")
.run((context) -> assertThat(context).hasFailed()); .run((context) -> assertThat(context).hasFailed());
} }

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -55,7 +55,7 @@ import static org.mockito.Mockito.mock;
*/ */
public class CassandraReactiveRepositoriesAutoConfigurationTests { public class CassandraReactiveRepositoriesAutoConfigurationTests {
private final ApplicationContextRunner runner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(CassandraAutoConfiguration.class, .withConfiguration(AutoConfigurations.of(CassandraAutoConfiguration.class,
CassandraRepositoriesAutoConfiguration.class, CassandraRepositoriesAutoConfiguration.class,
CassandraDataAutoConfiguration.class, CassandraDataAutoConfiguration.class,
@ -65,16 +65,17 @@ public class CassandraReactiveRepositoriesAutoConfigurationTests {
@Test @Test
public void testDefaultRepositoryConfiguration() { public void testDefaultRepositoryConfiguration() {
this.runner.withUserConfiguration(TestConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(TestConfiguration.class)
assertThat(context).hasSingleBean(ReactiveCityRepository.class); .run((context) -> {
assertThat(context).hasSingleBean(Cluster.class); assertThat(context).hasSingleBean(ReactiveCityRepository.class);
assertThat(getInitialEntitySet(context)).hasSize(1); assertThat(context).hasSingleBean(Cluster.class);
}); assertThat(getInitialEntitySet(context)).hasSize(1);
});
} }
@Test @Test
public void testNoRepositoryConfiguration() { public void testNoRepositoryConfiguration() {
this.runner.withUserConfiguration(TestExcludeConfiguration.class, this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class,
EmptyConfiguration.class).run((context) -> { EmptyConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(Cluster.class); assertThat(context).hasSingleBean(Cluster.class);
assertThat(getInitialEntitySet(context)).hasSize(1) assertThat(getInitialEntitySet(context)).hasSize(1)
@ -84,7 +85,7 @@ public class CassandraReactiveRepositoriesAutoConfigurationTests {
@Test @Test
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
this.runner.withUserConfiguration(TestExcludeConfiguration.class, this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class,
CustomizedConfiguration.class).run((context) -> { CustomizedConfiguration.class).run((context) -> {
assertThat(context) assertThat(context)
.hasSingleBean(ReactiveCityCassandraRepository.class); .hasSingleBean(ReactiveCityCassandraRepository.class);
@ -95,7 +96,7 @@ public class CassandraReactiveRepositoriesAutoConfigurationTests {
@Test @Test
public void enablingImperativeRepositoriesDisablesReactiveRepositories() { public void enablingImperativeRepositoriesDisablesReactiveRepositories() {
this.runner.withUserConfiguration(TestConfiguration.class) this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withPropertyValues("spring.data.cassandra.repositories.type=imperative") .withPropertyValues("spring.data.cassandra.repositories.type=imperative")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(ReactiveCityRepository.class)); .doesNotHaveBean(ReactiveCityRepository.class));
@ -103,7 +104,7 @@ public class CassandraReactiveRepositoriesAutoConfigurationTests {
@Test @Test
public void enablingNoRepositoriesDisablesReactiveRepositories() { public void enablingNoRepositoriesDisablesReactiveRepositories() {
this.runner.withUserConfiguration(TestConfiguration.class) this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withPropertyValues("spring.data.cassandra.repositories.type=none") .withPropertyValues("spring.data.cassandra.repositories.type=none")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(ReactiveCityRepository.class)); .doesNotHaveBean(ReactiveCityRepository.class));

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -52,7 +52,7 @@ import static org.mockito.Mockito.mock;
*/ */
public class CassandraRepositoriesAutoConfigurationTests { public class CassandraRepositoriesAutoConfigurationTests {
private final ApplicationContextRunner runner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(CassandraAutoConfiguration.class, .withConfiguration(AutoConfigurations.of(CassandraAutoConfiguration.class,
CassandraRepositoriesAutoConfiguration.class, CassandraRepositoriesAutoConfiguration.class,
CassandraDataAutoConfiguration.class, CassandraDataAutoConfiguration.class,
@ -60,7 +60,7 @@ public class CassandraRepositoriesAutoConfigurationTests {
@Test @Test
public void testDefaultRepositoryConfiguration() { public void testDefaultRepositoryConfiguration() {
this.runner.withUserConfiguration(TestConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(CityRepository.class); assertThat(context).hasSingleBean(CityRepository.class);
assertThat(context).hasSingleBean(Cluster.class); assertThat(context).hasSingleBean(Cluster.class);
assertThat(getInitialEntitySet(context)).hasSize(1); assertThat(getInitialEntitySet(context)).hasSize(1);
@ -69,7 +69,7 @@ public class CassandraRepositoriesAutoConfigurationTests {
@Test @Test
public void testNoRepositoryConfiguration() { public void testNoRepositoryConfiguration() {
this.runner.withUserConfiguration(TestExcludeConfiguration.class, this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class,
EmptyConfiguration.class).run((context) -> { EmptyConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(Cluster.class); assertThat(context).hasSingleBean(Cluster.class);
assertThat(getInitialEntitySet(context)).hasSize(1) assertThat(getInitialEntitySet(context)).hasSize(1)
@ -79,7 +79,7 @@ public class CassandraRepositoriesAutoConfigurationTests {
@Test @Test
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
this.runner.withUserConfiguration(TestExcludeConfiguration.class, this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class,
CustomizedConfiguration.class).run((context) -> { CustomizedConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(CityCassandraRepository.class); assertThat(context).hasSingleBean(CityCassandraRepository.class);
assertThat(getInitialEntitySet(context)).hasSize(1) assertThat(getInitialEntitySet(context)).hasSize(1)
@ -89,7 +89,7 @@ public class CassandraRepositoriesAutoConfigurationTests {
@Test @Test
public void enablingReactiveRepositoriesDisablesImperativeRepositories() { public void enablingReactiveRepositoriesDisablesImperativeRepositories() {
this.runner.withUserConfiguration(TestConfiguration.class) this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withPropertyValues("spring.data.cassandra.repositories.type=reactive") .withPropertyValues("spring.data.cassandra.repositories.type=reactive")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(CityCassandraRepository.class)); .doesNotHaveBean(CityCassandraRepository.class));
@ -97,7 +97,7 @@ public class CassandraRepositoriesAutoConfigurationTests {
@Test @Test
public void enablingNoRepositoriesDisablesImperativeRepositories() { public void enablingNoRepositoriesDisablesImperativeRepositories() {
this.runner.withUserConfiguration(TestConfiguration.class) this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withPropertyValues("spring.data.cassandra.repositories.type=none") .withPropertyValues("spring.data.cassandra.repositories.type=none")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(CityCassandraRepository.class)); .doesNotHaveBean(CityCassandraRepository.class));

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class MongoReactiveRepositoriesAutoConfigurationTests { public class MongoReactiveRepositoriesAutoConfigurationTests {
private final ApplicationContextRunner runner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class, .withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class,
MongoDataAutoConfiguration.class, MongoDataAutoConfiguration.class,
MongoReactiveAutoConfiguration.class, MongoReactiveAutoConfiguration.class,
@ -58,7 +58,7 @@ public class MongoReactiveRepositoriesAutoConfigurationTests {
@Test @Test
public void testDefaultRepositoryConfiguration() { public void testDefaultRepositoryConfiguration() {
this.runner.withUserConfiguration(TestConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(ReactiveCityRepository.class); assertThat(context).hasSingleBean(ReactiveCityRepository.class);
assertThat(context).hasSingleBean(MongoClient.class); assertThat(context).hasSingleBean(MongoClient.class);
MongoMappingContext mappingContext = context MongoMappingContext mappingContext = context
@ -72,27 +72,27 @@ public class MongoReactiveRepositoriesAutoConfigurationTests {
@Test @Test
public void testNoRepositoryConfiguration() { public void testNoRepositoryConfiguration() {
this.runner.withUserConfiguration(EmptyConfiguration.class) this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(MongoClient.class)); .run((context) -> assertThat(context).hasSingleBean(MongoClient.class));
} }
@Test @Test
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
this.runner.withUserConfiguration(CustomizedConfiguration.class) this.contextRunner.withUserConfiguration(CustomizedConfiguration.class)
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(ReactiveCityMongoDbRepository.class)); .doesNotHaveBean(ReactiveCityMongoDbRepository.class));
} }
@Test @Test
public void autoConfigurationShouldNotKickInEvenIfManualConfigDidNotCreateAnyRepositories() { public void autoConfigurationShouldNotKickInEvenIfManualConfigDidNotCreateAnyRepositories() {
this.runner.withUserConfiguration(SortOfInvalidCustomConfiguration.class) this.contextRunner.withUserConfiguration(SortOfInvalidCustomConfiguration.class)
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(ReactiveCityRepository.class)); .doesNotHaveBean(ReactiveCityRepository.class));
} }
@Test @Test
public void enablingImperativeRepositoriesDisablesReactiveRepositories() { public void enablingImperativeRepositoriesDisablesReactiveRepositories() {
this.runner.withUserConfiguration(TestConfiguration.class) this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withPropertyValues("spring.data.mongodb.repositories.type=imperative") .withPropertyValues("spring.data.mongodb.repositories.type=imperative")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(ReactiveCityRepository.class)); .doesNotHaveBean(ReactiveCityRepository.class));
@ -100,7 +100,7 @@ public class MongoReactiveRepositoriesAutoConfigurationTests {
@Test @Test
public void enablingNoRepositoriesDisablesReactiveRepositories() { public void enablingNoRepositoriesDisablesReactiveRepositories() {
this.runner.withUserConfiguration(TestConfiguration.class) this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withPropertyValues("spring.data.mongodb.repositories.type=none") .withPropertyValues("spring.data.mongodb.repositories.type=none")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(ReactiveCityRepository.class)); .doesNotHaveBean(ReactiveCityRepository.class));

@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class MongoRepositoriesAutoConfigurationTests { public class MongoRepositoriesAutoConfigurationTests {
private final ApplicationContextRunner runner = new ApplicationContextRunner() private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class, .withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class,
MongoDataAutoConfiguration.class, MongoDataAutoConfiguration.class,
MongoRepositoriesAutoConfiguration.class, MongoRepositoriesAutoConfiguration.class,
@ -53,7 +53,7 @@ public class MongoRepositoriesAutoConfigurationTests {
@Test @Test
public void testDefaultRepositoryConfiguration() { public void testDefaultRepositoryConfiguration() {
this.runner.withUserConfiguration(TestConfiguration.class).run((context) -> { this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(CityRepository.class); assertThat(context).hasSingleBean(CityRepository.class);
assertThat(context).hasSingleBean(MongoClient.class); assertThat(context).hasSingleBean(MongoClient.class);
MongoMappingContext mappingContext = context MongoMappingContext mappingContext = context
@ -67,26 +67,26 @@ public class MongoRepositoriesAutoConfigurationTests {
@Test @Test
public void testNoRepositoryConfiguration() { public void testNoRepositoryConfiguration() {
this.runner.withUserConfiguration(EmptyConfiguration.class) this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(MongoClient.class)); .run((context) -> assertThat(context).hasSingleBean(MongoClient.class));
} }
@Test @Test
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() { public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
this.runner.withUserConfiguration(CustomizedConfiguration.class) this.contextRunner.withUserConfiguration(CustomizedConfiguration.class)
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.hasSingleBean(CityMongoDbRepository.class)); .hasSingleBean(CityMongoDbRepository.class));
} }
@Test @Test
public void autoConfigurationShouldNotKickInEvenIfManualConfigDidNotCreateAnyRepositories() { public void autoConfigurationShouldNotKickInEvenIfManualConfigDidNotCreateAnyRepositories() {
this.runner.withUserConfiguration(SortOfInvalidCustomConfiguration.class).run( this.contextRunner.withUserConfiguration(SortOfInvalidCustomConfiguration.class).run(
(context) -> assertThat(context).doesNotHaveBean(CityRepository.class)); (context) -> assertThat(context).doesNotHaveBean(CityRepository.class));
} }
@Test @Test
public void enablingReactiveRepositoriesDisablesImperativeRepositories() { public void enablingReactiveRepositoriesDisablesImperativeRepositories() {
this.runner.withUserConfiguration(TestConfiguration.class) this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withPropertyValues("spring.data.mongodb.repositories.type=reactive") .withPropertyValues("spring.data.mongodb.repositories.type=reactive")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(CityRepository.class)); .doesNotHaveBean(CityRepository.class));
@ -94,7 +94,7 @@ public class MongoRepositoriesAutoConfigurationTests {
@Test @Test
public void enablingNoRepositoriesDisablesImperativeRepositories() { public void enablingNoRepositoriesDisablesImperativeRepositories() {
this.runner.withUserConfiguration(TestConfiguration.class) this.contextRunner.withUserConfiguration(TestConfiguration.class)
.withPropertyValues("spring.data.mongodb.repositories.type=none") .withPropertyValues("spring.data.mongodb.repositories.type=none")
.run((context) -> assertThat(context) .run((context) -> assertThat(context)
.doesNotHaveBean(CityRepository.class)); .doesNotHaveBean(CityRepository.class));

@ -66,10 +66,8 @@ public class RedisAutoConfigurationTests {
@Test @Test
public void testOverrideRedisConfiguration() { public void testOverrideRedisConfiguration() {
this.contextRunner this.contextRunner.withPropertyValues("spring.redis.host:foo",
.withPropertyValues("spring.redis.host:foo", "spring.redis.database:1", "spring.redis.lettuce.shutdown-timeout:500")
"spring.redis.database:1",
"spring.redis.lettuce.shutdown-timeout:500")
.run((context) -> { .run((context) -> {
LettuceConnectionFactory cf = context LettuceConnectionFactory cf = context
.getBean(LettuceConnectionFactory.class); .getBean(LettuceConnectionFactory.class);
@ -83,8 +81,7 @@ public class RedisAutoConfigurationTests {
@Test @Test
public void testCustomizeRedisConfiguration() { public void testCustomizeRedisConfiguration() {
this.contextRunner this.contextRunner.withUserConfiguration(CustomConfiguration.class)
.withUserConfiguration(CustomConfiguration.class)
.run((context) -> { .run((context) -> {
LettuceConnectionFactory cf = context LettuceConnectionFactory cf = context
.getBean(LettuceConnectionFactory.class); .getBean(LettuceConnectionFactory.class);
@ -125,19 +122,17 @@ public class RedisAutoConfigurationTests {
@Test @Test
public void testRedisConfigurationWithPool() { public void testRedisConfigurationWithPool() {
this.contextRunner this.contextRunner.withPropertyValues("spring.redis.host:foo",
.withPropertyValues("spring.redis.host:foo", "spring.redis.lettuce.pool.min-idle:1",
"spring.redis.lettuce.pool.min-idle:1", "spring.redis.lettuce.pool.max-idle:4",
"spring.redis.lettuce.pool.max-idle:4", "spring.redis.lettuce.pool.max-active:16",
"spring.redis.lettuce.pool.max-active:16", "spring.redis.lettuce.pool.max-wait:2000",
"spring.redis.lettuce.pool.max-wait:2000", "spring.redis.lettuce.shutdown-timeout:1000").run((context) -> {
"spring.redis.lettuce.shutdown-timeout:1000")
.run((context) -> {
LettuceConnectionFactory cf = context LettuceConnectionFactory cf = context
.getBean(LettuceConnectionFactory.class); .getBean(LettuceConnectionFactory.class);
assertThat(cf.getHostName()).isEqualTo("foo"); assertThat(cf.getHostName()).isEqualTo("foo");
GenericObjectPoolConfig poolConfig = GenericObjectPoolConfig poolConfig = getPoolingClientConfiguration(cf)
getPoolingClientConfiguration(cf).getPoolConfig(); .getPoolConfig();
assertThat(poolConfig.getMinIdle()).isEqualTo(1); assertThat(poolConfig.getMinIdle()).isEqualTo(1);
assertThat(poolConfig.getMaxIdle()).isEqualTo(4); assertThat(poolConfig.getMaxIdle()).isEqualTo(4);
assertThat(poolConfig.getMaxTotal()).isEqualTo(16); assertThat(poolConfig.getMaxTotal()).isEqualTo(16);
@ -149,8 +144,7 @@ public class RedisAutoConfigurationTests {
@Test @Test
public void testRedisConfigurationWithTimeout() { public void testRedisConfigurationWithTimeout() {
this.contextRunner this.contextRunner
.withPropertyValues("spring.redis.host:foo", .withPropertyValues("spring.redis.host:foo", "spring.redis.timeout:100")
"spring.redis.timeout:100")
.run((context) -> { .run((context) -> {
LettuceConnectionFactory cf = context LettuceConnectionFactory cf = context
.getBean(LettuceConnectionFactory.class); .getBean(LettuceConnectionFactory.class);
@ -183,10 +177,11 @@ public class RedisAutoConfigurationTests {
LettuceConnectionFactory connectionFactory = context LettuceConnectionFactory connectionFactory = context
.getBean(LettuceConnectionFactory.class); .getBean(LettuceConnectionFactory.class);
assertThat(connectionFactory.getPassword()).isEqualTo("password"); assertThat(connectionFactory.getPassword()).isEqualTo("password");
Set<RedisNode> sentinels = connectionFactory.getSentinelConfiguration() Set<RedisNode> sentinels = connectionFactory
.getSentinels(); .getSentinelConfiguration().getSentinels();
assertThat(sentinels.stream().map(Object::toString).collect(Collectors.toSet())) assertThat(sentinels.stream().map(Object::toString)
.contains("127.0.0.1:26379", "127.0.0.1:26380"); .collect(Collectors.toSet())).contains("127.0.0.1:26379",
"127.0.0.1:26380");
}); });
} }
@ -194,7 +189,8 @@ public class RedisAutoConfigurationTests {
public void testRedisConfigurationWithCluster() { public void testRedisConfigurationWithCluster() {
List<String> clusterNodes = Arrays.asList("127.0.0.1:27379", "127.0.0.1:27380"); List<String> clusterNodes = Arrays.asList("127.0.0.1:27379", "127.0.0.1:27380");
this.contextRunner this.contextRunner
.withPropertyValues("spring.redis.cluster.nodes[0]:" + clusterNodes.get(0), .withPropertyValues(
"spring.redis.cluster.nodes[0]:" + clusterNodes.get(0),
"spring.redis.cluster.nodes[1]:" + clusterNodes.get(1)) "spring.redis.cluster.nodes[1]:" + clusterNodes.get(1))
.run((context) -> { .run((context) -> {
assertThat(context.getBean(LettuceConnectionFactory.class) assertThat(context.getBean(LettuceConnectionFactory.class)
@ -211,8 +207,9 @@ public class RedisAutoConfigurationTests {
"spring.redis.cluster.nodes[0]:" + clusterNodes.get(0), "spring.redis.cluster.nodes[0]:" + clusterNodes.get(0),
"spring.redis.cluster.nodes[1]:" + clusterNodes.get(1)) "spring.redis.cluster.nodes[1]:" + clusterNodes.get(1))
.run((context) -> { .run((context) -> {
assertThat(context.getBean(LettuceConnectionFactory.class).getPassword()) assertThat(
.isEqualTo("password"); context.getBean(LettuceConnectionFactory.class).getPassword())
.isEqualTo("password");
}); });
} }

@ -34,8 +34,8 @@ import static org.assertj.core.api.Assertions.assertThat;
public class RedisReactiveAutoConfigurationTests { public class RedisReactiveAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations .withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class,
.of(RedisAutoConfiguration.class, RedisReactiveAutoConfiguration.class)); RedisReactiveAutoConfiguration.class));
@Test @Test
public void testDefaultRedisConfiguration() { public void testDefaultRedisConfiguration() {

@ -59,8 +59,8 @@ import static org.mockito.Mockito.mock;
public class JestAutoConfigurationTests { public class JestAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations .withConfiguration(AutoConfigurations.of(GsonAutoConfiguration.class,
.of(GsonAutoConfiguration.class, JestAutoConfiguration.class)); JestAutoConfiguration.class));
@Before @Before
public void preventElasticsearchFromConfiguringNetty() { public void preventElasticsearchFromConfiguringNetty() {
@ -81,32 +81,34 @@ public class JestAutoConfigurationTests {
@Test @Test
public void customJestClient() { public void customJestClient() {
this.contextRunner this.contextRunner.withUserConfiguration(CustomJestClient.class)
.withUserConfiguration(CustomJestClient.class) .withPropertyValues(
.withPropertyValues("spring.elasticsearch.jest.uris[0]=http://localhost:9200") "spring.elasticsearch.jest.uris[0]=http://localhost:9200")
.run((context) -> { .run((context) -> {
assertThat(context.getBeansOfType(JestClient.class)).hasSize(1); assertThat(context.getBeansOfType(JestClient.class)).hasSize(1);
}); });
} }
@Test @Test
public void customGson() { public void customGson() {
this.contextRunner this.contextRunner.withUserConfiguration(CustomGson.class)
.withUserConfiguration(CustomGson.class) .withPropertyValues(
.withPropertyValues("spring.elasticsearch.jest.uris=http://localhost:9200") "spring.elasticsearch.jest.uris=http://localhost:9200")
.run((context) -> { .run((context) -> {
JestHttpClient client = (JestHttpClient) context.getBean(JestClient.class); JestHttpClient client = (JestHttpClient) context
.getBean(JestClient.class);
assertThat(client.getGson()).isSameAs(context.getBean("customGson")); assertThat(client.getGson()).isSameAs(context.getBean("customGson"));
}); });
} }
@Test @Test
public void customizerOverridesAutoConfig() { public void customizerOverridesAutoConfig() {
this.contextRunner this.contextRunner.withUserConfiguration(BuilderCustomizer.class)
.withUserConfiguration(BuilderCustomizer.class) .withPropertyValues(
.withPropertyValues("spring.elasticsearch.jest.uris=http://localhost:9200") "spring.elasticsearch.jest.uris=http://localhost:9200")
.run((context) -> { .run((context) -> {
JestHttpClient client = (JestHttpClient) context.getBean(JestClient.class); JestHttpClient client = (JestHttpClient) context
.getBean(JestClient.class);
assertThat(client.getGson()) assertThat(client.getGson())
.isSameAs(context.getBean(BuilderCustomizer.class).getGson()); .isSameAs(context.getBean(BuilderCustomizer.class).getGson());
}); });
@ -115,37 +117,36 @@ public class JestAutoConfigurationTests {
@Test @Test
public void proxyHostWithoutPort() { public void proxyHostWithoutPort() {
this.contextRunner this.contextRunner
.withPropertyValues("spring.elasticsearch.jest.uris=http://localhost:9200", .withPropertyValues(
"spring.elasticsearch.jest.proxy.host=proxy.example.com") "spring.elasticsearch.jest.uris=http://localhost:9200",
.run((context) -> { "spring.elasticsearch.jest.proxy.host=proxy.example.com")
assertThat(context.getStartupFailure()) .run((context) -> {
.isInstanceOf(BeanCreationException.class) assertThat(context.getStartupFailure())
.hasMessageContaining("Proxy port must not be null"); .isInstanceOf(BeanCreationException.class)
}); .hasMessageContaining("Proxy port must not be null");
});
} }
@Test @Test
public void jestCanCommunicateWithElasticsearchInstance() { public void jestCanCommunicateWithElasticsearchInstance() {
new ElasticsearchNodeTemplate().doWithNode((node) -> new ElasticsearchNodeTemplate().doWithNode((node) -> this.contextRunner
this.contextRunner .withPropertyValues("spring.elasticsearch.jest.uris=http://localhost:"
.withPropertyValues("spring.elasticsearch.jest.uris=http://localhost:" + node.getHttpPort())
+ node.getHttpPort()) .run((context) -> {
.run((context) -> { JestClient client = context.getBean(JestClient.class);
JestClient client = context.getBean(JestClient.class); Map<String, String> source = new HashMap<>();
Map<String, String> source = new HashMap<>(); source.put("a", "alpha");
source.put("a", "alpha"); source.put("b", "bravo");
source.put("b", "bravo"); Index index = new Index.Builder(source).index("foo").type("bar")
Index index = new Index.Builder(source).index("foo").type("bar").build(); .build();
execute(client, index); execute(client, index);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.matchQuery("a", "alpha")); searchSourceBuilder.query(QueryBuilders.matchQuery("a", "alpha"));
assertThat( assertThat(execute(client,
execute(client, new Search.Builder(searchSourceBuilder.toString())
new Search.Builder(searchSourceBuilder.toString()) .addIndex("foo").build()).getResponseCode())
.addIndex("foo").build()).getResponseCode()) .isEqualTo(200);
.isEqualTo(200); }));
})
);
} }
private JestResult execute(JestClient client, Action<? extends JestResult> action) { private JestResult execute(JestClient client, Action<? extends JestResult> action) {

@ -38,9 +38,9 @@ import static org.assertj.core.api.Assertions.assertThat;
public class ProjectInfoAutoConfigurationTests { public class ProjectInfoAutoConfigurationTests {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, .withConfiguration(
ProjectInfoAutoConfiguration.class)); AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
ProjectInfoAutoConfiguration.class));
@Test @Test
public void gitPropertiesUnavailableIfResourceNotAvailable() { public void gitPropertiesUnavailableIfResourceNotAvailable() {
@ -51,9 +51,9 @@ public class ProjectInfoAutoConfigurationTests {
@Test @Test
public void gitPropertiesWithNoData() { public void gitPropertiesWithNoData() {
this.contextRunner.withPropertyValues( this.contextRunner
"spring.info.git.location=" + .withPropertyValues("spring.info.git.location="
"classpath:/org/springframework/boot/autoconfigure/info/git-no-data.properties") + "classpath:/org/springframework/boot/autoconfigure/info/git-no-data.properties")
.run((context) -> { .run((context) -> {
GitProperties gitProperties = context.getBean(GitProperties.class); GitProperties gitProperties = context.getBean(GitProperties.class);
assertThat(gitProperties.getBranch()).isNull(); assertThat(gitProperties.getBranch()).isNull();
@ -63,11 +63,12 @@ public class ProjectInfoAutoConfigurationTests {
@Test @Test
public void gitPropertiesFallbackWithGitPropertiesBean() { public void gitPropertiesFallbackWithGitPropertiesBean() {
this.contextRunner.withUserConfiguration(CustomInfoPropertiesConfiguration.class) this.contextRunner.withUserConfiguration(CustomInfoPropertiesConfiguration.class)
.withPropertyValues("spring.info.git.location=" + .withPropertyValues("spring.info.git.location="
"classpath:/org/springframework/boot/autoconfigure/info/git.properties") + "classpath:/org/springframework/boot/autoconfigure/info/git.properties")
.run((context) -> { .run((context) -> {
GitProperties gitProperties = context.getBean(GitProperties.class); GitProperties gitProperties = context.getBean(GitProperties.class);
assertThat(gitProperties).isSameAs(context.getBean("customGitProperties")); assertThat(gitProperties)
.isSameAs(context.getBean("customGitProperties"));
}); });
} }
@ -79,30 +80,33 @@ public class ProjectInfoAutoConfigurationTests {
assertThat(buildProperties.getArtifact()).isEqualTo("demo"); assertThat(buildProperties.getArtifact()).isEqualTo("demo");
assertThat(buildProperties.getName()).isEqualTo("Demo Project"); assertThat(buildProperties.getName()).isEqualTo("Demo Project");
assertThat(buildProperties.getVersion()).isEqualTo("0.0.1-SNAPSHOT"); assertThat(buildProperties.getVersion()).isEqualTo("0.0.1-SNAPSHOT");
assertThat(buildProperties.getTime().toEpochMilli()).isEqualTo(1457100965000L); assertThat(buildProperties.getTime().toEpochMilli())
.isEqualTo(1457100965000L);
}); });
} }
@Test @Test
public void buildPropertiesCustomLocation() { public void buildPropertiesCustomLocation() {
this.contextRunner this.contextRunner
.withPropertyValues("spring.info.build.location=" + .withPropertyValues("spring.info.build.location="
"classpath:/org/springframework/boot/autoconfigure/info/build-info.properties") + "classpath:/org/springframework/boot/autoconfigure/info/build-info.properties")
.run((context) -> { .run((context) -> {
BuildProperties buildProperties = context.getBean(BuildProperties.class); BuildProperties buildProperties = context
.getBean(BuildProperties.class);
assertThat(buildProperties.getGroup()).isEqualTo("com.example.acme"); assertThat(buildProperties.getGroup()).isEqualTo("com.example.acme");
assertThat(buildProperties.getArtifact()).isEqualTo("acme"); assertThat(buildProperties.getArtifact()).isEqualTo("acme");
assertThat(buildProperties.getName()).isEqualTo("acme"); assertThat(buildProperties.getName()).isEqualTo("acme");
assertThat(buildProperties.getVersion()).isEqualTo("1.0.1-SNAPSHOT"); assertThat(buildProperties.getVersion()).isEqualTo("1.0.1-SNAPSHOT");
assertThat(buildProperties.getTime().toEpochMilli()).isEqualTo(1457088120000L); assertThat(buildProperties.getTime().toEpochMilli())
.isEqualTo(1457088120000L);
}); });
} }
@Test @Test
public void buildPropertiesCustomInvalidLocation() { public void buildPropertiesCustomInvalidLocation() {
this.contextRunner this.contextRunner
.withPropertyValues("spring.info.build.location=" + .withPropertyValues("spring.info.build.location="
"classpath:/org/acme/no-build-info.properties") + "classpath:/org/acme/no-build-info.properties")
.run((context) -> { .run((context) -> {
assertThat(context.getBeansOfType(BuildProperties.class)).hasSize(0); assertThat(context.getBeansOfType(BuildProperties.class)).hasSize(0);
}); });
@ -110,10 +114,10 @@ public class ProjectInfoAutoConfigurationTests {
@Test @Test
public void buildPropertiesFallbackWithBuildInfoBean() { public void buildPropertiesFallbackWithBuildInfoBean() {
this.contextRunner this.contextRunner.withUserConfiguration(CustomInfoPropertiesConfiguration.class)
.withUserConfiguration(CustomInfoPropertiesConfiguration.class)
.run((context) -> { .run((context) -> {
BuildProperties buildProperties = context.getBean(BuildProperties.class); BuildProperties buildProperties = context
.getBean(BuildProperties.class);
assertThat(buildProperties) assertThat(buildProperties)
.isSameAs(context.getBean("customBuildProperties")); .isSameAs(context.getBean("customBuildProperties"));
}); });

@ -54,8 +54,7 @@ public class HikariDataSourceConfigurationTests {
public void testDataSourcePropertiesOverridden() { public void testDataSourcePropertiesOverridden() {
this.contextRunner.withPropertyValues( this.contextRunner.withPropertyValues(
"spring.datasource.hikari.jdbc-url=jdbc:foo//bar/spam", "spring.datasource.hikari.jdbc-url=jdbc:foo//bar/spam",
"spring.datasource.hikari.max-lifetime=1234") "spring.datasource.hikari.max-lifetime=1234").run((context) -> {
.run((context) -> {
HikariDataSource ds = context.getBean(HikariDataSource.class); HikariDataSource ds = context.getBean(HikariDataSource.class);
assertThat(ds.getJdbcUrl()).isEqualTo("jdbc:foo//bar/spam"); assertThat(ds.getJdbcUrl()).isEqualTo("jdbc:foo//bar/spam");
assertThat(ds.getMaxLifetime()).isEqualTo(1234); assertThat(ds.getMaxLifetime()).isEqualTo(1234);
@ -65,13 +64,14 @@ public class HikariDataSourceConfigurationTests {
@Test @Test
public void testDataSourceGenericPropertiesOverridden() { public void testDataSourceGenericPropertiesOverridden() {
this.contextRunner.withPropertyValues( this.contextRunner
"spring.datasource.hikari.data-source-properties" + .withPropertyValues("spring.datasource.hikari.data-source-properties"
".dataSourceClassName=org.h2.JDBCDataSource") + ".dataSourceClassName=org.h2.JDBCDataSource")
.run((context) -> { .run((context) -> {
HikariDataSource ds = context.getBean(HikariDataSource.class); HikariDataSource ds = context.getBean(HikariDataSource.class);
assertThat(ds.getDataSourceProperties().getProperty("dataSourceClassName")) assertThat(ds.getDataSourceProperties()
.isEqualTo("org.h2.JDBCDataSource"); .getProperty("dataSourceClassName"))
.isEqualTo("org.h2.JDBCDataSource");
}); });
} }
@ -96,9 +96,9 @@ public class HikariDataSourceConfigurationTests {
@Test @Test
public void poolNameTakesPrecedenceOverName() { public void poolNameTakesPrecedenceOverName() {
this.contextRunner.withPropertyValues( this.contextRunner
"spring.datasource.name=myDS", .withPropertyValues("spring.datasource.name=myDS",
"spring.datasource.hikari.pool-name=myHikariDS") "spring.datasource.hikari.pool-name=myHikariDS")
.run((context) -> { .run((context) -> {
HikariDataSource ds = context.getBean(HikariDataSource.class); HikariDataSource ds = context.getBean(HikariDataSource.class);
assertThat(ds.getPoolName()).isEqualTo("myHikariDS"); assertThat(ds.getPoolName()).isEqualTo("myHikariDS");

@ -57,13 +57,10 @@ import static org.junit.Assert.fail;
*/ */
public class JooqAutoConfigurationTests { public class JooqAutoConfigurationTests {
private static final String[] NO_BEANS = {};
private ApplicationContextRunner contextRunner = new ApplicationContextRunner() private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class)) .withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class))
.withPropertyValues("spring.datasource.name:jooqtest"); .withPropertyValues("spring.datasource.name:jooqtest");
@Rule @Rule
public ExpectedException thrown = ExpectedException.none(); public ExpectedException thrown = ExpectedException.none();
@ -76,13 +73,10 @@ public class JooqAutoConfigurationTests {
@Test @Test
public void jooqWithoutTx() { public void jooqWithoutTx() {
this.contextRunner this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class)
.withUserConfiguration(JooqDataSourceConfiguration.class)
.run((context) -> { .run((context) -> {
assertThat(context.getBeanNamesForType( assertThat(context).doesNotHaveBean(PlatformTransactionManager.class);
PlatformTransactionManager.class)).isEqualTo(NO_BEANS); assertThat(context).doesNotHaveBean(SpringTransactionProvider.class);
assertThat(context.getBeanNamesForType(
SpringTransactionProvider.class)).isEqualTo(NO_BEANS);
DSLContext dsl = context.getBean(DSLContext.class); DSLContext dsl = context.getBean(DSLContext.class);
dsl.execute("create table jooqtest (name varchar(255) primary key);"); dsl.execute("create table jooqtest (name varchar(255) primary key);");
dsl.transaction(new AssertFetch(dsl, dsl.transaction(new AssertFetch(dsl,
@ -92,31 +86,29 @@ public class JooqAutoConfigurationTests {
dsl.transaction(new AssertFetch(dsl, dsl.transaction(new AssertFetch(dsl,
"select count(*) as total from jooqtest;", "1")); "select count(*) as total from jooqtest;", "1"));
try { try {
dsl.transaction( dsl.transaction(new ExecuteSql(dsl,
new ExecuteSql(dsl, "insert into jooqtest (name) values ('bar');",
"insert into jooqtest (name) values ('bar');", "insert into jooqtest (name) values ('foo');"));
"insert into jooqtest (name) values ('foo');"));
fail("An DataIntegrityViolationException should have been thrown."); fail("An DataIntegrityViolationException should have been thrown.");
} }
catch (DataIntegrityViolationException ex) { catch (DataIntegrityViolationException ex) {
// Ignore // Ignore
} }
dsl.transaction( dsl.transaction(new AssertFetch(dsl,
new AssertFetch(dsl, "select count(*) as total from jooqtest;", "2"));
"select count(*) as total from jooqtest;", "2"));
}); });
} }
@Test @Test
public void jooqWithTx() { public void jooqWithTx() {
this.contextRunner this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class,
.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class) TxManagerConfiguration.class).run((context) -> {
.run((context) -> { assertThat(context).hasSingleBean(PlatformTransactionManager.class);
context.getBean(PlatformTransactionManager.class);
DSLContext dsl = context.getBean(DSLContext.class); DSLContext dsl = context.getBean(DSLContext.class);
assertThat(dsl.configuration().dialect()).isEqualTo(SQLDialect.HSQLDB); assertThat(dsl.configuration().dialect())
dsl.execute("create table jooqtest_tx (name varchar(255) primary key);"); .isEqualTo(SQLDialect.HSQLDB);
dsl.execute(
"create table jooqtest_tx (name varchar(255) primary key);");
dsl.transaction(new AssertFetch(dsl, dsl.transaction(new AssertFetch(dsl,
"select count(*) as total from jooqtest_tx;", "0")); "select count(*) as total from jooqtest_tx;", "0"));
dsl.transaction(new ExecuteSql(dsl, dsl.transaction(new ExecuteSql(dsl,
@ -124,45 +116,44 @@ public class JooqAutoConfigurationTests {
dsl.transaction(new AssertFetch(dsl, dsl.transaction(new AssertFetch(dsl,
"select count(*) as total from jooqtest_tx;", "1")); "select count(*) as total from jooqtest_tx;", "1"));
try { try {
dsl.transaction( dsl.transaction(new ExecuteSql(dsl,
new ExecuteSql(dsl, "insert into jooqtest (name) values ('bar');", "insert into jooqtest (name) values ('bar');",
"insert into jooqtest (name) values ('foo');")); "insert into jooqtest (name) values ('foo');"));
fail("A DataIntegrityViolationException should have been thrown."); fail("A DataIntegrityViolationException should have been thrown.");
} }
catch (DataIntegrityViolationException ex) { catch (DataIntegrityViolationException ex) {
// Ignore // Ignore
} }
dsl.transaction( dsl.transaction(new AssertFetch(dsl,
new AssertFetch(dsl, "select count(*) as total from jooqtest_tx;", "1"));
"select count(*) as total from jooqtest_tx;", "1"));
}); });
} }
@Test @Test
public void customProvidersArePickedUp() { public void customProvidersArePickedUp() {
this.contextRunner this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class,
.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class, TxManagerConfiguration.class, TestRecordMapperProvider.class,
TestRecordMapperProvider.class, TestRecordListenerProvider.class, TestRecordListenerProvider.class, TestExecuteListenerProvider.class,
TestExecuteListenerProvider.class, TestVisitListenerProvider.class) TestVisitListenerProvider.class).run((context) -> {
.run((context) -> {
DSLContext dsl = context.getBean(DSLContext.class); DSLContext dsl = context.getBean(DSLContext.class);
assertThat(dsl.configuration().recordMapperProvider().getClass()) assertThat(dsl.configuration().recordMapperProvider().getClass())
.isEqualTo(TestRecordMapperProvider.class); .isEqualTo(TestRecordMapperProvider.class);
assertThat(dsl.configuration().recordListenerProviders().length).isEqualTo(1); assertThat(dsl.configuration().recordListenerProviders().length)
assertThat(dsl.configuration().executeListenerProviders().length).isEqualTo(2); .isEqualTo(1);
assertThat(dsl.configuration().visitListenerProviders().length).isEqualTo(1); assertThat(dsl.configuration().executeListenerProviders().length)
.isEqualTo(2);
assertThat(dsl.configuration().visitListenerProviders().length)
.isEqualTo(1);
}); });
} }
@Test @Test
public void relaxedBindingOfSqlDialect() { public void relaxedBindingOfSqlDialect() {
this.contextRunner this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class)
.withUserConfiguration(JooqDataSourceConfiguration.class) .withPropertyValues("spring.jooq.sql-dialect:PoSTGrES").run((context) -> {
.withPropertyValues("spring.jooq.sql-dialect:PoSTGrES") assertThat(context.getBean(org.jooq.Configuration.class).dialect())
.run((context) -> { .isEqualTo(SQLDialect.POSTGRES);
assertThat(context.getBean(org.jooq.Configuration.class)
.dialect()).isEqualTo(SQLDialect.POSTGRES);
}); });
} }

@ -41,8 +41,8 @@ public class LdapAutoConfigurationTests {
public void contextSourceWithDefaultUrl() { public void contextSourceWithDefaultUrl() {
this.contextRunner.run(context -> { this.contextRunner.run(context -> {
LdapContextSource contextSource = context.getBean(LdapContextSource.class); LdapContextSource contextSource = context.getBean(LdapContextSource.class);
String[] urls = (String[]) ReflectionTestUtils String[] urls = (String[]) ReflectionTestUtils.getField(contextSource,
.getField(contextSource, "urls"); "urls");
assertThat(urls).containsExactly("ldap://localhost:389"); assertThat(urls).containsExactly("ldap://localhost:389");
assertThat(contextSource.isAnonymousReadOnly()).isFalse(); assertThat(contextSource.isAnonymousReadOnly()).isFalse();
}); });
@ -53,8 +53,8 @@ public class LdapAutoConfigurationTests {
this.contextRunner.withPropertyValues("spring.ldap.urls:ldap://localhost:123") this.contextRunner.withPropertyValues("spring.ldap.urls:ldap://localhost:123")
.run(context -> { .run(context -> {
ContextSource contextSource = context.getBean(ContextSource.class); ContextSource contextSource = context.getBean(ContextSource.class);
String[] urls = (String[]) ReflectionTestUtils.getField( String[] urls = (String[]) ReflectionTestUtils.getField(contextSource,
contextSource, "urls"); "urls");
assertThat(urls).containsExactly("ldap://localhost:123"); assertThat(urls).containsExactly("ldap://localhost:123");
}); });
} }
@ -67,8 +67,8 @@ public class LdapAutoConfigurationTests {
.run(context -> { .run(context -> {
ContextSource contextSource = context.getBean(ContextSource.class); ContextSource contextSource = context.getBean(ContextSource.class);
LdapProperties ldapProperties = context.getBean(LdapProperties.class); LdapProperties ldapProperties = context.getBean(LdapProperties.class);
String[] urls = (String[]) ReflectionTestUtils.getField( String[] urls = (String[]) ReflectionTestUtils.getField(contextSource,
contextSource, "urls"); "urls");
assertThat(urls).containsExactly("ldap://localhost:123", assertThat(urls).containsExactly("ldap://localhost:123",
"ldap://mycompany:123"); "ldap://mycompany:123");
assertThat(ldapProperties.getUrls()).hasSize(2); assertThat(ldapProperties.getUrls()).hasSize(2);
@ -78,21 +78,19 @@ public class LdapAutoConfigurationTests {
@Test @Test
public void contextSourceWithExtraCustomization() { public void contextSourceWithExtraCustomization() {
this.contextRunner this.contextRunner
.withPropertyValues( .withPropertyValues("spring.ldap.urls:ldap://localhost:123",
"spring.ldap.urls:ldap://localhost:123", "spring.ldap.username:root", "spring.ldap.password:secret",
"spring.ldap.username:root",
"spring.ldap.password:secret",
"spring.ldap.anonymous-read-only:true", "spring.ldap.anonymous-read-only:true",
"spring.ldap.base:cn=SpringDevelopers", "spring.ldap.base:cn=SpringDevelopers",
"spring.ldap.baseEnvironment.java.naming.security.authentication:DIGEST-MD5") "spring.ldap.baseEnvironment.java.naming.security.authentication:DIGEST-MD5")
.run(context -> { .run(context -> {
LdapContextSource contextSource = context.getBean( LdapContextSource contextSource = context
LdapContextSource.class); .getBean(LdapContextSource.class);
assertThat(contextSource.getUserDn()).isEqualTo("root"); assertThat(contextSource.getUserDn()).isEqualTo("root");
assertThat(contextSource.getPassword()).isEqualTo("secret"); assertThat(contextSource.getPassword()).isEqualTo("secret");
assertThat(contextSource.isAnonymousReadOnly()).isTrue(); assertThat(contextSource.isAnonymousReadOnly()).isTrue();
assertThat(contextSource.getBaseLdapPathAsString()).isEqualTo( assertThat(contextSource.getBaseLdapPathAsString())
"cn=SpringDevelopers"); .isEqualTo("cn=SpringDevelopers");
LdapProperties ldapProperties = context.getBean(LdapProperties.class); LdapProperties ldapProperties = context.getBean(LdapProperties.class);
assertThat(ldapProperties.getBaseEnvironment()).containsEntry( assertThat(ldapProperties.getBaseEnvironment()).containsEntry(
"java.naming.security.authentication", "DIGEST-MD5"); "java.naming.security.authentication", "DIGEST-MD5");

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

Loading…
Cancel
Save