本文整理汇总了Java中org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment方法的典型用法代码示例。如果您正苦于以下问题:Java EnvironmentTestUtils.addEnvironment方法的具体用法?Java EnvironmentTestUtils.addEnvironment怎么用?Java EnvironmentTestUtils.addEnvironment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.boot.test.util.EnvironmentTestUtils
的用法示例。
在下文中一共展示了EnvironmentTestUtils.addEnvironment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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
示例2: testDataSourcePropertiesOverridden
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
@Test
public void testDataSourcePropertiesOverridden() throws Exception {
this.context.register(CommonsDbcpDataSourceConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "url:jdbc:foo//bar/spam");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testWhileIdle:true");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnBorrow:true");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "testOnReturn:true");
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "timeBetweenEvictionRunsMillis:10000");
EnvironmentTestUtils.addEnvironment(this.context,
PREFIX + "minEvictableIdleTimeMillis:12345");
EnvironmentTestUtils.addEnvironment(this.context, PREFIX + "maxWait:1234");
this.context.refresh();
BasicDataSource ds = this.context.getBean(BasicDataSource.class);
assertThat(ds.getUrl()).isEqualTo("jdbc:foo//bar/spam");
assertThat(ds.getTestWhileIdle()).isTrue();
assertThat(ds.getTestOnBorrow()).isTrue();
assertThat(ds.getTestOnReturn()).isTrue();
assertThat(ds.getTimeBetweenEvictionRunsMillis()).isEqualTo(10000);
assertThat(ds.getMinEvictableIdleTimeMillis()).isEqualTo(12345);
assertThat(ds.getMaxWait()).isEqualTo(1234);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:24,代码来源:CommonsDbcpDataSourceConfigurationTests.java
示例3: testInfoEndpointOrdering
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
@Test
public void testInfoEndpointOrdering() throws Exception {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "info.name:foo");
this.context.register(CustomInfoContributorsConfig.class,
ProjectInfoAutoConfiguration.class,
InfoContributorAutoConfiguration.class, EndpointAutoConfiguration.class);
this.context.refresh();
InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class);
Map<String, Object> info = endpoint.invoke();
assertThat(info).isNotNull();
assertThat(info.get("name")).isEqualTo("foo");
assertThat(info.get("version")).isEqualTo("1.0");
Object git = info.get("git");
assertThat(git).isInstanceOf(Map.class);
}
示例4: portIsAvailableInParentContext
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
@Test
public void portIsAvailableInParentContext() {
ConfigurableApplicationContext parent = new AnnotationConfigApplicationContext();
parent.refresh();
try {
this.context = new AnnotationConfigApplicationContext();
this.context.setParent(parent);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.data.mongodb.port=0");
this.context.register(EmbeddedMongoAutoConfiguration.class,
MongoClientConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertThat(parent.getEnvironment().getProperty("local.mongo.port"))
.isNotNull();
}
finally {
parent.close();
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:21,代码来源:EmbeddedMongoAutoConfigurationTests.java
示例5: testWebConfiguration
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
@Test
public void testWebConfiguration() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(SecurityAutoConfiguration.class,
WebMvcAutoConfiguration.class,
ManagementWebSecurityAutoConfiguration.class,
JacksonAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
ManagementServerPropertiesAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
this.context.refresh();
assertThat(this.context.getBean(AuthenticationManagerBuilder.class)).isNotNull();
FilterChainProxy filterChainProxy = this.context.getBean(FilterChainProxy.class);
// 1 for static resources, one for management endpoints and one for the rest
assertThat(filterChainProxy.getFilterChains()).hasSize(3);
assertThat(filterChainProxy.getFilters("/beans")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/beans/")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/beans.foo")).isNotEmpty();
assertThat(filterChainProxy.getFilters("/beans/foo/bar")).isNotEmpty();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:24,代码来源:ManagementWebSecurityAutoConfigurationTests.java
示例6: testKeySanitizationWithCustomPatternAndKeyByEnvironment
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
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");
assertThat(nestedProperties).isNotNull();
assertThat(nestedProperties.get("dbPassword")).isEqualTo("******");
assertThat(nestedProperties.get("myTestProperty")).isEqualTo("******");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:ConfigurationPropertiesReportEndpointTests.java
示例7: initialize
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
@Override
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
"cassandra.host=" + cassandra.getContainerIpAddress(),
"cassandra.port=" + cassandra.getMappedPort(9042)
);
}
示例8: load
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
private void load(boolean refresh, String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(RocketMqAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(ctx, environment);
if (refresh) {
ctx.refresh();
}
this.context = ctx;
}
示例9: databaseBeanCreation
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
@Test
public void databaseBeanCreation() {
Database mockDb = mock(Database.class);
when(mockBuilder.build()).thenReturn(mockClient);
when(mockClient.database("testName", true)).thenReturn(mockDb);
this.context.register(MockCloudantClientConfig.class, MockClientBuilderConfig.class,
CloudantAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "cloudant.db=testName");
this.context.refresh();
Database db = this.context.getBean(Database.class);
assertEquals(mockDb, db);
}
示例10: outputNameCanBeCustomized
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
@Test
public void outputNameCanBeCustomized() {
EnvironmentTestUtils.addEnvironment(context, "tensorflow.outputName:outputName2");
context.register(Conf.class);
context.refresh();
TensorflowCommonProcessorProperties properties = context.getBean(TensorflowCommonProcessorProperties.class);
assertThat(properties.getOutputName(), equalTo("outputName2"));
}
开发者ID:spring-cloud-stream-app-starters,项目名称:tensorflow,代码行数:9,代码来源:TensorflowProcessorPropertiesTests.java
示例11: modelLocationCanBeCustomized
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
@Test
public void modelLocationCanBeCustomized() {
EnvironmentTestUtils.addEnvironment(context, "tensorflow.modelLocation:/remote");
context.register(Conf.class);
context.refresh();
TensorflowProcessorProperties properties = context.getBean(TensorflowProcessorProperties.class);
assertThat(properties.getModelLocation(), equalTo(context.getResource("/remote")));
}
开发者ID:tzolov,项目名称:tensorflow-spring-cloud-stream-app-starters,代码行数:9,代码来源:TensorflowProcessorPropertiesTest.java
示例12: load
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
private void load(Class<?> config, String... environment) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(applicationContext, environment);
applicationContext.register(config);
applicationContext.register(GitHubAutoConfiguration.class);
applicationContext.refresh();
this.context = applicationContext;
}
示例13: load
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
private void load(boolean refresh, String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(RocketMQAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(ctx, environment);
if (refresh) {
ctx.refresh();
}
this.context = ctx;
}
示例14: testFooCreatePropertyTrue
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
@Test
public void testFooCreatePropertyTrue() {
EnvironmentTestUtils.addEnvironment(context, "foo.create=true");
context.register(FooConfiguration.class);
context.refresh();
assertNotNull(context.getBean(Foo.class));
}
示例15: init
import org.springframework.boot.test.util.EnvironmentTestUtils; //导入方法依赖的package包/类
@Before
public void init() {
EnvironmentTestUtils.addEnvironment(context,
"datasource.initialize:false",
"datasource.url:jdbc:h2:mem:testdb-" + new Random().nextInt());
context.setClassLoader(new HidePackagesClassLoader("net.ttddyy.dsproxy", "com.p6spy"));
}
开发者ID:gavlyukovskiy,项目名称:spring-boot-data-source-decorator,代码行数:8,代码来源:FlexyPoolConfigurationTests.java