當前位置: 首頁>>代碼示例>>Java>>正文


Java EnvironmentTestUtils類代碼示例

本文整理匯總了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();
}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:21,代碼來源:ConfigurationTest.java

示例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();
}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:21,代碼來源:ConfigurationTest.java

示例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);
		}
	}
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:18,代碼來源:HypermediaAutoConfigurationTests.java

示例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


注:本文中的org.springframework.boot.test.util.EnvironmentTestUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。