This commit is contained in:
Phillip Webb 2017-04-17 22:08:51 -07:00
parent 3fe0b844a6
commit f46d799f31
8 changed files with 37 additions and 24 deletions

View File

@ -108,7 +108,8 @@ public class HealthMvcEndpointAutoConfigurationTests {
public void endpointConditionalOnMissingBean() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(TestConfiguration.class, TestHealthMvcEndpointConfiguration.class);
this.context.register(TestConfiguration.class,
TestHealthMvcEndpointConfiguration.class);
this.context.refresh();
MockHttpServletRequest request = new MockHttpServletRequest();
Health health = (Health) this.context.getBean(HealthMvcEndpoint.class)
@ -142,6 +143,7 @@ public class HealthMvcEndpointAutoConfigurationTests {
public HealthMvcEndpoint endpoint(HealthEndpoint endpoint) {
return new TestHealthMvcEndpoint(endpoint);
}
}
static class TestHealthMvcEndpoint extends HealthMvcEndpoint {
@ -151,9 +153,11 @@ public class HealthMvcEndpointAutoConfigurationTests {
}
@Override
protected boolean exposeHealthDetails(HttpServletRequest request, Principal principal) {
protected boolean exposeHealthDetails(HttpServletRequest request,
Principal principal) {
return true;
}
}
static class TestHealthIndicator extends AbstractHealthIndicator {

View File

@ -32,6 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Integration tests for {@link JsonTest}.
*
* @author Phillip Webb
* @author Madhura Bhave
*/
@RunWith(SpringRunner.class)
@JsonTest
@ -82,9 +83,9 @@ public class JsonTestIntegrationTests {
ExampleJsonObjectWithView object = new ExampleJsonObjectWithView();
object.setValue("spring");
JsonContent<ExampleJsonObjectWithView> content = this.jacksonWithViewJson
.forView(ExampleJsonObjectWithView.TestView.class)
.write(object);
.forView(ExampleJsonObjectWithView.TestView.class).write(object);
assertThat(content).doesNotHaveJsonPathValue("id");
assertThat(content).isEqualToJson("example.json");
}
}

View File

@ -113,6 +113,10 @@ public abstract class AbstractJsonMarshalTester<T> {
return this.type;
}
/**
* Return class used to load relative resources.
* @return the resource load class
*/
protected final Class<?> getResourceLoadClass() {
return this.resourceLoadClass;
}

View File

@ -152,13 +152,14 @@ public class JacksonTester<T> extends AbstractJsonMarshalTester<T> {
}
/**
* Returns a new instance of {@link JacksonTester} with the view
* that should be used for json serialization/deserialization.
* Returns a new instance of {@link JacksonTester} with the view that should be used
* for json serialization/deserialization.
* @param view the view class
* @return the new instance
*/
public JacksonTester<T> forView(Class<?> view) {
return new JacksonTester<T>(this.getResourceLoadClass(), this.getType(), this.objectMapper, view);
return new JacksonTester<T>(this.getResourceLoadClass(), this.getType(),
this.objectMapper, view);
}
/**

View File

@ -64,4 +64,3 @@ public class ExampleObject {
}
}

View File

@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Integration tests for {@link JacksonTester}. Shows typical usage.
*
* @author Phillip Webb
* @author Madhura Bhave
*/
public class JacksonTesterIntegrationTests {
@ -56,6 +57,13 @@ public class JacksonTesterIntegrationTests {
JacksonTester.initFields(this, this.objectMapper);
}
@Test
public void typicalTest() throws Exception {
String example = JSON;
assertThat(this.simpleJson.parse(example).getObject().getName())
.isEqualTo("Spring");
}
@Test
public void typicalListTest() throws Exception {
String example = "[" + JSON + "]";
@ -79,10 +87,9 @@ public class JacksonTesterIntegrationTests {
ExampleObjectWithView object = new ExampleObjectWithView();
object.setName("Spring");
object.setAge(123);
JsonContent<ExampleObjectWithView> content = this.jsonWithView.forView(
ExampleObjectWithView.TestView.class).write(object);
assertThat(content).extractingJsonPathStringValue("@.name")
.isEqualTo("Spring");
JsonContent<ExampleObjectWithView> content = this.jsonWithView
.forView(ExampleObjectWithView.TestView.class).write(object);
assertThat(content).extractingJsonPathStringValue("@.name").isEqualTo("Spring");
assertThat(content).doesNotHaveJsonPathValue("age");
}
@ -90,10 +97,9 @@ public class JacksonTesterIntegrationTests {
public void readWithResourceAndView() throws Exception {
this.objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
ByteArrayResource resource = new ByteArrayResource(JSON.getBytes());
ObjectContent<ExampleObjectWithView> content = this.jsonWithView.forView(
ExampleObjectWithView.TestView.class).read(resource);
assertThat(content.getObject().getName())
.isEqualTo("Spring");
ObjectContent<ExampleObjectWithView> content = this.jsonWithView
.forView(ExampleObjectWithView.TestView.class).read(resource);
assertThat(content.getObject().getName()).isEqualTo("Spring");
assertThat(content.getObject().getAge()).isEqualTo(0);
}
@ -101,10 +107,9 @@ public class JacksonTesterIntegrationTests {
public void readWithReaderAndView() throws Exception {
this.objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
Reader reader = new StringReader(JSON);
ObjectContent<ExampleObjectWithView> content = this.jsonWithView.forView(
ExampleObjectWithView.TestView.class).read(reader);
assertThat(content.getObject().getName())
.isEqualTo("Spring");
ObjectContent<ExampleObjectWithView> content = this.jsonWithView
.forView(ExampleObjectWithView.TestView.class).read(reader);
assertThat(content.getObject().getName()).isEqualTo("Spring");
assertThat(content.getObject().getAge()).isEqualTo(0);
}

View File

@ -33,9 +33,9 @@ public interface SpringApplicationAdminMXBean {
boolean isReady();
/**
* Specify if the application runs in an embedded web container. Return
* {@code false} on a web application that hasn't fully started yet, so it is
* preferable to wait for the application to be {@link #isReady() ready}.
* Specify if the application runs in an embedded web container. Return {@code false}
* on a web application that hasn't fully started yet, so it is preferable to wait for
* the application to be {@link #isReady() ready}.
* @return {@code true} if the application runs in an embedded web container
* @see #isReady()
*/