KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > search > extractors > TestRtfExtraction


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/search/extractors/TestRtfExtraction.java,v $
3  * Date : $Date: 2005/06/23 11:12:02 $
4  * Version: $Revision: 1.4 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31  
32 package org.opencms.search.extractors;
33
34 import java.io.InputStream JavaDoc;
35
36 import junit.framework.TestCase;
37
38 /**
39  * Tests the text extraction form a RTF file.<p>
40  */

41 public class TestRtfExtraction extends TestCase {
42     
43     /**
44      * Default JUnit constructor.<p>
45      *
46      * @param arg0 JUnit parameters
47      */

48     public TestRtfExtraction(String JavaDoc arg0) {
49         super(arg0);
50     }
51     
52     /**
53      * Tests the basic RTF extraction.<p>
54      *
55      * @throws Exception if the test fails
56      */

57     public void testBasicRtfExtration() throws Exception JavaDoc {
58         
59         // open an input stream for the test file
60
InputStream JavaDoc in = getClass().getClassLoader().getResourceAsStream("org/opencms/search/extractors/test1.rtf");
61         
62         // extract the content
63
I_CmsExtractionResult extractionResult = CmsExtractorRtf.getExtractor().extractText(in);
64         String JavaDoc result = extractionResult.getContent();
65         
66         System.out.println("---------------------------------------------------------------");
67         System.out.println("Extracted from RTF:");
68         System.out.println(result);
69         
70         assertTrue(result.indexOf("Alkacon Software") > -1);
71         assertTrue(result.indexOf("The OpenCms experts") > -1);
72         assertTrue(result.indexOf("Some content here.") > -1);
73         assertTrue(result.indexOf("Some content there.") > -1);
74         assertTrue(result.indexOf("Some content on a second sheet.") > -1);
75         assertTrue(result.indexOf("Some content on the third sheet.") > -1);
76         // NOTE: Euro symbol conversion fails - possible reason is that Swing classes handle only ISO
77
assertTrue(result.indexOf("\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df") > -1);
78     }
79 }
80
Popular Tags