KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > component > common > util > WSDLHelperTest


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: PetalsDispatcherTest.java 154 18 mai 2006 wjoseph $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.component.common.util;
23
24 import java.io.File JavaDoc;
25
26 import javax.xml.namespace.QName JavaDoc;
27
28 import junit.framework.TestCase;
29
30 import org.w3c.dom.Document JavaDoc;
31
32 import org.objectweb.petals.component.common.util.WSDLHelper;
33
34 /**
35  *
36  * @author wjoseph - EBM Websourcing
37  *
38  */

39 public class WSDLHelperTest extends TestCase {
40
41     File JavaDoc wsdlFile = null ;
42     @Override JavaDoc
43     protected void setUp() throws Exception JavaDoc {
44         wsdlFile = new File JavaDoc("src" + File.separator + "test-data" + File.separator +"test.wsdl");
45         if(!wsdlFile.exists()) {
46             wsdlFile = new File JavaDoc("common" + File.separator + "src" + File.separator + "test-data" + File.separator +"test.wsdl");
47             if(!wsdlFile.exists()) {
48                 wsdlFile = new File JavaDoc("components" + File.separator + "common" + File.separator + "src" + File.separator + "test-data" + File.separator +"test.wsdl");
49             }
50         }
51     }
52
53    public void testChangeServiceAddressInWSDL() {
54        /*
55         * Test Case 1
56         */

57        /*
58         * Create Test parameters
59         */

60        String JavaDoc prefix = "http://myhost.com:myport/myserver/myservices/";
61        QName JavaDoc serviceName = new QName JavaDoc("http://act.org/","EchoService");
62        Document JavaDoc serviceDesc = WSDLHelper.createDocumentFromWSDL(wsdlFile);
63        String JavaDoc oldAddress = null;
64        String JavaDoc newAddress = null;
65        try {
66        oldAddress = WSDLHelper.getServiceAddressFromWSDLDocument(serviceDesc, serviceName);
67        } catch (Exception JavaDoc e) {
68            e.printStackTrace();
69        }
70     
71        /*
72         * Run Test Case 1
73         */

74        try {
75            serviceDesc = WSDLHelper.changeServiceAddressInWSDL(serviceName, serviceDesc, prefix);
76        } catch (Exception JavaDoc e) {
77            e.printStackTrace();
78            fail("Error during invokation");
79        }
80        try {
81            newAddress = WSDLHelper.getServiceAddressFromWSDLDocument(serviceDesc, serviceName);
82            } catch (Exception JavaDoc e) {
83                e.printStackTrace();
84            }
85        assertNotSame(oldAddress, newAddress);
86        
87    }
88    
89    public void testGetPortNameFromWSDLDocument() {
90        /*
91         * Test Case 1
92         */

93        /*
94         * Create Test parameters
95         */

96        QName JavaDoc serviceName = new QName JavaDoc("http://act.org/","EchoService");
97        Document JavaDoc serviceDesc = WSDLHelper.createDocumentFromWSDL(wsdlFile);
98        String JavaDoc portName = null;
99        String JavaDoc port = "Echo";
100        /*
101         * Run Test Case 1
102         */

103        try {
104            portName = WSDLHelper.getPortNameFromWSDLDocument(serviceDesc, serviceName);
105        } catch (Exception JavaDoc e) {
106            e.printStackTrace();
107            fail("Error during invokation");
108        }
109        assertEquals(port, portName);
110    }
111    
112    public void testGetServiceNameFromWSDLFile() {
113        /*
114         * Test Case 1
115         */

116        /*
117         * Create Test parameters
118         */

119        QName JavaDoc serviceName = new QName JavaDoc("http://act.org/","EchoService");
120        QName JavaDoc service = null;
121        /*
122         * Run Test Case 1
123         */

124        try {
125            service = WSDLHelper.getServiceNameFromWSDLFile(wsdlFile)[0];
126        } catch (Exception JavaDoc e) {
127            e.printStackTrace();
128            fail("Error during invokation");
129        }
130        assertEquals(serviceName,service);
131    }
132    
133    public void testHasOperationNamed() {
134        /*
135         * Test Case 1
136         */

137        /*
138         * Create Test Parameters
139         */

140        QName JavaDoc serviceName = new QName JavaDoc("http://act.org/","EchoService");
141        Document JavaDoc serviceDesc = WSDLHelper.createDocumentFromWSDL(wsdlFile);
142        String JavaDoc op = "echoString";
143        boolean result = false;
144        /*
145         * Run Test Case 1
146         */

147        try {
148            result = WSDLHelper.hasOperationNamed(serviceDesc, op, serviceName);
149        } catch (Exception JavaDoc e) {
150            e.printStackTrace();
151            fail("Error during invokation");
152        }
153        assertTrue(result);
154        
155        /*
156         * Test Case 2
157         */

158        /*
159         * Create Test parameters
160         */

161        op = "fooOp";
162        /*
163         * Run test Case 2
164         */

165        try {
166            result = WSDLHelper.hasOperationNamed(serviceDesc, op, serviceName);
167        } catch (Exception JavaDoc e) {
168            e.printStackTrace();
169            fail("Error during invokation");
170        }
171        assertFalse(result);
172    }
173    
174    public void testIsInOutOperation() {
175        /*
176         * Test Case 1
177         */

178        /*
179         * Create Test Parameters
180         */

181        QName JavaDoc serviceName = new QName JavaDoc("http://act.org/","EchoService");
182        Document JavaDoc serviceDesc = WSDLHelper.createDocumentFromWSDL(wsdlFile);
183        String JavaDoc op = "echoString";
184        boolean result = false;
185        /*
186         * Run Test Case 1
187         */

188        try {
189            result = WSDLHelper.isInOutOperation(serviceDesc, op, serviceName);
190        } catch (Exception JavaDoc e) {
191            e.printStackTrace();
192            fail("Error during invokation");
193        }
194        assertTrue(result);
195        
196        /*
197         * Test Case 2
198         */

199        /*
200         * Create Test parameters
201         */

202        op = "fooOp";
203        /*
204         * Run test Case 2
205         */

206        try {
207            result = WSDLHelper.isInOutOperation(serviceDesc, op, serviceName);
208        } catch (Exception JavaDoc e) {
209            e.printStackTrace();
210            fail("Error during invokation");
211        }
212        assertFalse(result);
213    }
214    
215    public void testGetTargetNSFromWSDLDocument() {
216        /*
217         * Test Case 1
218         */

219        /*
220         * Create Test parameters
221         */

222        Document JavaDoc serviceDesc = WSDLHelper.createDocumentFromWSDL(wsdlFile);
223        String JavaDoc namespace = "http://act.org/";
224        String JavaDoc nameSpace = null;
225        /*
226         * Run test Case 1
227         */

228        try {
229             nameSpace = WSDLHelper.getTargetNSFromWSDLDocument(serviceDesc);
230        } catch (Exception JavaDoc e) {
231            e.printStackTrace();
232            fail("Error during invokation");
233        }
234        assertEquals(namespace, nameSpace);
235    }
236 }
237
Popular Tags