1 57 58 package faults; 59 60 import javax.wsdl.Definition; 61 import javax.wsdl.PortType; 62 import javax.wsdl.Service; 63 import junit.framework.Test; 64 import junit.framework.TestCase; 65 import junit.framework.TestSuite; 66 67 import org.apache.wsif.WSIFConstants; 68 import org.apache.wsif.WSIFMessage; 69 import org.apache.wsif.WSIFOperation; 70 import org.apache.wsif.WSIFPort; 71 import org.apache.wsif.WSIFService; 72 import org.apache.wsif.WSIFServiceFactory; 73 import org.apache.wsif.util.WSIFUtils; 74 import util.TestUtilities; 75 76 80 public class FaultMsgTest extends TestCase { 81 String wsdlLocation = 82 TestUtilities.getWsdlPath("java\\test\\faults") + "Stockquote.wsdl"; 83 static String server = TestUtilities.getSoapServer().toUpperCase(); 84 85 public FaultMsgTest(String name) { 86 super(name); 87 } 88 89 public static void main(String [] args) { 90 TestUtilities.startListeners(TestUtilities.STOCKQUOTE_LISTENER); 91 junit.textui.TestRunner.run (suite()); 92 TestUtilities.stopListeners(); 93 } 94 95 public static Test suite() { 96 return new TestSuite(FaultMsgTest.class); 97 } 98 99 public void setUp() { 100 TestUtilities.setUpExtensionsAndProviders(); 101 } 102 103 public void testAxis() { 105 doit(server+"Port", "axis"); 106 } 107 public void testSoap() { 108 doit(server+"Port", "soap"); 109 } 110 public void testSoapJms() { 111 if (TestUtilities.areWeTesting("jms")) 112 doit("SOAPJMSPort", "soap"); 113 } 114 public void testAxisJms() { 115 if (TestUtilities.areWeTesting("jms")) 116 doit("SOAPJMSPort", "axis"); 117 } 118 119 private void doit(String portName, String protocol) { 120 121 try { 122 invokeMethod( 123 wsdlLocation, 124 "getQuote", 125 null, 126 null, 127 portName, 128 protocol, 129 new String [] { "" }, 130 0); 131 } catch (Exception e) { 132 System.err.println("AsyncTest(" + portName + ") caught exception " + e); 133 e.printStackTrace(); 134 assertTrue(false); 135 } finally { 136 } 137 138 } 139 140 public static void invokeMethod( 141 String wsdlLocation, 142 String operationName, 143 String inputName, 144 String outputName, 145 String portName, 146 String protocol, 147 String [] args, 148 int argShift) 149 throws Exception { 150 151 String serviceNS = null; 152 String serviceName = null; 153 String portTypeNS = null; 154 String portTypeName = null; 155 156 TestUtilities.setProviderForProtocol( protocol ); 157 158 try { 159 System.out.println("Reading WSDL document from '" + wsdlLocation + "'"); 160 Definition def = WSIFUtils.readWSDL(null, wsdlLocation); 161 162 Service service = WSIFUtils.selectService(def, serviceNS, serviceName); 163 PortType portType = WSIFUtils.selectPortType(def, portTypeNS, portTypeName); 164 165 WSIFServiceFactory factory = WSIFServiceFactory.newInstance(); 166 WSIFService dpf = factory.getService(def, service, portType); 167 WSIFPort port = (portName == null) ? dpf.getPort() : dpf.getPort(portName); 168 169 WSIFOperation op1 = port.createOperation("getQuote", inputName, outputName); 171 WSIFMessage input1 = op1.createInputMessage(); 172 WSIFMessage output1 = op1.createOutputMessage(); 173 WSIFMessage fault1 = op1.createFaultMessage(); 174 input1.setObjectPart("symbol", ""); 175 boolean ok = op1.executeRequestResponseOperation(input1, output1, fault1); 176 177 assertEquals("ok getQuote response", true, ok); 178 float q1 = ((Float ) output1.getObjectPart("quote")).floatValue(); 179 assertEquals("getQuote value", -1.0F, q1, 0F); 180 181 op1 = port.createOperation("XXXgetQuote", inputName, outputName); 183 input1 = op1.createInputMessage(); 184 output1 = op1.createOutputMessage(); 185 fault1 = op1.createFaultMessage(); 186 input1.setObjectPart("symbol", ""); 187 ok = op1.executeRequestResponseOperation(input1, output1, fault1); 188 189 assertEquals("ok getQuote response", false, ok); 190 String name = fault1.getName(); 191 Object fobject = fault1.getObjectPart(WSIFConstants.SOAP_FAULT_OBJECT); 192 193 assertEquals("fault message name", WSIFConstants.SOAP_FAULT_MSG_NAME, name); 194 if ("axis".equals(protocol)) { 195 assertTrue("fault obj type", fobject instanceof org.apache.axis.AxisFault); 196 } else { 198 assertTrue("fault obj type", fobject instanceof org.apache.soap.Fault); 199 } 201 202 205 } catch (Exception ex) { 206 ex.printStackTrace(); 207 assertTrue(false); 208 } finally { 209 TestUtilities.resetDefaultProviders(); 210 } 211 212 } 213 } 214 | Popular Tags |