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 st...@apache.org on 2002/07/10 18:57:59 UTC

cvs commit: xml-axis/java/test/servlet/src/org/apache/axis/servlettests BaseSystemTest.java HttpUnitTestBase.java JwsTest.java ServicesTest.java

stevel      2002/07/10 09:57:59

  Added:       java/test/servlet test.xml
               java/test/servlet/lib Tidy.jar httpunit-license.html
                        httpunit.jar junit.jar
               java/test/servlet/src/org/apache/axis/servlettests
                        BaseSystemTest.java HttpUnitTestBase.java
                        JwsTest.java ServicesTest.java
  Log:
  servlet test framework. no deployment (yet), but runs against a local or remote server and generates an HTML report afterwards.
  
  Revision  Changes    Path
  1.1                  xml-axis/java/test/servlet/test.xml
  
  Index: test.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <project name="Web App Test" default="default" basedir=".">
    <description>
      Test a Web application with HttpUnit. Based on example code in 
      Java Development with Ant, Hatcher and Loughran, 2001.
      Customised for Axis by Steve Loughran.
      1. Needs XSLT support from Xalan to generate the reports.
      2. To run a single test, set testcase=the name of the test.
      3. default URL is http://localhost:8080/axis ; set the 
         axis.url property to target a different system.
    </description>
    
  <!-- BEGIN TOPLEVEL DECLARATIONS -->
    <!-- Load the application specific settings -->
    <!-- #Project specific props -->
    <property file="build.properties"/>
    
    <property name="build.dir" location="build"/>
        
    <!-- ========================================================== -->
    <!-- Test settings                                              -->
    <!-- ========================================================== -->
    <property name="test.dir" location="${build.dir}/test"/>
    <property name="test.classes.dir" location="${test.dir}/classes"/>
    <property name="test.data.dir" location="${test.dir}/data"/>
    <property name="test.reports.dir" location="${test.dir}/reports"/>
  
    <property name="axis.url" value="http://localhost:8080/axis"/>
    
    <path id="test.compile.classpath">
      <fileset dir="lib" includes="**/*.jar" />
    </path>
      
    <path id="test.classpath">
      <path refid="test.compile.classpath"/>
      <pathelement location="${test.classes.dir}"/>
    </path>    
    <!-- END TOPLEVEL DECLARATIONS -->
    
    <!-- Public Targets -->
  
    <target name="default" 
      depends="test"
      description="test axis on a server"
      />
  
    <!-- cleanup target -->
    <target name="clean" description="cleanup">
     <delete dir="${build.dir}" />
    </target>
  
    
    <!-- init configures things -->
    <target name="init" >
      <mkdir dir="${test.dir}" />
      <mkdir dir="${test.classes.dir}" />
      <mkdir dir="${test.data.dir}" />
      <mkdir dir="${test.reports.dir}" />
    </target>
    
      <!-- compile the java sources using the compilation classpath -->
    <target name="compile-tests" depends="init">
      <mkdir dir="${test.classes.dir}"/>
      <property name="build.debuglevel" value="lines,vars,source"/> 
      <javac destdir="${test.classes.dir}"
             debug="${build.debug}"
             includeAntRuntime="false"
             srcdir="src">
        <classpath refid="test.compile.classpath"/>
      </javac>
    </target>
    
     <!-- this is our test suite for httpunit -->
  
    <target name="test"
        depends="compile-tests" 
        description="test axis on a server" >
      <junit printsummary="false"
             errorProperty="test.failed"
             failureProperty="test.failed"
             haltonfailure="false"
             fork="true">
        <classpath 
          refid="test.classpath"/>
        <sysproperty key="server.url" 
          value="${axis.url}"/>
        <formatter type="xml"/>
        <formatter type="brief" usefile="false"/>
        <test name="${testcase}" if="testcase"/>
        <batchtest todir="${test.data.dir}" unless="testcase">
          <fileset dir="src" includes="**/*Test.java"/>
        </batchtest>
      </junit>
      
      <!-- generate any test reports -->
      <junitreport todir="${test.data.dir}">
        <fileset dir="${test.data.dir}">
          <include name="TEST-*.xml"/>
        </fileset>
        <report format="frames" todir="${test.reports.dir}"/>
      </junitreport>
      
      <!-- then bail out when things go bad -->
      <fail message="Functional tests failed - see the report"
        if="test.failed"/>
    </target>
  
      
  </project>
  
  
  
  
  1.1                  xml-axis/java/test/servlet/lib/Tidy.jar
  
  	<<Binary file>>
  
  
  1.1                  xml-axis/java/test/servlet/lib/httpunit-license.html
  
  Index: httpunit-license.html
  ===================================================================
  <HTML><HEAD><TITLE>HttpUnit License Agreement</TITLE></HEAD>
  <BODY>
  <P>
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated      
  documentation files (the "Software"), to deal in the Software without restriction, including without limitation   
  the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and  
  to permit persons to whom the Software is furnished to do so, subject to the following conditions:</P>                
  
  <P>                                                                                                                  
  The above copyright notice and this permission notice shall be included in all copies or substantial portions     
  of the Software.</P>                                                                                                  
                                                                                                                    
  <P>
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO  
  THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE    
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF         
  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER          
  DEALINGS IN THE SOFTWARE.
  </P>
  </BODY></HTML>                                                                                         
  
  
  
  1.1                  xml-axis/java/test/servlet/lib/httpunit.jar
  
  	<<Binary file>>
  
  
  1.1                  xml-axis/java/test/servlet/lib/junit.jar
  
  	<<Binary file>>
  
  
  1.1                  xml-axis/java/test/servlet/src/org/apache/axis/servlettests/BaseSystemTest.java
  
  Index: BaseSystemTest.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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 org.apache.axis.servlettests;
  
  import com.meterware.httpunit.*;
  
  
  /**
   *  test the basic system is there
   *
   *@author     steve loughran
   */
  
  public class BaseSystemTest extends HttpUnitTestBase {
  
  
      public BaseSystemTest(String name) {
          super(name);
      }
      
  
      public void testAxisHappy() throws Exception {
          WebRequest request = new GetMethodWebRequest(url+"/happyaxis.jsp");
          assertStringInBody(request,"The core axis libraries are present");
      }
  
      public void testIndex() throws Exception {
          WebRequest request = new GetMethodWebRequest(url+"/");
          assertStringInBody(request,"Apache-Axis");
      }
  
  
  }
  
  
  
  
  1.1                  xml-axis/java/test/servlet/src/org/apache/axis/servlettests/HttpUnitTestBase.java
  
  Index: HttpUnitTestBase.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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 org.apache.axis.servlettests;
  
  import junit.framework.TestCase;
  import com.meterware.httpunit.*;
  
  import java.io.*;
  import java.net.MalformedURLException;
  
  import org.xml.sax.SAXException;
  
  /**
   * class to make it that much easier to validate httpunit requests
   */
  public class HttpUnitTestBase extends TestCase {
      /**
       *  our url
       *
       */
      protected String url;
  
      public HttpUnitTestBase(String s) {
          super(s);
      }
  
      /**
       *  The JUnit setup method
       *
       */
      public void setUp() throws Exception {
          url=System.getProperty("server.url");
          assertNotNull("server.url not set",url);
          HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
          HttpUnitOptions.setMatchesIgnoreCase(true);
          HttpUnitOptions.setParserWarningsEnabled(true);
      }
  
      /**
       * assert that the response contains a string
       * @param response
       * @param searchfor
       * @param url
       * @throws IOException
       */
      public void assertStringInBody(WebResponse response,String searchfor, String url)
              throws IOException {
          String body=response.getText();
          boolean found=body.indexOf(searchfor)>=0;
          if(!found) {
              String message;
              message="failed to find "+searchfor+" at "+url;
              fail(message);
          }
      }
  
      /**
       * assert that a named string is in the request body of the
       * response to a request
       * @param request what we ask
       * @param searchfor string to look for
       * @throws IOException when the fetch fails
       * @throws org.xml.sax.SAXException
       */
      protected void assertStringInBody( WebRequest request,
                                         String searchfor
                                         )
                  throws IOException, org.xml.sax.SAXException {
          WebConversation session = new WebConversation();
          WebResponse response=session.getResponse(request);
          assertStringInBody(response,searchfor,request.getURL().toString());
      }
  
      /**
       * assert that a string is not in a response
       * @param response
       * @param searchfor
       * @param url
       * @throws IOException
       */
      protected void assertStringNotInBody(WebResponse response,
                                           String searchfor,
                                           String url)
              throws IOException {
          String body=response.getText();
          boolean found=body.indexOf(searchfor)>=0;
          if(found) {
              String message;
              message="unexpectedly found "+searchfor+" at "+url;
              fail(message);
          }
  
      }
  
      /**
       * assert that a string is not in the response to a request
       * @param request
       * @param searchfor
       * @throws IOException
       * @throws org.xml.sax.SAXException
       */
      protected void assertStringNotInBody( WebRequest request,
                                            String searchfor)
                  throws IOException, org.xml.sax.SAXException {
          WebConversation session = new WebConversation();
          WebResponse response=session.getResponse(request);
          assertStringNotInBody(response,searchfor,
                  request.getURL().toString());
      }
  
      /**
       * here we expect an errorCode other than 200, and look for it
       * @param request
       * @param errorCode
       * @throws MalformedURLException
       * @throws IOException
       * @throws SAXException
       */
      protected void expectErrorCode(WebRequest request,
                                     int errorCode)
                          throws MalformedURLException, IOException, SAXException {
          WebConversation session = new WebConversation();
          String errorText="Expected error "+errorCode+"from "+request.getURL();
          try {
              session.getResponse(request);
              fail(errorText+" -got success instead");
          } catch (HttpException e) {
              assertEquals(errorText,
                          errorCode,e.getResponseCode());
          }
      }
  }
  
  
  
  1.1                  xml-axis/java/test/servlet/src/org/apache/axis/servlettests/JwsTest.java
  
  Index: JwsTest.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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 org.apache.axis.servlettests;
  
  import com.meterware.httpunit.WebRequest;
  import com.meterware.httpunit.GetMethodWebRequest;
  
  /**
   * test for JWS pages being processed
   * @author Steve Loughran
   * @created Jul 10, 2002 12:09:20 AM
   */
  
  public class JwsTest extends HttpUnitTestBase {
  
      public JwsTest(String name) {
          super(name);
      }
  
      public void testStockQuote() throws Exception {
          WebRequest request = new GetMethodWebRequest(url+"/StockQuoteService.jws?wsdl");
          assertStringInBody(request,"<wsdl:definitions");
      }
  }
  
  
  
  1.1                  xml-axis/java/test/servlet/src/org/apache/axis/servlettests/ServicesTest.java
  
  Index: ServicesTest.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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 org.apache.axis.servlettests;
  
  import com.meterware.httpunit.WebRequest;
  import com.meterware.httpunit.GetMethodWebRequest;
  
  /**
   * test the services
   * @author Steve Loughran
   * @created Jul 10, 2002 12:09:06 AM
   */
  
  public class ServicesTest extends HttpUnitTestBase{
  
      private String services;
  
      private String invalid_service;
  
  
      public ServicesTest(String name) {
          super(name);
      }
  
      /**
       *  The JUnit setup method
       *
       */
      public void setUp() throws Exception {
          super.setUp();
          services=url+"/services/";
          invalid_service=services+"invalid-name";
      }
  
      /**
       * what string do we take as meaning services are present.
       */
      private final static String services_text="Some Services";
  
      private final static String hi_there="Hi there, this is an AXIS service!";
      /**
       * verify the /servlet url is there
       * @throws Exception
       */
      public void testServlet() throws Exception {
          WebRequest request = new GetMethodWebRequest(url+"/servlet/AxisServlet");
          assertStringInBody(request,services_text);
      }
  
      /**
       * verify the services url works
       */
      public void testServices() throws Exception {
          WebRequest request = new GetMethodWebRequest(services);
          assertStringInBody(request,hi_there);
      }
  
      /**
       * @todo decide on the exception to throw in the servlet, write the
       * test then fix the servlet
       * @throws Exception
       */
      public void testInvalidServiceRaisesError() throws Exception {
          WebRequest request = new GetMethodWebRequest(invalid_service);
          assertStringInBody(request,hi_there);
      }
  
      /**
       * @todo we get the error 500 here. Shouldnt a 404 be more correct?
       * @throws Exception
       */
      public void testInvalidServiceWsdlRaisesError() throws Exception {
          WebRequest request = new GetMethodWebRequest(invalid_service+"?wsdl");
          // "The AXIS engine could not find a target service to invoke!");
          expectErrorCode(request,500);
  
      }
  
  }