⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blogtest.java

📁 pebble-blog 博客源码博客源码博客源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  public void testUserIsBlogOwner() {    blog.setProperty(Blog.BLOG_OWNERS_KEY, "user1");    assertTrue(blog.isUserInRole(Constants.BLOG_OWNER_ROLE, "user1"));    assertFalse(blog.isUserInRole(Constants.BLOG_OWNER_ROLE, "user2"));  }  /**   * Tests that when no blog contributors are specified, then everybody takes   * on that role.   */  public void testUserIsBlogOwnerByDefault() {    blog.removeProperty(Blog.BLOG_OWNERS_KEY);    assertTrue(blog.isUserInRole(Constants.BLOG_OWNER_ROLE, "user1"));    assertTrue(blog.isUserInRole(Constants.BLOG_OWNER_ROLE, "usern"));  }  /**   * Tests that blog contributors can be assigned.   */  public void testAssignBlogContributors() {    blog.setProperty(Blog.BLOG_CONTRIBUTORS_KEY, "user1");    assertEquals("user1", blog.getProperty(Blog.BLOG_CONTRIBUTORS_KEY));    assertEquals("user1", blog.getBlogContributorsAsString());    Collection users = blog.getUsersInRole(Constants.BLOG_CONTRIBUTOR_ROLE);    assertEquals(1, users.size());    assertTrue(users.contains("user1"));    blog.setProperty(Blog.BLOG_CONTRIBUTORS_KEY, "user1,user2");    assertEquals("user1,user2", blog.getProperty(Blog.BLOG_CONTRIBUTORS_KEY));    assertEquals("user1,user2", blog.getBlogContributorsAsString());    users = blog.getUsersInRole(Constants.BLOG_CONTRIBUTOR_ROLE);    assertEquals(2, users.size());    assertTrue(users.contains("user1"));    assertTrue(users.contains("user2"));    blog.setProperty(Blog.BLOG_CONTRIBUTORS_KEY, "user1, user2");    assertEquals("user1, user2", blog.getProperty(Blog.BLOG_CONTRIBUTORS_KEY));    assertEquals("user1, user2", blog.getBlogContributorsAsString());    users = blog.getUsersInRole(Constants.BLOG_CONTRIBUTOR_ROLE);    assertEquals(2, users.size());    assertTrue(users.contains("user1"));    assertTrue(users.contains("user2"));  }  /**   * Tests that blog contributors can be assigned.   */  public void testNullBlogContributors() {    blog.removeProperty(Blog.BLOG_CONTRIBUTORS_KEY);    assertEquals(null, blog.getBlogContributorsAsString());    Collection users = blog.getUsersInRole(Constants.BLOG_CONTRIBUTOR_ROLE);    assertEquals(0, users.size());  }  /**   * Tests that it can be determined that a user is a blog contributor.   */  public void testUserIsBlogContributor() {    blog.setProperty(Blog.BLOG_CONTRIBUTORS_KEY, "user1");    assertTrue(blog.isUserInRole(Constants.BLOG_CONTRIBUTOR_ROLE, "user1"));    assertFalse(blog.isUserInRole(Constants.BLOG_CONTRIBUTOR_ROLE, "user2"));  }  /**   * Tests that when no blog contributors are specified, then everybody takes   * on that role.   */  public void testUserIsBlogContributorByDefault() {    blog.removeProperty(Blog.BLOG_CONTRIBUTORS_KEY);    assertTrue(blog.isUserInRole(Constants.BLOG_CONTRIBUTOR_ROLE, "user1"));    assertTrue(blog.isUserInRole(Constants.BLOG_CONTRIBUTOR_ROLE, "usern"));  }  public void testInvalidDayOfMonthAfterTimeZoneChanges() {    blog.getRecentBlogEntries();    blog.setProperty(Blog.TIMEZONE_KEY, "America/New_York");    // this should not cause an exception to be thrown    blog.getRecentBlogEntries();  }  public void testGetRecentBlogEntriesFromEmptyBlog() {    assertTrue(blog.getRecentBlogEntries(3).isEmpty());  }  public void testGetRecentBlogEntries() throws BlogServiceException {    BlogService service = new BlogService();    BlogEntry entry1 = new BlogEntry(blog);    entry1.setTitle("title1");    entry1.setBody("body1");    service.putBlogEntry(entry1);    BlogEntry entry2 = new BlogEntry(blog);    entry2.setTitle("title2");    entry2.setBody("body2");    service.putBlogEntry(entry2);    BlogEntry entry3 = new BlogEntry(blog);    entry3.setTitle("title3");    entry3.setBody("body3");    service.putBlogEntry(entry3);    BlogEntry entry4 = new BlogEntry(blog);    entry4.setTitle("title4");    entry4.setBody("body4");    service.putBlogEntry(entry4);    List entries = blog.getRecentBlogEntries(3);    assertEquals(3, entries.size());    assertEquals(entry4, entries.get(0));  }  /**   * Tests the images directory is correct and that it exists.   */  public void testImagesDirectoryAccessible() {    File file = new File(blog.getRoot(), "images");    assertEquals(file, new File(blog.getImagesDirectory()));    assertTrue(file.exists());  }  /**   * Tests the files directory is correct and that it exists.   */  public void testFilesDirectoryAccessible() {    File file = new File(blog.getRoot(), "files");    assertEquals(file, new File(blog.getFilesDirectory()));    assertTrue(file.exists());  }  /**   * Tests the theme directory is correct and that it doesn't exist by default   *  - starting up Pebble creates a theme based on the template if the theme   *  - directory doesn't exist.   */  public void testThemeDirectoryAccessible() {    File file = new File(blog.getRoot(), "theme");    assertEquals(file, new File(blog.getThemeDirectory()));    assertTrue(file.exists());  }  /**   * Tests setting a single e-mail address.   */  public void testSingleEmailAddress() {    blog.setProperty(Blog.EMAIL_KEY, "me@mydomain.com");    assertEquals("me@mydomain.com", blog.getEmail());    assertEquals(1, blog.getEmailAddresses().size());    assertEquals("me@mydomain.com", blog.getEmailAddresses().iterator().next());  }  /**   * Tests setting multiple e-mail address.   */  public void testMultipleEmailAddresses() {    blog.setProperty(Blog.EMAIL_KEY, "me@mydomain.com,you@yourdomain.com");    assertEquals("me@mydomain.com,you@yourdomain.com", blog.getEmail());    assertEquals(2, blog.getEmailAddresses().size());    Iterator it = blog.getEmailAddresses().iterator();    assertEquals("me@mydomain.com", it.next());    assertEquals("you@yourdomain.com", it.next());  }  /**   * Tests getting the first of multiple e-mail addresses.   */  public void testFirstEmailAddress() {    blog.setProperty(Blog.EMAIL_KEY, "");    assertEquals("", blog.getFirstEmailAddress());    blog.setProperty(Blog.EMAIL_KEY, "me@mydomain.com");    assertEquals("me@mydomain.com", blog.getFirstEmailAddress());    blog.setProperty(Blog.EMAIL_KEY, "me@mydomain.com,you@yourdomain.com");    assertEquals("me@mydomain.com", blog.getFirstEmailAddress());  }  /**   * Tests the domain.   */  public void testDomain() {    assertEquals("www.yourdomain.com", blog.getDomainName());    PebbleContext.getInstance().getConfiguration().setUrl("http://www.yourdomain.com:8080/blog");    assertEquals("www.yourdomain.com", blog.getDomainName());  }  /**   * Tests the protocol.   */  public void testProtocol() {    assertEquals("http://", blog.getProtocol());  }  /**   * Tests the context.   */  public void testContext() {    assertEquals("/blog/", blog.getContext());    PebbleContext.getInstance().getConfiguration().setUrl("http://www.yourdomain.com:8080");    assertEquals("/", blog.getContext());    PebbleContext.getInstance().getConfiguration().setUrl("http://www.yourdomain.com:8080/");    assertEquals("/", blog.getContext());  }  /**   * Tests the logger can be accessed and is of the correct type.   */  public void testLogger() {    assertNotNull(blog.getLogger());    assertTrue(blog.getLogger() instanceof CombinedLogFormatLogger);  }  /**   * Tests that listeners are fired when the blog is started.   */  public void testListenersFiredWhenBlogStarted() {    final StringBuffer buf = new StringBuffer("123");    BlogListener listener = new BlogListener() {      public void blogStarted(BlogEvent event) {        assertEquals(blog, event.getSource());        buf.reverse();      }      public void blogStopped(BlogEvent event) {        fail();      }    };    blog.getEventListenerList().addBlogListener(listener);    blog.start();    assertEquals("321", buf.toString());    blog.getEventListenerList().removeBlogListener(listener);    blog.stop();  }  /**   * Tests that listeners are fired when the blog is stopped.   */  public void testListenersFiredWhenBlogStopped() {    final StringBuffer buf = new StringBuffer("123");    BlogListener listener = new BlogListener() {      public void blogStarted(BlogEvent event) {        fail();      }      public void blogStopped(BlogEvent event) {        assertEquals(blog, event.getSource());        buf.reverse();      }    };    blog.getEventListenerList().addBlogListener(listener);    blog.stop();    assertEquals("321", buf.toString());  }  public void testApprovedCommentsForUnpublishedBlogEntriesDontShowUp() throws BlogServiceException {    BlogService service = new BlogService();    BlogEntry blogEntry = new BlogEntry(blog);    blogEntry.setTitle("title1");    blogEntry.setBody("body1");    blogEntry.setPublished(false);    service.putBlogEntry(blogEntry);    Comment comment = blogEntry.createComment("title", "body", "author", "email", "website", "127.0.0.1");    blogEntry.addComment(comment);    service.putBlogEntry(blogEntry);    assertFalse(blog.getRecentApprovedResponses().contains(comment));  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -