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 2003/01/10 07:38:06 UTC

cvs commit: xml-axis/java/test/httpunit/src/test AdminTest.java HttpUnitTestBase.java JspTest.java JwsTest.java ServicesTest.java

stevel      2003/01/09 22:38:06

  Modified:    java/test/httpunit build.xml
  Added:       java/test/httpunit AdminTest.java FunctionalTests.java
                        HttpUnitTestBase.java JspTest.java JwsTest.java
                        ServicesTest.java
  Removed:     java/test/httpunit/lib Tidy.jar httpunit-license.html
                        httpunit.jar junit.jar
               java/test/httpunit/src/test AdminTest.java
                        HttpUnitTestBase.java JspTest.java JwsTest.java
                        ServicesTest.java
  Log:
  Changes to httpunit tests
  
  1. layout aligned with rests of tests
  2. build file aligned with rests of tests
  3. lib file removed; you need httpunit in ant/lib, axis/lib or similar
  4. tested against httpunit1.5.2
  5. the compile/test only runs if httpunit.present is set and httpunit.enabled=="true".
  6. added all the tests for GET error codes that are about to go into AxisServlet
  
  Result: you can integrate httpunit with the rest of the tests, but only if you set up the lib dirs and enable the test. The reason is that SimpleAxisServer cannot handle the JSP tests, so this suite needs a real webapp server.
  
  Revision  Changes    Path
  1.12      +31 -31    xml-axis/java/test/httpunit/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/httpunit/build.xml,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- build.xml	29 Nov 2002 23:32:52 -0000	1.11
  +++ build.xml	10 Jan 2003 06:38:05 -0000	1.12
  @@ -53,11 +53,11 @@
     <property file="build.properties"/>
     
     
  -        &properties;
  -        &paths;
  -        &targets;
  -        <!-- &taskdefs; -->
  -        <!-- &taskdefs_post_compile; -->
  +    &properties;
  +    &paths;
  +    &taskdefs;
  +    &taskdefs_post_compile;
  +    &targets;
     
         
     <!-- ========================================================== -->
  @@ -65,20 +65,17 @@
     <!-- ========================================================== -->
   
   
  -  <property name="axis.url" value="http://localhost:8080/axis"/>
  -  
  -  
     <target name="copy"/>
     
     <target name="deploy"/>
     
  -  <target name="run" depends="test"/>
  +  <target name="run" />
     
     <target name="undeploy"/>
     
     
     <path id="test.compile.classpath">
  -    <fileset dir="${component.home}/lib" includes="**/*.jar" />
  +    <path refid="classpath"/>
     </path>
       
     <path id="test.classpath">
  @@ -102,21 +99,31 @@
     
     <!-- init configures things -->
     <target name="init" depends="setenv">
  -    <echo> Axis home=${axis.home}</echo>
  +    <condition property="execute.httpunit">
  +      <and>
  +        <isset property="httpunit.present"/>
  +        <istrue value="${httpunit.enabled}"/>
  +      </and>
  +    </condition>
  +    <echo>
  +    httpunit.present=${httpunit.present}
  +    httpunit.enabled = ${httpunit.enabled}
  +    execute.httpunit=${execute.httpunit}
  +    </echo>
       <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" depends="init">
  -    <property name="build.debuglevel" value="lines,vars,source"/> 
  +  <target name="compile" depends="init" if="execute.httpunit">
       <javac destdir="${test.classes.dir}"
              debug="${build.debug}"
  +           debuglevel="${debuglevel}"
              includeAntRuntime="false"
              fork="${javac.fork}"
  -           srcdir="${component.home}/src">
  +           srcdir="${axis.home}">
         <classpath refid="test.compile.classpath"/>
  +      <include name="${componentName}/*.java"/>
       </javac>
     </target>
     
  @@ -124,6 +131,7 @@
   
     <target name="run-test"
         depends="compile" 
  +      if="execute.httpunit"
         description="test axis on a server" >
       <junit printsummary="false"
              errorProperty="test.failed"
  @@ -132,30 +140,22 @@
              fork="true">
         <classpath 
           refid="test.classpath"/>
  -      <sysproperty key="server.url" 
  -        value="${axis.url}"/>
  +      <sysproperty key="test.functional.webapp.url" 
  +        value="${test.functional.webapp.url}"/>
         <formatter type="xml"/>
         <formatter type="brief" usefile="false"/>
         <test name="${testcase}" if="testcase"/>
  -      <batchtest todir="${test.data.dir}" unless="testcase">
  -        <fileset dir="${component.home}/src" includes="**/*Test.java"/>
  +      <batchtest todir="${test.reports.dir}" unless="testcase">
  +        <fileset dir="${build.dir}/classes"
  +          includes="test/httpunit/*Tests.class"/>
         </batchtest>
       </junit>
     </target>
       
     <!-- generate any test reports and fail, if needed -->
  -  <target name="test" depends="run-test" if="test.failed">    
  -    <junitreport todir="${test.data.dir}">
  -      <fileset dir="${test.data.dir}">
  -        <include name="TEST-*.xml"/>
  -      </fileset>
  -      <report format="frames" todir="${test.reports.dir}"/>
  -    </junitreport>
  -    
  -    <!-- bail out -->
  -    <fail message="Functional tests failed - see ${test.reports.dir}"  />
  -  </target>
  -
  +  <target name="test" depends="run-test" >
  +    <fail if="test.failed">Tests Failed</fail>
  +  </target>    
       
   </project>
   
  
  
  
  1.1                  xml-axis/java/test/httpunit/AdminTest.java
  
  Index: AdminTest.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 test.httpunit;
  
  import com.meterware.httpunit.*;
  
  /**
   * test the services
   * @author Steve Loughran
   * @created Jul 10, 2002 12:09:06 AM
   */
  
  public class AdminTest extends HttpUnitTestBase {
  
      private String servlet;
  
      private String invalid_service;
  
      private boolean isProduction=false;
  
      public AdminTest(String name) {
          super(name);
      }
  
      /**
       *  The JUnit setup method
       *
       */
      public void setUp() throws Exception {
          super.setUp();
          servlet = url + "/servlet/AdminServlet";
      }
  
      /**
       * verify the page is there
       * @throws Exception
       */
      public void testPage() throws Exception {
          WebRequest request = new GetMethodWebRequest(servlet);
          assertStringInBody(request, "Server");
      }
  
      /**
       * dev systems have commands
       * @throws Exception
       */
      public void testPageHasCommands() throws Exception {
          WebRequest request = new GetMethodWebRequest(servlet);
          assertStringInBody(request, "Server");
          WebConversation session = new WebConversation();
          WebResponse response = session.getResponse(request);
          String body = response.getText();
          assertTrue("start server", body.indexOf("start server")>0);
          assertTrue("stop server", body.indexOf("stop server") > 0);
          assertTrue("Current Load",body.indexOf("Current load") > 0);
      }
  
      /**
       * test stop command
       * @throws Exception
       */
      public void testStop() throws Exception {
          WebRequest request = new GetMethodWebRequest(servlet);
          request.setParameter("cmd", "stop");
          assertStringInBody(request, "Server is stopped");
      }
  
      /**
       * test start command
       * @throws Exception
       */
      public void testStart() throws Exception {
          WebRequest request = new GetMethodWebRequest(servlet);
          request.setParameter("cmd", "start");
          assertStringInBody(request, "Server is running");
      }
  
  }
  
  
  
  1.1                  xml-axis/java/test/httpunit/FunctionalTests.java
  
  Index: FunctionalTests.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 test.httpunit;
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import org.apache.axis.test.AxisTestBase;
  
  /**
   * test httpunit
   */
  public class FunctionalTests extends AxisTestBase {
  
      public FunctionalTests(String s) {
          super(s);
      }
  
  
      /**
       * here are the tests we run
       * @return suite of tests
       * @throws Exception
       */
      public static Test suite() throws Exception {
          TestSuite suite = new TestSuite();
          suite.addTestSuite(ServicesTest.class);
          suite.addTestSuite(JwsTest.class);
          if(isPropertyTrue("test.functional.httpunit.jsp")) {
              suite.addTestSuite(JspTest.class);
          }
          if(isPropertyTrue("test.functional.httpunit.adminservlet")) {
              suite.addTestSuite(AdminTest.class);
          }
          return suite;
      }
  }
  
  
  
  1.1                  xml-axis/java/test/httpunit/HttpUnitTestBase.java
  
  Index: HttpUnitTestBase.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 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 test.httpunit;
  
  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);
      }
  
      private static String URL_PROPERTY="test.functional.webapp.url";
      /**
       *  The JUnit setup method
       *
       */
      public void setUp() throws Exception {
          url=System.getProperty(URL_PROPERTY);
          assertNotNull(URL_PROPERTY+" 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 {
          WebResponse response = makeRequest(request);
          assertStringInBody(response,searchfor,request.getURL().toString());
      }
  
      /**
       * make a request in a new session
       * @param request   request to make
       * @return the response
       * @throws IOException
       * @throws SAXException
       */
      protected WebResponse makeRequest(WebRequest request) throws IOException, SAXException {
          WebConversation session = new WebConversation();
          WebResponse response=session.getResponse(request);
          return response;
      }
  
      /**
       * 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
       * checking for text is omitted as it doesnt work. It would never work on
       * java1.3, but one may have expected java1.4+ to have access to the
       * error stream in responses. clearly not
       * @param request
       * @param errorCode
       * @param errorText optional text string to search for
       * @throws MalformedURLException
       * @throws IOException
       * @throws SAXException
       */
      protected void expectErrorCode(WebRequest request,
                                     int errorCode, String errorText)
                          throws MalformedURLException, IOException, SAXException {
          WebConversation session = new WebConversation();
          String failureText="Expected error "+errorCode+" from "+request.getURL();
          try {
              session.getResponse(request);
              fail(errorText+" -got success instead");
          } catch (HttpException e) {
              assertEquals(failureText,errorCode,e.getResponseCode());
              /* checking for text omitted as it doesnt work.
              if(errorText!=null) {
                  assertTrue(
                          "Failed to find "+errorText+" in "+ e.getResponseMessage(),
                          e.getMessage().indexOf(errorText)>=0);
              }
              */
          }
      }
  }
  
  
  
  1.1                  xml-axis/java/test/httpunit/JspTest.java
  
  Index: JspTest.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 test.httpunit;
  
  import com.meterware.httpunit.*;
  
  
  /**
   *  test the basic system is there
   *
   *@author     steve loughran
   */
  
  public class JspTest extends HttpUnitTestBase {
  
  
      public JspTest(String name) {
          super(name);
      }
  
      /**
       * base page
       */
      public void testIndex() throws Exception {
          WebRequest request = new GetMethodWebRequest(url+"/");
          assertStringInBody(request,"Apache-Axis");
      }
  
      /**
       * happiness test
       */
      public void testAxisHappy() throws Exception {
          WebRequest request = new GetMethodWebRequest(url+"/happyaxis.jsp");
          assertStringInBody(request,"The core axis libraries are present");
      }
  
  
      /**
       * fingerprint
       */
      public void testFingerprint() throws Exception {
          WebRequest request = new GetMethodWebRequest(url+"/fingerprint.jsp");
          assertStringInBody(request,"System Fingerprint");
      }
      
  
  }
  
  
  
  
  1.1                  xml-axis/java/test/httpunit/JwsTest.java
  
  Index: JwsTest.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 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 test.httpunit;
  
  import com.meterware.httpunit.WebRequest;
  import com.meterware.httpunit.GetMethodWebRequest;
  import com.meterware.httpunit.WebResponse;
  
  /**
   * 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");
      }
  
      public void testEchoHeadersWsdl() throws Exception {
          WebRequest request = new GetMethodWebRequest(url + "/EchoHeaders.jws?wsdl");
          assertStringInBody(request, "<wsdl:definitions");
      }
  
  
      public void testEchoHeaders() throws Exception {
          WebRequest request = new GetMethodWebRequest(url + "/EchoHeaders.jws");
          assertStringInBody(request, "Web Service");
      }
  
      /**
       * see that we get a hello back
       * @throws Exception
       */
      public void testEchoHeadersWhoami() throws Exception {
          WebRequest request = new GetMethodWebRequest(url
                  + "/EchoHeaders.jws");
          request.setParameter("method", "whoami");
          assertStringInBody(request, "Hello");
      }
  
      /**
       * do we get a list of headers back?
       * @throws Exception
       */
      public void testEchoHeadersList() throws Exception {
          WebRequest request = new GetMethodWebRequest(url
                  + "/EchoHeaders.jws");
          request.setHeaderField("x-header","echo-header-test");
          request.setParameter("method", "list");
          assertStringInBody(request, "echo-header-test");
      }
  
      /**
       * send an echo with a space down
       * @throws Exception
       */
      public void testEchoHeadersEcho() throws Exception {
          WebRequest request = new GetMethodWebRequest(url
                  + "/EchoHeaders.jws");
          request.setParameter("method","echo");
          request.setParameter("param", "foo bar");
          assertStringInBody(request, "foo bar");
      }
  
      /**
       * we throw an error on missing JWS pages
       * @throws Exception
       */
      public void testMissingJWSRaisesException() throws Exception {
          WebRequest request = new GetMethodWebRequest(url
                  + "/EchoHeaders-not-really-there.jws");
          expectErrorCode(request,404, "No service");
      }
  
      /**
       * axis faults.
       * @throws Exception
       */
      public void testAxisFaultIsXML() throws Exception {
          WebRequest request = new GetMethodWebRequest(url
                  + "/EchoHeaders.jws");
          request.setParameter("method", "throwAxisFault");
          request.setParameter("param", "oops!");
          expectErrorCode(request, 500,
              "<faultcode>soapenv:Server.generalException</faultcode>");
      }
  
      /**
       * exceptions are user faults
       * @throws Exception
       */
      public void testExceptionIsXML() throws Exception {
          WebRequest request = new GetMethodWebRequest(url
                  + "/EchoHeaders.jws");
          request.setParameter("method", "throwAxisFault");
          request.setParameter("param", "oops!");
          expectErrorCode(request, 500,
                  "<faultcode>soapenv:Server.userException</faultcode>");
      }
  
      /**
       * 
       */
  
      /**
       * send a complex unicode round the loop and see what happens
       * @throws Exception
       */
      /* this is failing but it may be in the test code
      public void testEchoHeadersEchoUnicode() throws Exception {
          WebRequest request = new GetMethodWebRequest(url
                  + "/EchoHeaders.jws");
          request.setParameter("method", "echo");
          request.setParameter("param", "\u221a");
          assertStringInBody(request, "\u221a");
      }
      */
  
  }
  
  
  
  1.1                  xml-axis/java/test/httpunit/ServicesTest.java
  
  Index: ServicesTest.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 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 test.httpunit;
  
  import com.meterware.httpunit.WebRequest;
  import com.meterware.httpunit.GetMethodWebRequest;
  import com.meterware.httpunit.WebResponse;
  
  /**
   * 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);
          expectErrorCode(request,404, null);
      }
  
      /**
       * @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);
          expectErrorCode(request,404, null);
      }
  
      /**
       * A missing wsdl page should be a 404 error;
       * @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,404, null);
      }
  
      /**
       * test version call
       * @throws Exception
       */
      public void testVersionWSDL() throws Exception {
          WebRequest request = new GetMethodWebRequest(services
                  +"Version?wsdl");
          assertStringInBody(request,"<wsdl:definitions");
      }
  
      /**
       * test version call
       * @throws Exception
       */
      public void testVersionMethod() throws Exception {
          WebRequest request = new GetMethodWebRequest(services
                  + "Version?method=getVersion");
          WebResponse response=makeRequest(request);
          String body = response.getText();
          assertTrue(body.indexOf("<?xml") ==0);
          assertTrue(body.indexOf("<getVersionReturn")>0);
      }
  
      /**
       * test a get without any method
       * @throws Exception
       */
      public void testVersionNoMethod() throws Exception {
          WebRequest request = new GetMethodWebRequest(services
                  + "Version?arg1=foo&arg2=bar");
          expectErrorCode(request, 400, null);
      }
  
  
  }
  
  
  

