1 57 58 package soap; 59 60 import junit.framework.Test; 61 import junit.framework.TestCase; 62 import junit.framework.TestSuite; 63 64 import org.apache.wsif.WSIFException; 65 import org.apache.wsif.WSIFMessage; 66 import org.apache.wsif.WSIFOperation; 67 import org.apache.wsif.WSIFPort; 68 import org.apache.wsif.WSIFService; 69 import org.apache.wsif.WSIFServiceFactory; 70 import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis; 71 import org.apache.wsif.util.WSIFPluggableProviders; 72 import util.TestUtilities; 73 74 import addressbook.wsiftypes.Address; 75 import addressbook.wsiftypes.Phone; 76 77 88 public class InputPartsTest extends TestCase { 89 static final String WSDL_LOCATION = 90 TestUtilities.getWsdlPath("java\\test\\addressbook\\wsifservice") + 91 "AddressBook.wsdl"; 92 static String server = TestUtilities.getSoapServer().toUpperCase(); 93 94 public InputPartsTest(String name) { 95 super(name); 96 } 97 98 public static void main(String [] args) 99 { 100 TestUtilities.startListeners( 101 TestUtilities.ADDRESSBOOK_LISTENER 102 | TestUtilities.NATIVEJMS_LISTENER); 103 104 junit.textui.TestRunner.run(suite()); 105 TestUtilities.stopListeners(); 106 } 107 108 public static Test suite() { 109 return new TestSuite(InputPartsTest.class); 110 } 111 112 public void setUp() { 113 TestUtilities.setUpExtensionsAndProviders(); 114 } 115 116 public void testSoap() { 117 doit(server+"Port", "soap"); 118 } 119 public void testJava() { 120 doit("JavaPort", "java"); 121 } 122 public void testSoapJms() { 123 doit("SOAPJMSPort", "soap"); 124 } 125 public void testNativeJms() { 133 doit("NativeJmsPort", "" ); 134 } 135 136 private void doit(String portName, String protocol) { 137 if (portName.toUpperCase().indexOf("JMS") != -1 && !TestUtilities.areWeTesting("jms")) 138 return; 139 140 TestUtilities.setProviderForProtocol( protocol ); 141 142 System.out.println( 143 "\n=== " + this.getClass().getName() + " " + portName + " " + protocol ); 144 145 try { 146 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 147 WSIFService service = factory.getService(WSDL_LOCATION, 148 null, null, "http://wsifservice.addressbook/", "AddressBook"); 153 service.mapType( 154 new javax.xml.namespace.QName ( 155 "http://wsiftypes.addressbook/", 156 "address"), 157 Class.forName("addressbook.wsiftypes.Address")); 158 159 service.mapType( 160 new javax.xml.namespace.QName ( 161 "http://wsiftypes.addressbook/", 162 "phone"), 163 Class.forName("addressbook.wsiftypes.Phone")); 164 165 WSIFPort port = service.getPort( portName ); 166 167 Address addr1 = new Address (1, "University Drive", 168 "West Lafayette", "IN", 47907, 169 new Phone (765, "494", "4900")); 170 Address addr2 = new Address (0, "Somewhere Else", 171 "No Where", "NO", 71983, 172 new Phone (600, "391", "5682")); 173 Address addr3 = new Address( 0,"","","",0, new Phone() ); 174 175 addName( port, "ant", addr1 ); 176 Address addressFound = getAddress( port, "ant" ); 177 assertTrue( "test 1 addresses are not equal!!", addressFound.equals( addr1 ) ); 178 179 addName( port, null, addr2 ); 180 addressFound = getAddress( port, null ); 181 assertTrue( "test 2 addresses are not equal!!", addressFound.equals( addr2 ) ); 182 183 addName( port, "petra", null ); 184 addressFound = getAddress( port, "petra" ); 185 188 } catch (Exception e) { 189 e.printStackTrace(); 190 assertTrue( "got exception: " + e, false); 191 } finally { 192 if (protocol.equals("axis")) { 193 WSIFPluggableProviders.overrideDefaultProvider( 194 "http://schemas.xmlsoap.org/wsdl/soap/", 195 null); 196 } 197 } 198 199 } 200 201 private void addName(WSIFPort port, String name, Address addr) 202 throws WSIFException { 203 204 WSIFOperation operation = 205 port.createOperation("addEntry", "AddEntryWholeNameRequest", null); 206 WSIFMessage inputMessage = operation.createInputMessage(); 207 WSIFMessage outputMessage = operation.createOutputMessage(); 208 WSIFMessage faultMessage = operation.createFaultMessage(); 209 210 if ( name != null ) { 211 inputMessage.setObjectPart( "name", name ); 212 } 213 if ( addr != null ) { 214 inputMessage.setObjectPart( "address", addr ); 215 } 216 inputMessage.setObjectPart( "extra", "junk" ); 217 218 boolean ok = operation.executeRequestResponseOperation( 219 inputMessage, 220 outputMessage, 221 faultMessage); 222 223 assertTrue( "addEntry operation returned false!!", ok ); 224 225 } 226 227 private Address getAddress(WSIFPort port, String name) 228 throws WSIFException { 229 230 WSIFOperation operation = port.createOperation("getAddressFromName"); 231 WSIFMessage inputMessage = operation.createInputMessage(); 232 WSIFMessage outputMessage = operation.createOutputMessage(); 233 WSIFMessage faultMessage = operation.createFaultMessage(); 234 235 if ( name != null ) { 236 inputMessage.setObjectPart( "name", name ); 237 } 238 inputMessage.setObjectPart( "extra", "junk" ); 239 240 boolean ok = operation.executeRequestResponseOperation( 241 inputMessage, 242 outputMessage, 243 faultMessage); 244 245 assertTrue( "getAddressFromName operation returned false!!", ok ); 246 247 return (Address) outputMessage.getObjectPart( "address" ); 248 249 } 250 251 } 252
| Popular Tags
|