Commit b8d6b340 authored by Andy Wilkinson's avatar Andy Wilkinson

Test that HttpMapper properties are only used when they’re defined

Closes gh-1923
parent c053540b
......@@ -21,6 +21,8 @@ import java.util.List;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -34,6 +36,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
......@@ -155,6 +158,30 @@ public class HttpMessageConvertersAutoConfigurationTests {
assertConverterBeanRegisteredWithHttpMessageConverters(StringHttpMessageConverter.class);
}
@Test
public void httpMapperPropertiesAreNotAppliedWhenNotConfigured() throws Exception {
this.context.register(JacksonObjectMapperConfig.class,
HttpMessageConvertersAutoConfiguration.class);
this.context.refresh();
MappingJackson2HttpMessageConverter converter = this.context
.getBean(MappingJackson2HttpMessageConverter.class);
assertNull(new DirectFieldAccessor(converter)
.getPropertyValue("prettyPrint"));
}
@Test
public void httpMapperPropertiesAreAppliedWhenConfigured() throws Exception {
this.context.register(JacksonObjectMapperConfig.class,
HttpMessageConvertersAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"http.mappers.jsonPrettyPrint:true");
this.context.refresh();
MappingJackson2HttpMessageConverter converter = this.context
.getBean(MappingJackson2HttpMessageConverter.class);
assertTrue((Boolean) new DirectFieldAccessor(converter)
.getPropertyValue("prettyPrint"));
}
private void assertConverterBeanExists(Class<?> type, String beanName) {
assertEquals(1, this.context.getBeansOfType(type).size());
List<String> beanNames = Arrays.asList(this.context.getBeanDefinitionNames());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment