Home / Class/ ConfigDataActivationContextTests Class — spring-boot Architecture

ConfigDataActivationContextTests Class — spring-boot Architecture

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

Entity Profile

Relationship Graph

Source Code

core/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataActivationContextTests.java lines 42–99

class ConfigDataActivationContextTests {

	@Test
	void getCloudPlatformWhenCloudPropertyNotPresentDeducesCloudPlatform() {
		Environment environment = new MockEnvironment();
		Binder binder = Binder.get(environment);
		ConfigDataActivationContext context = new ConfigDataActivationContext(environment, binder);
		assertThat(context.getCloudPlatform()).isNull();
	}

	@Test
	void getCloudPlatformWhenCloudPropertyInEnvironmentDeducesCloudPlatform() {
		MockEnvironment environment = createKubernetesEnvironment();
		Binder binder = Binder.get(environment);
		ConfigDataActivationContext context = new ConfigDataActivationContext(environment, binder);
		assertThat(context.getCloudPlatform()).isEqualTo(CloudPlatform.KUBERNETES);
	}

	@Test
	void getCloudPlatformWhenCloudPropertyHasBeenContributedDuringInitialLoadDeducesCloudPlatform() {
		Environment environment = createKubernetesEnvironment();
		Binder binder = new Binder(
				new MapConfigurationPropertySource(Collections.singletonMap("spring.main.cloud-platform", "HEROKU")));
		ConfigDataActivationContext context = new ConfigDataActivationContext(environment, binder);
		assertThat(context.getCloudPlatform()).isEqualTo(CloudPlatform.HEROKU);
	}

	@Test
	void getProfilesWhenWithoutProfilesReturnsNull() {
		Environment environment = new MockEnvironment();
		Binder binder = Binder.get(environment);
		ConfigDataActivationContext context = new ConfigDataActivationContext(environment, binder);
		assertThat(context.getProfiles()).isNull();
	}

	@Test
	void getProfilesWhenWithProfilesReturnsProfiles() {
		MockEnvironment environment = new MockEnvironment();
		environment.setActiveProfiles("a", "b", "c");
		Binder binder = Binder.get(environment);
		ConfigDataActivationContext context = new ConfigDataActivationContext(environment, binder);
		Profiles profiles = new Profiles(environment, binder, null);
		context = context.withProfiles(profiles);
		assertThat(context.getProfiles()).isEqualTo(profiles);
	}

	private MockEnvironment createKubernetesEnvironment() {
		MockEnvironment environment = new MockEnvironment();
		Map<String, Object> map = new LinkedHashMap<>();
		map.put("KUBERNETES_SERVICE_HOST", "host");
		map.put("KUBERNETES_SERVICE_PORT", "port");
		PropertySource<?> propertySource = new MapPropertySource(
				StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, map);
		environment.getPropertySources().addLast(propertySource);
		return environment;
	}

}

Domain

Analyze Your Own Codebase

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

Try Supermodel Free