List of usage examples for org.springframework.context.support StaticApplicationContext refresh
@Override public void refresh() throws BeansException, IllegalStateException
From source file:org.jasig.cas.web.ProxyControllerTests.java
@Before public void onSetUp() throws Exception { this.proxyController = new ProxyController(); this.proxyController.setCentralAuthenticationService(getCentralAuthenticationService()); StaticApplicationContext context = new StaticApplicationContext(); context.refresh(); this.proxyController.setApplicationContext(context); }
From source file:com.bbytes.zorba.jobworker.event.JobEventTest.java
@Test public void testEventPublishAndListener() { JobEvent jobEvent = new JobEvent("testid", JobStatusType.STARTED, null, "Test event"); StaticApplicationContext context = new StaticApplicationContext(); context.addApplicationListener(this); context.refresh(); context.publishEvent(jobEvent);//from w ww. ja v a 2 s .com }
From source file:org.jasig.cas.web.ServiceValidateControllerTests.java
@Before public void onSetUp() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); context.refresh(); this.serviceValidateController = new ServiceValidateController(); this.serviceValidateController.setCentralAuthenticationService(getCentralAuthenticationService()); final Cas20ProxyHandler proxyHandler = new Cas20ProxyHandler(); proxyHandler.setHttpClient(new HttpClient()); this.serviceValidateController.setProxyHandler(proxyHandler); this.serviceValidateController.setApplicationContext(context); this.serviceValidateController.setArgumentExtractor(new CasArgumentExtractor()); }
From source file:org.springframework.ws.transport.http.HttpComponentsMessageSenderIntegrationTest.java
@Test public void testContextClose() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); int port = FreePortScanner.getFreePort(); Server jettyServer = new Server(port); Context jettyContext = new Context(jettyServer, "/"); jettyContext.addServlet(new ServletHolder(new EchoServlet()), "/"); jettyServer.start();//ww w .ja va2 s . c om WebServiceConnection connection = null; try { StaticApplicationContext appContext = new StaticApplicationContext(); appContext.registerSingleton("messageSender", HttpComponentsMessageSender.class); appContext.refresh(); HttpComponentsMessageSender messageSender = appContext.getBean("messageSender", HttpComponentsMessageSender.class); connection = messageSender.createConnection(new URI("http://localhost:" + port)); connection.send(new SaajSoapMessage(messageFactory.createMessage())); connection.receive(new SaajSoapMessageFactory(messageFactory)); appContext.close(); } finally { if (connection != null) { try { connection.close(); } catch (IOException ex) { // ignore } } if (jettyServer.isRunning()) { jettyServer.stop(); } } }
From source file:org.jboss.arquillian.spring.integration.enricher.AbstractSpringInjectionEnricher.java
/** * <p>Injects dependencies into the test case.</p> * * @param applicationContext the {@link org.springframework.context.ApplicationContext} * @param testCase the test case for which the beans will be injected *//* w ww. j av a2s. com*/ private void injectDependencies(ApplicationContext applicationContext, Object testCase) { // for applications that do not contain Annotation post processors, create new // application context with those and create test class from that context StaticApplicationContext staticContext = new StaticApplicationContext(applicationContext); AnnotationConfigUtils.registerAnnotationConfigProcessors(staticContext); staticContext.refresh(); // retrieves the bean factory AutowireCapableBeanFactory beanFactory = staticContext.getAutowireCapableBeanFactory(); // injects all the members beanFactory.autowireBeanProperties(testCase, AutowireCapableBeanFactory.AUTOWIRE_NO, false); // initialize the bean beanFactory.initializeBean(testCase, testCase.getClass().getName()); }
From source file:io.nuun.plugin.spring.UsingSpringAsDIPlugin.java
public Object nativeUnitModule() { ClassPathXmlApplicationContext parentCtx = new ClassPathXmlApplicationContext("context.xml"); StaticApplicationContext dynCtx = new StaticApplicationContext(); GenericBeanDefinition beanDef = new GenericBeanDefinition(); beanDef.setBeanClass(Service3Internal.class); beanDef.setScope("prototype"); dynCtx.registerBeanDefinition("service3", beanDef); dynCtx.setParent(parentCtx);/*ww w . j a v a 2 s .c om*/ dynCtx.refresh(); return dynCtx; }
From source file:org.nuunframework.spring.UsingSpringAsDIPlugin.java
@Override public Object dependencyInjectionDef() { ClassPathXmlApplicationContext parentCtx = new ClassPathXmlApplicationContext("context.xml"); StaticApplicationContext dynCtx = new StaticApplicationContext(); GenericBeanDefinition beanDef = new GenericBeanDefinition(); beanDef.setBeanClass(Service3Internal.class); beanDef.setScope("prototype"); dynCtx.registerBeanDefinition("service3", beanDef); dynCtx.setParent(parentCtx);/* w ww.j a v a 2 s.c o m*/ dynCtx.refresh(); return dynCtx; }
From source file:ch.rasc.wampspring.method.WampAnnotationMethodMessageHandlerTest.java
@Before public void setup() { MockitoAnnotations.initMocks(this); when(this.clientOutboundChannel.send(any(WampMessage.class))).thenReturn(true); DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(); MethodParameterConverter paramConverter = new MethodParameterConverter(new ObjectMapper(), conversionService);//www.ja v a 2 s . c om this.messageHandler = new WampAnnotationMethodMessageHandler(this.clientInboundChannel, this.clientOutboundChannel, this.eventMessenger, conversionService, paramConverter, new AntPathMatcher(), WampMessageSelectors.ACCEPT_ALL); @SuppressWarnings("resource") StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerPrototype("annotatedTestService", AnnotatedTestService.class); applicationContext.refresh(); this.messageHandler.setApplicationContext(applicationContext); this.messageHandler.afterPropertiesSet(); this.messageHandler.start(); }
From source file:net.sourceforge.vulcan.spring.SpringPluginManagerTest.java
public void testPluginAppCtxGetsParentPropertyPlaceholder() throws Exception { final PropertyResourceConfigurer cfgr = new PropertyPlaceholderConfigurer(); final StaticApplicationContext ctx = new StaticApplicationContext(); ctx.getBeanFactory().registerSingleton("foo", cfgr); ctx.refresh(); mgr.setApplicationContext(ctx);// w w w. jav a 2 s .c om expect(store.getPluginConfigs()).andReturn(new PluginMetaDataDto[] { createFakePluginConfig(true) }); expert.registerPlugin((ClassLoader) anyObject(), (String) anyObject()); replay(); mgr.init(); verify(); assertTrue("should contain cfgr", mgr.plugins.get("1").context.getBeanFactoryPostProcessors().contains(cfgr)); }
From source file:org.springframework.cloud.aws.messaging.listener.QueueMessageHandlerTest.java
@Test public void receiveMessage_methodAnnotatedWithMessageMappingAnnotation_methodInvokedForIncomingMessage() throws Exception { StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("incomingMessageHandler", IncomingMessageHandler.class); applicationContext.registerSingleton("queueMessageHandler", QueueMessageHandler.class); applicationContext.refresh(); MessageHandler messageHandler = applicationContext.getBean(MessageHandler.class); messageHandler.handleMessage(MessageBuilder.withPayload("testContent") .setHeader(QueueMessageHandler.Headers.LOGICAL_RESOURCE_ID_MESSAGE_HEADER_KEY, "receive").build()); IncomingMessageHandler messageListener = applicationContext.getBean(IncomingMessageHandler.class); assertEquals("testContent", messageListener.getLastReceivedMessage()); }