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();
}
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());
}
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());
}
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));
}
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);
}
Aggregations