1 4 package com.openedit.blog; 5 6 import java.io.StringWriter ; 7 import java.io.Writer ; 8 import java.text.SimpleDateFormat ; 9 import java.util.ArrayList ; 10 import java.util.List ; 11 12 import org.openedit.blog.modules.BlogModule; 13 14 import com.openedit.BaseTestCase; 15 import com.openedit.WebPageRequest; 16 import com.openedit.users.User; 17 import com.sun.syndication.feed.synd.SyndContent; 18 import com.sun.syndication.feed.synd.SyndContentImpl; 19 import com.sun.syndication.feed.synd.SyndEntry; 20 import com.sun.syndication.feed.synd.SyndEntryImpl; 21 import com.sun.syndication.feed.synd.SyndFeed; 22 import com.sun.syndication.feed.synd.SyndFeedImpl; 23 import com.sun.syndication.io.SyndFeedOutput; 24 25 29 public class BlogTest extends BaseTestCase 30 { 31 34 public BlogTest(String inName) 35 { 36 super( inName); 37 } 38 public void testReadExistingBlog() throws Exception 39 { 40 BlogModule blogmodule = (BlogModule)getBean("BlogModule"); 41 WebPageRequest req = getFixture().createPageRequest("/yetanotherblog/index.html"); 44 blogmodule.getBlog(req); 45 Blog blog = (Blog)req.getPageValue("blog"); 46 List recent = blog.getRecentEntries(5); 47 assertTrue(recent.size()>0); 48 BlogEntry entry = (BlogEntry)recent.get(0); 49 52 54 62 } 63 64 public void testPermalink() throws Exception 65 { 66 BlogModule blogmodule = (BlogModule)getBean("BlogModule"); 67 WebPageRequest req = getFixture().createPageRequest("/yetanotherblog/permalink/2005/2/17/112302.html"); 68 blogmodule.loadPermalink(req); 69 BlogEntry entry = (BlogEntry)req.getPageValue("entry"); 70 assertNotNull(entry); 71 } 72 public void testAtomFeed() throws Exception 73 { 74 SyndFeed feed = new SyndFeedImpl(); 76 feed.setFeedType("atom_0.3"); 77 feed.setTitle("Sample Feed (created with Rome)"); 78 feed.setLink("http://rome.dev.java.net"); 79 feed.setDescription("This feed has been created using Rome (Java syndication utilities"); 80 81 List entries = new ArrayList (); 82 SyndEntry entry; 83 SyndContent description; 84 85 entry = new SyndEntryImpl(); 86 entry.setTitle("Rome v1.0"); 87 entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome01"); 88 entry.setPublishedDate(new SimpleDateFormat ("MM/dd/yyyy").parse("1/1/2004")); 89 description = new SyndContentImpl(); 90 description.setType("text/plain"); 91 description.setValue("Initial release of Rome"); 92 entry.setDescription(description); 93 entries.add(entry); 94 95 entry = new BlogEntry(); 96 entry.setTitle("Rome v3.0"); 97 entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome03"); 98 entry.setPublishedDate(new SimpleDateFormat ("MM/dd/yyyy").parse("1/1/2004")); 99 description = new SyndContentImpl(); 100 description.setType("text/html"); 101 String content = "<p>More Bug fixes, mor API changes, some new features and some Unit testing</p>"+ 102 "<p>For details chec the <a HREF=\"http://wiki.java.net/bin/view/Javawsxml/RomeChangesLog#RomeV03\">Changes Log</a></p>"; 103 105 description.setValue( content ); 106 entry.setDescription(description); 107 entries.add(entry); 108 109 feed.setEntries(entries); 110 112 Writer writer = new StringWriter (); 113 SyndFeedOutput output = new SyndFeedOutput(); 114 output.output(feed,writer); 115 writer.close(); 116 assertTrue(writer.toString().length() > 200); 117 } 118 119 public void testEditing() throws Exception 120 { 121 BlogModule blogmodule = (BlogModule)getBean("BlogModule"); 122 WebPageRequest req = getFixture().createPageRequest("/yetanotherblog/comments.html"); 125 126 req.setRequestParameter("username","admin"); 127 req.setRequestParameter("password","admin"); 128 User admin = (User)req.getPageValue("user"); 129 req.setUser(admin); 130 getFixture().getEngine().executePageActions(req); 131 blogmodule.addNewEntry(req); 133 BlogEntry entry = (BlogEntry)req.getPageValue("entry"); 134 assertNotNull(entry); 135 136 req.setRequestParameter("title","New Entry"); 138 req.setRequestParameter("author","New Entry"); 139 140 blogmodule.saveEntry(req); 141 req.setRequestParameter("entryId",entry.getId()); 142 blogmodule.getEntry(req); 143 BlogEntry blogentry = (BlogEntry)req.getPageValue("entry"); 144 assertNotNull(blogentry); 145 assertEquals("New Entry", blogentry.getTitle()); 146 147 Blog blog = blogmodule.getBlog(req); 148 Question q = blog.getQuestion("1"); 149 req.putSessionValue("question", q); 150 151 req.setRequestParameter("entryId",entry.getId()); 153 req.setRequestParameter("author","jimbob"); 154 req.setRequestParameter("content","This is a comment"); 155 156 req.setRequestParameter("questionid","1"); 157 req.setRequestParameter("answerid","9"); 158 159 blogmodule.addNewComment(req); 160 req.setRequestParameter("entryId",entry.getId()); 161 blogmodule.getEntry(req); 162 blogentry = (BlogEntry)req.getPageValue("entry"); 163 assertEquals(1,blogentry.getComments().size()); 164 Comment comment = (Comment) blogentry.getComments().get(0); 165 assertTrue(comment.isVisible()); 166 167 req.setRequestParameter("entryId",entry.getId()); 168 req.setRequestParameter("commentId", comment.getId()); 169 req.setRequestParameter("actiontext","flip"); 170 blogmodule.changeCommentVisibility(req); 171 172 Comment blogcomment = (Comment) blogentry.getComments().get(0); 173 assertFalse(blogcomment.isVisible()); 174 175 176 assertFalse(entry.isVisible()); 177 req.setRequestParameter("entryId",entry.getId()); 178 blogmodule.changeEntryVisibility(req); 179 180 req.setRequestParameter("entryId",entry.getId()); 181 blogmodule.getEntry(req); 182 blogentry = (BlogEntry)req.getPageValue("entry"); 183 184 assertTrue(blogentry.isVisible()); 185 } 186 } 187 | Popular Tags |