Commit 7e58483e authored by Phillip Webb's avatar Phillip Webb

Add serialization endpoint tests

Test basic serialization in Endpoint tests to ensure that JSON
can always be produced.
parent 223a6bd0
...@@ -23,11 +23,14 @@ import java.util.Map; ...@@ -23,11 +23,14 @@ import java.util.Map;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySource;
import com.fasterxml.jackson.databind.ObjectMapper;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
...@@ -41,7 +44,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> { ...@@ -41,7 +44,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
protected AnnotationConfigApplicationContext context; protected AnnotationConfigApplicationContext context;
private final Class<?> configClass; protected final Class<?> configClass;
private final Class<?> type; private final Class<?> type;
...@@ -63,7 +66,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> { ...@@ -63,7 +66,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
@Before @Before
public void setup() { public void setup() {
this.context = new AnnotationConfigApplicationContext(); this.context = new AnnotationConfigApplicationContext();
this.context.register(this.configClass); this.context.register(JacksonAutoConfiguration.class, this.configClass);
this.context.refresh(); this.context.refresh();
} }
...@@ -160,6 +163,14 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> { ...@@ -160,6 +163,14 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
assertThat(getEndpointBean().isEnabled(), equalTo(true)); assertThat(getEndpointBean().isEnabled(), equalTo(true));
} }
@Test
public void serialize() throws Exception {
Object result = getEndpointBean().invoke();
if (result != null) {
this.context.getBean(ObjectMapper.class).writeValue(System.out, result);
}
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected T getEndpointBean() { protected T getEndpointBean() {
return (T) this.context.getBean(this.type); return (T) this.context.getBean(this.type);
......
...@@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionEvaluationRepor ...@@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionEvaluationRepor
import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -51,6 +52,9 @@ public class AutoConfigurationReportEndpointTests extends ...@@ -51,6 +52,9 @@ public class AutoConfigurationReportEndpointTests extends
@Test @Test
public void invoke() throws Exception { public void invoke() throws Exception {
this.context = new AnnotationConfigApplicationContext();
this.context.register(this.configClass);
this.context.refresh();
Report report = getEndpointBean().invoke(); Report report = getEndpointBean().invoke();
assertTrue(report.getPositiveMatches().isEmpty()); assertTrue(report.getPositiveMatches().isEmpty());
assertTrue(report.getNegativeMatches().containsKey("a")); assertTrue(report.getNegativeMatches().containsKey("a"));
......
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