1 17 package org.apache.axis2.om.impl.llom; 18 19 import org.apache.axis2.attachments.ByteArrayDataSource; 20 import org.apache.axis2.om.AbstractTestCase; 21 import org.apache.axis2.om.OMAttribute; 22 import org.apache.axis2.om.OMElement; 23 import org.apache.axis2.om.OMOutput; 24 25 import javax.activation.DataHandler ; 26 import java.io.File ; 27 import java.io.FileOutputStream ; 28 29 32 33 public class OMOutputTest extends AbstractTestCase { 34 35 38 public OMOutputTest(String testName) { 39 super(testName); 40 } 41 42 String outFileName; 43 44 String outBase64FileName; 45 46 OMElement envelope; 47 48 File outMTOMFile; 49 50 File outBase64File; 51 52 55 protected void setUp() throws Exception { 56 super.setUp(); 57 Object object; 58 DataHandler dataHandler; 59 60 outFileName = "mtom/OMSerializeMTOMOut.txt"; 61 outBase64FileName = "mtom/OMSerializeBase64Out.xml"; 62 outMTOMFile = getTestResourceFile(outFileName); 63 outBase64File = getTestResourceFile(outBase64FileName); 64 65 OMNamespaceImpl soap = new OMNamespaceImpl( 66 "http://schemas.xmlsoap.org/soap/envelope/", "soap"); 67 envelope = new OMElementImpl("Envelope", soap); 68 OMElement body = new OMElementImpl("Body", soap); 69 70 OMNamespaceImpl dataName = new OMNamespaceImpl( 71 "http://www.example.org/stuff", "m"); 72 OMElement data = new OMElementImpl("data", dataName); 73 74 OMNamespaceImpl mime = new OMNamespaceImpl( 75 "http://www.w3.org/2003/06/xmlmime", "m"); 76 77 OMElement text = new OMElementImpl("name", dataName); 78 OMAttribute cType1 = new OMAttributeImpl("contentType", mime, 79 "text/plain"); 80 text.addAttribute(cType1); 81 byte[] byteArray = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2, -1, 82 98 }; 83 dataHandler = new DataHandler (new ByteArrayDataSource(byteArray)); 84 OMTextImpl textData = new OMTextImpl(dataHandler, false); 85 86 envelope.addChild(body); 87 body.addChild(data); 88 data.addChild(text); 89 text.addChild(textData); 90 } 91 92 95 protected void tearDown() throws Exception { 96 super.tearDown(); 97 if (this.outMTOMFile.exists()) { 98 this.outMTOMFile.delete(); 99 } 100 if (this.outBase64File.exists()) { 101 this.outBase64File.delete(); 102 } 103 } 104 105 public void testComplete() throws Exception { 106 107 OMOutput mtomOutput = new OMOutput(new FileOutputStream ( 108 outMTOMFile), true); 109 OMOutput baseOutput = new OMOutput(new FileOutputStream ( 110 outBase64File), false); 111 112 envelope.serialize(baseOutput); 113 baseOutput.flush(); 114 115 envelope.serialize(mtomOutput); 116 117 mtomOutput.complete(); 118 } 119 } | Popular Tags |