Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: joist/java/org/joist/search SelfTest.java SearchTest.java

Project highlights: Architectural Overview

joist
Discussion topic

Back to topic list

CVS update: joist/java/org/joist/search SelfTest.java SearchTest.java

Author stack
Full name Michael Stack
Date 2000-10-25 13:11:05 PDT
Message User: stack
  Date: 00/10/25 13:11:05

  Added: java/org/joist/search SelfTest.java
  Removed: java/org/joist/search SearchTest.java
  Log:
  Renamed SearchTest as SelfTest
  
  Revision Changes Path
  1.1 joist/java/org/joist​/search/SelfTest.jav​a
  
  Index: SelfTest.java
  ====================​====================​====================​=======
  /* ====================​====================​====================​====
   * Copyright (c) 2000 Collab.Net. 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 Collab.Net (http://www.Collab.Net/)."
   * Alternately, this acknowlegement may appear in the software itself, if
   * and wherever such third-party acknowlegements normally appear.
   *
   * 4. The hosted project names must not be used to endorse or promote
   * products derived from this software without prior written
   * permission. For written permission, please contact info at collab dot net.
   *
   * 5. Products derived from this software may not use the "Tigris" name
   * nor may "Tigris" appear in their names without prior written
   * permission of Collab.Net.
   *
   * 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 COLLAB.NET 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 Collab.Net.
   */
  
  package org.joist.search;
   
   
  /** Class to test this package.
  * <p>
  * Uses junit. Doc. is a bit flakey.
  * <p>Here's how to run it:
  * <pre>
  * % javac -d classes org/tigris/helm/search/*.java
  * % java -classpath ${CLASSPATH}:./classes -nojit -Dquery="sandbox" -Dindex="${SANDBOX}​/search/swish.idx" junit.textui.TestRunner org.tigris.helm.sear​ch.SearchTestjava -Dquery="sandbox" -classpath ${CLASSPATH}:./classes -nojit junit.textui.TestRunner org.tigris.helm.sear​ch.SearchTest
  * </pre>
  * <p>Here is a note from <a hef="mailto:dlr@coll​ab.net">Daniell Rall</a>
  * on JUnit:
  * <pre>
  * Subject: Re: Heyup boss..
  * Date: Thu, 21 Sep 2000 14:53:32 -0700
  * From: "Daniel L. Rall" <dlr at collab dot net>
  * To: stack at collab dot net
  * References: 1 , 2 , 3
  *
  * Michael Stack wrote:
  * >
  * > Yeah, figured. Is it supposed to be? Part of the base machine RPM suite?
  * > Do you like junit framework?
  *
  * Yeah, I personally like the framework. Also, it is supported by the
  * guys who do the XP, UML, and Refactoring books. The only problem that
  * I've run into is when I make my public interfaces narrow, it becomes
  * difficult to test small sections of code without putting the tests in
  * the same package is the implementation (which probaby isn't that bad a
  * thing). This isn't really a "failing", IMO, just something to be aware
  * of. JUnit should be part of our base installs.
  * </pre>
  * <p>
  *
  * @see <a href="http://www.junit.org">JUnit Site</a>
  * @author <a href="mailto:stack@c​ollab.net">St.Ack​</a>
  * @version $Id: SelfTest.java,v 1.1 2000/10/25 20:11:05 stack Exp $
  */
  public class SelfTest
      extends junit.framework.TestCase
  {
      /** Class version string
      */
      public static final String versionID
          = "$Id: SelfTest.java,v 1.1 2000/10/25 20:11:05 stack Exp $";
      
      
      /** Use this key to pull query from system properties.
      */
      protected static final String QUERY_PARAM_KEY = "query";
      
      
      /** Use this key to pull query from system properties.
      */
      protected static final String INDEX_PARAM_KEY = "index";
      
      
      /** Use this key to pull TEST from system properties.
      */
      protected static final String TEST_KEY = "TEST";
      
      
      /** Query string to use in test.
      */
      private String strQuery = null;
      
      
      /** Path to index file to use.
      */
      private String index = null;
      
      
      /** How many results per page.
      */
      private static final int PAGES_PER_QUERY = 20;
      
      
      /** Path to the swish-e binary file
      */
      private static final String PATH_TO_BINARY
          = "/usr/bin/swish-e";
      
      
      /** Constructor
      * @param inString Call super constructor w/ this string
      */
      public SelfTest( String inString )
      {
          super( inString );
      }
      
      
      /** Setup for tests.
      */
      protected void setUp( )
      {
          strQuery = System.getProperty( QUERY_PARAM_KEY );
          index = System.getProperty( INDEX_PARAM_KEY );
      }
      
      
      /** Test query is non-null
      */
      public void testStrQueryNull( )
      {
          assertNotNull( "The 'query' system property is "
                          + "null. Set it on command-line "
                          + "w/ -D"
                          + QUERY_PARAM_KEY
                          + "=\"QUERY\"",
                          strQuery );
      }
      
      
      /** Test index is non-null
      */
      public void testIndexNull( )
      {
          assertNotNull( "The 'index' system property is "
                          + "null. Set it on command-line "
                          + "w/ -D"
                          + INDEX_PARAM_KEY
                          + "=\"INDEX\"",
                          index );
      }
      
      
       /** Test query is non-null
      */
      public void testQuery( )
      {
         try
         {
              SearchSwishe swishe = new SearchSwishe( PATH_TO_BINARY );
              assertNotNull( "Swishe object is null", swishe );
              Query query
                  = new Query( strQuery,
                      index,
                      PAGES_PER_QUERY );
              assertNotNull( "Query object is null", query );
              SearchResult searchresult = swishe.search( query );
              assertNotNull( "SearchResult object is null", searchresult );
              com.sun.java.util.co​llections.List items
                  = searchresult.getSear​chResultItems( );
              if( searchresult.getNumberOfHits( ) > 0 )
              {
                  assertNotNull( "SearchResultItems is null", items );
                  SearchResultItem item = null;
                  java.net.URL url = null;
                  for( int i = 0; i < items.size( ); i++ )
                  {
                      item = ( SearchResultItem )items.get( i );
                      assertNotNull( "A SearchResultItem is null", item );
                      url = item.getUrl( );
                      assertNotNull( "A SearchResultItem url is null", url );
                  }
              }
         }
          
         catch( Exception exception )
         {
              fail( exception.toString( ) );
         }
      }
      
       /** Test a bad query
      */
      public void testBadQuery( )
      {
         try
         {
              SearchSwishe swishe = new SearchSwishe( PATH_TO_BINARY );
              assertNotNull( "Swishe object is null", swishe );
              Query query
                  = new Query( "BAD_QUERY_BAD_QUERY",
                      index,
                      PAGES_PER_QUERY );
              assertNotNull( "Query object is null", query );
              SearchResult searchresult = swishe.search( query );
              assertNotNull( "SearchResult object is null", searchresult );
         }
          
         catch( Exception exception )
         {
              fail( exception.toString( ) );
         }
      }
      
  
      /** Test what happens if i enter a bad index.
      * Should get filenotfound exception.
      */
      public void testBadIndex( )
      {
         try
         {
              SearchSwishe swishe = new SearchSwishe( PATH_TO_BINARY );
              assertNotNull( "Swishe object is null", swishe );
              Query query
                  = new Query( strQuery,
                      "/BAD_INDEX",
                      PAGES_PER_QUERY );
         }
         
         catch( java.io.FileNotFoundException fnfexception )
         {
              // What we expected from our bad index
         }
          
         catch( Exception exception )
         {
              fail( exception.toString( ) );
         }
      }
      
      
       /** Test query is non-null
      */
      public void testQueryOnOneSwishe( )
      {
         try
         {
              SearchSwishe swishe = new SearchSwishe( PATH_TO_BINARY );
              assertNotNull( "Swishe object is null", swishe );
              Query query
                  = new Query( strQuery,
                      index,
                      PAGES_PER_QUERY );
              assertNotNull( "Query object is null", query );
              SearchResult searchresult = null;
              for( int i = 0; i < 10; i++ )
              {
                  searchresult = swishe.search( query );
                  assertNotNull( "SearchResult object is null", searchresult );
              }
         }
          
         catch( Exception exception )
         {
              fail( exception.toString( ) );
         }
      }
      
      
      /** Test query is non-null
      */
      public void testQueries( )
      {
          for( int i = 0; i < 10; i++ )
          {
              testQuery( );
          }
      }
         
      
      /** The test suite to run.
      */
      public static junit.framework.Test suite( )
      {
          junit.framework.TestSuite suite
              = new junit.framework.TestSuite( );
          suite.addTest( new SelfTest( "testStrQueryNull" ) );
          suite.addTest( new SelfTest( "testIndexNull" ) );
          suite.addTest( new SelfTest( "testQuery" ) );
          suite.addTest( new SelfTest( "testBadQuery" ) );
          suite.addTest( new SelfTest( "testBadIndex" ) );
          suite.addTest( new SelfTest( "testQueries" ) );
          suite.addTest( new SelfTest( "testQueryOnOneSwishe" ) );
          return suite;
      }
      
      
      /** Call test suite myself directly bypassing JUnit.
      * Pass at least a 'TEST' using
      * the '-Dkey=value' facility.
      * <p> Here's an example:
      * <pre>
      * % java -nojit -classpath ./classes:${CLASSPATH} -DDEBUG=true -DTEST=testQuery org.tigris.helm.sear​ch.SearchSwishe
      * </pre>
      *
      *
      * @param args List of command line arguments. Ignored.
      */
      public static void main( String[] args )
      {
         String strTest = System.getProperty( TEST_KEY );
         SelfTest test = new SelfTest( strTest );
      }
  }

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: joist/java/org/joist/search SelfTest.java SearchTest.java stack Michael Stack 2000-10-25 13:11:05 PDT
Messages per page: