Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
65   234   36   1,81
0   144   0,55   36
36     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  UriTransformerTest       Line # 43 65 0% 36 0 100% 1.0
 
  (70)
 
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.web.filter;
33   
34    import net.sourceforge.pebble.domain.*;
35    import net.sourceforge.pebble.permalink.DefaultPermalinkProvider;
36    import net.sourceforge.pebble.permalink.TitlePermalinkProvider;
37   
38    /**
39    * Tests for the UriTransformer class.
40    *
41    * @author Simon Brown
42    */
 
43    public class UriTransformerTest extends SingleBlogTestCase {
44   
45    private UriTransformer transformer;
46   
 
47  70 toggle protected void setUp() throws Exception {
48  70 super.setUp();
49   
50  70 transformer = new UriTransformer();
51    }
52   
 
53  2 toggle public void testSimpleUrlsForSingleUserBlog() throws Exception {
54  2 assertEquals("/viewHomePage.action", transformer.getUri("", blog));
55  2 assertEquals("/viewHomePage.action", transformer.getUri("/", blog));
56    }
57   
 
58  2 toggle public void testRssUrlForSingleUserBlog() throws Exception {
59  2 assertEquals("/feed.action?flavor=rss20", transformer.getUri("/rss.xml", blog));
60    }
61   
 
62  2 toggle public void testRssUrlForResponseFeed() throws Exception {
63  2 assertEquals("/responseFeed.action?flavor=rss20", transformer.getUri("/responses/rss.xml", blog));
64    }
65   
 
66  2 toggle public void testRssUrlForResponseFeedForBlogEntry() throws Exception {
67  2 assertEquals("/responseFeed.action?flavor=rss20&entry=1202928360000", transformer.getUri("/responses/rss.xml?entry=1202928360000", blog));
68    }
69   
 
70  2 toggle public void testRdfUrlForSingleUserBlog() throws Exception {
71  2 assertEquals("/feed.action?flavor=rdf", transformer.getUri("/rdf.xml", blog));
72    }
73   
 
74  2 toggle public void testAtomUrlForSingleUserBlog() throws Exception {
75  2 assertEquals("/feed.action?flavor=atom", transformer.getUri("/atom.xml", blog));
76    }
77   
 
78  2 toggle public void testAtomUrlForResponseFeed() throws Exception {
79  2 assertEquals("/responseFeed.action?flavor=atom", transformer.getUri("/responses/atom.xml", blog));
80    }
81   
 
82  2 toggle public void testIncorrectRssUrlForSingleUserBlog() throws Exception {
83  2 assertEquals("/viewFeeds.action/rss.xml", transformer.getUri("/viewFeeds.action/rss.xml", blog));
84    }
85   
 
86  2 toggle public void testRandomUrlForSingleUserBlog() throws Exception {
87    // test a random uri that doesn't point to anything special
88  2 assertEquals("/somerandompage.html", transformer.getUri("/somerandompage.html", blog));
89    }
90   
 
91  2 toggle public void testImageUrlForSingleUserBlog() throws Exception {
92    // test a uri that points to an image located within the blog
93  2 assertEquals("/file.action?type=" + FileMetaData.BLOG_IMAGE + "&name=/myImage.jpg", transformer.getUri("/images/myImage.jpg", blog));
94    }
95   
 
96  2 toggle public void testFileUrlForSingleUserBlog() throws Exception {
97    // test a uri that points to an image located within the blog
98  2 assertEquals("/file.action?type=" + FileMetaData.BLOG_FILE + "&name=/myFile.zip", transformer.getUri("/files/myFile.zip", blog));
99    }
100   
 
101  2 toggle public void testMonthlyUrlForSingleUserBlog() throws Exception {
102    // test a url to request a whole month
103  2 assertEquals("/viewMonth.action?year=2003&month=11", transformer.getUri("/2003/11.html", blog));
104    }
105   
 
106  2 toggle public void testDailyUrlForSingleUserBlog() throws Exception {
107    // test a url to request a whole day
108  2 assertEquals("/viewDay.action?year=2003&month=11&day=24", transformer.getUri("/2003/11/24.html", blog));
109    }
110   
 
111  2 toggle public void testPermalinkUrlsForSingleUserBlog() throws Exception {
112  2 BlogService service = new BlogService();
113  2 BlogEntry blogEntry = new BlogEntry(blog);
114  2 service.putBlogEntry(blogEntry);
115   
116    // test a url to request a single blog entry
117  2 String url = blogEntry.getLocalPermalink();
118  2 assertEquals("/viewBlogEntry.action?entry=" + blogEntry.getId(), transformer.getUri(url.substring(url.indexOf("/blog/")+5), blog));
119    }
120   
 
121  2 toggle public void testStaticPermalinkUrlsForSingleUserBlog() throws Exception {
122    // test a url to request a "static" permalink
123  2 assertEquals("/viewStaticPage.action?name=some-story", transformer.getUri("/pages/some-story.html", blog));
124    }
125   
 
126  2 toggle public void testDefaultStaticPageWithNoTrailingSlash() throws Exception {
127  2 assertEquals("/viewStaticPage.action?name=index", transformer.getUri("/pages", blog));
128    }
129   
 
130  2 toggle public void testDefaultStaticPageWithTrailingSlash() throws Exception {
131  2 assertEquals("/viewStaticPage.action?name=index", transformer.getUri("/pages/", blog));
132    }
133   
 
134  2 toggle public void testUrlEndingWithSlashForSingleUserBlog() throws Exception {
135    // test a url to request a single blog entry (long)
136  2 assertEquals("/2003/", transformer.getUri("/2003/", blog));
137    }
138   
 
139  2 toggle public void testCategoriesLink() throws Exception {
140  2 assertEquals("/viewCategories.action", transformer.getUri("/categories/", blog));
141  2 assertEquals("/viewCategories.action", transformer.getUri("/categories", blog));
142    }
143   
 
144  2 toggle public void testCategoryPermalink() throws Exception {
145  2 assertEquals("/viewCategory.action?category=/category1", transformer.getUri("/categories/category1/", blog));
146    }
147   
 
148  2 toggle public void testSubCategoryPermalinkWithTrailingSlash() throws Exception {
149  2 assertEquals("/viewCategory.action?category=/category1/subcategory", transformer.getUri("/categories/category1/subcategory/", blog));
150    }
151   
 
152  2 toggle public void testSubCategoryPermalinkWithoutTrailingSlash() throws Exception {
153  2 assertEquals("/viewCategory.action?category=/category1/subcategory", transformer.getUri("/categories/category1/subcategory", blog));
154    }
155   
 
156  2 toggle public void testCategoryNewsFeed() throws Exception {
157  2 assertEquals("/feed.action?category=/category1&flavor=rss20", transformer.getUri("/categories/category1/rss.xml", blog));
158  2 assertEquals("/feed.action?category=/category1&flavor=rdf", transformer.getUri("/categories/category1/rdf.xml", blog));
159  2 assertEquals("/feed.action?category=/category1&flavor=atom", transformer.getUri("/categories/category1/atom.xml", blog));
160    }
161   
 
162  2 toggle public void testTagsLink() throws Exception {
163  2 assertEquals("/viewTags.action", transformer.getUri("/tags/", blog));
164  2 assertEquals("/viewTags.action", transformer.getUri("/tags", blog));
165    }
166   
 
167  2 toggle public void testTagPermalinkWithTrailingSlash() throws Exception {
168  2 assertEquals("/viewTag.action?tag=automated unit testing", transformer.getUri("/tags/automated unit testing", blog));
169    }
170   
 
171  2 toggle public void testTagPermalinkWithoutTrailingSlash() throws Exception {
172  2 assertEquals("/viewTag.action?tag=automated unit testing", transformer.getUri("/tags/automated unit testing/", blog));
173    }
174   
 
175  2 toggle public void testTagNewsFeed() throws Exception {
176  2 assertEquals("/feed.action?tag=automated+unit+testing&flavor=rss20", transformer.getUri("/tags/automated+unit+testing/rss.xml", blog));
177  2 assertEquals("/feed.action?tag=automated+unit+testing&flavor=rdf", transformer.getUri("/tags/automated+unit+testing/rdf.xml", blog));
178  2 assertEquals("/feed.action?tag=automated+unit+testing&flavor=atom", transformer.getUri("/tags/automated+unit+testing/atom.xml", blog));
179    }
180   
 
181  2 toggle public void testAuthorPermalink() throws Exception {
182  2 assertEquals("/aboutAuthor.action?user=sbrown", transformer.getUri("/authors/sbrown/", blog));
183    }
184   
 
185  2 toggle public void testAuthorNewsFeed() throws Exception {
186  2 assertEquals("/feed.action?author=sbrown&flavor=rss20", transformer.getUri("/authors/sbrown/rss.xml", blog));
187  2 assertEquals("/feed.action?author=sbrown&flavor=rdf", transformer.getUri("/authors/sbrown/rdf.xml", blog));
188  2 assertEquals("/feed.action?author=sbrown&flavor=atom", transformer.getUri("/authors/sbrown/atom.xml", blog));
189    }
190   
 
191  2 toggle public void testTodayPage() throws Exception {
192  2 assertEquals("/viewDay.action", transformer.getUri("/today.html", blog));
193    }
194   
 
195  2 toggle public void testBlogEntryWithDefaultPermalinkProvider() throws Exception {
196  2 BlogService service = new BlogService();
197  2 BlogEntry blogEntry = new BlogEntry(blog);
198  2 service.putBlogEntry(blogEntry);
199  2 assertEquals("/viewBlogEntry.action?entry=" + blogEntry.getId(), transformer.getUri(blog.getPermalinkProvider().getPermalink(blogEntry), blog));
200    }
201   
 
202  2 toggle public void testBlogEntryWithTitlePermalinkProvider() throws Exception {
203  2 blog.setPermalinkProvider(new TitlePermalinkProvider());
204   
205  2 BlogService service = new BlogService();
206  2 BlogEntry blogEntry = new BlogEntry(blog);
207  2 blogEntry.setTitle("Some title");
208  2 service.putBlogEntry(blogEntry);
209   
210  2 assertEquals("/viewBlogEntry.action?entry=" + blogEntry.getId(), transformer.getUri(blog.getPermalinkProvider().getPermalink(blogEntry), blog));
211    }
212   
 
213  2 toggle public void testBlogEntryFallsBackToDefaultPermalinkProvider() throws Exception {
214  2 DefaultPermalinkProvider defaultProvider = new DefaultPermalinkProvider();
215  2 defaultProvider.setBlog(blog);
216  2 blog.setPermalinkProvider(new TitlePermalinkProvider());
217   
218  2 BlogService service = new BlogService();
219  2 BlogEntry blogEntry = new BlogEntry(blog);
220  2 blogEntry.setTitle("Some title");
221  2 service.putBlogEntry(blogEntry);
222   
223  2 assertEquals("/viewBlogEntry.action?entry=" + blogEntry.getId(), transformer.getUri(defaultProvider.getPermalink(blogEntry), blog));
224    }
225   
 
226  2 toggle public void testViewBlogEntriesByPageUrlForSingleUserBlog() throws Exception {
227  2 assertEquals("/viewBlogEntriesByPage.action?page=1", transformer.getUri("/blogentries/1.html", blog));
228    }
229   
 
230  2 toggle public void testAboutUrlForSingleUserBlog() throws Exception {
231  2 assertEquals("/about.action", transformer.getUri("/about.html", blog));
232    }
233   
234    }