use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.
the class SubProtocolWebSocketHandlerTests method checkSession.
@Test
@SuppressWarnings("unchecked")
public void checkSession() throws Exception {
TestWebSocketSession session1 = new TestWebSocketSession("id1");
TestWebSocketSession session2 = new TestWebSocketSession("id2");
session1.setOpen(true);
session2.setOpen(true);
session1.setAcceptedProtocol("v12.stomp");
session2.setAcceptedProtocol("v12.stomp");
this.webSocketHandler.setProtocolHandlers(Arrays.asList(this.stompHandler));
this.webSocketHandler.afterConnectionEstablished(session1);
this.webSocketHandler.afterConnectionEstablished(session2);
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(this.webSocketHandler);
Map<String, ?> map = (Map<String, ?>) handlerAccessor.getPropertyValue("sessions");
DirectFieldAccessor session1Accessor = new DirectFieldAccessor(map.get("id1"));
DirectFieldAccessor session2Accessor = new DirectFieldAccessor(map.get("id2"));
long sixtyOneSecondsAgo = System.currentTimeMillis() - 61 * 1000;
handlerAccessor.setPropertyValue("lastSessionCheckTime", sixtyOneSecondsAgo);
session1Accessor.setPropertyValue("createTime", sixtyOneSecondsAgo);
session2Accessor.setPropertyValue("createTime", sixtyOneSecondsAgo);
this.webSocketHandler.start();
this.webSocketHandler.handleMessage(session1, new TextMessage("foo"));
assertTrue(session1.isOpen());
assertNull(session1.getCloseStatus());
assertFalse(session2.isOpen());
assertEquals(CloseStatus.SESSION_NOT_RELIABLE, session2.getCloseStatus());
assertNotEquals("lastSessionCheckTime not updated", sixtyOneSecondsAgo, handlerAccessor.getPropertyValue("lastSessionCheckTime"));
}
use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.
the class TestValidator method annotationMethodMessageHandler.
@Test
public void annotationMethodMessageHandler() {
loadBeanDefinitions("websocket-config-broker-simple.xml");
SimpAnnotationMethodMessageHandler annotationMethodMessageHandler = this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);
assertNotNull(annotationMethodMessageHandler);
MessageConverter messageConverter = annotationMethodMessageHandler.getMessageConverter();
assertNotNull(messageConverter);
assertTrue(messageConverter instanceof CompositeMessageConverter);
String name = MessageBrokerBeanDefinitionParser.MESSAGE_CONVERTER_BEAN_NAME;
CompositeMessageConverter compositeMessageConverter = this.appContext.getBean(name, CompositeMessageConverter.class);
assertNotNull(compositeMessageConverter);
name = MessageBrokerBeanDefinitionParser.MESSAGING_TEMPLATE_BEAN_NAME;
SimpMessagingTemplate simpMessagingTemplate = this.appContext.getBean(name, SimpMessagingTemplate.class);
assertNotNull(simpMessagingTemplate);
assertEquals("/personal/", simpMessagingTemplate.getUserDestinationPrefix());
List<MessageConverter> converters = compositeMessageConverter.getConverters();
assertThat(converters.size(), Matchers.is(3));
assertThat(converters.get(0), Matchers.instanceOf(StringMessageConverter.class));
assertThat(converters.get(1), Matchers.instanceOf(ByteArrayMessageConverter.class));
assertThat(converters.get(2), Matchers.instanceOf(MappingJackson2MessageConverter.class));
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
assertEquals(MimeTypeUtils.APPLICATION_JSON, ((DefaultContentTypeResolver) resolver).getDefaultMimeType());
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(annotationMethodMessageHandler);
String pathSeparator = (String) new DirectFieldAccessor(handlerAccessor.getPropertyValue("pathMatcher")).getPropertyValue("pathSeparator");
assertEquals(".", pathSeparator);
}
use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.
the class TestPathHelper method testArgumentResolvers.
private void testArgumentResolvers(Object bean) {
assertNotNull(bean);
Object value = new DirectFieldAccessor(bean).getPropertyValue("customArgumentResolvers");
assertNotNull(value);
assertTrue(value instanceof List);
@SuppressWarnings("unchecked") List<HandlerMethodArgumentResolver> resolvers = (List<HandlerMethodArgumentResolver>) value;
assertEquals(3, resolvers.size());
assertTrue(resolvers.get(0) instanceof ServletWebArgumentResolverAdapter);
assertTrue(resolvers.get(1) instanceof TestHandlerMethodArgumentResolver);
assertTrue(resolvers.get(2) instanceof TestHandlerMethodArgumentResolver);
assertNotSame(resolvers.get(1), resolvers.get(2));
}
use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.
the class TestPathHelper method verifyResponseBodyAdvice.
@SuppressWarnings("unchecked")
private void verifyResponseBodyAdvice(Object bean) {
assertNotNull(bean);
Object value = new DirectFieldAccessor(bean).getPropertyValue("responseBodyAdvice");
assertNotNull(value);
assertTrue(value instanceof List);
List<ResponseBodyAdvice> converters = (List<ResponseBodyAdvice>) value;
assertTrue(converters.get(0) instanceof JsonViewResponseBodyAdvice);
}
use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.
the class TestPathHelper method verifyRequestResponseBodyAdvice.
@SuppressWarnings("unchecked")
private void verifyRequestResponseBodyAdvice(Object bean) {
assertNotNull(bean);
Object value = new DirectFieldAccessor(bean).getPropertyValue("requestResponseBodyAdvice");
assertNotNull(value);
assertTrue(value instanceof List);
List<ResponseBodyAdvice> converters = (List<ResponseBodyAdvice>) value;
assertTrue(converters.get(0) instanceof JsonViewRequestBodyAdvice);
assertTrue(converters.get(1) instanceof JsonViewResponseBodyAdvice);
}
Aggregations