[jboss-cvs] jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/plugin ...

Christian Bauer christian at hibernate.org
Tue Dec 18 23:29:27 EST 2007


  User: cbauer  
  Date: 07/12/18 23:29:27

  Added:       examples/wiki/src/test/org/jboss/seam/wiki/test/plugin     
                        TopicHomeTests.java ForumQueryTests.java
                        ForumHomeTests.java BlogDAOTests.java
                        ForumDAOTests.java
  Log:
  Major rewrite of the most of the application
  
  Revision  Changes    Path
  1.1      date: 2007/12/19 04:29:27;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/plugin/TopicHomeTests.java
  
  Index: TopicHomeTests.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.plugin;
  
  import org.dbunit.operation.DatabaseOperation;
  import org.jboss.seam.contexts.Contexts;
  import org.jboss.seam.wiki.core.dao.WikiNodeDAO;
  import org.jboss.seam.wiki.core.feeds.FeedDAO;
  import org.jboss.seam.wiki.core.model.FeedEntry;
  import org.jboss.seam.wiki.core.model.WikiDirectory;
  import org.jboss.seam.wiki.core.model.WikiDocument;
  import org.jboss.seam.wiki.plugin.forum.TopicHome;
  import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
  import org.testng.annotations.Test;
  
  public class TopicHomeTests extends DBUnitSeamTest {
  
      protected void prepareDBUnitOperations() {
          beforeTestOperations.add(
              new DataSetOperation("org/jboss/seam/wiki/test/WikiBaseData.dbunit.xml", DatabaseOperation.CLEAN_INSERT)
          );
          beforeTestOperations.add(
              new DataSetOperation("org/jboss/seam/wiki/test/ForumData.dbunit.xml", DatabaseOperation.INSERT)
          );
      }
  
      @Test
      public void newTopic() throws Exception {
  
          final String conversationId = new FacesRequest() {
  
              protected void updateModelValues() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(102l);
                  Contexts.getPageContext().set("currentDirectory", forumDir);
              }
  
              protected void invokeApplication() throws Exception {
                  TopicHome home = (TopicHome)getInstance("topicHome");
                  home.newTopic();
              }
          }.run();
  
          new FacesRequest() {
  
              protected void beforeRequest() {
                  setParameter("cid", conversationId);
              }
  
              protected void updateModelValues() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(102l);
                  Contexts.getPageContext().set("currentDirectory", forumDir);
              }
  
              protected void invokeApplication() throws Exception {
                  TopicHome home = (TopicHome)getInstance("topicHome");
  
                  home.getInstance().setName("New Topic");
                  home.setFormContent("This is a new topic.");
  
                  assert invokeMethod("#{topicHome.persist}") == null;
              }
  
              protected void renderResponse() throws Exception {
                  Long newId = (Long)getValue("#{topicHome.instance.id}");
  
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDocument newTopic = nodeDAO.findWikiDocument(newId);
  
                  assert newTopic.getAreaNumber().equals(100l);
  
                  FeedDAO feedDAO = (FeedDAO)getInstance("feedDAO");
                  FeedEntry fe = feedDAO.findFeedEntry(newTopic);
                  assert fe.getTitle().equals("[Seam Users] New Topic");
  
                  assert newTopic.getHeaderMacrosString().contains("forumPosting");
                  assert newTopic.getFooterMacrosString().contains("forumReplies");
                  assert newTopic.getContent().equals("This is a new topic.");
                  assert !newTopic.isNameAsTitle();
                  assert newTopic.isEnableCommentForm();
                  assert newTopic.isEnableComments();
                  assert newTopic.isEnableCommentsOnFeeds();
              }
          }.run();
  
      }
  
      @Test
      public void newStickyTopic() throws Exception {
  
          loginAdmin();
  
          final String conversationId = new FacesRequest() {
  
              protected void updateModelValues() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(102l);
                  Contexts.getPageContext().set("currentDirectory", forumDir);
              }
  
              protected void invokeApplication() throws Exception {
                  TopicHome home = (TopicHome)getInstance("topicHome");
                  home.newTopic();
              }
          }.run();
  
          new FacesRequest() {
  
              protected void beforeRequest() {
                  setParameter("cid", conversationId);
              }
  
              protected void updateModelValues() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(102l);
                  Contexts.getPageContext().set("currentDirectory", forumDir);
              }
  
              protected void invokeApplication() throws Exception {
                  TopicHome home = (TopicHome)getInstance("topicHome");
  
                  home.getInstance().setName("New Topic");
                  home.setFormContent("This is a new topic.");
                  home.setSticky(true);
  
                  assert invokeMethod("#{topicHome.persist}") == null;
              }
  
              protected void renderResponse() throws Exception {
                  Long newId = (Long)getValue("#{topicHome.instance.id}");
  
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDocument newTopic = nodeDAO.findWikiDocument(newId);
  
                  assert newTopic.getAreaNumber().equals(100l);
  
                  FeedDAO feedDAO = (FeedDAO)getInstance("feedDAO");
                  FeedEntry fe = feedDAO.findFeedEntry(newTopic);
                  assert fe.getTitle().equals("[Seam Users] New Topic");
  
                  assert newTopic.getHeaderMacrosString().contains("forumStickyPosting");
                  assert newTopic.getFooterMacrosString().contains("forumReplies");
                  assert newTopic.getContent().equals("This is a new topic.");
                  assert !newTopic.isNameAsTitle();
                  assert newTopic.isEnableCommentForm();
                  assert newTopic.isEnableComments();
                  assert newTopic.isEnableCommentsOnFeeds();
              }
          }.run();
      }
  
      @Test
      public void newClosedTopic() throws Exception {
  
          loginAdmin();
  
          final String conversationId = new FacesRequest() {
  
              protected void updateModelValues() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(102l);
                  Contexts.getPageContext().set("currentDirectory", forumDir);
              }
  
              protected void invokeApplication() throws Exception {
                  TopicHome home = (TopicHome)getInstance("topicHome");
                  home.newTopic();
              }
          }.run();
  
          new FacesRequest() {
  
              protected void beforeRequest() {
                  setParameter("cid", conversationId);
              }
  
              protected void updateModelValues() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(102l);
                  Contexts.getPageContext().set("currentDirectory", forumDir);
              }
  
              protected void invokeApplication() throws Exception {
                  TopicHome home = (TopicHome)getInstance("topicHome");
  
                  home.getInstance().setName("New Topic");
                  home.setFormContent("This is a new topic.");
                  home.getInstance().setEnableComments(false);
  
                  assert invokeMethod("#{topicHome.persist}") == null;
              }
  
              protected void renderResponse() throws Exception {
                  Long newId = (Long)getValue("#{topicHome.instance.id}");
  
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDocument newTopic = nodeDAO.findWikiDocument(newId);
  
                  assert newTopic.getAreaNumber().equals(100l);
  
                  FeedDAO feedDAO = (FeedDAO)getInstance("feedDAO");
                  FeedEntry fe = feedDAO.findFeedEntry(newTopic);
                  assert fe.getTitle().equals("[Seam Users] New Topic");
  
                  assert newTopic.getHeaderMacrosString().contains("forumPosting");
                  assert newTopic.getFooterMacrosString().contains("forumReplies");
                  assert newTopic.getContent().equals("This is a new topic.");
                  assert !newTopic.isNameAsTitle();
                  assert !newTopic.isEnableComments();
              }
          }.run();
      }
  
      private void loginAdmin() throws Exception {
          new FacesRequest() {
             protected void invokeApplication() throws Exception {
                setValue("#{identity.username}", "admin");
                setValue("#{identity.password}", "admin");
                invokeAction("#{identity.login}");
                assert getValue("#{identity.loggedIn}").equals(true);
             }
          }.run();
      }
  
  
  }
  
  
  1.1      date: 2007/12/19 04:29:27;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/plugin/ForumQueryTests.java
  
  Index: ForumQueryTests.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.plugin;
  
  import org.dbunit.operation.DatabaseOperation;
  import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
  import org.jboss.seam.wiki.core.model.WikiDirectory;
  import org.jboss.seam.wiki.core.model.WikiDocument;
  import org.jboss.seam.wiki.core.dao.WikiNodeDAO;
  import org.jboss.seam.wiki.plugin.forum.*;
  import org.jboss.seam.contexts.Contexts;
  import org.testng.annotations.Test;
  
  import java.util.*;
  
  public class ForumQueryTests extends DBUnitSeamTest {
  
      protected void prepareDBUnitOperations() {
          beforeTestOperations.add(
              new DataSetOperation("org/jboss/seam/wiki/test/WikiBaseData.dbunit.xml", DatabaseOperation.CLEAN_INSERT)
          );
          beforeTestOperations.add(
              new DataSetOperation("org/jboss/seam/wiki/test/ForumData.dbunit.xml", DatabaseOperation.INSERT)
          );
      }
  
      @Test
      public void findForums() throws Exception {
  
          loginMember();
  
          new FacesRequest() {
  
              protected void updateModelValues() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(100l);
                  Contexts.getPageContext().set("currentDirectory", forumDir);
              }
  
              protected void invokeApplication() throws Exception {
  
                  ForumQuery query = (ForumQuery)getInstance("forumQuery");
                  List<ForumInfo> forums = query.getForums();
  
                  assert forums.size() == 2;
  
                  assert forums.get(0).getForum().getId().equals(102l);
                  assert forums.get(0).getTotalNumOfTopics() == 2;
                  assert forums.get(0).getTotalNumOfPosts() == 5;
                  assert forums.get(0).getLastTopic().getId().equals(107l);
                  assert forums.get(0).getLastComment().getId().equals(106l);
                  assert forums.get(0).isUnreadPostings();
  
                  assert forums.get(1).getForum().getId().equals(109l);
                  assert forums.get(1).getTotalNumOfTopics() == 1;
                  assert forums.get(1).getTotalNumOfPosts() == 1;
                  assert forums.get(1).getLastTopic().getId().equals(111l);
                  assert forums.get(1).getLastComment() == null;
                  assert forums.get(1).isUnreadPostings();
              }
          }.run();
      }
  
      @Test
      public void findTopicsOne() throws Exception {
  
          loginMember();
  
          new FacesRequest() {
  
              protected void updateModelValues() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(102l);
                  Contexts.getPageContext().set("currentDirectory", forumDir);
              }
  
              protected void invokeApplication() throws Exception {
  
                  ForumQuery query = (ForumQuery)getInstance("forumQuery");
                  List<TopicInfo> topics = query.getTopics();
  
                  assert topics.size() == 2;
  
                  assert topics.get(0).getTopic().getId().equals(107l);
                  assert topics.get(0).getNumOfReplies() == 1l;
                  assert topics.get(0).isSticky();
                  assert topics.get(0).getLastComment().getId().equals(108l);
                  assert topics.get(0).isUnread();
  
                  assert topics.get(1).getTopic().getId().equals(104l);
                  assert topics.get(1).getNumOfReplies() == 2l;
                  assert !topics.get(1).isSticky();
                  assert topics.get(1).getLastComment().getId().equals(106l);
                  assert topics.get(0).isUnread();
              }
          }.run();
      }
  
      @Test
      public void findTopicsTwo() throws Exception {
  
          loginMember();
  
          new FacesRequest() {
  
              protected void updateModelValues() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(109l);
                  Contexts.getPageContext().set("currentDirectory", forumDir);
              }
  
              protected void invokeApplication() throws Exception {
  
                  ForumQuery query = (ForumQuery)getInstance("forumQuery");
                  List<TopicInfo> topics = query.getTopics();
  
                  assert topics.size() == 1;
  
                  assert topics.get(0).getTopic().getId().equals(111l);
                  assert topics.get(0).getNumOfReplies() == 0l;
                  assert !topics.get(0).isSticky();
                  assert topics.get(0).getLastComment() == null;
                  assert topics.get(0).isUnread();
              }
          }.run();
      }
  
      private void loginMember() throws Exception {
          new FacesRequest() {
             protected void invokeApplication() throws Exception {
                setValue("#{identity.username}", "member");
                setValue("#{identity.password}", "member");
                invokeAction("#{identity.login}");
                assert getValue("#{identity.loggedIn}").equals(true);
             }
          }.run();
      }
  
  }
  
  
  1.1      date: 2007/12/19 04:29:27;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/plugin/ForumHomeTests.java
  
  Index: ForumHomeTests.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.plugin;
  
  import org.dbunit.operation.DatabaseOperation;
  import org.hibernate.Session;
  import org.hibernate.ejb.HibernateEntityManagerFactory;
  import org.jboss.seam.contexts.Contexts;
  import org.jboss.seam.wiki.core.dao.WikiNodeDAO;
  import org.jboss.seam.wiki.core.model.*;
  import org.jboss.seam.wiki.plugin.forum.ForumHome;
  import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
  import org.testng.annotations.Test;
  
  public class ForumHomeTests extends DBUnitSeamTest {
  
      protected void prepareDBUnitOperations() {
          beforeTestOperations.add(
              new DataSetOperation("org/jboss/seam/wiki/test/WikiBaseData.dbunit.xml", DatabaseOperation.CLEAN_INSERT)
          );
          beforeTestOperations.add(
              new DataSetOperation("org/jboss/seam/wiki/test/ForumData.dbunit.xml", DatabaseOperation.INSERT)
          );
      }
  
      @Test
      public void addForum() throws Exception {
  
          loginAdmin();
  
          final String conversationId = new FacesRequest() {
  
              protected void updateModelValues() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(100l);
                  Contexts.getPageContext().set("currentDirectory", forumDir);
              }
  
              protected void invokeApplication() throws Exception {
                  ForumHome home = (ForumHome)getInstance("forumHome");
                  home.newForum();
              }
          }.run();
  
          new FacesRequest() {
  
              protected void beforeRequest() {
                  setParameter("cid", conversationId);
              }
  
              protected void updateModelValues() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(100l);
                  Contexts.getPageContext().set("currentDirectory", forumDir);
              }
  
              protected void invokeApplication() throws Exception {
                  ForumHome home = (ForumHome)getInstance("forumHome");
  
                  home.getInstance().setName("New Forum");
                  home.getInstance().setDescription("This is a new forum");
  
                  assert invokeMethod("#{forumHome.persist}") == null;
              }
  
              protected void renderResponse() throws Exception {
                  Long newId = (Long)getValue("#{forumHome.instance.id}");
  
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory newForum = nodeDAO.findWikiDirectory(newId);
  
                  assert newForum.getAreaNumber().equals(100l);
  
                  assert newForum.getFeed() != null;
  
                  Session s = getHibernateSession();
                  WikiMenuItem newMenuItem = (WikiMenuItem)s
                          .createQuery("select m from WikiMenuItem m where m.directory.id = :dir")
                          .setParameter("dir", newId)
                          .uniqueResult();
                  assert newMenuItem.getDisplayPosition() == 2l;
                  s.close();
  
                  assert newForum.getDefaultFile().getName().equals("New Forum Forum");
                  assert newForum.getDefaultFile().getAreaNumber().equals(100l);
                  assert newForum.getDefaultFile().getWikiname().equals("NewForumForum");
                  assert ((WikiDocument)newForum.getDefaultFile()).isNameAsTitle();
                  assert newForum.getDefaultFile().getReadAccessLevel() == 0;
                  assert newForum.getDefaultFile().getWriteAccessLevel() == Role.ADMINROLE_ACCESSLEVEL;
                  assert newForum.getDefaultFile().getCreatedBy().getUsername().equals(User.ADMIN_USERNAME);
                  assert !((WikiDocument)newForum.getDefaultFile()).isEnableCommentForm();
                  assert !((WikiDocument)newForum.getDefaultFile()).isEnableComments();
                  assert !((WikiDocument)newForum.getDefaultFile()).isEnableCommentsOnFeeds();
                  assert ((WikiDocument)newForum.getDefaultFile()).getHeaderMacrosString()
                          .equals("clearBackground hideControls hideComments hideTags hideCreatorHistory");
                  assert ((WikiDocument)newForum.getDefaultFile()).getContentMacrosString().equals("forumTopics");
                  assert ((WikiDocument)newForum.getDefaultFile()).getFooterMacrosString().equals("");
  
              }
          }.run();
  
      }
  
  
      private void loginAdmin() throws Exception {
          new FacesRequest() {
             protected void invokeApplication() throws Exception {
                setValue("#{identity.username}", "admin");
                setValue("#{identity.password}", "admin");
                invokeAction("#{identity.login}");
                assert getValue("#{identity.loggedIn}").equals(true);
             }
          }.run();
      }
  
      private Session getHibernateSession() throws Exception {
          org.jboss.ejb3.entity.InjectedEntityManagerFactory jbossEMF =
                  (org.jboss.ejb3.entity.InjectedEntityManagerFactory) getInitialContext().lookup("java:/entityManagerFactories/wiki");
          return ((HibernateEntityManagerFactory) jbossEMF.getDelegate()).getSessionFactory().openSession();
      }
  
  
  }
  
  
  1.1      date: 2007/12/19 04:29:27;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/plugin/BlogDAOTests.java
  
  Index: BlogDAOTests.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.plugin;
  
  import org.dbunit.operation.DatabaseOperation;
  import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
  
  public class BlogDAOTests extends DBUnitSeamTest {
  
      protected void prepareDBUnitOperations() {
          beforeTestOperations.add(
              new DataSetOperation("org/jboss/seam/wiki/test/WikiBaseData.dbunit.xml", DatabaseOperation.CLEAN_INSERT)
          );
          beforeTestOperations.add(
              new DataSetOperation("org/jboss/seam/wiki/test/BlogData.dbunit.xml", DatabaseOperation.INSERT)
          );
      }
  /*
      @Test
      public void findBlogEntriesWithCommentCount() throws Exception {
          new FacesRequest() {
              protected void invokeApplication() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory blogDir = nodeDAO.findWikiDirectory(51l);
  
                  BlogDAO dao = (BlogDAO)getInstance("blogDAO");
  
                  List<BlogEntry> entries =
                      dao.findBlogEntriesWithCommentCount(
                              blogDir,
                              (WikiDocument)blogDir.getDefaultFile(),
                              "createdOn", true,
                              0, 10,
                              null, null, null,
                              null
                      );
                  assert entries.size() == 5;
                  assert entries.get(0).getEntryDocument().getId().equals(55l);
                  assert entries.get(0).getCommentCount().equals(2l);
                  assert entries.get(1).getEntryDocument().getId().equals(54l);
                  assert entries.get(1).getCommentCount().equals(1l);
                  assert entries.get(2).getEntryDocument().getId().equals(53l);
                  assert entries.get(2).getCommentCount().equals(0l);
                  assert entries.get(3).getEntryDocument().getId().equals(52l);
                  assert entries.get(3).getCommentCount().equals(0l);
                  assert entries.get(4).getEntryDocument().getId().equals(51l);
                  assert entries.get(4).getCommentCount().equals(0l);
              }
          }.run();
  
      }
  
      @Test
      public void findBlogEntriesWithCommentCountLimitDate() throws Exception {
          new FacesRequest() {
              protected void invokeApplication() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory blogDir = nodeDAO.findWikiDirectory(51l);
  
                  BlogDAO dao = (BlogDAO)getInstance("blogDAO");
  
                  // Year
                  List<BlogEntry> entries =
                      dao.findBlogEntriesWithCommentCount(
                              blogDir,
                              (WikiDocument)blogDir.getDefaultFile(),
                              "createdOn", true,
                              0,10,
                              2007, null, null,
                              null
                      );
                  assert entries.size() == 4;
                  assert entries.get(0).getEntryDocument().getId().equals(55l);
                  assert entries.get(0).getCommentCount().equals(2l);
                  assert entries.get(1).getEntryDocument().getId().equals(54l);
                  assert entries.get(1).getCommentCount().equals(1l);
                  assert entries.get(2).getEntryDocument().getId().equals(53l);
                  assert entries.get(2).getCommentCount().equals(0l);
                  assert entries.get(3).getEntryDocument().getId().equals(52l);
                  assert entries.get(3).getCommentCount().equals(0l);
  
                  // Month
                  entries =
                      dao.findBlogEntriesWithCommentCount(
                              blogDir,
                              (WikiDocument)blogDir.getDefaultFile(),
                              "createdOn", true,
                              0,10,
                              2007, 8, null,
                              null
                      );
                  assert entries.size() == 2;
                  assert entries.get(0).getEntryDocument().getId().equals(53l);
                  assert entries.get(0).getCommentCount().equals(0l);
                  assert entries.get(1).getEntryDocument().getId().equals(52l);
                  assert entries.get(1).getCommentCount().equals(0l);
  
                  // Day
                  entries =
                      dao.findBlogEntriesWithCommentCount(
                              blogDir,
                              (WikiDocument)blogDir.getDefaultFile(),
                              "createdOn", true,
                              0, 10,
                              2007, 9, 2,
                              null
                      );
                  assert entries.size() == 2;
                  assert entries.get(0).getEntryDocument().getId().equals(55l);
                  assert entries.get(0).getCommentCount().equals(2l);
                  assert entries.get(1).getEntryDocument().getId().equals(54l);
                  assert entries.get(1).getCommentCount().equals(1l);
  
              }
          }.run();
  
      }
  
      @Test
      public void findBlogEntriesWithCommentCountLimitTag() throws Exception {
          new FacesRequest() {
              protected void invokeApplication() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory blogDir = nodeDAO.findWikiDirectory(51l);
  
                  BlogDAO dao = (BlogDAO)getInstance("blogDAO");
  
                  // Year
                  List<BlogEntry> entries =
                      dao.findBlogEntriesWithCommentCount(
                              blogDir,
                              (WikiDocument)blogDir.getDefaultFile(),
                              "createdOn", true,
                              0,10,
                              null, null, null,
                              "foo"
                      );
  
                  assert entries.size() == 3;
                  assert entries.get(0).getEntryDocument().getId().equals(55l);
                  assert entries.get(0).getCommentCount().equals(2l);
                  assert entries.get(1).getEntryDocument().getId().equals(52l);
                  assert entries.get(1).getCommentCount().equals(0l);
                  assert entries.get(2).getEntryDocument().getId().equals(51l);
                  assert entries.get(2).getCommentCount().equals(0l);
              }
          }.run();
      }
  
      @Test
      public void findBlogEntriesWithCommentCountLimitTagDate() throws Exception {
          new FacesRequest() {
              protected void invokeApplication() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory blogDir = nodeDAO.findWikiDirectory(51l);
  
                  BlogDAO dao = (BlogDAO)getInstance("blogDAO");
  
                  // Year
                  List<BlogEntry> entries =
                      dao.findBlogEntriesWithCommentCount(
                              blogDir,
                              (WikiDocument)blogDir.getDefaultFile(),
                              "createdOn", true,
                              0,10,
                              2007, null, null,
                              "foo"
                      );
  
                  assert entries.size() == 2;
                  assert entries.get(0).getEntryDocument().getId().equals(55l);
                  assert entries.get(0).getCommentCount().equals(2l);
                  assert entries.get(1).getEntryDocument().getId().equals(52l);
                  assert entries.get(1).getCommentCount().equals(0l);
              }
          }.run();
      }
      */
  
  }
  
  
  
  1.1      date: 2007/12/19 04:29:27;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/plugin/ForumDAOTests.java
  
  Index: ForumDAOTests.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.plugin;
  
  import org.dbunit.operation.DatabaseOperation;
  import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
  import org.jboss.seam.wiki.core.model.WikiDirectory;
  import org.jboss.seam.wiki.core.dao.WikiNodeDAO;
  import org.jboss.seam.wiki.plugin.forum.ForumDAO;
  import org.jboss.seam.wiki.plugin.forum.ForumInfo;
  import org.jboss.seam.wiki.plugin.forum.TopicInfo;
  import org.testng.annotations.Test;
  
  import java.util.*;
  
  public class ForumDAOTests extends DBUnitSeamTest {
  
      protected void prepareDBUnitOperations() {
          beforeTestOperations.add(
              new DataSetOperation("org/jboss/seam/wiki/test/WikiBaseData.dbunit.xml", DatabaseOperation.CLEAN_INSERT)
          );
          beforeTestOperations.add(
              new DataSetOperation("org/jboss/seam/wiki/test/ForumData.dbunit.xml", DatabaseOperation.INSERT)
          );
      }
  
      @Test
      public void findForumsGuest() throws Exception {
          new FacesRequest() {
              protected void invokeApplication() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(100l);
  
                  ForumDAO dao = (ForumDAO)getInstance("forumDAO");
  
                  Map<Long, ForumInfo> forums = dao.findForums(forumDir);
  
                  assert forums.size() == 1;
                  assert forums.get(102l).getForum().getId().equals(102l);
              }
          }.run();
      }
  
      @Test
      public void findForumsMember() throws Exception {
  
          loginMember();
  
          new FacesRequest() {
              protected void invokeApplication() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(100l);
  
                  ForumDAO dao = (ForumDAO)getInstance("forumDAO");
  
                  Map<Long, ForumInfo> forums = dao.findForums(forumDir);
  
                  assert forums.size() == 2;
                  assert forums.get(102l).getForum().getId().equals(102l);
                  assert forums.get(109l).getForum().getId().equals(109l);
              }
          }.run();
  
      }
  
      @Test
      public void findForumInfoMember() throws Exception {
  
          loginMember();
  
          new FacesRequest() {
              protected void invokeApplication() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forumDir = nodeDAO.findWikiDirectory(100l);
  
                  ForumDAO dao = (ForumDAO)getInstance("forumDAO");
  
                  Map<Long, ForumInfo> infos = dao.findForums(forumDir);
                  assert infos.size() == 2;
  
                  assert infos.get(102l).getTotalNumOfTopics() == 2;
                  assert infos.get(102l).getTotalNumOfPosts() == 5;
                  assert infos.get(102l).getLastTopic().getId().equals(107l);
                  assert infos.get(102l).getLastComment().getId().equals(106l);
  
                  assert infos.get(109l).getTotalNumOfTopics() == 1;
                  assert infos.get(109l).getTotalNumOfPosts() == 1;
                  assert infos.get(109l).getLastTopic().getId().equals(111l);
                  assert infos.get(109l).getLastComment() == null;
              }
          }.run();
  
      }
  
      @Test
      public void findUnreadTopicsAllForums() throws Exception {
  
          loginMember();
  
          new FacesRequest() {
              protected void invokeApplication() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forums = nodeDAO.findWikiDirectory(100l);
  
                  ForumDAO dao = (ForumDAO)getInstance("forumDAO");
  
                  Calendar lastLogin = new GregorianCalendar(2007, 2, 1);
                  Map<Long, Long> unreadTopics = dao.findUnreadTopicAndParentIds(forums, lastLogin.getTime());
  
                  assert unreadTopics.size() == 3;
                  assert unreadTopics.get(111l).equals(109l);
                  assert unreadTopics.get(107l).equals(102l);
                  assert unreadTopics.get(104l).equals(102l);
  
                  lastLogin = new GregorianCalendar(2007, 3, 5);
                  unreadTopics = dao.findUnreadTopicAndParentIds(forums, lastLogin.getTime());
  
                  assert unreadTopics.size() == 2;
                  assert unreadTopics.get(111l).equals(109l);
                  assert unreadTopics.get(104l).equals(102l);
              }
          }.run();
      }
  
      @Test
      public void findUnreadTopicsInForum() throws Exception {
  
          loginMember();
  
          new FacesRequest() {
              protected void invokeApplication() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forum = nodeDAO.findWikiDirectory(102l);
  
                  ForumDAO dao = (ForumDAO)getInstance("forumDAO");
  
                  Calendar lastLogin = new GregorianCalendar(2007, 2, 1);
                  Map<Long, Long> unreadTopics = dao.findUnreadTopicAndParentIdsInForum(forum, lastLogin.getTime());
  
                  assert unreadTopics.size() == 2;
                  assert unreadTopics.get(107l).equals(102l);
                  assert unreadTopics.get(104l).equals(102l);
  
                  lastLogin = new GregorianCalendar(2007, 3, 5);
                  unreadTopics = dao.findUnreadTopicAndParentIdsInForum(forum, lastLogin.getTime());
  
                  assert unreadTopics.size() == 1;
                  assert unreadTopics.get(104l).equals(102l);
              }
          }.run();
      }
  
      @Test
      public void findTopicCount() throws Exception {
  
          loginMember();
  
          new FacesRequest() {
              protected void invokeApplication() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forum = nodeDAO.findWikiDirectory(102l);
  
                  ForumDAO dao = (ForumDAO)getInstance("forumDAO");
                  assert dao.findTopicCount(forum).equals(2l);
  
                  forum = nodeDAO.findWikiDirectory(109l);
                  assert dao.findTopicCount(forum).equals(1l);
  
              }
          }.run();
  
      }
  
      @Test
      public void findTopicsOne() throws Exception {
  
          loginMember();
  
          new FacesRequest() {
              protected void invokeApplication() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forum = nodeDAO.findWikiDirectory(102l);
  
                  ForumDAO dao = (ForumDAO)getInstance("forumDAO");
  
                  Map<Long, TopicInfo> topics = dao.findTopics(forum, 0, 10);
  
                  assert topics.size() == 2;
  
                  assert topics.get(107l).getTopic().getId().equals(107l);
                  assert topics.get(107l).getNumOfReplies() == 1l;
                  assert topics.get(107l).isSticky();
                  assert topics.get(107l).getLastComment().getId().equals(108l);
  
                  assert topics.get(104l).getTopic().getId().equals(104l);
                  assert topics.get(104l).getNumOfReplies() == 2l;
                  assert !topics.get(104l).isSticky();
                  assert topics.get(104l).getLastComment().getId().equals(106l);
              }
          }.run();
      }
  
      @Test
      public void findTopicsTwo() throws Exception {
  
          loginMember();
  
          new FacesRequest() {
              protected void invokeApplication() throws Exception {
                  WikiNodeDAO nodeDAO = (WikiNodeDAO)getInstance("wikiNodeDAO");
                  WikiDirectory forum = nodeDAO.findWikiDirectory(109l);
  
                  ForumDAO dao = (ForumDAO)getInstance("forumDAO");
  
                  Map<Long, TopicInfo> topics = dao.findTopics(forum, 0, 10);
  
                  assert topics.size() == 1;
  
                  assert topics.get(111l).getTopic().getId().equals(111l);
                  assert topics.get(111l).getNumOfReplies() == 0l;
                  assert !topics.get(111l).isSticky();
                  assert topics.get(111l).getLastComment() == null;
              }
          }.run();
  
      }
  
      private void loginMember() throws Exception {
          new FacesRequest() {
             protected void invokeApplication() throws Exception {
                setValue("#{identity.username}", "member");
                setValue("#{identity.password}", "member");
                invokeAction("#{identity.login}");
                assert getValue("#{identity.loggedIn}").equals(true);
             }
          }.run();
      }
  
  }
  
  



More information about the jboss-cvs-commits mailing list