ndlesiecki    2003/06/26 08:09:02

  Modified:    framework/src/test/share/org/apache/cactus
                        TestWebRequest.java
  Added:       framework/src/test/share/org/apache/cactus/util
                        UniqueGeneratorTest.java
               framework/src/test/share/org/apache/cactus
                        RequestDirectivesTest.java
  Log:
  Added the concept of request directives and moved functionality there.
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.1                  
jakarta-cactus/framework/src/test/share/org/apache/cactus/util/UniqueGeneratorTest.java
  
  Index: UniqueGeneratorTest.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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", "Cactus" 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 [EMAIL PROTECTED]
   *
   * 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.cactus.util;
  
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Set;
  
  import org.apache.cactus.ServletTestCase;
  
  import junit.framework.TestCase;
  
  /**
   * Smoke test for the unique id generator.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]>Nicholas Lesiecki</a>
   *
   * @version $Id: UniqueGeneratorTest.java,v 1.1 2003/06/26 15:09:02 ndlesiecki Exp $
   */
  public class UniqueGeneratorTest extends TestCase
  {
  
      /**
       * Simulates several simultaneous id generations using threads.
       * Verifies that there are no duplicates among the generated ids.
       */
      public void testThatSimultaneouslyGeneratedIdsAreUnique()
      {
          final ServletTestCase aTestCase = new ServletTestCase("foo");
          Thread[] threads = new Thread[10];
          final List results = Collections.synchronizedList(new ArrayList());
          for (int i = 0; i < threads.length; i++)
          {
              threads[i] = new Thread()
              {
                  public void run()
                  {
                      results.add(UniqueGenerator.generate(aTestCase));
                  }
              };
          }
  
          //loops seperate to make their beginning as simultaneous
          //as possible
          for (int i = 0; i < threads.length; i++)
          {
              threads[i].run();
          }
  
          try
          {
              //in case the threads need time to finish
              Thread.sleep(200);
          }
          catch (InterruptedException e)
          {
              throw new ChainedRuntimeException(e);
          }
  
          Set resultSet = new HashSet(results);
          assertEquals(
              "Results contained duplicate ids.",
              results.size(),
              resultSet.size());
      }
  }
  
  
  
  1.16      +1 -35     
jakarta-cactus/framework/src/test/share/org/apache/cactus/TestWebRequest.java
  
  Index: TestWebRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/test/share/org/apache/cactus/TestWebRequest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TestWebRequest.java       22 Jun 2003 18:00:27 -0000      1.15
  +++ TestWebRequest.java       26 Jun 2003 15:09:02 -0000      1.16
  @@ -271,39 +271,5 @@
           }
       }
       
  -    /**
  -     * Verifies that setting the unique id on the request adds it to
  -     * the list of query string parameters.
  -     */
  -    public void testUniqueIdIsAddedToListOfQueryStringParameters()
  -    {
  -        WebRequest request = new WebRequest(new ServletConfiguration());
  -
  -        String testId = "XXX-TEST";
  -        request.setUniqueId(testId);
  -        assertEquals(testId, request.getUniqueId());
  -        assertEquals(testId, 
  -            request.getParameterGet(HttpServiceDefinition.TEST_ID_PARAM));
  -    }
  -
  -    /**
  -     * Verifies that once the unique id is set on the request object, 
  -     * it cannot be set to anything else.
  -     */
  -    public void testUniqueIdCannotBeReset()
  -    {
  -        WebRequest request = new WebRequest(new ServletConfiguration());
  -        request.setUniqueId("XXX-TEST");
  -
  -        try
  -        {
  -            request.setUniqueId("something-else");
  -            fail("The unique id should not be able to be reset");
  -        } 
  -        catch (IllegalStateException expected)
  -        {
  -            assertTrue(true);
  -        }
  -    }
   
   }
  
  
  
  1.1                  
jakarta-cactus/framework/src/test/share/org/apache/cactus/RequestDirectivesTest.java
  
  Index: RequestDirectivesTest.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-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", "Cactus" 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 [EMAIL PROTECTED]
   *
   * 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.cactus;
  
  import junit.framework.TestCase;
  
  /**
   * Verifies that the RequestDirectives are successfully added to the WebRequest.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]>Nicholas Lesiecki</a>
   *
   * @version $Id: RequestDirectivesTest.java,v 1.1 2003/06/26 15:09:02 ndlesiecki Exp 
$
   */
  public class RequestDirectivesTest extends TestCase
  {
      /**
       * Holds a variable common to all tests.
       */
      private WebRequest request;
      
      /**
       * Holds a variable common to all tests.
       */
      private String testId;
  
      /**
       * Holds a variable common to all tests.
       */
      private RequestDirectives directives;
  
      /**
       * Creates a blank WebRequest and sets up direcitves
       */
      public void setUp()
      {
          request = new WebRequest();
          testId = "abcd";
          directives = new RequestDirectives(request);
          directives.setId(testId);
      }
  
      /**
       * Verifies that setting the unique id on the directives adds it to
       * the list of query string parameters.
       */
      public void testIdAddedToQueryParameters()
      {
          assertEquals(testId, 
              request.getParameterGet(HttpServiceDefinition.TEST_ID_PARAM));
      }
      
      /**
       * Verifies the directives can read an id from a WebRequest
       * it did not originally modify.
       */
      public void testReadIdFromAnotherClientSideRequest()
      {
          RequestDirectives fresh = new RequestDirectives(request);
          assertEquals(testId, fresh.getId());
      }
  
  
      /**
       * Verifies that once the unique id is set on the request object, 
       * it cannot be set to anything else.
       */
      public void testUniqueIdCannotBeReset()
      {
          try
          {
              directives.setId("something-else");
              fail("The unique id should not be able to be reset");
          } 
          catch (IllegalStateException expected)
          {
              assertTrue(true);
          }
      }
  
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to