mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 03:43:21 +08:00
Add serialization endpoint tests
Test basic serialization in Endpoint tests to ensure that JSON can always be produced.
This commit is contained in:
parent
223a6bd062
commit
7e58483ead
@ -23,11 +23,14 @@ import java.util.Map;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@ -41,7 +44,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
|
||||
|
||||
protected AnnotationConfigApplicationContext context;
|
||||
|
||||
private final Class<?> configClass;
|
||||
protected final Class<?> configClass;
|
||||
|
||||
private final Class<?> type;
|
||||
|
||||
@ -63,7 +66,7 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
|
||||
@Before
|
||||
public void setup() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(this.configClass);
|
||||
this.context.register(JacksonAutoConfiguration.class, this.configClass);
|
||||
this.context.refresh();
|
||||
}
|
||||
|
||||
@ -160,6 +163,14 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
|
||||
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")
|
||||
protected T getEndpointBean() {
|
||||
return (T) this.context.getBean(this.type);
|
||||
|
@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionEvaluationRepor
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Condition;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -51,6 +52,9 @@ public class AutoConfigurationReportEndpointTests extends
|
||||
|
||||
@Test
|
||||
public void invoke() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
this.context.register(this.configClass);
|
||||
this.context.refresh();
|
||||
Report report = getEndpointBean().invoke();
|
||||
assertTrue(report.getPositiveMatches().isEmpty());
|
||||
assertTrue(report.getNegativeMatches().containsKey("a"));
|
||||
|
Loading…
Reference in New Issue
Block a user