Search in sources :

Example 81 with ApplicationContext

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

the class WebSocketMessageBrokerConfigurationSupportTests method clientInboundChannelSendMessage.

@Test
public void clientInboundChannelSendMessage() throws Exception {
    ApplicationContext config = createConfig(TestChannelConfig.class, TestConfigurer.class);
    TestChannel channel = config.getBean("clientInboundChannel", TestChannel.class);
    SubProtocolWebSocketHandler webSocketHandler = config.getBean(SubProtocolWebSocketHandler.class);
    List<ChannelInterceptor> interceptors = channel.getInterceptors();
    assertEquals(ImmutableMessageChannelInterceptor.class, interceptors.get(interceptors.size() - 1).getClass());
    TestWebSocketSession session = new TestWebSocketSession("s1");
    session.setOpen(true);
    webSocketHandler.afterConnectionEstablished(session);
    TextMessage textMessage = StompTextMessageBuilder.create(StompCommand.SEND).headers("destination:/foo").build();
    webSocketHandler.handleMessage(session, textMessage);
    Message<?> message = channel.messages.get(0);
    StompHeaderAccessor accessor = StompHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
    assertNotNull(accessor);
    assertFalse(accessor.isMutable());
    assertEquals(SimpMessageType.MESSAGE, accessor.getMessageType());
    assertEquals("/foo", accessor.getDestination());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) TestWebSocketSession(org.springframework.web.socket.handler.TestWebSocketSession) SubProtocolWebSocketHandler(org.springframework.web.socket.messaging.SubProtocolWebSocketHandler) ChannelInterceptor(org.springframework.messaging.support.ChannelInterceptor) ImmutableMessageChannelInterceptor(org.springframework.messaging.support.ImmutableMessageChannelInterceptor) StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) TextMessage(org.springframework.web.socket.TextMessage) Test(org.junit.Test)

Example 82 with ApplicationContext

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

the class WebSocketMessageBrokerConfigurationSupportTests method clientOutboundChannel.

@Test
public void clientOutboundChannel() {
    ApplicationContext config = createConfig(TestChannelConfig.class, TestConfigurer.class);
    TestChannel channel = config.getBean("clientOutboundChannel", TestChannel.class);
    Set<MessageHandler> handlers = channel.getSubscribers();
    List<ChannelInterceptor> interceptors = channel.getInterceptors();
    assertEquals(ImmutableMessageChannelInterceptor.class, interceptors.get(interceptors.size() - 1).getClass());
    assertEquals(1, handlers.size());
    assertTrue(handlers.contains(config.getBean(SubProtocolWebSocketHandler.class)));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler) UserDestinationMessageHandler(org.springframework.messaging.simp.user.UserDestinationMessageHandler) MessageHandler(org.springframework.messaging.MessageHandler) ChannelInterceptor(org.springframework.messaging.support.ChannelInterceptor) ImmutableMessageChannelInterceptor(org.springframework.messaging.support.ImmutableMessageChannelInterceptor) Test(org.junit.Test)

Example 83 with ApplicationContext

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

the class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests method testRequestScopeWithProxiedTargetClass.

@Test
public void testRequestScopeWithProxiedTargetClass() {
    RequestContextHolder.setRequestAttributes(oldRequestAttributes);
    ApplicationContext context = createContext(ScopedProxyMode.TARGET_CLASS);
    IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
    // should be a class-based proxy
    assertTrue(AopUtils.isCglibProxy(bean));
    assertTrue(bean instanceof RequestScopedTestBean);
    assertEquals(DEFAULT_NAME, bean.getName());
    bean.setName(MODIFIED_NAME);
    RequestContextHolder.setRequestAttributes(newRequestAttributes);
    // this is a proxy so it should be reset to default
    assertEquals(DEFAULT_NAME, bean.getName());
    RequestContextHolder.setRequestAttributes(oldRequestAttributes);
    assertEquals(MODIFIED_NAME, bean.getName());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) Test(org.junit.Test)

Example 84 with ApplicationContext

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

the class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests method testSingletonScopeIgnoresProxyInterfaces.

@Test
public void testSingletonScopeIgnoresProxyInterfaces() {
    RequestContextHolder.setRequestAttributes(oldRequestAttributes);
    ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
    ScopedTestBean bean = (ScopedTestBean) context.getBean("singleton");
    // should not be a proxy
    assertFalse(AopUtils.isAopProxy(bean));
    assertEquals(DEFAULT_NAME, bean.getName());
    bean.setName(MODIFIED_NAME);
    RequestContextHolder.setRequestAttributes(newRequestAttributes);
    // not a proxy so this should not have changed
    assertEquals(MODIFIED_NAME, bean.getName());
    // singleton bean, so name should be modified even after lookup
    ScopedTestBean bean2 = (ScopedTestBean) context.getBean("singleton");
    assertEquals(MODIFIED_NAME, bean2.getName());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) Test(org.junit.Test)

Example 85 with ApplicationContext

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

the class ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests method testRequestScopeWithProxiedInterfaces.

@Test
public void testRequestScopeWithProxiedInterfaces() {
    RequestContextHolder.setRequestAttributes(oldRequestAttributes);
    ApplicationContext context = createContext(ScopedProxyMode.INTERFACES);
    IScopedTestBean bean = (IScopedTestBean) context.getBean("request");
    // should be dynamic proxy, implementing both interfaces
    assertTrue(AopUtils.isJdkDynamicProxy(bean));
    assertTrue(bean instanceof AnotherScopeTestInterface);
    assertEquals(DEFAULT_NAME, bean.getName());
    bean.setName(MODIFIED_NAME);
    RequestContextHolder.setRequestAttributes(newRequestAttributes);
    // this is a proxy so it should be reset to default
    assertEquals(DEFAULT_NAME, bean.getName());
    RequestContextHolder.setRequestAttributes(oldRequestAttributes);
    assertEquals(MODIFIED_NAME, bean.getName());
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) Test(org.junit.Test)

Aggregations

ApplicationContext (org.springframework.context.ApplicationContext)578 Test (org.junit.Test)262 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)179 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)44 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)37 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)28 File (java.io.File)25 DataSource (javax.sql.DataSource)24 Messenger (org.springframework.scripting.Messenger)24 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)21 Refreshable (org.springframework.aop.target.dynamic.Refreshable)20 StubCloudConnectorTest (org.springframework.cloud.StubCloudConnectorTest)17 HashMap (java.util.HashMap)16 SchedulerException (org.quartz.SchedulerException)16 ArrayList (java.util.ArrayList)14 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)14 WebApplicationContext (org.springframework.web.context.WebApplicationContext)14 MovieMapper (com.mapper.MovieMapper)13 Map (java.util.Map)13 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)13