org.springframework.boot.test.util.TestPropertyValues Java Examples
The following examples show how to use
org.springframework.boot.test.util.TestPropertyValues.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OAuth2AutoConfigurationTests.java From spring-security-oauth2-boot with Apache License 2.0 | 6 votes |
@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(1); assertThat(countBeans(CustomAuthorizationServer.class)).isEqualTo(1); assertThat(countBeans(RESOURCE_SERVER_CONFIG)).isEqualTo(1); verifyAuthentication(config); }
Example #2
Source File: ZipkinKinesisCollectorModuleTest.java From zipkin-aws with Apache License 2.0 | 6 votes |
@Test public void kinesisCollectorConfiguredForAWSWithGivenCredentials() { TestPropertyValues.of( "zipkin.collector.kinesis.stream-name: zipkin-test", "zipkin.collector.kinesis.app-name: zipkin", "zipkin.collector.kinesis.aws-sts-region: us-east-1", "zipkin.collector.kinesis.aws-access-key-id: x", "zipkin.collector.kinesis.aws-secret-access-key: x", "zipkin.collector.kinesis.aws-sts-role-arn: test") .applyTo(context); context.register( PropertyPlaceholderAutoConfiguration.class, ZipkinKinesisCollectorModule.class, ZipkinKinesisCredentialsConfiguration.class, InMemoryConfiguration.class); context.refresh(); assertThat(context.getBean(KinesisCollector.class)).isNotNull(); assertThat(context.getBean(AWSSecurityTokenService.class)).isNotNull(); assertThat(context.getBean(AWSCredentialsProvider.class)) .isInstanceOf(STSAssumeRoleSessionCredentialsProvider.class); }
Example #3
Source File: ZipkinKinesisCollectorModuleTest.java From zipkin-aws with Apache License 2.0 | 6 votes |
@Test public void kinesisCollectorCreatedWhenAllRequiredValuesAreProvided() { TestPropertyValues.of( "zipkin.collector.kinesis.stream-name: zipkin-test", // The yaml file has a default for this "zipkin.collector.kinesis.app-name: zipkin") .applyTo(context); context.register( PropertyPlaceholderAutoConfiguration.class, ZipkinKinesisCollectorModule.class, ZipkinKinesisCredentialsConfiguration.class, InMemoryConfiguration.class); context.refresh(); assertThat(context.getBean(KinesisCollector.class)).isNotNull(); assertThat(context.getBean(ZipkinKinesisCollectorProperties.class)).isNotNull(); }
Example #4
Source File: MoreRefreshScopeIntegrationTests.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
@Test @DirtiesContext public void testRefresh() throws Exception { then(this.service.getMessage()).isEqualTo("Hello scope!"); String id1 = this.service.toString(); // Change the dynamic property source... TestPropertyValues.of("message:Foo").applyTo(this.environment, Type.MAP, "morerefreshtests"); // ...and then refresh, so the bean is re-initialized: this.scope.refreshAll(); String id2 = this.service.toString(); String message = this.service.getMessage(); then(message).isEqualTo("Foo"); then(TestService.getInitCount()).isEqualTo(1); then(TestService.getDestroyCount()).isEqualTo(1); then(id2).isNotSameAs(id1); }
Example #5
Source File: LdapConfigurationTest.java From edison-microservice with Apache License 2.0 | 6 votes |
@Test public void shouldReadNewPrefixesPropertyAndIncludeOldPrefixProperty() { this.context.register(EnableAutoConfig.class); TestPropertyValues .of("edison.application.management.base-path=/internal") .and("edison.ldap.enabled=true") .and("edison.ldap.host=localhost") .and("edison.ldap.rdn-identifier=test-rdn") .and("edison.ldap.base-dn=test-dn") .and("edison.ldap.prefix=/deprecatedTestPrefix") .and("edison.ldap.prefixes=/newTestPrefix") .applyTo(context); this.context.refresh(); final FilterRegistrationBean<?> filterRegistrationBean = this.context.getBean("ldapAuthenticationFilter", FilterRegistrationBean.class); final ArrayList<String> urlPatterns = new ArrayList<String>(filterRegistrationBean.getUrlPatterns()); assertThat(urlPatterns, hasSize(2)); assertThat(urlPatterns, containsInAnyOrder("/deprecatedTestPrefix/*", "/newTestPrefix/*")); }
Example #6
Source File: ConfigServicePropertySourceLocatorTests.java From spring-cloud-config with Apache License 2.0 | 6 votes |
@Test public void sunnyDayWithNoSuchLabelAndFailFast() { ConfigClientProperties defaults = new ConfigClientProperties(this.environment); defaults.setFailFast(true); this.locator = new ConfigServicePropertySourceLocator(defaults); mockRequestResponseWithLabel( new ResponseEntity<>((Void) null, HttpStatus.NOT_FOUND), "release(_)v1.0.0"); this.locator.setRestTemplate(this.restTemplate); TestPropertyValues.of("spring.cloud.config.label:release/v1.0.1") .applyTo(this.environment); this.expected.expect(IsInstanceOf.instanceOf(IllegalStateException.class)); this.expected.expectMessage( "Could not locate PropertySource and the fail fast property is set, failing: None of labels [release/v1.0.1] found"); this.locator.locateCollection(this.environment); }
Example #7
Source File: WireMockInitializer.java From blog-tutorials with MIT License | 6 votes |
@Override public void initialize(ConfigurableApplicationContext configurableApplicationContext) { WireMockServer wireMockServer = new WireMockServer(new WireMockConfiguration().dynamicPort()); wireMockServer.start(); configurableApplicationContext.getBeanFactory().registerSingleton("wireMockServer", wireMockServer); configurableApplicationContext.addApplicationListener(applicationEvent -> { if (applicationEvent instanceof ContextClosedEvent) { wireMockServer.stop(); } }); TestPropertyValues .of("todo_url:http://localhost:" + wireMockServer.port() + "/todos") .applyTo(configurableApplicationContext); }
Example #8
Source File: EurekaClientAutoConfigurationTests.java From spring-cloud-netflix with Apache License 2.0 | 6 votes |
@Test public void statusPageUrl_and_healthCheckUrl_contain_management_context_path() throws Exception { TestPropertyValues .of("server.port=8989", "management.server.servlet.context-path=/management") .applyTo(this.context); setupContext(RefreshAutoConfiguration.class); EurekaInstanceConfigBean instance = this.context .getBean(EurekaInstanceConfigBean.class); assertThat(instance.getStatusPageUrl().endsWith(":8989/management/actuator/info")) .as("Wrong status page: " + instance.getStatusPageUrl()).isTrue(); assertThat( instance.getHealthCheckUrl().endsWith(":8989/management/actuator/health")) .as("Wrong health check: " + instance.getHealthCheckUrl()) .isTrue(); }
Example #9
Source File: S3TogglzConfigurationTest.java From edison-microservice with Apache License 2.0 | 6 votes |
@Test public void shouldThrowExceptionOnMissingBucket() { //given when(mock.listObjects(any(ListObjectsRequest.class))).thenThrow(NoSuchBucketException.builder().build()); this.context.register(TogglzAutoConfiguration.class); this.context.register(S3TestConfiguration.class); TestPropertyValues .of("edison.togglz.s3.enabled=true") .and("edison.togglz.s3.bucket-name=togglz-bucket") .and("edison.togglz.s3.check-bucket=true") .applyTo(context); //expect Assertions.assertThrows(BeanCreationException.class, this.context::refresh); }
Example #10
Source File: EnvironmentDecryptApplicationInitializerTests.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
@Test public void testOnlyDecryptIfNotOverridden() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); TextEncryptor encryptor = mock(TextEncryptor.class); when(encryptor.decrypt("bar2")).thenReturn("bar2"); EnvironmentDecryptApplicationInitializer initializer = new EnvironmentDecryptApplicationInitializer( encryptor); TestPropertyValues.of("foo: {cipher}bar", "foo2: {cipher}bar2").applyTo(context); context.getEnvironment().getPropertySources().addFirst(new MapPropertySource( "test_override", Collections.singletonMap("foo", "spam"))); initializer.initialize(context); then(context.getEnvironment().getProperty("foo")).isEqualTo("spam"); then(context.getEnvironment().getProperty("foo2")).isEqualTo("bar2"); verify(encryptor).decrypt("bar2"); verifyNoMoreInteractions(encryptor); }
Example #11
Source File: DataFlowClientAutoConfigurationAgaintstServerTests.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
@Test public void usingUserWithViewRolesWithOauth() { context = new AnnotationConfigApplicationContext(); TestPropertyValues.of( "spring.cloud.dataflow.client.server-uri=" + "http://localhost:" + localDataflowResource.getDataflowPort(), "spring.cloud.dataflow.client.authentication.client-id=myclient", "spring.cloud.dataflow.client.authentication.client-secret=mysecret", "spring.cloud.dataflow.client.authentication.token-uri=" + "http://localhost:" + oAuth2ServerResource.getOauth2ServerPort() + "/oauth/token", "spring.cloud.dataflow.client.authentication.scope=dataflow.view").applyTo(context); context.register(TestApplication2.class); context.refresh(); final DataFlowOperations dataFlowOperations = context.getBean(DataFlowOperations.class); final AboutResource about = dataFlowOperations.aboutOperation().get(); assertNotNull(about); assertEquals("myclient", about.getSecurityInfo().getUsername()); assertEquals(1, about.getSecurityInfo().getRoles().size()); }
Example #12
Source File: LdapConfigurationTest.java From edison-microservice with Apache License 2.0 | 5 votes |
@Test public void shouldValidateProperties() { this.context.register(EnableAutoConfig.class); TestPropertyValues .of("edison.application.management.base-path=/internal") .and("edison.ldap.enabled=true") .applyTo(context); assertThrows(UnsatisfiedDependencyException.class, () -> { this.context.refresh(); }); }
Example #13
Source File: LdapConfigurationTest.java From edison-microservice with Apache License 2.0 | 5 votes |
@Test public void shouldRegisterLdapFilterButNotLdapRoleFilter() { this.context.register(EnableAutoConfig.class); TestPropertyValues .of("edison.application.management.base-path=/internal") .and("edison.ldap.enabled=true") .and("edison.ldap.host=localhost") .and("edison.ldap.base-dn=test-dn") .and("edison.ldap.rdn-identifier=test-rdn") .applyTo(context); this.context.refresh(); assertThat(this.context.containsBean("ldapAuthenticationFilter"), is(true)); assertThat(this.context.containsBean("ldapRoleAuthenticationFilter"), is(false)); }
Example #14
Source File: TogglzConsoleConfigurationTest.java From edison-microservice with Apache License 2.0 | 5 votes |
@Test public void shouldNotRegisterTogglzConsoleServletIfDisabled() { this.context.register(TogglzConsoleConfiguration.class); this.context.register(NavBarConfiguration.class); TestPropertyValues.of("edison.application.management.base-path=/internal", "edison.togglz.console.enabled=false").applyTo(context); this.context.refresh(); assertThat(this.context.containsBean("togglzServlet"), is(false)); }
Example #15
Source File: PostRepositoryTest.java From spring-reactive-sample with GNU General Public License v3.0 | 5 votes |
@Override public void initialize(ConfigurableApplicationContext configurableApplicationContext) { final Neo4jContainer<?> neo4jContainer = new Neo4jContainer<>("neo4j:4.0").withoutAuthentication(); neo4jContainer.start(); configurableApplicationContext .addApplicationListener((ApplicationListener<ContextClosedEvent>) event -> neo4jContainer.stop()); TestPropertyValues.of("org.neo4j.driver.uri=" + neo4jContainer.getBoltUrl()) .applyTo(configurableApplicationContext.getEnvironment()); }
Example #16
Source File: ConditionalOnMissingSpringCacheProviderTest.java From memcached-spring-boot with Apache License 2.0 | 5 votes |
@Test public void whenSpringCacheTypeIsEmptyThenOutcomeShouldNotMatch() { TestPropertyValues.of("spring.cache.type=").applyTo(this.context); this.context.register(OnMissingSpringCacheTypeConfig.class); this.context.refresh(); assertThat(this.context.containsBean("foo")).isFalse(); }
Example #17
Source File: EnvironmentDecryptApplicationInitializerTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Test public void errorOnDecryptWithEmpty() { this.listener = new EnvironmentDecryptApplicationInitializer( Encryptors.text("deadbeef", "AFFE37")); this.listener.setFailOnError(false); ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); TestPropertyValues.of("foo: {cipher}bar").applyTo(context); this.listener.initialize(context); // Assert logs contain warning String sysOutput = this.outputCapture.toString(); then(sysOutput).contains("Cannot decrypt: key=foo"); // Empty is safest fallback for undecryptable cipher then(context.getEnvironment().getProperty("foo")).isEqualTo(""); }
Example #18
Source File: HistoryConfigurationTest.java From synapse with Apache License 2.0 | 5 votes |
@Test public void shouldNotExposeHistoryIfDisabled() { TestPropertyValues.of( "synapse.edison.history.enabled=false") .applyTo(context); context.register(HistoryController.class); context.register(HistoryService.class); context.refresh(); assertThat(context.containsBean("historyController"), is(false)); assertThat(context.containsBean("historyService"), is(false)); }
Example #19
Source File: ResourceServerTokenServicesConfigurationTests.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
@Test public void userInfoWithCustomizer() { TestPropertyValues.of("security.oauth2.resource.userInfoUri:https://example.com", "security.oauth2.resource.tokenInfoUri:https://example.com", "security.oauth2.resource.preferTokenInfo:false").applyTo(this.environment); this.context = new SpringApplicationBuilder(ResourceConfiguration.class, Customizer.class) .environment(this.environment).web(WebApplicationType.NONE).run(); UserInfoTokenServices services = this.context.getBean(UserInfoTokenServices.class); assertThat(services).isNotNull(); }
Example #20
Source File: TwitterSentimentProcessorPropertiesTests.java From tensorflow with Apache License 2.0 | 5 votes |
@Test public void vocabularyCanBeCustomized() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); TestPropertyValues.of("tensorflow.twitter.vocabulary=/remote").applyTo(context); context.register(Conf.class); context.refresh(); TwitterSentimentProcessorProperties properties = context.getBean(TwitterSentimentProcessorProperties.class); assertThat(properties.getVocabulary(), equalTo(context.getResource("/remote"))); context.close(); }
Example #21
Source File: AbstractIntegrationTest.java From event-sourcing-microservices-example with GNU General Public License v3.0 | 5 votes |
@Override public void initialize(@NotNull ConfigurableApplicationContext configurableApplicationContext) { String jdbcUrl = String.format("jdbc:postgresql://%s:%d/%s", postgres.getContainerIpAddress(), postgres.getMappedPort(5432), "postgres"); TestPropertyValues values = TestPropertyValues.of( "postgres.host=" + postgres.getContainerIpAddress(), "postgres.port=" + postgres.getMappedPort(5432), "postgres.url=" + jdbcUrl, "spring.datasource.url=" + jdbcUrl, "spring.cloud.stream.kafka.binder.brokers=" + kafka.getBootstrapServers(), "eureka.client.enabled=false"); values.applyTo(configurableApplicationContext); }
Example #22
Source File: TogglzConfigurationTest.java From edison-microservice with Apache License 2.0 | 5 votes |
@Test public void shouldRegisterTogglzConsoleServlet() { this.context.register(TogglzConfiguration.class); this.context.register(InMemoryFeatureStateRepositoryConfiguration.class); TestPropertyValues.of("edison.application.management.base-path=/internal").applyTo(context); this.context.refresh(); assertThat(this.context.containsBean("togglzFilter"), is(true)); assertThat(this.context.containsBean("featureClassProvider"), is(true)); assertThat(this.context.containsBean("userProvider"), is(true)); assertThat(this.context.containsBean("togglzConfig"), is(true)); assertThat(this.context.containsBean("featureManager"), is(true)); }
Example #23
Source File: MongoTogglzConfigurationTest.java From edison-microservice with Apache License 2.0 | 5 votes |
@Test public void shouldUseMongoStateRepositoryIfEnabled() { this.context.register(MongoTogglzTestConfiguration.class); TestPropertyValues .of("edison.togglz.mongo.enabled=true") .and("edison.mongo.db=db") .and("edison.mongo.user=test") .and("edison.mongo.password=test") .applyTo(context); this.context.refresh(); assertThat(this.context.containsBean("stateRepository"), is(true)); assertThat(this.context.getBean("stateRepository", StateRepository.class), is(instanceOf(MongoTogglzRepository.class))); }
Example #24
Source File: TensorflowProcessorPropertiesTests.java From tensorflow with Apache License 2.0 | 5 votes |
@Test public void outputNameCanBeCustomized() { TestPropertyValues.of("tensorflow.outputName:outputName2").applyTo(context); context.register(Conf.class); context.refresh(); TensorflowCommonProcessorProperties properties = context.getBean(TensorflowCommonProcessorProperties.class); assertThat(properties.getOutputName(), equalTo("outputName2")); }
Example #25
Source File: VcapServiceCredentialsEnvironmentPostProcessorTests.java From spring-cloud-cloudfoundry with Apache License 2.0 | 5 votes |
@Test public void addTokenUri() { TestPropertyValues .of("vcap.services.sso.credentials.accessTokenUri:http://exampledomain") .applyTo(this.environment); this.listener.postProcessEnvironment(this.environment, new SpringApplication()); assertThat(this.environment .resolvePlaceholders("${security.oauth2.client.access-token-uri}")) .isEqualTo("http://exampledomain"); }
Example #26
Source File: MongeezAutoConfigurationTests.java From mongeez-spring-boot-starter with Apache License 2.0 | 5 votes |
@Test(expected = BeanCreationException.class) public void shouldFailIfOnlyMongoCredentialsProvided() { String mongoUsername = "foo"; String mongoPassword = "bar"; TestPropertyValues.of("spring.data.mongodb.username:" + mongoUsername) .and("spring.data.mongodb.password:" + mongoPassword) .applyTo(this.context); registerAndRefresh(DoNotExecuteMongeezPostProcessor.class, MongoAutoConfiguration.class, MongeezAutoConfiguration.class); }
Example #27
Source File: ConditionalOnMissingSpringCacheProviderTest.java From memcached-spring-boot with Apache License 2.0 | 5 votes |
@Test public void whenSpringCacheTypeIsPresentThenOutcomeShouldNotMatch() { TestPropertyValues.of("spring.cache.type=none").applyTo(this.context); this.context.register(OnMissingSpringCacheTypeConfig.class); this.context.refresh(); assertThat(this.context.containsBean("foo")).isFalse(); }
Example #28
Source File: ConfigClientPropertiesTests.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Test public void changeNameInOverride() { this.locator.setName("one"); ConfigurableEnvironment environment = new StandardEnvironment(); TestPropertyValues.of("spring.application.name:two").applyTo(environment); ConfigClientProperties override = this.locator.override(environment); assertThat(override.getName()).isEqualTo("two"); }
Example #29
Source File: ContextInstanceDataAutoConfigurationTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void placeHolder_customAttributeSeparator_createInstanceDataResolverThatResolvesWithCustomAttribute() throws Exception { // Arrange HttpServer httpServer = MetaDataServer.setupHttpServer(); HttpContext instanceIdHttpContext = httpServer.createContext( "/latest/meta-data/instance-id", new MetaDataServer.HttpResponseWriterHandler("testInstanceId")); HttpContext userDataHttpContext = httpServer.createContext("/latest/user-data", new MetaDataServer.HttpResponseWriterHandler("a:b/c:d")); this.context = new AnnotationConfigApplicationContext(); TestPropertyValues.of("cloud.aws.instance.data.attributeSeparator:/") .applyTo(this.context); this.context.register(ContextInstanceDataAutoConfiguration.class); // Act this.context.refresh(); // Assert assertThat(this.context.getEnvironment().getProperty("a")).isEqualTo("b"); assertThat(this.context.getEnvironment().getProperty("c")).isEqualTo("d"); httpServer.removeContext(instanceIdHttpContext); httpServer.removeContext(userDataHttpContext); }
Example #30
Source File: ResourceServerTokenServicesConfigurationTests.java From spring-security-oauth2-boot with Apache License 2.0 | 5 votes |
@Test public void switchToUserInfo() { TestPropertyValues.of("security.oauth2.resource.userInfoUri:https://example.com").applyTo(this.environment); this.context = new SpringApplicationBuilder(ResourceConfiguration.class).environment(this.environment) .web(WebApplicationType.NONE).run(); UserInfoTokenServices services = this.context.getBean(UserInfoTokenServices.class); assertThat(services).isNotNull(); }