[jboss-cvs] jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/editing ...
Christian Bauer
christian at hibernate.org
Fri Jan 11 13:05:15 EST 2008
User: cbauer
Date: 08/01/11 13:05:15
Modified: examples/wiki/src/test/org/jboss/seam/wiki/test/editing
Linking.java
Log:
JBSEAM-2136 - Anchor/linking support for document headlines
Revision Changes Path
1.3 +103 -38 jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/editing/Linking.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Linking.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/editing/Linking.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Linking.java 10 Jan 2008 08:37:45 -0000 1.2
+++ Linking.java 11 Jan 2008 18:05:15 -0000 1.3
@@ -7,13 +7,20 @@
package org.jboss.seam.wiki.test.editing;
import org.dbunit.operation.DatabaseOperation;
-import org.jboss.seam.core.Conversation;
import org.jboss.seam.wiki.core.action.DocumentHome;
+import org.jboss.seam.wiki.core.engine.WikiLink;
+import org.jboss.seam.wiki.core.engine.WikiLinkResolver;
+import org.jboss.seam.wiki.core.engine.WikiTextRenderer;
import org.jboss.seam.wiki.core.model.WikiDocument;
import org.jboss.seam.wiki.core.model.WikiUpload;
import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
+import org.jboss.seam.wiki.util.WikiUtil;
import org.testng.annotations.Test;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
public class Linking extends DBUnitSeamTest {
protected void prepareDBUnitOperations() {
@@ -23,6 +30,9 @@
beforeTestOperations.add(
new DataSetOperation("org/jboss/seam/wiki/test/UploadData.dbunit.xml", DatabaseOperation.INSERT)
);
+ beforeTestOperations.add(
+ new DataSetOperation("org/jboss/seam/wiki/test/HelpDocuments.dbunit.xml", DatabaseOperation.INSERT)
+ );
}
@Test
@@ -31,7 +41,6 @@
final String conversationId = new NonFacesRequest("/docEdit_d.xhtml") {
protected void beforeRequest() {
setParameter("documentId", "6");
- setParameter("parentDirectoryId", "3");
}
}.run();
@@ -42,8 +51,6 @@
}
protected void invokeApplication() throws Exception {
- assert Conversation.instance().isLongRunning();
-
DocumentHome docHome = (DocumentHome)getInstance(DocumentHome.class);
assert docHome.getInstance().getId().equals(6l); // Init!
@@ -85,12 +92,11 @@
}
@Test
- public void linkToDocuments() throws Exception {
+ public void linkToCustomProtocols() throws Exception {
final String conversationId = new NonFacesRequest("/docEdit_d.xhtml") {
protected void beforeRequest() {
setParameter("documentId", "6");
- setParameter("parentDirectoryId", "3");
}
}.run();
@@ -101,35 +107,81 @@
}
protected void invokeApplication() throws Exception {
- assert Conversation.instance().isLongRunning();
+ DocumentHome docHome = (DocumentHome)getInstance(DocumentHome.class);
+ assert docHome.getInstance().getId().equals(6l); // Init!
+
+ WikiLinkResolver resolver = (WikiLinkResolver)getInstance("wikiLinkResolver");
+ Map<String, WikiLink> links = new HashMap<String, WikiLink>();
+
+ docHome.setFormContent("[=>hhh://1234]");
+ resolver.resolveLinkText(3l, links, "hhh://1234");
+ assert links.size()==1;
+ assert links.get("hhh://1234").getUrl().equals("http://opensource.atlassian.com/projects/hibernate/browse/HHH-1234");
+ }
+
+ }.run();
+ }
+
+ @Test
+ public void linkToDocuments() throws Exception {
+ final String conversationId = new NonFacesRequest("/docEdit_d.xhtml") {
+ protected void beforeRequest() {
+ setParameter("documentId", "6");
+ }
+ }.run();
+
+ new FacesRequest("/docEdit_d.xhtml") {
+
+ protected void beforeRequest() {
+ setParameter("cid", conversationId);
+ }
+
+ protected void invokeApplication() throws Exception {
DocumentHome docHome = (DocumentHome)getInstance(DocumentHome.class);
assert docHome.getInstance().getId().equals(6l); // Init!
- docHome.setFormContent("[=>Two]");
- assert docHome.getInstance().getContent().equals("[=>wiki://7]");
- assert docHome.getFormContent().equals("[=>Two]");
+ WikiLinkResolver resolver = (WikiLinkResolver)getInstance("wikiLinkResolver");
- docHome.setFormContent("[=>Four]");
- assert docHome.getInstance().getContent().equals("[=>Four]");
- assert docHome.getFormContent().equals("[=>Four]");
+ checkLink(resolver, 7l, "[=>Two]", "[=>wiki://7]");
+ checkLink(resolver, 7l, "[Foo Bar=>Two]", "[Foo Bar=>wiki://7]");
- docHome.setFormContent("[=>BBB|Four]");
- assert docHome.getInstance().getContent().equals("[=>wiki://9]");
- assert docHome.getFormContent().equals("[=>BBB|Four]");
+ checkLink(resolver, 9l, "[=>BBB|Four]", "[=>wiki://9]");
+ checkLink(resolver, 9l, "[Foo Bar=>BBB|Four]", "[Foo Bar=>wiki://9]");
- docHome.setFormContent("[Foo Bar=>Two]");
- assert docHome.getInstance().getContent().equals("[Foo Bar=>wiki://7]");
- assert docHome.getFormContent().equals("[Foo Bar=>Two]");
+ checkLink(resolver, null, "[=>Four]", "[=>Four]"); // Broken link
+ checkLink(resolver, null, "[Foo Bar=>Four]", "[Foo Bar=>Four]"); // Broken link
- docHome.setFormContent("[Foo Bar=>Four]");
- assert docHome.getInstance().getContent().equals("[Foo Bar=>Four]");
- assert docHome.getFormContent().equals("[Foo Bar=>Four]");
+ }
- docHome.setFormContent("[Foo Bar=>BBB|Four]");
- assert docHome.getInstance().getContent().equals("[Foo Bar=>wiki://9]");
- assert docHome.getFormContent().equals("[Foo Bar=>BBB|Four]");
+ }.run();
+ }
+ @Test
+ public void linkToDocumentFragments() throws Exception {
+
+ final String conversationId = new NonFacesRequest("/docEdit_d.xhtml") {
+ protected void beforeRequest() {
+ setParameter("documentId", "6");
+ }
+ }.run();
+
+ new FacesRequest("/docEdit_d.xhtml") {
+
+ protected void beforeRequest() {
+ setParameter("cid", conversationId);
+ }
+
+ protected void invokeApplication() throws Exception {
+ DocumentHome docHome = (DocumentHome)getInstance(DocumentHome.class);
+ assert docHome.getInstance().getId().equals(6l); // Init!
+
+ WikiLinkResolver resolver = (WikiLinkResolver)getInstance("wikiLinkResolver");
+
+ final String FRAGMENT = "#foo123.,; baz -?!()/&";
+
+ checkLink(resolver, 7l, "[=>Two"+FRAGMENT+"]", "[=>wiki://7"+FRAGMENT+"]", FRAGMENT);
+ checkLink(resolver, 9l, "[=>BBB|Four"+FRAGMENT+"]", "[=>wiki://9"+FRAGMENT+"]", FRAGMENT);
}
}.run();
@@ -141,7 +193,6 @@
final String conversationId = new NonFacesRequest("/docEdit_d.xhtml") {
protected void beforeRequest() {
setParameter("documentId", "6");
- setParameter("parentDirectoryId", "3");
}
}.run();
@@ -152,19 +203,12 @@
}
protected void invokeApplication() throws Exception {
- assert Conversation.instance().isLongRunning();
-
DocumentHome docHome = (DocumentHome)getInstance(DocumentHome.class);
assert docHome.getInstance().getId().equals(6l); // Init!
- docHome.setFormContent("[=>Two]");
- assert docHome.getInstance().getContent().equals("[=>wiki://7]");
- assert docHome.getFormContent().equals("[=>Two]");
-
- docHome.setFormContent("[=>BBB|Test Image]");
- assert docHome.getInstance().getContent().equals("[=>wiki://30]");
- assert docHome.getFormContent().equals("[=>BBB|Test Image]");
+ WikiLinkResolver resolver = (WikiLinkResolver)getInstance("wikiLinkResolver");
+ checkLink(resolver, 30l, "[=>BBB|Test Image]", "[=>wiki://30]");
}
}.run();
@@ -176,7 +220,6 @@
final String conversationId = new NonFacesRequest("/docEdit_d.xhtml") {
protected void beforeRequest() {
setParameter("documentId", "6");
- setParameter("parentDirectoryId", "3");
}
}.run();
@@ -187,8 +230,6 @@
}
protected void invokeApplication() throws Exception {
- assert Conversation.instance().isLongRunning();
-
DocumentHome docHome = (DocumentHome)getInstance(DocumentHome.class);
assert docHome.getInstance().getId().equals(6l); // Init!
@@ -223,5 +264,29 @@
}.run();
}
+ private void checkLink(WikiLinkResolver resolver, Long fileId, String wikiText, String databaseText) {
+ checkLink(resolver, fileId, wikiText, databaseText, null);
+ }
+
+ private void checkLink(WikiLinkResolver resolver, Long fileId, String wikiText, String databaseText, String fragment) {
+ assert resolver.convertToWikiProtocol(new HashSet(), 3l, wikiText).equals(databaseText);
+ assert resolver.convertFromWikiProtocol(3l, databaseText).equals(wikiText);
+ Map<String, WikiLink> links = new HashMap<String, WikiLink>();
+ resolver.resolveLinkText(3l, links, databaseText);
+ assert links.size()==1;
+ if (fileId == null) {
+ assert links.get(databaseText).isBroken();
+ } else {
+ assert links.get(databaseText).getFile().getId().equals(fileId);
+ if (fragment != null) {
+ assert links.get(databaseText).getFragment().equals(fragment);
+ assert links.get(databaseText).getEncodedFragment().equals(
+ WikiTextRenderer.HEADLINE_ID_PREFIX+WikiUtil.convertToWikiName(fragment)
+ );
+ }
+ }
+
+ }
+
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list