KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > om > factory > OMLinkedListImplFactoryTest


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
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  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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  */

16 package org.apache.axis2.om.factory;
17
18 import org.apache.axis2.om.*;
19 import org.apache.axis2.soap.*;
20 import org.apache.axis2.soap.impl.llom.SOAPConstants;
21 import org.apache.axis2.soap.impl.llom.soap11.SOAP11Constants;
22
23 /**
24  * User: Eran Chinthaka (eran.chinthaka@gmail.com)
25  * Date: Feb 8, 2005
26  * Time: 11:06:09 AM
27  * All Rights Reserved.
28  */

29 public class OMLinkedListImplFactoryTest extends AbstractTestCase {
30     public OMLinkedListImplFactoryTest(String JavaDoc testName) {
31         super(testName);
32     }
33
34    SOAPFactory omFactory;
35     OMNamespace namespace;
36     String JavaDoc nsUri = "http://www.apache.org/~chinthaka";
37     String JavaDoc nsPrefix = "myhome";
38
39     protected void setUp() throws Exception JavaDoc {
40         super.setUp();
41         omFactory = OMAbstractFactory.getSOAP11Factory();
42         namespace = omFactory.createOMNamespace(nsUri, nsPrefix);
43     }
44
45     public void testCreateOMElementWithNoBuilder() {
46         OMElement omElement = omFactory.createOMElement("chinthaka", namespace);
47         assertTrue("Programatically created OMElement should have done = true ", omElement.isComplete());
48
49     }
50
51     public void testCreateOMElement() {
52         try {
53             OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(getTestResourceFile("soap/whitespacedMessage.xml"));
54             OMElement documentElement = omBuilder.getDocumentElement();
55             OMElement child = omFactory.createOMElement("child", namespace, documentElement, omBuilder);
56             assertTrue("OMElement with a builder should start with done = false ", !child.isComplete());
57             assertTrue("This OMElement must have a builder ", child.getBuilder() instanceof OMXMLParserWrapper);
58
59         } catch (Exception JavaDoc e) {
60             e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
61
}
62     }
63
64     public void testCreateOMNamespace() {
65         assertTrue("OMNamespace uri not correct", nsUri.equals(namespace.getName())); // here equalsIgnoreCase should not be used as case does matter
66
assertTrue("OMNamespace prefix not correct", nsPrefix.equals(namespace.getPrefix())); // here equalsIgnoreCase should not be used as case does matter
67
}
68
69     public void testCreateText() {
70         OMElement omElement = omFactory.createOMElement("chinthaka", namespace);
71         String JavaDoc text = "sampleText";
72         OMText omText = omFactory.createText(omElement, text);
73         assertTrue("Programatically created OMText should have done = true ", omText.isComplete());
74         assertTrue("Programatically created OMText should have correct text value ", text.equals(omText.getText()));
75
76     }
77
78     public void testCreateSOAPBody() {
79         try {
80             OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(getTestResourceFile("soap/minimalMessage.xml"));
81             SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
82             SOAPBody soapBodyOne = omFactory.createSOAPBody(soapEnvelope);
83             assertTrue("Programatically created SOAPBody should have done = true ", soapBodyOne.isComplete());
84             soapBodyOne.detach();
85             SOAPBody soapBodyTwo = omFactory.createSOAPBody(soapEnvelope, omBuilder);
86             assertTrue("SOAPBody with a builder should start with done = false ", !soapBodyTwo.isComplete());
87             assertTrue("This SOAPBody must have a builder ", soapBodyTwo.getBuilder() instanceof OMXMLParserWrapper);
88
89
90         } catch (Exception JavaDoc e) {
91             e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
92
}
93     }
94
95     public void testCreateSOAPEnvelope() {
96         try {
97             OMNamespace soapNamespace = omFactory.createOMNamespace(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI, SOAPConstants.SOAP_DEFAULT_NAMESPACE_PREFIX);
98             SOAPEnvelope soapEnvelopeTwo = omFactory.createSOAPEnvelope();
99             assertTrue("Programatically created SOAPEnvelope should have done = true ", soapEnvelopeTwo.isComplete());
100             SOAPEnvelope soapEnvelope = omFactory.createSOAPEnvelope(OMTestUtils.getOMBuilder(getTestResourceFile("soap/minimalMessage.xml")));
101             assertTrue("SOAPEnvelope with a builder should start with done = false ", !soapEnvelope.isComplete());
102             assertTrue("This SOAPEnvelope must have a builder ", soapEnvelope.getBuilder() instanceof OMXMLParserWrapper);
103
104
105         } catch (Exception JavaDoc e) {
106             e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
107
}
108     }
109
110     public void testCreateSOAPHeader() {
111         try {
112             OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(getTestResourceFile("soap/minimalMessage.xml"));
113             SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
114             SOAPHeader soapHeader = omFactory.createSOAPHeader(soapEnvelope);
115             assertTrue("Programatically created SOAPHeader should have done = true ", soapHeader.isComplete());
116             soapHeader.detach();
117             SOAPHeader soapHeaderTwo = omFactory.createSOAPHeader(soapEnvelope, omBuilder);
118             assertTrue("SOAPHeader with a builder should start with done = false ", !soapHeaderTwo.isComplete());
119             assertTrue("This SOAPHeader must have a builder ", soapHeaderTwo.getBuilder() instanceof OMXMLParserWrapper);
120
121
122         } catch (Exception JavaDoc e) {
123             e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
124
}
125     }
126
127     public void testCreateSOAPHeaderBlock() {
128         try {
129             OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(getTestResourceFile("soap/soapmessage.xml"));
130             SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
131             SOAPHeader soapHeader = soapEnvelope.getHeader();
132             SOAPHeaderBlock soapHeaderBlock = omFactory.createSOAPHeaderBlock("soapHeaderBlockOne", namespace, soapHeader);
133             assertTrue("Programatically created SOAPHeaderBlock should have done = true ", soapHeaderBlock.isComplete());
134             SOAPHeaderBlock soapHeaderBlockTwo = omFactory.createSOAPHeaderBlock("soapHeaderBlockOne", namespace, soapHeader, omBuilder);
135             assertTrue("SOAPHeaderBlock with a builder should start with done = false ", !soapHeaderBlockTwo.isComplete());
136             assertTrue("This SOAPHeaderBlock must have a builder ", soapHeaderBlockTwo.getBuilder() instanceof OMXMLParserWrapper);
137
138
139         } catch (Exception JavaDoc e) {
140             e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
141
}
142     }
143
144     public void testCreateSOAPFault() {
145         try {
146             OMXMLParserWrapper omBuilder = OMTestUtils.getOMBuilder(getTestResourceFile("soap/soapmessage.xml"));
147             SOAPEnvelope soapEnvelope = (SOAPEnvelope) omBuilder.getDocumentElement();
148             SOAPBody soapBody = soapEnvelope.getBody();
149             SOAPFault soapFault = omFactory.createSOAPFault(soapBody, new Exception JavaDoc(" this is just a test "));
150             assertTrue("Programatically created SOAPFault should have done = true ", soapFault.isComplete());
151             soapFault.detach();
152             SOAPFault soapFaultTwo = omFactory.createSOAPFault(soapBody, omBuilder);
153             assertTrue("SOAPFault with a builder should start with done = false ", !soapFaultTwo.isComplete());
154             assertTrue("This SOAPFault must have a builder ", soapFaultTwo.getBuilder() instanceof OMXMLParserWrapper);
155
156
157         } catch (Exception JavaDoc e) {
158             e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
159
}
160     }
161
162
163 }
164
Popular Tags