Search in sources :

Example 31 with AnnotationConfigApplicationContext

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);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext)

Example 32 with AnnotationConfigApplicationContext

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();
}
Also used : RichGaugeReaderPublicMetrics(org.springframework.boot.actuate.endpoint.RichGaugeReaderPublicMetrics) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RichGauge(org.springframework.boot.actuate.metrics.rich.RichGauge) RichGaugeReader(org.springframework.boot.actuate.metrics.rich.RichGaugeReader) Metric(org.springframework.boot.actuate.metrics.Metric) Test(org.junit.Test)

Example 33 with AnnotationConfigApplicationContext

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();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) WebRequestTraceFilter(org.springframework.boot.actuate.trace.WebRequestTraceFilter) Test(org.junit.Test)

Example 34 with AnnotationConfigApplicationContext

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);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.Test)

Example 35 with AnnotationConfigApplicationContext

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);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Test(org.junit.Test)

Aggregations

AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)800 Test (org.junit.Test)528 DSLContext (org.jooq.DSLContext)53 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)42 ApplicationContext (org.springframework.context.ApplicationContext)25 Before (org.junit.Before)23 DIConfiguration (com.khartec.waltz.service.DIConfiguration)15 Filter (javax.servlet.Filter)15 Map (java.util.Map)14 OncePerRequestFilter (org.springframework.web.filter.OncePerRequestFilter)14 TestBean (org.springframework.tests.sample.beans.TestBean)13 PropertyPlaceholderAutoConfiguration (org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration)12 MockMvc (org.springframework.test.web.servlet.MockMvc)12 EntityKind (com.khartec.waltz.model.EntityKind)11 List (java.util.List)10 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)10 MockEnvironment (org.springframework.mock.env.MockEnvironment)10 EntityReference (com.khartec.waltz.model.EntityReference)9 MapPropertySource (org.springframework.core.env.MapPropertySource)9 IOException (java.io.IOException)8