1 17 package org.apache.servicemix.components.util; 18 19 import java.io.Reader ; 20 import java.io.StringReader ; 21 22 import javax.jbi.messaging.NormalizedMessage; 23 import javax.xml.transform.Source ; 24 import javax.xml.transform.sax.SAXSource ; 25 import javax.xml.transform.stream.StreamSource ; 26 27 import junit.framework.TestCase; 28 29 import org.apache.servicemix.jbi.jaxp.SourceTransformer; 30 import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl; 31 import org.xml.sax.InputSource ; 32 33 public class CopyTransformerTest extends TestCase { 34 35 private CopyTransformer transformer = CopyTransformer.getInstance(); 36 37 public void testWithSAXSource() throws Exception { 38 Reader r = new StringReader ("<hello>world</hello>"); 39 Source src = new SAXSource (new InputSource (r)); 40 NormalizedMessage msg = copyMessage(src); 41 r.close(); 42 new SourceTransformer().contentToString(msg); 43 } 44 45 public void testWithStreamSource() throws Exception { 46 Reader r = new StringReader ("<hello>world</hello>"); 47 Source src = new StreamSource (r); 48 NormalizedMessage msg = copyMessage(src); 49 r.close(); 50 new SourceTransformer().contentToString(msg); 51 } 52 53 protected NormalizedMessage copyMessage(Source src) throws Exception { 54 NormalizedMessage from = new NormalizedMessageImpl(); 55 NormalizedMessage to = new NormalizedMessageImpl(); 56 from.setContent(src); 57 transformer.transform(null, from, to); 58 return to; 59 } 60 61 } 62 | Popular Tags |