KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > om > impl > llom > OMOutputTest


1 /**
2  * Copyright 2001-2004 The Apache Software Foundation.
3  * <p/>
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * <p/>
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * <p/>
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  * <p/>
16  */

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 JavaDoc;
26 import java.io.File JavaDoc;
27 import java.io.FileOutputStream JavaDoc;
28
29 /**
30  * @author <a HREF="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
31  */

32
33 public class OMOutputTest extends AbstractTestCase {
34
35     /**
36      * @param testName
37      */

38     public OMOutputTest(String JavaDoc testName) {
39         super(testName);
40     }
41
42     String JavaDoc outFileName;
43
44     String JavaDoc outBase64FileName;
45
46     OMElement envelope;
47
48     File JavaDoc outMTOMFile;
49
50     File JavaDoc outBase64File;
51
52     /*
53      * @see TestCase#setUp()
54      */

55     protected void setUp() throws Exception JavaDoc {
56         super.setUp();
57         Object JavaDoc object;
58         DataHandler JavaDoc 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 JavaDoc(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     /*
93      * @see TestCase#tearDown()
94      */

95     protected void tearDown() throws Exception JavaDoc {
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 JavaDoc {
106
107         OMOutput mtomOutput = new OMOutput(new FileOutputStream JavaDoc(
108                 outMTOMFile), true);
109         OMOutput baseOutput = new OMOutput(new FileOutputStream JavaDoc(
110                 outBase64File), false);
111
112         envelope.serialize(baseOutput);
113         baseOutput.flush();
114
115         envelope.serialize(mtomOutput);
116
117         mtomOutput.complete();
118     }
119 }
Popular Tags