KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > search > TestChannelSearcher


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25

26
27 // $Id: TestChannelSearcher.java,v 1.9 2003/09/17 20:22:08 niko_schmuck Exp $
28

29 package de.nava.informa.search;
30
31 import java.io.IOException JavaDoc;
32 import java.net.MalformedURLException JavaDoc;
33 import java.net.URL JavaDoc;
34 import java.util.List JavaDoc;
35
36 import de.nava.informa.core.ChannelGroupIF;
37 import de.nava.informa.core.ChannelIF;
38 import de.nava.informa.core.ItemIF;
39 import de.nava.informa.impl.basic.Channel;
40 import de.nava.informa.impl.basic.ChannelGroup;
41 import de.nava.informa.impl.basic.Item;
42 import de.nava.informa.utils.InformaTestCase;
43
44
45
46 public class TestChannelSearcher extends InformaTestCase {
47
48   ChannelGroupIF channels;
49   ItemIF itemA;
50   long channelId;
51   
52   public TestChannelSearcher(String JavaDoc name) {
53     super("TestChannelSearcher", name);
54   }
55
56   protected void setUp() throws MalformedURLException JavaDoc {
57     ChannelIF channelA = new Channel("example.org");
58     channelId = channelA.getId();
59     itemA = new Item("Java 1.5 out", "Long awaited...",
60                      new URL JavaDoc("http://example.org/1234"));
61     channelA.addItem(itemA);
62     ItemIF itemB = new Item("XML virus found", "All about it here.",
63                             new URL JavaDoc("http://example.org/2345"));
64     channelA.addItem(itemB);
65     ItemIF itemC = new Item("Quiet Slashdot", "No news today.",
66                             new URL JavaDoc("http://example.org/3456"));
67     channelA.addItem(itemC);
68     channels = new ChannelGroup("Default");
69     channels.add(channelA);
70   }
71   
72   public void testIndexItems() throws IOException JavaDoc, QueryParseException {
73     assertEquals("Default", channels.getTitle());
74     ChannelIF channelA = channels.getById(channelId);
75     assertEquals(3, channelA.getItems().size());
76     // create the full-text index
77
ChannelIndexer indexer = new ChannelIndexer(getIndexDir());
78     indexer.indexChannels(true, channels.getAll());
79     assertEquals(getIndexDir(), indexer.getIndexDir());
80     assertEquals(3, indexer.getNrOfIndexedItems());
81     // query the full-text index
82
ChannelSearcher searcher = new ChannelSearcher(getIndexDir());
83     List JavaDoc results = searcher.search(channels, "java");
84     assertEquals(1, results.size());
85     ItemResult result = (ItemResult) results.get(0);
86     assertEquals(itemA, result.getItem());
87     assertEquals(0.63f, result.getScore(), 0.01f);
88   }
89     
90 }
91
Popular Tags