本文整理汇总了Java中org.springframework.boot.test.util.TestPropertyValues类的典型用法代码示例。如果您正苦于以下问题:Java TestPropertyValues类的具体用法?Java TestPropertyValues怎么用?Java TestPropertyValues使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TestPropertyValues类属于org.springframework.boot.test.util包,在下文中一共展示了TestPropertyValues类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: springSocialUserInfo
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void springSocialUserInfo() {
TestPropertyValues
.of("security.oauth2.resource.userInfoUri:http://example.com",
"spring.social.facebook.app-id=foo",
"spring.social.facebook.app-secret=bar")
.applyTo(this.environment);
this.context = new SpringApplicationBuilder(SocialResourceConfiguration.class)
.environment(this.environment).web(WebApplicationType.SERVLET).run();
ConnectionFactoryLocator connectionFactory = this.context
.getBean(ConnectionFactoryLocator.class);
assertThat(connectionFactory).isNotNull();
SpringSocialTokenServices services = this.context
.getBean(SpringSocialTokenServices.class);
assertThat(services).isNotNull();
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:17,代码来源:ResourceServerTokenServicesConfigurationTests.java
示例2: testEnvironmentalOverrides
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void testEnvironmentalOverrides() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
TestPropertyValues
.of("security.oauth2.client.clientId:myclientid",
"security.oauth2.client.clientSecret:mysecret",
"security.oauth2.client.autoApproveScopes:read,write",
"security.oauth2.client.accessTokenValiditySeconds:40",
"security.oauth2.client.refreshTokenValiditySeconds:80")
.applyTo(this.context);
this.context.register(AuthorizationAndResourceServerConfiguration.class,
MinimalSecureWebApplication.class);
this.context.refresh();
ClientDetails config = this.context.getBean(ClientDetails.class);
assertThat(config.getClientId()).isEqualTo("myclientid");
assertThat(config.getClientSecret()).isEqualTo("mysecret");
assertThat(config.isAutoApprove("read")).isTrue();
assertThat(config.isAutoApprove("write")).isTrue();
assertThat(config.isAutoApprove("foo")).isFalse();
assertThat(config.getAccessTokenValiditySeconds()).isEqualTo(40);
assertThat(config.getRefreshTokenValiditySeconds()).isEqualTo(80);
verifyAuthentication(config);
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:24,代码来源:OAuth2AutoConfigurationTests.java
示例3: testCanUseClientCredentials
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void testCanUseClientCredentials() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(TestSecurityConfiguration.class,
MinimalSecureWebApplication.class);
TestPropertyValues
.of("security.oauth2.client.clientId=client",
"security.oauth2.client.grantType=client_credentials")
.applyTo(this.context);
ConfigurationPropertySources.attach(this.context.getEnvironment());
this.context.refresh();
OAuth2ClientContext bean = this.context.getBean(OAuth2ClientContext.class);
assertThat(bean.getAccessTokenRequest()).isNotNull();
assertThat(countBeans(ClientCredentialsResourceDetails.class)).isEqualTo(1);
assertThat(countBeans(OAuth2ClientContext.class)).isEqualTo(1);
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:17,代码来源:OAuth2AutoConfigurationTests.java
示例4: testCanUseClientCredentialsWithEnableOAuth2Client
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void testCanUseClientCredentialsWithEnableOAuth2Client() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(ClientConfiguration.class,
MinimalSecureWebApplication.class);
TestPropertyValues
.of("security.oauth2.client.clientId=client",
"security.oauth2.client.grantType=client_credentials")
.applyTo(this.context);
ConfigurationPropertySources.attach(this.context.getEnvironment());
this.context.refresh();
// The primary context is fine (not session scoped):
OAuth2ClientContext bean = this.context.getBean(OAuth2ClientContext.class);
assertThat(bean.getAccessTokenRequest()).isNotNull();
assertThat(countBeans(ClientCredentialsResourceDetails.class)).isEqualTo(1);
// Kind of a bug (should ideally be 1), but the cause is in Spring OAuth2 (there
// is no need for the extra session-scoped bean). What this test proves is that
// even if the user screws up and does @EnableOAuth2Client for client credentials,
// it will still just about work (because of the @Primary annotation on the
// Boot-created instance of OAuth2ClientContext).
assertThat(countBeans(OAuth2ClientContext.class)).isEqualTo(2);
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:23,代码来源:OAuth2AutoConfigurationTests.java
示例5: testAuthorizationServerOverride
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void testAuthorizationServerOverride() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
TestPropertyValues.of("security.oauth2.resourceId:resource-id")
.applyTo(this.context);
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:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:20,代码来源:OAuth2AutoConfigurationTests.java
示例6: testWithCheckConfigLocationFileDoesNotExists
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void testWithCheckConfigLocationFileDoesNotExists() {
TestPropertyValues.of("mybatis.config-location:foo.xml",
"mybatis.check-config-location=true")
.applyTo(this.context);
this.context.register(EmbeddedDataSourceConfiguration.class,
MybatisAutoConfiguration.class);
try {
this.context.refresh();
fail("Should be occurred a BeanCreationException.");
} catch (BeanCreationException e) {
assertThat(e.getMessage()).isEqualTo("Error creating bean with name 'mybatisAutoConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Cannot find config location: class path resource [foo.xml] (please add config file or check your Mybatis configuration)");
}
}
示例7: testMixedWithConfigurationFileAndInterceptor
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void testMixedWithConfigurationFileAndInterceptor() {
TestPropertyValues.of(
"mybatis.config-location:mybatis-config-settings-only.xml")
.applyTo(this.context);
this.context.register(EmbeddedDataSourceConfiguration.class,
MybatisInterceptorConfiguration.class);
this.context.refresh();
org.apache.ibatis.session.Configuration configuration = this.context.getBean(
SqlSessionFactory.class).getConfiguration();
assertThat(this.context.getBeanNamesForType(SqlSessionFactory.class)).hasSize(1);
assertThat(this.context.getBeanNamesForType(SqlSessionTemplate.class)).hasSize(1);
assertThat(this.context.getBeanNamesForType(CityMapper.class)).hasSize(1);
assertThat(configuration.getDefaultFetchSize()).isEqualTo(1000);
assertThat(configuration.getInterceptors()).hasSize(1);
assertThat(configuration.getInterceptors().get(0)).isInstanceOf(MyInterceptor.class);
}
示例8: testMixedWithConfigurationFileAndDatabaseIdProvider
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void testMixedWithConfigurationFileAndDatabaseIdProvider() {
TestPropertyValues.of(
"mybatis.config-location:mybatis-config-settings-only.xml")
.applyTo(this.context);
this.context.register(EmbeddedDataSourceConfiguration.class,
MybatisBootMapperScanAutoConfiguration.class,
DatabaseProvidersConfiguration.class);
this.context.refresh();
org.apache.ibatis.session.Configuration configuration = this.context.getBean(
SqlSessionFactory.class).getConfiguration();
assertThat(this.context.getBeanNamesForType(SqlSessionFactory.class)).hasSize(1);
assertThat(this.context.getBeanNamesForType(SqlSessionTemplate.class)).hasSize(1);
assertThat(this.context.getBeanNamesForType(CityMapper.class)).hasSize(1);
assertThat(configuration.getDefaultFetchSize()).isEqualTo(1000);
assertThat(configuration.getDatabaseId()).isEqualTo("h2");
}
示例9: testMixedWithConfigurationFileAndTypeHandlersPackage
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void testMixedWithConfigurationFileAndTypeHandlersPackage() {
TestPropertyValues.of(
"mybatis.config-location:mybatis-config-settings-only.xml",
"mybatis.type-handlers-package:org.mybatis.spring.boot.autoconfigure.handler")
.applyTo(this.context);
this.context.register(EmbeddedDataSourceConfiguration.class,
MybatisBootMapperScanAutoConfiguration.class);
this.context.refresh();
org.apache.ibatis.session.Configuration configuration = this.context.getBean(
SqlSessionFactory.class).getConfiguration();
assertThat(this.context.getBeanNamesForType(SqlSessionFactory.class)).hasSize(1);
assertThat(this.context.getBeanNamesForType(SqlSessionTemplate.class)).hasSize(1);
assertThat(this.context.getBeanNamesForType(CityMapper.class)).hasSize(1);
assertThat(configuration.getDefaultFetchSize()).isEqualTo(1000);
assertThat(configuration.getTypeHandlerRegistry().getTypeHandler(BigInteger.class)).isInstanceOf(DummyTypeHandler.class);
}
示例10: testMixedWithConfigurationFileAndTypeAliasesPackageAndMapperLocations
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void testMixedWithConfigurationFileAndTypeAliasesPackageAndMapperLocations() {
TestPropertyValues.of(
"mybatis.config-location:mybatis-config-settings-only.xml",
"mybatis.type-aliases-package:org.mybatis.spring.boot.autoconfigure.domain",
"mybatis.mapper-locations:classpath:org/mybatis/spring/boot/autoconfigure/repository/CityMapper.xml")
.applyTo(this.context);
this.context.register(EmbeddedDataSourceConfiguration.class,
MybatisBootMapperScanAutoConfiguration.class);
this.context.refresh();
org.apache.ibatis.session.Configuration configuration = this.context.getBean(
SqlSessionFactory.class).getConfiguration();
assertThat(this.context.getBeanNamesForType(SqlSessionFactory.class)).hasSize(1);
assertThat(this.context.getBeanNamesForType(SqlSessionTemplate.class)).hasSize(1);
assertThat(this.context.getBeanNamesForType(CityMapper.class)).hasSize(1);
assertThat(configuration.getDefaultFetchSize()).isEqualTo(1000);
assertThat(configuration.getMappedStatementNames()).contains("selectCityById");
assertThat(configuration.getMappedStatementNames()).contains("org.mybatis.spring.boot.autoconfigure.repository.CityMapperImpl.selectCityById");
}
示例11: testConfigFileAndConfigurationWithTogether
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void testConfigFileAndConfigurationWithTogether() {
TestPropertyValues.of(
"mybatis.config-location:mybatis-config.xml",
"mybatis.configuration.default-statement-timeout:30")
.applyTo(this.context);
this.context.register(EmbeddedDataSourceConfiguration.class,
MybatisAutoConfiguration.class);
try {
this.context.refresh();
fail("Should be occurred a BeanCreationException.");
} catch (BeanCreationException e) {
assertThat(e.getMessage()).contains("Property 'configuration' and 'configLocation' can not specified with together");
}
}
示例12: testWithConfigurationVariablesAndPropertiesOtherKey
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void testWithConfigurationVariablesAndPropertiesOtherKey() {
TestPropertyValues.of(
"mybatis.configuration.variables.key1:value1",
"mybatis.configuration-properties.key2:value2")
.applyTo(this.context);
this.context.register(EmbeddedDataSourceConfiguration.class,
MybatisAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
Properties variables = this.context.getBean(SqlSessionFactory.class).getConfiguration().getVariables();
assertThat(variables).hasSize(2);
assertThat(variables.getProperty("key1")).isEqualTo("value1");
assertThat(variables.getProperty("key2")).isEqualTo("value2");
}
示例13: shouldDoNothingIfNoServersAreSet
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void shouldDoNothingIfNoServersAreSet() throws Exception {
// given
TestPropertyValues
.of("edison.serviceregistry.enabled=true")
.and("edison.serviceregistry.servers=")
.applyTo(context);
context.register(DefaultAsyncHttpClient.class);
context.register(ApplicationInfoConfiguration.class);
context.register(AsyncHttpRegistryClient.class);
context.refresh();
RegistryClient bean = context.getBean(RegistryClient.class);
assertThat(bean.isRunning(), is(false));
}
示例14: shouldDoNothingIfNoServiceAreSet
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void shouldDoNothingIfNoServiceAreSet() throws Exception {
// given
TestPropertyValues
.of("edison.serviceregistry.enabled=true")
.and("edison.serviceregistry.service=")
.applyTo(context);
context.register(DefaultAsyncHttpClient.class);
context.register(ApplicationInfoConfiguration.class);
context.register(AsyncHttpRegistryClient.class);
context.refresh();
RegistryClient bean = context.getBean(RegistryClient.class);
assertThat(bean.isRunning(), is(false));
}
示例15: shouldDoNothingIfRegistryDisabled
import org.springframework.boot.test.util.TestPropertyValues; //导入依赖的package包/类
@Test
public void shouldDoNothingIfRegistryDisabled() throws Exception {
// given
TestPropertyValues
.of("edison.serviceregistry.enabled=false")
.and("edison.serviceregistry.servers=http://foo")
.and("edison.serviceregistry.service=http://test")
.applyTo(context);
context.register(DefaultAsyncHttpClient.class);
context.register(ApplicationInfoConfiguration.class);
context.register(AsyncHttpRegistryClient.class);
context.refresh();
RegistryClient bean = context.getBean(RegistryClient.class);
assertThat(bean.isRunning(), is(false));
}