|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This report was generated with an evaluation server license. Purchase Clover or configure your license. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CategoryIndexTest | Line # 41 | 17 | 0% | 3 | 0 | 100% |
1.0
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| (4) | |||
| Result | |||
|
0.4
|
net.sourceforge.pebble.index.CategoryIndexTest.testUnindexBlogEntry
net.sourceforge.pebble.index.CategoryIndexTest.testUnindexBlogEntry
|
1 PASS | |
|
0.4
|
net.sourceforge.pebble.index.CategoryIndexTest.testUnindexBlogEntry
net.sourceforge.pebble.index.CategoryIndexTest.testUnindexBlogEntry
|
1 PASS | |
|
0.35
|
net.sourceforge.pebble.index.CategoryIndexTest.testIndexBlogEntry
net.sourceforge.pebble.index.CategoryIndexTest.testIndexBlogEntry
|
1 PASS | |
|
0.35
|
net.sourceforge.pebble.index.CategoryIndexTest.testIndexBlogEntry
net.sourceforge.pebble.index.CategoryIndexTest.testIndexBlogEntry
|
1 PASS | |
| 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 CategoryIndex class. | |
| 38 | * | |
| 39 | * @author Simon Brown | |
| 40 | */ | |
| 41 | public class CategoryIndexTest extends SingleBlogTestCase { | |
| 42 | ||
| 43 | private CategoryIndex index; | |
| 44 | private Category javaCategory; | |
| 45 | ||
| 46 | 4 |
protected void setUp() throws Exception { |
| 47 | 4 | super.setUp(); |
| 48 | ||
| 49 | 4 | this.index = new CategoryIndex(blog); |
| 50 | 4 | javaCategory = new Category("/java", "Java"); |
| 51 | 4 | blog.addCategory(javaCategory); |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * Tests that a single blog entry can be indexed. | |
| 56 | */ | |
| 57 | 2 |
public void testIndexBlogEntry() throws Exception { |
| 58 | 2 | BlogEntry blogEntry = new BlogEntry(blog); |
| 59 | 2 | blogEntry.addCategory(javaCategory); |
| 60 | 2 | blogEntry.setPublished(true); |
| 61 | 2 | index.index(blogEntry); |
| 62 | ||
| 63 | 2 | assertEquals(1, javaCategory.getNumberOfBlogEntries()); |
| 64 | 2 | assertTrue(index.getRecentBlogEntries(javaCategory).contains(blogEntry.getId())); |
| 65 | } | |
| 66 | ||
| 67 | /** | |
| 68 | * Tests that a single blog entry can be unindexed. | |
| 69 | */ | |
| 70 | 2 |
public void testUnindexBlogEntry() throws Exception { |
| 71 | 2 | BlogEntry blogEntry = new BlogEntry(blog); |
| 72 | 2 | blogEntry.addCategory(javaCategory); |
| 73 | 2 | index.index(blogEntry); |
| 74 | ||
| 75 | 2 | blogEntry.removeAllCategories(); |
| 76 | 2 | index.unindex(blogEntry); |
| 77 | ||
| 78 | 2 | assertEquals(0, javaCategory.getNumberOfBlogEntries()); |
| 79 | 2 | assertFalse(index.getRecentBlogEntries(javaCategory).contains(blogEntry.getId())); |
| 80 | } | |
| 81 | ||
| 82 | // /** | |
| 83 | // * Tests that category/tag statistics are updated. | |
| 84 | // */ | |
| 85 | // public void testCategoryAndTagStatisticsUpdated() throws Exception { | |
| 86 | // CategoryBuilder builder = new CategoryBuilder(blog); | |
| 87 | // Category java = new Category("/java", "Java"); | |
| 88 | // builder.addCategory(java); | |
| 89 | // java.setTags("java"); | |
| 90 | // Category apple = new Category("/apple", "Apple"); | |
| 91 | // builder.addCategory(apple); | |
| 92 | // apple.setTags("apple"); | |
| 93 | // Category root = builder.getRootCategory(); | |
| 94 | // root.setTags("myblog"); | |
| 95 | // blog.setRootCategory(root); | |
| 96 | // BlogEntry blogEntry = new BlogEntry(blog); | |
| 97 | // blogEntry.addCategory(java); | |
| 98 | // blogEntry.setTags("junit"); | |
| 99 | // | |
| 100 | // assertEquals(0, root.getNumberOfBlogEntries()); | |
| 101 | // assertEquals(0, java.getNumberOfBlogEntries()); | |
| 102 | // assertEquals(0, apple.getNumberOfBlogEntries()); | |
| 103 | // assertEquals(0, blog.getTagIndex().getTag("myblog").getNumberOfBlogEntries()); | |
| 104 | // assertEquals(0, blog.getTagIndex().getTag("java").getNumberOfBlogEntries()); | |
| 105 | // assertEquals(0, blog.getTagIndex().getTag("apple").getNumberOfBlogEntries()); | |
| 106 | // assertEquals(0, blog.getTagIndex().getTag("junit").getNumberOfBlogEntries()); | |
| 107 | // assertTrue(blog.getTagIndex().getTags().isEmpty()); | |
| 108 | // | |
| 109 | // // blog entry added | |
| 110 | // BlogService service = new BlogService(); | |
| 111 | // service.putBlogEntry(blogEntry); | |
| 112 | // | |
| 113 | // assertEquals(1, root.getNumberOfBlogEntries()); | |
| 114 | // assertEquals(1, java.getNumberOfBlogEntries()); | |
| 115 | // assertEquals(0, apple.getNumberOfBlogEntries()); | |
| 116 | // assertEquals(1, blog.getTagIndex().getTag("myblog").getNumberOfBlogEntries()); | |
| 117 | // assertEquals(1, blog.getTagIndex().getTag("java").getNumberOfBlogEntries()); | |
| 118 | // assertEquals(0, blog.getTagIndex().getTag("apple").getNumberOfBlogEntries()); | |
| 119 | // assertEquals(1, blog.getTagIndex().getTag("junit").getNumberOfBlogEntries()); | |
| 120 | // assertFalse(blog.getTagIndex().getTags().contains(blog.getTagIndex().getTag("apple"))); | |
| 121 | // | |
| 122 | // // blog entry changed - category added | |
| 123 | // blogEntry.addCategory(apple); | |
| 124 | // service.putBlogEntry(blogEntry); | |
| 125 | // assertEquals(1, root.getNumberOfBlogEntries()); | |
| 126 | // assertEquals(1, java.getNumberOfBlogEntries()); | |
| 127 | // assertEquals(1, apple.getNumberOfBlogEntries()); | |
| 128 | // assertEquals(1, blog.getTagIndex().getTag("myblog").getNumberOfBlogEntries()); | |
| 129 | // assertEquals(1, blog.getTagIndex().getTag("java").getNumberOfBlogEntries()); | |
| 130 | // assertEquals(1, blog.getTagIndex().getTag("apple").getNumberOfBlogEntries()); | |
| 131 | // assertEquals(1, blog.getTagIndex().getTag("junit").getNumberOfBlogEntries()); | |
| 132 | // | |
| 133 | // // blog entry changed - category changed | |
| 134 | // blogEntry.removeAllCategories(); | |
| 135 | // blogEntry.addCategory(apple); | |
| 136 | // service.putBlogEntry(blogEntry); | |
| 137 | // assertEquals(1, root.getNumberOfBlogEntries()); | |
| 138 | // assertEquals(0, java.getNumberOfBlogEntries()); | |
| 139 | // assertEquals(1, apple.getNumberOfBlogEntries()); | |
| 140 | // assertEquals(1, blog.getTagIndex().getTag("myblog").getNumberOfBlogEntries()); | |
| 141 | // assertEquals(0, blog.getTagIndex().getTag("java").getNumberOfBlogEntries()); | |
| 142 | // assertEquals(1, blog.getTagIndex().getTag("apple").getNumberOfBlogEntries()); | |
| 143 | // assertEquals(1, blog.getTagIndex().getTag("junit").getNumberOfBlogEntries()); | |
| 144 | // assertFalse(blog.getTagIndex().getTags().contains(blog.getTagIndex().getTag("java"))); | |
| 145 | // | |
| 146 | // // blog entry changed - tag removed | |
| 147 | // blogEntry.setTags(""); | |
| 148 | // service.putBlogEntry(blogEntry); | |
| 149 | // assertEquals(1, root.getNumberOfBlogEntries()); | |
| 150 | // assertEquals(0, java.getNumberOfBlogEntries()); | |
| 151 | // assertEquals(1, apple.getNumberOfBlogEntries()); | |
| 152 | // assertEquals(1, blog.getTagIndex().getTag("myblog").getNumberOfBlogEntries()); | |
| 153 | // assertEquals(0, blog.getTagIndex().getTag("java").getNumberOfBlogEntries()); | |
| 154 | // assertEquals(1, blog.getTagIndex().getTag("apple").getNumberOfBlogEntries()); | |
| 155 | // assertEquals(0, blog.getTagIndex().getTag("junit").getNumberOfBlogEntries()); | |
| 156 | // assertFalse(blog.getTagIndex().getTags().contains(blog.getTagIndex().getTag("java"))); | |
| 157 | // assertFalse(blog.getTagIndex().getTags().contains(blog.getTagIndex().getTag("junit"))); | |
| 158 | // | |
| 159 | // // blog entry changed - tag added | |
| 160 | // blogEntry.setTags("junit"); | |
| 161 | // service.putBlogEntry(blogEntry); | |
| 162 | // assertEquals(1, root.getNumberOfBlogEntries()); | |
| 163 | // assertEquals(0, java.getNumberOfBlogEntries()); | |
| 164 | // assertEquals(1, apple.getNumberOfBlogEntries()); | |
| 165 | // assertEquals(1, blog.getTagIndex().getTag("myblog").getNumberOfBlogEntries()); | |
| 166 | // assertEquals(0, blog.getTagIndex().getTag("java").getNumberOfBlogEntries()); | |
| 167 | // assertEquals(1, blog.getTagIndex().getTag("apple").getNumberOfBlogEntries()); | |
| 168 | // assertEquals(1, blog.getTagIndex().getTag("junit").getNumberOfBlogEntries()); | |
| 169 | // assertFalse(blog.getTagIndex().getTags().contains(blog.getTagIndex().getTag("java"))); | |
| 170 | // | |
| 171 | // // blog entry rejected | |
| 172 | // blogEntry.setRejected(); | |
| 173 | // service.putBlogEntry(blogEntry); | |
| 174 | // assertEquals(0, root.getNumberOfBlogEntries()); | |
| 175 | // assertEquals(0, java.getNumberOfBlogEntries()); | |
| 176 | // assertEquals(0, apple.getNumberOfBlogEntries()); | |
| 177 | // assertEquals(0, blog.getTagIndex().getTag("myblog").getNumberOfBlogEntries()); | |
| 178 | // assertEquals(0, blog.getTagIndex().getTag("java").getNumberOfBlogEntries()); | |
| 179 | // assertEquals(0, blog.getTagIndex().getTag("apple").getNumberOfBlogEntries()); | |
| 180 | // assertEquals(0, blog.getTagIndex().getTag("junit").getNumberOfBlogEntries()); | |
| 181 | // assertTrue(blog.getTagIndex().getTags().isEmpty()); | |
| 182 | // | |
| 183 | // // blog entry approved | |
| 184 | // blogEntry.setApproved(); | |
| 185 | // service.putBlogEntry(blogEntry); | |
| 186 | // assertEquals(1, root.getNumberOfBlogEntries()); | |
| 187 | // assertEquals(0, java.getNumberOfBlogEntries()); | |
| 188 | // assertEquals(1, apple.getNumberOfBlogEntries()); | |
| 189 | // assertEquals(1, blog.getTagIndex().getTag("myblog").getNumberOfBlogEntries()); | |
| 190 | // assertEquals(0, blog.getTagIndex().getTag("java").getNumberOfBlogEntries()); | |
| 191 | // assertEquals(1, blog.getTagIndex().getTag("apple").getNumberOfBlogEntries()); | |
| 192 | // assertEquals(1, blog.getTagIndex().getTag("junit").getNumberOfBlogEntries()); | |
| 193 | // assertFalse(blog.getTagIndex().getTags().contains(blog.getTagIndex().getTag("java"))); | |
| 194 | // | |
| 195 | // // blog entry removed | |
| 196 | // service.removeBlogEntry(blogEntry); | |
| 197 | // assertEquals(0, root.getNumberOfBlogEntries()); | |
| 198 | // assertEquals(0, java.getNumberOfBlogEntries()); | |
| 199 | // assertEquals(0, apple.getNumberOfBlogEntries()); | |
| 200 | // assertEquals(0, blog.getTagIndex().getTag("myblog").getNumberOfBlogEntries()); | |
| 201 | // assertEquals(0, blog.getTagIndex().getTag("java").getNumberOfBlogEntries()); | |
| 202 | // assertEquals(0, blog.getTagIndex().getTag("apple").getNumberOfBlogEntries()); | |
| 203 | // assertEquals(0, blog.getTagIndex().getTag("junit").getNumberOfBlogEntries()); | |
| 204 | // assertTrue(blog.getTagIndex().getTags().isEmpty()); | |
| 205 | // } | |
| 206 | // | |
| 207 | } | |
|
||||||||||||