Re: cvs commit: xml-axis/java/test/httpunit/src/test AdminTest.java HttpUnitTestBase.java JspTest.java JwsTest.java ServicesTest.java

Posted by Steve Loughran <st...@iseran.com>.
----- Original Message -----
From: <st...@apache.org>
To: <xm...@apache.org>
Sent: Thursday, January 09, 2003 22:38
Subject: cvs commit: xml-axis/java/test/httpunit/src/test AdminTest.java
HttpUnitTestBase.java JspTest.java JwsTest.java ServicesTest.java

>   Log:
>   Changes to httpunit tests
>
>   1. layout aligned with rests of tests
>   2. build file aligned with rests of tests
>   3. lib file removed; you need httpunit in ant/lib, axis/lib or similar
>   4. tested against httpunit1.5.2
>   5. the compile/test only runs if httpunit.present is set and
httpunit.enabled=="true".
>   6. added all the tests for GET error codes that are about to go into
AxisServlet
>
>   Result: you can integrate httpunit with the rest of the tests, but only
if you set up the lib dirs and enable the test. The reason is that
SimpleAxisServer cannot handle the JSP tests, so this suite needs a real
webapp server.

One more thing. although I have tests that say what error code *and* error
text they expect, we can only check the error code in the tests because our
friend java.net.HttpUrlConnection  is stopping HttpUnit from getting at the
response text for any error on a page that doesnt end in .html or .txt; a
long standing defect fixed in java1.4, but whose fix is not incorporated in
httpunit.


    public void testExceptionIsXML() throws Exception {
>           WebRequest request = new GetMethodWebRequest(url
>                   + "/EchoHeaders.jws");
>           request.setParameter("method", "throwAxisFault");
>           request.setParameter("param", "oops!");
>           expectErrorCode(request, 500,
>                   "<faultcode>soapenv:Server.userException</faultcode>");
>       }