Home / Class/ ConfigDataImporterTests Class — spring-boot Architecture

ConfigDataImporterTests Class — spring-boot Architecture

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

Entity Profile

Relationship Graph

Source Code

core/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataImporterTests.java lines 44–154

@ExtendWith(MockitoExtension.class)
class ConfigDataImporterTests {

	private final DeferredLogFactory logFactory = Supplier::get;

	@Mock
	@SuppressWarnings("NullAway.Init")
	private ConfigDataLocationResolvers resolvers;

	@Mock
	@SuppressWarnings("NullAway.Init")
	private ConfigDataLoaders loaders;

	@Mock
	@SuppressWarnings("NullAway.Init")
	private Binder binder;

	@Mock
	@SuppressWarnings("NullAway.Init")
	private ConfigDataLocationResolverContext locationResolverContext;

	@Mock
	@SuppressWarnings("NullAway.Init")
	private ConfigDataLoaderContext loaderContext;

	@Mock
	@SuppressWarnings("NullAway.Init")
	private ConfigDataActivationContext activationContext;

	@Mock
	@SuppressWarnings("NullAway.Init")
	private Profiles profiles;

	@BeforeEach
	void setup() {
		given(this.activationContext.getProfiles()).willReturn(this.profiles);
	}

	@Test
	void loadImportsResolvesAndLoadsLocations() throws Exception {
		ConfigDataLocation location1 = ConfigDataLocation.of("test1");
		ConfigDataLocation location2 = ConfigDataLocation.of("test2");
		TestResource resource1 = new TestResource("r1");
		TestResource resource2 = new TestResource("r2");
		ConfigData configData1 = new ConfigData(Collections.singleton(new MockPropertySource()));
		ConfigData configData2 = new ConfigData(Collections.singleton(new MockPropertySource()));
		given(this.resolvers.resolve(this.locationResolverContext, location1, this.profiles))
			.willReturn(Collections.singletonList(new ConfigDataResolutionResult(location1, resource1, false)));
		given(this.resolvers.resolve(this.locationResolverContext, location2, this.profiles))
			.willReturn(Collections.singletonList(new ConfigDataResolutionResult(location2, resource2, false)));
		given(this.loaders.load(this.loaderContext, resource1)).willReturn(configData1);
		given(this.loaders.load(this.loaderContext, resource2)).willReturn(configData2);
		ConfigDataImporter importer = new ConfigDataImporter(this.logFactory, ConfigDataNotFoundAction.FAIL,
				this.resolvers, this.loaders);
		Collection<ConfigData> loaded = importer
			.resolveAndLoad(this.activationContext, this.locationResolverContext, this.loaderContext,
					Arrays.asList(location1, location2))
			.values();
		assertThat(loaded).containsExactly(configData2, configData1);
	}

	@Test
	void loadImportsWhenAlreadyImportedLocationSkipsLoad() throws Exception {
		ConfigDataLocation location1 = ConfigDataLocation.of("test1");
		ConfigDataLocation location2 = ConfigDataLocation.of("test2");
		ConfigDataLocation location3 = ConfigDataLocation.of("test3");
		List<ConfigDataLocation> locations1and2 = Arrays.asList(location1, location2);
		List<ConfigDataLocation> locations2and3 = Arrays.asList(location2, location3);
		TestResource resource1 = new TestResource("r1");
		TestResource resource2 = new TestResource("r2");
		TestResource resource3 = new TestResource("r3");
		ConfigData configData1 = new ConfigData(Collections.singleton(new MockPropertySource()));
		ConfigData configData2 = new ConfigData(Collections.singleton(new MockPropertySource()));
		ConfigData configData3 = new ConfigData(Collections.singleton(new MockPropertySource()));
		given(this.resolvers.resolve(this.locationResolverContext, location1, this.profiles))
			.willReturn(Collections.singletonList(new ConfigDataResolutionResult(location1, resource1, false)));
		given(this.resolvers.resolve(this.locationResolverContext, location2, this.profiles))
			.willReturn(Collections.singletonList(new ConfigDataResolutionResult(location2, resource2, false)));
		given(this.resolvers.resolve(this.locationResolverContext, location3, this.profiles))
			.willReturn(Collections.singletonList(new ConfigDataResolutionResult(location3, resource3, false)));
		given(this.loaders.load(this.loaderContext, resource1)).willReturn(configData1);
		given(this.loaders.load(this.loaderContext, resource2)).willReturn(configData2);
		given(this.loaders.load(this.loaderContext, resource3)).willReturn(configData3);
		ConfigDataImporter importer = new ConfigDataImporter(this.logFactory, ConfigDataNotFoundAction.FAIL,
				this.resolvers, this.loaders);
		Collection<ConfigData> loaded1and2 = importer
			.resolveAndLoad(this.activationContext, this.locationResolverContext, this.loaderContext, locations1and2)
			.values();
		Collection<ConfigData> loaded2and3 = importer
			.resolveAndLoad(this.activationContext, this.locationResolverContext, this.loaderContext, locations2and3)
			.values();
		assertThat(loaded1and2).containsExactly(configData2, configData1);
		assertThat(loaded2and3).containsExactly(configData3);
	}

	static class TestResource extends ConfigDataResource {

		private final String name;

		TestResource(String name) {
			this.name = name;
		}

		@Override
		public String toString() {
			return this.name;
		}

	}

}

Domain

Analyze Your Own Codebase

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

Try Supermodel Free