Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
77   187   11   12,83
0   105   0,14   6
6     1,83  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  SearchIndexTest       Line # 42 77 0% 11 10 88% 0.8795181
 
  (10)
 
1    /*
2    * Copyright (c) 2003-2006, Simon Brown
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * - Redistributions of source code must retain the above copyright
9    * notice, this list of conditions and the following disclaimer.
10    *
11    * - Redistributions in binary form must reproduce the above copyright
12    * notice, this list of conditions and the following disclaimer in
13    * the documentation and/or other materials provided with the
14    * distribution.
15    *
16    * - Neither the name of Pebble nor the names of its contributors may
17    * be used to endorse or promote products derived from this software
18    * without specific prior written permission.
19    *
20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30    * POSSIBILITY OF SUCH DAMAGE.
31    */
32    package net.sourceforge.pebble.index;
33   
34    import net.sourceforge.pebble.domain.*;
35    import net.sourceforge.pebble.search.SearchResults;
36   
37    /**
38    * Tests for the SearchResults class.
39    *
40    * @author Simon Brown
41    */
 
42    public class SearchIndexTest extends SingleBlogTestCase {
43   
44    private SearchIndex index;
45   
 
46  10 toggle protected void setUp() throws Exception {
47  10 super.setUp();
48   
49  10 index = new SearchIndex(blog);
50  10 index.clear();
51    }
52   
53    /**
54    * Tests that a search can be performed on a blog entry title.
55    */
 
56  2 toggle public void testSearchOnTitle() {
57  2 try {
58  2 SearchResults results = index.search("jsp");
59  2 assertEquals(0, results.getNumberOfHits());
60   
61  2 BlogEntry blogEntry = new BlogEntry(blog);
62  2 blogEntry.setTitle("Some JSP topic");
63  2 blogEntry.setPublished(true);
64  2 index.index(blogEntry);
65   
66  2 results = index.search("jsp");
67  2 assertEquals(1, results.getNumberOfHits());
68    } catch (Exception e) {
69  0 e.printStackTrace();
70  0 fail();
71    }
72    }
73   
74    /**
75    * Tests that a search can be performed on a blog entry body.
76    */
 
77  2 toggle public void testSearchOnBody() {
78  2 try {
79  2 SearchResults results = index.search("jsp");
80  2 assertEquals(0, results.getNumberOfHits());
81   
82  2 BlogEntry blogEntry = new BlogEntry(blog);
83  2 blogEntry.setBody("Some JSP topic");
84  2 blogEntry.setPublished(true);
85  2 index.index(blogEntry);
86   
87  2 results = index.search("jsp");
88  2 assertEquals(1, results.getNumberOfHits());
89    } catch (Exception e) {
90  0 e.printStackTrace();
91  0 fail();
92    }
93    }
94   
95    /**
96    * Tests that a search can be performed on a category.
97    */
 
98  2 toggle public void testSearchOnCategory() {
99  2 try {
100  2 blog.addCategory(new Category("/category1", "Category 1"));
101  2 blog.addCategory(new Category("/category2", "Category 2"));
102   
103  2 SearchResults results = index.search("category:/category1");
104  2 assertEquals(0, results.getNumberOfHits());
105   
106  2 BlogEntry blogEntry = new BlogEntry(blog);
107  2 blogEntry.addCategory(blog.getCategory("/category1"));
108  2 blogEntry.setPublished(true);
109  2 index.index(blogEntry);
110   
111  2 results = index.search("category:/category1");
112  2 assertEquals(1, results.getNumberOfHits());
113   
114    // and add another category
115  2 blogEntry.addCategory(blog.getCategory("/category2"));
116  2 index.index(blogEntry);
117   
118  2 results = index.search("category:/category1");
119  2 assertEquals(1, results.getNumberOfHits());
120  2 results = index.search("category:/category2");
121  2 assertEquals(1, results.getNumberOfHits());
122    } catch (Exception e) {
123  0 e.printStackTrace();
124  0 fail();
125    }
126    }
127   
128    /**
129    * Tests that searches work across comments.
130    */
 
131  2 toggle public void testSearchOnComments() {
132  2 try {
133  2 SearchResults results = index.search("swing");
134  2 assertEquals(0, results.getNumberOfHits());
135   
136  2 BlogEntry blogEntry = new BlogEntry(blog);
137  2 blogEntry.addCategory(blog.getCategory("/category1"));
138  2 blogEntry.setPublished(true);
139  2 index.index(blogEntry);
140   
141    // should be no hits returned yet
142  2 results = index.search("swing");
143  2 assertEquals(0, results.getNumberOfHits());
144   
145    // now add some comments
146  2 Comment comment = blogEntry.createComment("Comment title", "Comment body", "Some author", "me@somedomain.com", "http://www.google.com", "127.0.0.1");
147  2 blogEntry.addComment(comment);
148  2 index.index(blogEntry);
149  2 results = index.search("swing");
150  2 assertEquals(0, results.getNumberOfHits());
151   
152  2 comment = blogEntry.createComment("Comment title", "Comment body with Swing in it", "Some author", "me@somedomain.com", "http://www.google.com", "127.0.0.1");
153  2 blogEntry.addComment(comment);
154  2 index.index(blogEntry);
155  2 results = index.search("swing");
156  2 assertEquals(1, results.getNumberOfHits());
157    } catch (Exception e) {
158  0 e.printStackTrace();
159  0 fail();
160    }
161    }
162   
163    /**
164    * Tests that blog entries can be removed from the index.
165    */
 
166  2 toggle public void testSearchOnRemovedBlogEntry() {
167  2 try {
168  2 BlogEntry blogEntry = new BlogEntry(blog);
169  2 blogEntry.setTitle("Some JSP topic");
170  2 blogEntry.setPublished(true);
171  2 index.index(blogEntry);
172   
173  2 SearchResults results = index.search("jsp");
174  2 assertEquals(1, results.getNumberOfHits());
175   
176    // and now remove the blog entry, checking that the search no longer
177    // returns that hit
178  2 index.unindex(blogEntry);
179  2 results = index.search("jsp");
180  2 assertEquals(0, results.getNumberOfHits());
181    } catch (Exception e) {
182  0 e.printStackTrace();
183  0 fail();
184    }
185    }
186   
187    }