001: /*
002: * Created on Feb 18, 2005
003: */
004: package com.openedit.blog;
005:
006: import java.io.StringWriter;
007: import java.io.Writer;
008: import java.text.SimpleDateFormat;
009: import java.util.ArrayList;
010: import java.util.List;
011:
012: import org.openedit.blog.modules.BlogModule;
013:
014: import com.openedit.BaseTestCase;
015: import com.openedit.WebPageRequest;
016: import com.openedit.modules.admin.users.Question;
017: import com.openedit.users.User;
018: import com.sun.syndication.feed.synd.SyndContent;
019: import com.sun.syndication.feed.synd.SyndContentImpl;
020: import com.sun.syndication.feed.synd.SyndEntry;
021: import com.sun.syndication.feed.synd.SyndEntryImpl;
022: import com.sun.syndication.feed.synd.SyndFeed;
023: import com.sun.syndication.feed.synd.SyndFeedImpl;
024: import com.sun.syndication.io.SyndFeedOutput;
025:
026: /**
027: * @author cburkey
028: *
029: */
030: public class BlogTest extends BaseTestCase {
031: /**
032: *
033: */
034: public BlogTest(String inName) {
035: super (inName);
036: }
037:
038: public void testReadExistingBlog() throws Exception {
039: BlogModule blogmodule = (BlogModule) getBean("BlogModule");
040: //list last five entries
041: //System.out.println(SimpleDateFormat.getDateTimeInstance().format(new Date()));
042: WebPageRequest req = getFixture().createPageRequest(
043: "/yetanotherblog/index.html");
044: blogmodule.getBlog(req);
045: Blog blog = (Blog) req.getPageValue("blog");
046: List recent = blog.getRecentEntries(5);
047: assertTrue(recent.size() > 0);
048: BlogEntry entry = (BlogEntry) recent.get(0);
049: // FIXME: Actually test something here.
050: //assertEquals("A blog entry",entry.getTitle());
051:
052: //assertEquals(1,entry.getCategories().size() );
053:
054: /* assertTrue(entry.getDescription().getValue().length() > 100);
055: assertEquals(entry.getLink(),"http://localhost:8080/yetanotherblog/permalink/2005/2/17/112302.html");
056: assertEquals(entry.getPath(),"/yetanotherblog/2005/2/17/112302.html");
057: assertEquals(entry.getId(),"yetanotherblog2005217112302");
058:
059: int count = entry.countComments();
060: assertEquals(1,count);
061: */
062: }
063:
064: public void testPermalink() throws Exception {
065: BlogModule blogmodule = (BlogModule) getBean("BlogModule");
066: WebPageRequest req = getFixture().createPageRequest(
067: "/yetanotherblog/permalink/2005/2/17/112302.html");
068: blogmodule.loadPermalink(req);
069: BlogEntry entry = (BlogEntry) req.getPageValue("entry");
070: assertNotNull(entry);
071: }
072:
073: public void testAtomFeed() throws Exception {
074: //this makes a blog
075: SyndFeed feed = new SyndFeedImpl();
076: feed.setFeedType("atom_0.3");
077: feed.setTitle("Sample Feed (created with Rome)");
078: feed.setLink("http://rome.dev.java.net");
079: feed
080: .setDescription("This feed has been created using Rome (Java syndication utilities");
081:
082: List entries = new ArrayList();
083: SyndEntry entry;
084: SyndContent description;
085:
086: entry = new SyndEntryImpl();
087: entry.setTitle("Rome v1.0");
088: entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome01");
089: entry.setPublishedDate(new SimpleDateFormat("MM/dd/yyyy")
090: .parse("1/1/2004"));
091: description = new SyndContentImpl();
092: description.setType("text/plain");
093: description.setValue("Initial release of Rome");
094: entry.setDescription(description);
095: entries.add(entry);
096:
097: entry = new BlogEntry();
098: entry.setTitle("Rome v3.0");
099: entry.setLink("http://wiki.java.net/bin/view/Javawsxml/Rome03");
100: entry.setPublishedDate(new SimpleDateFormat("MM/dd/yyyy")
101: .parse("1/1/2004"));
102: description = new SyndContentImpl();
103: description.setType("text/html");
104: String content = "<p>More Bug fixes, mor API changes, some new features and some Unit testing</p>"
105: + "<p>For details chec the <a href=\"http://wiki.java.net/bin/view/Javawsxml/RomeChangesLog#RomeV03\">Changes Log</a></p>";
106: //content = content.replaceAll(" "," ");
107:
108: description.setValue(content);
109: entry.setDescription(description);
110: entries.add(entry);
111:
112: feed.setEntries(entries);
113: //blog.setFeed(feed);
114:
115: Writer writer = new StringWriter();
116: SyndFeedOutput output = new SyndFeedOutput();
117: output.output(feed, writer);
118: writer.close();
119: assertTrue(writer.toString().length() > 200);
120: }
121:
122: public void testEditing() throws Exception {
123: BlogModule blogmodule = (BlogModule) getBean("BlogModule");
124: //list last five entries
125: //System.out.println(SimpleDateFormat.getDateTimeInstance().format(new Date()));
126: WebPageRequest req = getFixture().createPageRequest(
127: "/yetanotherblog/comments.html");
128:
129: req.setRequestParameter("username", "admin");
130: req.setRequestParameter("password", "admin");
131: User admin = (User) req.getPageValue("user");
132: req.setUser(admin);
133: getFixture().getEngine().executePageActions(req);
134: //add entry
135: blogmodule.addNewEntry(req);
136: BlogEntry entry = (BlogEntry) req.getPageValue("entry");
137: assertNotNull(entry);
138:
139: //test new entry
140: req.setRequestParameter("title", "New Entry");
141: req.setRequestParameter("author", "New Entry");
142:
143: blogmodule.saveEntry(req);
144: req.setRequestParameter("entryId", entry.getId());
145: blogmodule.getEntry(req);
146: BlogEntry blogentry = (BlogEntry) req.getPageValue("entry");
147: assertNotNull(blogentry);
148: assertEquals("New Entry", blogentry.getTitle());
149:
150: Blog blog = blogmodule.getBlog(req);
151: Question q = new Question();//blog.getQuestion("1");
152: q.setId("1");
153: q.setAnswer("9");
154: req.putSessionValue("question", q);
155:
156: //add comments
157: req.setRequestParameter("entryId", entry.getId());
158: req.setRequestParameter("author", "jimbob");
159: req.setRequestParameter("content", "This is a comment");
160:
161: req.setRequestParameter("questionid", "1");
162: req.setRequestParameter("answerid", "9");
163:
164: blogmodule.addNewComment(req);
165: req.setRequestParameter("entryId", entry.getId());
166: blogmodule.getEntry(req);
167: blogentry = (BlogEntry) req.getPageValue("entry");
168: assertEquals(1, blogentry.getComments().size());
169: Comment comment = (Comment) blogentry.getComments().get(0);
170: assertTrue(comment.isVisible());
171:
172: req.setRequestParameter("entryId", entry.getId());
173: req.setRequestParameter("commentId", comment.getId());
174: req.setRequestParameter("actiontext", "flip");
175: blogmodule.changeCommentVisibility(req);
176:
177: Comment blogcomment = (Comment) blogentry.getComments().get(0);
178: assertFalse(blogcomment.isVisible());
179:
180: assertFalse(entry.isVisible());
181: req.setRequestParameter("entryId", entry.getId());
182: blogmodule.changeEntryVisibility(req);
183:
184: req.setRequestParameter("entryId", entry.getId());
185: blogmodule.getEntry(req);
186: blogentry = (BlogEntry) req.getPageValue("entry");
187:
188: assertTrue(blogentry.isVisible());
189: }
190: }
|