/** * Builder method to add more properties. * @param pairs the property pairs to add * @return a new {@link TestPropertyValues} instance */ public TestPropertyValues and(String... pairs) { return and(Arrays.stream(pairs).map(Pair::parse)); }
/** * Add the specified {@link System} property pairs. Key-value pairs can be specified * with colon (":") or equals ("=") separators. System properties are added before the * context is {@link #run(ContextConsumer) run} and restored when the context is * closed. * @param pairs the key-value pairs for properties that need to be added to the system * @return a new instance with the updated system properties * @see TestPropertyValues * @see #withSystemProperties(String...) */ public SELF withSystemProperties(String... pairs) { return newInstance(this.contextFactory, this.initializers, this.environmentProperties, this.systemProperties.and(pairs), this.classLoader, this.parent, this.configurations); }
/** * Add the specified {@link Environment} property pairs. Key-value pairs can be * specified with colon (":") or equals ("=") separators. Override matching keys that * might have been specified previously. * @param pairs the key-value pairs for properties that need to be added to the * environment * @return a new instance with the updated property values * @see TestPropertyValues * @see #withSystemProperties(String...) */ public SELF withPropertyValues(String... pairs) { return newInstance(this.contextFactory, this.initializers, this.environmentProperties.and(pairs), this.systemProperties, this.classLoader, this.parent, this.configurations); }
/** * Return a new {@link TestPropertyValues} with the underlying map populated with the * given property pairs. Name-value pairs can be specified with colon (":") or equals * ("=") separators. * @param pairs the name-value pairs for properties that need to be added to the * environment * @return the new instance */ public static TestPropertyValues of(Stream<String> pairs) { if (pairs == null) { return empty(); } return empty().and(pairs.map(Pair::parse)); }
@Test public void shouldUseSSLEncryptionIfConfigured() { this.context.register(EnableAutoConfig.class); TestPropertyValues .of("edison.application.management.base-path=/internal") .and("edison.ldap.enabled=true") .and("edison.ldap.encryptionType=SSL") .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.getBean("ldapConnectionFactory").getClass().getSimpleName(), is(SSLLdapConnectionFactory.class.getSimpleName())); }
@Test public void shouldUseStartTLSEncryptionIfConfigured() { this.context.register(EnableAutoConfig.class); TestPropertyValues .of("edison.application.management.base-path=/internal") .and("edison.ldap.enabled=true") .and("edison.ldap.encryptionType=StartTLS") .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.getBean("ldapConnectionFactory").getClass().getSimpleName(), is(StartTlsLdapConnectionFactory.class.getSimpleName())); }
@Test public void shouldUseStartTLSEncryptionAsDefault() { 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.getBean("ldapConnectionFactory").getClass().getSimpleName(), is(StartTlsLdapConnectionFactory.class.getSimpleName())); }
@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)); }
@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))); }
@Test public void shouldUseInMemoryStateRepositoryIfMongoDisabled() { this.context.register(MongoTogglzTestConfiguration.class); TestPropertyValues .of("edison.togglz.mongo.enabled=false") .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(InMemoryStateRepository.class))); }
@Test public void shouldUseInMemoryStateRepositoryIfMissingS3Client() { this.context.register(TogglzAutoConfiguration.class); TestPropertyValues .of("edison.togglz.s3.enabled=true") .and("edison.togglz.s3.bucket-name=togglz-bucket") .applyTo(context); this.context.refresh(); assertThat(this.context.containsBean("stateRepository"), is(true)); assertThat(this.context.getBean("stateRepository", StateRepository.class), is(instanceOf(InMemoryStateRepository.class))); }
@Test public void shouldUseMongoJobRepositoryIfEnabled() { this.context.register(MongoTestConfiguration.class); this.context.register(JobsAutoConfiguration.class); TestPropertyValues .of("edison.jobs.mongo.enabled=true") .and("edison.mongo.db=db") .applyTo(context); this.context.refresh(); assertThat(this.context.containsBean("jobRepository"), is(true)); assertThat(this.context.getBean("jobRepository"), is(instanceOf(MongoJobRepository.class))); }
@Test public void shouldExposeS3StaterepositoryIfEnabled() { 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") .applyTo(context); this.context.refresh(); assertThat(this.context.containsBean("stateRepository"), is(true)); assertThat(this.context.getBean("stateRepository", StateRepository.class), is(instanceOf(S3TogglzRepository.class))); }
@Test public void shouldUseInMemoryStateRepositoryIfS3Disabled() { this.context.register(S3TestConfiguration.class); this.context.register(TogglzAutoConfiguration.class); TestPropertyValues .of("edison.togglz.s3.enabled=false") .and("edison.togglz.s3.bucket-name=togglz-bucket") .applyTo(context); this.context.refresh(); assertThat(this.context.containsBean("stateRepository"), is(true)); assertThat(this.context.getBean("stateRepository", StateRepository.class), is(instanceOf(InMemoryStateRepository.class))); }
@Test public void shouldNotRegisterLdapFilterIfDisabled() { this.context.register(EnableAutoConfig.class); TestPropertyValues .of("edison.application.management.base-path=/internal") .and("edison.ldap.enabled=false") .applyTo(context); this.context.refresh(); assertThat(this.context.containsBean("ldapAuthenticationFilter"), is(false)); }
@Test void shouldLoadPropertiesFromParamStore() { this.context.register(ParamStoreTestConfiguration.class); TestPropertyValues .of("edison.env.paramstore.enabled=true") .and("edison.env.paramstore.path=mongo") .applyTo(context); this.context.refresh(); assertThat(this.context.containsBean("paramStorePropertySourcePostProcessor"), is(true)); assertThat(this.context.getEnvironment().getPropertySources().contains("paramStorePropertySource"), is(true)); assertEquals("secret", this.context.getEnvironment().getProperty("password")); }
@Test public void shouldDoNothingIfNoServiceAreSet() { // 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)); }
@Test public void shouldDoNothingIfNoServersAreSet() { // 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)); }
@Test public void shouldHaveRegistryIfServersAndServicePresent() { // given TestPropertyValues .of("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(); assertThat(context.containsBean("asyncHttpRegistryClient"), is(true)); }
@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(); }); }