use of org.springframework.messaging.converter.ContentTypeResolver in project spring-framework by spring-projects.
the class MessageBrokerConfigurationTests method configureMessageConvertersDefault.
@Test
public void configureMessageConvertersDefault() {
AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig();
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
List<MessageConverter> converters = compositeConverter.getConverters();
assertThat(converters).hasSize(3);
assertThat(converters.get(0)).isInstanceOf(StringMessageConverter.class);
assertThat(converters.get(1)).isInstanceOf(ByteArrayMessageConverter.class);
assertThat(converters.get(2)).isInstanceOf(MappingJackson2MessageConverter.class);
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
assertThat(((DefaultContentTypeResolver) resolver).getDefaultMimeType()).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
}
use of org.springframework.messaging.converter.ContentTypeResolver 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);
assertThat(annotationMethodMessageHandler).isNotNull();
MessageConverter messageConverter = annotationMethodMessageHandler.getMessageConverter();
assertThat(messageConverter).isNotNull();
assertThat(messageConverter instanceof CompositeMessageConverter).isTrue();
String name = MessageBrokerBeanDefinitionParser.MESSAGE_CONVERTER_BEAN_NAME;
CompositeMessageConverter compositeMessageConverter = this.appContext.getBean(name, CompositeMessageConverter.class);
assertThat(compositeMessageConverter).isNotNull();
name = MessageBrokerBeanDefinitionParser.MESSAGING_TEMPLATE_BEAN_NAME;
SimpMessagingTemplate simpMessagingTemplate = this.appContext.getBean(name, SimpMessagingTemplate.class);
assertThat(simpMessagingTemplate).isNotNull();
assertThat(simpMessagingTemplate.getUserDestinationPrefix()).isEqualTo("/personal/");
List<MessageConverter> converters = compositeMessageConverter.getConverters();
assertThat(converters).hasSize(3);
assertThat(converters.get(0)).isInstanceOf(StringMessageConverter.class);
assertThat(converters.get(1)).isInstanceOf(ByteArrayMessageConverter.class);
assertThat(converters.get(2)).isInstanceOf(MappingJackson2MessageConverter.class);
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(2)).getContentTypeResolver();
assertThat(((DefaultContentTypeResolver) resolver).getDefaultMimeType()).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(annotationMethodMessageHandler);
Object pathMatcher = handlerAccessor.getPropertyValue("pathMatcher");
String pathSeparator = (String) new DirectFieldAccessor(pathMatcher).getPropertyValue("pathSeparator");
assertThat(pathSeparator).isEqualTo(".");
}
Aggregations