Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
136   276   26   5,23
0   196   0,19   26
26     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  RequestTest       Line # 45 136 0% 26 0 100% 1.0
 
  (50)
 
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.logging;
33   
34    import net.sourceforge.pebble.PebbleContext;
35    import net.sourceforge.pebble.permalink.TitlePermalinkProvider;
36    import net.sourceforge.pebble.domain.BlogEntry;
37    import net.sourceforge.pebble.domain.BlogService;
38    import net.sourceforge.pebble.domain.SingleBlogTestCase;
39   
40    /**
41    * Tests for the Request class.
42    *
43    * @author Simon Brown
44    */
 
45    public class RequestTest extends SingleBlogTestCase {
46   
47    private Request url;
48   
 
49  50 toggle protected void setUp() throws Exception {
50  50 super.setUp();
51   
52  50 url = new Request("http://www.somedomain.com");
53  50 url.addLogEntry(new LogEntry());
54    }
55   
 
56  2 toggle public void testConstruction() {
57  2 assertEquals("http://www.somedomain.com", url.getName());
58  2 assertEquals("http://www.somedomain.com", url.getUrl());
59  2 assertEquals(1, url.getCount());
60    }
61   
 
62  2 toggle public void testIncrementingCount() {
63  2 assertEquals(1, url.getCount());
64  2 url.addLogEntry(new LogEntry());
65  2 assertEquals(2, url.getCount());
66    }
67   
 
68  2 toggle public void testShortUrlIsNotTruncated() {
69  2 String s = "http://www.somedomain.com";
70  2 url = new Request(s);
71  2 assertEquals("http://www.somedomain.com", url.getTruncatedName());
72    }
73   
 
74  2 toggle public void testLongUrlIsTruncated() {
75  2 String s = "http://www.somedomain.com/here/is/a/long/url/abcdefghijklmnopqrstuvwxyz012345678012345678901234567890123456789";
76  2 url = new Request(s);
77  2 assertEquals(s.substring(0, Request.NAME_LENGTH_LIMIT - 3) + "...", url.getTruncatedName());
78    }
79   
 
80  2 toggle public void testEmptyUrl() {
81  2 url = new Request("");
82  2 assertEquals("", url.getUrl());
83  2 assertEquals("None", url.getName());
84    }
85   
 
86  2 toggle public void testNullUrl() {
87  2 url = new Request(null);
88  2 assertEquals(null, url.getUrl());
89  2 assertEquals("None", url.getName());
90    }
91   
 
92  2 toggle public void testHashCode() {
93  2 url = new Request(null);
94  2 assertEquals(0, url.hashCode());
95  2 url = new Request("http://www.somedomain.com");
96  2 assertEquals("http://www.somedomain.com".hashCode(), url.hashCode());
97    }
98   
 
99  2 toggle public void testEquals() {
100  2 Request url1 = new Request("http://www.somedomain.com");
101  2 Request url2 = new Request("http://www.yahoo.com");
102  2 Request url3 = new Request(null);
103  2 Request url4 = new Request(null);
104   
105  2 assertFalse(url1.equals(null));
106  2 assertFalse(url1.equals("http://www.somedomain.com"));
107  2 assertTrue(url1.equals(url1));
108  2 assertFalse(url1.equals(url2));
109  2 assertFalse(url2.equals(url1));
110  2 assertFalse(url1.equals(url3));
111  2 assertFalse(url3.equals(url1));
112  2 assertTrue(url3.equals(url4));
113    }
114   
115    /**
116    * Test that friendly names are used for news feeds.
117    */
 
118  2 toggle public void testFriendlyNamesForNewsFeeds() {
119  2 url = new Request("http://...rss.xml");
120  2 assertEquals("Feed : Blog Entries", url.getName());
121  2 url = new Request("http://...rss.xml?category=java");
122  2 assertEquals("Feed : Blog Entries", url.getName());
123   
124  2 url = new Request("http://...feed.xml");
125  2 assertEquals("Feed : Blog Entries", url.getName());
126  2 url = new Request("http://...feed.xml?category=java");
127  2 assertEquals("Feed : Blog Entries", url.getName());
128   
129  2 url = new Request("http://...feed.action");
130  2 assertEquals("Feed : Blog Entries", url.getName());
131  2 url = new Request("http://...feed.action?category=java");
132  2 assertEquals("Feed : Blog Entries", url.getName());
133   
134  2 url = new Request("http://...rdf.xml");
135  2 assertEquals("Feed : Blog Entries", url.getName());
136  2 url = new Request("http://...rdf.xml?category=java");
137  2 assertEquals("Feed : Blog Entries", url.getName());
138   
139  2 url = new Request("http://...atom.xml");
140  2 assertEquals("Feed : Blog Entries", url.getName());
141  2 url = new Request("http://...atom.xml?category=java");
142  2 assertEquals("Feed : Blog Entries", url.getName());
143    }
144   
 
145  2 toggle public void testFriendlyNamesForHomePage() throws Exception {
146  2 url = new Request("/", blog);
147  2 assertEquals("Home", url.getName());
148    }
149   
 
150  2 toggle public void testFriendlyNamesForBlogEntries() throws Exception {
151  2 BlogEntry be = new BlogEntry(blog);
152  2 be.setTitle("Test blog entry");
153  2 BlogService service = new BlogService();
154  2 service.putBlogEntry(be);
155  2 String permalink = "/" + be.getPermalink().substring(PebbleContext.getInstance().getConfiguration().getUrl().length());
156  2 url = new Request(permalink, blog);
157  2 assertEquals("Blog Entry : Test blog entry", url.getName());
158    }
159   
 
160  2 toggle public void testFriendlyNamesForBlogEntriesUsingDefaultPermalinkProvider() throws Exception {
161  2 BlogEntry be = new BlogEntry(blog);
162  2 be.setTitle("Test blog entry");
163  2 BlogService service = new BlogService();
164  2 service.putBlogEntry(be);
165  2 String permalink = "/" + be.getPermalink().substring(PebbleContext.getInstance().getConfiguration().getUrl().length());
166  2 blog.setPermalinkProvider(new TitlePermalinkProvider());
167  2 url = new Request(permalink, blog);
168  2 assertEquals("Blog Entry : Test blog entry", url.getName());
169    }
170   
 
171  2 toggle public void testFriendlyNamesForTagPage() throws Exception {
172  2 url = new Request("/tags/", blog);
173  2 assertEquals("Tags", url.getName());
174  2 url = new Request("/tags", blog);
175  2 assertEquals("Tags", url.getName());
176   
177  2 url = new Request("/tags/java", blog);
178  2 assertEquals("Tag : java", url.getName());
179  2 url = new Request("/tags/java/", blog);
180  2 assertEquals("Tag : java", url.getName());
181    }
182   
 
183  2 toggle public void testFriendlyNamesForCategoryPage() throws Exception {
184  2 url = new Request("/categories/", blog);
185  2 assertEquals("Categories", url.getName());
186  2 url = new Request("/categories", blog);
187  2 assertEquals("Categories", url.getName());
188   
189  2 url = new Request("/categories/java", blog);
190  2 assertEquals("Category : java", url.getName());
191  2 url = new Request("/categories/java/", blog);
192  2 assertEquals("Category : java", url.getName());
193    }
194   
 
195  2 toggle public void testFriendlyNamesForFile() throws Exception {
196  2 url = new Request("/files/", blog);
197  2 assertEquals("Files", url.getName());
198  2 url = new Request("/files", blog);
199  2 assertEquals("Files", url.getName());
200   
201  2 url = new Request("/files/test.txt", blog);
202  2 assertEquals("File : test.txt", url.getName());
203  2 url = new Request("/files/directory/test.txt", blog);
204  2 assertEquals("File : directory/test.txt", url.getName());
205    }
206   
 
207  2 toggle public void testFriendlyNamesForBlogEntriesByPage() throws Exception {
208  2 url = new Request("/blogentries/1.html", blog);
209  2 assertEquals("Blog Entries : Page 1", url.getName());
210    }
211   
 
212  2 toggle public void testFriendlyNamesForMonthPages() throws Exception {
213  2 url = new Request("/2007/07.html", blog);
214  2 assertEquals("Month : July 2007", url.getName());
215    }
216   
 
217  2 toggle public void testFriendlyNamesForDayPages() throws Exception {
218  2 url = new Request("/2007/07/01.html", blog);
219  2 assertEquals("Day : 01 July 2007", url.getName());
220    }
221   
 
222  2 toggle public void testFriendlyNamesForResponsesFeed() throws Exception {
223  2 url = new Request("/responses/rss.xml", blog);
224  2 assertEquals("Feed : Responses", url.getName());
225  2 url = new Request("/responses/atom.xml", blog);
226  2 assertEquals("Feed : Responses", url.getName());
227    }
228   
 
229  2 toggle public void testFriendlyNamesForCategoryFeeds() throws Exception {
230  2 url = new Request("/categories/java/rss.xml", blog);
231  2 assertEquals("Feed : category=java", url.getName());
232  2 url = new Request("/categories/java/atom.xml", blog);
233  2 assertEquals("Feed : category=java", url.getName());
234   
235  2 url = new Request("/categories/java/junit/rss.xml", blog);
236  2 assertEquals("Feed : category=java/junit", url.getName());
237  2 url = new Request("/categories/java/junit/atom.xml", blog);
238  2 assertEquals("Feed : category=java/junit", url.getName());
239    }
240   
 
241  2 toggle public void testFriendlyNamesForTagFeeds() throws Exception {
242  2 url = new Request("/tags/java/rss.xml", blog);
243  2 assertEquals("Feed : tag=java", url.getName());
244  2 url = new Request("/tags/java/atom.xml", blog);
245  2 assertEquals("Feed : tag=java", url.getName());
246    }
247   
 
248  2 toggle public void testFriendlyNamesForAuthorFeeds() throws Exception {
249  2 url = new Request("/authors/sbrown/rss.xml", blog);
250  2 assertEquals("Feed : author=sbrown", url.getName());
251  2 url = new Request("/authors/sbrown/atom.xml", blog);
252  2 assertEquals("Feed : author=sbrown", url.getName());
253    }
254   
 
255  2 toggle public void testFriendlyNamesForAuthorPage() throws Exception {
256  2 url = new Request("/authors/sbrown/", blog);
257  2 assertEquals("Author : sbrown", url.getName());
258  2 url = new Request("/authors/sbrown", blog);
259  2 assertEquals("Author : sbrown", url.getName());
260    }
261   
 
262  2 toggle public void testFriendlyNamesForStaticPage() throws Exception {
263  2 url = new Request("/pages/sbrown.html", blog);
264  2 assertEquals("Static Page : sbrown.html", url.getName());
265  2 url = new Request("/pages/authors/sbrown.html", blog);
266  2 assertEquals("Static Page : authors/sbrown.html", url.getName());
267    }
268   
 
269  2 toggle public void testFriendlyNamesForSearches() throws Exception {
270  2 url = new Request("/search.action", blog);
271  2 assertEquals("Search", url.getName());
272  2 url = new Request("/search.action?query=java", blog);
273  2 assertEquals("Search", url.getName());
274    }
275   
276    }