use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-boot by spring-projects.
the class ManagementServerPropertiesTests method load.
public ManagementServerProperties load(String... environment) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(ctx, environment);
ctx.register(Config.class);
ctx.refresh();
this.context = ctx;
return this.context.getBean(ManagementServerProperties.class);
}
use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-boot by spring-projects.
the class PublicMetricsAutoConfigurationTests method richGaugePublicMetrics.
@Test
public void richGaugePublicMetrics() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(RichGaugeReaderConfig.class, MetricRepositoryAutoConfiguration.class, PublicMetricsAutoConfiguration.class);
RichGaugeReader richGaugeReader = context.getBean(RichGaugeReader.class);
assertThat(richGaugeReader).isNotNull();
given(richGaugeReader.findAll()).willReturn(Collections.singletonList(new RichGauge("bar", 3.7d)));
RichGaugeReaderPublicMetrics publicMetrics = context.getBean(RichGaugeReaderPublicMetrics.class);
assertThat(publicMetrics).isNotNull();
Collection<Metric<?>> metrics = publicMetrics.metrics();
assertThat(metrics).isNotNull();
assertThat(6).isEqualTo(metrics.size());
assertHasMetric(metrics, new Metric<>("bar.val", 3.7d));
assertHasMetric(metrics, new Metric<>("bar.avg", 3.7d));
assertHasMetric(metrics, new Metric<>("bar.min", 3.7d));
assertHasMetric(metrics, new Metric<>("bar.max", 3.7d));
assertHasMetric(metrics, new Metric<>("bar.alpha", -1.d));
assertHasMetric(metrics, new Metric<>("bar.count", 1L));
context.close();
}
use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-boot by spring-projects.
the class TraceWebFilterAutoConfigurationTests method overrideTraceFilter.
@Test
public void overrideTraceFilter() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(CustomTraceFilterConfig.class, PropertyPlaceholderAutoConfiguration.class, TraceRepositoryAutoConfiguration.class, TraceWebFilterAutoConfiguration.class);
WebRequestTraceFilter filter = context.getBean(WebRequestTraceFilter.class);
assertThat(filter).isInstanceOf(TestWebRequestTraceFilter.class);
context.close();
}
use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-boot by spring-projects.
the class ConfigurationPropertiesReportEndpointParentTests method testInvoke.
@Test
public void testInvoke() throws Exception {
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
parent.register(Parent.class);
parent.refresh();
this.context = new AnnotationConfigApplicationContext();
this.context.setParent(parent);
this.context.register(Config.class);
this.context.refresh();
ConfigurationPropertiesReportEndpoint endpoint = this.context.getBean(ConfigurationPropertiesReportEndpoint.class);
Map<String, Object> result = endpoint.invoke();
assertThat(result).containsKey("parent");
// the endpoint, the test props and the parent
assertThat(result).hasSize(3);
// System.err.println(result);
}
use of org.springframework.context.annotation.AnnotationConfigApplicationContext in project spring-boot by spring-projects.
the class ConfigurationPropertiesReportEndpointParentTests method testInvokeWithFactory.
@Test
public void testInvokeWithFactory() throws Exception {
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
parent.register(Parent.class);
parent.refresh();
this.context = new AnnotationConfigApplicationContext();
this.context.setParent(parent);
this.context.register(Factory.class);
this.context.refresh();
ConfigurationPropertiesReportEndpoint endpoint = this.context.getBean(ConfigurationPropertiesReportEndpoint.class);
Map<String, Object> result = endpoint.invoke();
assertThat(result.containsKey("parent")).isTrue();
// the endpoint, the test props and the parent
assertThat(result).hasSize(3);
// System.err.println(result);
}
Aggregations