You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by to...@apache.org on 2002/05/09 22:17:58 UTC

cvs commit: xml-axis/java/test/wsdl/qualify Qualify_ServiceTestCase.java Qualify_BindingImpl.java

tomj        02/05/09 13:17:57

  Modified:    java/test/wsdl/qualify Qualify_ServiceTestCase.java
                        Qualify_BindingImpl.java
  Log:
  Update to Qualify test cases to do more validation.
  There are still some bugs in the way I check the DOM, so there is work left to do
  on these.
  
  Revision  Changes    Path
  1.2       +179 -25   xml-axis/java/test/wsdl/qualify/Qualify_ServiceTestCase.java
  
  Index: Qualify_ServiceTestCase.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/qualify/Qualify_ServiceTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Qualify_ServiceTestCase.java	6 Apr 2002 01:46:04 -0000	1.1
  +++ Qualify_ServiceTestCase.java	9 May 2002 20:17:57 -0000	1.2
  @@ -1,3 +1,57 @@
  +/*
  + * 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/>.
  + */
   /**
    * Qualify_ServiceTestCase.java
    *
  @@ -7,62 +61,162 @@
   
   package test.wsdl.qualify;
   
  +import junit.framework.AssertionFailedError;
  +import org.apache.axis.Message;
  +import org.apache.axis.MessageContext;
  +import org.apache.axis.utils.XMLUtils;
  +import org.apache.axis.message.SOAPEnvelope;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.Node;
  +import org.w3c.dom.Document;
  +import org.w3c.dom.NodeList;
  +import org.xml.sax.InputSource;
  +
  +import javax.xml.rpc.ServiceException;
  +import java.io.InputStream;
  +import java.io.IOException;
  +import java.io.Reader;
  +import java.io.StringReader;
  +
   public class Qualify_ServiceTestCase extends junit.framework.TestCase {
  +
  +    public static final String namespace = "urn:qualifyTest";
  +
       public Qualify_ServiceTestCase(String name) {
           super(name);
       }
  +
       public void test1QualifySimple() {
  -        test.wsdl.qualify.Qualify_Binding binding;
  +        Qualify_ServiceLocator locator = new Qualify_ServiceLocator();
  +        Qualify_Binding binding;
           try {
  -            binding = new test.wsdl.qualify.Qualify_ServiceLocator().getQualify();
  -        }
  -        catch (javax.xml.rpc.ServiceException jre) {
  -            throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
  +            binding = locator.getQualify();
  +        } catch (javax.xml.rpc.ServiceException jre) {
  +            throw new AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
           }
           assertTrue("binding is null", binding != null);
   
           try {
  -            java.lang.String value = null;
  -            java.lang.String name = "Tommy";
  +            String value = null;
  +            String name = "Tommy";
               value = binding.simple(name);
  -            
  -            // Get the XML response
  +
               // Validate XML reponse to make sure elements are properly qualified
               // or not per the WSDL
  -            // FIXME
  +            MessageContext mc = null;
  +            try {
  +                mc = locator.getCall().getMessageContext();
  +            } catch (ServiceException e) {
  +                throw new AssertionFailedError("Unable to get call object from service");
  +            }
  +            Message response = mc.getResponseMessage();
  +            SOAPEnvelope env = response.getSOAPPart().getAsSOAPEnvelope();
  +            String responseString = response.getSOAPPart().getAsString();
  +
  +            Element body;
  +            try {
  +                body = env.getFirstBody().getAsDOM();
  +            } catch (Exception e) {
  +                throw new AssertionFailedError("Unable to get request body as DOM Element on server");
  +            }
  +
  +            // debug
  +            //System.err.println("Response:\n---------\n" + responseString + "\n------");
  +
  +            /*
  +             * Here is what we expect the Body to look like:
  +             * <SimpleResponse xmlns="urn:qualifyTest">
  +             *   <SimpleResult>Hello there: Tommy</SimpleResult>
  +             * </SimpleResponse>
  +             */
  +
  +            // Now we have a DOM Element, verfy namespace attributes
  +            String simpleNS = body.getNamespaceURI();
  +            assertEquals("Namespace of Simple element incorrect", simpleNS, namespace);
  +
  +            Node nameNode = body.getFirstChild();
  +            String nameNS = nameNode.getNamespaceURI();
  +            assertNull("Namespace of name element incorrect", nameNS);
               
               // Check the response
  -            junit.framework.Assert.assertEquals(value, "Hello there: " + name);
  -        }
  -        catch (java.rmi.RemoteException re) {
  -            throw new junit.framework.AssertionFailedError("Remote Exception caught: " + re);
  +            assertEquals(value, "Hello there: " + name);
  +
  +        } catch (java.rmi.RemoteException re) {
  +            throw new AssertionFailedError("Remote Exception caught: " + re);
           }
       }
   
       public void test2QualifyFormOverride() {
  +        Qualify_ServiceLocator locator = new Qualify_ServiceLocator();
           test.wsdl.qualify.Qualify_Binding binding;
           try {
  -            binding = new test.wsdl.qualify.Qualify_ServiceLocator().getQualify();
  -        }
  -        catch (javax.xml.rpc.ServiceException jre) {
  -            throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
  +            binding = locator.getQualify();
  +        } catch (javax.xml.rpc.ServiceException jre) {
  +            throw new AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
           }
           assertTrue("binding is null", binding != null);
   
           try {
  -            test.wsdl.qualify.Response value = null;
  -            value = binding.formOverride(new test.wsdl.qualify.Complex());
  +            Response value = null;
  +            Complex arg = new Complex();
  +            arg.setName("Timmah");
  +            value = binding.formOverride(arg);
               
               // Get the XML response
               // Validate XML reponse to make sure elements are properly qualified
               // or not per the WSDL
  -            // FIXME
  +            MessageContext mc = null;
  +            try {
  +                mc = locator.getCall().getMessageContext();
  +            } catch (ServiceException e) {
  +                throw new AssertionFailedError("Unable to get call object from service");
  +            }
  +            Message response = mc.getResponseMessage();
  +            SOAPEnvelope env = response.getSOAPPart().getAsSOAPEnvelope();
  +            String responseString = response.getSOAPPart().getAsString();
  +
  +            Element body;
  +            try {
  +                body = env.getFirstBody().getAsDOM();
  +            } catch (Exception e) {
  +                throw new AssertionFailedError("Unable to get request body as DOM Element on server");
  +            }
  +
  +            // debug
  +            //System.err.println("Response:\n---------\n" + responseString + "\n------");
  +
  +            /*
  +             * Here is what we expect the Body to look like:
  +             * <FormOverrideResponse xmlns="urn:qualifyTest">
  +             *  <response xmlns="">
  +             *   <ns1:name xmlns:ns1="urn:qualifyTest">Tommy</ns1:name>
  +             *  </response>
  +             * </FormOverrideResponse>
  +             */
  +
  +            // Now we have a DOM Element, verfy namespace attributes
  +            String FormOverrideNS = body.getNamespaceURI();
  +            assertEquals("Namespace of <FormOverrideResponse> element incorrect",
  +                         FormOverrideNS, namespace);
  +
  +            Node complexNode = body.getFirstChild();
  +            String complexNS = complexNode.getNamespaceURI();
  +            assertNull("Namespace of <complex> element incorrect", complexNS);
               
  +            // FIXME: for some reason I can't get at the <name> node which is
  +            // under the <complex> node.  Are we not converting the request to
  +            // DOM correctly?
  +            if (complexNode.hasChildNodes()) {
  +                Node nameNode = complexNode.getFirstChild();
  +                String nameNS = nameNode.getNamespaceURI();
  +                assertEquals("Namespace of <name> element incorrect", 
  +                             nameNS, namespace);
  +            }
  +
               // Check the response
  -            junit.framework.Assert.assertEquals(value.getName(), "Tommy");
  -        }
  -        catch (java.rmi.RemoteException re) {
  -            throw new junit.framework.AssertionFailedError("Remote Exception caught: " + re);
  +            assertEquals(value.getName(), "Tommy");
  +        } catch (java.rmi.RemoteException re) {
  +            throw new AssertionFailedError("Remote Exception caught: " + re);
           }
       }
   
  
  
  
  1.2       +155 -7    xml-axis/java/test/wsdl/qualify/Qualify_BindingImpl.java
  
  Index: Qualify_BindingImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/qualify/Qualify_BindingImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Qualify_BindingImpl.java	6 Apr 2002 01:46:04 -0000	1.1
  +++ Qualify_BindingImpl.java	9 May 2002 20:17:57 -0000	1.2
  @@ -1,19 +1,120 @@
  +/*
  + * 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/>.
  + */
  +
  +
   /**
    * Qualify_BindingImpl.java
    *
  - * This file was auto-generated from WSDL
  - * by the Apache Axis Wsdl2java emitter.
  + * Service implementation for Qualified/Nonqualified elements in a complex
  + * type.  The service validates the request XML and the test client validates
  + * the response XML to verify the elements that should be namesapce qualified
  + * are, and those that are not supposed to be aren't.
    */
   
   package test.wsdl.qualify;
   
  +import org.apache.axis.MessageContext;
  +import org.apache.axis.Message;
  +import org.apache.axis.AxisFault;
  +import org.apache.axis.message.SOAPEnvelope;
  +import org.apache.axis.message.RPCElement;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.Node;
  +
   public class Qualify_BindingImpl implements test.wsdl.qualify.Qualify_Binding {
  +    
  +    public static final String namespace = "urn:qualifyTest";
  +    
       public java.lang.String simple(java.lang.String name) throws java.rmi.RemoteException {
           // Validate XML request to make sure elements are properly qualified
           // or not per the WSDL
  -        
  -        // FIXME
  -        
  +        MessageContext mc = MessageContext.getCurrentContext();
  +        Message request = mc.getRequestMessage();
  +        SOAPEnvelope env = request.getSOAPPart().getAsSOAPEnvelope();
  +        String requestString = request.getSOAPPart().getAsString();
  +
  +        Element body;
  +        try {
  +            body =  env.getFirstBody().getAsDOM();
  +        } catch (Exception e) {
  +            throw new AxisFault("Unable to get request body as DOM Element on server");
  +        }
  +
  +        // debug
  +        //System.err.println("Request:\n---------\n" + requestString + "\n------");
  +
  +        /*
  +         * Here is what we expect the Body to look like:
  +         *   <Simple xmlns="urn:qualifyTest">
  +         *    <name>Tommy</name>
  +         *   </Simple>
  +         */
  +
  +        // Now we have a DOM Element, verfy namespace attributes
  +        String simpleNS = body.getNamespaceURI();
  +        if (!simpleNS.equals(namespace) ) {
  +            throw new AxisFault("Namespace of Simple element incorrect: " + 
  +                                simpleNS + " should be: " + namespace);
  +        }
  +
  +        Node nameNode = body.getFirstChild();
  +        String nameNS = nameNode.getNamespaceURI();
  +        if (nameNS != null ) {
  +            throw new AxisFault("Namespace of name element incorrect: " + 
  +                                nameNS + " should be: NULL");
  +        }
           // Return a response (which the client will validate)
           return "Hello there: " + name;
       }
  @@ -21,8 +122,55 @@
       public test.wsdl.qualify.Response formOverride(test.wsdl.qualify.Complex complex) throws java.rmi.RemoteException {
           // Validate XML request to make sure elements are properly qualified
           // or not per the WSDL
  -        // FIXME
  -        
  +        MessageContext mc = MessageContext.getCurrentContext();
  +        Message request = mc.getRequestMessage();
  +        SOAPEnvelope env = request.getSOAPPart().getAsSOAPEnvelope();
  +        String requestString = request.getSOAPPart().getAsString();
  +
  +        Element body;
  +        try {
  +            body =  env.getFirstBody().getAsDOM();
  +        } catch (Exception e) {
  +            throw new AxisFault("Unable to get request body as DOM Element on server");
  +        }
  +        // debug
  +        //System.err.println("Request:\n---------\n" + requestString + "\n------");
  +
  +        /*
  +         * Here is what we expect the Body to look like:
  +         *     <FormOverride xmlns="urn:qualifyTest">
  +         *       <complex xmlns="">
  +         *           <ns1:name xmlns:ns1="urn:qualifyTest">Timmah</ns1:name>
  +         *        </complex>
  +         *     </FormOverride>
  +         */
  +
  +        // Now we have a DOM Element, verfy namespace attributes
  +        String FormOverrideNS = body.getNamespaceURI();
  +        if (!FormOverrideNS.equals(namespace) ) {
  +            throw new AxisFault("Namespace of FormOverrideNS element incorrect: " + 
  +                                FormOverrideNS + " should be: " + namespace);
  +        }
  +
  +        Node complexNode = body.getFirstChild();
  +        String complexNS = complexNode.getNamespaceURI();
  +        if (complexNS != null ) {
  +            throw new AxisFault("Namespace of <complex> element incorrect: " + 
  +                                complexNS + " should be: NULL");
  +        }
  +
  +        // FIXME: for some reason I can't get at the <name> node which is
  +        // under the <complex> node.  Are we not converting the request to
  +        // DOM correctly?
  +        if (complexNode.hasChildNodes()) {
  +            Node nameNode = complexNode.getFirstChild();
  +            String nameNS = nameNode.getNamespaceURI();
  +            if (!nameNS.equals(namespace)) {
  +                throw new AxisFault("Namespace of <name> element incorrect: " +  
  +                                    nameNS + " should be: " + namespace);
  +            }
  +        }        
  +
           // Return a response (which the client will validate)
           test.wsdl.qualify.Response r = new Response();
           r.setName("Tommy");