1 22 package org.objectweb.petals.component.common.util; 23 24 import java.io.File ; 25 26 import javax.xml.namespace.QName ; 27 28 import junit.framework.TestCase; 29 30 import org.w3c.dom.Document ; 31 32 import org.objectweb.petals.component.common.util.WSDLHelper; 33 34 39 public class WSDLHelperTest extends TestCase { 40 41 File wsdlFile = null ; 42 @Override 43 protected void setUp() throws Exception { 44 wsdlFile = new File ("src" + File.separator + "test-data" + File.separator +"test.wsdl"); 45 if(!wsdlFile.exists()) { 46 wsdlFile = new File ("common" + File.separator + "src" + File.separator + "test-data" + File.separator +"test.wsdl"); 47 if(!wsdlFile.exists()) { 48 wsdlFile = new File ("components" + File.separator + "common" + File.separator + "src" + File.separator + "test-data" + File.separator +"test.wsdl"); 49 } 50 } 51 } 52 53 public void testChangeServiceAddressInWSDL() { 54 57 60 String prefix = "http://myhost.com:myport/myserver/myservices/"; 61 QName serviceName = new QName ("http://act.org/","EchoService"); 62 Document serviceDesc = WSDLHelper.createDocumentFromWSDL(wsdlFile); 63 String oldAddress = null; 64 String newAddress = null; 65 try { 66 oldAddress = WSDLHelper.getServiceAddressFromWSDLDocument(serviceDesc, serviceName); 67 } catch (Exception e) { 68 e.printStackTrace(); 69 } 70 71 74 try { 75 serviceDesc = WSDLHelper.changeServiceAddressInWSDL(serviceName, serviceDesc, prefix); 76 } catch (Exception e) { 77 e.printStackTrace(); 78 fail("Error during invokation"); 79 } 80 try { 81 newAddress = WSDLHelper.getServiceAddressFromWSDLDocument(serviceDesc, serviceName); 82 } catch (Exception e) { 83 e.printStackTrace(); 84 } 85 assertNotSame(oldAddress, newAddress); 86 87 } 88 89 public void testGetPortNameFromWSDLDocument() { 90 93 96 QName serviceName = new QName ("http://act.org/","EchoService"); 97 Document serviceDesc = WSDLHelper.createDocumentFromWSDL(wsdlFile); 98 String portName = null; 99 String port = "Echo"; 100 103 try { 104 portName = WSDLHelper.getPortNameFromWSDLDocument(serviceDesc, serviceName); 105 } catch (Exception e) { 106 e.printStackTrace(); 107 fail("Error during invokation"); 108 } 109 assertEquals(port, portName); 110 } 111 112 public void testGetServiceNameFromWSDLFile() { 113 116 119 QName serviceName = new QName ("http://act.org/","EchoService"); 120 QName service = null; 121 124 try { 125 service = WSDLHelper.getServiceNameFromWSDLFile(wsdlFile)[0]; 126 } catch (Exception e) { 127 e.printStackTrace(); 128 fail("Error during invokation"); 129 } 130 assertEquals(serviceName,service); 131 } 132 133 public void testHasOperationNamed() { 134 137 140 QName serviceName = new QName ("http://act.org/","EchoService"); 141 Document serviceDesc = WSDLHelper.createDocumentFromWSDL(wsdlFile); 142 String op = "echoString"; 143 boolean result = false; 144 147 try { 148 result = WSDLHelper.hasOperationNamed(serviceDesc, op, serviceName); 149 } catch (Exception e) { 150 e.printStackTrace(); 151 fail("Error during invokation"); 152 } 153 assertTrue(result); 154 155 158 161 op = "fooOp"; 162 165 try { 166 result = WSDLHelper.hasOperationNamed(serviceDesc, op, serviceName); 167 } catch (Exception e) { 168 e.printStackTrace(); 169 fail("Error during invokation"); 170 } 171 assertFalse(result); 172 } 173 174 public void testIsInOutOperation() { 175 178 181 QName serviceName = new QName ("http://act.org/","EchoService"); 182 Document serviceDesc = WSDLHelper.createDocumentFromWSDL(wsdlFile); 183 String op = "echoString"; 184 boolean result = false; 185 188 try { 189 result = WSDLHelper.isInOutOperation(serviceDesc, op, serviceName); 190 } catch (Exception e) { 191 e.printStackTrace(); 192 fail("Error during invokation"); 193 } 194 assertTrue(result); 195 196 199 202 op = "fooOp"; 203 206 try { 207 result = WSDLHelper.isInOutOperation(serviceDesc, op, serviceName); 208 } catch (Exception e) { 209 e.printStackTrace(); 210 fail("Error during invokation"); 211 } 212 assertFalse(result); 213 } 214 215 public void testGetTargetNSFromWSDLDocument() { 216 219 222 Document serviceDesc = WSDLHelper.createDocumentFromWSDL(wsdlFile); 223 String namespace = "http://act.org/"; 224 String nameSpace = null; 225 228 try { 229 nameSpace = WSDLHelper.getTargetNSFromWSDLDocument(serviceDesc); 230 } catch (Exception e) { 231 e.printStackTrace(); 232 fail("Error during invokation"); 233 } 234 assertEquals(namespace, nameSpace); 235 } 236 } 237 | Popular Tags |