Author: piergiorgiolucidi
Date: 2009-03-03 13:54:59 -0500 (Tue, 03 Mar 2009)
New Revision: 249
Added:
contrib/wikiPortlet/trunk/wiki-test/
contrib/wikiPortlet/trunk/wiki-test/.classpath
contrib/wikiPortlet/trunk/wiki-test/.project
contrib/wikiPortlet/trunk/wiki-test/.settings/
contrib/wikiPortlet/trunk/wiki-test/.settings/org.hibernate.eclipse.console.prefs
contrib/wikiPortlet/trunk/wiki-test/META-INF/
contrib/wikiPortlet/trunk/wiki-test/WEB-INF/
contrib/wikiPortlet/trunk/wiki-test/WEB-INF/web.xml
contrib/wikiPortlet/trunk/wiki-test/maven.xml
contrib/wikiPortlet/trunk/wiki-test/pom.xml
contrib/wikiPortlet/trunk/wiki-test/project.properties
contrib/wikiPortlet/trunk/wiki-test/project.xml
contrib/wikiPortlet/trunk/wiki-test/src/
contrib/wikiPortlet/trunk/wiki-test/src/etc/
contrib/wikiPortlet/trunk/wiki-test/src/etc/testing-ideas.txt
contrib/wikiPortlet/trunk/wiki-test/src/java/
contrib/wikiPortlet/trunk/wiki-test/src/java/org/
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/AttachmentTest.java
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/DictionaryTest.java
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/FindPagesTest.java
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/GetSavePageTest.java
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/PageModsTest.java
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/PropsTest.java
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/SubPagesTest.java
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/TestCredentials.java
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/TestWikiSession.java
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/WikiTest.java
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/WikiTestException.java
contrib/wikiPortlet/trunk/wiki-test/src/web/
contrib/wikiPortlet/trunk/wiki-test/src/web/WEB-INF/
contrib/wikiPortlet/trunk/wiki-test/src/web/WEB-INF/web.xml
Log:
- Portal 2.7.x support: wiki-test
Added: contrib/wikiPortlet/trunk/wiki-test/.classpath
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/.classpath (rev 0)
+++ contrib/wikiPortlet/trunk/wiki-test/.classpath 2009-03-03 18:54:59 UTC (rev 249)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/java"/>
+ <classpathentry kind="lib"
path="src/web/WEB-INF/lib/junitee.jar"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: contrib/wikiPortlet/trunk/wiki-test/.project
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/.project (rev 0)
+++ contrib/wikiPortlet/trunk/wiki-test/.project 2009-03-03 18:54:59 UTC (rev 249)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>wiki-test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: contrib/wikiPortlet/trunk/wiki-test/.settings/org.hibernate.eclipse.console.prefs
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/.settings/org.hibernate.eclipse.console.prefs
(rev 0)
+++
contrib/wikiPortlet/trunk/wiki-test/.settings/org.hibernate.eclipse.console.prefs 2009-03-03
18:54:59 UTC (rev 249)
@@ -0,0 +1,4 @@
+#Fri Mar 17 15:02:47 CET 2006
+default.configuration=
+eclipse.preferences.version=1
+hibernate3.enabled=false
Added: contrib/wikiPortlet/trunk/wiki-test/WEB-INF/web.xml
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/WEB-INF/web.xml (rev 0)
+++ contrib/wikiPortlet/trunk/wiki-test/WEB-INF/web.xml 2009-03-03 18:54:59 UTC (rev 249)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+
+
+
+</web-app>
+
Added: contrib/wikiPortlet/trunk/wiki-test/maven.xml
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/maven.xml (rev 0)
+++ contrib/wikiPortlet/trunk/wiki-test/maven.xml 2009-03-03 18:54:59 UTC (rev 249)
@@ -0,0 +1,27 @@
+<!--
+ JBoss, the OpenSource J2EE webOS
+ Distributable under LGPL license.
+ See terms of license at
gnu.org.
+ -->
+<project xmlns:j="jelly:core" xmlns:ant="jelly:ant"
xmlns:u="jelly:util" >
+ <goal name="build">
+
+ <attainGoal name="jar" />
+
+ <ant:copy file="target/wiki-test.jar"
+ tofile="target/wiki-test/WEB-INF/lib/wiki-test.jar" />
+
+ <attainGoal name="war" />
+
+ </goal>
+
+ <goal name="deploy">
+
+ </goal>
+
+ <goal name="all">
+ <attainGoal name="build" />
+ <attainGoal name="deploy" />
+ </goal>
+
+</project>
Added: contrib/wikiPortlet/trunk/wiki-test/pom.xml
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/pom.xml (rev 0)
+++ contrib/wikiPortlet/trunk/wiki-test/pom.xml 2009-03-03 18:54:59 UTC (rev 249)
@@ -0,0 +1,135 @@
+<!--
+ JBoss, the OpenSource J2EE webOS Distributable under LGPL license. See
+ terms of license at
gnu.org.
+ Maven manual install: portal-core-lib.jar
+ portal-portlet-lib javax-servlet.jar javax-servlet-jsp.jar
+ activation.jar jboss-ejb3x.jar jboss-ejb3.jar portal-identity-lib.jar
+ jboss-portlet-api-lib.jar
+
+ author: Piergiorgio Lucidi
+-->
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>jboss</groupId>
+ <artifactId>wiki</artifactId>
+ <version>1.0</version>
+ </parent>
+ <artifactId>wiki-test</artifactId>
+ <name>JBoss Wiki Test</name>
+ <version>1.0</version>
+ <packaging>war</packaging>
+ <developers>
+ <developer>
+ <name>Tomasz Szymanski</name>
+ <url>http://mamut.net.pl</url>
+ <roles>
+ <role>Retired Project Lead</role>
+ </roles>
+ </developer>
+ <developer>
+ <name>Piergiorgio Lucidi</name>
+ <email>p.lucidi(a)sourcesense.com</email>
+ <
url>http://www.open4dev.com/</url>
+ <organization>Sourcesense</organization>
+ <
organizationUrl>http://www.sourcesense.com/</organizationUrl>
+ </developer>
+ </developers>
+ <build>
+
+ <sourceDirectory>src/java</sourceDirectory>
+ <resources>
+ <resource>
+ <directory>src/etc/</directory>
+ <includes>
+ <include>**/*.properties</include>
+ <include>**/*.xml</include>
+ <include>**/*.types</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <webappDirectory>${basedir}</webappDirectory>
+ <warSourceDirectory>${basedir}</warSourceDirectory>
+ <warSourceExcludes>WEB-INF/lib/*.jar</warSourceExcludes>
+ <excludes>**/.svn/**</excludes>
+ <warName>wiki-test</warName>
+ <outputDirectory>target</outputDirectory>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>wiki-common</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.9</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jdom</groupId>
+ <artifactId>jdom</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-ejb3</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-ejb3x</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: contrib/wikiPortlet/trunk/wiki-test/project.properties
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/project.properties (rev
0)
+++ contrib/wikiPortlet/trunk/wiki-test/project.properties 2009-03-03 18:54:59 UTC (rev
249)
@@ -0,0 +1,11 @@
+maven.repo.remote=http://repository.atlassian.com,http://www.ibiblio.org/maven,http://dist.codehaus.org/
+maven.junit.fork=yes
+maven.war.src=${basedir}/src/web
+
+maven.final.name=${pom.artifactId}
+
+maven.jar.override=on
+
+maven.jar.shotoku-base=${ext.root.dir}/shotoku/shotoku-base/target/shotoku-base.jar
+
+maven.war.classes.excludes=**/test/*.class
Added: contrib/wikiPortlet/trunk/wiki-test/project.xml
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/project.xml (rev 0)
+++ contrib/wikiPortlet/trunk/wiki-test/project.xml 2009-03-03 18:54:59 UTC (rev 249)
@@ -0,0 +1,187 @@
+<?xml version='1.0' encoding='ISO-8859-1'?>
+<!--
+ JBoss, the OpenSource J2EE webOS
+ Distributable under LGPL license.
+ See terms of license at
gnu.org.
+ -->
+<project>
+ <pomVersion>3</pomVersion>
+ <extend>../common.xml</extend>
+ <id>wiki-test</id>
+ <name>Wiki test</name>
+ <currentVersion>1.0</currentVersion>
+ <build>
+ <!--
<unitTestSourceDirectory>./src/test/java</unitTestSourceDirectory>
+ <unitTest>
+ <includes>
+ <include>**/*Test.java</include>
+ <include>**/Test*.java</include>
+ </includes>
+ </unitTest>-->
+ <sourceDirectory>src/java</sourceDirectory>
+ <resources>
+ <resource>
+ <directory>src/etc/</directory>
+ <include>**/*.properties</include>
+ </resource>
+ <resource>
+ <directory>src/etc/</directory>
+ <include>**/*.xml</include>
+ </resource>
+ <resource>
+ <directory>src/etc/</directory>
+ <include>**/*.types</include>
+ </resource>
+ </resources>
+ </build>
+ <organization>
+ <name>Tomasz Szymanski</name>
+ <url>http://mamut.net.pl</url>
+ </organization>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.9</version>
+ </dependency>
+
+ <dependency>
+ <groupId>wiki-common</groupId>
+ <artifactId>wiki-common</artifactId>
+ <version>1.0</version>
+ <properties>
+� � � � � � � � <ejb.manifest.classpath>true</ejb.manifest.classpath>
+� � � � � � </properties>
+ <jar>wiki-common.jar</jar>
+ </dependency>
+
+ <dependency>
+ <groupId>aslibs</groupId>
+ <artifactId>javax.servlet</artifactId>
+ <version>1.0</version>
+ <jar>javax.servlet.jar</jar>
+ </dependency>
+
+ <dependency>
+ <groupId>aslibs</groupId>
+ <artifactId>javax.servlet.jsp</artifactId>
+ <version>1.0</version>
+ <jar>javax.servlet.jsp.jar</jar>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <properties>
+ <war.bundle>true</war.bundle>
+ </properties>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>activation</artifactId>
+ <version>1.0</version>
+ <jar>activation.jar</jar>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-fileupload</groupId>
+ <artifactId>commons-fileupload.jar</artifactId>
+ <version>1.0</version>
+ <jar>commons-fileupload-1.0.jar</jar>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>dom4j</groupId>
+ <artifactId>dom4j</artifactId>
+ <version>1.6</version>
+ </dependency>
+
+ <dependency>
+ <groupId>jdom</groupId>
+ <artifactId>jdom</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-ejb3x</artifactId>
+ <version>1.0</version>
+ <jar>jboss-ejb3x.jar</jar>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-ejb3</artifactId>
+ <version>1.0</version>
+ <jar>jboss-ejb3.jar</jar>
+ </dependency>
+
+ <dependency>
+ <id>portlet-api</id>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-jmx</artifactId>
+ <version>1.0</version>
+ <jar>jboss-jmx.jar</jar>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-common</artifactId>
+ <version>1.0</version>
+ <jar>jboss-common.jar</jar>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>portal-common-lib</artifactId>
+ <version>1.0</version>
+ <jar>portal-common-lib.jar</jar>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>portal-core-lib</artifactId>
+ <version>1.0</version>
+ <jar>portal-core-lib.jar</jar>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>portal-portlet-lib</artifactId>
+ <version>1.0</version>
+ <jar>portal-portlet-lib.jar</jar>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jbossall-client</artifactId>
+ <version>3.2.3</version>
+ </dependency>
+ </dependencies>
+</project>
Added: contrib/wikiPortlet/trunk/wiki-test/src/etc/testing-ideas.txt
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/src/etc/testing-ideas.txt
(rev 0)
+++ contrib/wikiPortlet/trunk/wiki-test/src/etc/testing-ideas.txt 2009-03-03 18:54:59 UTC
(rev 249)
@@ -0,0 +1,32 @@
+What should wiki-test do:
+
+MediaDataSource:
+- deleting
+- edit -> save -> get -> pageExist
+- subpages
+ - list
+ - deleting
+- refreshing
+- finding
+- get page/content at version
+- all page names, add page, all page name - compare
+- get/set page mods. access pages
+- editing pages with session id (add / end) - try arePagesEdited; getPagesWaiting()
+- roles set
+- get/set meta properties
+- all pages check
+
+AttachmentDataSource:
+- add/check/delete attachments for page
+- delete mutliple attachments
+- last attachment version
+- attachment at version
+- attachment size
+
+Dictionary:
+- simple - add/remove translation / tranlsation exists
+- add translation Tomek -> Ziomek, then try adding page "Tomek"
+
+Plugins:
+
+InsidePlugins:
Added:
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/AttachmentTest.java
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/AttachmentTest.java
(rev 0)
+++
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/AttachmentTest.java 2009-03-03
18:54:59 UTC (rev 249)
@@ -0,0 +1,186 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wiki.test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.wiki.WikiAttachment;
+import org.jboss.wiki.WikiPage;
+import org.jboss.wiki.exceptions.WikiException;
+
+public class AttachmentTest extends WikiTest {
+
+ private static final String ATT_CONTENT = "This is simple text attachment";
+
+ private static final String ATT_NAME = "testFile.txt";
+
+ private static final String ATT_CONTENT_2 = "This is simple text attachment, but
second one";
+
+ private static final String ATT_NAME_2 = "testAnotherFile.txt";
+
+ public void testSaveGetDelete() throws WikiException, IOException {
+ String testPage = createTestPage(plainUser, PAGE_CONTENT);
+
+ WikiPage page = wikiEngine.getByName(testPage, null, langCode);
+
+ File att = createTempFile(ATT_CONTENT);
+
+ // add attachment
+ page.addAttachement(new FileInputStream(att), ATT_NAME, plainUser
+ .getName());
+
+ att = createTempFile(ATT_CONTENT_2);
+
+ // add attachment
+ page.addAttachement(new FileInputStream(att), ATT_NAME_2, plainUser
+ .getName());
+
+ // reload page
+ wikiEngine.refreshPage(testPage, langCode);
+
+ page = wikiEngine.getByName(testPage, null, langCode);
+
+ Set<String> attSet = page.getAttachementsSet();
+
+ // see if attSet has two attachemnt, we just added
+ Set<String> mySet = new HashSet<String>();
+ mySet.add(ATT_NAME);
+ mySet.add(ATT_NAME_2);
+
+ assertEquals(attSet, mySet);
+
+ // see if attachments contain our data
+ WikiAttachment wikiAttachment1 = wikiEngine.getAttachment(testPage,
+ ATT_NAME, langCode);
+ WikiAttachment wikiAttachment2 = wikiEngine.getAttachment(testPage,
+ ATT_NAME_2, langCode);
+
+ assertEquals(
+ loadContentFromAttachment(wikiAttachment1.getInputStream()),
+ ATT_CONTENT);
+
+ // load content for 2nd attachment
+
+ assertEquals(
+ loadContentFromAttachment(wikiAttachment2.getInputStream()),
+ ATT_CONTENT_2);
+
+ // delete attachments
+ wikiEngine.deleteAttachment(testPage, ATT_NAME, langCode);
+ wikiEngine.deleteAttachment(testPage, ATT_NAME_2, langCode);
+
+ // check atts for page
+ assertTrue(page.getAttachementsSet() == null);
+ }
+
+ public void testAttachmentVersions() throws WikiException, IOException {
+ String testPage = createTestPage(plainUser, PAGE_CONTENT);
+
+ WikiPage page = wikiEngine.getByName(testPage, null, langCode);
+
+ File att = createTempFile(ATT_CONTENT);
+
+ // add attachment
+ page.addAttachement(new FileInputStream(att), ATT_NAME, plainUser
+ .getName());
+
+ File att2 = createTempFile(ATT_CONTENT_2);
+
+ // add attachment with same name and different content
+ page.addAttachement(new FileInputStream(att2), ATT_NAME, plainUser
+ .getName());
+
+
+ // get attachment
+ WikiAttachment wikiAttachment = wikiEngine.getAttachment(testPage,
+ ATT_NAME, langCode);
+
+ // version should be "2"
+ assertEquals(wikiAttachment.getVersion(), 2);
+
+ // test att size
+ assertEquals(wikiEngine.getAttachmentSize(testPage, ATT_NAME, 1, langCode),
att.length());
+ assertEquals(wikiEngine.getAttachmentSize(testPage, ATT_NAME, 2, langCode),
att2.length());
+
+ // check content of last attachment
+ assertEquals(loadContentFromAttachment(wikiAttachment.getInputStream()),
ATT_CONTENT_2);
+
+ //load att at version 1
+ wikiAttachment = wikiEngine.getAttachment(testPage, ATT_NAME, 1, langCode);
+
+ // version should be "1"
+ assertEquals(wikiAttachment.getVersion(), 1);
+
+ // check content of last attachment
+ assertEquals(loadContentFromAttachment(wikiAttachment.getInputStream()), ATT_CONTENT);
+
+ }
+
+ public void testDeleteMultipleAttachments() throws IOException, WikiException {
+ String testPage = createTestPage(plainUser, PAGE_CONTENT);
+
+ WikiPage page = wikiEngine.getByName(testPage, null, langCode);
+
+ File att = createTempFile(ATT_CONTENT);
+
+ // add attachment
+ page.addAttachement(new FileInputStream(att), ATT_NAME, plainUser
+ .getName());
+
+ File att2 = createTempFile(ATT_CONTENT_2);
+
+ // add attachment with same name and different content
+ page.addAttachement(new FileInputStream(att2), ATT_NAME_2, plainUser
+ .getName());
+
+ // see if attSet has two attachemnt, we just added
+ Set<String> mySet = new HashSet<String>();
+ mySet.add(ATT_NAME);
+ mySet.add(ATT_NAME_2);
+
+ assertEquals(page.getAttachementsSet(), mySet);
+
+ // delete all atts
+ wikiEngine.deleteAttachments(testPage, langCode);
+
+ // there should be no atts for page
+ assertTrue(page.getAttachementsSet() == null);
+ }
+
+ private String loadContentFromAttachment(InputStream is) throws IOException {
+ int chr;
+ String content = "";
+
+ while ((chr = is.read()) != -1) {
+ content += (char) chr;
+ }
+
+ is.close();
+
+ return content;
+ }
+}
Added:
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/DictionaryTest.java
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/DictionaryTest.java
(rev 0)
+++
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/DictionaryTest.java 2009-03-03
18:54:59 UTC (rev 249)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wiki.test;
+
+import java.util.Map;
+
+import org.jboss.wiki.WikiContext;
+import org.jboss.wiki.WikiPage;
+import org.jboss.wiki.exceptions.WikiException;
+import org.jboss.wiki.plugins.ReTranslateUids;
+
+public class DictionaryTest extends WikiTest {
+
+ private static final String PAGE_W_LINK_PREF = "This page contains single [";
+
+ private static final String PAGE_W_LINK_SUFF = "] - that is very linky";
+
+ private static final String LINK1 = "TestLink";
+
+ private static final String LINK2 = "AnotherLink";
+
+ public void testDictionary() throws WikiException, InterruptedException{
+
+ WikiContext wikiContext = new WikiContext(plainUser,
wikiEngine.getWikiType("html"), testWikiSession);
+
+ String page1 = createTestPage(plainUser, "1 page number 1");
+ String page2 = createTestPage(plainUser, "2 page number 2");
+
+ WikiPage wikiPage1 = wikiEngine.getByName(page1, null, langCode);
+ WikiPage wikiPage2 = wikiEngine.getByName(page2, null, langCode);
+
+ // set apropriate content of pages
+ wikiPage1.setContent("1 ["+page2+"]");
+ wikiPage1.setLastVersion(wikiPage1.getLastVersion()+1);
+ wikiPage1.save(plainUser, wikiEngine.getEditSessionId(), langCode, testWikiSession);
+
+ wikiPage2.setContent("1 ["+page2+"]");
+ wikiPage2.setLastVersion(wikiPage2.getLastVersion()+1);
+ wikiPage2.save(plainUser, wikiEngine.getEditSessionId(), langCode, testWikiSession);
+
+ int i = 0;
+ String newPage2Name = page2 + (i++);
+
+ while(wikiEngine.pageExists(newPage2Name, langCode)) {
+ newPage2Name = page2 + (i++);
+ }
+
+ log.info("New name for page2: "+newPage2Name);
+
+ addRenaming(page2, newPage2Name);
+
+ // wait for page to rename
+ while (!wikiEngine.getPagesWaiting(langCode).isEmpty()) {
+ Thread.sleep(5 * 1000);
+ }
+
+ Map<String,String> pageMapings = wikiEngine.getRenameMapings(langCode);
+ for (String uid : pageMapings.keySet()) {
+ System.out.println("Uid: "+uid+" Real: "+pageMapings.get(uid));
+ }
+
+ // add new page to deleting
+ pagesToDelete.remove(page2);
+ pagesToDelete.add(newPage2Name);
+
+ // see if page after translation exists
+ assertTrue(wikiEngine.pageExists(newPage2Name, langCode));
+
+ // get page with renamed reference
+ WikiPage afterRename = wikiEngine.getByName(page1, wikiContext, langCode);
+
+ String pageContentRenamed = afterRename.getContent();
+
+ log.info("page1 content: "+pageContentRenamed);
+
+ int link = -1;
+
+ // look if there is any link
+ if ((link = pageContentRenamed.lastIndexOf(hostURL+"/wiki/")) == -1) {
+ fail("There is no link in afterRename page.");
+ }
+ else {
+ // find link in page
+ String pageName = pageContentRenamed.substring(link +
(hostURL+"/wiki/").length(), pageContentRenamed.indexOf("\"",
link + (hostURL+"/wiki/").length()));
+ log.info("PAGENAME: "+pageName);
+
+
+ // check if the link is the one renamed in dictionary
+ assertEquals(pageName, newPage2Name);
+
+ }
+ }
+
+ public void testTranslating () throws WikiException {
+ WikiContext wikiContext = new WikiContext(plainUser,
wikiEngine.getWikiType("edit"), testWikiSession);
+
+ // create first uniqueLink
+ String uniqueLink = getUniqueName(LINK1);
+
+ // create another uniqueLink, we'll make translation to
+ String uniqueLinkTo = getUniqueName(LINK2);
+
+ // create page with first link
+ String testPage = createTestPage(plainUser, PAGE_W_LINK_PREF + uniqueLink +
PAGE_W_LINK_SUFF);
+
+ // add renaming
+ addRenaming(uniqueLink, uniqueLinkTo);
+
+ // sourcePage - will have link to first uniqueLink
+ WikiPage sourcePage = wikiEngine.getByName(testPage, null, langCode);
+
+ //page after translation - will have link to second uniqueLink
+ WikiPage page = wikiEngine.getByName(testPage, wikiContext, langCode);
+
+ // source page should have link to 1st uniqueLink
+ assertTrue(sourcePage.getContent().indexOf(uniqueLink) != -1);
+
+ // translated page should have link to 2nd uniqueLink
+ assertTrue(page.getContent().indexOf(uniqueLinkTo) != -1);
+
+ // page content should differ
+ assertFalse(page.getContent().equals(sourcePage.getContent()));
+
+ // retranslate uids
+ ReTranslateUids reTranslateUids = new ReTranslateUids(wikiEngine);
+
+ // get retranslated content
+ String reTranslated = reTranslateUids.getNewContent(page.getContent(), langCode);
+
+ // retranslated should be the same as sourcePage
+ assertEquals(reTranslated, sourcePage.getContent());
+ }
+}
Added:
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/FindPagesTest.java
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/FindPagesTest.java
(rev 0)
+++
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/FindPagesTest.java 2009-03-03
18:54:59 UTC (rev 249)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wiki.test;
+
+import java.util.Map;
+
+import org.jboss.wiki.exceptions.WikiException;
+
+public class FindPagesTest extends WikiTest {
+
+ private final static String CONTENT_MOD = "1234567890";
+
+ public void testFinding() throws WikiException {
+ String page1 = createTestPage(plainUser, PAGE_CONTENT);
+
+ String page2 = createTestPage(plainUser, PAGE_CONTENT + CONTENT_MOD);
+
+ String page3 = createTestPage(plainUser, CONTENT_MOD + PAGE_CONTENT + CONTENT_MOD);
+
+ // first search - just page content - all pages should be returned
+ Map<String, Integer> searchResult = wikiEngine.findPages(PAGE_CONTENT,
langCode);
+
+ // look if pages are in results
+ assertTrue(searchResult.keySet().contains(page1));
+ assertTrue(searchResult.keySet().contains(page2));
+ assertTrue(searchResult.keySet().contains(page3));
+
+ // only content
+ Map<String, Integer> searchResult2 = wikiEngine.findPages(CONTENT_MOD,
langCode);
+
+ // first page shouldn't be in results
+ assertFalse(searchResult2.keySet().contains(page1));
+
+ // 2 and 3 pages should be available
+ assertTrue(searchResult2.keySet().contains(page2));
+ assertTrue(searchResult2.keySet().contains(page3));
+
+ // page 3 should have bigger result
+
+ assertTrue(searchResult2.get(page3).compareTo(searchResult2.get(page2)) > 0);
+
+ // page2 name
+ Map<String, Integer> searchResult3 = wikiEngine.findPages(page2, langCode);
+
+ //this should return only page2
+ assertFalse(searchResult3.keySet().contains(page1));
+ assertTrue(searchResult3.keySet().contains(page2));
+ assertFalse(searchResult3.keySet().contains(page3));
+ }
+
+}
Added:
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/GetSavePageTest.java
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/GetSavePageTest.java
(rev 0)
+++
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/GetSavePageTest.java 2009-03-03
18:54:59 UTC (rev 249)
@@ -0,0 +1,149 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wiki.test;
+
+import java.util.Date;
+import java.util.Set;
+import java.util.Vector;
+
+import org.jboss.wiki.WikiContext;
+import org.jboss.wiki.WikiPage;
+import org.jboss.wiki.exceptions.WikiException;
+
+public class GetSavePageTest extends WikiTest {
+
+ private final static String PAGE_CONTENT = "This is simple conten link Hello
!";
+
+ private final static String PAGE_CONTENT_2 = "This is another content";
+
+ private final static String PAGE_VER_NAME = "TestVersionsPage";
+
+ private final static int NUM_OF_SESSIDS = 100;
+
+ public void testSaveGetPage() throws WikiException {
+ WikiContext wikiContext = new WikiContext(plainUser, wikiEngine
+ .getWikiType("html"), testWikiSession);
+
+ String testPageName = createTestPage(plainUser, PAGE_CONTENT);
+
+ assertTrue(wikiEngine.pageExists(testPageName, langCode));
+
+ WikiPage wikiPage2 = wikiEngine.getByName(testPageName, wikiContext,
+ langCode);
+
+ String pageContent = wikiPage2.getPageContent();
+
+ assertTrue(pageContent.indexOf(PAGE_CONTENT) != -1);
+
+ }
+
+ public void testGetAllPages() throws WikiException {
+ Set<String> pageNames = wikiEngine.getAllPageNames(langCode);
+
+ for (String pageName : pageNames) {
+ assertTrue(wikiEngine.pageExists(pageName, langCode));
+ }
+
+ String newPage = createTestPage(plainUser, PAGE_CONTENT);
+
+ Set<String> newPageNames = wikiEngine.getAllPageNames(langCode);
+
+ pageNames.add(newPage);
+
+ // check if the previous set is was just set after adding a page - this page
+ assertEquals(pageNames, newPageNames);
+ }
+
+ public void testLocking() throws WikiException {
+ WikiPage wikiPage = wikiEngine.getByName(createTestPage(plainUser,
+ "some page content"), null, langCode);
+
+ Vector<Integer> sessIds = new Vector<Integer>();
+
+ // genrate sess ids and lock pages
+ for (int i = 0; i < NUM_OF_SESSIDS; i++) {
+ sessIds.add(wikiEngine.getEditSessionId());
+
+ // check if lock gives a Date
+ if (i > 0) {
+ assertTrue(wikiPage.lock(plainUser, sessIds.get(i)) != null);
+ } else {
+ assertTrue(wikiPage.lock(plainUser, sessIds.get(i)) == null);
+ }
+ }
+
+ // try saving page with wrong sessionId
+ wikiPage.save(plainUser, NUM_OF_SESSIDS * 2, langCode, testWikiSession);
+
+ // check what wikiEngine thinks
+ assertTrue(wikiEngine.arePagesEdited());
+
+ // unlock
+ for (int i = 0; i < NUM_OF_SESSIDS; i++) {
+ wikiPage.unlock(plainUser, sessIds.get(i));
+ }
+
+ // check what wikiengine thinks
+ assertFalse(wikiEngine.arePagesEdited());
+ }
+
+ public void testVersions() throws WikiException {
+ String testPageName = getUniqueName(PAGE_VER_NAME);
+
+ // create page at version 1
+ WikiPage testPage = new WikiPage(testPageName, plainUser, PAGE_CONTENT,
+ 1, 1, new Date(), wikiEngine, true, true, null, null,
+ PAGE_CONTENT.length(), langCode);
+
+ // save page
+ wikiEngine.savePage(plainUser, testPage, langCode, testWikiSession);
+
+ // add testpage to to-delete list
+ pagesToDelete.add(testPageName);
+
+ // check if it exists
+ assertTrue(wikiEngine.pageExists(testPageName, langCode));
+
+ // get the page again
+ testPage = wikiEngine.getByName(testPageName, null, langCode);
+
+ // save next version
+ testPage.setContent(PAGE_CONTENT_2);
+ testPage.setLastVersion(testPage.getLastVersion() + 1);
+
+ wikiEngine.savePage(plainUser, testPage, langCode, testWikiSession);
+
+ // get page again at current version
+ testPage = wikiEngine.getByName(testPageName, null, langCode);
+
+ // check content and version
+ assertEquals(testPage.getContent(), PAGE_CONTENT_2);
+ assertEquals(testPage.getVersion(), 2);
+
+ // and at version 1
+ WikiPage prevVersionPage = wikiEngine.getByName(testPageName, null, 1, langCode);
+
+ // check content and version
+ assertEquals(prevVersionPage.getContent(), PAGE_CONTENT);
+ assertEquals(prevVersionPage.getVersion(), 1);
+ }
+}
Added: contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/PageModsTest.java
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/PageModsTest.java
(rev 0)
+++
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/PageModsTest.java 2009-03-03
18:54:59 UTC (rev 249)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wiki.test;
+
+import org.jboss.wiki.MediaDataSource;
+import org.jboss.wiki.WikiContext;
+import org.jboss.wiki.WikiPage;
+import org.jboss.wiki.exceptions.EditingNotAllowedException;
+import org.jboss.wiki.exceptions.WikiException;
+
+public class PageModsTest extends WikiTest {
+
+ private final static String PAGE_CONTENT = "This is a simple page content.";
+
+ public void testGlobalMods() throws WikiException {
+ String testPage = createTestPage(plainUser, PAGE_CONTENT);
+
+ WikiPage page = wikiEngine.getByName(testPage, null, langCode);
+
+ // no mods - version is 1
+ assertEquals(page.getLastVersion(), 1);
+
+ // set page not editable
+ page.setEditable(false);
+
+ assertEquals(wikiEngine.getPageMod(testPage, langCode),
+ MediaDataSource.VIEWABLE);
+
+ // try to save page - it should throw an error
+ page.setContent(PAGE_CONTENT + PAGE_CONTENT);
+ page.setLastVersion(page.getLastVersion() + 1);
+
+ try {
+ wikiEngine.savePage(plainUser, page, langCode, testWikiSession);
+ fail("Saving should throw an exception - page isn't editable");
+ } catch (EditingNotAllowedException e) {
+ // it's ok - page isn't editable
+ }
+
+ // set page not viewable
+ page.setViewable(false);
+
+ // try to get the page
+ page = wikiEngine.getByName(testPage, new WikiContext(notLogedIn,
+ wikiEngine.getWikiType("html"), testWikiSession), langCode);
+
+ // if page wasn't viewable - it's version will be 0
+ assertEquals(page.getVersion(), 0);
+
+ // try the same with getMods - if page is not viewable and not editable - mod = 0
+ assertEquals(wikiEngine.getPageMod(testPage, langCode), 0);
+
+ // check if admin has access
+ page = wikiEngine.getByName(testPage, new WikiContext(adminUser,
+ wikiEngine.getWikiType("html"), testWikiSession), langCode);
+
+ assertEquals(page.getVersion(), 1);
+
+ }
+
+ public void testRolesSet() throws WikiException {
+ String testPage = createTestPage(plainUser, PAGE_CONTENT);
+
+ WikiPage page = wikiEngine.getByName(testPage, null, langCode);
+
+ page.setEditRoles(roles);
+ wikiEngine.saveRolesSet(page, roles, MediaDataSource.EDITABLE, langCode);
+
+ page.setViewRoles(roles);
+ wikiEngine.saveRolesSet(page, roles, MediaDataSource.VIEWABLE, langCode);
+
+ // reload the page from DS
+ wikiEngine.refreshPage(testPage, langCode);
+
+ // try to save page - it should throw an error
+ page.setContent(PAGE_CONTENT + PAGE_CONTENT);
+ page.setLastVersion(page.getLastVersion() + 1);
+
+ try {
+ wikiEngine.savePage(plainUser, page, langCode, testWikiSession);
+ fail("Saving should throw an exception - page isn't editable");
+ } catch (EditingNotAllowedException e) {
+ // it's ok - page isn't editable
+ }
+
+ // try to get the page with not allowed user
+ page = wikiEngine.getByName(testPage, new WikiContext(plainUser,
+ wikiEngine.getWikiType("html"), testWikiSession), langCode);
+
+ // if page wasn't viewable - it's version will be 0
+ assertEquals(page.getVersion(), 0);
+
+ // try to get the page with allowed user
+ page = wikiEngine.getByName(testPage, new WikiContext(plainUserRoles,
+ wikiEngine.getWikiType("html"), testWikiSession), langCode);
+
+ // if page is viewable - it's version will be 1
+ assertEquals(page.getVersion(), 1);
+
+ // look if page is editable
+ assertTrue(page.isEditable(plainUserRoles));
+ assertFalse(page.isEditable(plainUser));
+
+ // check if admin has access
+ page = wikiEngine.getByName(testPage, new WikiContext(adminUser,
+ wikiEngine.getWikiType("html"), testWikiSession), langCode);
+
+ assertEquals(page.getVersion(), 1);
+
+ }
+
+}
Added: contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/PropsTest.java
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/PropsTest.java
(rev 0)
+++
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/PropsTest.java 2009-03-03
18:54:59 UTC (rev 249)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wiki.test;
+
+import org.jboss.wiki.WikiPage;
+import org.jboss.wiki.exceptions.WikiException;
+
+public class PropsTest extends WikiTest {
+
+ private final static String PROP1 = "property1";
+
+ private final static String KEY1 = "bim bom";
+
+ private final static String PROP2 = "pRoperty2";
+
+ private final static String KEY2 = "bele bele BYM";
+
+ private final static String PROP3 = "WielkaPropa";
+
+ private final static String KEY3 = "I don't like Yor";
+
+ public void testProperties() throws WikiException {
+ String testPage = createTestPage(plainUser, PAGE_CONTENT);
+
+ WikiPage page = wikiEngine.getByName(testPage, null, langCode);
+
+ // set some properties
+ page.setMetaDataProperty(PROP1, KEY1);
+ page.setMetaDataProperty(PROP2, KEY2);
+ page.setMetaDataProperty(PROP3, KEY3);
+
+ // refresh page
+ wikiEngine.refreshPage(testPage, langCode);
+
+ // reload page
+ page = wikiEngine.getByName(testPage, null, langCode);
+
+ // check properties
+ assertEquals(page.getMetaDataProperty(PROP1), KEY1);
+ assertEquals(page.getMetaDataProperty(PROP2), KEY2);
+ assertEquals(page.getMetaDataProperty(PROP3), KEY3);
+
+ // remove property
+ page.removeMetaDataProperty(PROP2);
+
+ // refresh page
+ wikiEngine.refreshPage(testPage, langCode);
+
+ // reload page
+ page = wikiEngine.getByName(testPage, null, langCode);
+
+ // it should be null now
+ assertNull(page.getMetaDataProperty(PROP2));
+ }
+}
Added: contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/SubPagesTest.java
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/SubPagesTest.java
(rev 0)
+++
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/SubPagesTest.java 2009-03-03
18:54:59 UTC (rev 249)
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wiki.test;
+
+import java.util.Date;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.wiki.WikiPage;
+import org.jboss.wiki.exceptions.WikiException;
+
+public class SubPagesTest extends WikiTest {
+
+ private static final String SUB_PAGE_1 = "SubPage1";
+
+ private static final String SUB_PAGE_2 = "SubPage2";
+
+ private static final String PAGE_CONTENT_2 = "Sub page content 1";
+
+ private static final String PAGE_CONTENT_3 = "Sub page content 2";
+
+ private static final String SUB_PAGE_PREFIX = "TestPageSubpages";
+
+ public void testSubpagesList() throws WikiException {
+ String page = createTestPage(plainUser, PAGE_CONTENT);
+
+ // create first subpage
+ WikiPage subPage1 = new WikiPage(page + "/" + SUB_PAGE_1, plainUser,
+ PAGE_CONTENT_2, 1, 1, new Date(), wikiEngine, true, true, null,
+ null, PAGE_CONTENT_2.length(), langCode);
+
+ wikiEngine.savePage(plainUser, subPage1, langCode, testWikiSession);
+
+ //add to "to-delete" list
+ pagesToDelete.add(page+"/"+SUB_PAGE_1);
+
+ // create second subpage
+ WikiPage subPage2 = new WikiPage(page + "/" + SUB_PAGE_2, plainUser,
+ PAGE_CONTENT_3, 1, 1, new Date(), wikiEngine, true, true, null,
+ null, PAGE_CONTENT_3.length(), langCode);
+
+ wikiEngine.savePage(plainUser, subPage2, langCode, testWikiSession);
+
+ //add to "to-delete" list
+ pagesToDelete.add(page+"/"+SUB_PAGE_2);
+
+ Set<String> subPagesList = wikiEngine.getPagesFor(page, langCode);
+
+ // construct new set with new subpages' names
+ Set<String> mySet = new TreeSet<String>();
+ mySet.add(page+"/"+SUB_PAGE_1); mySet.add(page+"/"+SUB_PAGE_2);
+
+ // check if both sets are the same
+ assertEquals(subPagesList, mySet);
+ }
+
+ public void testSubpagesDelete() throws WikiException {
+ Set<String> createdPages = new TreeSet<String>();
+
+ String page = getUniqueName(SUB_PAGE_PREFIX);
+
+ // create first page
+ WikiPage rootPage = new WikiPage(page, plainUser,
+ PAGE_CONTENT_2, 1, 1, new Date(), wikiEngine, true, true, null,
+ null, PAGE_CONTENT_2.length(), langCode);
+
+ wikiEngine.savePage(plainUser, rootPage, langCode, testWikiSession);
+ createdPages.add(page);
+
+ // create first subpage
+ WikiPage subPage1 = new WikiPage(page + "/" + SUB_PAGE_1, plainUser,
+ PAGE_CONTENT_2, 1, 1, new Date(), wikiEngine, true, true, null,
+ null, PAGE_CONTENT_2.length(), langCode);
+
+ wikiEngine.savePage(plainUser, subPage1, langCode, testWikiSession);
+ createdPages.add(page + "/" + SUB_PAGE_1);
+
+ // create second subpage
+ WikiPage subPage2 = new WikiPage(page + "/" + SUB_PAGE_2, plainUser,
+ PAGE_CONTENT_2, 1, 1, new Date(), wikiEngine, true, true, null,
+ null, PAGE_CONTENT_2.length(), langCode);
+
+ wikiEngine.savePage(plainUser, subPage2, langCode, testWikiSession);
+ createdPages.add(page + "/" + SUB_PAGE_2);
+
+ // create first subsubpage
+ WikiPage subSubPage1 = new WikiPage(page + "/" + SUB_PAGE_1 + "/" +
SUB_PAGE_1, plainUser,
+ PAGE_CONTENT_2, 1, 1, new Date(), wikiEngine, true, true, null,
+ null, PAGE_CONTENT_2.length(), langCode);
+
+ wikiEngine.savePage(plainUser, subSubPage1, langCode, testWikiSession);
+ createdPages.add(page + "/" + SUB_PAGE_1 + "/" + SUB_PAGE_1);
+
+ // add a page that is more deep inside
+ String name = page + "/" + SUB_PAGE_1 + "/" + SUB_PAGE_1 +
"/" + SUB_PAGE_2 + "/" + SUB_PAGE_2 + "/" + SUB_PAGE_1;
+ WikiPage subSubmultiple = new WikiPage(name, plainUser,
+ PAGE_CONTENT_2, 1, 1, new Date(), wikiEngine, true, true, null,
+ null, PAGE_CONTENT_2.length(), langCode);
+
+ wikiEngine.savePage(plainUser, subSubmultiple, langCode, testWikiSession);
+ createdPages.add(name);
+
+
+ // all pages should be there
+ for (String s : createdPages) {
+ assertTrue(wikiEngine.pageExists(s, langCode));
+ }
+
+ wikiEngine.deletePage(page, true, langCode);
+
+ // after deleting - no pages :)
+ for (String s : createdPages) {
+ assertFalse(wikiEngine.pageExists(s, langCode));
+ }
+
+ }
+}
+
Added:
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/TestCredentials.java
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/TestCredentials.java
(rev 0)
+++
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/TestCredentials.java 2009-03-03
18:54:59 UTC (rev 249)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wiki.test;
+
+import java.util.Set;
+
+import org.jboss.wiki.Credentials;
+
+public class TestCredentials extends Credentials {
+ private boolean logedIn = false;
+ private boolean admin = false;
+ private Set<String> roles;
+
+ public TestCredentials(boolean logedIn, boolean admin) {
+ init(logedIn, admin);
+ }
+
+ public TestCredentials(boolean logedIn, boolean admin, Set<String> roles) {
+ init(logedIn, admin);
+ this.roles = roles;
+ }
+
+ private void init(boolean logedIn, boolean admin) {
+ this.admin = admin;
+ this.logedIn = logedIn;
+ }
+
+ @Override
+ public String getName() {
+ return (isLoggedIn()) ? ((isAdmin()) ? "admin" : "test-user") :
"Unknown";
+ }
+
+ @Override
+ public boolean isLoggedIn() {
+ return logedIn;
+ }
+
+ @Override
+ public boolean isAdmin() {
+ return admin;
+ }
+
+ @Override
+ public void setParam(Object param) {
+ // Do nothing
+
+ }
+
+ @Override
+ public boolean isUserInRole(String role) {
+ if (roles == null) {
+ return false;
+ }
+
+ return (roles.contains(role));
+ }
+
+ @Override
+ public Set<String> getAllRoles() {
+ return roles;
+ }
+
+ @Override
+ public String getEmail() {
+ return null;
+ }
+
+}
\ No newline at end of file
Added:
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/TestWikiSession.java
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/TestWikiSession.java
(rev 0)
+++
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/TestWikiSession.java 2009-03-03
18:54:59 UTC (rev 249)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wiki.test;
+
+import java.util.HashMap;
+
+import org.jboss.wiki.WikiSession;
+
+public class TestWikiSession implements WikiSession {
+
+ HashMap<String, Object> attributes;
+
+ public TestWikiSession() {
+ attributes = new HashMap<String, Object>();
+ }
+
+ public Object getAttribute(String attributeName) {
+ return attributes.get(attributeName);
+ }
+
+ public void setAttribute(String attributeName, Object attribute) {
+ attributes.put(attributeName, attribute);
+ }
+
+ public void removeAttribute(String attributeName) {
+ attributes.remove(attributeName);
+ }
+
+ public String getId() {
+ return toString();
+ }
+
+}
\ No newline at end of file
Added: contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/WikiTest.java
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/WikiTest.java
(rev 0)
+++
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/WikiTest.java 2009-03-03
18:54:59 UTC (rev 249)
@@ -0,0 +1,230 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wiki.test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.TreeSet;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+
+import org.jboss.wiki.Credentials;
+import org.jboss.wiki.WikiCommon;
+import org.jboss.wiki.WikiContext;
+import org.jboss.wiki.WikiEngine;
+import org.jboss.wiki.WikiPage;
+import org.jboss.wiki.WikiSession;
+import org.jboss.wiki.exceptions.PageRenamingException;
+import org.jboss.wiki.exceptions.WikiException;
+import org.jboss.wiki.exceptions.WikiManagementNotFoundException;
+import org.jboss.wiki.management.WikiServiceManagement;
+
+public class WikiTest extends TestCase {
+ protected WikiEngine wikiEngine;
+
+ protected WikiSession testWikiSession;
+
+ protected Credentials notLogedIn = new TestCredentials(false, false);
+
+ protected Credentials adminUser = new TestCredentials(true, true);
+
+ protected Credentials plainUser = new TestCredentials(true, false);
+
+ protected Credentials plainUserRoles;
+
+ protected Set<String> pagesToDelete;
+
+ protected Set<File> filesToDelete;
+
+ protected Set<String> dictsToRemove;
+
+ protected final static String TEST_PAGE_BASE_NAME = "TestPage";
+
+ protected final static String hostURL = "http://localhost:8080";
+
+ protected final static String actionURL = "/Szimano";
+
+ protected final static String ROLE_NAME = "MyRole";
+
+ protected final static String PAGE_CONTENT = "This is a simple page
content.";
+
+ protected final static String FILE_PREFIX = "wikiTestFile";
+
+ protected final static String FILE_SUFFIX = ".wikiFile";
+
+ protected Set<String> roles;
+
+ protected String langCode;
+
+ protected Logger log;
+
+ @Override
+ protected void setUp() throws Exception {
+ log = Logger.getLogger(WikiTest.class);
+
+ WikiCommon wikiCommon = new WikiCommon();
+
+ try {
+ WikiServiceManagement wikiServiceMenagement = wikiCommon
+ .getWikiManagement();
+ wikiEngine = wikiServiceMenagement.getWikiEngine();
+ } catch (WikiManagementNotFoundException e1) {
+ log.info("Couldn't find WikiManagement - probably u're executing tests
outside AS");
+ wikiEngine = new WikiEngine();
+ }
+
+ testWikiSession = new TestWikiSession();
+ pagesToDelete = new HashSet<String>();
+ filesToDelete = new HashSet<File>();
+ dictsToRemove = new HashSet<String>();
+
+ // set session atributes
+ testWikiSession.setAttribute("credentials", plainUser);
+ testWikiSession.setAttribute("actionURL", actionURL);
+ testWikiSession.setAttribute("hostURL", hostURL);
+
+ langCode = wikiEngine.defaultLangugeCode;
+
+ roles = new TreeSet<String>();
+ roles.add(ROLE_NAME);
+
+ plainUserRoles = new TestCredentials(true, false, roles);
+ }
+
+ protected String createTestPage(Credentials user, String pageContent)
+ throws WikiException {
+ WikiContext wikiContext = new WikiContext(user, wikiEngine
+ .getWikiType("html"), testWikiSession);
+
+ if (wikiContext == null) {
+ fail("There is no html wikitype");
+ }
+
+ String testPageName = TEST_PAGE_BASE_NAME;
+ int i = 0;
+
+ while (wikiEngine.pageExists(testPageName, langCode)) {
+ testPageName = TEST_PAGE_BASE_NAME + (i++);
+ }
+
+ WikiPage wikiPage = new WikiPage(testPageName, user, pageContent, 1, 1,
+ new Date(), wikiEngine, true, true, null, null, pageContent
+ .length(), langCode);
+
+ wikiPage.save(plainUser, wikiEngine.getEditSessionId(), langCode, testWikiSession);
+
+ pagesToDelete.add(testPageName);
+
+ return testPageName;
+ }
+
+ protected String getUniqueName(String prefix) {
+
+ if (wikiEngine.pageExists(prefix, langCode)) {
+ int i = 0;
+
+ while (wikiEngine.pageExists(prefix + i, langCode)) {
+ i++;
+ }
+
+ return prefix + i;
+ }
+
+ return prefix;
+ }
+
+ private void deleteAllTestPages() {
+ boolean ret = true;
+
+ for (String pageName : pagesToDelete) {
+ if (!wikiEngine.deletePage(pageName, true, langCode)) {
+ ret = false;
+ log.error("Couldn't delete " + pageName);
+ }
+ }
+
+ if (!ret) {
+ // fail("Problems with deleting pages");
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ // at the end delete created testpages
+
+ deleteAllTestPages();
+
+ deleteAllTempFiles();
+
+ removeDicts();
+
+ super.tearDown();
+ }
+
+ private void removeDicts() throws PageRenamingException,
+ InterruptedException {
+ for (String dict : dictsToRemove) {
+ wikiEngine.removeDictForPage(dict, langCode);
+ System.out.println("Removed dict: "+dict);
+ }
+
+ // wait for all pages beeing deleted
+ while (!wikiEngine.getDictRemovesWaiting(langCode).isEmpty()) {
+ Thread.sleep(5 * 1000);
+ }
+ }
+
+ private void deleteAllTempFiles() {
+ for (File f : filesToDelete) {
+ f.delete();
+ }
+ }
+
+ protected File createTempFile(String content) throws IOException {
+ File attFile = File.createTempFile(FILE_PREFIX, FILE_SUFFIX);
+
+ FileOutputStream fos = new FileOutputStream(attFile);
+
+ for (int i = 0; i < content.length(); i++) {
+ fos.write(content.charAt(i));
+ }
+
+ fos.close();
+
+ return attFile;
+ }
+
+ protected void addRenaming(String uid, String newName)
+ throws PageRenamingException {
+ wikiEngine.rename(uid, newName, langCode);
+
+ System.out.println("Added renaming: "+uid+" -> "+newName);
+
+ dictsToRemove.add(newName);
+ }
+}
Added:
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/WikiTestException.java
===================================================================
---
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/WikiTestException.java
(rev 0)
+++
contrib/wikiPortlet/trunk/wiki-test/src/java/org/jboss/wiki/test/WikiTestException.java 2009-03-03
18:54:59 UTC (rev 249)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wiki.test;
+
+public class WikiTestException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public WikiTestException() {
+ super();
+ }
+
+ public WikiTestException(Throwable t) {
+ super(t);
+ }
+
+ public WikiTestException(String msg) {
+ super(msg);
+ }
+}
Added: contrib/wikiPortlet/trunk/wiki-test/src/web/WEB-INF/web.xml
===================================================================
--- contrib/wikiPortlet/trunk/wiki-test/src/web/WEB-INF/web.xml
(rev 0)
+++ contrib/wikiPortlet/trunk/wiki-test/src/web/WEB-INF/web.xml 2009-03-03 18:54:59 UTC
(rev 249)
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+
+ <servlet>
+ <servlet-name>JUnitEETestServlet</servlet-name>
+ <description>JUnitEE test runner</description>
+ <servlet-class>org.junitee.servlet.JUnitEEThreadedServlet</servlet-class>
+ <init-param>
+ <param-name>searchResources</param-name>
+ <param-value>wiki-test.jar</param-value>
+ </init-param>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>JUnitEETestServlet</servlet-name>
+ <url-pattern>/test/*</url-pattern>
+ </servlet-mapping>
+</web-app>