Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2006-08-22 19:48:53 -0400
committermkersten2006-08-22 19:48:53 -0400
commit04a0d2895fad2f7645c213b8f7aa7e1df8add1ff (patch)
tree340593919e2e0c64ec40e68942bed8e3ab9ec2a7 /org.eclipse.mylyn.trac.tests
parent6187d8c06648f429c8bba3ba7aeb2a5bb0997720 (diff)
downloadorg.eclipse.mylyn.tasks-04a0d2895fad2f7645c213b8f7aa7e1df8add1ff.tar.gz
org.eclipse.mylyn.tasks-04a0d2895fad2f7645c213b8f7aa7e1df8add1ff.tar.xz
org.eclipse.mylyn.tasks-04a0d2895fad2f7645c213b8f7aa7e1df8add1ff.zip
Progress on: 151900: Trac connector: implement attachment support
https://bugs.eclipse.org/bugs/show_bug.cgi?id=151900
Diffstat (limited to 'org.eclipse.mylyn.trac.tests')
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java1
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Constants.java3
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracAttachmentHandlerTest.java131
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java33
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java5
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/XmlRpcServer.java4
6 files changed, 175 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java
index 4865f583b..d373eab6e 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java
@@ -37,6 +37,7 @@ public class AllTracTests {
suite.addTestSuite(TracQueryTest.class);
suite.addTestSuite(TracRepositoryQueryTest.class);
suite.addTestSuite(TracClientManagerTest.class);
+ suite.addTestSuite(TracAttachmentHandlerTest.class);
// $JUnit-END$
return suite;
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Constants.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Constants.java
index 012e540da..9b3d23f02 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Constants.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/Constants.java
@@ -23,6 +23,7 @@ public class Constants {
public static final String TEST_TRAC_010_SSL_URL = "https://mylar.eclipse.org/trac010";
public static final String TEST_TRAC_010_DIGEST_AUTH_URL = "http://mylar.eclipse.org/trac010digest";
-
+
+ public static final String TEST_TRAC_INVALID_URL = "http://mylar.eclipse.org/doesnotexist";
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracAttachmentHandlerTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracAttachmentHandlerTest.java
new file mode 100644
index 000000000..54dd656f6
--- /dev/null
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracAttachmentHandlerTest.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2006 Mylar eclipse.org project 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
+ *
+ * Contributors:
+ * Mylar project committers - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylar.trac.tests;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.net.Proxy;
+
+import junit.framework.TestCase;
+
+import org.eclipse.mylar.core.core.tests.support.MylarTestUtils;
+import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.Credentials;
+import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.PrivilegeLevel;
+import org.eclipse.mylar.internal.trac.TracRepositoryConnector;
+import org.eclipse.mylar.internal.trac.TracTask;
+import org.eclipse.mylar.internal.trac.TracUiPlugin;
+import org.eclipse.mylar.internal.trac.core.ITracClient;
+import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
+import org.eclipse.mylar.tasks.core.IAttachmentHandler;
+import org.eclipse.mylar.tasks.core.TaskRepository;
+import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnector;
+import org.eclipse.mylar.tasks.ui.TaskRepositoryManager;
+import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylar.trac.tests.support.TestFixture;
+import org.eclipse.mylar.trac.tests.support.XmlRpcServer.TestData;
+
+/**
+ * @author Steffen Pingel
+ */
+public class TracAttachmentHandlerTest extends TestCase {
+
+ private TaskRepository repository;
+
+ private TaskRepositoryManager manager;
+
+ private TracRepositoryConnector connector;
+
+ private IAttachmentHandler attachmentHandler;
+
+ private Proxy proxySettings;
+
+ private TestData data;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ manager = TasksUiPlugin.getRepositoryManager();
+ manager.clearRepositories();
+
+ proxySettings = TasksUiPlugin.getDefault().getProxySettings();
+
+ data = TestFixture.init010();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ protected void init(String url, Version version) {
+ String kind = TracUiPlugin.REPOSITORY_KIND;
+ Credentials credentials = MylarTestUtils.readCredentials(PrivilegeLevel.USER);
+
+ repository = new TaskRepository(kind, url);
+ repository.setAuthenticationCredentials(credentials.username, credentials.password);
+ repository.setTimeZoneId(ITracClient.TIME_ZONE);
+ repository.setCharacterEncoding(ITracClient.CHARSET);
+ repository.setVersion(version.name());
+
+ manager.addRepository(repository);
+
+ AbstractRepositoryConnector abstractConnector = manager.getRepositoryConnector(kind);
+ connector = (TracRepositoryConnector) abstractConnector;
+ connector.setForceSyncExec(true);
+
+ attachmentHandler = connector.getAttachmentHandler();
+ }
+
+ public void testDownloadAttachment() throws Exception {
+ // TODO needs RepositoryTaskData
+ }
+
+ public void testUploadAttachment() throws Exception {
+ init(Constants.TEST_TRAC_010_URL, Version.XML_RPC);
+ TracTask task = (TracTask) connector.createTaskFromExistingKey(repository, data.attachmentTicketId + "");
+ File file = File.createTempFile("attachment", null);
+ OutputStream out = new FileOutputStream(file);
+ try {
+ out.write("Mylar".getBytes());
+ } finally {
+ out.close();
+ }
+ attachmentHandler.uploadAttachment(repository, task, "comment", "description", file, "", false, proxySettings);
+
+ ITracClient client = connector.getClientManager().getRepository(repository);
+ byte[] result = client.getAttachmentData(data.attachmentTicketId, file.getName());
+ assertEquals("Mylar", new String(result));
+ }
+
+ public void testCanUploadAttachment010() {
+ init(Constants.TEST_TRAC_010_URL, Version.XML_RPC);
+ TracTask task = (TracTask) connector.createTaskFromExistingKey(repository, data.attachmentTicketId + "");
+ assertTrue(attachmentHandler.canUploadAttachment(repository, task));
+ }
+
+ public void testCanUploadAttachment096() {
+ init(Constants.TEST_TRAC_010_URL, Version.TRAC_0_9);
+ TracTask task = (TracTask) connector.createTaskFromExistingKey(repository, data.attachmentTicketId + "");
+ assertFalse(attachmentHandler.canUploadAttachment(repository, task));
+ }
+
+ public void testCanDownloadAttachment() throws Exception {
+ init(Constants.TEST_TRAC_010_URL, Version.XML_RPC);
+ TracTask task = (TracTask) connector.createTaskFromExistingKey(repository, data.attachmentTicketId + "");
+ assertFalse(attachmentHandler.canDownloadAttachment(repository, task));
+
+ init(Constants.TEST_TRAC_010_URL, Version.TRAC_0_9);
+ task = (TracTask) connector.createTaskFromExistingKey(repository, data.attachmentTicketId + "");
+ assertFalse(attachmentHandler.canDownloadAttachment(repository, task));
+ }
+
+}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java
index 2ed1fcaea..e189218a6 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java
@@ -11,6 +11,7 @@
package org.eclipse.mylar.trac.tests;
+import java.io.File;
import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.Comparator;
@@ -18,10 +19,12 @@ import java.util.List;
import junit.framework.TestCase;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.mylar.context.core.ContextCorePlugin;
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils;
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.Credentials;
import org.eclipse.mylar.core.core.tests.support.MylarTestUtils.PrivilegeLevel;
@@ -235,7 +238,7 @@ public class TracRepositoryConnectorTest extends TestCase {
protected void updateAttributes() throws Exception {
connector.updateAttributes(repository, new NullProgressMonitor());
-
+
ITracClient server = connector.getClientManager().getRepository(repository);
TracVersion[] versions = server.getVersions();
assertEquals(2, versions.length);
@@ -248,4 +251,32 @@ public class TracRepositoryConnectorTest extends TestCase {
assertEquals("2.0", versions[1].getName());
}
+ public void testContext010() throws Exception {
+ init(Constants.TEST_TRAC_010_URL, Version.XML_RPC);
+ TracTask task = (TracTask) connector.createTaskFromExistingKey(repository, data.attachmentTicketId + "");
+
+ File sourceContextFile = ContextCorePlugin.getContextManager().getFileForContext(task.getHandleIdentifier());
+ sourceContextFile.createNewFile();
+ sourceContextFile.deleteOnExit();
+
+ assertTrue(connector.attachContext(repository, task, ""));
+ // TODO check if context was attached, requires RepositoryTaskData (bug
+ // #151899)
+ }
+
+ public void testContext096() throws Exception {
+ init(Constants.TEST_TRAC_096_URL, Version.TRAC_0_9);
+ TracTask task = (TracTask) connector.createTaskFromExistingKey(repository, data.attachmentTicketId + "");
+
+ File sourceContextFile = ContextCorePlugin.getContextManager().getFileForContext(task.getHandleIdentifier());
+ sourceContextFile.createNewFile();
+ sourceContextFile.deleteOnExit();
+
+ try {
+ connector.attachContext(repository, task, "");
+ fail("expected CoreException"); // operation should not be supported
+ } catch (CoreException e) {
+ }
+ }
+
} \ No newline at end of file
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java
index eb93310bc..d065e1720 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java
@@ -44,6 +44,8 @@ public class TestFixture {
server.ticket(2).itemCreated();
server.ticket(3).itemCreated();
server.ticket(4).itemCreated();
+ server.ticket(5).itemCreated();
+ server.ticket(6).itemCreated();
}
// private static void initializeRepository(XmlRpcServer server) throws Exception {
@@ -65,6 +67,9 @@ public class TestFixture {
// ticket = server.ticket().create("summary3", "description3");
// ticket.update("comment", "milestone", "milestone2");
// ticket = server.ticket().create("summary4", "description4");
+//
+// Ticket ticket = server.ticket().create("attachment test", "");
+// // create attachment named attachment.txt that contains the text "Mylar"
// }
public static XmlRpcServer.TestData init010() throws Exception {
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/XmlRpcServer.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/XmlRpcServer.java
index c6412d8a1..8ed9f516b 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/XmlRpcServer.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/XmlRpcServer.java
@@ -128,6 +128,10 @@ public class XmlRpcServer {
// all created tickets
public List<Ticket> tickets = new ArrayList<Ticket>();
+ public int attachmentTicketId = 5;
+
+ public int htmlEntitiesTicketId = 6;
+
/**
* Undo all changes.
*/

Back to the top