INT-896, Fixed the test to cover that it actually works

This commit is contained in:
Oleg Zhurakousky
2010-07-21 19:04:28 +00:00
parent a44f618868
commit 13356b2d96
2 changed files with 9 additions and 4 deletions

View File

@@ -37,6 +37,7 @@ import org.springframework.xml.transform.StringResult;
/**
* @author Jonas Partner
* @author Mark Fisher
* @author Oleg Zhurakousky
*/
public class MarshallingTransformerParserTests {
@@ -111,8 +112,7 @@ public class MarshallingTransformerParserTests {
Message<?> result = output.receive(0);
assertTrue("Wrong payload type", result.getPayload() instanceof DOMResult);
Document doc = (Document) ((DOMResult) result.getPayload()).getNode();
String expected = "[Payload=hello][Headers=";
assertEquals("Wrong payload", expected, doc.getDocumentElement().getTextContent().substring(0, expected.length()));
assertEquals("Wrong payload", "hello", doc.getDocumentElement().getTextContent());
}
}

View File

@@ -22,6 +22,7 @@ import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import org.springframework.integration.core.Message;
import org.springframework.oxm.Marshaller;
import org.springframework.oxm.XmlMappingException;
import org.springframework.xml.transform.StringSource;
@@ -29,12 +30,16 @@ import org.springframework.xml.transform.StringSource;
/**
*
* @author Jonas Partner
*
* @author Oleg Zhurakousky
*/
public class StubMarshaller implements Marshaller {
public void marshal(Object graph, Result result) throws XmlMappingException, IOException {
public void marshal(Object source, Result result) throws XmlMappingException, IOException {
try {
Object graph = source;
if (source instanceof Message<?>) {
graph = ((Message<?>)source).getPayload();
}
Transformer transformer = TransformerFactory.newInstance().newTransformer();
StringSource stringSource = new StringSource("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><root>" + graph.toString() + "</root>");
transformer.transform(stringSource, result);