/*
 *  TestMSExcelParser.java 
 *  Based on the Unit Tests for MSWordParser by John Xing
 */
package org.apache.nutch.parse.msexcel;

import org.apache.nutch.protocol.ProtocolFactory;
import org.apache.nutch.protocol.Protocol;
import org.apache.nutch.protocol.Content;
import org.apache.nutch.protocol.ProtocolException;

import org.apache.nutch.parse.ParserFactory;
import org.apache.nutch.parse.Parser;
import org.apache.nutch.parse.Parse;
import org.apache.nutch.parse.ParseException;

import junit.framework.TestCase;

/** 
 * Based on Unit tests for MSWordParser by John Xing
 *
 * @author Rohit Kulkarni & Ashish Vaidya
 */
public class TestMSExcelParser extends TestCase {

  private String fileSeparator = System.getProperty("file.separator");
  // This system property is defined in ./src/plugin/build-plugin.xml
  private String sampleDir = System.getProperty("test.data",".");
  
  // Make sure sample files are copied to "test.data"
  
  private String[] sampleFiles = {"test.xls"};

  private String expectedText = "BitStream test.xls 321654.0 Apache incubator 1234.0 Doug Cutting 89078.0 CS 599 Search Engines Spring 2005.0 SBC 1234.0 764893.0 Java NUTCH!! ";

  public TestMSExcelParser(String name) { 
    super(name); 
  }

  protected void setUp() {}

  protected void tearDown() {}

  public void testIt() throws ProtocolException, ParseException {
    String urlString;
    Protocol protocol;
    Content content;
    Parser parser;
    Parse parse;

    for (int i = 0; i < sampleFiles.length; i++) {
      urlString = "file:" + sampleDir + fileSeparator + sampleFiles[i];

      protocol = ProtocolFactory.getProtocol(urlString);
      content = protocol.getContent(urlString);

      parser = ParserFactory.getParser(content.getContentType(), urlString);
      parse = parser.getParse(content);

      assertTrue(parse.getText().equals(expectedText));
    }
  }

}

@@ -127,16 +127,116 @@
 excel;%0A%0A
+// Nutch imports%0Aimport org.apache.nutch.crawl.CrawlDatum;%0Aimport org.apache.nutch.parse.ParseUtil;%0A
 import o
@@ -410,25 +410,24 @@
 lException;%0A
-%0A
 import org.a
@@ -449,24 +449,16 @@
 se.Parse
-rFactory
 ;%0Aimport
@@ -486,17 +486,25 @@
 se.Parse
-r
+Exception
 ;%0Aimport
@@ -525,100 +525,182 @@
 tch.
-parse.Parse;%0Aimport org.apache.nutch.parse.ParseExcep
+util.NutchConfiguration;%0A%0A// JUnit imports%0Aimport junit.framework.TestCase;%0A%0A// Hadoop imports%0Aimport org.apache.hadoop.conf.Configura
 tion;%0A
-%0A
 import 
-junit.framework.TestCase;
+org.apache.hadoop.io.UTF8;%0A
 %0A%0A/*
@@ -1238,16 +1238,53 @@
  Apache 
+%22 +%0A                                %22
 incubato
@@ -1313,16 +1313,53 @@
 89078.0 
+%22 +%0A                                %22
 CS 599 S
@@ -1390,16 +1390,53 @@
 5.0 SBC 
+%22 +%0A                                %22
 1234.0 7
@@ -1523,76 +1523,14 @@
 me);
- 
 %0A  %7D%0A%0A
-  protected void setUp() %7B%7D%0A%0A  protected void tearDown() %7B%7D%0A%0A
   pu
@@ -1591,16 +1591,17 @@
 ption %7B%0A
+%0A
     Stri
@@ -1671,16 +1671,69 @@
 arse
-r
  parse
-r
+;%0A%0A    Configuration conf = NutchConfiguration.create()
 ;%0A  
@@ -1735,32 +1735,115 @@
 );%0A    Parse
+Util
  parse
+r = new ParseUtil(conf);%0A    ProtocolFactory factory = new ProtocolFactory(conf)
 ;
-%0A
 %0A    for (in
@@ -1972,25 +1972,17 @@
 tocol = 
-ProtocolF
+f
 actory.g
@@ -2036,136 +2036,173 @@
 .get
-Content(urlString);%0A%0A      parser = ParserFactory.getParser(content.getContentType(), urlString);%0A      parse = parser.getParse(
+ProtocolOutput(new UTF8(urlString),%0A                                           new CrawlDatum()).getContent();%0A      parse = parser.parseByParserId(%22parse-msexcel%22, 
 cont

Fix parse-msexcel unit tests