List of usage examples for org.springframework.context.support GenericApplicationContext GenericApplicationContext
public GenericApplicationContext(@Nullable ApplicationContext parent)
From source file:org.marketcetera.util.spring.SpringUtilsTest.java
@Test public void propertiesConfigurerList() { GenericApplicationContext context = new GenericApplicationContext( new FileSystemXmlApplicationContext(TEST_SPRING_FILE)); SpringUtils.addPropertiesConfigurer(context, TEST_CONFIGURER_BEAN, TEST_PROPERTIES_FILES_BEAN); SpringUtils.addStringBean(context, TEST_NAME_BEAN, "${" + TEST_NAME_PROP + "}"); context.refresh();//from w w w. ja va 2s . co m assertEquals(TEST_VALUE_PROP_OVERRIDE, context.getBean(TEST_NAME_BEAN)); }
From source file:org.openmrs.test.StartModuleExecutionListener.java
/** * called before @BeforeTransaction methods * /*from w ww.ja v a 2 s .c om*/ * @see org.springframework.test.context.support.AbstractTestExecutionListener#prepareTestInstance(org.springframework.test.context.TestContext) */ @Override public void prepareTestInstance(TestContext testContext) throws Exception { StartModule startModuleAnnotation = testContext.getTestClass().getAnnotation(StartModule.class); // if the developer listed some modules with the @StartModule annotation on the class if (startModuleAnnotation != null) { if (!lastClassRun.equals(testContext.getTestClass().getSimpleName())) { // mark this with our class so that the services are only restarted once lastClassRun = testContext.getTestClass().getSimpleName(); if (!Context.isSessionOpen()) Context.openSession(); ModuleUtil.shutdown(); // load the omods that the dev defined for this class String modulesToLoad = StringUtils.join(startModuleAnnotation.value(), " "); Properties props = BaseContextSensitiveTest.runtimeProperties; props.setProperty(ModuleConstants.RUNTIMEPROPERTY_MODULE_LIST_TO_LOAD, modulesToLoad); try { ModuleUtil.startup(props); } catch (Exception e) { System.out.println("Error while starting modules: "); e.printStackTrace(System.out); throw e; } Assert.assertTrue( "Some of the modules did not start successfully for " + testContext.getTestClass().getSimpleName() + ". Only " + ModuleFactory.getStartedModules().size() + " modules started instead of " + startModuleAnnotation.value().length, startModuleAnnotation.value().length <= ModuleFactory.getStartedModules().size()); /* * Refresh spring so the Services are recreated (aka serializer gets put into the SerializationService) * To do this, wrap the applicationContext from the testContext into a GenericApplicationContext, allowing * loading beans from moduleApplicationContext into it and then calling ctx.refresh() * This approach ensures that the application context remains consistent */ GenericApplicationContext ctx = new GenericApplicationContext(testContext.getApplicationContext()); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx); Enumeration<URL> list = OpenmrsClassLoader.getInstance() .getResources("moduleApplicationContext.xml"); while (list.hasMoreElements()) { xmlReader.loadBeanDefinitions(new UrlResource(list.nextElement())); } //ensure that when refreshing, we use the openmrs class loader for the started modules. boolean useSystemClassLoader = Context.isUseSystemClassLoader(); Context.setUseSystemClassLoader(false); try { ctx.refresh(); } finally { Context.setUseSystemClassLoader(useSystemClassLoader); } // session is closed by the test framework //Context.closeSession(); } } }
From source file:org.sakaiproject.test.SakaiDependencyInjectionTests.java
@Override protected ConfigurableApplicationContext createApplicationContext(String[] locations) { if (log.isDebugEnabled()) log.debug("createApplicationContext locations=" + Arrays.asList(locations)); ComponentContainerEmulator.startComponentManagerForTest(); ConfigurableApplicationContext componentContext = (ConfigurableApplicationContext) ComponentContainerEmulator .getContainerApplicationContext(); // WARNING: Copied from the superclass! The only change is to add a // parent application context to the application context constructor. GenericApplicationContext context = new GenericApplicationContext(componentContext); customizeBeanFactory(context.getDefaultListableBeanFactory()); new XmlBeanDefinitionReader(context).loadBeanDefinitions(locations); context.refresh();/* w ww .ja va 2 s. co m*/ return context; }
From source file:org.springframework.aop.aspectj.autoproxy.AspectJAutoProxyCreatorTests.java
@Test public void testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory() { ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml"); GenericApplicationContext childAc = new GenericApplicationContext(ac); // Create a child factory with a bean that should be woven RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.getPropertyValues().addPropertyValue(new PropertyValue("name", "Adrian")) .addPropertyValue(new PropertyValue("age", new Integer(34))); childAc.registerBeanDefinition("adrian2", bd); // Register the advisor auto proxy creator with subclass childAc.registerBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class.getName(), new RootBeanDefinition(AnnotationAwareAspectJAutoProxyCreator.class)); childAc.refresh();//from www. j av a 2 s. c om ITestBean beanFromChildContextThatShouldBeWeaved = (ITestBean) childAc.getBean("adrian2"); //testAspectsAndAdvisorAreApplied(childAc, (ITestBean) ac.getBean("adrian")); doTestAspectsAndAdvisorAreApplied(childAc, beanFromChildContextThatShouldBeWeaved); }