use of javax.xml.transform.stream.StreamResult in project spring-framework by spring-projects.
the class XStreamMarshallerTests method annotatedMarshalStreamResultWriter.
@Test
public void annotatedMarshalStreamResultWriter() throws Exception {
marshaller.setAnnotatedClasses(Flight.class);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
Flight flight = new Flight();
flight.setFlightNumber(42);
marshaller.marshal(flight, result);
String expected = "<flight><number>42</number></flight>";
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(expected));
}
use of javax.xml.transform.stream.StreamResult in project spring-framework by spring-projects.
the class XStreamMarshallerTests method omitFields.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void omitFields() throws Exception {
Map omittedFieldsMap = Collections.singletonMap(Flight.class, "flightNumber");
marshaller.setOmittedFields(omittedFieldsMap);
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
assertXpathNotExists("/flight/flightNumber", writer.toString());
}
use of javax.xml.transform.stream.StreamResult in project spring-framework by spring-projects.
the class XStreamMarshallerTests method fieldAliases.
@Test
public void fieldAliases() throws Exception {
marshaller.setFieldAliases(Collections.singletonMap("org.springframework.oxm.xstream.Flight.flightNumber", "flightNo"));
Writer writer = new StringWriter();
marshaller.marshal(flight, new StreamResult(writer));
String expected = "<flight><flightNo>42</flightNo></flight>";
assertThat("Marshaller does not use aliases", writer.toString(), isSimilarTo(expected));
}
use of javax.xml.transform.stream.StreamResult in project spring-framework by spring-projects.
the class JibxMarshallerTests method encodingAndStandalone.
@Test
public void encodingAndStandalone() throws Exception {
marshaller.setEncoding("ISO-8859-1");
marshaller.setStandalone(Boolean.TRUE);
StringWriter writer = new StringWriter();
marshaller.marshal(flights, new StreamResult(writer));
assertTrue("Encoding and standalone not set", writer.toString().startsWith("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>"));
}
use of javax.xml.transform.stream.StreamResult in project spring-framework by spring-projects.
the class JibxMarshallerTests method indentation.
@Test
public void indentation() throws Exception {
marshaller.setIndent(4);
StringWriter writer = new StringWriter();
marshaller.marshal(flights, new StreamResult(writer));
String expected = "<?xml version=\"1.0\"?>\n" + "<flights xmlns=\"http://samples.springframework.org/flight\">\n" + " <flight>\n" + " <number>42</number>\n" + " </flight>\n" + "</flights>";
assertThat(writer.toString(), isSimilarTo(expected).ignoreWhitespace());
}
Aggregations