diff --git a/mdx-web/src/main/java/com/mx/path/model/mdx/web/MdxOnDemandSerializationWebMvcConfigurer.java b/mdx-web/src/main/java/com/mx/path/model/mdx/web/MdxOnDemandSerializationWebMvcConfigurer.java index f6d3002d..0f7c996a 100644 --- a/mdx-web/src/main/java/com/mx/path/model/mdx/web/MdxOnDemandSerializationWebMvcConfigurer.java +++ b/mdx-web/src/main/java/com/mx/path/model/mdx/web/MdxOnDemandSerializationWebMvcConfigurer.java @@ -8,6 +8,7 @@ import com.mx.path.model.mdx.model.Resources; import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.json.GsonHttpMessageConverter; @@ -25,6 +26,7 @@ public class MdxOnDemandSerializationWebMvcConfigurer implements WebMvcConfigure CONVERT_CLASSES = new ArrayList<>(); CONVERT_CLASSES.add(GsonHttpMessageConverter.class); CONVERT_CLASSES.add(StringHttpMessageConverter.class); + CONVERT_CLASSES.add(ByteArrayHttpMessageConverter.class); } @Override diff --git a/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/MdxOnDemandSerializationWebMvcConfigurerTest.groovy b/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/MdxOnDemandSerializationWebMvcConfigurerTest.groovy new file mode 100644 index 00000000..c977889a --- /dev/null +++ b/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/MdxOnDemandSerializationWebMvcConfigurerTest.groovy @@ -0,0 +1,60 @@ +package com.mx.path.model.mdx.web + +import com.fasterxml.jackson.databind.module.SimpleModule + +import org.springframework.http.converter.ByteArrayHttpMessageConverter +import org.springframework.http.converter.FormHttpMessageConverter +import org.springframework.http.converter.ResourceHttpMessageConverter +import org.springframework.http.converter.StringHttpMessageConverter +import org.springframework.http.converter.json.GsonHttpMessageConverter +import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter + +import spock.lang.Specification + +class MdxOnDemandSerializationWebMvcConfigurerTest extends Specification { + + MdxOnDemandSerializationWebMvcConfigurer subject + + def setup() { + subject = new MdxOnDemandSerializationWebMvcConfigurer() + } + + def "filters non-whitelisted message converters and appends the custom XML converter"() { + given: + def gsonConverter = new GsonHttpMessageConverter() + def stringConverter = new StringHttpMessageConverter() + def byteArrayConverter = new ByteArrayHttpMessageConverter() + def unwantedResourceConverter = new ResourceHttpMessageConverter() + def unwantedFormConverter = new FormHttpMessageConverter() + + def converters = [ + unwantedResourceConverter, + gsonConverter, + unwantedFormConverter, + stringConverter, + byteArrayConverter + ] + + when: + subject.configureMessageConverters(converters) + + then: + verifyAll(converters) { + it.size() == 4 + it.contains(gsonConverter) + it.contains(stringConverter) + it.contains(byteArrayConverter) + !it.contains(unwantedResourceConverter) + !it.contains(unwantedFormConverter) + it.last() instanceof MappingJackson2XmlHttpMessageConverter + } + } + + def "payloadModule returns a correctly instantiated SimpleModule"() { + when: + def module = subject.payloadModule() + + then: + module instanceof SimpleModule + } +}