use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class MappingJackson2HttpMessageConverterTests method prefixJson.
@Test
public void prefixJson() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
this.converter.setPrefixJson(true);
this.converter.writeInternal("foo", null, outputMessage);
assertEquals(")]}', \"foo\"", outputMessage.getBodyAsString(StandardCharsets.UTF_8));
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class MappingJackson2HttpMessageConverterTests method prettyPrintWithSse.
@Test
public void prettyPrintWithSse() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
outputMessage.getHeaders().setContentType(MediaType.TEXT_EVENT_STREAM);
PrettyPrintBean bean = new PrettyPrintBean();
bean.setName("Jason");
this.converter.setPrettyPrint(true);
this.converter.writeInternal(bean, null, outputMessage);
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertEquals("{\ndata: \"name\" : \"Jason\"\ndata:}", result);
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class MappingJackson2HttpMessageConverterTests method write.
@Test
public void write() throws IOException {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
MyBean body = new MyBean();
body.setString("Foo");
body.setNumber(42);
body.setFraction(42F);
body.setArray(new String[] { "Foo", "Bar" });
body.setBool(true);
body.setBytes(new byte[] { 0x1, 0x2 });
converter.write(body, null, outputMessage);
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertTrue(result.contains("\"string\":\"Foo\""));
assertTrue(result.contains("\"number\":42"));
assertTrue(result.contains("fraction\":42.0"));
assertTrue(result.contains("\"array\":[\"Foo\",\"Bar\"]"));
assertTrue(result.contains("\"bool\":true"));
assertTrue(result.contains("\"bytes\":\"AQI=\""));
assertEquals("Invalid content-type", new MediaType("application", "json", StandardCharsets.UTF_8), outputMessage.getHeaders().getContentType());
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class MappingJackson2HttpMessageConverterTests method prettyPrint.
@Test
public void prettyPrint() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
PrettyPrintBean bean = new PrettyPrintBean();
bean.setName("Jason");
this.converter.setPrettyPrint(true);
this.converter.writeInternal(bean, null, outputMessage);
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertEquals("{" + NEWLINE_SYSTEM_PROPERTY + " \"name\" : \"Jason\"" + NEWLINE_SYSTEM_PROPERTY + "}", result);
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class StringHttpMessageConverterTests method setUp.
@Before
public void setUp() {
this.converter = new StringHttpMessageConverter();
this.outputMessage = new MockHttpOutputMessage();
}
Aggregations