Polish
This commit is contained in:
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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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 {
|
||||
|
||||
private final ApplicationContextRunner runner = new ApplicationContextRunner()
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(BaseConfiguration.class);
|
||||
|
||||
@Test
|
||||
|
@ -137,7 +137,7 @@ public class ScheduledTasksEndpointTests {
|
|||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.servlet.FilterRegistration;
|
||||
import javax.servlet.ServletContext;
|
||||
|
@ -47,6 +48,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.mock.web.MockServletConfig;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.reactive.config.EnableWebFlux;
|
||||
|
@ -68,8 +70,8 @@ import static org.mockito.Mockito.mock;
|
|||
*/
|
||||
public class MappingsEndpointTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void servletWebMappings() {
|
||||
ServletContext servletContext = mock(ServletContext.class);
|
||||
given(servletContext.getInitParameterNames())
|
||||
|
@ -82,49 +84,51 @@ public class MappingsEndpointTests {
|
|||
ServletRegistration servletRegistration = mock(ServletRegistration.class);
|
||||
given((Map<String, ServletRegistration>) servletContext.getServletRegistrations())
|
||||
.willReturn(Collections.singletonMap("testServlet", servletRegistration));
|
||||
WebApplicationContextRunner runner = new WebApplicationContextRunner(() -> {
|
||||
Supplier<ConfigurableWebApplicationContext> contextSupplier = () -> {
|
||||
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||
context.setServletContext(servletContext);
|
||||
return context;
|
||||
}).withUserConfiguration(EndpointConfiguration.class,
|
||||
ServletWebConfiguration.class);
|
||||
runner.run((context) -> {
|
||||
ContextMappings contextMappings = contextMappings(context);
|
||||
assertThat(contextMappings.getParentId()).isNull();
|
||||
assertThat(contextMappings.getMappings())
|
||||
.containsOnlyKeys("dispatcherServlets", "servletFilters", "servlets");
|
||||
Map<String, List<DispatcherServletMappingDescription>> dispatcherServlets = mappings(
|
||||
contextMappings, "dispatcherServlets");
|
||||
assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet");
|
||||
List<DispatcherServletMappingDescription> handlerMappings = dispatcherServlets
|
||||
.get("dispatcherServlet");
|
||||
assertThat(handlerMappings).hasSize(1);
|
||||
List<ServletRegistrationMappingDescription> servlets = mappings(
|
||||
contextMappings, "servlets");
|
||||
assertThat(servlets).hasSize(1);
|
||||
List<FilterRegistrationMappingDescription> filters = mappings(contextMappings,
|
||||
"servletFilters");
|
||||
assertThat(filters).hasSize(1);
|
||||
});
|
||||
};
|
||||
new WebApplicationContextRunner(contextSupplier)
|
||||
.withUserConfiguration(EndpointConfiguration.class,
|
||||
ServletWebConfiguration.class)
|
||||
.run((context) -> {
|
||||
ContextMappings contextMappings = contextMappings(context);
|
||||
assertThat(contextMappings.getParentId()).isNull();
|
||||
assertThat(contextMappings.getMappings()).containsOnlyKeys(
|
||||
"dispatcherServlets", "servletFilters", "servlets");
|
||||
Map<String, List<DispatcherServletMappingDescription>> dispatcherServlets = mappings(
|
||||
contextMappings, "dispatcherServlets");
|
||||
assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet");
|
||||
List<DispatcherServletMappingDescription> handlerMappings = dispatcherServlets
|
||||
.get("dispatcherServlet");
|
||||
assertThat(handlerMappings).hasSize(1);
|
||||
List<ServletRegistrationMappingDescription> servlets = mappings(
|
||||
contextMappings, "servlets");
|
||||
assertThat(servlets).hasSize(1);
|
||||
List<FilterRegistrationMappingDescription> filters = mappings(
|
||||
contextMappings, "servletFilters");
|
||||
assertThat(filters).hasSize(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reactiveWebMappings() {
|
||||
ReactiveWebApplicationContextRunner runner = new ReactiveWebApplicationContextRunner()
|
||||
new ReactiveWebApplicationContextRunner()
|
||||
.withUserConfiguration(EndpointConfiguration.class,
|
||||
ReactiveWebConfiguration.class);
|
||||
runner.run((context) -> {
|
||||
ContextMappings contextMappings = contextMappings(context);
|
||||
assertThat(contextMappings.getParentId()).isNull();
|
||||
assertThat(contextMappings.getMappings())
|
||||
.containsOnlyKeys("dispatcherHandlers");
|
||||
Map<String, List<DispatcherHandlerMappingDescription>> dispatcherHandlers = mappings(
|
||||
contextMappings, "dispatcherHandlers");
|
||||
assertThat(dispatcherHandlers).containsOnlyKeys("webHandler");
|
||||
List<DispatcherHandlerMappingDescription> handlerMappings = dispatcherHandlers
|
||||
.get("webHandler");
|
||||
assertThat(handlerMappings).hasSize(3);
|
||||
});
|
||||
ReactiveWebConfiguration.class)
|
||||
.run((context) -> {
|
||||
ContextMappings contextMappings = contextMappings(context);
|
||||
assertThat(contextMappings.getParentId()).isNull();
|
||||
assertThat(contextMappings.getMappings())
|
||||
.containsOnlyKeys("dispatcherHandlers");
|
||||
Map<String, List<DispatcherHandlerMappingDescription>> dispatcherHandlers = mappings(
|
||||
contextMappings, "dispatcherHandlers");
|
||||
assertThat(dispatcherHandlers).containsOnlyKeys("webHandler");
|
||||
List<DispatcherHandlerMappingDescription> handlerMappings = dispatcherHandlers
|
||||
.get("webHandler");
|
||||
assertThat(handlerMappings).hasSize(3);
|
||||
});
|
||||
}
|
||||
|
||||
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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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 {
|
||||
|
||||
private final ApplicationContextRunner runner = new ApplicationContextRunner();
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
|
||||
|
||||
@Test
|
||||
public void imperativeRepositoryMatchesWithNoConfiguredType() {
|
||||
this.runner.withUserConfiguration(ImperativeRepository.class)
|
||||
this.contextRunner.withUserConfiguration(ImperativeRepository.class)
|
||||
.run((context) -> assertThat(context)
|
||||
.hasSingleBean(ImperativeRepository.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reactiveRepositoryMatchesWithNoConfiguredType() {
|
||||
this.runner.withUserConfiguration(ReactiveRepository.class).run(
|
||||
this.contextRunner.withUserConfiguration(ReactiveRepository.class).run(
|
||||
(context) -> assertThat(context).hasSingleBean(ReactiveRepository.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void imperativeRepositoryMatchesWithAutoConfiguredType() {
|
||||
this.runner.withUserConfiguration(ImperativeRepository.class)
|
||||
this.contextRunner.withUserConfiguration(ImperativeRepository.class)
|
||||
.withPropertyValues("spring.data.test.repositories.type:auto")
|
||||
.run((context) -> assertThat(context)
|
||||
.hasSingleBean(ImperativeRepository.class));
|
||||
|
@ -55,7 +55,7 @@ public class ConditionalOnRepositoryTypeTests {
|
|||
|
||||
@Test
|
||||
public void reactiveRepositoryMatchesWithAutoConfiguredType() {
|
||||
this.runner.withUserConfiguration(ReactiveRepository.class)
|
||||
this.contextRunner.withUserConfiguration(ReactiveRepository.class)
|
||||
.withPropertyValues("spring.data.test.repositories.type:auto")
|
||||
.run((context) -> assertThat(context)
|
||||
.hasSingleBean(ReactiveRepository.class));
|
||||
|
@ -63,7 +63,7 @@ public class ConditionalOnRepositoryTypeTests {
|
|||
|
||||
@Test
|
||||
public void imperativeRepositoryMatchesWithImperativeConfiguredType() {
|
||||
this.runner.withUserConfiguration(ImperativeRepository.class)
|
||||
this.contextRunner.withUserConfiguration(ImperativeRepository.class)
|
||||
.withPropertyValues("spring.data.test.repositories.type:imperative")
|
||||
.run((context) -> assertThat(context)
|
||||
.hasSingleBean(ImperativeRepository.class));
|
||||
|
@ -71,7 +71,7 @@ public class ConditionalOnRepositoryTypeTests {
|
|||
|
||||
@Test
|
||||
public void reactiveRepositoryMatchesWithReactiveConfiguredType() {
|
||||
this.runner.withUserConfiguration(ReactiveRepository.class)
|
||||
this.contextRunner.withUserConfiguration(ReactiveRepository.class)
|
||||
.withPropertyValues("spring.data.test.repositories.type:reactive")
|
||||
.run((context) -> assertThat(context)
|
||||
.hasSingleBean(ReactiveRepository.class));
|
||||
|
@ -79,7 +79,7 @@ public class ConditionalOnRepositoryTypeTests {
|
|||
|
||||
@Test
|
||||
public void imperativeRepositoryDoesNotMatchWithReactiveConfiguredType() {
|
||||
this.runner.withUserConfiguration(ImperativeRepository.class)
|
||||
this.contextRunner.withUserConfiguration(ImperativeRepository.class)
|
||||
.withPropertyValues("spring.data.test.repositories.type:reactive")
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(ImperativeRepository.class));
|
||||
|
@ -87,7 +87,7 @@ public class ConditionalOnRepositoryTypeTests {
|
|||
|
||||
@Test
|
||||
public void reactiveRepositoryDoesNotMatchWithImperativeConfiguredType() {
|
||||
this.runner.withUserConfiguration(ReactiveRepository.class)
|
||||
this.contextRunner.withUserConfiguration(ReactiveRepository.class)
|
||||
.withPropertyValues("spring.data.test.repositories.type:imperative")
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(ReactiveRepository.class));
|
||||
|
@ -95,7 +95,7 @@ public class ConditionalOnRepositoryTypeTests {
|
|||
|
||||
@Test
|
||||
public void imperativeRepositoryDoesNotMatchWithNoneConfiguredType() {
|
||||
this.runner.withUserConfiguration(ImperativeRepository.class)
|
||||
this.contextRunner.withUserConfiguration(ImperativeRepository.class)
|
||||
.withPropertyValues("spring.data.test.repositories.type:none")
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(ImperativeRepository.class));
|
||||
|
@ -103,7 +103,7 @@ public class ConditionalOnRepositoryTypeTests {
|
|||
|
||||
@Test
|
||||
public void reactiveRepositoryDoesNotMatchWithNoneConfiguredType() {
|
||||
this.runner.withUserConfiguration(ReactiveRepository.class)
|
||||
this.contextRunner.withUserConfiguration(ReactiveRepository.class)
|
||||
.withPropertyValues("spring.data.test.repositories.type:none")
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(ReactiveRepository.class));
|
||||
|
@ -111,7 +111,7 @@ public class ConditionalOnRepositoryTypeTests {
|
|||
|
||||
@Test
|
||||
public void failsFastWhenConfiguredTypeIsUnknown() {
|
||||
this.runner.withUserConfiguration(ReactiveRepository.class)
|
||||
this.contextRunner.withUserConfiguration(ReactiveRepository.class)
|
||||
.withPropertyValues("spring.data.test.repositories.type:abcde")
|
||||
.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");
|
||||
* 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 {
|
||||
|
||||
private final ApplicationContextRunner runner = new ApplicationContextRunner()
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(CassandraAutoConfiguration.class,
|
||||
CassandraRepositoriesAutoConfiguration.class,
|
||||
CassandraDataAutoConfiguration.class,
|
||||
|
@ -65,16 +65,17 @@ public class CassandraReactiveRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testDefaultRepositoryConfiguration() {
|
||||
this.runner.withUserConfiguration(TestConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(ReactiveCityRepository.class);
|
||||
assertThat(context).hasSingleBean(Cluster.class);
|
||||
assertThat(getInitialEntitySet(context)).hasSize(1);
|
||||
});
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(ReactiveCityRepository.class);
|
||||
assertThat(context).hasSingleBean(Cluster.class);
|
||||
assertThat(getInitialEntitySet(context)).hasSize(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRepositoryConfiguration() {
|
||||
this.runner.withUserConfiguration(TestExcludeConfiguration.class,
|
||||
this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class,
|
||||
EmptyConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(Cluster.class);
|
||||
assertThat(getInitialEntitySet(context)).hasSize(1)
|
||||
|
@ -84,7 +85,7 @@ public class CassandraReactiveRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
|
||||
this.runner.withUserConfiguration(TestExcludeConfiguration.class,
|
||||
this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class,
|
||||
CustomizedConfiguration.class).run((context) -> {
|
||||
assertThat(context)
|
||||
.hasSingleBean(ReactiveCityCassandraRepository.class);
|
||||
|
@ -95,7 +96,7 @@ public class CassandraReactiveRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void enablingImperativeRepositoriesDisablesReactiveRepositories() {
|
||||
this.runner.withUserConfiguration(TestConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues("spring.data.cassandra.repositories.type=imperative")
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(ReactiveCityRepository.class));
|
||||
|
@ -103,7 +104,7 @@ public class CassandraReactiveRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void enablingNoRepositoriesDisablesReactiveRepositories() {
|
||||
this.runner.withUserConfiguration(TestConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues("spring.data.cassandra.repositories.type=none")
|
||||
.run((context) -> assertThat(context)
|
||||
.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");
|
||||
* 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 {
|
||||
|
||||
private final ApplicationContextRunner runner = new ApplicationContextRunner()
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(CassandraAutoConfiguration.class,
|
||||
CassandraRepositoriesAutoConfiguration.class,
|
||||
CassandraDataAutoConfiguration.class,
|
||||
|
@ -60,7 +60,7 @@ public class CassandraRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
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(Cluster.class);
|
||||
assertThat(getInitialEntitySet(context)).hasSize(1);
|
||||
|
@ -69,7 +69,7 @@ public class CassandraRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testNoRepositoryConfiguration() {
|
||||
this.runner.withUserConfiguration(TestExcludeConfiguration.class,
|
||||
this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class,
|
||||
EmptyConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(Cluster.class);
|
||||
assertThat(getInitialEntitySet(context)).hasSize(1)
|
||||
|
@ -79,7 +79,7 @@ public class CassandraRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
|
||||
this.runner.withUserConfiguration(TestExcludeConfiguration.class,
|
||||
this.contextRunner.withUserConfiguration(TestExcludeConfiguration.class,
|
||||
CustomizedConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(CityCassandraRepository.class);
|
||||
assertThat(getInitialEntitySet(context)).hasSize(1)
|
||||
|
@ -89,7 +89,7 @@ public class CassandraRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void enablingReactiveRepositoriesDisablesImperativeRepositories() {
|
||||
this.runner.withUserConfiguration(TestConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues("spring.data.cassandra.repositories.type=reactive")
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(CityCassandraRepository.class));
|
||||
|
@ -97,7 +97,7 @@ public class CassandraRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void enablingNoRepositoriesDisablesImperativeRepositories() {
|
||||
this.runner.withUserConfiguration(TestConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues("spring.data.cassandra.repositories.type=none")
|
||||
.run((context) -> assertThat(context)
|
||||
.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");
|
||||
* 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 {
|
||||
|
||||
private final ApplicationContextRunner runner = new ApplicationContextRunner()
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class,
|
||||
MongoDataAutoConfiguration.class,
|
||||
MongoReactiveAutoConfiguration.class,
|
||||
|
@ -58,7 +58,7 @@ public class MongoReactiveRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
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(MongoClient.class);
|
||||
MongoMappingContext mappingContext = context
|
||||
|
@ -72,27 +72,27 @@ public class MongoReactiveRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testNoRepositoryConfiguration() {
|
||||
this.runner.withUserConfiguration(EmptyConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(MongoClient.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
|
||||
this.runner.withUserConfiguration(CustomizedConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(CustomizedConfiguration.class)
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(ReactiveCityMongoDbRepository.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoConfigurationShouldNotKickInEvenIfManualConfigDidNotCreateAnyRepositories() {
|
||||
this.runner.withUserConfiguration(SortOfInvalidCustomConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(SortOfInvalidCustomConfiguration.class)
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(ReactiveCityRepository.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enablingImperativeRepositoriesDisablesReactiveRepositories() {
|
||||
this.runner.withUserConfiguration(TestConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues("spring.data.mongodb.repositories.type=imperative")
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(ReactiveCityRepository.class));
|
||||
|
@ -100,7 +100,7 @@ public class MongoReactiveRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void enablingNoRepositoriesDisablesReactiveRepositories() {
|
||||
this.runner.withUserConfiguration(TestConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues("spring.data.mongodb.repositories.type=none")
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(ReactiveCityRepository.class));
|
||||
|
|
|
@ -45,7 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*/
|
||||
public class MongoRepositoriesAutoConfigurationTests {
|
||||
|
||||
private final ApplicationContextRunner runner = new ApplicationContextRunner()
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(MongoAutoConfiguration.class,
|
||||
MongoDataAutoConfiguration.class,
|
||||
MongoRepositoriesAutoConfiguration.class,
|
||||
|
@ -53,7 +53,7 @@ public class MongoRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
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(MongoClient.class);
|
||||
MongoMappingContext mappingContext = context
|
||||
|
@ -67,26 +67,26 @@ public class MongoRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testNoRepositoryConfiguration() {
|
||||
this.runner.withUserConfiguration(EmptyConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(MongoClient.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
|
||||
this.runner.withUserConfiguration(CustomizedConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(CustomizedConfiguration.class)
|
||||
.run((context) -> assertThat(context)
|
||||
.hasSingleBean(CityMongoDbRepository.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoConfigurationShouldNotKickInEvenIfManualConfigDidNotCreateAnyRepositories() {
|
||||
this.runner.withUserConfiguration(SortOfInvalidCustomConfiguration.class).run(
|
||||
this.contextRunner.withUserConfiguration(SortOfInvalidCustomConfiguration.class).run(
|
||||
(context) -> assertThat(context).doesNotHaveBean(CityRepository.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enablingReactiveRepositoriesDisablesImperativeRepositories() {
|
||||
this.runner.withUserConfiguration(TestConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues("spring.data.mongodb.repositories.type=reactive")
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(CityRepository.class));
|
||||
|
@ -94,7 +94,7 @@ public class MongoRepositoriesAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void enablingNoRepositoriesDisablesImperativeRepositories() {
|
||||
this.runner.withUserConfiguration(TestConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||
.withPropertyValues("spring.data.mongodb.repositories.type=none")
|
||||
.run((context) -> assertThat(context)
|
||||
.doesNotHaveBean(CityRepository.class));
|
||||
|
|
|
@ -66,10 +66,8 @@ public class RedisAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testOverrideRedisConfiguration() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.redis.host:foo",
|
||||
"spring.redis.database:1",
|
||||
"spring.redis.lettuce.shutdown-timeout:500")
|
||||
this.contextRunner.withPropertyValues("spring.redis.host:foo",
|
||||
"spring.redis.database:1", "spring.redis.lettuce.shutdown-timeout:500")
|
||||
.run((context) -> {
|
||||
LettuceConnectionFactory cf = context
|
||||
.getBean(LettuceConnectionFactory.class);
|
||||
|
@ -83,8 +81,7 @@ public class RedisAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testCustomizeRedisConfiguration() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(CustomConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(CustomConfiguration.class)
|
||||
.run((context) -> {
|
||||
LettuceConnectionFactory cf = context
|
||||
.getBean(LettuceConnectionFactory.class);
|
||||
|
@ -125,19 +122,17 @@ public class RedisAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testRedisConfigurationWithPool() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.redis.host:foo",
|
||||
"spring.redis.lettuce.pool.min-idle:1",
|
||||
"spring.redis.lettuce.pool.max-idle:4",
|
||||
"spring.redis.lettuce.pool.max-active:16",
|
||||
"spring.redis.lettuce.pool.max-wait:2000",
|
||||
"spring.redis.lettuce.shutdown-timeout:1000")
|
||||
.run((context) -> {
|
||||
this.contextRunner.withPropertyValues("spring.redis.host:foo",
|
||||
"spring.redis.lettuce.pool.min-idle:1",
|
||||
"spring.redis.lettuce.pool.max-idle:4",
|
||||
"spring.redis.lettuce.pool.max-active:16",
|
||||
"spring.redis.lettuce.pool.max-wait:2000",
|
||||
"spring.redis.lettuce.shutdown-timeout:1000").run((context) -> {
|
||||
LettuceConnectionFactory cf = context
|
||||
.getBean(LettuceConnectionFactory.class);
|
||||
assertThat(cf.getHostName()).isEqualTo("foo");
|
||||
GenericObjectPoolConfig poolConfig =
|
||||
getPoolingClientConfiguration(cf).getPoolConfig();
|
||||
GenericObjectPoolConfig poolConfig = getPoolingClientConfiguration(cf)
|
||||
.getPoolConfig();
|
||||
assertThat(poolConfig.getMinIdle()).isEqualTo(1);
|
||||
assertThat(poolConfig.getMaxIdle()).isEqualTo(4);
|
||||
assertThat(poolConfig.getMaxTotal()).isEqualTo(16);
|
||||
|
@ -149,8 +144,7 @@ public class RedisAutoConfigurationTests {
|
|||
@Test
|
||||
public void testRedisConfigurationWithTimeout() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.redis.host:foo",
|
||||
"spring.redis.timeout:100")
|
||||
.withPropertyValues("spring.redis.host:foo", "spring.redis.timeout:100")
|
||||
.run((context) -> {
|
||||
LettuceConnectionFactory cf = context
|
||||
.getBean(LettuceConnectionFactory.class);
|
||||
|
@ -183,10 +177,11 @@ public class RedisAutoConfigurationTests {
|
|||
LettuceConnectionFactory connectionFactory = context
|
||||
.getBean(LettuceConnectionFactory.class);
|
||||
assertThat(connectionFactory.getPassword()).isEqualTo("password");
|
||||
Set<RedisNode> sentinels = connectionFactory.getSentinelConfiguration()
|
||||
.getSentinels();
|
||||
assertThat(sentinels.stream().map(Object::toString).collect(Collectors.toSet()))
|
||||
.contains("127.0.0.1:26379", "127.0.0.1:26380");
|
||||
Set<RedisNode> sentinels = connectionFactory
|
||||
.getSentinelConfiguration().getSentinels();
|
||||
assertThat(sentinels.stream().map(Object::toString)
|
||||
.collect(Collectors.toSet())).contains("127.0.0.1:26379",
|
||||
"127.0.0.1:26380");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -194,7 +189,8 @@ public class RedisAutoConfigurationTests {
|
|||
public void testRedisConfigurationWithCluster() {
|
||||
List<String> clusterNodes = Arrays.asList("127.0.0.1:27379", "127.0.0.1:27380");
|
||||
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))
|
||||
.run((context) -> {
|
||||
assertThat(context.getBean(LettuceConnectionFactory.class)
|
||||
|
@ -211,8 +207,9 @@ public class RedisAutoConfigurationTests {
|
|||
"spring.redis.cluster.nodes[0]:" + clusterNodes.get(0),
|
||||
"spring.redis.cluster.nodes[1]:" + clusterNodes.get(1))
|
||||
.run((context) -> {
|
||||
assertThat(context.getBean(LettuceConnectionFactory.class).getPassword())
|
||||
.isEqualTo("password");
|
||||
assertThat(
|
||||
context.getBean(LettuceConnectionFactory.class).getPassword())
|
||||
.isEqualTo("password");
|
||||
|
||||
});
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
public class RedisReactiveAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations
|
||||
.of(RedisAutoConfiguration.class, RedisReactiveAutoConfiguration.class));
|
||||
.withConfiguration(AutoConfigurations.of(RedisAutoConfiguration.class,
|
||||
RedisReactiveAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void testDefaultRedisConfiguration() {
|
||||
|
|
|
@ -59,8 +59,8 @@ import static org.mockito.Mockito.mock;
|
|||
public class JestAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations
|
||||
.of(GsonAutoConfiguration.class, JestAutoConfiguration.class));
|
||||
.withConfiguration(AutoConfigurations.of(GsonAutoConfiguration.class,
|
||||
JestAutoConfiguration.class));
|
||||
|
||||
@Before
|
||||
public void preventElasticsearchFromConfiguringNetty() {
|
||||
|
@ -81,32 +81,34 @@ public class JestAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void customJestClient() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(CustomJestClient.class)
|
||||
.withPropertyValues("spring.elasticsearch.jest.uris[0]=http://localhost:9200")
|
||||
this.contextRunner.withUserConfiguration(CustomJestClient.class)
|
||||
.withPropertyValues(
|
||||
"spring.elasticsearch.jest.uris[0]=http://localhost:9200")
|
||||
.run((context) -> {
|
||||
assertThat(context.getBeansOfType(JestClient.class)).hasSize(1);
|
||||
});
|
||||
assertThat(context.getBeansOfType(JestClient.class)).hasSize(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customGson() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(CustomGson.class)
|
||||
.withPropertyValues("spring.elasticsearch.jest.uris=http://localhost:9200")
|
||||
this.contextRunner.withUserConfiguration(CustomGson.class)
|
||||
.withPropertyValues(
|
||||
"spring.elasticsearch.jest.uris=http://localhost:9200")
|
||||
.run((context) -> {
|
||||
JestHttpClient client = (JestHttpClient) context.getBean(JestClient.class);
|
||||
JestHttpClient client = (JestHttpClient) context
|
||||
.getBean(JestClient.class);
|
||||
assertThat(client.getGson()).isSameAs(context.getBean("customGson"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customizerOverridesAutoConfig() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(BuilderCustomizer.class)
|
||||
.withPropertyValues("spring.elasticsearch.jest.uris=http://localhost:9200")
|
||||
this.contextRunner.withUserConfiguration(BuilderCustomizer.class)
|
||||
.withPropertyValues(
|
||||
"spring.elasticsearch.jest.uris=http://localhost:9200")
|
||||
.run((context) -> {
|
||||
JestHttpClient client = (JestHttpClient) context.getBean(JestClient.class);
|
||||
JestHttpClient client = (JestHttpClient) context
|
||||
.getBean(JestClient.class);
|
||||
assertThat(client.getGson())
|
||||
.isSameAs(context.getBean(BuilderCustomizer.class).getGson());
|
||||
});
|
||||
|
@ -115,37 +117,36 @@ public class JestAutoConfigurationTests {
|
|||
@Test
|
||||
public void proxyHostWithoutPort() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.elasticsearch.jest.uris=http://localhost:9200",
|
||||
"spring.elasticsearch.jest.proxy.host=proxy.example.com")
|
||||
.run((context) -> {
|
||||
assertThat(context.getStartupFailure())
|
||||
.isInstanceOf(BeanCreationException.class)
|
||||
.hasMessageContaining("Proxy port must not be null");
|
||||
});
|
||||
.withPropertyValues(
|
||||
"spring.elasticsearch.jest.uris=http://localhost:9200",
|
||||
"spring.elasticsearch.jest.proxy.host=proxy.example.com")
|
||||
.run((context) -> {
|
||||
assertThat(context.getStartupFailure())
|
||||
.isInstanceOf(BeanCreationException.class)
|
||||
.hasMessageContaining("Proxy port must not be null");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jestCanCommunicateWithElasticsearchInstance() {
|
||||
new ElasticsearchNodeTemplate().doWithNode((node) ->
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.elasticsearch.jest.uris=http://localhost:"
|
||||
+ node.getHttpPort())
|
||||
.run((context) -> {
|
||||
JestClient client = context.getBean(JestClient.class);
|
||||
Map<String, String> source = new HashMap<>();
|
||||
source.put("a", "alpha");
|
||||
source.put("b", "bravo");
|
||||
Index index = new Index.Builder(source).index("foo").type("bar").build();
|
||||
execute(client, index);
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
searchSourceBuilder.query(QueryBuilders.matchQuery("a", "alpha"));
|
||||
assertThat(
|
||||
execute(client,
|
||||
new Search.Builder(searchSourceBuilder.toString())
|
||||
.addIndex("foo").build()).getResponseCode())
|
||||
.isEqualTo(200);
|
||||
})
|
||||
);
|
||||
new ElasticsearchNodeTemplate().doWithNode((node) -> this.contextRunner
|
||||
.withPropertyValues("spring.elasticsearch.jest.uris=http://localhost:"
|
||||
+ node.getHttpPort())
|
||||
.run((context) -> {
|
||||
JestClient client = context.getBean(JestClient.class);
|
||||
Map<String, String> source = new HashMap<>();
|
||||
source.put("a", "alpha");
|
||||
source.put("b", "bravo");
|
||||
Index index = new Index.Builder(source).index("foo").type("bar")
|
||||
.build();
|
||||
execute(client, index);
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
searchSourceBuilder.query(QueryBuilders.matchQuery("a", "alpha"));
|
||||
assertThat(execute(client,
|
||||
new Search.Builder(searchSourceBuilder.toString())
|
||||
.addIndex("foo").build()).getResponseCode())
|
||||
.isEqualTo(200);
|
||||
}));
|
||||
}
|
||||
|
||||
private JestResult execute(JestClient client, Action<? extends JestResult> action) {
|
||||
|
|
|
@ -38,9 +38,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
public class ProjectInfoAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
ProjectInfoAutoConfiguration.class));
|
||||
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
|
||||
ProjectInfoAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void gitPropertiesUnavailableIfResourceNotAvailable() {
|
||||
|
@ -51,9 +51,9 @@ public class ProjectInfoAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void gitPropertiesWithNoData() {
|
||||
this.contextRunner.withPropertyValues(
|
||||
"spring.info.git.location=" +
|
||||
"classpath:/org/springframework/boot/autoconfigure/info/git-no-data.properties")
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.info.git.location="
|
||||
+ "classpath:/org/springframework/boot/autoconfigure/info/git-no-data.properties")
|
||||
.run((context) -> {
|
||||
GitProperties gitProperties = context.getBean(GitProperties.class);
|
||||
assertThat(gitProperties.getBranch()).isNull();
|
||||
|
@ -63,11 +63,12 @@ public class ProjectInfoAutoConfigurationTests {
|
|||
@Test
|
||||
public void gitPropertiesFallbackWithGitPropertiesBean() {
|
||||
this.contextRunner.withUserConfiguration(CustomInfoPropertiesConfiguration.class)
|
||||
.withPropertyValues("spring.info.git.location=" +
|
||||
"classpath:/org/springframework/boot/autoconfigure/info/git.properties")
|
||||
.withPropertyValues("spring.info.git.location="
|
||||
+ "classpath:/org/springframework/boot/autoconfigure/info/git.properties")
|
||||
.run((context) -> {
|
||||
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.getName()).isEqualTo("Demo Project");
|
||||
assertThat(buildProperties.getVersion()).isEqualTo("0.0.1-SNAPSHOT");
|
||||
assertThat(buildProperties.getTime().toEpochMilli()).isEqualTo(1457100965000L);
|
||||
assertThat(buildProperties.getTime().toEpochMilli())
|
||||
.isEqualTo(1457100965000L);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildPropertiesCustomLocation() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.info.build.location=" +
|
||||
"classpath:/org/springframework/boot/autoconfigure/info/build-info.properties")
|
||||
.withPropertyValues("spring.info.build.location="
|
||||
+ "classpath:/org/springframework/boot/autoconfigure/info/build-info.properties")
|
||||
.run((context) -> {
|
||||
BuildProperties buildProperties = context.getBean(BuildProperties.class);
|
||||
BuildProperties buildProperties = context
|
||||
.getBean(BuildProperties.class);
|
||||
assertThat(buildProperties.getGroup()).isEqualTo("com.example.acme");
|
||||
assertThat(buildProperties.getArtifact()).isEqualTo("acme");
|
||||
assertThat(buildProperties.getName()).isEqualTo("acme");
|
||||
assertThat(buildProperties.getVersion()).isEqualTo("1.0.1-SNAPSHOT");
|
||||
assertThat(buildProperties.getTime().toEpochMilli()).isEqualTo(1457088120000L);
|
||||
assertThat(buildProperties.getTime().toEpochMilli())
|
||||
.isEqualTo(1457088120000L);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildPropertiesCustomInvalidLocation() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.info.build.location=" +
|
||||
"classpath:/org/acme/no-build-info.properties")
|
||||
.withPropertyValues("spring.info.build.location="
|
||||
+ "classpath:/org/acme/no-build-info.properties")
|
||||
.run((context) -> {
|
||||
assertThat(context.getBeansOfType(BuildProperties.class)).hasSize(0);
|
||||
});
|
||||
|
@ -110,10 +114,10 @@ public class ProjectInfoAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void buildPropertiesFallbackWithBuildInfoBean() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(CustomInfoPropertiesConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(CustomInfoPropertiesConfiguration.class)
|
||||
.run((context) -> {
|
||||
BuildProperties buildProperties = context.getBean(BuildProperties.class);
|
||||
BuildProperties buildProperties = context
|
||||
.getBean(BuildProperties.class);
|
||||
assertThat(buildProperties)
|
||||
.isSameAs(context.getBean("customBuildProperties"));
|
||||
});
|
||||
|
|
|
@ -54,8 +54,7 @@ public class HikariDataSourceConfigurationTests {
|
|||
public void testDataSourcePropertiesOverridden() {
|
||||
this.contextRunner.withPropertyValues(
|
||||
"spring.datasource.hikari.jdbc-url=jdbc:foo//bar/spam",
|
||||
"spring.datasource.hikari.max-lifetime=1234")
|
||||
.run((context) -> {
|
||||
"spring.datasource.hikari.max-lifetime=1234").run((context) -> {
|
||||
HikariDataSource ds = context.getBean(HikariDataSource.class);
|
||||
assertThat(ds.getJdbcUrl()).isEqualTo("jdbc:foo//bar/spam");
|
||||
assertThat(ds.getMaxLifetime()).isEqualTo(1234);
|
||||
|
@ -65,13 +64,14 @@ public class HikariDataSourceConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void testDataSourceGenericPropertiesOverridden() {
|
||||
this.contextRunner.withPropertyValues(
|
||||
"spring.datasource.hikari.data-source-properties" +
|
||||
".dataSourceClassName=org.h2.JDBCDataSource")
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.datasource.hikari.data-source-properties"
|
||||
+ ".dataSourceClassName=org.h2.JDBCDataSource")
|
||||
.run((context) -> {
|
||||
HikariDataSource ds = context.getBean(HikariDataSource.class);
|
||||
assertThat(ds.getDataSourceProperties().getProperty("dataSourceClassName"))
|
||||
.isEqualTo("org.h2.JDBCDataSource");
|
||||
assertThat(ds.getDataSourceProperties()
|
||||
.getProperty("dataSourceClassName"))
|
||||
.isEqualTo("org.h2.JDBCDataSource");
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -96,9 +96,9 @@ public class HikariDataSourceConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void poolNameTakesPrecedenceOverName() {
|
||||
this.contextRunner.withPropertyValues(
|
||||
"spring.datasource.name=myDS",
|
||||
"spring.datasource.hikari.pool-name=myHikariDS")
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.datasource.name=myDS",
|
||||
"spring.datasource.hikari.pool-name=myHikariDS")
|
||||
.run((context) -> {
|
||||
HikariDataSource ds = context.getBean(HikariDataSource.class);
|
||||
assertThat(ds.getPoolName()).isEqualTo("myHikariDS");
|
||||
|
|
|
@ -57,13 +57,10 @@ import static org.junit.Assert.fail;
|
|||
*/
|
||||
public class JooqAutoConfigurationTests {
|
||||
|
||||
private static final String[] NO_BEANS = {};
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class))
|
||||
.withPropertyValues("spring.datasource.name:jooqtest");
|
||||
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
|
@ -76,13 +73,10 @@ public class JooqAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void jooqWithoutTx() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(JooqDataSourceConfiguration.class)
|
||||
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context.getBeanNamesForType(
|
||||
PlatformTransactionManager.class)).isEqualTo(NO_BEANS);
|
||||
assertThat(context.getBeanNamesForType(
|
||||
SpringTransactionProvider.class)).isEqualTo(NO_BEANS);
|
||||
assertThat(context).doesNotHaveBean(PlatformTransactionManager.class);
|
||||
assertThat(context).doesNotHaveBean(SpringTransactionProvider.class);
|
||||
DSLContext dsl = context.getBean(DSLContext.class);
|
||||
dsl.execute("create table jooqtest (name varchar(255) primary key);");
|
||||
dsl.transaction(new AssertFetch(dsl,
|
||||
|
@ -92,31 +86,29 @@ public class JooqAutoConfigurationTests {
|
|||
dsl.transaction(new AssertFetch(dsl,
|
||||
"select count(*) as total from jooqtest;", "1"));
|
||||
try {
|
||||
dsl.transaction(
|
||||
new ExecuteSql(dsl,
|
||||
"insert into jooqtest (name) values ('bar');",
|
||||
"insert into jooqtest (name) values ('foo');"));
|
||||
dsl.transaction(new ExecuteSql(dsl,
|
||||
"insert into jooqtest (name) values ('bar');",
|
||||
"insert into jooqtest (name) values ('foo');"));
|
||||
fail("An DataIntegrityViolationException should have been thrown.");
|
||||
}
|
||||
catch (DataIntegrityViolationException ex) {
|
||||
// Ignore
|
||||
}
|
||||
dsl.transaction(
|
||||
new AssertFetch(dsl,
|
||||
"select count(*) as total from jooqtest;", "2"));
|
||||
|
||||
dsl.transaction(new AssertFetch(dsl,
|
||||
"select count(*) as total from jooqtest;", "2"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jooqWithTx() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class)
|
||||
.run((context) -> {
|
||||
context.getBean(PlatformTransactionManager.class);
|
||||
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class,
|
||||
TxManagerConfiguration.class).run((context) -> {
|
||||
assertThat(context).hasSingleBean(PlatformTransactionManager.class);
|
||||
DSLContext dsl = context.getBean(DSLContext.class);
|
||||
assertThat(dsl.configuration().dialect()).isEqualTo(SQLDialect.HSQLDB);
|
||||
dsl.execute("create table jooqtest_tx (name varchar(255) primary key);");
|
||||
assertThat(dsl.configuration().dialect())
|
||||
.isEqualTo(SQLDialect.HSQLDB);
|
||||
dsl.execute(
|
||||
"create table jooqtest_tx (name varchar(255) primary key);");
|
||||
dsl.transaction(new AssertFetch(dsl,
|
||||
"select count(*) as total from jooqtest_tx;", "0"));
|
||||
dsl.transaction(new ExecuteSql(dsl,
|
||||
|
@ -124,45 +116,44 @@ public class JooqAutoConfigurationTests {
|
|||
dsl.transaction(new AssertFetch(dsl,
|
||||
"select count(*) as total from jooqtest_tx;", "1"));
|
||||
try {
|
||||
dsl.transaction(
|
||||
new ExecuteSql(dsl, "insert into jooqtest (name) values ('bar');",
|
||||
"insert into jooqtest (name) values ('foo');"));
|
||||
dsl.transaction(new ExecuteSql(dsl,
|
||||
"insert into jooqtest (name) values ('bar');",
|
||||
"insert into jooqtest (name) values ('foo');"));
|
||||
fail("A DataIntegrityViolationException should have been thrown.");
|
||||
}
|
||||
catch (DataIntegrityViolationException ex) {
|
||||
// Ignore
|
||||
}
|
||||
dsl.transaction(
|
||||
new AssertFetch(dsl,
|
||||
"select count(*) as total from jooqtest_tx;", "1"));
|
||||
dsl.transaction(new AssertFetch(dsl,
|
||||
"select count(*) as total from jooqtest_tx;", "1"));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customProvidersArePickedUp() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class,
|
||||
TestRecordMapperProvider.class, TestRecordListenerProvider.class,
|
||||
TestExecuteListenerProvider.class, TestVisitListenerProvider.class)
|
||||
.run((context) -> {
|
||||
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class,
|
||||
TxManagerConfiguration.class, TestRecordMapperProvider.class,
|
||||
TestRecordListenerProvider.class, TestExecuteListenerProvider.class,
|
||||
TestVisitListenerProvider.class).run((context) -> {
|
||||
DSLContext dsl = context.getBean(DSLContext.class);
|
||||
assertThat(dsl.configuration().recordMapperProvider().getClass())
|
||||
.isEqualTo(TestRecordMapperProvider.class);
|
||||
assertThat(dsl.configuration().recordListenerProviders().length).isEqualTo(1);
|
||||
assertThat(dsl.configuration().executeListenerProviders().length).isEqualTo(2);
|
||||
assertThat(dsl.configuration().visitListenerProviders().length).isEqualTo(1);
|
||||
assertThat(dsl.configuration().recordListenerProviders().length)
|
||||
.isEqualTo(1);
|
||||
assertThat(dsl.configuration().executeListenerProviders().length)
|
||||
.isEqualTo(2);
|
||||
assertThat(dsl.configuration().visitListenerProviders().length)
|
||||
.isEqualTo(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void relaxedBindingOfSqlDialect() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(JooqDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.jooq.sql-dialect:PoSTGrES")
|
||||
.run((context) -> {
|
||||
assertThat(context.getBean(org.jooq.Configuration.class)
|
||||
.dialect()).isEqualTo(SQLDialect.POSTGRES);
|
||||
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class)
|
||||
.withPropertyValues("spring.jooq.sql-dialect:PoSTGrES").run((context) -> {
|
||||
assertThat(context.getBean(org.jooq.Configuration.class).dialect())
|
||||
.isEqualTo(SQLDialect.POSTGRES);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -41,8 +41,8 @@ public class LdapAutoConfigurationTests {
|
|||
public void contextSourceWithDefaultUrl() {
|
||||
this.contextRunner.run(context -> {
|
||||
LdapContextSource contextSource = context.getBean(LdapContextSource.class);
|
||||
String[] urls = (String[]) ReflectionTestUtils
|
||||
.getField(contextSource, "urls");
|
||||
String[] urls = (String[]) ReflectionTestUtils.getField(contextSource,
|
||||
"urls");
|
||||
assertThat(urls).containsExactly("ldap://localhost:389");
|
||||
assertThat(contextSource.isAnonymousReadOnly()).isFalse();
|
||||
});
|
||||
|
@ -53,8 +53,8 @@ public class LdapAutoConfigurationTests {
|
|||
this.contextRunner.withPropertyValues("spring.ldap.urls:ldap://localhost:123")
|
||||
.run(context -> {
|
||||
ContextSource contextSource = context.getBean(ContextSource.class);
|
||||
String[] urls = (String[]) ReflectionTestUtils.getField(
|
||||
contextSource, "urls");
|
||||
String[] urls = (String[]) ReflectionTestUtils.getField(contextSource,
|
||||
"urls");
|
||||
assertThat(urls).containsExactly("ldap://localhost:123");
|
||||
});
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ public class LdapAutoConfigurationTests {
|
|||
.run(context -> {
|
||||
ContextSource contextSource = context.getBean(ContextSource.class);
|
||||
LdapProperties ldapProperties = context.getBean(LdapProperties.class);
|
||||
String[] urls = (String[]) ReflectionTestUtils.getField(
|
||||
contextSource, "urls");
|
||||
String[] urls = (String[]) ReflectionTestUtils.getField(contextSource,
|
||||
"urls");
|
||||
assertThat(urls).containsExactly("ldap://localhost:123",
|
||||
"ldap://mycompany:123");
|
||||
assertThat(ldapProperties.getUrls()).hasSize(2);
|
||||
|
@ -78,21 +78,19 @@ public class LdapAutoConfigurationTests {
|
|||
@Test
|
||||
public void contextSourceWithExtraCustomization() {
|
||||
this.contextRunner
|
||||
.withPropertyValues(
|
||||
"spring.ldap.urls:ldap://localhost:123",
|
||||
"spring.ldap.username:root",
|
||||
"spring.ldap.password:secret",
|
||||
.withPropertyValues("spring.ldap.urls:ldap://localhost:123",
|
||||
"spring.ldap.username:root", "spring.ldap.password:secret",
|
||||
"spring.ldap.anonymous-read-only:true",
|
||||
"spring.ldap.base:cn=SpringDevelopers",
|
||||
"spring.ldap.baseEnvironment.java.naming.security.authentication:DIGEST-MD5")
|
||||
.run(context -> {
|
||||
LdapContextSource contextSource = context.getBean(
|
||||
LdapContextSource.class);
|
||||
LdapContextSource contextSource = context
|
||||
.getBean(LdapContextSource.class);
|
||||
assertThat(contextSource.getUserDn()).isEqualTo("root");
|
||||
assertThat(contextSource.getPassword()).isEqualTo("secret");
|
||||
assertThat(contextSource.isAnonymousReadOnly()).isTrue();
|
||||
assertThat(contextSource.getBaseLdapPathAsString()).isEqualTo(
|
||||
"cn=SpringDevelopers");
|
||||
assertThat(contextSource.getBaseLdapPathAsString())
|
||||
.isEqualTo("cn=SpringDevelopers");
|
||||
LdapProperties ldapProperties = context.getBean(LdapProperties.class);
|
||||
assertThat(ldapProperties.getBaseEnvironment()).containsEntry(
|
||||
"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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* 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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
Loading…
Reference in New Issue