KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > parse > pdf > TestPdfParser


1 /* Copyright (c) 2004 The Nutch Organization. All rights reserved. */
2 /* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
3
4 package net.nutch.parse.pdf;
5
6 import net.nutch.protocol.ProtocolFactory;
7 import net.nutch.protocol.Protocol;
8 import net.nutch.protocol.Content;
9 import net.nutch.protocol.ProtocolException;
10
11 import net.nutch.parse.ParserFactory;
12 import net.nutch.parse.Parser;
13 import net.nutch.parse.Parse;
14 import net.nutch.parse.ParseException;
15
16 import junit.framework.TestCase;
17
18 /**
19  * Unit tests for PdfParser.
20  *
21  * @author John Xing
22  */

23 public class TestPdfParser extends TestCase {
24
25   private String JavaDoc fileSeparator = System.getProperty("file.separator");
26   // This system property is defined in ./src/plugin/build-plugin.xml
27
private String JavaDoc sampleDir = System.getProperty("test.data",".");
28   // Make sure sample files are copied to "test.data" as specified in
29
// ./src/plugin/parse-pdf/build.xml during plugin compilation.
30
// Check ./src/plugin/parse-pdf/sample/README.txt for what they are.
31
private String JavaDoc[] sampleFiles = {"pdftest.pdf"};
32
33   private String JavaDoc expectedText = "A VERY SMALL PDF FILE";
34
35   public TestPdfParser(String JavaDoc name) {
36     super(name);
37   }
38
39   protected void setUp() {}
40
41   protected void tearDown() {}
42
43   public void testIt() throws ProtocolException, ParseException {
44     String JavaDoc urlString;
45     Protocol protocol;
46     Content content;
47     Parser parser;
48     Parse parse;
49
50     for (int i=0; i<sampleFiles.length; i++) {
51       urlString = "file:" + sampleDir + fileSeparator + sampleFiles[i];
52
53       protocol = ProtocolFactory.getProtocol(urlString);
54       content = protocol.getContent(urlString);
55
56       parser = ParserFactory.getParser(content.getContentType(), urlString);
57       parse = parser.getParse(content);
58
59       int index = parse.getText().indexOf(expectedText);
60       assertTrue(index > 0);
61     }
62   }
63
64 }
65
Popular Tags