use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class MappingJackson2XmlHttpMessageConverterTests 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</string>"));
assertTrue(result.contains("<number>42</number>"));
assertTrue(result.contains("<fraction>42.0</fraction>"));
assertTrue(result.contains("<array><array>Foo</array><array>Bar</array></array>"));
assertTrue(result.contains("<bool>true</bool>"));
assertTrue(result.contains("<bytes>AQI=</bytes>"));
assertEquals("Invalid content-type", new MediaType("application", "xml", StandardCharsets.UTF_8), outputMessage.getHeaders().getContentType());
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class MarshallingHttpMessageConverterTests method write.
@Test
public void write() throws Exception {
String body = "<root>Hello World</root>";
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
Marshaller marshaller = mock(Marshaller.class);
willDoNothing().given(marshaller).marshal(eq(body), isA(Result.class));
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller);
converter.write(body, null, outputMessage);
assertEquals("Invalid content-type", new MediaType("application", "xml"), outputMessage.getHeaders().getContentType());
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class SourceHttpMessageConverterTests method writeSAXSource.
@Test
public void writeSAXSource() throws Exception {
String xml = "<root>Hello World</root>";
SAXSource saxSource = new SAXSource(new InputSource(new StringReader(xml)));
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
converter.write(saxSource, null, outputMessage);
assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8), isSimilarTo("<root>Hello World</root>"));
assertEquals("Invalid content-type", new MediaType("application", "xml"), outputMessage.getHeaders().getContentType());
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class SourceHttpMessageConverterTests method writeStreamSource.
@Test
public void writeStreamSource() throws Exception {
String xml = "<root>Hello World</root>";
StreamSource streamSource = new StreamSource(new StringReader(xml));
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
converter.write(streamSource, null, outputMessage);
assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8), isSimilarTo("<root>Hello World</root>"));
assertEquals("Invalid content-type", new MediaType("application", "xml"), outputMessage.getHeaders().getContentType());
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class ResourceHttpMessageConverterTests method shouldWriteImageResource.
@Test
public void shouldWriteImageResource() throws IOException {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
Resource body = new ClassPathResource("logo.jpg", getClass());
converter.write(body, null, outputMessage);
assertEquals("Invalid content-type", MediaType.IMAGE_JPEG, outputMessage.getHeaders().getContentType());
assertEquals("Invalid content-length", body.getFile().length(), outputMessage.getHeaders().getContentLength());
}
Aggregations