FileDocCategorySizeDatePackage
TestChainFault.javaAPI DocApache Axis 1.46916Sat Apr 22 18:57:28 BST 2006test.chains

TestChainFault

public class TestChainFault extends TestCase
Used to verify that Faults are processed properly in the Handler chain
author
Russell Butek (butek@us.ibm.com)
author
Chris Haddad

Fields Summary
public static String
FAULT_MESSAGE
Constructors Summary
public TestChainFault(String name)


        
        super(name);
    
Methods Summary
java.lang.StringgetFaultString(org.apache.axis.MessageContext msgContext)
Extract the fault string from the Soap Response

      String stRetval = null;
      Message message = msgContext.getResponseMessage();
      try {
          if (message != null) {
            SOAPBody oBody  = message.getSOAPEnvelope().getBody();
            stRetval = oBody.getFault().getFaultString();
          }
      }
      catch (javax.xml.soap.SOAPException e) {
          e.printStackTrace();
          assertTrue("Unforseen soap exception", false);
      }
      catch (AxisFault f) {
          f.printStackTrace();
          assertTrue("Unforseen axis fault", false);
      }

      return stRetval;
    
protected voidsetup()

    
public static junit.framework.Testsuite()

        return new TestSuite(TestChainFault.class);
    
public voidtestFaultDetailAvailableDuringInvoke()
Ensure that the fault detail is being passed back to handlers that executed prior to the fault

      // the handler instance to validate
      // NOTE:must execute before the handler that throws the fault
      TestHandler testHandler = null;

        try {
            SimpleChain c = new SimpleChain();

            for (int i = 0; i < 5; i++) {
                TestHandler th = new TestHandler(i);
                if (i == 2)
                  testHandler = th;

                if (i == 3) {
                    th.setToFault();
                }
                c.addHandler(th);
            }


            TestMessageContext mc = new TestMessageContext();
            try {
                c.invoke(mc);
                assertTrue("Testcase error - didn't throw fault", false);
            } catch (AxisFault f) {
                // did we save off the fault string?
              assertEquals("faultstring does not match constant",
                           TestChainFault.FAULT_MESSAGE,
                           testHandler.getFaultCatch());
                // does saved faultString match AxisFault?
              assertEquals("Fault not caught by handler",
                testHandler.getFaultCatch(),f.getFaultString());
            }

        } catch (Exception ex) {
            assertTrue("Unexpected exception", false);
        }
    
public voidtestSimpleChainFaultAfterInvoke()

        try {
            SimpleChain c = new SimpleChain();

            for (int i = 0; i < 5; i++) {
                c.addHandler(new TestHandler(i));
            }

            TestMessageContext mc = new TestMessageContext();
            c.invoke(mc);
            c.onFault(mc);
            assertEquals("Some onFaults were missed", mc.count(), 0);

        } catch (Exception ex) {
            assertTrue("Unexpected exception", false);
            ex.printStackTrace();
        }
    
public voidtestSimpleChainFaultDuringInvoke()

        try {
            SimpleChain c = new SimpleChain();

            for (int i = 0; i < 5; i++) {
                TestHandler th = new TestHandler(i);
                if (i == 3) {
                    th.setToFault();
                }
                c.addHandler(th);
            }


            TestMessageContext mc = new TestMessageContext();
            try {
                c.invoke(mc);
                assertTrue("Testcase error - didn't throw fault", false);
            } catch (AxisFault f) {
                assertEquals("Some onFaults were missed", mc.count(), 0);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
            assertTrue("Unexpected exception", false);
        }