1 package com.atlassian.bonnie.search.extractor;
2
3 import com.atlassian.bonnie.search.Extractor;
4 import com.atlassian.bonnie.search.MockSearchableAttachment;
5 import org.apache.lucene.document.Document;
6
7 public class TestMsExcelContentExtractor extends BaseAttachmentContentExtractorTest
8 {
9 private MockSearchableAttachment excelAttachment;
10
11 public Extractor getExtractor()
12 {
13 return new MsExcelContentExtractor();
14 }
15
16
17
18
19
20
21 public void testSimpleExcelDoc()
22 {
23 assertOnExtractedTextOf(excelAttachment, new String[]{"Apples", "Quantity", "10", "20", "354259021", "1.5", "2.75"}, new String[0]);
24 }
25
26 public void testMultipleOccurrencesOfWordsAreExtracted()
27 {
28 StringBuffer searchableContent = new StringBuffer();
29 extractor.addFields(new Document(), searchableContent, excelAttachment);
30
31
32 int startIndex = 0;
33 int occurrences = 0;
34
35 while ((startIndex = searchableContent.indexOf("Apples", startIndex)) != -1)
36 {
37 occurrences++;
38 startIndex++;
39 }
40
41 assertEquals(3, occurrences);
42 }
43
44 protected void setUp() throws Exception
45 {
46 super.setUp();
47 excelAttachment = createSearchableAttachment("test-attachment-search.xls", "application/excel");
48 }
49
50 protected void tearDown() throws Exception
51 {
52 excelAttachment = null;
53 super.tearDown();
54 }
55 }