| 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.apache.xmlrpc.XmlRpcException; |
| 39 |
|
|
| 40 |
|
import java.util.Calendar; |
| 41 |
|
import java.util.Hashtable; |
| 42 |
|
import java.util.Vector; |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
@author |
| 48 |
|
|
|
|
|
| 86,2% |
Uncovered Elements: 22 (159) |
Complexity: 31 |
Complexity Density: 0,22 |
|
| 49 |
|
public class MultiBlogBloggerAPIHandlerTest extends MultiBlogTestCase { |
| 50 |
|
|
| 51 |
|
private BloggerAPIHandler handler = new BloggerAPIHandler(); |
| 52 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
| 53 |
30
|
protected void setUp() throws Exception {... |
| 54 |
30
|
super.setUp(); |
| 55 |
|
|
| 56 |
30
|
handler.setAuthenticationManager(new net.sourceforge.pebble.mock.MockAuthenticationManager(true, new GrantedAuthority[] {new GrantedAuthorityImpl(Constants.BLOG_CONTRIBUTOR_ROLE)})); |
| 57 |
30
|
blog1.setProperty(Blog.BLOG_CONTRIBUTORS_KEY, "username"); |
| 58 |
30
|
blog2.setProperty(Blog.BLOG_CONTRIBUTORS_KEY, "username2"); |
| 59 |
|
} |
| 60 |
|
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
1
PASS
|
|
| 61 |
2
|
public void testGetRecentPostsFromEmptyBlog() {... |
| 62 |
2
|
try { |
| 63 |
2
|
Vector posts = handler.getRecentPosts("appkey", "blog1", "username", "password", 3); |
| 64 |
2
|
assertTrue(posts.isEmpty()); |
| 65 |
|
} catch (Exception e) { |
| 66 |
0
|
fail(); |
| 67 |
|
} |
| 68 |
|
} |
| 69 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 70 |
2
|
public void testGetRecentPostsFromNonExistentBlog() {... |
| 71 |
2
|
String blogid = "someBlog"; |
| 72 |
2
|
try { |
| 73 |
2
|
handler.getRecentPosts("appkey", blogid, "username", "password", 3); |
| 74 |
0
|
fail(); |
| 75 |
|
} catch (XmlRpcException xmlrpce) { |
| 76 |
2
|
assertEquals("Blog with ID of " + blogid + " not found.", xmlrpce.getMessage()); |
| 77 |
|
} |
| 78 |
|
} |
| 79 |
|
|
|
|
|
| 93,5% |
Uncovered Elements: 2 (31) |
Complexity: 2 |
Complexity Density: 0,06 |
1
PASS
|
|
| 80 |
2
|
public void testGetRecentPosts() {... |
| 81 |
2
|
try { |
| 82 |
2
|
BlogService service = new BlogService(); |
| 83 |
|
|
| 84 |
2
|
BlogEntry entry1 = new BlogEntry(blog1); |
| 85 |
2
|
entry1.setTitle("title1"); |
| 86 |
2
|
entry1.setBody("body1"); |
| 87 |
2
|
service.putBlogEntry(entry1); |
| 88 |
|
|
| 89 |
2
|
BlogEntry entry2 = new BlogEntry(blog1); |
| 90 |
2
|
entry2.setTitle("title2"); |
| 91 |
2
|
entry2.setBody("body2"); |
| 92 |
2
|
service.putBlogEntry(entry2); |
| 93 |
|
|
| 94 |
2
|
BlogEntry entry3 = new BlogEntry(blog1); |
| 95 |
2
|
entry3.setTitle("title3"); |
| 96 |
2
|
entry3.setBody("body3"); |
| 97 |
2
|
service.putBlogEntry(entry3); |
| 98 |
|
|
| 99 |
2
|
BlogEntry entry4 = new BlogEntry(blog1); |
| 100 |
2
|
entry4.setTitle("title4"); |
| 101 |
2
|
entry4.setBody("body4"); |
| 102 |
2
|
service.putBlogEntry(entry4); |
| 103 |
|
|
| 104 |
2
|
Vector posts = handler.getRecentPosts("appkey", "blog1", "username", "password", 3); |
| 105 |
|
|
| 106 |
2
|
assertEquals(3, posts.size()); |
| 107 |
2
|
Hashtable ht = (Hashtable)posts.get(0); |
| 108 |
2
|
assertEquals("blog1/" + entry4.getId(), ht.get(BloggerAPIHandler.POST_ID)); |
| 109 |
2
|
assertEquals("<title>title4</title><category></category>body4", ht.get(BloggerAPIHandler.CONTENT)); |
| 110 |
2
|
ht = (Hashtable)posts.get(1); |
| 111 |
2
|
assertEquals("blog1/" + entry3.getId(), ht.get(BloggerAPIHandler.POST_ID)); |
| 112 |
2
|
assertEquals("<title>title3</title><category></category>body3", ht.get(BloggerAPIHandler.CONTENT)); |
| 113 |
2
|
ht = (Hashtable)posts.get(2); |
| 114 |
2
|
assertEquals("blog1/" + entry2.getId(), ht.get(BloggerAPIHandler.POST_ID)); |
| 115 |
2
|
assertEquals("<title>title2</title><category></category>body2", ht.get(BloggerAPIHandler.CONTENT)); |
| 116 |
|
} catch (Exception e) { |
| 117 |
0
|
e.printStackTrace(); |
| 118 |
0
|
fail(); |
| 119 |
|
} |
| 120 |
|
} |
| 121 |
|
|
|
|
|
| 85,7% |
Uncovered Elements: 2 (14) |
Complexity: 2 |
Complexity Density: 0,14 |
1
PASS
|
|
| 122 |
2
|
public void testGetPost() {... |
| 123 |
2
|
try { |
| 124 |
2
|
BlogService service = new BlogService(); |
| 125 |
2
|
BlogEntry entry = new BlogEntry(blog1); |
| 126 |
2
|
entry.setTitle("title"); |
| 127 |
2
|
entry.setBody("body"); |
| 128 |
2
|
entry.setAuthor("simon"); |
| 129 |
2
|
service.putBlogEntry(entry); |
| 130 |
|
|
| 131 |
2
|
Hashtable post = handler.getPost("appkey", "blog1/" + entry.getId(), "username", "password"); |
| 132 |
2
|
assertEquals("<title>title</title><category></category>body", post.get(BloggerAPIHandler.CONTENT)); |
| 133 |
2
|
assertEquals(entry.getAuthor(), post.get(BloggerAPIHandler.USER_ID)); |
| 134 |
2
|
assertEquals(entry.getDate(), post.get(BloggerAPIHandler.DATE_CREATED)); |
| 135 |
2
|
assertEquals("blog1/" + entry.getId(), post.get(BloggerAPIHandler.POST_ID)); |
| 136 |
|
} catch (Exception e) { |
| 137 |
0
|
e.printStackTrace(); |
| 138 |
0
|
fail(); |
| 139 |
|
} |
| 140 |
|
} |
| 141 |
|
|
|
|
|
| 86,7% |
Uncovered Elements: 2 (15) |
Complexity: 2 |
Complexity Density: 0,13 |
1
PASS
|
|
| 142 |
2
|
public void testGetPostWithCategory() {... |
| 143 |
2
|
try { |
| 144 |
2
|
BlogService service = new BlogService(); |
| 145 |
2
|
BlogEntry entry = new BlogEntry(blog1); |
| 146 |
2
|
entry.setTitle("title"); |
| 147 |
2
|
entry.setBody("body"); |
| 148 |
2
|
entry.setAuthor("simon"); |
| 149 |
2
|
entry.addCategory(new Category("java", "Java")); |
| 150 |
2
|
service.putBlogEntry(entry); |
| 151 |
|
|
| 152 |
2
|
Hashtable post = handler.getPost("appkey", "blog1/" + entry.getId(), "username", "password"); |
| 153 |
2
|
assertEquals("<title>title</title><category>/java</category>body", post.get(BloggerAPIHandler.CONTENT)); |
| 154 |
2
|
assertEquals(entry.getAuthor(), post.get(BloggerAPIHandler.USER_ID)); |
| 155 |
2
|
assertEquals(entry.getDate(), post.get(BloggerAPIHandler.DATE_CREATED)); |
| 156 |
2
|
assertEquals("blog1/" + entry.getId(), post.get(BloggerAPIHandler.POST_ID)); |
| 157 |
|
} catch (Exception e) { |
| 158 |
0
|
e.printStackTrace(); |
| 159 |
0
|
fail(); |
| 160 |
|
} |
| 161 |
|
} |
| 162 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 163 |
2
|
public void testGetPostWithIdThatDoesntExist() {... |
| 164 |
2
|
String postid = "1234567890123"; |
| 165 |
2
|
try { |
| 166 |
2
|
handler.getPost("appkey", "blog1/" + postid, "username", "password"); |
| 167 |
0
|
fail(); |
| 168 |
|
} catch (XmlRpcException xmlrpce) { |
| 169 |
2
|
assertEquals("Blog entry with ID of " + postid + " was not found.", xmlrpce.getMessage()); |
| 170 |
|
} |
| 171 |
|
} |
| 172 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 173 |
2
|
public void testGetPostWithNullId() {... |
| 174 |
2
|
String postid = null; |
| 175 |
2
|
try { |
| 176 |
2
|
handler.getPost("appkey", postid, "username", "password"); |
| 177 |
0
|
fail(); |
| 178 |
|
} catch (XmlRpcException xmlrpce) { |
| 179 |
2
|
assertEquals("Blog with ID of " + null + " not found.", xmlrpce.getMessage()); |
| 180 |
|
} |
| 181 |
|
} |
| 182 |
|
|
|
|
|
| 83,3% |
Uncovered Elements: 2 (12) |
Complexity: 2 |
Complexity Density: 0,17 |
1
PASS
|
|
| 183 |
2
|
public void testDeletePost() {... |
| 184 |
2
|
try { |
| 185 |
2
|
BlogService service = new BlogService(); |
| 186 |
2
|
BlogEntry entry = new BlogEntry(blog1); |
| 187 |
2
|
entry.setTitle("title"); |
| 188 |
2
|
entry.setBody("body"); |
| 189 |
2
|
entry.setAuthor("simon"); |
| 190 |
2
|
service.putBlogEntry(entry); |
| 191 |
|
|
| 192 |
2
|
boolean result = handler.deletePost("appkey", "blog1/" + entry.getId(), "username", "password", true); |
| 193 |
2
|
assertTrue("deletePost() returned false instead of true", result); |
| 194 |
2
|
assertNull(service.getBlogEntry(blog1, entry.getId())); |
| 195 |
|
} catch (Exception e) { |
| 196 |
0
|
e.printStackTrace(); |
| 197 |
0
|
fail(); |
| 198 |
|
} |
| 199 |
|
} |
| 200 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 201 |
2
|
public void testDeletePostWithIdThatDoesntExist() {... |
| 202 |
2
|
String postid = "1234567890123"; |
| 203 |
2
|
try { |
| 204 |
2
|
handler.deletePost("appkey", "blog1/" + postid, "username", "password", true); |
| 205 |
0
|
fail(); |
| 206 |
|
} catch (XmlRpcException xmlrpce) { |
| 207 |
2
|
assertEquals("Blog entry with ID of " + postid + " was not found.", xmlrpce.getMessage()); |
| 208 |
|
} |
| 209 |
|
} |
| 210 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 211 |
2
|
public void testDeletePostWithNullId() {... |
| 212 |
2
|
String postid = null; |
| 213 |
2
|
try { |
| 214 |
2
|
handler.deletePost("appkey", postid, "username", "password", true); |
| 215 |
0
|
fail(); |
| 216 |
|
} catch (XmlRpcException xmlrpce) { |
| 217 |
2
|
assertEquals("Blog with ID of " + null + " not found.", xmlrpce.getMessage()); |
| 218 |
|
} |
| 219 |
|
} |
| 220 |
|
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 221 |
2
|
public void testGetUserInfo() {... |
| 222 |
2
|
try { |
| 223 |
2
|
Hashtable userInfo = handler.getUserInfo("appkey", "username", "password"); |
| 224 |
2
|
assertEquals("username", userInfo.get("userid")); |
| 225 |
|
} catch (Exception e) { |
| 226 |
0
|
e.printStackTrace(); |
| 227 |
0
|
fail(); |
| 228 |
|
} |
| 229 |
|
} |
| 230 |
|
|
|
|
|
| 77,8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0,22 |
1
PASS
|
|
| 231 |
2
|
public void testGetUsersBlogs() {... |
| 232 |
2
|
try { |
| 233 |
2
|
Vector blogs = handler.getUsersBlogs("appkey", "username", "password"); |
| 234 |
2
|
assertEquals(1, blogs.size()); |
| 235 |
|
|
| 236 |
2
|
Hashtable blog = (Hashtable)blogs.get(0); |
| 237 |
2
|
assertEquals("http://www.yourdomain.com/blog/blog1/", blog.get("url")); |
| 238 |
2
|
assertEquals("blog1", blog.get("blogid")); |
| 239 |
2
|
assertEquals("My blog", blog.get("blogName")); |
| 240 |
|
} catch (Exception e) { |
| 241 |
0
|
e.printStackTrace(); |
| 242 |
0
|
fail(); |
| 243 |
|
} |
| 244 |
|
} |
| 245 |
|
|
|
|
|
| 85,7% |
Uncovered Elements: 2 (14) |
Complexity: 2 |
Complexity Density: 0,14 |
1
PASS
|
|
| 246 |
2
|
public void testAddCategory() {... |
| 247 |
2
|
try { |
| 248 |
2
|
BlogService service = new BlogService(); |
| 249 |
2
|
BlogEntry entry = new BlogEntry(blog1); |
| 250 |
2
|
service.putBlogEntry(entry); |
| 251 |
2
|
blog1.addCategory(new Category("/aCategory", "A Category")); |
| 252 |
|
|
| 253 |
2
|
boolean result = handler.addCategory("appkey", "blog1/" + entry.getId(), "username", "password", "/aCategory"); |
| 254 |
2
|
entry = service.getBlogEntry(blog1, entry.getId()); |
| 255 |
2
|
assertTrue("Category wasn't added", result); |
| 256 |
2
|
assertTrue(entry.inCategory(blog1.getCategory("aCategory"))); |
| 257 |
|
|
| 258 |
2
|
result = handler.addCategory("appkey", "blog1/" + entry.getId(), "username", "password", "/aNonExistentCategory"); |
| 259 |
2
|
entry = service.getBlogEntry(blog1, entry.getId()); |
| 260 |
2
|
assertFalse("Category was added", result); |
| 261 |
|
} catch (Exception e) { |
| 262 |
0
|
e.printStackTrace(); |
| 263 |
0
|
fail(); |
| 264 |
|
} |
| 265 |
|
} |
| 266 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 267 |
2
|
public void testAddCategoryWithIdThatDoesntExist() {... |
| 268 |
2
|
String postid = "1234567890123"; |
| 269 |
2
|
try { |
| 270 |
2
|
handler.addCategory("appkey", "blog1/" + postid, "username", "password", "aCategory"); |
| 271 |
0
|
fail(); |
| 272 |
|
} catch (XmlRpcException xmlrpce) { |
| 273 |
2
|
assertEquals("Blog entry with ID of " + postid + " was not found.", xmlrpce.getMessage()); |
| 274 |
|
} |
| 275 |
|
} |
| 276 |
|
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1
PASS
|
|
| 277 |
2
|
public void testAddCategoryWithNullId() {... |
| 278 |
2
|
String postid = null; |
| 279 |
2
|
try { |
| 280 |
2
|
handler.addCategory("appkey", postid, "username", "password", "aCategory"); |
| 281 |
0
|
fail(); |
| 282 |
|
} catch (XmlRpcException xmlrpce) { |
| 283 |
2
|
assertEquals("Blog with ID of " + null + " not found.", xmlrpce.getMessage()); |
| 284 |
|
} |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
} |