KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/search/extractors/TestMsWordExtraction.java,v $
3  * Date : $Date: 2005/06/23 11:12:02 $
4  * Version: $Revision: 1.5 $
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 import java.util.Map JavaDoc;
36
37 import junit.framework.TestCase;
38
39 /**
40  * Tests the text extraction form a Word file.<p>
41  */

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

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

58     public void testBasicWordExtration() throws Exception JavaDoc {
59         
60         // open an input stream for the test file
61
InputStream JavaDoc in = getClass().getClassLoader().getResourceAsStream("org/opencms/search/extractors/test1.doc");
62         
63         // extract the content
64
I_CmsExtractionResult extractionResult = CmsExtractorMsWord.getExtractor().extractText(in);
65         String JavaDoc result = extractionResult.getContent();
66         
67         System.out.println("---------------------------------------------------------------");
68         System.out.println("Extracted from MS Word:");
69         System.out.println(result);
70         
71         assertTrue(result.indexOf("Alkacon Software") > -1);
72         assertTrue(result.indexOf("The OpenCms experts") > -1);
73         assertTrue(result.indexOf("Some content here.") > -1);
74         assertTrue(result.indexOf("Some content there.") > -1);
75         assertTrue(result.indexOf("Some content on a second sheet.") > -1);
76         assertTrue(result.indexOf("Some content on the third sheet.") > -1);
77         assertTrue(result.indexOf("\u00e4\u00f6\u00fc\u00c4\u00d6\u00dc\u00df\u20ac") > -1);
78         
79         Map JavaDoc meta = extractionResult.getMetaInfo();
80         assertEquals("Alkacon Software - The OpenCms experts", meta.get(I_CmsExtractionResult.META_TITLE));
81         assertEquals("This is the subject", meta.get(I_CmsExtractionResult.META_SUBJECT));
82         assertEquals("Alexander Kandzior", meta.get(I_CmsExtractionResult.META_AUTHOR));
83         assertEquals("Alkacon Software", meta.get(I_CmsExtractionResult.META_COMPANY));
84         assertEquals("This is the comment", meta.get(I_CmsExtractionResult.META_COMMENTS));
85         assertEquals("Key1, Key2", meta.get(I_CmsExtractionResult.META_KEYWORDS));
86     }
87 }
88
Popular Tags