本文整理汇总了Java中org.springframework.boot.test.EnvironmentTestUtils类的典型用法代码示例。如果您正苦于以下问题:Java EnvironmentTestUtils类的具体用法?Java EnvironmentTestUtils怎么用?Java EnvironmentTestUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EnvironmentTestUtils类属于org.springframework.boot.test包,在下文中一共展示了EnvironmentTestUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testOkHttpClientAutoConfiguredWithCustomProperties
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void testOkHttpClientAutoConfiguredWithCustomProperties() {
context = new AnnotationConfigApplicationContext();
context.register(OkHttpAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(context, "spring.okhttp.connection-timeout:500");
EnvironmentTestUtils.addEnvironment(context, "spring.okhttp.read-timeout:600");
EnvironmentTestUtils.addEnvironment(context, "spring.okhttp.write-timeout:700");
context.refresh();
OkHttpClient okHttpClient = context.getBean(OkHttpClient.class);
assertThat(okHttpClient).isNotNull();
assertThat(okHttpClient.connectTimeoutMillis()).isEqualTo(500);
assertThat(okHttpClient.readTimeoutMillis()).isEqualTo(600);
assertThat(okHttpClient.writeTimeoutMillis()).isEqualTo(700);
}
开发者ID:troinine,项目名称:spring-boot-square-oss-support,代码行数:17,代码来源:OkHttpAutoConfigurationTest.java
示例2: testKeySanitizationWithCustomPatternByEnvironment
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testKeySanitizationWithCustomPatternByEnvironment() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.env.keys-to-sanitize: .*pass.*");
this.context.register(Config.class);
this.context.refresh();
System.setProperty("dbPassword", "123456");
System.setProperty("apiKey", "123456");
EnvironmentEndpoint report = getEndpointBean();
Map<String, Object> env = report.invoke();
assertEquals("******",
((Map<String, Object>) env.get("systemProperties")).get("dbPassword"));
assertEquals("123456",
((Map<String, Object>) env.get("systemProperties")).get("apiKey"));
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:18,代码来源:EnvironmentEndpointTests.java
示例3: testCycle
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testCycle() throws Exception {
this.context.register(CycleConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo.name:foo");
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class);
Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("foo");
assertNotNull(nestedProperties);
assertEquals("foo", nestedProperties.get("prefix"));
Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties");
assertNotNull(map);
assertEquals(1, map.size());
assertEquals("Cannot serialize 'foo'", map.get("error"));
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:20,代码来源:ConfigurationPropertiesReportEndpointSerializationTests.java
示例4: testExplicitDriverClassClearsUserName
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void testExplicitDriverClassClearsUserName() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.datasource.driverClassName:org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigurationTests$DatabaseDriver",
"spring.datasource.url:jdbc:foo://localhost");
this.context.register(DataSourceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
DataSource bean = this.context.getBean(DataSource.class);
assertNotNull(bean);
org.apache.tomcat.jdbc.pool.DataSource pool = (org.apache.tomcat.jdbc.pool.DataSource) bean;
assertEquals(
"org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigurationTests$DatabaseDriver",
pool.getDriverClassName());
assertNull(pool.getUsername());
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:17,代码来源:DataSourceAutoConfigurationTests.java
示例5: testNaming
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testNaming() throws Exception {
this.context.register(FooConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo.name:foo");
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class);
Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("foo");
assertNotNull(nestedProperties);
assertEquals("foo", nestedProperties.get("prefix"));
Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties");
assertNotNull(map);
assertEquals(2, map.size());
assertEquals("foo", map.get("name"));
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:20,代码来源:ConfigurationPropertiesReportEndpointSerializationTests.java
示例6: defaultPropertyValues
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void defaultPropertyValues() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:true");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DeviceDelegatingViewResolverConfiguration.class);
this.context.refresh();
LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context
.getBean("deviceDelegatingViewResolver",
LiteDeviceDelegatingViewResolver.class);
DirectFieldAccessor accessor = new DirectFieldAccessor(
liteDeviceDelegatingViewResolver);
assertEquals(false, accessor.getPropertyValue("enableFallback"));
assertEquals("", accessor.getPropertyValue("normalPrefix"));
assertEquals("mobile/", accessor.getPropertyValue("mobilePrefix"));
assertEquals("tablet/", accessor.getPropertyValue("tabletPrefix"));
assertEquals("", accessor.getPropertyValue("normalSuffix"));
assertEquals("", accessor.getPropertyValue("mobileSuffix"));
assertEquals("", accessor.getPropertyValue("tabletSuffix"));
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:25,代码来源:DeviceDelegatingViewResolverAutoConfigurationTests.java
示例7: testFieldNamingStrategy
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
public void testFieldNamingStrategy(String strategy,
Class<? extends FieldNamingStrategy> expectedType) {
this.context = new AnnotationConfigApplicationContext();
if (strategy != null) {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.mongodb.field-naming-strategy:" + strategy);
}
this.context.register(PropertyPlaceholderAutoConfiguration.class,
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class);
this.context.refresh();
MongoMappingContext mappingContext = this.context
.getBean(MongoMappingContext.class);
FieldNamingStrategy fieldNamingStrategy = (FieldNamingStrategy) ReflectionTestUtils
.getField(mappingContext, "fieldNamingStrategy");
assertEquals(expectedType, fieldNamingStrategy.getClass());
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:17,代码来源:MongoDataAutoConfigurationTests.java
示例8: createNodeClientWithOverrides
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void createNodeClientWithOverrides() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.elasticsearch.properties.foo.bar:baz",
"spring.data.elasticsearch.properties.path.data:target/data",
"spring.data.elasticsearch.properties.path.logs:target/logs",
"spring.data.elasticsearch.properties.node.local:false",
"spring.data.elasticsearch.properties.node.data:true",
"spring.data.elasticsearch.properties.http.enabled:true");
this.context.register(PropertyPlaceholderAutoConfiguration.class,
ElasticsearchAutoConfiguration.class);
this.context.refresh();
assertEquals(1, this.context.getBeanNamesForType(Client.class).length);
NodeClient client = (NodeClient) this.context.getBean(Client.class);
assertThat(client.settings().get("foo.bar"), is(equalTo("baz")));
assertThat(client.settings().get("node.local"), is(equalTo("false")));
assertThat(client.settings().get("node.data"), is(equalTo("true")));
assertThat(client.settings().get("http.enabled"), is(equalTo("true")));
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:21,代码来源:ElasticsearchAutoConfigurationTests.java
示例9: testKeySanitizationWithCustomPatternAndKeyByEnvironment
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testKeySanitizationWithCustomPatternAndKeyByEnvironment()
throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.configprops.keys-to-sanitize: .*pass.*, property");
this.context.register(Config.class);
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = getEndpointBean();
Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties
.get("testProperties")).get("properties");
assertNotNull(nestedProperties);
assertEquals("******", nestedProperties.get("dbPassword"));
assertEquals("******", nestedProperties.get("myTestProperty"));
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:18,代码来源:ConfigurationPropertiesReportEndpointTests.java
示例10: testMap
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testMap() throws Exception {
this.context.register(MapConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo.map.name:foo");
this.context.refresh();
ConfigurationPropertiesReportEndpoint report = this.context
.getBean(ConfigurationPropertiesReportEndpoint.class);
Map<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("foo");
assertNotNull(nestedProperties);
assertEquals("foo", nestedProperties.get("prefix"));
Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties");
assertNotNull(map);
assertEquals(3, map.size());
assertEquals("foo", ((Map<String, Object>) map.get("map")).get("name"));
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:20,代码来源:ConfigurationPropertiesReportEndpointSerializationTests.java
示例11: deviceDelegatingInternalResourceViewResolverDisabled
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test(expected = NoSuchBeanDefinitionException.class)
public void deviceDelegatingInternalResourceViewResolverDisabled() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.mobile.devicedelegatingviewresolver.enabled:false");
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
DeviceDelegatingViewResolverConfiguration.class);
this.context.refresh();
assertNotNull(this.context.getBean(InternalResourceViewResolver.class));
try {
this.context.getBean(ThymeleafViewResolver.class);
}
catch (NoSuchBeanDefinitionException ex) {
// expected. ThymeleafViewResolver shouldn't be defined.
}
this.context.getBean("deviceDelegatingViewResolver",
AbstractDeviceDelegatingViewResolver.class);
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:21,代码来源:DeviceDelegatingViewResolverAutoConfigurationTests.java
示例12: elasticSearchHealthIndicator
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void elasticSearchHealthIndicator() {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.elasticsearch.properties.path.data:target/data",
"spring.data.elasticsearch.properties.path.logs:target/logs",
"management.health.diskspace.enabled:false");
this.context.register(ElasticsearchAutoConfiguration.class,
ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
this.context.refresh();
Map<String, HealthIndicator> beans = this.context
.getBeansOfType(HealthIndicator.class);
assertEquals(1, beans.size());
assertEquals(ElasticsearchHealthIndicator.class,
beans.values().iterator().next().getClass());
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:17,代码来源:HealthIndicatorAutoConfigurationTests.java
示例13: load
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
private AnnotationConfigApplicationContext load(Class<?> config, String... env) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, env);
context.register(config);
context.refresh();
return context;
}
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:8,代码来源:OnSecurityEnabledAndOAuth2DisabledTests.java
示例14: load
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
applicationContext.register(config);
applicationContext.register(S3AutoConfiguration.class);
applicationContext.refresh();
this.context = applicationContext;
}
开发者ID:kbastani,项目名称:spring-boot-starter-amazon-s3,代码行数:9,代码来源:S3AutoConfigurationTest.java
示例15: load
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
applicationContext.register(config);
applicationContext.register(GraphQLAutoConfiguration.class);
applicationContext.refresh();
this.context = applicationContext;
}
开发者ID:oembedler,项目名称:graphql-spring-boot,代码行数:9,代码来源:GraphQLAutoConfigurationTest.java
示例16: should_set_service_with_valid_id_name_and_description_and_plans
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void should_set_service_with_valid_id_name_and_description_and_plans() {
this.context.register(TestConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"services.tripadvisor.name:a_name",
"services.tripadvisor.description:a_description",
"services.tripadvisor.plans.default.name:default",
"services.tripadvisor.plans.default.id:default_id",
"services.tripadvisor.plans.default.credentials.uri:http://localhost");
this.context.refresh();
}
开发者ID:orange-cloudfoundry,项目名称:static-creds-broker,代码行数:12,代码来源:ServicePropertiesTest.java
示例17: fail_to_set_service_with_no_name
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void fail_to_set_service_with_no_name() {
this.context.register(TestConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"services.tripadvisor.name:",
"services.tripadvisor.description:a_description",
"services.tripadvisor.plans.default.name:default");
this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage(ServiceProperties.NO_NAME_ERROR);
this.context.refresh();
}
开发者ID:orange-cloudfoundry,项目名称:static-creds-broker,代码行数:12,代码来源:ServicePropertiesTest.java
示例18: fail_to_set_service_with_no_description
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void fail_to_set_service_with_no_description() {
this.context.register(TestConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"services.tripadvisor.name:a_name",
"services.tripadvisor.description:",
"services.tripadvisor.plans.default.name:default");
this.thrown.expect(BeanCreationException.class);
this.thrown.expectMessage(ServiceProperties.NO_DESCRIPTION_ERROR);
this.context.refresh();
}
开发者ID:orange-cloudfoundry,项目名称:static-creds-broker,代码行数:12,代码来源:ServicePropertiesTest.java
示例19: headersAppendedIfNecessary
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void headersAppendedIfNecessary() {
EnvironmentTestUtils.addEnvironment(this.environment, "spring.cloud.stream.test.binder.headers[0]=X-Custom",
"spring.cloud.stream.test.binder.headers[1]=X-Mine");
this.processor.postProcessEnvironment(this.environment,
new SpringApplication(StreamEnvironmentPostProcessorTests.class));
assertThat(this.environment.getProperty("spring.cloud.stream.test.binder.headers[2]"))
.isEqualTo(Span.SPAN_ID_NAME);
}
开发者ID:reshmik,项目名称:Zipkin,代码行数:10,代码来源:StreamEnvironmentPostProcessorTests.java
示例20: localDirCanBeCustomized
import org.springframework.boot.test.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void localDirCanBeCustomized() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context, "ftp.localDir:local");
context.register(Conf.class);
context.refresh();
FtpSourceProperties properties = context.getBean(FtpSourceProperties.class);
assertThat(properties.getLocalDir(), equalTo(new File("local")));
}
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:10,代码来源:FtpSourcePropertiesTests.java
注:本文中的org.springframework.boot.test.EnvironmentTestUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论