Search in sources :

Example 96 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-boot by spring-projects.

the class EndpointMBeanExporterTests method testRegistrationWithDifferentDomainAndIdentity.

@Test
public void testRegistrationWithDifferentDomainAndIdentity() throws Exception {
    Map<String, Object> properties = new HashMap<>();
    properties.put("domain", "test-domain");
    properties.put("ensureUniqueRuntimeObjectNames", true);
    this.context = new GenericApplicationContext();
    this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class, null, new MutablePropertyValues(properties)));
    this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(TestEndpoint.class));
    this.context.refresh();
    MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
    assertThat(mbeanExporter.getServer().getMBeanInfo(getObjectName("test-domain", "endpoint1", true, this.context))).isNotNull();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) MBeanExporter(org.springframework.jmx.export.MBeanExporter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 97 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.

the class EvalTagTests method environmentAccess.

@Test
public void environmentAccess() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("key.foo", "value.foo");
    GenericApplicationContext wac = (GenericApplicationContext) context.getRequest().getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    wac.getEnvironment().getPropertySources().addFirst(new MapPropertySource("mapSource", map));
    wac.getDefaultListableBeanFactory().registerSingleton("bean2", context.getRequest().getAttribute("bean"));
    tag.setExpression("@environment['key.foo']");
    int action = tag.doStartTag();
    assertEquals(Tag.EVAL_BODY_INCLUDE, action);
    action = tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, action);
    assertEquals("value.foo", ((MockHttpServletResponse) context.getResponse()).getContentAsString());
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.Test)

Example 98 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.

the class EnvironmentSystemIntegrationTests method genericApplicationContext_standardEnv.

@Test
public void genericApplicationContext_standardEnv() {
    ConfigurableApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
    ctx.refresh();
    assertHasStandardEnvironment(ctx);
    assertEnvironmentBeanRegistered(ctx);
    assertEnvironmentAwareInvoked(ctx, ctx.getEnvironment());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) Test(org.junit.Test)

Example 99 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.

the class EnvironmentSystemIntegrationTests method classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedComponents.

@Test
public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCapableBDR_scanProfileAnnotatedComponents() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    ctx.setEnvironment(prodEnv);
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
    scanner.scan("org.springframework.core.env.scan2");
    ctx.refresh();
    assertThat(scanner.getEnvironment(), is((Environment) ctx.getEnvironment()));
    assertThat(ctx.containsBean(DEV_BEAN_NAME), is(false));
    assertThat(ctx.containsBean(PROD_BEAN_NAME), is(true));
}
Also used : ClassPathBeanDefinitionScanner(org.springframework.context.annotation.ClassPathBeanDefinitionScanner) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) StandardServletEnvironment(org.springframework.web.context.support.StandardServletEnvironment) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 100 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project camel by apache.

the class Configuration method shouldOnlyCollectRoutesOnce.

@Test
public void shouldOnlyCollectRoutesOnce() {
    GenericApplicationContext parent = new GenericApplicationContext();
    parent.refresh();
    ConfigurableApplicationContext context = new SpringApplicationBuilder(Configuration.class).web(false).parent(parent).run();
    ContextRefreshedEvent refreshEvent = new ContextRefreshedEvent(context);
    RoutesCollector collector = context.getBean(RoutesCollector.class);
    //no changes should happen here
    collector.onApplicationEvent(refreshEvent);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) RoutesCollector(org.apache.camel.spring.boot.RoutesCollector) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.Test)

Aggregations

GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)231 Test (org.junit.Test)182 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)79 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)50 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)36 BeanCreationException (org.springframework.beans.factory.BeanCreationException)26 TestBean (org.springframework.tests.sample.beans.TestBean)17 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)15 DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)12 ClassPathResource (org.springframework.core.io.ClassPathResource)11 MBeanExporter (org.springframework.jmx.export.MBeanExporter)11 BeansException (org.springframework.beans.BeansException)8 HashMap (java.util.HashMap)7 UnsatisfiedDependencyException (org.springframework.beans.factory.UnsatisfiedDependencyException)7 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 EntityManager (javax.persistence.EntityManager)5 Before (org.junit.Before)5 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)5 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5