KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > om > impl > llom > mtom > MTOMStAXSOAPModelBuilderTest


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.mtom;
18
19 import org.apache.axis2.attachments.MIMEHelper;
20 import org.apache.axis2.om.AbstractTestCase;
21 import org.apache.axis2.om.OMElement;
22 import org.apache.axis2.om.OMText;
23 import org.apache.axis2.om.OMXMLParserWrapper;
24
25 import javax.activation.DataHandler JavaDoc;
26 import javax.xml.stream.XMLInputFactory;
27 import javax.xml.stream.XMLStreamReader;
28 import java.io.BufferedReader JavaDoc;
29 import java.io.FileInputStream JavaDoc;
30 import java.io.InputStream JavaDoc;
31 import java.io.InputStreamReader JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 /**
35  * @author <a HREF="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
36  */

37
38 public class MTOMStAXSOAPModelBuilderTest extends AbstractTestCase {
39     MIMEHelper mimeHelper;
40     
41     String JavaDoc inFileName;
42     
43     OMXMLParserWrapper builder;
44     
45     /**
46      * @param testName
47      */

48     public MTOMStAXSOAPModelBuilderTest(String JavaDoc testName) {
49         super(testName);
50     }
51     
52     String JavaDoc contentTypeString = "multipart/Related; type=\"application/xop+xml\"; boundary=\"----=_AxIs2_Def_boundary_=42214532\"; start=\"<SOAPPart>\"";
53     
54     protected void setUp() throws Exception JavaDoc {
55         super.setUp();
56         inFileName = "mtom/MTOMBuilderTestIn.txt";
57         InputStream JavaDoc inStream = new FileInputStream JavaDoc(
58                 getTestResourceFile(inFileName));
59         mimeHelper = new MIMEHelper(inStream, contentTypeString);
60         XMLStreamReader reader = XMLInputFactory.newInstance()
61         .createXMLStreamReader(
62                 new BufferedReader JavaDoc(new InputStreamReader JavaDoc(mimeHelper
63                         .getSOAPPartInputStream())));
64         builder = new MTOMStAXSOAPModelBuilder(reader, mimeHelper);
65         
66     }
67     
68     public void testCreateOMElement() throws Exception JavaDoc {
69         OMElement root = (OMElement) builder.getDocumentElement();
70         System.out.println(root.getLocalName() + " : "
71                 + root.getNamespace().getName());
72         OMElement body = (OMElement) root.getFirstChild();
73         System.out.println(body.getLocalName() + " : "
74                 + body.getNamespace().getName());
75         
76         OMElement data = (OMElement) body.getFirstChild();
77         System.out.println(data.getLocalName() + " : "
78                 + data.getNamespace().getName());
79         Iterator JavaDoc childIt = data.getChildren();
80         //while (childIt.hasNext()) {
81
OMElement child = (OMElement) childIt.next();
82         OMText blob = (OMText) child.getFirstChild();
83         /*
84          * Following is the procedure the user has to follow to read objects in
85          * OBBlob User has to know the object type & whether it is serializable.
86          * If it is not he has to use a Custom Defined DataSource to get the
87          * Object.
88          */

89         byte[] expectedObject = new byte[] { 13, 56, 65, 32, 12, 12, 7, -3, -2,
90                 -1, 98 };
91         DataHandler JavaDoc actualDH;
92         actualDH = blob.getDataHandler();
93         //ByteArrayInputStream object = (ByteArrayInputStream) actualDH
94
//.getContent();
95
//byte[] actualObject= null;
96
// object.read(actualObject,0,10);
97

98         // assertEquals("Object check", expectedObject[5],actualObject[5] );
99
}
100     
101     public void testGetDataHandler() {
102     }
103     
104 }
Popular Tags