/*
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.context.properties;
import java.beans.PropertyEditorSupport;
import java.io.File;
import java.text.ParseException;
import java.time.Duration;
import java.time.Period;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import javax.annotation.PostConstruct;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.properties.bind.BindException;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.boot.context.properties.bind.validation.BindValidationException;
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
import org.springframework.boot.convert.ApplicationConversionService;
import org.springframework.boot.convert.DataSizeUnit;
import org.springframework.boot.convert.DurationFormat;
import org.springframework.boot.convert.DurationStyle;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.boot.convert.PeriodFormat;
import org.springframework.boot.convert.PeriodStyle;
import org.springframework.boot.convert.PeriodUnit;
import org.springframework.boot.env.RandomValuePropertySource;
import org.springframework.boot.testsupport.system.CapturedOutput;
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.env.SystemEnvironmentPropertySource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.ProtocolResolver;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.format.Formatter;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.stereotype.Component;
import org.springframework.test.context.support.TestPropertySourceUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import org.springframework.validation.annotation.Validated;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link ConfigurationProperties @ConfigurationProperties}-annotated beans.
* Covers {@link EnableConfigurationProperties @EnableConfigurationProperties},
* {@link ConfigurationPropertiesBindingPostProcessor} and
* {@link ConfigurationPropertiesBinder}.
*
* @author Dave Syer
* @author Christian Dupuis
* @author Phillip Webb
* @author Stephane Nicoll
* @author Madhura Bhave
* @author Vladislav Kisel
*/
@ExtendWith(OutputCaptureExtension.class)
class ConfigurationPropertiesTests {
private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
@AfterEach
void cleanup() {
this.context.close();
System.clearProperty("name");
System.clearProperty("nested.name");
System.clearProperty("nested_name");
}
@Test
void loadShouldBind() {
load(BasicConfiguration.class, "name=foo");
assertThat(this.context.getBeanNamesForType(BasicProperties.class)).hasSize(1);
assertThat(this.context.containsBean(BasicProperties.class.getName())).isTrue();
assertThat(this.context.getBean(BasicProperties.class).name).isEqualTo("foo");
}
@Test
void loadShouldBindNested() {
load(NestedConfiguration.class, "name=foo", "nested.name=bar");
assertThat(this.context.getBeanNamesForType(NestedProperties.class)).hasSize(1);
assertThat(this.context.getBean(NestedProperties.class).name).isEqualTo("foo");
assertThat(this.context.getBean(NestedProperties.class).nested.name).isEqualTo("bar");
}
@Test
void loadWhenUsingSystemPropertiesShouldBind() {
System.setProperty("name", "foo");
load(BasicConfiguration.class);
assertThat(this.context.getBeanNamesForType(BasicProperties.class)).hasSize(1);
assertThat(this.context.getBean(BasicProperties.class).name).isEqualTo("foo");
}
@Test
void loadWhenUsingSystemPropertiesShouldBindNested() {
System.setProperty("name", "foo");
System.setProperty("nested.name", "bar");
load(NestedConfiguration.class);
assertThat(this.context.getBeanNamesForType(NestedProperties.class)).hasSize(1);
assertThat(this.context.getBean(NestedProperties.class).name).isEqualTo("foo");
assertThat(this.context.getBean(NestedProperties.class).nested.name).isEqualTo("bar");
}
@Test
void loadWhenHasIgnoreUnknownFieldsFalseAndNoUnknownFieldsShouldBind() {
removeSystemProperties();
load(IgnoreUnknownFieldsFalseConfiguration.class, "name=foo");
IgnoreUnknownFieldsFalseProperties bean = this.context.getBean(IgnoreUnknownFieldsFalseProperties.class);
assertThat(((BasicProperties) bean).name).isEqualTo("foo");
}
@Test
void loadWhenHasIgnoreUnknownFieldsFalseAndUnknownFieldsShouldFail() {
removeSystemProperties();
assertT
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
spring boot 2.7.1 源码 (2000个子文件)
bootstrap.min.css 141KB
bootstrap.min.css 81KB
bootstrap.min.css 81KB
bootstrap.min.css 81KB
bootstrap.min.css 81KB
bootstrap.min.css 81KB
spring-javadoc.css 13KB
spring-javadoc.css 13KB
application.css 110B
test.css 5B
custom.css 2B
snake.html 7KB
snake.html 7KB
snake.html 7KB
snake.html 7KB
reverse.html 4KB
reverse.html 4KB
reverse.html 4KB
reverse.html 4KB
echo.html 4KB
echo.html 4KB
echo.html 4KB
echo.html 4KB
form.html 2KB
view.html 1KB
list.html 1KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1KB
home.html 1KB
index.html 1KB
home.html 709B
fragments.html 684B
login.html 514B
login.html 513B
login.html 511B
login.html 510B
layout.html 379B
layout.html 334B
view.html 315B
partial.html 314B
index.html 188B
access.html 185B
home.html 132B
home.html 129B
home.html 129B
home.html 129B
home.html 126B
java8time-dialect.html 76B
message.html 76B
503.html 70B
5xx.html 70B
security-dialect.html 64B
index.html 58B
content.html 54B
home.html 48B
data-dialect.html 45B
template.html 34B
index.html 19B
template.html 16B
template.html 16B
foo.html 16B
index.html 14B
index.html 14B
index.html 14B
index.html 14B
index.html 14B
index.html 14B
index.html 14B
index.html 14B
index.html 14B
index.html 14B
404.html 10B
4xx.html 10B
402.html 8B
4xx.html 8B
5xx.html 8B
4xx.html 8B
foo_de.html 2B
actuator-docs-index.html 1B
custom.html 1B
actuator-docs-index.html 1B
ConfigurationPropertiesTests.java 79KB
SpringApplicationTests.java 71KB
AbstractServletWebServerFactoryTests.java 67KB
WebMvcAutoConfigurationTests.java 60KB
ConfigFileApplicationListenerTests.java 53KB
SpringApplication.java 52KB
RabbitAutoConfigurationTests.java 50KB
JsonContentAssert.java 47KB
TestRestTemplate.java 43KB
JsonContentAssertTests.java 43KB
KafkaAutoConfigurationTests.java 42KB
CacheAutoConfigurationTests.java 41KB
ConfigDataEnvironmentPostProcessorIntegrationTests.java 40KB
ServerProperties.java 39KB
KafkaProperties.java 38KB
QuartzEndpointTests.java 37KB
WebFluxAutoConfigurationTests.java 36KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
yehong1225
- 粉丝: 21
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0