Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
75   152   3   25
0   93   0,04   3
3     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  FileBlogEntryDAOTest       Line # 48 75 0% 3 0 100% 1.0
 
  (2)
 
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.dao.file;
33   
34    import net.sourceforge.pebble.dao.BlogEntryDAO;
35    import net.sourceforge.pebble.domain.*;
36    import net.sourceforge.pebble.util.FileUtils;
37   
38    import java.io.File;
39    import java.text.SimpleDateFormat;
40    import java.util.List;
41    import java.util.Locale;
42   
43    /**
44    * Tests for the FileBlogEntryDAO class.
45    *
46    * @author Simon Brown
47    */
 
48    public class FileBlogEntryDAOTest extends SingleBlogTestCase {
49   
50    private BlogEntryDAO dao= new FileBlogEntryDAO();
51    private Locale defaultLocale;
52   
 
53  2 toggle protected void setUp() throws Exception {
54  2 super.setUp();
55   
56  2 defaultLocale = Locale.getDefault();
57  2 Locale.setDefault(Locale.ENGLISH);
58    }
59   
60   
 
61  2 toggle public void tearDown() throws Exception {
62  2 super.tearDown();
63   
64  2 Locale.setDefault(defaultLocale);
65    }
66   
 
67  2 toggle public void testLoadBlogEntryFomFile() throws Exception {
68   
69  2 File source = new File(TEST_RESOURCE_LOCATION, "1081203335000.xml");
70  2 File destination = new File(blog.getRoot(), "2004/04/05/");
71  2 destination.mkdirs();
72  2 FileUtils.copyFile(source, new File(destination, "1081203335000.xml"));
73   
74  2 Day day = blog.getBlogForDay(2004, 04, 05);
75  2 Category category1 = new Category("/category1", "Category 1");
76  2 blog.addCategory(category1);
77  2 Category category2 = new Category("/category2", "Category 2");
78  2 blog.addCategory(category2);
79  2 BlogEntry blogEntry = dao.loadBlogEntry(blog, "1081203335000");
80  2 SimpleDateFormat sdf = new SimpleDateFormat(FileBlogEntryDAO.NEW_PERSISTENT_DATETIME_FORMAT);
81   
82    // test that the blog entry properties were loaded okay
83  2 assertEquals("Blog entry title", blogEntry.getTitle());
84  2 assertEquals("Blog entry subtitle", blogEntry.getSubtitle());
85  2 assertEquals("<p>Blog entry excerpt.</p>", blogEntry.getExcerpt());
86  2 assertEquals("<p>Blog entry body.</p>", blogEntry.getBody());
87  2 assertEquals(1081203335000L, blogEntry.getDate().getTime());
88  2 assertEquals("Europe/Paris", blogEntry.getTimeZoneId());
89  2 assertTrue(blogEntry.isUnpublished());
90  2 assertEquals("simon", blogEntry.getAuthor());
91  2 assertTrue(blogEntry.isCommentsEnabled());
92  2 assertTrue(blogEntry.isTrackBacksEnabled());
93  2 assertEquals(2, blogEntry.getCategories().size());
94  2 assertTrue(blogEntry.getCategories().contains(category1));
95  2 assertTrue(blogEntry.getCategories().contains(category2));
96  2 assertEquals("sometag", blogEntry.getTags());
97   
98    // test that the attachment was loaded
99  2 Attachment attachment = blogEntry.getAttachment();
100  2 assertNotNull(attachment);
101  2 assertEquals("./files/java-development-on-mac-os-x.pdf", attachment.getUrl());
102  2 assertEquals(3443670, attachment.getSize());
103  2 assertEquals("application/pdf", attachment.getType());
104   
105    // now test the comments were loaded okay
106  2 List comments = blogEntry.getComments();
107  2 assertEquals(2, comments.size());
108  2 Comment comment1 = (Comment)comments.get(0);
109  2 assertEquals("Comment title 1", comment1.getTitle());
110  2 assertEquals("<p>Comment 1.</p>", comment1.getBody());
111  2 assertEquals("Comment author 1", comment1.getAuthor());
112  2 assertEquals("me@author1.com", comment1.getEmail());
113  2 assertEquals("http://www.author1.com", comment1.getWebsite());
114  2 assertEquals("127.0.0.1", comment1.getIpAddress());
115  2 assertTrue(comment1.isApproved());
116  2 assertEquals(sdf.parse("05 Apr 2004 23:27:30:0 +0100"), comment1.getDate());
117  2 assertFalse(comment1.isAuthenticated());
118   
119  2 Comment comment2 = (Comment)comments.get(1);
120  2 assertEquals("Re: " + blogEntry.getTitle(), comment2.getTitle());
121  2 assertEquals("<p>Comment 2.</p>", comment2.getBody());
122  2 assertEquals("Comment author 2", comment2.getAuthor());
123  2 assertEquals("me@author2.com", comment2.getEmail());
124  2 assertEquals("http://www.author2.com", comment2.getWebsite());
125  2 assertEquals("192.168.0.1", comment2.getIpAddress());
126  2 assertTrue(comment2.isPending());
127  2 assertEquals(sdf.parse("05 Apr 2004 23:31:00:0 +0100"), comment2.getDate());
128  2 assertTrue(comment2.isAuthenticated());
129   
130    // now test the Trackbacks were loaded okay
131  2 List trackBacks = blogEntry.getTrackBacks();
132  2 assertEquals(2, trackBacks.size());
133  2 TrackBack trackBack1 = (TrackBack)trackBacks.get(0);
134  2 assertEquals("TrackBack title 1", trackBack1.getTitle());
135  2 assertEquals("TrackBack body 1.", trackBack1.getExcerpt());
136  2 assertEquals("http://www.author1.com/entry", trackBack1.getUrl());
137  2 assertEquals("Blog name 1", trackBack1.getBlogName());
138  2 assertEquals("127.0.0.1", trackBack1.getIpAddress());
139  2 assertTrue(trackBack1.isApproved());
140  2 assertEquals(sdf.parse("06 Apr 2004 07:09:24:0 +0100"), trackBack1.getDate());
141   
142  2 TrackBack trackBack2 = (TrackBack)trackBacks.get(1);
143  2 assertEquals("TrackBack title 2", trackBack2.getTitle());
144  2 assertEquals("TrackBack body 2.", trackBack2.getExcerpt());
145  2 assertEquals("http://www.author2.com/entry", trackBack2.getUrl());
146  2 assertEquals("Blog name 2", trackBack2.getBlogName());
147  2 assertEquals("192.168.0.1", trackBack2.getIpAddress());
148  2 assertTrue(trackBack2.isPending());
149  2 assertEquals(sdf.parse("06 Apr 2004 07:09:24:0 +0100"), trackBack2.getDate());
150    }
151   
152    }