use of org.springframework.context.support.GenericApplicationContext in project camel by apache.
the class CamelSpringTestContextLoader method loadContext.
/**
* Modeled after the Spring implementation in {@link AbstractGenericContextLoader},
* this method creates and refreshes the application context while providing for
* processing of additional Camel specific post-refresh actions. We do not provide the
* pre-post hooks for customization seen in {@link AbstractGenericContextLoader} because
* they probably are unnecessary for 90+% of users.
* <p/>
* For some functionality, we cannot use {@link org.springframework.test.context.TestExecutionListener} because we need
* to both produce the desired outcome during application context loading, and also cleanup
* after ourselves even if the test class never executes. Thus the listeners, which
* only run if the application context is successfully initialized are insufficient to
* provide the behavior described above.
*/
@Override
public ApplicationContext loadContext(String... locations) throws Exception {
Class<?> testClass = getTestClass();
if (LOG.isDebugEnabled()) {
LOG.debug("Loading ApplicationContext for locations [" + StringUtils.arrayToCommaDelimitedString(locations) + "].");
}
try {
GenericApplicationContext context = createContext(testClass, null);
loadBeanDefinitions(context, locations);
return loadContext(context, testClass);
} finally {
cleanup(testClass);
}
}
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