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