axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ru...@apache.org
Subject cvs commit: xml-axis/java/test/faults FaultEncode.java PackageTests.java
Date Wed, 28 Nov 2001 12:04:12 GMT
rubys       01/11/28 04:04:12

  Modified:    java/src/org/apache/axis/encoding SerializationContext.java
               java/test/RPCDispatch Service.java TestRPC.java
               java/test/faults PackageTests.java
  Added:       java/test/faults FaultEncode.java
  Log:
  Fix encoding of Fault detail elements
  
  Revision  Changes    Path
  1.62      +1 -1      xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java
  
  Index: SerializationContext.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- SerializationContext.java	2001/11/27 03:35:02	1.61
  +++ SerializationContext.java	2001/11/28 12:04:12	1.62
  @@ -630,7 +630,7 @@
               if (child instanceof Element) {
                   writeDOMElement((Element)child);
               } else if (child instanceof Text) {
  -                writeString(((Text)child).getData());
  +                writeSafeString(((Text)child).getData());
               }
           }
   
  
  
  
  1.8       +20 -0     xml-axis/java/test/RPCDispatch/Service.java
  
  Index: Service.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/RPCDispatch/Service.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Service.java	2001/11/02 03:07:42	1.7
  +++ Service.java	2001/11/28 12:04:12	1.8
  @@ -65,4 +65,24 @@
       public Integer echoInt(Integer value) throws Exception {
          return value;
       }
  +
  +    /**
  +     * Simple exception to be used in generating faults
  +     */
  +    class TestFault extends Exception {
  +        TestFault(String msg) throws Exception {
  +            super(msg);
  +            if (msg == null) throw new Exception("default value");
  +        }
  +    }
  +
  +    /**
  +     * Simple fault.
  +     */
  +    public String simpleFault(String value) throws Exception {
  +       TestFault fault = new TestFault(value);
  +       throw fault;
  +    }
  +
  +
   }
  
  
  
  1.28      +21 -0     xml-axis/java/test/RPCDispatch/TestRPC.java
  
  Index: TestRPC.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/RPCDispatch/TestRPC.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- TestRPC.java	2001/11/13 00:21:03	1.27
  +++ TestRPC.java	2001/11/28 12:04:12	1.28
  @@ -14,6 +14,9 @@
   
   import org.xml.sax.SAXException;
   
  +import org.w3c.dom.Element;
  +import org.w3c.dom.Text;
  +
   import java.util.Vector;
   
   /**
  @@ -159,6 +162,24 @@
           assertNull("The result was not null as expected.", rpc("echoInt", new Object[]
{null}));
       }
       
  +    /**
  +     * Test faults
  +     */
  +    public void testSimpleFault() throws Exception {
  +        // Register the reverseData service
  +        SOAPService simpleFault = new SOAPService(RPCDispatcher);
  +        simpleFault.setOption("className", "test.RPCDispatch.Service");
  +        simpleFault.setOption("methodName", "simpleFault");
  +        engine.deployService(SOAPAction, simpleFault);
  +
  +        Object result = rpc("simpleFault", new Object[] {"foobar"});
  +        assertTrue("Did not get a fault as expected.", 
  +           result instanceof AxisFault);
  +        AxisFault fault = (AxisFault) result;
  +        assertEquals("faultString was not set correctly.", 
  +            "foobar", fault.getFaultString());
  +    }
  +
       public static void main(String args[])
       {
         try {
  
  
  
  1.2       +1 -0      xml-axis/java/test/faults/PackageTests.java
  
  Index: PackageTests.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/faults/PackageTests.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PackageTests.java	2001/11/07 19:20:48	1.1
  +++ PackageTests.java	2001/11/28 12:04:12	1.2
  @@ -74,6 +74,7 @@
           TestSuite suite = new TestSuite();
   
           suite.addTestSuite(FaultDecode.class);
  +        suite.addTestSuite(FaultEncode.class);
   
           return suite;
       }
  
  
  
  1.1                  xml-axis/java/test/faults/FaultEncode.java
  
  Index: FaultEncode.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package test.faults;
  
  import junit.framework.TestCase;
  import junit.framework.TestResult;
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  import org.apache.axis.AxisFault;
  import org.apache.axis.Message;
  import org.apache.axis.MessageContext;
  import org.apache.axis.utils.QFault;
  import org.apache.axis.message.SOAPBodyElement;
  import org.apache.axis.message.SOAPEnvelope;
  import org.apache.axis.message.SOAPFaultElement;
  import org.apache.axis.server.AxisServer;
  import org.w3c.dom.Element;
  import org.w3c.dom.Text;
  
  /**
   * This class tests Fault deserialization.
   *
   * @author Sam Ruby (rubys@us.ibm.com)
   */
  
  public class FaultEncode extends TestCase {
      
      public FaultEncode(String name) {
          super(name);
      } // ctor
      
      public void testFault() throws Exception {
          AxisFault fault = new AxisFault();
          fault.setFaultCode("<code>");
          fault.setFaultString("<string>");
          fault.setFaultActor("<actor>");
          fault.setFaultDetailString("<detail>");
  
          AxisServer server = new AxisServer();
          Message message = new Message(fault);
          message.setMessageContext(new MessageContext(server));
  
          String data = message.getSOAPPart().getAsString();
          assertTrue("Fault code not encoded correctly",
              data.indexOf("&lt;code&gt;")>=0);
          assertTrue("Fault string not encoded correctly",
              data.indexOf("&lt;string&gt;")>=0);
          assertTrue("Fault actor not encoded correctly",
              data.indexOf("&lt;actor&gt;")>=0);
          assertTrue("Fault detail not encoded correctly",
              data.indexOf("&lt;detail&gt;")>=0);
          
      } // testFault
  }
  
  
  

Mime
View raw message