Package de.nava.informa.utils

Source Code of de.nava.informa.utils.InformaTestCase

//
// Informa -- RSS Library for Java
// Copyright (c) 2002-2003 by Niko Schmuck
//
// Niko Schmuck
// http://sourceforge.net/projects/informa
// mailto:niko_schmuck@users.sourceforge.net
//
// This library is free software.
//
// You may redistribute it and/or modify it under the terms of the GNU
// Lesser General Public License as published by the Free Software Foundation.
//
// Version 2.1 of the license should be included with this distribution in
// the file LICENSE. If the license is not included with this distribution,
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
// MA 02139 USA.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied waranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//


// $Id: InformaTestCase.java,v 1.14 2004/05/21 11:26:54 niko_schmuck Exp $

package de.nava.informa.utils;

import java.io.File;
import java.util.Iterator;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.nava.informa.core.ChannelIF;
import de.nava.informa.core.ItemIF;

/**
* Base class for unit tests of the informa library. It provides some
* convenience methods for easy data file retrieval.
*
* @author Niko Schmuck
*/
public class InformaTestCase extends TestCase {

  private static Log logger = LogFactory.getLog(InformaTestCase.class);
 
  protected final static String FS = System.getProperty("file.separator");
  protected static String dataDir;
  protected static String indexDir;
  protected static String outputDir;
  protected static String baselineDir;

  protected String testcase_name;
  protected String method_name;
 
  static {
    // fall-back mechanism to get the base directory
    String baseDir = System.getProperty("INFORMA_HOME");
    logger.debug("retrieving property INFORMA_HOME: " + baseDir);
    if (baseDir == null) {
      baseDir = System.getProperty("basedir");
      logger.debug("retrieving property basedir: " + baseDir);
    }
    if (baseDir == null) {
      baseDir = System.getProperty("user.dir");
      logger.debug("retrieving property user.dir: " + baseDir);
    }
    // calculate other dirs from this
    String writeDir = baseDir + FS + "build" + FS + "test" + FS + "data";
    indexDir = writeDir + FS + "index";
    outputDir = writeDir + FS + "out";
    // the output directory is only used to write files generated by test
    // cases and may therefore not exist yet
    File out = new File(outputDir);
    if (!out.exists()) {
      out.mkdirs();
    }
    // Those directories are only used in read-only mode
    String refDir = baseDir + FS + "test";
    dataDir = refDir + FS + "data";
    baselineDir = refDir + FS + "baseline";
  }
 

  /**
   * Constructor for a new informa specific test case. The base directory
   * is calculated from one of the following system properties (order matters):
   * <code>INFORMA_HOME, basedir, user.dir</code>
   *
   * @param name the name of the test case (read method, thanks JUnit)
   */
  public InformaTestCase(String testcase_name, String method_name) {
    super(method_name);
    this.method_name = method_name;
    this.testcase_name = testcase_name;
  }

  /**
   * @return The directory from which we can retrieve test relevant data.
   */
  public static String getDataDir() {
    return dataDir;
  }
 
  /**
   * @return The directory to store the full-text index in.
   */
  public static String getIndexDir() {
    return indexDir;
  }

  /**
   * @return The directory where our test might want to write a produced
   *         file to.
   */ 
  public static String getOutputDir() {
    return outputDir;
  }

  /**
   * @return The directory containing the gold files to compare the
   *         files generated by the current test runs with.
   */
  public static String getBaselineDir() {
    return baselineDir;
  }

  /**
   * Returns the name of the testcase inclusive the class.
   */
  public String getName() {
    return testcase_name + "." + method_name;
  }
 
  // =====================================================================
  // internal helper methods
  // =====================================================================
 
  protected ItemIF searchForItem(ChannelIF chn, String itmTitle) {
    ItemIF lookup_item = null;
    Iterator it = chn.getItems().iterator();
    while (it.hasNext()) {
      ItemIF item = (ItemIF) it.next();
      assertNotNull("Item has no title", item.getTitle());
      assertNotNull("Item has no link", item.getLink());
      // logger.debug("title: <" + item.getTitle() + ">");
      if (item.getTitle().startsWith(itmTitle)) {
        lookup_item = item;
        break;
      }
    }
    return lookup_item;
  }

}
TOP

Related Classes of de.nava.informa.utils.InformaTestCase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.