| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
package net.sourceforge.pebble.webservice; |
| 33 |
|
|
| 34 |
|
import net.sourceforge.pebble.Constants; |
| 35 |
|
import net.sourceforge.pebble.domain.*; |
| 36 |
|
import org.acegisecurity.GrantedAuthority; |
| 37 |
|
import org.acegisecurity.GrantedAuthorityImpl; |
| 38 |
|
import org.acegisecurity.MockAuthenticationManager; |
| 39 |
|
import org.apache.xmlrpc.XmlRpcException; |
| 40 |
|
|
| 41 |
|
import java.util.Calendar; |
| 42 |
|
import java.util.Hashtable; |
| 43 |
|
import java.util.Vector; |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
@author |
| 49 |
|
|
|
|
|
| 84,8% |
Uncovered Elements: 30 (198) |
Complexity: 44 |
Complexity Density: 0,24 |
|
| 50 |
|
public class MultiBlogMetaWeblogAPIHandlerTest extends MultiBlogTestCase { |
| 51 |
|
|
| 52 |
|
private MetaWeblogAPIHandler handler = new MetaWeblogAPIHandler(); |
| 53 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
| 54 |
26
|
protected void setUp() throws Exception {... |
| 55 |
26
|
super.setUp(); |
| 56 |
|
|
| 57 |
26
|
handler.setAuthenticationManager(new net.sourceforge.pebble.mock.MockAuthenticationManager(true, new GrantedAuthority[] {new GrantedAuthorityImpl(Constants.BLOG_CONTRIBUTOR_ROLE)})); |
| 58 |
26
|
blog1.setProperty(Blog.BLOG_CONTRIBUTORS_KEY, "username"); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
|
|
|
| 55% |
Uncovered Elements: 9 (20) |
Complexity: 11 |
Complexity Density: 0,55 |
1
PASS
|
|
| 64 |
2
|
public void testAuthenticationFailure() {... |
| 65 |
2
|
handler.setAuthenticationManager(new MockAuthenticationManager(false)); |
| 66 |
2
|
try { |
| 67 |
2
|
handler.getCategories("blog1/123", "username", "password"); |
| 68 |
0
|
fail(); |
| 69 |
|
} catch (XmlRpcAuthenticationException xmlrpcae) { |
| 70 |
|
} catch (XmlRpcException xmlrpce) { |
| 71 |
|
} |
| 72 |
2
|
try { |
| 73 |
2
|
handler.editPost("blog1/123", "username", "password", new Hashtable(), true); |
| 74 |
0
|
fail(); |
| 75 |
|
} catch (XmlRpcAuthenticationException xmlrpcae) { |
| 76 |
|
} catch (XmlRpcException xmlrpce) { |
| 77 |
0
|
fail(); |
| 78 |
|
} |
| 79 |
2
|
try { |
| 80 |
2
|
handler.getPost("blog1/123", "username", "password"); |
| 81 |
0
|
fail(); |
| 82 |
|
} catch (XmlRpcAuthenticationException xmlrpcae) { |
| 83 |
|
} catch (XmlRpcException xmlrpce) { |
| 84 |
0
|
fail(); |
| 85 |
|
} |
| 86 |
2
|
try { |
| 87 |
2
|
handler.getRecentPosts("blog1", "username", "password", 10); |
| 88 |
0
|
fail(); |
| 89 |
|
} catch (XmlRpcAuthenticationException xmlrpcae) { |
| 90 |
|
} catch (XmlRpcException xmlrpce) { |
| 91 |
0
|
fail(); |
| 92 |
|
} |
| 93 |
2
|
try { |
| 94 |
2
|
handler.newPost("blog1", "username", "password", new Hashtable(), true); |
| 95 |
0
|
fail(); |
| 96 |
|
} catch (XmlRpcAuthenticationException xmlrpcae) { |
| 97 |
|
} catch (XmlRpcException xmlrpce) { |
| 98 |
0
|
fail(); |
| 99 |
|
} |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
|
|
|
| 66,7% |
Uncovered Elements: 5 (15) |
Complexity: 11 |
Complexity Density: 0,73 |
1
PASS
|
|
| 105 |
2
|
public void testAuthenticationSuccess() {... |
| 106 |
2
|
try { |
| 107 |
2
|
handler.getCategories("blog1/123", "username", "password"); |
| 108 |
|
} catch (XmlRpcAuthenticationException xmlrpcae) { |
| 109 |
0
|
fail(); |
| 110 |
|
} catch (XmlRpcException xmlrpce) { |
| 111 |
|
} |
| 112 |
2
|
try { |
| 113 |
2
|
handler.editPost("blog1/123", "username", "password", new Hashtable(), true); |
| 114 |
|
} catch (XmlRpcAuthenticationException xmlrpcae) { |
| 115 |
0
|
fail(); |
| 116 |
|
} catch (XmlRpcException xmlrpce) { |
| 117 |
|
} |
| 118 |
2
|
try { |
| 119 |
2
|
handler.getPost("blog1/123", "username", "password"); |
| 120 |
|
} catch (XmlRpcAuthenticationException xmlrpcae) { |
| 121 |
0
|
fail(); |
| 122 |
|
} catch (XmlRpcException xmlrpce) { |
| 123 |
|
} |
| 124 |
2
|
try { |
| 125 |
2
|
handler.getRecentPosts("blog1", "username", "password", 10); |
| 126 |
|
} catch (XmlRpcAuthenticationException xmlrpcae) { |
| 127 |
0
|
fail(); |
| 128 |
|
} catch (XmlRpcException xmlrpce) { |
| 129 |
|
} |
| 130 |
2
|
try { |
| 131 |
2
|
handler.newPost("blog1", "username", "password", new Hashtable(), true); |
| 132 |
|
} catch (XmlRpcAuthenticationException xmlrpcae) { |
| 133 |
0
|
fail(); |
| 134 |
|
} catch (XmlRpcException xmlrpce) { |
| 135 |
|
} |
| 136 |
|
} |
| 137 |
|
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 138 |
2
|
public void testGetRecentPostsFromEmptyBlog() {... |
| 139 |
2
|
try { |
| 140 |
2
|
Vector posts = handler.getRecentPosts("blog1", "username", "password", 3); |
| 141 |
2
|
assertTrue(posts.isEmpty()); |
| 142 |
|
} catch (Exception e) { |
| 143 |
0
|
e.printStackTrace(); |
| 144 |
0
|
fail(); |
| 145 |
|
} |
| 146 |
|
} |
| 147 |
|
|
|
|
|
| 94,3% |
Uncovered Elements: 2 (35) |
Complexity: 2 |
Complexity Density: 0,06 |
1
PASS
|
|
| 148 |
2
|
public void testGetRecentPosts() {... |
| 149 |
2
|
try { |
| 150 |
2
|
BlogService service = new BlogService(); |
| 151 |
|
|
| 152 |
2
|
BlogEntry entry1 = new BlogEntry(blog1); |
| 153 |
2
|
entry1.setTitle("title1"); |
| 154 |
2
|
entry1.setBody("body1"); |
| 155 |
2
|
service.putBlogEntry(entry1); |
| 156 |
|
|
| 157 |
2
|
BlogEntry entry2 = new BlogEntry(blog1); |
| 158 |
2
|
entry2.setTitle("title2"); |
| 159 |
2
|
entry2.setBody("body2"); |
| 160 |
2
|
service.putBlogEntry(entry2); |
| 161 |
|
|
| 162 |
2
|
BlogEntry entry3 = new BlogEntry(blog1); |
| 163 |
2
|
entry3.setTitle("title3"); |
| 164 |
2
|
entry3.setBody("body3"); |
| 165 |
2
|
service.putBlogEntry(entry3); |
| 166 |
|
|
| 167 |
2
|
BlogEntry entry4 = new BlogEntry(blog1); |
| 168 |
2
|
entry4.setTitle("title4"); |
| 169 |
2
|
entry4.setBody("body4"); |
| 170 |
2
|
service.putBlogEntry(entry4); |
| 171 |
|
|
| 172 |
2
|
Vector posts = handler.getRecentPosts("blog1", "username", "password", 3); |
| 173 |
|
|
| 174 |
2
|
assertFalse(posts.isEmpty()); |
| 175 |
2
|
assertEquals(3, posts.size()); |
| 176 |
2
|
Hashtable ht = (Hashtable)posts.get(0); |
| 177 |
2
|
assertEquals("blog1/" + entry4.getId(), ht.get(MetaWeblogAPIHandler.POST_ID)); |
| 178 |
2
|
assertEquals("body4", ht.get(MetaWeblogAPIHandler.DESCRIPTION)); |
| 179 |
2
|
assertEquals("title4", ht.get(MetaWeblogAPIHandler.TITLE)); |
| 180 |
2
|
ht = (Hashtable)posts.get(1); |
| 181 |
2
|
assertEquals("blog1/" + entry3.getId(), ht.get(MetaWeblogAPIHandler.POST_ID)); |
| 182 |
2
|
assertEquals("body3", ht.get(MetaWeblogAPIHandler.DESCRIPTION)); |
| 183 |
2
|
assertEquals("title3", ht.get(MetaWeblogAPIHandler.TITLE)); |
| 184 |
2
|
ht = (Hashtable)posts.get(2); |
| 185 |
2
|
assertEquals("blog1/" + entry2.getId(), ht.get(MetaWeblogAPIHandler.POST_ID)); |
| 186 |
2
|
assertEquals("body2", ht.get(MetaWeblogAPIHandler.DESCRIPTION)); |
| 187 |
2
|
assertEquals("title2", ht.get(MetaWeblogAPIHandler.TITLE)); |
| 188 |
|
} catch (Exception e) { |
| 189 |
0
|
e.printStackTrace(); |
| 190 |
0
|
fail(); |
| 191 |
|
} |
| 192 |
|
} |
| 193 |
|
|
|
|
|
| 90,5% |
Uncovered Elements: 2 (21) |
Complexity: 2 |
Complexity Density: 0,1 |
1
PASS
|
|
| 194 |
2
|
public void testGetPost() {... |
| 195 |
2
|
try { |
| 196 |
2
|
Category category = new Category("/aCategory", "A Category"); |
| 197 |
2
|
blog1.addCategory(category); |
| 198 |
|
|
| 199 |
2
|
BlogService service = new BlogService(); |
| 200 |
2
|
BlogEntry entry = new BlogEntry(blog1); |
| 201 |
2
|
entry.setTitle("title"); |
| 202 |
2
|
entry.setBody("body"); |
| 203 |
2
|
entry.setAuthor("simon"); |
| 204 |
2
|
entry.addCategory(category); |
| 205 |
2
|
service.putBlogEntry(entry); |
| 206 |
|
|
| 207 |
2
|
Hashtable post = handler.getPost("blog1/" + entry.getId(), "username", "password"); |
| 208 |
2
|
assertEquals("title", post.get(MetaWeblogAPIHandler.TITLE)); |
| 209 |
2
|
assertEquals("body", post.get(MetaWeblogAPIHandler.DESCRIPTION)); |
| 210 |
2
|
Vector categories = (Vector)post.get(MetaWeblogAPIHandler.CATEGORIES); |
| 211 |
2
|
assertEquals(1, categories.size()); |
| 212 |
2
|
assertEquals("/aCategory", categories.get(0)); |
| 213 |
2
|
assertEquals(entry.getAuthor(), post.get(MetaWeblogAPIHandler.USER_ID)); |
| 214 |
2
|
assertEquals(entry.getDate(), post.get(MetaWeblogAPIHandler.DATE_CREATED)); |
| 215 |
2
|
assertEquals("blog1/" + entry.getId(), post.get(MetaWeblogAPIHandler.POST_ID)); |
| 216 |
|
} catch (Exception e) { |
| 217 |
0
|
e.printStackTrace(); |
| 218 |
0
|
fail(); |
| 219 |
|
} |
| 220 |
|
} |
| 221 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 222 |
2
|
public void testGetPostWithIdThatDoesntExist() {... |
| 223 |
2
|
String postid = "1234567890123"; |
| 224 |
2
|
try { |
| 225 |
2
|
handler.getPost("blog1/" + postid, "username", "password"); |
| 226 |
0
|
fail(); |
| 227 |
|
} catch (XmlRpcException xmlrpce) { |
| 228 |
2
|
assertEquals("Blog entry with ID of " + postid + " was not found.", xmlrpce.getMessage()); |
| 229 |
|
} |
| 230 |
|
} |
| 231 |
|
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
| 232 |
2
|
public void testGetPostWithNullId() {... |
| 233 |
2
|
try { |
| 234 |
2
|
handler.getPost("blog1/", "username", "password"); |
| 235 |
0
|
fail(); |
| 236 |
|
} catch (XmlRpcException xmlrpce) { |
| 237 |
2
|
assertEquals("Blog entry with ID of was not found.", xmlrpce.getMessage()); |
| 238 |
|
} |
| 239 |
|
} |
| 240 |
|
|
|
|
|
| 89,5% |
Uncovered Elements: 2 (19) |
Complexity: 2 |
Complexity Density: 0,11 |
1
PASS
|
|
| 241 |
2
|
public void testNewPost() {... |
| 242 |
2
|
try { |
| 243 |
2
|
Category category = new Category("/aCategory", "A Category"); |
| 244 |
2
|
blog1.addCategory(category); |
| 245 |
2
|
Hashtable struct = new Hashtable(); |
| 246 |
2
|
struct.put(MetaWeblogAPIHandler.TITLE, "Title"); |
| 247 |
2
|
struct.put(MetaWeblogAPIHandler.DESCRIPTION, "<p>Content</p>"); |
| 248 |
2
|
Vector categories = new Vector(); |
| 249 |
2
|
categories.add(category.getId()); |
| 250 |
2
|
struct.put(MetaWeblogAPIHandler.CATEGORIES, categories); |
| 251 |
|
|
| 252 |
2
|
String postid = handler.newPost("blog1", "username", "password", struct, true); |
| 253 |
|
|
| 254 |
2
|
BlogService service = new BlogService(); |
| 255 |
2
|
BlogEntry entry = service.getBlogEntry(blog1, postid.substring("blog1".length()+1)); |
| 256 |
|
|
| 257 |
2
|
assertEquals("blog1/" + entry.getId(), postid); |
| 258 |
2
|
assertEquals("Title", entry.getTitle()); |
| 259 |
2
|
assertTrue(entry.inCategory(category)); |
| 260 |
2
|
assertEquals("<p>Content</p>", entry.getBody()); |
| 261 |
2
|
assertEquals("username", entry.getAuthor()); |
| 262 |
|
} catch (Exception e) { |
| 263 |
0
|
e.printStackTrace(); |
| 264 |
0
|
fail(); |
| 265 |
|
} |
| 266 |
|
} |
| 267 |
|
|
| 268 |
|
|
| 269 |
|
|
| 270 |
|
|
| 271 |
|
|
|
|
|
| 88,2% |
Uncovered Elements: 2 (17) |
Complexity: 2 |
Complexity Density: 0,12 |
1
PASS
|
|
| 272 |
2
|
public void testNewPostWithCategoryThatDoesntExist() {... |
| 273 |
2
|
try { |
| 274 |
2
|
Hashtable struct = new Hashtable(); |
| 275 |
2
|
struct.put(MetaWeblogAPIHandler.TITLE, "Title"); |
| 276 |
2
|
struct.put(MetaWeblogAPIHandler.DESCRIPTION, "<p>Content</p>"); |
| 277 |
2
|
Vector categories = new Vector(); |
| 278 |
2
|
categories.add("someUnknownCategory"); |
| 279 |
2
|
struct.put(MetaWeblogAPIHandler.CATEGORIES, categories); |
| 280 |
|
|
| 281 |
2
|
String postid = handler.newPost("blog1", "username", "password", struct, true); |
| 282 |
|
|
| 283 |
2
|
BlogService service = new BlogService(); |
| 284 |
2
|
BlogEntry entry = service.getBlogEntry(blog1, postid.substring("blog1".length()+1)); |
| 285 |
|
|
| 286 |
2
|
assertEquals("blog1/" + entry.getId(), postid); |
| 287 |
2
|
assertEquals("Title", entry.getTitle()); |
| 288 |
2
|
assertEquals(0, entry.getCategories().size()); |
| 289 |
2
|
assertEquals("<p>Content</p>", entry.getBody()); |
| 290 |
2
|
assertEquals("username", entry.getAuthor()); |
| 291 |
|
} catch (Exception e) { |
| 292 |
0
|
e.printStackTrace(); |
| 293 |
0
|
fail(); |
| 294 |
|
} |
| 295 |
|
} |
| 296 |
|
|
|
|
|
| 88,2% |
Uncovered Elements: 2 (17) |
Complexity: 2 |
Complexity Density: 0,12 |
1
PASS
|
|
| 297 |
2
|
public void testEditPost() {... |
| 298 |
2
|
try { |
| 299 |
2
|
BlogService service = new BlogService(); |
| 300 |
2
|
BlogEntry entry = new BlogEntry(blog1); |
| 301 |
2
|
entry.setTitle("title"); |
| 302 |
2
|
entry.setBody("body"); |
| 303 |
2
|
service.putBlogEntry(entry); |
| 304 |
|
|
| 305 |
2
|
Hashtable struct = new Hashtable(); |
| 306 |
2
|
struct.put(MetaWeblogAPIHandler.TITLE, "Title"); |
| 307 |
2
|
struct.put(MetaWeblogAPIHandler.DESCRIPTION, "<p>Content</p>"); |
| 308 |
2
|
boolean result = handler.editPost("blog1/" + entry.getId(), "username", "password", struct, true); |
| 309 |
|
|
| 310 |
2
|
assertTrue(result); |
| 311 |
2
|
entry = service.getBlogEntry(blog1, entry.getId()); |
| 312 |
2
|
assertEquals("Title", entry.getTitle()); |
| 313 |
2
|
assertEquals("<p>Content</p>", entry.getBody()); |
| 314 |
2
|
assertEquals("username", entry.getAuthor()); |
| 315 |
|
|
| 316 |
|
} catch (Exception e) { |
| 317 |
0
|
e.printStackTrace(); |
| 318 |
0
|
fail(); |
| 319 |
|
} |
| 320 |
|
} |
| 321 |
|
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
| 322 |
2
|
public void testEditPostWithNullId() {... |
| 323 |
2
|
try { |
| 324 |
2
|
handler.editPost("blog1/", "username", "password", new Hashtable(), true); |
| 325 |
0
|
fail(); |
| 326 |
|
} catch (XmlRpcException xmlrpce) { |
| 327 |
2
|
assertEquals("Blog entry with ID of was not found.", xmlrpce.getMessage()); |
| 328 |
|
} |
| 329 |
|
} |
| 330 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 331 |
2
|
public void testEditPostWithIdThatDoesntExist() {... |
| 332 |
2
|
String postid = "1234567890123"; |
| 333 |
2
|
try { |
| 334 |
2
|
handler.editPost("blog1/" + postid, "username", "password", new Hashtable(), true); |
| 335 |
0
|
fail(); |
| 336 |
|
} catch (XmlRpcException xmlrpce) { |
| 337 |
2
|
assertEquals("Blog entry with ID of " + postid + " was not found.", xmlrpce.getMessage()); |
| 338 |
|
} |
| 339 |
|
} |
| 340 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0,07 |
1
PASS
|
|
| 341 |
2
|
public void testGetCategories() throws Exception {... |
| 342 |
2
|
Hashtable categories = handler.getCategories("blog1", "username", "password"); |
| 343 |
2
|
assertEquals(0, categories.size()); |
| 344 |
|
|
| 345 |
2
|
blog1.addCategory(new Category("/category1", "Category 1")); |
| 346 |
2
|
blog1.addCategory(new Category("/category2", "Category 2")); |
| 347 |
2
|
categories = handler.getCategories("blog1", "username", "password"); |
| 348 |
2
|
assertTrue(categories.size() == 2); |
| 349 |
2
|
Hashtable struct = (Hashtable)categories.get("/category1"); |
| 350 |
2
|
assertEquals("/category1", struct.get(MetaWeblogAPIHandler.DESCRIPTION)); |
| 351 |
2
|
assertEquals(blog1.getUrl() + "categories/category1/", struct.get(MetaWeblogAPIHandler.HTML_URL)); |
| 352 |
2
|
assertEquals(blog1.getUrl() + "rss.xml?category=/category1", struct.get(MetaWeblogAPIHandler.RSS_URL)); |
| 353 |
2
|
struct = (Hashtable)categories.get("/category2"); |
| 354 |
2
|
assertEquals("/category2", struct.get(MetaWeblogAPIHandler.DESCRIPTION)); |
| 355 |
2
|
assertEquals(blog1.getUrl() + "categories/category2/", struct.get(MetaWeblogAPIHandler.HTML_URL)); |
| 356 |
2
|
assertEquals(blog1.getUrl() + "rss.xml?category=/category2", struct.get(MetaWeblogAPIHandler.RSS_URL)); |
| 357 |
|
} |
| 358 |
|
|
| 359 |
|
} |