Log in Help
Print
Homegatewikicowtestunitgateyamtranslate 〉 TreeTranslatorTests.java
 
/*
 *  TreeTranslatorTests.java
 *  Copyright (c) 1998-2008, The University of Sheffield.
 *
 *  This code is from the GATE project (http://gate.ac.uk/) and is free
 *  software licenced under the GNU General Public License version 3. It is
 *  distributed without any warranty. For more details see COPYING.txt in the
 *  top level directory (or at http://gatewiki.sf.net/COPYING.txt).
 *  
 *  Hamish Cunningham, 3rd May 2006
 */

package gate.yam.translate;

import java.io.*;
import junit.framework.*;
import gate.util.*;
import gate.yam.*;


/**
 * Unit test for TreeTranslator.
 */
public class TreeTranslatorTests extends AbstractTranslatorTest
{
  /** Create the test case. */
  public TreeTranslatorTests(String testName) { super(testName); }

  /** Paths of example test files. */
  public String[] getTestFilePaths() {
    String testFilePaths[] = {
//      "/yam-comprehensive",
      "/yam-pretty",
      "/yam-scratch",
      "/yam-lists",
      "/yam-small-error",
      "/yam-errors",
      "/yam-minimal",
      "/yam-urls",
      "/yam-first"
    };
    return testFilePaths;
  }

  /** Suffix of input files. */
  public String getInputSuffix() { return "yam"; }

  /** Suffix of output files. */
  public String[] getOutputSuffixes() {
    String outputSuffixes[] = {
      "tree"
    };
    return outputSuffixes;
  }

  /** Run the translator and get the response */
  public Writer doTranslation(
    Reader testReader, Writer responseWriter, String outputType,
    String testName
  ) throws Exception {
    // find the source directory
    String testFilePath =
      this.getClass().getResource(testName + ".yam").getPath();
    File testFileDir = new File(testFilePath).getParentFile();

    if(outputType.equals("tree")) {
      YamCommand yam = new YamCommand();
      yam.translate(
        testReader, responseWriter, YamFile.FileType.TREE, testFileDir
      );
    } else {
      throw new GateException("unknown output type " + outputType);
    }
    return responseWriter;
  }
}