Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
16   179   3   5,33
0   26   0,19   3
3     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  TagIndexTest       Line # 41 16 0% 3 0 100% 1.0
 
  (4)
 
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   
36    /**
37    * Tests for the TagIndex class.
38    *
39    * @author Simon Brown
40    */
 
41    public class TagIndexTest extends SingleBlogTestCase {
42   
43    private TagIndex index;
44   
 
45  4 toggle protected void setUp() throws Exception {
46  4 super.setUp();
47   
48  4 this.index = new TagIndex(blog);
49    }
50   
51    /**
52    * Tests that a single blog entry can be indexed.
53    */
 
54  2 toggle public void testIndexBlogEntry() throws Exception {
55  2 BlogEntry blogEntry = new BlogEntry(blog);
56  2 blogEntry.setTags("junit");
57  2 blogEntry.setPublished(true);
58  2 index.index(blogEntry);
59   
60  2 assertEquals(1, index.getTag("junit").getNumberOfBlogEntries());
61  2 assertTrue(index.getTags().contains(new Tag("junit", blog)));
62  2 assertEquals(1, index.getTags().size());
63    }
64   
65    /**
66    * Tests that a single blog entry can be unindexed.
67    */
 
68  2 toggle public void testUnindexBlogEntry() throws Exception {
69  2 BlogEntry blogEntry = new BlogEntry(blog);
70  2 blogEntry.setTags("junit");
71  2 index.index(blogEntry);
72   
73  2 blogEntry.setTags("");
74  2 index.unindex(blogEntry);
75   
76  2 assertEquals(0, index.getTag("junit").getNumberOfBlogEntries());
77  2 assertEquals(0, index.getTags().size());
78    }
79   
80    // /**
81    // * Tests that category/tag statistics are updated.
82    // */
83    // public void testTagStatisticsUpdatedWithCategories() throws Exception {
84    // CategoryBuilder builder = new CategoryBuilder(blog);
85    // Category java = new Category("/java", "Java");
86    // builder.addCategory(java);
87    // java.setTags("java");
88    // Category apple = new Category("/apple", "Apple");
89    // builder.addCategory(apple);
90    // apple.setTags("apple");
91    // Category root = builder.getRootCategory();
92    // root.setTags("myblog");
93    // blog.setRootCategory(root);
94    //
95    // BlogEntry blogEntry = new BlogEntry(blog);
96    // blogEntry.addCategory(java);
97    // blogEntry.setTags("junit");
98    //
99    // assertEquals(0, index.getTag("myblog").getNumberOfBlogEntries());
100    // assertEquals(0, index.getTag("java").getNumberOfBlogEntries());
101    // assertEquals(0, index.getTag("apple").getNumberOfBlogEntries());
102    // assertEquals(0, index.getTag("junit").getNumberOfBlogEntries());
103    // assertTrue(index.getTags().isEmpty());
104    //
105    // // blog entry added
106    // BlogService service = new BlogService();
107    // service.putBlogEntry(blogEntry);
108    //
109    // assertEquals(1, index.getTag("myblog").getNumberOfBlogEntries());
110    // assertEquals(1, index.getTag("java").getNumberOfBlogEntries());
111    // assertEquals(0, index.getTag("apple").getNumberOfBlogEntries());
112    // assertEquals(1, index.getTag("junit").getNumberOfBlogEntries());
113    // assertFalse(index.getTags().contains(index.getTag("apple")));
114    //
115    // // blog entry changed - category added
116    // blogEntry.addCategory(apple);
117    // service.putBlogEntry(blogEntry);
118    // assertEquals(1, index.getTag("myblog").getNumberOfBlogEntries());
119    // assertEquals(1, index.getTag("java").getNumberOfBlogEntries());
120    // assertEquals(1, index.getTag("apple").getNumberOfBlogEntries());
121    // assertEquals(1, index.getTag("junit").getNumberOfBlogEntries());
122    //
123    // // blog entry changed - category changed
124    // blogEntry.removeAllCategories();
125    // blogEntry.addCategory(apple);
126    // service.putBlogEntry(blogEntry);
127    // assertEquals(1, index.getTag("myblog").getNumberOfBlogEntries());
128    // assertEquals(0, index.getTag("java").getNumberOfBlogEntries());
129    // assertEquals(1, index.getTag("apple").getNumberOfBlogEntries());
130    // assertEquals(1, index.getTag("junit").getNumberOfBlogEntries());
131    // assertFalse(index.getTags().contains(index.getTag("java")));
132    //
133    // // blog entry changed - tag removed
134    // blogEntry.setTags("");
135    // service.putBlogEntry(blogEntry);
136    // assertEquals(1, index.getTag("myblog").getNumberOfBlogEntries());
137    // assertEquals(0, index.getTag("java").getNumberOfBlogEntries());
138    // assertEquals(1, index.getTag("apple").getNumberOfBlogEntries());
139    // assertEquals(0, index.getTag("junit").getNumberOfBlogEntries());
140    // assertFalse(index.getTags().contains(index.getTag("java")));
141    // assertFalse(index.getTags().contains(index.getTag("junit")));
142    //
143    // // blog entry changed - tag added
144    // blogEntry.setTags("junit");
145    // service.putBlogEntry(blogEntry);
146    // assertEquals(1, index.getTag("myblog").getNumberOfBlogEntries());
147    // assertEquals(0, index.getTag("java").getNumberOfBlogEntries());
148    // assertEquals(1, index.getTag("apple").getNumberOfBlogEntries());
149    // assertEquals(1, index.getTag("junit").getNumberOfBlogEntries());
150    // assertFalse(index.getTags().contains(index.getTag("java")));
151    //
152    // // blog entry rejected
153    // blogEntry.setRejected();
154    // service.putBlogEntry(blogEntry);
155    // assertEquals(0, index.getTag("myblog").getNumberOfBlogEntries());
156    // assertEquals(0, index.getTag("java").getNumberOfBlogEntries());
157    // assertEquals(0, index.getTag("apple").getNumberOfBlogEntries());
158    // assertEquals(0, index.getTag("junit").getNumberOfBlogEntries());
159    // assertTrue(index.getTags().isEmpty());
160    //
161    // // blog entry approved
162    // blogEntry.setApproved();
163    // service.putBlogEntry(blogEntry);
164    // assertEquals(1, index.getTag("myblog").getNumberOfBlogEntries());
165    // assertEquals(0, index.getTag("java").getNumberOfBlogEntries());
166    // assertEquals(1, index.getTag("apple").getNumberOfBlogEntries());
167    // assertEquals(1, index.getTag("junit").getNumberOfBlogEntries());
168    // assertFalse(index.getTags().contains(index.getTag("java")));
169    //
170    // // blog entry removed
171    // service.removeBlogEntry(blogEntry);
172    // assertEquals(0, index.getTag("myblog").getNumberOfBlogEntries());
173    // assertEquals(0, index.getTag("java").getNumberOfBlogEntries());
174    // assertEquals(0, index.getTag("apple").getNumberOfBlogEntries());
175    // assertEquals(0, index.getTag("junit").getNumberOfBlogEntries());
176    // assertTrue(index.getTags().isEmpty());
177    // }
178    //
179    }