Home / Class/ SystemEnvironmentPropertySourceEnvironmentPostProcessorTests Class — spring-boot Architecture

SystemEnvironmentPropertySourceEnvironmentPostProcessorTests Class — spring-boot Architecture

Architecture documentation for the SystemEnvironmentPropertySourceEnvironmentPostProcessorTests class in SystemEnvironmentPropertySourceEnvironmentPostProcessorTests.java from the spring-boot codebase.

Entity Profile

Relationship Graph

Source Code

core/spring-boot/src/test/java/org/springframework/boot/support/SystemEnvironmentPropertySourceEnvironmentPostProcessorTests.java lines 39–129

class SystemEnvironmentPropertySourceEnvironmentPostProcessorTests {

	private final ConfigurableEnvironment environment = new StandardEnvironment();

	private final SpringApplication application = new SpringApplication();

	@Test
	void postProcessShouldReplaceSystemEnvironmentPropertySource() {
		SystemEnvironmentPropertySourceEnvironmentPostProcessor postProcessor = new SystemEnvironmentPropertySourceEnvironmentPostProcessor();
		postProcessor.postProcessEnvironment(this.environment, this.application);
		PropertySource<?> replaced = this.environment.getPropertySources().get("systemEnvironment");
		assertThat(replaced).isInstanceOf(OriginAwareSystemEnvironmentPropertySource.class);
	}

	@Test
	@SuppressWarnings("unchecked")
	void replacedPropertySourceShouldBeOriginAware() {
		SystemEnvironmentPropertySourceEnvironmentPostProcessor postProcessor = new SystemEnvironmentPropertySourceEnvironmentPostProcessor();
		PropertySource<?> original = this.environment.getPropertySources().get("systemEnvironment");
		assertThat(original).isNotNull();
		postProcessor.postProcessEnvironment(this.environment, this.application);
		OriginAwareSystemEnvironmentPropertySource replaced = (OriginAwareSystemEnvironmentPropertySource) this.environment
			.getPropertySources()
			.get("systemEnvironment");
		assertThat(replaced).isNotNull();
		Map<String, Object> originalMap = (Map<String, Object>) original.getSource();
		Map<String, Object> replacedMap = replaced.getSource();
		originalMap.forEach((key, value) -> {
			Object actual = replacedMap.get(key);
			assertThat(actual).isEqualTo(value);
			assertThat(replaced.getOrigin(key)).isInstanceOf(SystemEnvironmentOrigin.class);
		});
	}

	@Test
	void replacedPropertySourceWhenPropertyAbsentShouldReturnNullOrigin() {
		SystemEnvironmentPropertySourceEnvironmentPostProcessor postProcessor = new SystemEnvironmentPropertySourceEnvironmentPostProcessor();
		postProcessor.postProcessEnvironment(this.environment, this.application);
		OriginAwareSystemEnvironmentPropertySource replaced = (OriginAwareSystemEnvironmentPropertySource) this.environment
			.getPropertySources()
			.get("systemEnvironment");
		assertThat(replaced).isNotNull();
		assertThat(replaced.getOrigin("NON_EXISTENT")).isNull();
	}

	@Test
	void replacedPropertySourceShouldResolveProperty() {
		SystemEnvironmentPropertySourceEnvironmentPostProcessor postProcessor = new SystemEnvironmentPropertySourceEnvironmentPostProcessor();
		Map<String, Object> source = Collections.singletonMap("FOO_BAR_BAZ", "hello");
		this.environment.getPropertySources()
			.replace("systemEnvironment", new SystemEnvironmentPropertySource("systemEnvironment", source));
		postProcessor.postProcessEnvironment(this.environment, this.application);
		OriginAwareSystemEnvironmentPropertySource replaced = (OriginAwareSystemEnvironmentPropertySource) this.environment
			.getPropertySources()
			.get("systemEnvironment");
		assertThat(replaced).isNotNull();
		SystemEnvironmentOrigin origin = (SystemEnvironmentOrigin) replaced.getOrigin("foo.bar.baz");
		assertThat(origin).isNotNull();
		assertThat(origin.getProperty()).isEqualTo("FOO_BAR_BAZ");
		assertThat(replaced.getProperty("foo.bar.baz")).isEqualTo("hello");
	}

	@Test
	void propertySourceShouldBePrefixed() {
		SystemEnvironmentPropertySourceEnvironmentPostProcessor postProcessor = new SystemEnvironmentPropertySourceEnvironmentPostProcessor();
		SpringApplication application = new SpringApplication();
		application.setEnvironmentPrefix("my");
		postProcessor.postProcessEnvironment(this.environment, application);
		OriginAwareSystemEnvironmentPropertySource replaced = (OriginAwareSystemEnvironmentPropertySource) this.environment
			.getPropertySources()
			.get("systemEnvironment");
		assertThat(replaced).isNotNull();
		assertThat(replaced.getPrefix()).isEqualTo("my");
	}

	@Test
	void postProcessWithParentEnvironmentShouldApplyPrefix() {
		SpringApplication application = new SpringApplication();
		application.setEnvironmentPrefix("my");
		new SystemEnvironmentPropertySourceEnvironmentPostProcessor().postProcessEnvironment(this.environment,
				application);
		StandardEnvironment child = new StandardEnvironment();
		SystemEnvironmentPropertySourceEnvironmentPostProcessor.postProcessEnvironment(child, this.environment);
		OriginAwareSystemEnvironmentPropertySource replaced = (OriginAwareSystemEnvironmentPropertySource) child
			.getPropertySources()
			.get("systemEnvironment");
		assertThat(replaced).isNotNull();
		assertThat(replaced.getPrefix()).isEqualTo("my");
	}

}

Domain

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free