Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
143   287   31   8,94
0   217   0,22   16
16     1,94  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  MultiBlogBloggerAPIHandlerTest       Line # 49 143 0% 31 22 86,2% 0.8616352
 
  (30)
 
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.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    * Tests for the BloggerAPIHandler class, when using a composite blog.
46    *
47    * @author Simon Brown
48    */
 
49    public class MultiBlogBloggerAPIHandlerTest extends MultiBlogTestCase {
50   
51    private BloggerAPIHandler handler = new BloggerAPIHandler();
52   
 
53  30 toggle 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   
 
61  2 toggle 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   
 
70  2 toggle 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   
 
80  2 toggle 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   
 
122  2 toggle 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   
 
142  2 toggle 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   
 
163  2 toggle 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   
 
173  2 toggle 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   
 
183  2 toggle 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   
 
201  2 toggle 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   
 
211  2 toggle 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   
 
221  2 toggle 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   
 
231  2 toggle 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   
 
246  2 toggle 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   
 
267  2 toggle 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   
 
277  2 toggle 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    }