use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class AtomFeedHttpMessageConverterTests method writeOtherCharset.
@Test
public void writeOtherCharset() throws IOException, SAXException {
Feed feed = new Feed("atom_1.0");
feed.setTitle("title");
String encoding = "ISO-8859-1";
feed.setEncoding(encoding);
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
converter.write(feed, null, outputMessage);
assertEquals("Invalid content-type", new MediaType("application", "atom+xml", Charset.forName(encoding)), outputMessage.getHeaders().getContentType());
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class RssChannelHttpMessageConverterTests method writeOtherCharset.
@Test
public void writeOtherCharset() throws IOException, SAXException {
Channel channel = new Channel("rss_2.0");
channel.setTitle("title");
channel.setLink("http://example.com");
channel.setDescription("description");
String encoding = "ISO-8859-1";
channel.setEncoding(encoding);
Item item1 = new Item();
item1.setTitle("title1");
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
converter.write(channel, null, outputMessage);
assertEquals("Invalid content-type", new MediaType("application", "rss+xml", Charset.forName(encoding)), outputMessage.getHeaders().getContentType());
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class Jaxb2RootElementHttpMessageConverterTests method customizeMarshaller.
// SPR-11488
@Test
public void customizeMarshaller() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
MyJaxb2RootElementHttpMessageConverter myConverter = new MyJaxb2RootElementHttpMessageConverter();
myConverter.write(new MyRootElement(new MyCustomElement("a", "b")), null, outputMessage);
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8), isSimilarTo("<myRootElement><element>a|||b</element></myRootElement>").withDifferenceEvaluator(ev));
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class Jaxb2RootElementHttpMessageConverterTests method writeXmlRootElementSubclass.
@Test
public void writeXmlRootElementSubclass() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
converter.write(rootElementCglib, null, outputMessage);
assertEquals("Invalid content-type", new MediaType("application", "xml"), outputMessage.getHeaders().getContentType());
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8), isSimilarTo("<rootElement><type s=\"Hello World\"/></rootElement>").withDifferenceEvaluator(ev));
}
use of org.springframework.http.MockHttpOutputMessage in project spring-framework by spring-projects.
the class MappingJackson2XmlHttpMessageConverterTests method jsonView.
@Test
public void jsonView() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
JacksonViewBean bean = new JacksonViewBean();
bean.setWithView1("with");
bean.setWithView2("with");
bean.setWithoutView("without");
MappingJacksonValue jacksonValue = new MappingJacksonValue(bean);
jacksonValue.setSerializationView(MyJacksonView1.class);
this.writeInternal(jacksonValue, outputMessage);
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertThat(result, containsString("<withView1>with</withView1>"));
assertThat(result, not(containsString("<withView2>with</withView2>")));
assertThat(result, not(containsString("<withoutView>without</withoutView>")));
}
Aggregations