use of org.springframework.boot.context.config.ConfigDataLocationResolverContext in project spring-cloud-consul by spring-cloud.
the class ConsulConfigDataLocationResolver method resolveProfileSpecific.
@Override
public List<ConsulConfigDataResource> resolveProfileSpecific(ConfigDataLocationResolverContext resolverContext, ConfigDataLocation location, Profiles profiles) throws ConfigDataLocationNotFoundException {
UriComponents locationUri = parseLocation(resolverContext, location);
// create consul client
registerBean(resolverContext, ConsulProperties.class, loadProperties(resolverContext, locationUri));
registerAndPromoteBean(resolverContext, ConsulClient.class, this::createConsulClient);
// create locations
ConsulConfigProperties properties = loadConfigProperties(resolverContext);
ConsulPropertySources consulPropertySources = new ConsulPropertySources(properties, log);
List<Context> contexts = (locationUri == null || CollectionUtils.isEmpty(locationUri.getPathSegments())) ? consulPropertySources.generateAutomaticContexts(profiles.getAccepted(), false) : getCustomContexts(locationUri, properties);
registerAndPromoteBean(resolverContext, ConsulConfigProperties.class, InstanceSupplier.of(properties));
registerAndPromoteBean(resolverContext, ConsulConfigIndexes.class, InstanceSupplier.from(ConsulConfigDataIndexes::new));
return contexts.stream().map(propertySourceContext -> new ConsulConfigDataResource(propertySourceContext.getPath(), properties, consulPropertySources, propertySourceContext.getProfile())).collect(Collectors.toList());
}
use of org.springframework.boot.context.config.ConfigDataLocationResolverContext in project spring-cloud-consul by spring-cloud.
the class ConsulConfigDataLocationResolverTests method testResolveProfileSpecific.
private List<ConsulConfigDataResource> testResolveProfileSpecific(String location) {
ConsulConfigDataLocationResolver resolver = createResolver();
ConfigDataLocationResolverContext context = mock(ConfigDataLocationResolverContext.class);
when(context.getBootstrapContext()).thenReturn(new DefaultBootstrapContext());
MockEnvironment env = new MockEnvironment();
env.setProperty("spring.application.name", "testapp");
when(context.getBinder()).thenReturn(Binder.get(env));
Profiles profiles = mock(Profiles.class);
when(profiles.getAccepted()).thenReturn(Collections.singletonList("dev"));
return resolver.resolveProfileSpecific(context, ConfigDataLocation.of(location), profiles);
}
use of org.springframework.boot.context.config.ConfigDataLocationResolverContext in project spring-cloud-consul by spring-cloud.
the class ConsulConfigDataLocationResolverTests method testLoadProperties.
@Test
public void testLoadProperties() {
Binder binder = Binder.get(new MockEnvironment());
ConfigDataLocationResolverContext resolverContext = mock(ConfigDataLocationResolverContext.class);
when(resolverContext.getBinder()).thenReturn(binder);
when(resolverContext.getBootstrapContext()).thenReturn(new DefaultBootstrapContext());
ConsulProperties properties = createResolver().loadProperties(resolverContext, UriComponentsBuilder.fromUriString("consul://myhost:8502").build());
assertThat(properties.getHost()).isEqualTo("myhost");
assertThat(properties.getPort()).isEqualTo(8502);
}
Aggregations