Home / Class/ TestConfigDataBootstrap Class — spring-boot Architecture

TestConfigDataBootstrap Class — spring-boot Architecture

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

Entity Profile

Relationship Graph

Source Code

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

class TestConfigDataBootstrap {

	static class LocationResolver implements ConfigDataLocationResolver<Resource> {

		@Override
		public boolean isResolvable(ConfigDataLocationResolverContext context, ConfigDataLocation location) {
			context.getBootstrapContext().get(Binder.class); // gh-24559
			return location.hasPrefix("testbootstrap:");
		}

		@Override
		public List<Resource> resolve(ConfigDataLocationResolverContext context, ConfigDataLocation location) {
			context.getBootstrapContext()
				.registerIfAbsent(ResolverHelper.class, InstanceSupplier.from(() -> new ResolverHelper(location)));
			ResolverHelper helper = context.getBootstrapContext().get(ResolverHelper.class);
			assertThat(helper).isNotNull();
			return Collections.singletonList(new Resource(helper));
		}

	}

	static class Loader implements ConfigDataLoader<Resource> {

		@Override
		public ConfigData load(ConfigDataLoaderContext context, Resource location) throws IOException {
			context.getBootstrapContext()
				.registerIfAbsent(LoaderHelper.class,
						(bootstrapContext) -> new LoaderHelper(location, () -> bootstrapContext.get(Binder.class)));
			LoaderHelper helper = context.getBootstrapContext().get(LoaderHelper.class);
			assertThat(helper).isNotNull();
			context.getBootstrapContext().addCloseListener(helper);
			return new ConfigData(
					Collections.singleton(new MapPropertySource("loaded", Collections.singletonMap("test", "test"))));
		}

	}

	static class Resource extends ConfigDataResource {

		private final ResolverHelper resolverHelper;

		Resource(ResolverHelper resolverHelper) {
			this.resolverHelper = resolverHelper;
		}

		@Override
		public String toString() {
			return "test";
		}

		ResolverHelper getResolverHelper() {
			return this.resolverHelper;
		}

	}

	static class ResolverHelper {

		private final ConfigDataLocation location;

		ResolverHelper(ConfigDataLocation location) {
			this.location = location;
		}

		ConfigDataLocation getLocation() {
			return this.location;
		}

	}

	static class LoaderHelper implements ApplicationListener<BootstrapContextClosedEvent> {

		private final Resource location;

		private final Supplier<Binder> binder;

		LoaderHelper(Resource location, Supplier<Binder> binder) {
			this.location = location;
			this.binder = binder;
		}

		Resource getLocation() {
			return this.location;
		}

		@Nullable String getBound() {
			return this.binder.get().bind("myprop", String.class).orElse(null);
		}

		@Nullable String getProfileBound() {
			return this.binder.get().bind("myprofileprop", String.class).orElse(null);
		}

		@Override
		public void onApplicationEvent(BootstrapContextClosedEvent event) {
			event.getApplicationContext().getBeanFactory().registerSingleton("loaderHelper", this);
		}

	}

}

Domain

Analyze Your Own Codebase

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

Try Supermodel Free