Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracWikiClient.java211
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/InvalidWikiPageException.java35
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java172
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPage.java50
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPageInfo.java77
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientTest.java247
6 files changed, 786 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracWikiClient.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracWikiClient.java
index a1e947404..24add52fe 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracWikiClient.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/ITracWikiClient.java
@@ -8,7 +8,17 @@
package org.eclipse.mylyn.internal.trac.core;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.mylyn.internal.trac.core.model.TracWikiPage;
+import org.eclipse.mylyn.internal.trac.core.model.TracWikiPageInfo;
+
/**
+ * Interface for the WikiRPC API provided by the Trac XML-RPC Plugin
+ *
* @author Xiaoyang Guan
*
*/
@@ -25,4 +35,205 @@ public interface ITracWikiClient {
*/
public String wikiToHtml(String sourceText) throws TracException;
+ /**
+ * Validates the Trac XML-RPC WikiRPC API version of the repository
+ *
+ * @throws TracException
+ */
+ public void validateWikiRPCAPI() throws TracException;
+
+ /**
+ * Gets the list of the names of all pages from the repository
+ *
+ * @return The array of the names of all Wiki pages
+ * @throws TracException
+ */
+ public String[] getAllWikiPageNames() throws TracException;
+
+ /**
+ * Gets the latest version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @return the Wiki page at the latest version
+ * @throws TracException
+ */
+ public TracWikiPage getWikiPage(String pageName) throws TracException;
+
+ /**
+ * Gets a specific version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @param version
+ * the version of the Wiki page
+ * @return the Wiki page at the specified version
+ * @throws TracException
+ */
+ public TracWikiPage getWikiPage(String pageName, int version) throws TracException;
+
+ /**
+ * Gets the information about the latest version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @return The information about the page at the latest version
+ * @throws TracException
+ */
+ public TracWikiPageInfo getWikiPageInfo(String pageName) throws TracException;
+
+ /**
+ * Gets the information about the specified version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @param version
+ * the version of the Wiki page
+ * @return The information about the page at the specified version
+ * @throws TracException
+ */
+ public TracWikiPageInfo getWikiPageInfo(String pageName, int version) throws TracException;
+
+ /**
+ * Gets the information about all versions of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @return The list of the information about all versions of the page
+ * @throws TracException
+ */
+ public List<TracWikiPageInfo> getWikiPageInfoAllVersions(String pageName) throws TracException;
+
+ /**
+ * Gets the raw Wiki text of the latest version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @return the raw Wiki text of the page, latest version
+ * @throws TracException
+ */
+ public String getWikiPageContent(String pageName) throws TracException;
+
+ /**
+ * Gets the raw Wiki text of the specified version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @param version
+ * the version of the Wiki page
+ * @return the raw Wiki text of the page, specified version
+ * @throws TracException
+ */
+ public String getWikiPageContent(String pageName, int version) throws TracException;
+
+ /**
+ * Gets the rendered HTML of the latest version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @return the rendered HTML of the page, latest version
+ * @throws TracException
+ */
+ public String getWikiPageHTML(String pageName) throws TracException;
+
+ /**
+ * Gets the rendered HTML of the specified version of a Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @param version
+ * the version of the Wiki page
+ * @return the rendered HTML of the page, specified version
+ * @throws TracException
+ */
+ public String getWikiPageHTML(String pageName, int version) throws TracException;
+
+ /**
+ * Gets the list of information about all pages that have been modified since a given date from the repository
+ *
+ * @param since
+ * the date from which the changes to the Wiki pages should be retrieved
+ * @return list of information about the modified pages
+ * @throws TracException
+ */
+ public List<TracWikiPageInfo> getRecentWikiChanges(Date since) throws TracException;
+
+ /**
+ * Writes the content of a Wiki page to the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @param content
+ * the content of the page to be written
+ * @param attributes
+ * a Map used to set any Wiki-specific things, which the server can freely ignore or incorporate.
+ * Standard names are:
+ * <ul>
+ * <li> comment (String): A comment for the page.
+ * <li> minoredit (Boolean): This was a minor edit only.
+ * </ul>
+ * @return <code>true</code> if successful
+ * @throws TracException
+ */
+ public boolean putWikipage(String pageName, String content, Map<String, Object> attributes) throws TracException;
+
+ /**
+ * Gets the list of the names of attachments on a given Wiki page from the repository
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @return an array of the names of attachments on the given page. Returns an empty array if the page has no
+ * attachment or the page does not exist.
+ * @throws TracException
+ */
+ public String[] listWikiPageAttachments(String pageName) throws TracException;
+
+ /**
+ * Gets the content of an attachment on a Wiki page from the repository
+ *
+ * @param attachmentName
+ * the path of the attachment, in the format of "pagename/filename"
+ * @return An InputStream of the content of the attachment
+ * @throws TracException
+ */
+ public InputStream getWikiPageAttachment(String attachmentName) throws TracException;
+
+ /**
+ * (over)writes an attachment on a Wiki page to the repository. If the named attachment did not exist on the
+ * repository, it is created; if it already exists, its content is overwritten with the new content. This method is
+ * compatible with WikiRPC. ITracWikiClient.putWikiPageAttachmentEx has a more extensive set of (Trac-specific)
+ * features.
+ *
+ * @param attachmentName
+ * the path of the attachment, in the format of "pagename/filename"
+ * @param in
+ * An InputStream of the content of the attachment
+ * @return <code>true</code> if successful
+ * @throws TracException
+ */
+ public boolean putWikiPageAttachment(String attachmentName, InputStream in) throws TracException;
+
+ /**
+ * Attach a file to a Wiki page on the repository. This method is not compatible with WikiRPC.
+ *
+ * @see ITracWikiClient.putAttachment
+ *
+ * @param pageName
+ * the name of the Wiki page
+ * @param fileName
+ * the name of the file to be attached
+ * @param description
+ * the description of the attachment
+ * @param in
+ * An InputStream of the content of the attachment
+ * @param replace
+ * whether to overwrite an existing attachment with the same filename
+ * @return The (possibly transformed) filename of the attachment. If <code>replace</code> is <code>true</code>,
+ * the returned name is always the same as the argument <code>fileName</code>; if <code>replace</code>
+ * is <code>false</code> and an attachment with name <code>fileName</code> already exists, a number is
+ * appended to the file name (before suffix) and the generated filename of the attachment is returned.
+ * @throws TracException
+ */
+ public String putWikiPageAttachmentEx(String pageName, String fileName, String description, InputStream in,
+ boolean replace) throws TracException;
}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/InvalidWikiPageException.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/InvalidWikiPageException.java
new file mode 100644
index 000000000..9abb95605
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/InvalidWikiPageException.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Mylyn project committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.trac.core;
+
+/**
+ * Indicates an error while parsing the page info retrieved from a repository. If the requested page name or version
+ * doesn't exist on the repository, the XmlRpcPlugin returns an Integer of 0 without generating any error info.
+ *
+ * @author Xiaoyang Guan
+ */
+public class InvalidWikiPageException extends TracRemoteException {
+
+ private static final long serialVersionUID = 7505355497334178587L;
+
+ public InvalidWikiPageException() {
+ }
+
+ public InvalidWikiPageException(String message) {
+ super(message);
+ }
+
+ public InvalidWikiPageException(Throwable cause) {
+ super(cause);
+ }
+
+ public InvalidWikiPageException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java
index 442b655f1..f62134cb3 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracXmlRpcClient.java
@@ -44,6 +44,8 @@ import org.eclipse.mylyn.internal.trac.core.model.TracTicketResolution;
import org.eclipse.mylyn.internal.trac.core.model.TracTicketStatus;
import org.eclipse.mylyn.internal.trac.core.model.TracTicketType;
import org.eclipse.mylyn.internal.trac.core.model.TracVersion;
+import org.eclipse.mylyn.internal.trac.core.model.TracWikiPage;
+import org.eclipse.mylyn.internal.trac.core.model.TracWikiPageInfo;
import org.eclipse.mylyn.internal.trac.core.model.TracTicket.Key;
import org.eclipse.mylyn.internal.trac.core.util.TracHttpClientTransportFactory;
import org.eclipse.mylyn.internal.trac.core.util.TracUtils;
@@ -55,8 +57,9 @@ import org.eclipse.mylyn.web.core.WebClientUtil;
* Represents a Trac repository that is accessed through the Trac XmlRpcPlugin.
*
* @author Steffen Pingel
+ * @author Xiaoyang Guan
*/
-public class TracXmlRpcClient extends AbstractTracClient {
+public class TracXmlRpcClient extends AbstractTracClient implements ITracWikiClient {
public static final String XMLRPC_URL = "/xmlrpc";
@@ -68,6 +71,10 @@ public class TracXmlRpcClient extends AbstractTracClient {
private static final int NO_SUCH_METHOD_ERROR = 1;
+ private static final int LATEST_VERSION = -1;
+
+ public static final int REQUIRED_WIKI_RPC_VERSION = 2;
+
private XmlRpcClient xmlrpc;
private TracHttpClientTransportFactory factory;
@@ -652,8 +659,171 @@ public class TracXmlRpcClient extends AbstractTracClient {
return parseDate(result[2]);
}
+ public void validateWikiRPCAPI() throws TracException {
+ if (((Integer) call("wiki.getRPCVersionSupported")) < 2)
+ validate();
+ }
+
public String wikiToHtml(String sourceText) throws TracException {
return (String) call("wiki.wikiToHtml", sourceText);
}
+ public String[] getAllWikiPageNames() throws TracException {
+ Object[] result = (Object[]) call("wiki.getAllPages");
+ String[] wikiPageNames = new String[result.length];
+ for (int i = 0; i < wikiPageNames.length; i++) {
+ wikiPageNames[i] = (String) result[i];
+ }
+ return wikiPageNames;
+ }
+
+ public TracWikiPageInfo getWikiPageInfo(String pageName) throws TracException {
+ return getWikiPageInfo(pageName, LATEST_VERSION);
+ }
+
+ public TracWikiPageInfo getWikiPageInfo(String pageName, int version) throws TracException {
+ // Note: if an unexpected null value is passed to XmlRpcPlugin, XmlRpcClient will throw a TracRemoteException.
+ // So, this null-parameter checking may be omitted if resorting to XmlRpcClient is more appropriate.
+ if (pageName == null)
+ throw new IllegalArgumentException("Wiki page name cannot be null");
+
+ Object result = (version == LATEST_VERSION) ? call("wiki.getPageInfo", pageName) //
+ : call("wiki.getPageInfoVersion", pageName, version);
+ return parseWikiPageInfo(result);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<TracWikiPageInfo> getWikiPageInfoAllVersions(String pageName) throws TracException {
+ TracWikiPageInfo latestVersion = getWikiPageInfo(pageName);
+ Map<String, Object>[] calls = new Map[latestVersion.getVersion() - 1];
+ for (int i = 0; i < calls.length; i++) {
+ calls[i] = createMultiCall("wiki.getPageInfoVersion", pageName, i + 1);
+ }
+
+ Object[] result = multicall(calls);
+
+ List<TracWikiPageInfo> versions = new ArrayList<TracWikiPageInfo>(result.length + 1);
+ for (Object item : result) {
+ Object pageInfoResult = getMultiCallResult(item);
+ versions.add(parseWikiPageInfo(pageInfoResult));
+ }
+ versions.add(latestVersion);
+
+ return versions;
+ }
+
+ private TracWikiPageInfo parseWikiPageInfo(Object pageInfoResult) throws InvalidWikiPageException {
+ // Note: Trac XML-RPC Plugin returns 0 (as Integer) if pageName or version doesn't exist,
+ // and XmlRpcClient doesn't throw an Exception in this case
+ if (pageInfoResult instanceof Map<?, ?>) {
+ TracWikiPageInfo pageInfo = new TracWikiPageInfo();
+ Map<?, ?> infoMap = (Map<?, ?>) pageInfoResult;
+ pageInfo.setPageName((String) infoMap.get("name"));
+ pageInfo.setAuthor((String) infoMap.get("author"));
+ pageInfo.setLastModified(parseDate(infoMap.get("lastModified")));
+ pageInfo.setVersion((Integer) infoMap.get("version"));
+ return pageInfo;
+ } else {
+ throw new InvalidWikiPageException("Wiki page name or version does not exist");
+ }
+ }
+
+ public String getWikiPageContent(String pageName) throws TracException {
+ return getWikiPageContent(pageName, LATEST_VERSION);
+ }
+
+ public String getWikiPageContent(String pageName, int version) throws TracException {
+ // Note: if an unexpected null value is passed to XmlRpcPlugin, XmlRpcClient will throw a TracRemoteException.
+ // So, this null-parameter checking may be omitted if resorting to XmlRpcClient is more appropriate.
+ if (pageName == null)
+ throw new IllegalArgumentException("Wiki page name cannot be null");
+ if (version == LATEST_VERSION) {
+ // XmlRpcClient throws a TracRemoteException if pageName or version doesn't exist
+ return (String) call("wiki.getPage", pageName);
+ } else {
+ return (String) call("wiki.getPageVersion", pageName, version);
+ }
+ }
+
+ public String getWikiPageHTML(String pageName) throws TracException {
+ return getWikiPageHTML(pageName, LATEST_VERSION);
+ }
+
+ public String getWikiPageHTML(String pageName, int version) throws TracException {
+ if (pageName == null) {
+ throw new IllegalArgumentException("Wiki page name cannot be null");
+ }
+
+ if (version == LATEST_VERSION) {
+ // XmlRpcClient throws a TracRemoteException if pageName or version doesn't exist
+ return (String) call("wiki.getPageHTML", pageName);
+ } else {
+ return (String) call("wiki.getPageHTMLVersion", pageName, version);
+ }
+ }
+
+ public List<TracWikiPageInfo> getRecentWikiChanges(Date since) throws TracException {
+ if (since == null) {
+ throw new IllegalArgumentException("Date parameter cannot be null");
+ }
+
+ Object[] result = (Object[]) call("wiki.getRecentChanges", since);
+ List<TracWikiPageInfo> changes = new ArrayList<TracWikiPageInfo>(result.length);
+ for (Object item : result) {
+ changes.add(parseWikiPageInfo(item));
+ }
+ return changes;
+ }
+
+ public TracWikiPage getWikiPage(String pageName) throws TracException {
+ return getWikiPage(pageName, LATEST_VERSION);
+ }
+
+ public TracWikiPage getWikiPage(String pageName, int version) throws TracException {
+ TracWikiPage page = new TracWikiPage();
+ page.setPageInfo(getWikiPageInfo(pageName, version));
+ page.setContent(getWikiPageContent(pageName, version));
+ page.setPageHTML(getWikiPageHTML(pageName, version));
+ return page;
+ }
+
+ public boolean putWikipage(String pageName, String content, Map<String, Object> attributes) throws TracException {
+ Boolean result = (Boolean) call("wiki.putPage", pageName, content, attributes);
+ return result.booleanValue();
+ }
+
+ public String[] listWikiPageAttachments(String pageName) throws TracException {
+ Object[] result = (Object[]) call("wiki.listAttachments", pageName);
+ String[] attachments = new String[result.length];
+ for (int i = 0; i < attachments.length; i++) {
+ attachments[i] = (String) result[i];
+ }
+ return attachments;
+ }
+
+ public InputStream getWikiPageAttachment(String attachmentName) throws TracException {
+ byte[] data = (byte[]) call("wiki.getAttachment", attachmentName);
+ return new ByteArrayInputStream(data);
+ }
+
+ public boolean putWikiPageAttachment(String attachmentName, InputStream in) throws TracException {
+ byte[] data;
+ try {
+ data = readData(in, new NullProgressMonitor());
+ } catch (IOException e) {
+ throw new TracException(e);
+ }
+ return (Boolean) call("wiki.putAttachment", attachmentName, data);
+ }
+
+ public String putWikiPageAttachmentEx(String pageName, String fileName, String description, InputStream in,
+ boolean replace) throws TracException {
+ byte[] data;
+ try {
+ data = readData(in, new NullProgressMonitor());
+ } catch (IOException e) {
+ throw new TracException(e);
+ }
+ return (String) call("wiki.putAttachmentEx", pageName, fileName, description, data, replace);
+ }
} \ No newline at end of file
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPage.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPage.java
new file mode 100644
index 000000000..07d1baf49
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPage.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Mylyn project committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.trac.core.model;
+
+/**
+ * Represents a Trac Wiki page at a specific version.
+ *
+ * @author Xiaoyang Guan
+ */
+public class TracWikiPage {
+
+ private TracWikiPageInfo pageInfo;
+
+ private String content;
+
+ private String pageHTML;
+
+ public TracWikiPage() {
+ }
+
+ public TracWikiPageInfo getPageInfo() {
+ return pageInfo;
+ }
+
+ public void setPageInfo(TracWikiPageInfo pageInfo) {
+ this.pageInfo = pageInfo;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public String getPageHTML() {
+ return pageHTML;
+ }
+
+ public void setPageHTML(String pageHTML) {
+ this.pageHTML = pageHTML;
+ }
+}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPageInfo.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPageInfo.java
new file mode 100644
index 000000000..729e2996d
--- /dev/null
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/model/TracWikiPageInfo.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Mylyn project committers and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.trac.core.model;
+
+import java.util.Date;
+
+/**
+ * Information about a Trac Wiki page at a specific version
+ *
+ * @author Xiaoyang Guan
+ */
+public class TracWikiPageInfo {
+
+ private String pageName;
+
+ private String author;
+
+ private Date lastModified;
+
+ private int version;
+
+ private String comment;
+
+ public TracWikiPageInfo() {
+ }
+
+ public String getPageName() {
+ return pageName;
+ }
+
+ public void setPageName(String pageName) {
+ this.pageName = pageName;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public Date getLastModified() {
+ return lastModified;
+ }
+
+ public void setLastModified(Date lastModified) {
+ this.lastModified = lastModified;
+ }
+
+ public int getVersion() {
+ return version;
+ }
+
+ public void setVersion(int version) {
+ this.version = version;
+ }
+
+ public String getComment() {
+ return comment;
+ }
+
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+
+ public String toString() {
+ return pageName + ": version " + version + " by " + author + " last modified at " + lastModified;
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientTest.java
index 24bb2f749..75ac183be 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcClientTest.java
@@ -11,6 +11,7 @@ package org.eclipse.mylyn.trac.tests;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
+import java.util.List;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylyn.internal.trac.core.TracPermissionDeniedException;
@@ -18,6 +19,8 @@ import org.eclipse.mylyn.internal.trac.core.TracRemoteException;
import org.eclipse.mylyn.internal.trac.core.TracXmlRpcClient;
import org.eclipse.mylyn.internal.trac.core.ITracClient.Version;
import org.eclipse.mylyn.internal.trac.core.model.TracVersion;
+import org.eclipse.mylyn.internal.trac.core.model.TracWikiPage;
+import org.eclipse.mylyn.internal.trac.core.model.TracWikiPageInfo;
/**
* @author Steffen Pingel
@@ -80,16 +83,16 @@ public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest {
assertEquals(new Date(0), versions[1].getTime());
}
- public void testWikiToHtml010() throws Exception{
+ public void testWikiToHtml010() throws Exception {
connect010();
wikiToHtml(TracTestConstants.TEST_TRAC_010_URL);
}
-
- public void testWikiToHtml011() throws Exception{
+
+ public void testWikiToHtml011() throws Exception {
connect011();
wikiToHtml(TracTestConstants.TEST_TRAC_011_URL);
}
-
+
public void wikiToHtml(String tracUrl) throws Exception {
String html = ((TracXmlRpcClient) repository).wikiToHtml("");
assertEquals("", html);
@@ -102,9 +105,243 @@ public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest {
+ " * {{{monospace}}} or `monospace`\n" + " * ~~strike-through~~\n" + " * ^superscript^ \n"
+ " * ,,subscript,,\n" + "= Heading =\n" + "== Subheading ==\n";
- String expectedHtml = "<h1 id=\"WikiFormattingTesting\"><a class=\"missing wiki\" href=\"" + tracUrl + "/wiki/WikiFormattingTesting\" rel=\"nofollow\">WikiFormattingTesting?</a></h1>\n<ul><li><strong>bold</strong>, <strong>\'\'\' can be bold too</strong>, and <strong>! </strong>\n</li><li><i>italic</i>\n</li><li><strong><i>bold italic</i></strong>\n</li><li><span class=\"underline\">underline</span>\n</li><li><tt>monospace</tt> or <tt>monospace</tt>\n</li><li><del>strike-through</del>\n</li><li><sup>superscript</sup> \n</li><li><sub>subscript</sub>\n</li></ul><h1 id=\"Heading\">Heading</h1>\n<h2 id=\"Subheading\">Subheading</h2>\n";
+ String expectedHtml = "<h1 id=\"WikiFormattingTesting\"><a class=\"missing wiki\" href=\""
+ + tracUrl
+ + "/wiki/WikiFormattingTesting\" rel=\"nofollow\">WikiFormattingTesting?</a></h1>\n<ul><li><strong>bold</strong>, <strong>\'\'\' can be bold too</strong>, and <strong>! </strong>\n</li><li><i>italic</i>\n</li><li><strong><i>bold italic</i></strong>\n</li><li><span class=\"underline\">underline</span>\n</li><li><tt>monospace</tt> or <tt>monospace</tt>\n</li><li><del>strike-through</del>\n</li><li><sup>superscript</sup> \n</li><li><sub>subscript</sub>\n</li></ul><h1 id=\"Heading\">Heading</h1>\n<h2 id=\"Subheading\">Subheading</h2>\n";
html = ((TracXmlRpcClient) repository).wikiToHtml(source);
assertEquals(expectedHtml, html);
}
+
+ public void testValidateWikiAPI010() throws Exception {
+ connect010();
+ ((TracXmlRpcClient) repository).validateWikiRPCAPI();
+ }
+
+ public void testValidateWikiAPI011() throws Exception {
+ connect011();
+ ((TracXmlRpcClient) repository).validateWikiRPCAPI();
+ }
+
+ public void testGetAllWikiPageNames010() throws Exception {
+ connect010();
+ getAllWikiPageNames();
+ }
+
+ public void testGetAllWikiPageNames011() throws Exception {
+ connect011();
+ getAllWikiPageNames();
+ }
+
+ private void getAllWikiPageNames() throws Exception {
+ String[] names = ((TracXmlRpcClient) repository).getAllWikiPageNames();
+ List<String> all = Arrays.asList(names);
+ assertTrue(all.contains("Test"));
+ }
+
+ public void testGetWikiPage010() throws Exception {
+ connect010();
+ getWikiPage();
+ }
+
+ public void testGetWikiPage011() throws Exception {
+ connect011();
+ getWikiPage();
+ }
+
+ private void getWikiPage() throws Exception {
+ String pageName = "Test";
+ String author = "admin@mylar.eclipse.org";
+ int version = 1;
+
+ TracWikiPage page = ((TracXmlRpcClient) repository).getWikiPage(pageName);
+ assertEquals(pageName, page.getPageInfo().getPageName());
+ assertEquals(author, page.getPageInfo().getAuthor());
+ assertEquals(version, page.getPageInfo().getVersion());
+ // XXX: The Date returned from Wiki API seems to have a problem with the Time Zone
+ //String date = "Sat Nov 11 18:10:56 EST 2006";
+ //assertEquals(date, page.getPageVersion().getLastModified().toString());
+ assertTrue(page.getContent() != null);
+ assertTrue(page.getPageHTML().startsWith("<html>"));
+
+ pageName = "WikiStart";
+ author = "trac";
+ version = 1;
+
+ page = ((TracXmlRpcClient) repository).getWikiPage("WikiStart", 1);
+ assertEquals(pageName, page.getPageInfo().getPageName());
+ assertEquals(author, page.getPageInfo().getAuthor());
+ assertEquals(version, page.getPageInfo().getVersion());
+ assertTrue(page.getContent() != null);
+ assertTrue(page.getPageHTML().startsWith("<html>"));
+ }
+
+ public void testGetWikiPageInvalid010() throws Exception {
+ connect010();
+ getWikiPageInvalid();
+ }
+
+ public void testGetWikiPageInvalid011() throws Exception {
+ connect011();
+ getWikiPageInvalid();
+ }
+
+ private void getWikiPageInvalid() throws Exception {
+ // get info -- non-existing version
+ try {
+ ((TracXmlRpcClient) repository).getWikiPageInfo("Test", 10);
+ fail("Expected TracRemoteException");
+ } catch (TracRemoteException e) {
+ }
+
+ // get info -- non-existing page name
+ try {
+ ((TracXmlRpcClient) repository).getWikiPageInfo("NoSuchPage");
+ fail("Expected TracRemoteException");
+ } catch (TracRemoteException e) {
+ }
+
+ // get info -- null parameter
+ try {
+ ((TracXmlRpcClient) repository).getWikiPageInfo(null);
+ fail("Expected RuntimeException");
+ } catch (IllegalArgumentException e) {
+ }
+
+ // get content -- non-existing version
+ try {
+ ((TracXmlRpcClient) repository).getWikiPageContent("Test", 10);
+ fail("Expected TracRemoteException");
+ } catch (TracRemoteException e) {
+ }
+
+ // get content -- non-existing page name
+ try {
+ ((TracXmlRpcClient) repository).getWikiPageContent("NoSuchPage");
+ fail("Expected TracRemoteException");
+ } catch (TracRemoteException e) {
+ }
+
+ // get content -- null parameter
+ try {
+ ((TracXmlRpcClient) repository).getWikiPageContent(null);
+ fail("Expected RuntimeException");
+ } catch (IllegalArgumentException e) {
+ }
+
+ // get HTML -- non-existing version
+ try {
+ ((TracXmlRpcClient) repository).getWikiPageHTML("Test", 10);
+ fail("Expected TracRemoteException");
+ } catch (TracRemoteException e) {
+ }
+
+ // get HTML -- non-existing page name
+ try {
+ ((TracXmlRpcClient) repository).getWikiPageHTML("NoSuchPage");
+ fail("Expected TracRemoteException");
+ } catch (TracRemoteException e) {
+ }
+
+ // get HTML -- null parameter
+ try {
+ ((TracXmlRpcClient) repository).getWikiPageHTML(null);
+ fail("Expected RuntimeException");
+ } catch (IllegalArgumentException e) {
+ }
+
+ // get a page -- non-existing version
+ try {
+ ((TracXmlRpcClient) repository).getWikiPage("Test", 10);
+ fail("Expected TracRemoteException");
+ } catch (TracRemoteException e) {
+ }
+
+ // get a page -- non-existing page name
+ try {
+ ((TracXmlRpcClient) repository).getWikiPage("NoSuchPage");
+ fail("Expected TracRemoteException");
+ } catch (TracRemoteException e) {
+ }
+
+ // get a page -- null parameter
+ try {
+ ((TracXmlRpcClient) repository).getWikiPage(null);
+ fail("Expected RuntimeException");
+ } catch (IllegalArgumentException e) {
+ }
+
+ // get all versions of a page -- non-existing page name
+ try {
+ ((TracXmlRpcClient) repository).getWikiPageInfoAllVersions("NoSuchPage");
+ fail("Expected TracRemoteException");
+ } catch (TracRemoteException e) {
+ }
+
+ // get all versions of a page -- null parameter
+ try {
+ ((TracXmlRpcClient) repository).getWikiPageInfoAllVersions(null);
+ fail("Expected RuntimeException");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testGetWikiPageInfoAllVersions010() throws Exception {
+ connect010();
+ getWikiPageInfoAllVersions();
+ }
+
+ public void testGetWikiPageInfoAllVersions011() throws Exception {
+ connect011();
+ getWikiPageInfoAllVersions();
+ }
+
+ private void getWikiPageInfoAllVersions() throws Exception {
+ String pageName = "Test";
+
+ List<TracWikiPageInfo> versions = ((TracXmlRpcClient) repository).getWikiPageInfoAllVersions(pageName);
+ assertTrue(versions.size() >= 1);
+ int counter = 1;
+ for (TracWikiPageInfo version : versions) {
+ assertTrue(version.getPageName().equals(pageName));
+ assertTrue(version.getVersion() == counter++); // assuming versions are ordered increasingly
+ }
+ }
+
+ public void testGetRecentWikiChanges010() throws Exception {
+ connect010();
+ getRecentWikiChanges();
+ }
+
+ public void testGetRecentWikiChanges011() throws Exception {
+ connect011();
+ getRecentWikiChanges();
+ }
+
+ private void getRecentWikiChanges() throws Exception {
+ List<TracWikiPageInfo> changes = ((TracXmlRpcClient) repository).getRecentWikiChanges(new Date(0));
+ TracWikiPageInfo testPage = null;
+ for (TracWikiPageInfo item : changes) {
+ assertTrue(item.getPageName() != null);
+ if (item.getPageName().equals("Test")) {
+ testPage = item;
+ }
+ }
+ assertFalse(changes.contains(null));
+ assertTrue(changes.contains(testPage));
+ }
+
+ public void testPutWikiPage010() throws Exception {
+ connect010();
+ putWikiPage();
+ }
+
+ public void testPutWikiPage011() throws Exception {
+ connect011();
+ putWikiPage();
+ }
+
+ private void putWikiPage() throws Exception {
+ // TODO: testing wiki.putPage()
+ }
}

Back to the top