Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading