[jboss-cvs] jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/editing ...
Christian Bauer
christian at hibernate.org
Sat Aug 25 13:59:27 EDT 2007
User: cbauer
Date: 07/08/25 13:59:27
Modified: examples/wiki/src/test/org/jboss/seam/wiki/test/editing
NestedNodes.xml BasicNodeOperations.java
Added: examples/wiki/src/test/org/jboss/seam/wiki/test/editing
OptionalNodeOperations.java
Log:
Major refactoring of navigation
Revision Changes Path
1.2 +0 -2 jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/editing/NestedNodes.xml
(In the diff below, changes in quantity of whitespace are not shown.)
Index: NestedNodes.xml
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/editing/NestedNodes.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- NestedNodes.xml 17 Aug 2007 13:00:30 -0000 1.1
+++ NestedNodes.xml 25 Aug 2007 17:59:27 -0000 1.2
@@ -5,8 +5,6 @@
<NODE NODE_ID="100" NODE_TYPE="DIRECTORY" NODE_REVISION="1" OBJ_VERSION="0" NAME="Test Area" WIKINAME="TestArea"
READ_ACCESS_LEVEL="0" WRITE_ACCESS_LEVEL="0" MENU_ITEM="true" CREATED_ON="2006-09-23 13:45:00" CREATED_BY_USER_ID="1" LAST_MODIFIED_ON="2006-09-23 13:45:00" LAST_MODIFIED_BY_USER_ID="1"
AREA_NR="100" PARENT_NODE_ID="1" NS_THREAD="1" NS_LEFT="8" NS_RIGHT="23" DISPLAY_POSITION="2"/>
- <NODE_DIRECTORY DIRECTORY_ID="100" DEFAULT_DOCUMENT_ID="101"/>
-
<NODE NODE_ID="101" NODE_TYPE="DOCUMENT" NODE_REVISION="1" OBJ_VERSION="0" NAME="Test Document1" WIKINAME="TestDocument1"
READ_ACCESS_LEVEL="0" WRITE_ACCESS_LEVEL="0" MENU_ITEM="true" CREATED_ON="2006-09-23 13:45:00" CREATED_BY_USER_ID="1" LAST_MODIFIED_ON="2006-09-23 13:45:00" LAST_MODIFIED_BY_USER_ID="1"
1.2 +72 -21 jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/editing/BasicNodeOperations.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BasicNodeOperations.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/editing/BasicNodeOperations.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- BasicNodeOperations.java 17 Aug 2007 13:00:30 -0000 1.1
+++ BasicNodeOperations.java 25 Aug 2007 17:59:27 -0000 1.2
@@ -19,6 +19,9 @@
import org.jboss.seam.wiki.core.nestedset.NestedSetResultTransformer;
import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
import org.jboss.seam.wiki.util.WikiUtil;
+import org.jboss.seam.core.Conversation;
+import org.jboss.seam.faces.Redirect;
+import org.jboss.seam.Component;
import org.testng.annotations.Test;
import java.util.Comparator;
@@ -50,22 +53,33 @@
@Test
public void deleteDocument() throws Exception {
+ final String conversationId = new NonFacesRequest("/docEdit.xhtml") {
+ protected void beforeRequest() {
+ setParameter("documentId", TEST_DOCUMENT1_ID.toString());
+ setParameter("parentDirectoryId", TEST_DIRECTORY1_ID.toString());
+ }
+ }.run();
+
new FacesRequest("/docEdit.xhtml") {
protected void beforeRequest() {
- setParameter("nodeId", TEST_DOCUMENT1_ID.toString());
- setParameter("parentDirId", TEST_DIRECTORY1_ID.toString());
+ setParameter("cid", conversationId);
}
protected void invokeApplication() throws Exception {
+ assert Conversation.instance().isLongRunning();
- assert checkNestedSetNodeInMemory( (Node)getValue("#{documentHome.instance}"), 9, 10);
- assert checkNestedSetNodeInMemory( (Node)getValue("#{documentHome.parentDirectory}"), 8, 23);
+ DocumentHome docHome = (DocumentHome)getInstance("documentHome");
+ assert checkNestedSetNodeInMemory( docHome.getInstance(), 9, 10);
+ assert checkNestedSetNodeInMemory( docHome.getParentDirectory(), 8, 23);
assert invokeMethod("#{documentHome.remove}").equals("removed");
- }
- protected void renderResponse() throws Exception {
+ // TODO: SeamTest doesn't do navigation but we don't want to have /docEdit.xhtml in the RENDER RESPONSE
+ Conversation.instance().end();
+ Redirect.instance().setViewId("/dirDisplay.xhtml");
+ Redirect.instance().execute();
+
assert checkNestedSetNodeInDatabase(TEST_DIRECTORY1_ID, 8, 21);
assert checkNestedSetNodeInDatabase(TEST_DOCUMENT2_ID, 9, 10);
assert checkNestedSetNodeInDatabase(TEST_DOCUMENT3_ID, 11, 12);
@@ -85,14 +99,22 @@
@Test
public void deleteDirectory() throws Exception {
+ final String conversationId = new NonFacesRequest("/dirEdit.xhtml") {
+ protected void beforeRequest() {
+ setParameter("directoryId", TEST_DIRECTORY2_ID.toString());
+ setParameter("parentDirectoryId", TEST_DIRECTORY1_ID.toString());
+ }
+ }.run();
+
new FacesRequest("/dirEdit.xhtml") {
protected void beforeRequest() {
- setParameter("nodeId", TEST_DIRECTORY2_ID.toString());
- setParameter("parentDirId", TEST_DIRECTORY1_ID.toString());
+ setParameter("cid", conversationId);
}
protected void invokeApplication() throws Exception {
+ DirectoryHome dirHome = (DirectoryHome)getInstance("directoryHome");
+ dirHome.init(); // TODO: Seam test doesn't call page actions
assert checkNestedSetNodeInDatabase(TEST_DIRECTORY1_ID, 8, 23);
assert checkNestedSetNodeInDatabase(TEST_DOCUMENT1_ID, 9, 10);
assert checkNestedSetNodeInDatabase(TEST_DOCUMENT2_ID, 11, 12);
@@ -102,13 +124,16 @@
assert checkNestedSetNodeInDatabase(TEST_DOCUMENT6_ID, 18, 19);
assert checkNestedSetNodeInDatabase(TEST_DOCUMENT7_ID, 21, 22);
- assert checkNestedSetNodeInMemory( (Node)getValue("#{directoryHome.instance}"), 15, 20);
- assert checkNestedSetNodeInMemory( (Node)getValue("#{directoryHome.parentDirectory}"), 8, 23);
+ assert checkNestedSetNodeInMemory( dirHome.getInstance(), 15, 20);
+ assert checkNestedSetNodeInMemory( dirHome.getParentDirectory(), 8, 23);
assert invokeMethod("#{directoryHome.remove}").equals("removed");
- }
- protected void renderResponse() throws Exception {
+ // TODO: SeamTest doesn't do navigation but we don't want to have /dirEdit.xhtml in the RENDER RESPONSE
+ Conversation.instance().end();
+ Redirect.instance().setViewId("/dirDisplay.xhtml");
+ Redirect.instance().execute();
+
assert checkNestedSetNodeInDatabase(TEST_DIRECTORY1_ID, 8, 17);
assert checkNestedSetNodeInDatabase(TEST_DOCUMENT1_ID, 9, 10);
assert checkNestedSetNodeInDatabase(TEST_DOCUMENT2_ID, 11, 12);
@@ -128,10 +153,16 @@
@Test
public void createDocumentInArea() throws Exception {
+ final String conversationId = new NonFacesRequest("/docEdit.xhtml") {
+ protected void beforeRequest() {
+ setParameter("parentDirectoryId", TEST_DIRECTORY1_ID.toString());
+ }
+ }.run();
+
new FacesRequest("/docEdit.xhtml") {
protected void beforeRequest() {
- setParameter("parentDirId", TEST_DIRECTORY1_ID.toString());
+ setParameter("cid", conversationId);
}
protected void invokeApplication() throws Exception {
@@ -151,9 +182,10 @@
assert checkNestedSetNodeInDatabase(TEST_DOCUMENT6_ID, 18, 19);
assert checkNestedSetNodeInDatabase(TEST_DOCUMENT7_ID, 21, 22);
- assert checkNestedSetNodeInMemory( (Node)getValue("#{documentHome.parentDirectory}"), 8, 23);
+ assert checkNestedSetNodeInMemory( docHome.getParentDirectory(), 8, 23);
assert invokeMethod("#{documentHome.persist}").equals("persisted");
+
}
protected void renderResponse() throws Exception {
@@ -183,14 +215,21 @@
@Test
public void createDocumentInSubdirectory() throws Exception {
+ final String conversationId = new NonFacesRequest("/docEdit.xhtml") {
+ protected void beforeRequest() {
+ setParameter("parentDirectoryId", TEST_DIRECTORY2_ID.toString());
+ }
+ }.run();
+
new FacesRequest("/docEdit.xhtml") {
protected void beforeRequest() {
- setParameter("parentDirId", TEST_DIRECTORY2_ID.toString());
+ setParameter("cid", conversationId);
}
protected void invokeApplication() throws Exception {
DocumentHome docHome = (DocumentHome)getInstance("documentHome");
+
docHome.getInstance().setName("Testname");
docHome.getInstance().setReadAccessLevel(0);
docHome.getInstance().setWriteAccessLevel(0);
@@ -205,7 +244,7 @@
assert checkNestedSetNodeInDatabase(TEST_DOCUMENT6_ID, 18, 19);
assert checkNestedSetNodeInDatabase(TEST_DOCUMENT7_ID, 21, 22);
- assert checkNestedSetNodeInMemory( (Node)getValue("#{documentHome.parentDirectory}"), 15, 20);
+ assert checkNestedSetNodeInMemory( docHome.getParentDirectory(), 15, 20);
assert invokeMethod("#{documentHome.persist}").equals("persisted");
}
@@ -236,11 +275,17 @@
@Test
public void moveDirectoryLeft() throws Exception {
+ final String conversationId = new NonFacesRequest("/dirEdit.xhtml") {
+ protected void beforeRequest() {
+ setParameter("directoryId", TEST_DIRECTORY1_ID.toString());
+ setParameter("parentDirectoryId", TEST_WIKI_ROOT_ID.toString());
+ }
+ }.run();
+
new FacesRequest("/dirEdit.xhtml") {
protected void beforeRequest() {
- setParameter("nodeId", TEST_DIRECTORY1_ID.toString());
- setParameter("parentDirId", TEST_WIKI_ROOT_ID.toString());
+ setParameter("cid", conversationId);
}
protected void invokeApplication() throws Exception {
@@ -279,11 +324,17 @@
@Test
public void moveDocumentRight() throws Exception {
+ final String conversationId = new NonFacesRequest("/dirEdit.xhtml") {
+ protected void beforeRequest() {
+ setParameter("directoryId", TEST_DIRECTORY1_ID.toString());
+ setParameter("parentDirectoryId", TEST_WIKI_ROOT_ID.toString());
+ }
+ }.run();
+
new FacesRequest("/dirEdit.xhtml") {
protected void beforeRequest() {
- setParameter("nodeId", TEST_DIRECTORY1_ID.toString());
- setParameter("parentDirId", TEST_WIKI_ROOT_ID.toString());
+ setParameter("cid", conversationId);
}
protected void invokeApplication() throws Exception {
@@ -362,7 +413,7 @@
}
}
private void displayNodes(NestedSetNodeWrapper<Node> startNode) {
- StringBuffer levelMarkers = new StringBuffer();
+ StringBuilder levelMarkers = new StringBuilder();
for (int i = 1; i <= startNode.getLevel(); i++) {
levelMarkers.append("#");
}
1.1 date: 2007/08/25 17:59:27; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/editing/OptionalNodeOperations.java
Index: OptionalNodeOperations.java
===================================================================
package org.jboss.seam.wiki.test.editing;
import org.dbunit.operation.DatabaseOperation;
import org.jboss.seam.log.Log;
import org.jboss.seam.log.Logging;
import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
import org.jboss.seam.wiki.core.action.DirectoryHome;
import org.jboss.seam.wiki.core.model.Document;
import org.jboss.seam.core.Conversation;
import org.testng.annotations.Test;
public class OptionalNodeOperations extends DBUnitSeamTest {
private Log log = Logging.getLog(OptionalNodeOperations.class);
private static final Long TEST_WIKI_ROOT_ID = 1l;
private static final Long TEST_DIRECTORY1_ID = 100l;
private static final Long TEST_DOCUMENT1_ID = 101l;
private static final Long TEST_DOCUMENT2_ID = 102l;
private static final Long TEST_DOCUMENT3_ID = 103l;
private static final Long TEST_DIRECTORY2_ID = 104l;
private static final Long TEST_DOCUMENT5_ID = 105l;
private static final Long TEST_DOCUMENT6_ID = 106l;
private static final Long TEST_DOCUMENT7_ID = 107l;
protected void prepareDBUnitOperations() {
beforeTestOperations.add(
new DataSetOperation("org/jboss/seam/wiki/test/WikiBaseData.xml")
);
beforeTestOperations.add(
new DataSetOperation("org/jboss/seam/wiki/test/editing/NestedNodes.xml", DatabaseOperation.INSERT)
);
}
@Test
public void setDefaultDocument() throws Exception {
final String conversationId = new NonFacesRequest("/dirEdit.xhtml") {
protected void beforeRequest() {
setParameter("directoryId", TEST_DIRECTORY1_ID.toString());
setParameter("parentDirectoryId", TEST_WIKI_ROOT_ID.toString());
}
}.run();
new FacesRequest("/dirEdit.xhtml") {
Long newDefaultDocumentId = null;
protected void beforeRequest() {
setParameter("cid", conversationId);
}
protected void invokeApplication() throws Exception {
assert Conversation.instance().isLongRunning();
DirectoryHome dirHome = (DirectoryHome)getInstance("directoryHome");
// Just take the first one
Document defaultDocument = dirHome.getChildDocuments().get(0);
dirHome.getInstance().setDefaultDocument(defaultDocument);
newDefaultDocumentId = defaultDocument.getId();
assert invokeMethod("#{directoryHome.update}").equals("updated");
}
protected void renderResponse() throws Exception {
DirectoryHome dirHome = (DirectoryHome)getInstance("directoryHome");
assert dirHome.getInstance().getDefaultDocument().getId().equals(newDefaultDocumentId);
}
}.run();
}
@Test
public void changeDefaultDocument() throws Exception {
final String conversationId = new NonFacesRequest("/dirEdit.xhtml") {
protected void beforeRequest() {
setParameter("directoryId", TEST_DIRECTORY2_ID.toString());
setParameter("parentDirectoryId", TEST_DIRECTORY1_ID.toString());
}
}.run();
new FacesRequest("/dirEdit.xhtml") {
Long newDefaultDocumentId = null;
protected void beforeRequest() {
setParameter("cid", conversationId);
}
protected void invokeApplication() throws Exception {
assert Conversation.instance().isLongRunning();
DirectoryHome dirHome = (DirectoryHome)getInstance("directoryHome");
// Switch from first to second
Document defaultDocument = dirHome.getChildDocuments().get(1);
dirHome.getInstance().setDefaultDocument(defaultDocument);
newDefaultDocumentId = defaultDocument.getId();
assert invokeMethod("#{directoryHome.update}").equals("updated");
}
protected void renderResponse() throws Exception {
DirectoryHome dirHome = (DirectoryHome)getInstance("directoryHome");
assert dirHome.getInstance().getDefaultDocument().getId().equals(newDefaultDocumentId);
}
}.run();
}
}
More information about the jboss-cvs-commits
mailing list