📄 blogentrytest.java
字号:
assertEquals(1, blogEntry.getNumberOfComments()); blogEntry.removeComment(blogComment2.getId()); assertFalse(blogEntry.getComments().contains(blogComment1)); assertFalse(blogEntry.getComments().contains(blogComment2)); assertEquals(0, blogEntry.getNumberOfComments()); } /** * Tests that a blog entry can correctly manage blog comments when two are * added at the same time. */ public void testTwoCommentsAddedAtTheSameTime() { Comment blogComment1, blogComment2; blogComment1 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1"); blogComment2 = (Comment)blogComment1.clone(); assertEquals(blogComment1.getId(), blogComment2.getId()); blogEntry.addComment(blogComment1); assertEquals(1, blogEntry.getNumberOfComments()); assertEquals(1, blogEntry.getComments().size()); assertTrue(blogEntry.getComments().contains(blogComment1)); blogEntry.addComment(blogComment2); assertEquals(2, blogEntry.getNumberOfComments()); assertEquals(2, blogEntry.getComments().size()); assertTrue(blogEntry.getComments().contains(blogComment1)); assertTrue(blogEntry.getComments().contains(blogComment2)); } /** * Tests that nested comments can be accessed. */ public void testNestedComments() { Comment comment1, comment2; Date date1 = new Date(0); Date date2 = new Date(1000); comment1 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", date1, State.APPROVED); blogEntry.addComment(comment1); comment2 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", date2, State.APPROVED); comment2.setParent(comment1); blogEntry.addComment(comment2); assertEquals(2, blogEntry.getComments().size()); assertEquals(comment1, blogEntry.getComments().get(0)); assertEquals(comment2, blogEntry.getComments().get(1)); assertEquals(comment1, blogEntry.getComment(comment1.getId())); assertEquals(comment2, blogEntry.getComment(comment2.getId())); } /** * Tests that the number of comments reported is correct when some of those * comments are nested. */ public void testNumberOfCommentsCorrectWhenNestedCommentsPresent() { Comment comment1, comment2; Calendar cal1, cal2; cal1 = blog.getCalendar(); cal1.set(Calendar.DAY_OF_MONTH, 1); cal2 = blog.getCalendar(); cal2.set(Calendar.DAY_OF_MONTH, 2); comment1 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", cal1.getTime(), State.APPROVED); blogEntry.addComment(comment1); comment2 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", cal2.getTime(), State.APPROVED); comment2.setParent(comment1); blogEntry.addComment(comment2); assertEquals(2, blogEntry.getNumberOfComments()); } /** * Tests that removing a comment also removes all of its children. */ public void testRemovingCommentRemovesAllChildren() { Comment comment1, comment2; Date date1 = new Date(0); Date date2 = new Date(1000); comment1 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", date1, State.APPROVED); blogEntry.addComment(comment1); comment2 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", date2, State.APPROVED); comment2.setParent(comment1); blogEntry.addComment(comment2); // now remove the top-level comment, and hopefully all of its children blogEntry.removeComment(comment1.getId()); assertEquals(0, blogEntry.getNumberOfComments()); } /** * Tests that a nested comment can be removed. */ public void testNestedCommentCanBeRemoved() { Comment comment1, comment2; Date date1 = new Date(0); Date date2 = new Date(1000); comment1 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", date1, State.APPROVED); blogEntry.addComment(comment1); comment2 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", date2, State.APPROVED); comment2.setParent(comment1); blogEntry.addComment(comment2); // now remove the nested comment blogEntry.removeComment(comment2.getId()); assertEquals(1, blogEntry.getNumberOfComments()); assertNull(blogEntry.getComment(comment2.getId())); } /** * Tests that the permalink for a comment is correctly set. */ public void testCommentPermalink() { Comment blogComment; blogComment = blogEntry.createComment("Title", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1"); blogEntry.addComment(blogComment); assertEquals(blogEntry.getLocalPermalink() + "#comment" + blogComment.getId(), blogComment.getPermalink()); } /** * Tests that a blog entry can correctly manage trackbacks. */ public void testTrackBacks() { // check that there are no trackbacks to start with assertEquals(0, blogEntry.getNumberOfTrackBacks()); assertEquals(0, blogEntry.getTrackBacks().size()); } /** * Tests that a blog entry is cloneable. */ public void testCloneableNormalBlogEntry() { blogEntry.setTitle("An old title"); blogEntry.setSubtitle("An old subtitle"); blogEntry.setBody("An old body"); blogEntry.setAuthor("An old author"); blogEntry.setPersistent(true); blogEntry.setCommentsEnabled(false); blogEntry.setTrackBacksEnabled(false); blogEntry.setTimeZoneId("Europe/Paris"); Category category1 = blog.getCategory("/testCategory1"); Category category2 = blog.getCategory("/testCategory2"); Category category3 = blog.getCategory("/testCategory3"); blogEntry.addCategory(category1); blogEntry.addCategory(category2); blogEntry.setTags("some+tag"); BlogEntry clonedBlogEntry = (BlogEntry)blogEntry.clone(); assertEquals(blogEntry.getTitle(), clonedBlogEntry.getTitle()); assertEquals(blogEntry.getSubtitle(), clonedBlogEntry.getSubtitle()); assertEquals(blogEntry.getBody(), clonedBlogEntry.getBody()); assertEquals(blogEntry.getAuthor(), clonedBlogEntry.getAuthor()); assertEquals(blogEntry.getPermalink(), clonedBlogEntry.getPermalink()); assertEquals(blogEntry.inCategory(category1), clonedBlogEntry.inCategory(category1)); assertEquals(blogEntry.inCategory(category2), clonedBlogEntry.inCategory(category2)); assertEquals(blogEntry.inCategory(category3), clonedBlogEntry.inCategory(category3)); assertEquals("some+tag", clonedBlogEntry.getTags()); assertEquals(blogEntry.isPersistent(), clonedBlogEntry.isPersistent()); assertFalse(clonedBlogEntry.isCommentsEnabled()); assertFalse(clonedBlogEntry.isTrackBacksEnabled()); assertNull(clonedBlogEntry.getAttachment()); assertEquals(blogEntry.getTimeZoneId(), clonedBlogEntry.getTimeZoneId()); } /** * Tests that a blog entry is cloneable. */ public void testCloneableAggregatedBlogEntry() { blogEntry.setTitle("An old title"); blogEntry.setBody("An old body"); blogEntry.setAuthor("An old author"); blogEntry.setOriginalPermalink("An old alternative permalink"); Category category1 = blog.getCategory("/testCategory1"); Category category2 = blog.getCategory("/testCategory2"); Category category3 = blog.getCategory("/testCategory3"); blogEntry.addCategory(category1); blogEntry.addCategory(category2); BlogEntry clonedBlogEntry = (BlogEntry)blogEntry.clone(); assertEquals(blogEntry.getTitle(), clonedBlogEntry.getTitle()); assertEquals(blogEntry.getBody(), clonedBlogEntry.getBody()); assertEquals(blogEntry.getAuthor(), clonedBlogEntry.getAuthor()); assertEquals(blogEntry.getOriginalPermalink(), clonedBlogEntry.getOriginalPermalink()); assertEquals(blogEntry.inCategory(category1), clonedBlogEntry.inCategory(category1)); assertEquals(blogEntry.inCategory(category2), clonedBlogEntry.inCategory(category2)); assertEquals(blogEntry.inCategory(category3), clonedBlogEntry.inCategory(category3)); assertNull(clonedBlogEntry.getAttachment()); } public void testTopLevelCommentsClonedProperly() { Comment comment = blogEntry.createComment("Title", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1"); blogEntry.addComment(comment); BlogEntry clonedBlogEntry = (BlogEntry)blogEntry.clone(); Comment clonedComment = clonedBlogEntry.getComments().get(0); assertSame(clonedBlogEntry, clonedComment.getBlogEntry()); } public void testNestedCommentsClonedProperly() { Comment comment1 = blogEntry.createComment("Title", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1"); blogEntry.addComment(comment1); Comment comment2 = blogEntry.createComment("Title", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1"); comment2.setParent(comment1); blogEntry.addComment(comment2); BlogEntry clonedBlogEntry = (BlogEntry)blogEntry.clone(); Comment clonedComment1 = clonedBlogEntry.getComments().get(0); Comment clonedComment2 = clonedBlogEntry.getComments().get(1); assertSame(clonedComment1, clonedComment2.getParent()); assertSame(clonedBlogEntry, clonedComment1.getBlogEntry()); assertSame(clonedBlogEntry, clonedComment2.getBlogEntry()); }// todo// public void testValidationForStaticPage() {// blogEntry.setType(BlogEntry.STATIC_PAGE);//// ValidationContext context = new ValidationContext();// blogEntry.validate(context);// assertTrue("Name shouldn't be empty", context.hasErrors());//// context = new ValidationContext();// blogEntry.setStaticName("someStoryName");// blogEntry.validate(context);// assertFalse(context.hasErrors());//// context = new ValidationContext();// blogEntry.setStaticName("2004/someStoryName");// blogEntry.validate(context);// assertFalse(context.hasErrors());//// context = new ValidationContext();// blogEntry.setStaticName("some-story-name");// blogEntry.validate(context);// assertFalse(context.hasErrors());//// context = new ValidationContext();// blogEntry.setStaticName("someStoryName.html");// blogEntry.validate(context);// assertTrue("Name shouldn't contain punctuation", context.hasErrors());// } /** * Tests that the next blog entry can be accessed. */ public void testGetNextBlogEntry() throws Exception { BlogService service = new BlogService(); Day today = blog.getBlogForToday(); Day oneDayAgo = today.getPreviousDay(); Day twoDaysAgo = today.getPreviousDay().getPreviousDay(); BlogEntry b1 = new BlogEntry(blog); b1.setDate(twoDaysAgo.getDate()); b1.setPublished(true); BlogEntry b2 = new BlogEntry(blog); b2.setDate(oneDayAgo.getDate()); b2.setPublished(true); BlogEntry b3 = new BlogEntry(blog); b3.setDate(today.getDate()); b3.setPublished(true); service.putBlogEntry(b1); service.putBlogEntry(b2); service.putBlogEntry(b3); assertNull(b3.getNextBlogEntry()); assertEquals(b3, b2.getNextBlogEntry()); assertEquals(b2, b1.getNextBlogEntry()); } /** * Tests that the previous blog entry can be accessed. */ public void testGetPreviousBlogEntry() throws Exception { BlogService service = new BlogService(); Day today = blog.getBlogForToday(); Day oneDayAgo = today.getPreviousDay(); Day twoDaysAgo = today.getPreviousDay().getPreviousDay(); BlogEntry b1 = new BlogEntry(blog); b1.setDate(twoDaysAgo.getDate()); b1.setPublished(true); BlogEntry b2 = new BlogEntry(blog); b2.setDate(oneDayAgo.getDate()); b2.setPublished(true); BlogEntry b3 = new BlogEntry(blog); b3.setDate(today.getDate()); b3.setPublished(true); service.putBlogEntry(b1); service.putBlogEntry(b2); service.putBlogEntry(b3); assertNull(b1.getPreviousBlogEntry()); assertEquals(b1, b2.getPreviousBlogEntry()); assertEquals(b2, b3.getPreviousBlogEntry()); } /** * Tests for a blog entry attachment. */ public void testAttachment() { Attachment a = new Attachment("url", 1024, "image/jpeg"); blogEntry.setAttachment(a); assertEquals(a, blogEntry.getAttachment()); BlogEntry clonedBlogEntry = (BlogEntry)blogEntry.clone(); assertEquals(a, clonedBlogEntry.getAttachment()); }// todo// public void testPermalinkForStaticPage() {// blogEntry.setType(BlogEntry.STATIC_PAGE);// blogEntry.setStaticName("SomePage");// assertEquals("http://www.yourdomain.com/blog/pages/SomePage.html", blogEntry.getPermalink());// }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -