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

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


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

  Added:       examples/wiki/src/test/org/jboss/seam/wiki/test/browse        
                        DisplayComments.java DisplayHelp.java
                        DisplayDocuments.java DisplayMenu.java
                        DisplayHistory.java DisplayDirectories.java
  Removed:     examples/wiki/src/test/org/jboss/seam/wiki/test/browse        
                        DisplayNodes.java TestAreaAndDocument.xml
  Log:
  Major rewrite of the most of the application
  
  Revision  Changes    Path
  1.1      date: 2007/12/19 04:29:28;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/browse/DisplayComments.java
  
  Index: DisplayComments.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.browse;
  
  import org.dbunit.operation.DatabaseOperation;
  import org.jboss.seam.wiki.core.action.CommentQuery;
  import org.jboss.seam.wiki.core.model.WikiDocument;
  import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
  import org.testng.annotations.Test;
  
  public class DisplayComments extends DBUnitSeamTest {
  
  
      protected void prepareDBUnitOperations() {
          beforeTestOperations.add(
              new DataSetOperation("org/jboss/seam/wiki/test/WikiBaseData.dbunit.xml", DatabaseOperation.CLEAN_INSERT)
          );
      }
  
      @Test
      public void commentQuery() throws Exception {
  
          new NonFacesRequest("/wiki.xhtml") {
  
              protected void beforeRequest() {
                  setParameter("nodeId", "6");
              }
  
              protected void renderResponse() throws Exception {
                  WikiDocument doc = (WikiDocument)getValue("#{currentDocument}");
                  assert doc != null;
                  assert doc.getId().equals(6l);
  
  
                  CommentQuery commentQuery = (CommentQuery)getInstance("commentQuery");
                  assert commentQuery.getComments().size() == 6;
  
                  assert commentQuery.getComments().get(0).getId().equals(10l);
                  assert commentQuery.getComments().get(1).getId().equals(11l);
                  assert commentQuery.getComments().get(2).getId().equals(12l);
                  assert commentQuery.getComments().get(3).getId().equals(13l);
                  assert commentQuery.getComments().get(4).getId().equals(14l);
                  assert commentQuery.getComments().get(5).getId().equals(15l);
              }
  
          }.run();
      }
  
  
  }
  
  
  
  1.1      date: 2007/12/19 04:29:28;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/browse/DisplayHelp.java
  
  Index: DisplayHelp.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.browse;
  
  import org.dbunit.operation.DatabaseOperation;
  import org.jboss.seam.wiki.core.action.Help;
  import org.jboss.seam.wiki.core.nestedset.query.NestedSetNodeWrapper;
  import org.jboss.seam.wiki.core.model.WikiDirectory;
  import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
  import org.testng.annotations.Test;
  
  public class DisplayHelp 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/HelpDocuments.dbunit.xml", DatabaseOperation.INSERT)
          );
      }
  
      @Test
      public void checkHelpDirectories() throws Exception {
  
          new FacesRequest("/wiki.xhtml") {
              protected void renderResponse() throws Exception {
  
                  Help help = (Help)getValue("#{help}");
                  NestedSetNodeWrapper<WikiDirectory> root = help.getRoot();
  
                  assert root.getWrappedChildren().size() == 4;
                  assert root.getWrappedChildren().size() == root.getWrappedChildrenSorted().size();
  
                  // These guys are sorted because we flattened the tree (see NestedSetResultTransformer docs)
                  assert root.getWrappedChildren().get(0).getLevel().equals(1l);
                  assert root.getWrappedChildren().get(0).getWrappedNode().getId().equals(23l);
                  assert root.getWrappedChildren().get(1).getLevel().equals(2l);
                  assert root.getWrappedChildren().get(1).getWrappedNode().getId().equals(25l);
                  assert root.getWrappedChildren().get(2).getLevel().equals(2l);
                  assert root.getWrappedChildren().get(2).getWrappedNode().getId().equals(24l);
                  assert root.getWrappedChildren().get(3).getLevel().equals(1l);
                  assert root.getWrappedChildren().get(3).getWrappedNode().getId().equals(21l);
  
                  assert help.getSelectedDirectory() == null;
                  assert help.getSelectedDocument() == null;
  
              }
          }.run();
      }
  
      @Test
      public void selectHelpDocument() throws Exception {
  
          new FacesRequest("/wiki.xhtml") {
  
              protected void invokeApplication() throws Exception {
                  assert invokeMethod("#{help.selectDocumentByName('Wiki Text Markup')}") == null;
              }
  
              protected void renderResponse() throws Exception {
  
                  Help help = (Help)getValue("#{help}");
                  NestedSetNodeWrapper<WikiDirectory> root = help.getRoot();
  
                  assert root.getWrappedChildren().size() == 4;
                  assert root.getWrappedChildren().size() == root.getWrappedChildrenSorted().size();
  
                  // These guys are sorted because we flattened the tree (see NestedSetResultTransformer docs)
                  assert root.getWrappedChildren().get(0).getLevel().equals(1l);
                  assert root.getWrappedChildren().get(0).getWrappedNode().getId().equals(23l);
                  assert root.getWrappedChildren().get(1).getLevel().equals(2l);
                  assert root.getWrappedChildren().get(1).getWrappedNode().getId().equals(25l);
                  assert root.getWrappedChildren().get(2).getLevel().equals(2l);
                  assert root.getWrappedChildren().get(2).getWrappedNode().getId().equals(24l);
                  assert root.getWrappedChildren().get(3).getLevel().equals(1l);
                  assert root.getWrappedChildren().get(3).getWrappedNode().getId().equals(21l);
  
  
                  assert help.getSelectedNode().getWrappedNode().getId().equals(21l);
                  assert help.getSelectedDocument().getId().equals(22l);
                  assert help.getSelectedDirectory().getId().equals(21l);
  
              }
          }.run();
      }
  
  }
  
  
  
  1.1      date: 2007/12/19 04:29:28;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/browse/DisplayDocuments.java
  
  Index: DisplayDocuments.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.browse;
  
  import org.dbunit.operation.DatabaseOperation;
  import org.jboss.seam.wiki.core.model.*;
  import org.jboss.seam.wiki.core.action.DocumentHome;
  import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
  import org.testng.annotations.Test;
  
  import java.util.List;
  
  public class DisplayDocuments extends DBUnitSeamTest {
  
  
      protected void prepareDBUnitOperations() {
          beforeTestOperations.add(
                  new DataSetOperation("org/jboss/seam/wiki/test/WikiBaseData.dbunit.xml", DatabaseOperation.CLEAN_INSERT)
          );
      }
  
      @Test
      public void documentFromNodeId() throws Exception {
  
          new NonFacesRequest("/wiki.xhtml") {
  
              protected void beforeRequest() {
                  setParameter("nodeId", "6");
              }
  
              protected void renderResponse() throws Exception {
                  WikiDocument doc = (WikiDocument)getValue("#{currentDocument}");
                  assert doc != null;
                  assert doc.getId().equals(6l);
                  
                  assert doc.getArea().getId().equals(3l);
  
                  WikiDirectory dir = (WikiDirectory)getValue("#{currentDirectory}");
                  assert dir != null;
                  assert dir.getId().equals(3l);
  
                  List<WikiNode> currentDirectoryPath = (List<WikiNode>)getValue("#{breadcrumb}");
                  assert currentDirectoryPath.size() == 2;
                  assert currentDirectoryPath.get(0).getId().equals( ((WikiDirectory)getValue("#{currentDirectory}")).getId() );
                  assert currentDirectoryPath.get(1).getId().equals( ((WikiDocument)getValue("#{currentDocument}")).getId()  );
  
                  assert getRenderedViewId().equals("/docDisplay_d.xhtml");
              }
  
          }.run();
      }
  
      @Test
      public void documentFromWikiName() throws Exception {
  
          new NonFacesRequest("/wiki.xhtml") {
  
              protected void beforeRequest() {
                  setParameter("areaName", "CCC");
                  setParameter("nodeName", "One");
              }
  
              protected void renderResponse() throws Exception {
                  WikiDocument doc = (WikiDocument)getValue("#{currentDocument}");
                  assert doc != null;
                  assert doc.getId().equals(6l);
  
                  WikiDirectory dir = (WikiDirectory)getValue("#{currentDirectory}");
                  assert dir != null;
                  assert dir.getId().equals(3l);
  
                  assert getRenderedViewId().equals("/docDisplay_d.xhtml");
              }
          }.run();
      }
  
      @Test
      public void defaultDocumentFromAreaWikiName() throws Exception {
  
          new NonFacesRequest("/wiki.xhtml") {
  
              protected void beforeRequest() {
                  setParameter("areaName", "CCC");
              }
  
              protected void renderResponse() throws Exception {
                  WikiDocument doc = (WikiDocument)getValue("#{currentDocument}");
                  assert doc != null;
                  assert doc.getId().equals(6l);
  
                  WikiDirectory dir = (WikiDirectory)getValue("#{currentDirectory}");
                  assert dir != null;
                  assert dir.getId().equals(3l);
  
                  assert getRenderedViewId().equals("/docDisplay_d.xhtml");
              }
          }.run();
      }
  
  }
  
  
  
  1.1      date: 2007/12/19 04:29:28;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/browse/DisplayMenu.java
  
  Index: DisplayMenu.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.browse;
  
  import org.dbunit.operation.DatabaseOperation;
  import org.jboss.seam.wiki.core.action.Menu;
  import org.jboss.seam.wiki.core.nestedset.query.NestedSetNodeWrapper;
  import org.jboss.seam.wiki.core.model.WikiDirectory;
  import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
  import org.testng.annotations.Test;
  
  public class DisplayMenu extends DBUnitSeamTest {
  
  
      protected void prepareDBUnitOperations() {
          beforeTestOperations.add(
                  new DataSetOperation("org/jboss/seam/wiki/test/WikiBaseData.dbunit.xml", DatabaseOperation.CLEAN_INSERT)
          );
      }
  
      @Test
      public void allMenuItems() throws Exception {
  
          new NonFacesRequest("/wiki.xhtml") {
  
              protected void renderResponse() throws Exception {
  
                  Menu menu = (Menu)getValue("#{menu}");
  
                  assert menu.getRoot().getAdditionalProjections().get("displayPosition") == null;
                  assert menu.getRoot().getWrappedNode().getId().equals(1l);
                  assert menu.getRoot().getLevel().equals(0l);
                  assert menu.getRoot().getWrappedChildren().size() == 2;
                  for (NestedSetNodeWrapper<WikiDirectory> child : menu.getRoot().getWrappedChildrenSorted()) {
                      assert child.getLevel().equals(1l);
                  }
  
              }
  
          }.run();
      }
  
  
      /*
          System.out.println("#### GOT MENU ROOT DISPLAY POSITION: " + menu.getRoot().getAdditionalProjections().get("displayPosition") + ": " + menu.getRoot());
          System.out.println("############## ROOT HAS CHILDREN: " + menu.getRoot().getWrappedChildren().size());
  
          for (NestedSetNodeWrapper<WikiDirectory> child : menu.getRoot().getWrappedChildrenSorted()) {
  
              System.out.println("#### CHILD DISPLAY POSITION: " + child.getAdditionalProjections().get("displayPosition") + ": " + child);
  
              for (NestedSetNodeWrapper<WikiDirectory> child2 : child.getWrappedChildrenSorted()) {
                  System.out.println("####### CHILD2 DISPLAY POSITION: " + child.getAdditionalProjections().get("displayPosition") + ": " + child2);
  
              }
          }
       */
  }
  
  
  1.1      date: 2007/12/19 04:29:28;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/browse/DisplayHistory.java
  
  Index: DisplayHistory.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.browse;
  
  import org.dbunit.operation.DatabaseOperation;
  import org.jboss.seam.wiki.TestBean;
  import org.jboss.seam.wiki.core.action.DocumentHistory;
  import org.jboss.seam.wiki.core.model.WikiFile;
  import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
  import org.testng.annotations.Test;
  
  import java.util.List;
  
  // TODO: Finish this, http://jira.jboss.com/jira/browse/JBSEAM-2296
  public class DisplayHistory extends DBUnitSeamTest {
  
  
      protected void prepareDBUnitOperations() {
          beforeTestOperations.add(
                  new DataSetOperation("org/jboss/seam/wiki/test/WikiBaseData.dbunit.xml", DatabaseOperation.CLEAN_INSERT)
          );
      }
  
      @Test
      public void displayDocumentHistory() throws Exception {
  
          new FacesRequest("/docHistory_d.xhtml") {
  
              protected void beforeRequest() {
                  setParameter("fileId", "6");
              }
  
              protected void invokeApplication() throws Exception {
                  DocumentHistory docHistory = (DocumentHistory)getInstance("documentHistory");
                  docHistory.init();
              }
  
              protected void renderResponse() throws Exception {
                  WikiFile currentFile = (WikiFile)getValue("#{documentHistory.currentFile}");
                  assert currentFile.getId().equals(6l);
                  assert currentFile.getRevision() == 3;
  
                  DocumentHistory docHistory = (DocumentHistory)getInstance("documentHistory");
                  List<WikiFile> historicalFileList = docHistory.getHistoricalFileList();
                  assert historicalFileList.size() == 3;
  
                  // Sorted by revision descending
                  assert historicalFileList.get(0).getRevision() == 2;
                  assert historicalFileList.get(0).getId().equals(6l);
                  assert historicalFileList.get(0).getLastModifiedByUsername().equals("admin");
                  assert historicalFileList.get(0).getLastModifiedOn() != null;
  
                  assert historicalFileList.get(1).getRevision() == 1;
                  assert historicalFileList.get(0).getId().equals(6l);
                  assert historicalFileList.get(1).getLastModifiedByUsername().equals("guest");
                  assert historicalFileList.get(1).getLastModifiedOn() != null;
  
                  assert historicalFileList.get(2).getRevision() == 0;
                  assert historicalFileList.get(0).getId().equals(6l);
                  assert historicalFileList.get(2).getLastModifiedByUsername().equals("admin");
                  assert historicalFileList.get(2).getLastModifiedOn() == null;
  
              }
          }.run();
      }
  
      //@Test
      // TODO: Seam bug http://jira.jboss.com/jira/browse/JBSEAM-2296
      public void displayHistoricalRevision() throws Exception {
  
          new FacesRequest("/docHistory_d.xhtml") {
  
              protected void beforeRequest() {
                  setParameter("fileId", "1");
              }
  
              protected void invokeApplication() throws Exception {
                  DocumentHistory docHistory = (DocumentHistory)getInstance("documentHistory");
                  docHistory.init();
  
                  List<WikiFile> historicalFileList = docHistory.getHistoricalFileList();
                  WikiFile selected = historicalFileList.get(1);
                  assert selected.getHistoricalFileId().equals(2l);
  
                  System.out.println("#### HASH BEFORE: " + selected.hashCode());
                  docHistory.setSelectedHistoricalFile(selected);
                  WikiFile selectedHistoricalFile = docHistory.getSelectedHistoricalFile();
  
                  System.out.println("#### HASH AFTER: " + selectedHistoricalFile.hashCode());
                  assert selectedHistoricalFile.getHistoricalFileId().equals(selected.getHistoricalFileId());
                  assert selectedHistoricalFile.getId().equals(1l);
                  assert selectedHistoricalFile.getRevision() == 1;
              }
  
              protected void renderResponse() throws Exception {
                  DocumentHistory docHistory = (DocumentHistory)getInstance("documentHistory");
  
              }
          }.run();
      }
  
      //@Test
      public void test() throws Exception {
          new FacesRequest() {
              /*
              protected void invokeApplication() throws Exception {
                  TestBean testBean = (TestBean)getInstance("testBean");
                  testBean.init();
                  testBean.setName("B");
                  System.out.println("#### NAME IS: " + testBean.getName());
                  assert testBean.getName().equals("B");
              }
              */
          }.run();
      }
  
  }
  
  
  
  1.1      date: 2007/12/19 04:29:28;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/browse/DisplayDirectories.java
  
  Index: DisplayDirectories.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.browse;
  
  import org.dbunit.operation.DatabaseOperation;
  import org.jboss.seam.wiki.core.action.DirectoryHome;
  import org.jboss.seam.wiki.core.model.*;
  import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
  import org.testng.annotations.Test;
  
  public class DisplayDirectories extends DBUnitSeamTest {
  
  
      protected void prepareDBUnitOperations() {
          beforeTestOperations.add(
                  new DataSetOperation("org/jboss/seam/wiki/test/WikiBaseData.dbunit.xml", DatabaseOperation.CLEAN_INSERT)
          );
      }
  
      @Test
      public void directoryFromAreaWikiname() throws Exception {
  
          new NonFacesRequest("/wiki.xhtml") {
  
              protected void beforeRequest() {
                  setParameter("areaName", "BBB");
              }
  
              protected void renderResponse() throws Exception {
                  WikiDocument doc = (WikiDocument)getValue("#{currentDocument}");
                  assert doc == null;
  
                  DirectoryHome dirHome = (DirectoryHome)getInstance("directoryHome");
                  WikiDirectory dir = dirHome.getInstance();
                  assert dir != null;
                  assert dir.getId().equals(2l);
                  assert dir.getArea().getId().equals(2l);
  
                  assert dirHome.getChildNodes().size() == 1;
  
                  assert getRenderedViewId().equals("/dirDisplay_d.xhtml");
              }
          }.run();
      }
  
      @Test
      public void directoryFromFullWikiname() throws Exception {
  
          new NonFacesRequest("/wiki.xhtml") {
  
              protected void beforeRequest() {
                  setParameter("areaName", "CCC");
                  setParameter("nodeName", "DDD");
              }
  
              protected void renderResponse() throws Exception {
                  WikiDocument doc = (WikiDocument)getValue("#{currentDocument}");
                  assert doc == null;
  
                  DirectoryHome dirHome = (DirectoryHome)getInstance("directoryHome");
                  WikiDirectory dir = dirHome.getInstance();
                  assert dir != null;
                  assert dir.getId().equals(4l);
  
                  assert dirHome.getChildNodes().size() == 1;
  
                  assert getRenderedViewId().equals("/dirDisplay_d.xhtml");
              }
          }.run();
      }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list