KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsdl > MessageReuseTest


1 /*
2  * Copyright 2001-2004 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
17 package org.apache.wsdl;
18
19 import org.apache.axis2.wsdl.WSDLVersionWrapper;
20 import org.apache.axis2.wsdl.builder.WOMBuilderFactory;
21 import org.apache.wsdl.extensions.ExtensionConstants;
22 import org.apache.wsdl.extensions.Schema;
23 import org.w3c.dom.Element JavaDoc;
24 import org.w3c.dom.Node JavaDoc;
25 import org.w3c.dom.NodeList JavaDoc;
26
27 import javax.wsdl.Definition;
28 import javax.xml.namespace.QName JavaDoc;
29 import java.io.FileInputStream JavaDoc;
30 import java.io.InputStream JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 /**
34  * @author chathura@opensource.lk
35  *
36  */

37 public class MessageReuseTest extends AbstractTestCase {
38
39     private WSDLDescription womDescription;
40
41     private Definition wsdl4jDefinition;
42
43     public MessageReuseTest(String JavaDoc arg) {
44         super(arg);
45     }
46
47     protected void setUp() throws Exception JavaDoc {
48
49         WSDLVersionWrapper wsdlVersionWrapper = null;
50         if (null == this.womDescription) {
51             InputStream JavaDoc in = new FileInputStream JavaDoc(getTestResourceFile("BookQuote.wsdl"));
52             wsdlVersionWrapper = WOMBuilderFactory.getBuilder(WOMBuilderFactory.WSDL11).build(in);
53             this.womDescription = wsdlVersionWrapper.getDescription();
54         }
55         if (null == wsdl4jDefinition) {
56             this.wsdl4jDefinition = wsdlVersionWrapper.getDefinition();
57         }
58
59     }
60
61     public void testMultipartmessageReuse() throws Exception JavaDoc {
62
63         WSDLInterface interface1 = this.womDescription.getInterface(
64                 new QName JavaDoc("http://www.Monson-Haefel.com/jwsbook/BookQuote",
65                         "BookQuote"));
66         WSDLOperation operation1 = (WSDLOperation) interface1.getAllOperations()
67                 .get("getBookPrice");
68         QName JavaDoc element1 = operation1.getInputMessage().getElement();
69         WSDLOperation operation2 = (WSDLOperation)interface1.getAllOperations().get("getBookPriceNonRobust");
70         QName JavaDoc element2 = operation2.getInputMessage().getElement();
71         assertEquals(element1, element2);
72         
73         Iterator JavaDoc iterator = womDescription.getTypes().getExtensibilityElements().iterator();
74         Schema types= null;
75         while(iterator.hasNext()){
76             WSDLExtensibilityElement temp = (WSDLExtensibilityElement)iterator.next();
77             if(ExtensionConstants.SCHEMA.equals(temp.getType())){
78                 types = (Schema)temp;
79             }
80         }
81         int numberOfBookQuote_getBookPrice = 0;
82         NodeList JavaDoc childNodes = types.getElelment().getChildNodes();
83         for(int i=0; i< childNodes.getLength(); i++){
84             Node JavaDoc item = childNodes.item(i);
85             if(item instanceof Element JavaDoc){
86                 Element JavaDoc temp = (Element JavaDoc)item;
87                 if("complexType".equals(temp.getNodeName()) &&
88                         "BookQuote_getBookPrice".equals(temp.getAttribute("name"))){
89                     numberOfBookQuote_getBookPrice++;
90                 }
91                 
92             }
93         }
94         assertEquals(numberOfBookQuote_getBookPrice, 1);
95         
96
97     }
98 }
Popular Tags