mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Polish
This commit is contained in:
parent
8f7004738b
commit
2c7dd9f519
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -193,8 +193,7 @@ public class LoggersMvcEndpointTests {
|
||||
@Test
|
||||
public void setLoggerWithNoLogLevel() throws Exception {
|
||||
this.mvc.perform(post(PATH + "/ROOT").contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{}"))
|
||||
.andExpect(status().isNoContent());
|
||||
.content("{}")).andExpect(status().isNoContent());
|
||||
verify(this.loggingSystem).setLogLevel("ROOT", null);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
|
||||
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties.Pageable;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -62,20 +63,19 @@ public class SpringDataWebAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public PageableHandlerMethodArgumentResolverCustomizer pageableCustomizer() {
|
||||
return pageableResolver -> {
|
||||
pageableResolver.setFallbackPageable(PageRequest.of(0,
|
||||
this.properties.getPageable().getDefaultPageSize()));
|
||||
pageableResolver.setPageParameterName(
|
||||
this.properties.getPageable().getPageParameter());
|
||||
pageableResolver.setSizeParameterName(
|
||||
this.properties.getPageable().getSizeParameter());
|
||||
return (resolver) -> {
|
||||
Pageable pageable = this.properties.getPageable();
|
||||
resolver.setFallbackPageable(
|
||||
PageRequest.of(0, pageable.getDefaultPageSize()));
|
||||
resolver.setPageParameterName(pageable.getPageParameter());
|
||||
resolver.setSizeParameterName(pageable.getSizeParameter());
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SortHandlerMethodArgumentResolverCustomizer sortCustomizer() {
|
||||
return sortResolver -> sortResolver
|
||||
return (resolver) -> resolver
|
||||
.setSortParameter(this.properties.getSort().getSortParameter());
|
||||
}
|
||||
|
||||
|
@ -54,10 +54,8 @@ public class InfluxDbAutoConfiguration {
|
||||
if (Strings.isNullOrEmpty(client.getUser())) {
|
||||
return InfluxDBFactory.connect(client.getUrl());
|
||||
}
|
||||
else {
|
||||
return InfluxDBFactory.connect(client.getUrl(), client.getUser(),
|
||||
client.getPassword());
|
||||
}
|
||||
return InfluxDBFactory.connect(client.getUrl(), client.getUser(),
|
||||
client.getPassword());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -84,7 +84,8 @@ public class JdbcTemplateAutoConfiguration {
|
||||
@Primary
|
||||
@ConditionalOnSingleCandidate(JdbcTemplate.class)
|
||||
@ConditionalOnMissingBean(NamedParameterJdbcOperations.class)
|
||||
public NamedParameterJdbcTemplate namedParameterJdbcTemplate(JdbcTemplate jdbcTemplate) {
|
||||
public NamedParameterJdbcTemplate namedParameterJdbcTemplate(
|
||||
JdbcTemplate jdbcTemplate) {
|
||||
return new NamedParameterJdbcTemplate(jdbcTemplate);
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
public class JooqProperties {
|
||||
|
||||
/**
|
||||
* Sql dialect to use, auto-detected by default.
|
||||
* SQL dialect to use, auto-detected by default.
|
||||
*/
|
||||
private SQLDialect sqlDialect;
|
||||
|
||||
|
@ -34,6 +34,7 @@ import com.mongodb.reactivestreams.client.MongoClient;
|
||||
import com.mongodb.reactivestreams.client.MongoClients;
|
||||
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A factory for a reactive {@link MongoClient} that applies {@link MongoProperties}.
|
||||
@ -96,67 +97,88 @@ public class ReactiveMongoClientFactory {
|
||||
|
||||
private MongoClient createNetworkMongoClient(MongoClientSettings settings) {
|
||||
if (hasCustomAddress() || hasCustomCredentials()) {
|
||||
if (this.properties.getUri() != null) {
|
||||
throw new IllegalStateException("Invalid mongo configuration, "
|
||||
+ "either uri or host/port/credentials must be specified");
|
||||
}
|
||||
|
||||
Builder builder = builder(settings);
|
||||
if (hasCustomCredentials()) {
|
||||
List<MongoCredential> credentials = new ArrayList<>();
|
||||
String database = this.properties.getAuthenticationDatabase() == null
|
||||
? this.properties.getMongoClientDatabase()
|
||||
: this.properties.getAuthenticationDatabase();
|
||||
credentials.add(
|
||||
MongoCredential.createCredential(this.properties.getUsername(),
|
||||
database, this.properties.getPassword()));
|
||||
builder.credentialList(credentials);
|
||||
}
|
||||
String host = this.properties.getHost() == null ? "localhost"
|
||||
: this.properties.getHost();
|
||||
int port = this.properties.getPort() != null ? this.properties.getPort()
|
||||
: MongoProperties.DEFAULT_PORT;
|
||||
ClusterSettings clusterSettings = ClusterSettings.builder()
|
||||
.hosts(Collections.singletonList(new ServerAddress(host, port)))
|
||||
.build();
|
||||
builder.clusterSettings(clusterSettings);
|
||||
return MongoClients.create(builder.build());
|
||||
return createCredentialNetworkMongoClient(settings);
|
||||
}
|
||||
ConnectionString connectionString = new ConnectionString(
|
||||
this.properties.determineUri());
|
||||
return MongoClients.create(createBuilder(settings, connectionString).build());
|
||||
}
|
||||
|
||||
private MongoClient createCredentialNetworkMongoClient(MongoClientSettings settings) {
|
||||
Assert.state(this.properties.getUri() == null, "Invalid mongo configuration, "
|
||||
+ "either uri or host/port/credentials must be specified");
|
||||
Builder builder = builder(settings);
|
||||
if (hasCustomCredentials()) {
|
||||
applyCredentials(builder);
|
||||
}
|
||||
String host = getOrDefault(this.properties.getHost(), "localhost");
|
||||
int port = getOrDefault(this.properties.getPort(), MongoProperties.DEFAULT_PORT);
|
||||
ServerAddress serverAddress = new ServerAddress(host, port);
|
||||
builder.clusterSettings(ClusterSettings.builder()
|
||||
.hosts(Collections.singletonList(serverAddress)).build());
|
||||
return MongoClients.create(builder.build());
|
||||
}
|
||||
|
||||
private void applyCredentials(Builder builder) {
|
||||
List<MongoCredential> credentials = new ArrayList<>();
|
||||
String database = this.properties.getAuthenticationDatabase() == null
|
||||
? this.properties.getMongoClientDatabase()
|
||||
: this.properties.getAuthenticationDatabase();
|
||||
credentials.add(MongoCredential.createCredential(this.properties.getUsername(),
|
||||
database, this.properties.getPassword()));
|
||||
builder.credentialList(credentials);
|
||||
}
|
||||
|
||||
private <T> T getOrDefault(T value, T defaultValue) {
|
||||
return (value == null ? defaultValue : value);
|
||||
}
|
||||
|
||||
private Builder createBuilder(MongoClientSettings settings,
|
||||
ConnectionString connectionString) {
|
||||
Builder builder = builder(settings)
|
||||
.clusterSettings(ClusterSettings.builder()
|
||||
.applyConnectionString(connectionString).build())
|
||||
.connectionPoolSettings(ConnectionPoolSettings.builder()
|
||||
.applyConnectionString(connectionString).build())
|
||||
.serverSettings(ServerSettings.builder()
|
||||
.applyConnectionString(connectionString).build())
|
||||
.credentialList(connectionString.getCredentialList())
|
||||
.sslSettings(SslSettings.builder().applyConnectionString(connectionString)
|
||||
.build())
|
||||
.socketSettings(SocketSettings.builder()
|
||||
.applyConnectionString(connectionString).build());
|
||||
if (connectionString.getReadPreference() != null) {
|
||||
builder.readPreference(connectionString.getReadPreference());
|
||||
ConnectionString connection) {
|
||||
Builder builder = builder(settings);
|
||||
builder.clusterSettings(getClusterSettings(connection));
|
||||
builder.connectionPoolSettings(getConnectionPoolSettings(connection));
|
||||
builder.serverSettings(getServerSettings(connection));
|
||||
builder.credentialList(connection.getCredentialList());
|
||||
builder.sslSettings(getSslSettings(connection));
|
||||
builder.socketSettings(getSocketSettings(connection));
|
||||
if (connection.getReadPreference() != null) {
|
||||
builder.readPreference(connection.getReadPreference());
|
||||
}
|
||||
if (connectionString.getReadConcern() != null) {
|
||||
builder.readConcern(connectionString.getReadConcern());
|
||||
if (connection.getReadConcern() != null) {
|
||||
builder.readConcern(connection.getReadConcern());
|
||||
}
|
||||
if (connectionString.getWriteConcern() != null) {
|
||||
builder.writeConcern(connectionString.getWriteConcern());
|
||||
if (connection.getWriteConcern() != null) {
|
||||
builder.writeConcern(connection.getWriteConcern());
|
||||
}
|
||||
if (connectionString.getApplicationName() != null) {
|
||||
builder.applicationName(connectionString.getApplicationName());
|
||||
if (connection.getApplicationName() != null) {
|
||||
builder.applicationName(connection.getApplicationName());
|
||||
}
|
||||
customize(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
private ClusterSettings getClusterSettings(ConnectionString connection) {
|
||||
return ClusterSettings.builder().applyConnectionString(connection).build();
|
||||
}
|
||||
|
||||
private ConnectionPoolSettings getConnectionPoolSettings(
|
||||
ConnectionString connection) {
|
||||
return ConnectionPoolSettings.builder().applyConnectionString(connection).build();
|
||||
}
|
||||
|
||||
private ServerSettings getServerSettings(ConnectionString connection) {
|
||||
return ServerSettings.builder().applyConnectionString(connection).build();
|
||||
}
|
||||
|
||||
private SslSettings getSslSettings(ConnectionString connection) {
|
||||
return SslSettings.builder().applyConnectionString(connection).build();
|
||||
}
|
||||
|
||||
private SocketSettings getSocketSettings(ConnectionString connection) {
|
||||
return SocketSettings.builder().applyConnectionString(connection).build();
|
||||
}
|
||||
|
||||
private void customize(MongoClientSettings.Builder builder) {
|
||||
for (MongoClientSettingsBuilderCustomizer customizer : this.builderCustomizers) {
|
||||
customizer.customize(builder);
|
||||
@ -176,7 +198,6 @@ public class ReactiveMongoClientFactory {
|
||||
if (settings == null) {
|
||||
return MongoClientSettings.builder();
|
||||
}
|
||||
|
||||
return MongoClientSettings.builder(settings);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -56,8 +56,7 @@ public class ElasticsearchDataAutoConfigurationTests {
|
||||
ElasticsearchAutoConfiguration.class,
|
||||
ElasticsearchDataAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBeanNamesForType(ElasticsearchTemplate.class))
|
||||
.hasSize(1);
|
||||
asssertHasSingleBean(ElasticsearchTemplate.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -71,9 +70,7 @@ public class ElasticsearchDataAutoConfigurationTests {
|
||||
ElasticsearchAutoConfiguration.class,
|
||||
ElasticsearchDataAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(
|
||||
this.context.getBeanNamesForType(SimpleElasticsearchMappingContext.class))
|
||||
.hasSize(1);
|
||||
asssertHasSingleBean(SimpleElasticsearchMappingContext.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -87,8 +84,11 @@ public class ElasticsearchDataAutoConfigurationTests {
|
||||
ElasticsearchAutoConfiguration.class,
|
||||
ElasticsearchDataAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBeanNamesForType(ElasticsearchConverter.class))
|
||||
.hasSize(1);
|
||||
asssertHasSingleBean(ElasticsearchConverter.class);
|
||||
}
|
||||
|
||||
private void asssertHasSingleBean(Class<?> type) {
|
||||
assertThat(this.context.getBeanNamesForType(type)).hasSize(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Sergey Kuptsov
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class InfluxDbAutoConfigurationTest {
|
||||
public class InfluxDbAutoConfigurationTests {
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
@ -60,8 +60,8 @@ public class JdbcTemplateAutoConfigurationTests {
|
||||
load();
|
||||
assertThat(this.context.getBeansOfType(JdbcOperations.class)).hasSize(1);
|
||||
JdbcTemplate jdbcTemplate = this.context.getBean(JdbcTemplate.class);
|
||||
assertThat(jdbcTemplate.getDataSource()).isEqualTo(
|
||||
this.context.getBean(DataSource.class));
|
||||
assertThat(jdbcTemplate.getDataSource())
|
||||
.isEqualTo(this.context.getBean(DataSource.class));
|
||||
assertThat(jdbcTemplate.getFetchSize()).isEqualTo(-1);
|
||||
assertThat(jdbcTemplate.getQueryTimeout()).isEqualTo(-1);
|
||||
assertThat(jdbcTemplate.getMaxRows()).isEqualTo(-1);
|
||||
@ -86,8 +86,8 @@ public class JdbcTemplateAutoConfigurationTests {
|
||||
assertThat(this.context.getBeansOfType(JdbcOperations.class)).hasSize(1);
|
||||
JdbcTemplate jdbcTemplate = this.context.getBean(JdbcTemplate.class);
|
||||
assertThat(jdbcTemplate).isNotNull();
|
||||
assertThat(jdbcTemplate.getDataSource()).isEqualTo(
|
||||
this.context.getBean("customDataSource"));
|
||||
assertThat(jdbcTemplate.getDataSource())
|
||||
.isEqualTo(this.context.getBean("customDataSource"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -95,10 +95,10 @@ public class JdbcTemplateAutoConfigurationTests {
|
||||
load();
|
||||
assertThat(this.context.getBeansOfType(NamedParameterJdbcOperations.class))
|
||||
.hasSize(1);
|
||||
NamedParameterJdbcTemplate namedParameterJdbcTemplate = this.context.getBean(
|
||||
NamedParameterJdbcTemplate.class);
|
||||
assertThat(namedParameterJdbcTemplate.getJdbcOperations()).isEqualTo(
|
||||
this.context.getBean(JdbcOperations.class));
|
||||
NamedParameterJdbcTemplate namedParameterJdbcTemplate = this.context
|
||||
.getBean(NamedParameterJdbcTemplate.class);
|
||||
assertThat(namedParameterJdbcTemplate.getJdbcOperations())
|
||||
.isEqualTo(this.context.getBean(JdbcOperations.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -157,8 +157,8 @@ public class MongoReactiveAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public MongoClientSettingsBuilderCustomizer customizer() {
|
||||
return clientSettingsBuilder ->
|
||||
clientSettingsBuilder.applicationName("overridden-name");
|
||||
return clientSettingsBuilder -> clientSettingsBuilder
|
||||
.applicationName("overridden-name");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -5861,7 +5861,7 @@ into the `ApplicationContext`:
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@JooqTest
|
||||
public class ExampleJooqTests {
|
||||
|
@ -47,11 +47,9 @@ public class SampleWebFluxApplicationTests {
|
||||
|
||||
@Test
|
||||
public void testEcho() throws Exception {
|
||||
this.webClient.post().uri("/echo")
|
||||
.contentType(MediaType.TEXT_PLAIN)
|
||||
this.webClient.post().uri("/echo").contentType(MediaType.TEXT_PLAIN)
|
||||
.accept(MediaType.TEXT_PLAIN)
|
||||
.body(Mono.just("Hello WebFlux!"), String.class)
|
||||
.exchange()
|
||||
.body(Mono.just("Hello WebFlux!"), String.class).exchange()
|
||||
.expectBody(String.class).isEqualTo("Hello WebFlux!");
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2015 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -42,8 +42,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* Using this annotation will disable full auto-configuration and instead apply only
|
||||
* configuration relevant to jOOQ tests.
|
||||
* <p>
|
||||
* By default, tests annotated with {@code @JooqTest} use the configured database. If
|
||||
* you want to replace any explicit or usually auto-configured DataSource by an embedded
|
||||
* By default, tests annotated with {@code @JooqTest} use the configured database. If you
|
||||
* want to replace any explicit or usually auto-configured DataSource by an embedded
|
||||
* in-memory database, the {@link AutoConfigureTestDatabase @AutoConfigureTestDatabase}
|
||||
* annotation can be used to override these settings.
|
||||
*
|
||||
|
@ -59,8 +59,8 @@ public class JooqTestIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testDSLContext() {
|
||||
assertThat(this.dsl.selectCount().from("INFORMATION_SCHEMA.TABLES")
|
||||
.fetchOne(0, Integer.class)).isGreaterThan(0);
|
||||
assertThat(this.dsl.selectCount().from("INFORMATION_SCHEMA.TABLES").fetchOne(0,
|
||||
Integer.class)).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -30,8 +30,8 @@ import org.springframework.core.env.SystemEnvironmentPropertySource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Test utilities for adding properties to the environment. The type of {@link PropertySource}
|
||||
* to be added can be specified by {@link Type}.
|
||||
* Test utilities for adding properties to the environment. The type of
|
||||
* {@link PropertySource} to be added can be specified by {@link Type}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
* @since 2.0.0
|
||||
@ -44,14 +44,25 @@ public final class TestPropertyValues {
|
||||
addProperties(pairs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new {@link TestPropertyValues} with the underlying map populated with the given property pairs.
|
||||
* Name-value pairs can be specified with colon (":") or equals ("=") separators.
|
||||
* @param pairs The key value pairs for properties that need to be added to the environment
|
||||
* @return the new instance
|
||||
*/
|
||||
public static TestPropertyValues of(String... pairs) {
|
||||
return new TestPropertyValues(pairs);
|
||||
private void addProperties(String[] pairs) {
|
||||
for (String pair : pairs) {
|
||||
int index = getSeparatorIndex(pair);
|
||||
String key = pair.substring(0, index > 0 ? index : pair.length());
|
||||
String value = index > 0 ? pair.substring(index + 1) : "";
|
||||
this.properties.put(key.trim(), value.trim());
|
||||
}
|
||||
}
|
||||
|
||||
private int getSeparatorIndex(String pair) {
|
||||
int colonIndex = pair.indexOf(":");
|
||||
int equalIndex = pair.indexOf("=");
|
||||
if (colonIndex == -1) {
|
||||
return equalIndex;
|
||||
}
|
||||
if (equalIndex == -1) {
|
||||
return colonIndex;
|
||||
}
|
||||
return Math.min(colonIndex, equalIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,17 +76,9 @@ public final class TestPropertyValues {
|
||||
return this;
|
||||
}
|
||||
|
||||
private void addProperties(String[] pairs) {
|
||||
for (String pair : pairs) {
|
||||
int index = getSeparatorIndex(pair);
|
||||
String key = pair.substring(0, index > 0 ? index : pair.length());
|
||||
String value = index > 0 ? pair.substring(index + 1) : "";
|
||||
this.properties.put(key.trim(), value.trim());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the properties from the underlying map to the environment owned by an {@link ApplicationContext}.
|
||||
* Add the properties from the underlying map to the environment owned by an
|
||||
* {@link ApplicationContext}.
|
||||
* @param context the context with an environment to modify
|
||||
*/
|
||||
public void applyTo(ConfigurableApplicationContext context) {
|
||||
@ -83,8 +86,8 @@ public final class TestPropertyValues {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the properties from the underlying map to the environment. The default property source used is
|
||||
* {@link MapPropertySource}.
|
||||
* Add the properties from the underlying map to the environment. The default property
|
||||
* source used is {@link MapPropertySource}.
|
||||
* @param environment the environment that needs to be modified
|
||||
*/
|
||||
public void applyTo(ConfigurableEnvironment environment) {
|
||||
@ -92,7 +95,8 @@ public final class TestPropertyValues {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the properties from the underlying map to the environment using the specified property source type.
|
||||
* Add the properties from the underlying map to the environment using the specified
|
||||
* property source type.
|
||||
* @param environment the environment that needs to be modified
|
||||
* @param type the type of {@link PropertySource} to be added. See {@link Type}
|
||||
*/
|
||||
@ -101,7 +105,8 @@ public final class TestPropertyValues {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the properties from the underlying map to the environment using the specified property source type and name.
|
||||
* Add the properties from the underlying map to the environment using the specified
|
||||
* property source type and name.
|
||||
* @param environment the environment that needs to be modified
|
||||
* @param type the type of {@link PropertySource} to be added. See {@link Type}
|
||||
* @param name the name for the property source
|
||||
@ -120,26 +125,27 @@ public final class TestPropertyValues {
|
||||
if (sources.contains(name)) {
|
||||
PropertySource<?> propertySource = sources.get(name);
|
||||
if (propertySource.getClass().equals(type.getSourceClass())) {
|
||||
Map<String, Object> source = (Map<String, Object>) propertySource.getSource();
|
||||
source.putAll(this.properties);
|
||||
((Map<String, Object>) propertySource.getSource())
|
||||
.putAll(this.properties);
|
||||
return;
|
||||
}
|
||||
}
|
||||
MapPropertySource source = (type.equals(Type.MAP) ? new MapPropertySource(name, this.properties) :
|
||||
new SystemEnvironmentPropertySource(name, this.properties));
|
||||
MapPropertySource source = (type.equals(Type.MAP)
|
||||
? new MapPropertySource(name, this.properties)
|
||||
: new SystemEnvironmentPropertySource(name, this.properties));
|
||||
sources.addFirst(source);
|
||||
}
|
||||
|
||||
private static int getSeparatorIndex(String pair) {
|
||||
int colonIndex = pair.indexOf(":");
|
||||
int equalIndex = pair.indexOf("=");
|
||||
if (colonIndex == -1) {
|
||||
return equalIndex;
|
||||
}
|
||||
if (equalIndex == -1) {
|
||||
return colonIndex;
|
||||
}
|
||||
return Math.min(colonIndex, equalIndex);
|
||||
/**
|
||||
* Return a new {@link TestPropertyValues} with the underlying map populated with the
|
||||
* given property pairs. Name-value pairs can be specified with colon (":") or equals
|
||||
* ("=") separators.
|
||||
* @param pairs The key value pairs for properties that need to be added to the
|
||||
* environment
|
||||
* @return the new instance
|
||||
*/
|
||||
public static TestPropertyValues of(String... pairs) {
|
||||
return new TestPropertyValues(pairs);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,7 +172,7 @@ public final class TestPropertyValues {
|
||||
public Class<? extends MapPropertySource> getSourceClass() {
|
||||
return this.sourceClass;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -36,9 +36,11 @@ public class TestPropertyValuesTests {
|
||||
private final ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
|
||||
@Test
|
||||
public void applyToEnvironmentShouldAttachConfigurationPropertySource() throws Exception {
|
||||
public void applyToEnvironmentShouldAttachConfigurationPropertySource()
|
||||
throws Exception {
|
||||
TestPropertyValues.of("foo.bar=baz").applyTo(this.environment);
|
||||
PropertySource<?> source = this.environment.getPropertySources().get("configurationProperties");
|
||||
PropertySource<?> source = this.environment.getPropertySources()
|
||||
.get("configurationProperties");
|
||||
assertThat(source).isNotNull();
|
||||
}
|
||||
|
||||
@ -63,17 +65,22 @@ public class TestPropertyValuesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyToExistingNameAndDifferentTypeShouldOverrideExistingOne() throws Exception {
|
||||
TestPropertyValues.of("foo.bar=baz", "hello.world=hi").applyTo(this.environment, Type.MAP, "other");
|
||||
TestPropertyValues.of("FOO_BAR=BAZ").applyTo(this.environment, Type.SYSTEM, "other");
|
||||
assertThat(this.environment.getPropertySources().get("other")).isInstanceOf(SystemEnvironmentPropertySource.class);
|
||||
public void applyToExistingNameAndDifferentTypeShouldOverrideExistingOne()
|
||||
throws Exception {
|
||||
TestPropertyValues.of("foo.bar=baz", "hello.world=hi").applyTo(this.environment,
|
||||
Type.MAP, "other");
|
||||
TestPropertyValues.of("FOO_BAR=BAZ").applyTo(this.environment, Type.SYSTEM,
|
||||
"other");
|
||||
assertThat(this.environment.getPropertySources().get("other"))
|
||||
.isInstanceOf(SystemEnvironmentPropertySource.class);
|
||||
assertThat(this.environment.getProperty("foo.bar")).isEqualTo("BAZ");
|
||||
assertThat(this.environment.getProperty("hello.world")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyToExistingNameAndSameTypeShouldMerge() throws Exception {
|
||||
TestPropertyValues.of("foo.bar=baz", "hello.world=hi").applyTo(this.environment, Type.MAP);
|
||||
TestPropertyValues.of("foo.bar=baz", "hello.world=hi").applyTo(this.environment,
|
||||
Type.MAP);
|
||||
TestPropertyValues.of("foo.bar=new").applyTo(this.environment, Type.MAP);
|
||||
assertThat(this.environment.getProperty("foo.bar")).isEqualTo("new");
|
||||
assertThat(this.environment.getProperty("hello.world")).isEqualTo("hi");
|
||||
@ -81,10 +88,11 @@ public class TestPropertyValuesTests {
|
||||
|
||||
@Test
|
||||
public void andShouldChainAndAddSingleKeyValue() throws Exception {
|
||||
TestPropertyValues.of("foo.bar=baz").and("hello.world", "hi").and("bling.blah", "bing")
|
||||
.applyTo(this.environment, Type.MAP);
|
||||
TestPropertyValues.of("foo.bar=baz").and("hello.world", "hi")
|
||||
.and("bling.blah", "bing").applyTo(this.environment, Type.MAP);
|
||||
assertThat(this.environment.getProperty("foo.bar")).isEqualTo("baz");
|
||||
assertThat(this.environment.getProperty("hello.world")).isEqualTo("hi");
|
||||
assertThat(this.environment.getProperty("bling.blah")).isEqualTo("bing");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -60,4 +60,5 @@ public class OriginTrackedSystemPropertySource extends SystemEnvironmentProperty
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -116,8 +116,8 @@ public abstract class LoggingSystem {
|
||||
* Sets the logging level for a given logger.
|
||||
* @param loggerName the name of the logger to set ({@code null} can be used for the
|
||||
* root logger).
|
||||
* @param level the log level ({@code null} can be used to remove any custom level
|
||||
* for the logger and use the default configuration instead)
|
||||
* @param level the log level ({@code null} can be used to remove any custom level for
|
||||
* the logger and use the default configuration instead)
|
||||
*/
|
||||
public void setLogLevel(String loggerName, LogLevel level) {
|
||||
throw new UnsupportedOperationException("Unable to set log level");
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -225,12 +225,14 @@ public class BinderTests {
|
||||
Bindable<JavaBean> target = Bindable.of(JavaBean.class);
|
||||
this.thrown.expect(BindException.class);
|
||||
this.thrown.expect(new AssertionMatcher<BindException>() {
|
||||
|
||||
@Override
|
||||
public void assertion(BindException ex) throws AssertionError {
|
||||
assertThat(ex.getCause().getMessage())
|
||||
.isEqualTo("No setter found for property: items");
|
||||
assertThat(ex.getProperty()).isNull();
|
||||
}
|
||||
|
||||
});
|
||||
this.binder.bind("foo", target);
|
||||
}
|
||||
@ -252,6 +254,7 @@ public class BinderTests {
|
||||
public List<String> getItems() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum ExampleEnum {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -56,7 +56,6 @@ public class AtomikosPropertiesTests {
|
||||
this.properties.getRecovery().setDelay(3000);
|
||||
this.properties.getRecovery().setMaxRetries(10);
|
||||
this.properties.getRecovery().setRetryInterval(4000);
|
||||
|
||||
assertThat(this.properties.asProperties().size()).isEqualTo(17);
|
||||
assertProperty("com.atomikos.icatch.service", "service");
|
||||
assertProperty("com.atomikos.icatch.max_timeout", "1");
|
||||
|
Loading…
Reference in New Issue
Block a user