本文整理汇总了Java中org.springframework.boot.test.util.EnvironmentTestUtils类的典型用法代码示例。如果您正苦于以下问题:Java EnvironmentTestUtils类的具体用法?Java EnvironmentTestUtils怎么用?Java EnvironmentTestUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EnvironmentTestUtils类属于org.springframework.boot.test.util包,在下文中一共展示了EnvironmentTestUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gridFsTemplateExists
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void gridFsTemplateExists() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.mongodb.gridFsDatabase:grid");
this.context.register(PropertyPlaceholderAutoConfiguration.class,
MongoAutoConfiguration.class, MongoDataAutoConfiguration.class);
this.context.refresh();
assertThat(this.context.getBeanNamesForType(GridFsTemplate.class).length)
.isEqualTo(1);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:MongoDataAutoConfigurationTests.java
示例2: init
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Before
public void init() {
dbUrl = "h2:mem:testdb-" + new Random().nextInt();
EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.initialize:false",
"spring.datasource.url:jdbc:" + dbUrl);
context.setClassLoader(new HidePackagesClassLoader("com.vladmihalcea.flexypool", "net.ttddyy.dsproxy"));
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
TraceAutoConfiguration.class,
SleuthLogAutoConfiguration.class,
SleuthListenerAutoConfiguration.class,
SavingSpanReporterConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
dataSource = context.getBean(DataSource.class);
spanReporter = context.getBean(CollectingSpanReporter.class);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:20,代码来源:TracingJdbcEventListenerTests.java
示例3: init
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Before
public void init() {
dbUrl = "h2:mem:testdb-" + new Random().nextInt();
EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.initialize:false",
"spring.datasource.url:jdbc:" + dbUrl);
context.setClassLoader(new HidePackagesClassLoader("com.vladmihalcea.flexypool", "com.p6spy"));
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
SavingSpanReporterConfiguration.class,
TraceAutoConfiguration.class,
SleuthLogAutoConfiguration.class,
SleuthListenerAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
dataSource = context.getBean(DataSource.class);
spanReporter = context.getBean(CollectingSpanReporter.class);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:20,代码来源:TracingQueryExecutionListenerTests.java
示例4: testDecoratedHikariSpecificPropertiesIsSet
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void testDecoratedHikariSpecificPropertiesIsSet() throws Exception {
EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.type:" + HikariDataSource.class.getName(),
"spring.datasource.hikari.catalog:test_catalog");
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
DataSource dataSource = context.getBean(DataSource.class);
assertThat(dataSource).isNotNull();
assertThat(dataSource).isInstanceOf(DecoratedDataSource.class);
DataSource realDataSource = ((DecoratedDataSource) dataSource).getRealDataSource();
assertThat(realDataSource).isInstanceOf(HikariDataSource.class);
assertThat(((HikariDataSource) realDataSource).getCatalog()).isEqualTo("test_catalog");
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:17,代码来源:DataSourceDecoratorAutoConfigurationTests.java
示例5: testDecoratingCanBeDisabledForSpecificBeans
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void testDecoratingCanBeDisabledForSpecificBeans() throws Exception {
EnvironmentTestUtils.addEnvironment(context,
"decorator.datasource.exclude-beans:secondDataSource");
context.register(TestMultiDataSourceConfiguration.class,
DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
DataSource dataSource = context.getBean("dataSource", DataSource.class);
assertThat(dataSource).isInstanceOf(DecoratedDataSource.class);
DataSource secondDataSource = context.getBean("secondDataSource", DataSource.class);
assertThat(secondDataSource).isInstanceOf(BasicDataSource.class);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:17,代码来源:DataSourceDecoratorAutoConfigurationTests.java
示例6: testDecoratingHikariDataSourceWithDefaultStrategies
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void testDecoratingHikariDataSourceWithDefaultStrategies() throws Exception {
EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.type:" + HikariDataSource.class.getName());
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
context.refresh();
DataSource dataSource = context.getBean(DataSource.class);
assertDataSourceOfType(dataSource, HikariDataSource.class);
FlexyPoolDataSource<HikariDataSource> flexyPoolDataSource = assertDataSourceOfType(dataSource, HikariDataSource.class);
IncrementPoolOnTimeoutConnectionAcquiringStrategy strategy1 =
findStrategy(flexyPoolDataSource, IncrementPoolOnTimeoutConnectionAcquiringStrategy.class);
assertThat(strategy1).isNotNull();
assertThat(strategy1).hasFieldOrPropertyWithValue("maxOverflowPoolSize", 15);
assertThat(strategy1).hasFieldOrPropertyWithValue("timeoutMillis", 500);
RetryConnectionAcquiringStrategy strategy2 =
findStrategy(flexyPoolDataSource, RetryConnectionAcquiringStrategy.class);
assertThat(strategy2).isNotNull();
assertThat(strategy2).hasFieldOrPropertyWithValue("retryAttempts", 2);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:24,代码来源:FlexyPoolConfigurationTests.java
示例7: testDecoratingHikariDataSourceWithCustomPropertyStrategies
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void testDecoratingHikariDataSourceWithCustomPropertyStrategies() throws Exception {
EnvironmentTestUtils.addEnvironment(context,
"spring.datasource.type:" + HikariDataSource.class.getName(),
"decorator.datasource.flexy-pool.acquiring-strategy.increment-pool.max-overflow-pool-size:15",
"decorator.datasource.flexy-pool.acquiring-strategy.increment-pool.timeout-millis:500",
"decorator.datasource.flexy-pool.acquiring-strategy.retry.attempts:5");
context.register(DataSourceAutoConfiguration.class,
DataSourceDecoratorAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
HikariConfiguration.class);
context.refresh();
DataSource dataSource = context.getBean(DataSource.class);
FlexyPoolDataSource<HikariDataSource> flexyPoolDataSource = assertDataSourceOfType(dataSource, HikariDataSource.class);
IncrementPoolOnTimeoutConnectionAcquiringStrategy strategy1 =
findStrategy(flexyPoolDataSource, IncrementPoolOnTimeoutConnectionAcquiringStrategy.class);
assertThat(strategy1).isNotNull();
assertThat(strategy1).hasFieldOrPropertyWithValue("maxOverflowPoolSize", 35);
assertThat(strategy1).hasFieldOrPropertyWithValue("timeoutMillis", 10000);
RetryConnectionAcquiringStrategy strategy2 =
findStrategy(flexyPoolDataSource, RetryConnectionAcquiringStrategy.class);
assertThat(strategy2).isNotNull();
assertThat(strategy2).hasFieldOrPropertyWithValue("retryAttempts", 5);
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:27,代码来源:FlexyPoolConfigurationTests.java
示例8: testMissingSSLProperty
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test(expected = BeanCreationException.class)
public void testMissingSSLProperty() throws Exception {
context.register(SpringBootstrap.class);
// @formatter:off
EnvironmentTestUtils.addEnvironment(this.context,
"qonduit.server.ip:127.0.0.1",
"qonduit.server.tcp-port:54321",
"qonduit.server.udp-port:54325",
"qonduit.http.ip:127.0.0.1",
"qonduit.http.port:54322",
"qonduit.websocket.ip:127.0.0.1",
"qonduit.websocket.port:54323",
"qonduit.accumulo.zookeepers:localhost:2181",
"qonduit.accumulo.instance-name:test",
"qonduit.accumulo.username:root",
"qonduit.accumulo.password:secret",
"qonduit.http.host:localhost");
// @formatter:on
context.refresh();
}
示例9: testSSLProperty
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void testSSLProperty() throws Exception {
context.register(SpringBootstrap.class);
// @formatter:off
EnvironmentTestUtils.addEnvironment(this.context,
"qonduit.server.ip:127.0.0.1",
"qonduit.http.ip:127.0.0.1",
"qonduit.http.port:54322",
"qonduit.websocket.ip:127.0.0.1",
"qonduit.websocket.port:54323",
"qonduit.accumulo.zookeepers:localhost:2181",
"qonduit.accumulo.instance-name:test",
"qonduit.accumulo.username:root",
"qonduit.accumulo.password:secret",
"qonduit.http.host:localhost",
"qonduit.security.ssl.certificate-file:/tmp/foo",
"qonduit.security.ssl.key-file:/tmp/bar");
// @formatter:on
context.refresh();
}
示例10: createFromConfigClass
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void createFromConfigClass() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "spring.thymeleaf.mode:XHTML",
"spring.thymeleaf.suffix:");
this.context.register(ThymeleafAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
TemplateEngine engine = this.context.getBean(TemplateEngine.class);
Context attrs = new Context(Locale.UK, Collections.singletonMap("foo", "bar"));
String result = engine.process("template.txt", attrs);
assertThat(result).isEqualTo("<html>bar</html>");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:ThymeleafAutoConfigurationTests.java
示例11: testAuthorizationServerOverride
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void testAuthorizationServerOverride() {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"security.oauth2.resourceId:resource-id");
this.context.register(AuthorizationAndResourceServerConfiguration.class,
CustomAuthorizationServer.class, MinimalSecureWebApplication.class);
this.context.refresh();
BaseClientDetails config = new BaseClientDetails();
config.setClientId("client");
config.setClientSecret("secret");
config.setResourceIds(Arrays.asList("resource-id"));
config.setAuthorizedGrantTypes(Arrays.asList("password"));
config.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList("USER"));
config.setScope(Arrays.asList("read"));
assertThat(countBeans(AUTHORIZATION_SERVER_CONFIG)).isEqualTo(0);
assertThat(countBeans(RESOURCE_SERVER_CONFIG)).isEqualTo(1);
verifyAuthentication(config);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:OAuth2AutoConfigurationTests.java
示例12: testNestedNaming
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testNestedNaming() throws Exception {
this.context.register(FooConfig.class);
EnvironmentTestUtils.addEnvironment(this.context, "foo.bar.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");
assertThat(nestedProperties).isNotNull();
Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties");
assertThat(map).isNotNull();
assertThat(map).hasSize(2);
assertThat(((Map<String, Object>) map.get("bar")).get("name")).isEqualTo("foo");
}
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:19,代码来源:ConfigurationPropertiesReportEndpointSerializationTests.java
示例13: testKeySanitizationWithCustomPatternUsingCompositeKeys
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testKeySanitizationWithCustomPatternUsingCompositeKeys()
throws Exception {
// gh-4415
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context,
"endpoints.configprops.keys-to-sanitize: .*\\.secrets\\..*, .*\\.hidden\\..*");
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");
assertThat(nestedProperties).isNotNull();
Map<String, Object> secrets = (Map<String, Object>) nestedProperties
.get("secrets");
Map<String, Object> hidden = (Map<String, Object>) nestedProperties.get("hidden");
assertThat(secrets.get("mine")).isEqualTo("******");
assertThat(secrets.get("yours")).isEqualTo("******");
assertThat(hidden.get("mine")).isEqualTo("******");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:ConfigurationPropertiesReportEndpointTests.java
示例14: customizationOfSupportedMediaTypesCanBeDisabled
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void customizationOfSupportedMediaTypesCanBeDisabled() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(BaseConfig.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.hateoas.use-hal-as-default-json-media-type:false");
this.context.refresh();
RequestMappingHandlerAdapter handlerAdapter = this.context
.getBean(RequestMappingHandlerAdapter.class);
for (HttpMessageConverter<?> converter : handlerAdapter.getMessageConverters()) {
if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
assertThat(converter.getSupportedMediaTypes())
.containsExactly(MediaTypes.HAL_JSON);
}
}
}
示例15: testSecurityFilterDoesNotCauseEarlyInitialization
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入依赖的package包/类
@Test
public void testSecurityFilterDoesNotCauseEarlyInitialization() throws Exception {
AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext();
try {
EnvironmentTestUtils.addEnvironment(context, "server.port:0",
"security.user.password:password");
context.register(Config.class);
context.refresh();
int port = context.getEmbeddedServletContainer().getPort();
new TestRestTemplate("user", "password")
.getForEntity("http://localhost:" + port, Object.class);
// If early initialization occurred a ConverterNotFoundException is thrown
}
finally {
context.close();
}
}
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:20,代码来源:SecurityFilterAutoConfigurationEarlyInitializationTests.java