Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten2006-07-06 15:09:23 +0000
committermkersten2006-07-06 15:09:23 +0000
commitebd5c8eb0dba12d645ad90047c98fa63745713ca (patch)
treefafd7d51ade875fecf5343e3687156631682acbd /org.eclipse.mylyn.trac.tests
parentfc4fbb4b481b91eb60fb0a629bbf40fd329136b3 (diff)
downloadorg.eclipse.mylyn.tasks-ebd5c8eb0dba12d645ad90047c98fa63745713ca.tar.gz
org.eclipse.mylyn.tasks-ebd5c8eb0dba12d645ad90047c98fa63745713ca.tar.xz
org.eclipse.mylyn.tasks-ebd5c8eb0dba12d645ad90047c98fa63745713ca.zip
Progress on: 149385: Trac connector: implement externalizer and adding of existing tickets
https://bugs.eclipse.org/bugs/show_bug.cgi?id=149385
Diffstat (limited to 'org.eclipse.mylyn.trac.tests')
-rw-r--r--org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF1
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientSearchTest.java42
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java81
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcTest.java4
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java59
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/XmlRpcServer.java32
6 files changed, 172 insertions, 47 deletions
diff --git a/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF
index a0170f9ad..5a2a32b24 100644
--- a/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.trac.tests/META-INF/MANIFEST.MF
@@ -6,5 +6,6 @@ Bundle-Version: 0.0.0
Bundle-Localization: plugin
Require-Bundle: org.junit,
org.apache.xmlrpc,
+ org.eclipse.mylar.tasklist,
org.eclipse.mylar.trac
Export-Package: org.eclipse.mylar.trac.tests
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientSearchTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientSearchTest.java
index dbbefdae2..02d6d7a70 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientSearchTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AbstractTracClientSearchTest.java
@@ -23,7 +23,8 @@ import org.eclipse.mylar.internal.trac.model.TracSearch;
import org.eclipse.mylar.internal.trac.model.TracTicket;
import org.eclipse.mylar.internal.trac.model.TracTicket.Key;
import org.eclipse.mylar.trac.tests.support.AbstractTracRepositoryFactory;
-import org.eclipse.mylar.trac.tests.support.XmlRpcServer;
+import org.eclipse.mylar.trac.tests.support.TestFixture;
+import org.eclipse.mylar.trac.tests.support.XmlRpcServer.TestData;
import org.eclipse.mylar.trac.tests.support.XmlRpcServer.Ticket;
/**
@@ -34,13 +35,9 @@ import org.eclipse.mylar.trac.tests.support.XmlRpcServer.Ticket;
*/
public abstract class AbstractTracClientSearchTest extends TestCase {
- protected XmlRpcServer server;
-
protected AbstractTracRepositoryFactory factory;
- protected static List<Ticket> tickets;
-
- private static boolean setupRun = false;
+ protected List<Ticket> tickets;
public AbstractTracClientSearchTest(AbstractTracRepositoryFactory factory) {
this.factory = factory;
@@ -49,41 +46,16 @@ public abstract class AbstractTracClientSearchTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
- server = new XmlRpcServer(Constants.TEST_REPOSITORY1_URL, Constants.TEST_REPOSITORY1_ADMIN_USERNAME,
- Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
-
- if (!setupRun) {
- tickets = new ArrayList<Ticket>();
-
- server.ticket().deleteAll();
-
- server.ticketMilestone("m1").deleteAndCreate();
- Ticket ticket = add(server.ticket().create("summary1", "description1"));
- ticket.update("comment", "milestone", "m1");
-
- server.ticketMilestone("m2").deleteAndCreate();
- ticket = add(server.ticket().create("summary2", "description2"));
- ticket.update("comment", "milestone", "m2");
- ticket = add(server.ticket().create("summary3", "description3"));
- ticket.update("comment", "milestone", "m2");
-
- ticket = add(server.ticket().create("summary4", "description4"));
-
- setupRun = true;
- }
+ TestData data = TestFixture.initializeRepository1();
+ tickets = data.tickets;
factory.connectRepository1();
}
protected void tearDown() throws Exception {
super.tearDown();
-
- // server.getFixture().cleanup();
- }
-
- protected Ticket add(Ticket ticket) {
- tickets.add(ticket);
- return ticket;
+
+ // TestFixture.cleanupRepository1();
}
protected void assertTicketEquals(Ticket ticket, TracTicket tracTicket) throws Exception {
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 bc5f8b288..1c079adea 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,15 +11,68 @@
package org.eclipse.mylar.trac.tests;
-import org.eclipse.mylar.internal.trac.TracRepositoryConnector;
-
import junit.framework.TestCase;
+import org.eclipse.mylar.internal.trac.MylarTracPlugin;
+import org.eclipse.mylar.internal.trac.TracRepositoryConnector;
+import org.eclipse.mylar.internal.trac.TracTask;
+import org.eclipse.mylar.internal.trac.core.ITracClient;
+import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
+import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryConnector;
+import org.eclipse.mylar.provisional.tasklist.ITask;
+import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
+import org.eclipse.mylar.provisional.tasklist.TaskRepository;
+import org.eclipse.mylar.provisional.tasklist.TaskRepositoryManager;
+import org.eclipse.mylar.trac.tests.support.TestFixture;
+import org.eclipse.mylar.trac.tests.support.XmlRpcServer.TestData;
+
/**
* @author Steffen Pingel
*/
public class TracRepositoryConnectorTest extends TestCase {
+ private TestData data;
+
+ private TaskRepository repository;
+
+ private TaskRepositoryManager manager;
+
+ private TracRepositoryConnector connector;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ manager = MylarTaskListPlugin.getRepositoryManager();
+ manager.clearRepositories();
+
+ data = TestFixture.initializeRepository1();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ // TestFixture.cleanupRepository1();
+ }
+
+ protected void init(Version version) {
+ String kind = MylarTracPlugin.REPOSITORY_KIND;
+
+ repository = new TaskRepository(kind, Constants.TEST_REPOSITORY1_URL);
+ repository.setAuthenticationCredentials(Constants.TEST_REPOSITORY1_USERNAME,
+ Constants.TEST_REPOSITORY1_USERNAME);
+ repository.setTimeZoneId(ITracClient.TIME_ZONE);
+ repository.setCharacterEncoding(ITracClient.CHARSET);
+ repository.setVersion(version.name());
+
+ manager.addRepository(repository);
+
+ AbstractRepositoryConnector abstractConnector = manager.getRepositoryConnector(kind);
+ assertEquals(abstractConnector.getRepositoryType(), kind);
+
+ connector = (TracRepositoryConnector) abstractConnector;
+ connector.setForceSyncExec(true);
+ }
+
public void testGetRepositoryUrlFromTaskUrl() {
TracRepositoryConnector connector = new TracRepositoryConnector();
assertEquals("http://host/repo", connector.getRepositoryUrlFromTaskUrl("http://host/repo/ticket/1"));
@@ -28,4 +81,28 @@ public class TracRepositoryConnectorTest extends TestCase {
assertEquals(null, connector.getRepositoryUrlFromTaskUrl("http://host/repo/ticket-2342"));
}
+ public void testCreateTaskFromExistingKeyXmlRpc() {
+ init(Version.XML_RPC);
+ createTaskFromExistingKey();
+ }
+
+ public void testCreateTaskFromExistingKeyTrac09() {
+ init(Version.TRAC_0_9);
+ createTaskFromExistingKey();
+ }
+
+ protected void createTaskFromExistingKey() {
+ String id = data.tickets.get(0).getId() + "";
+ ITask task = connector.createTaskFromExistingKey(repository, id);
+ assertNotNull(task);
+ assertEquals(TracTask.class, task.getClass());
+ assertTrue(task.getDescription().contains("summary1"));
+ assertEquals(repository.getUrl() + ITracClient.TICKET_URL + id, task.getUrl());
+
+ task = connector.createTaskFromExistingKey(repository, "does not exist");
+ assertNull(task);
+
+ task = connector.createTaskFromExistingKey(repository, Integer.MAX_VALUE + "");
+ assertNull(task);
+ }
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcTest.java
index e6a5ff405..49b8b2d1d 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracXmlRpcTest.java
@@ -246,13 +246,13 @@ public class TracXmlRpcTest extends TestCase {
public void testGetTicketNonExistant() throws XmlRpcException, IOException {
try {
- call("ticket.delete", 1);
+ call("ticket.delete", Integer.MAX_VALUE);
} catch (Exception e) {
// ignore
}
try {
- Vector ticket = (Vector) call("ticket.get", 1);
+ Vector ticket = (Vector) call("ticket.get", Integer.MAX_VALUE);
fail("Expected XmlRpcException, got ticket instead: " + ticket);
} catch (XmlRpcException e) {
// ignore
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
new file mode 100644
index 000000000..8defafc79
--- /dev/null
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * 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.support;
+
+import org.eclipse.mylar.trac.tests.Constants;
+import org.eclipse.mylar.trac.tests.support.XmlRpcServer.Ticket;
+
+/**
+ * Initializes Trac repositories to a defined state. This is done once per test
+ * run, since cleaning and initializing the repository for each test method
+ * would take too long.
+ *
+ * @author Steffen Pingel
+ */
+public class TestFixture {
+
+ public static XmlRpcServer.TestData data1;
+
+ public static XmlRpcServer.TestData initializeRepository1() throws Exception {
+ if (data1 == null) {
+ XmlRpcServer server = new XmlRpcServer(Constants.TEST_REPOSITORY1_URL,
+ Constants.TEST_REPOSITORY1_ADMIN_USERNAME, Constants.TEST_REPOSITORY1_ADMIN_PASSWORD);
+
+ server.ticket().deleteAll();
+
+ server.ticketMilestone("m1").deleteAndCreate();
+ Ticket ticket = server.ticket().create("summary1", "description1");
+ ticket.update("comment", "milestone", "m1");
+
+ server.ticketMilestone("m2").deleteAndCreate();
+ ticket = server.ticket().create("summary2", "description2");
+ ticket.update("comment", "milestone", "m2");
+ ticket = server.ticket().create("summary3", "description3");
+ ticket.update("comment", "milestone", "m2");
+
+ ticket = server.ticket().create("summary4", "description4");
+
+ data1 = server.getData();
+ }
+ return data1;
+ }
+
+ public static void cleanupRepository1() throws Exception {
+ if (data1 != null) {
+ data1.cleanup();
+ data1 = null;
+ }
+ }
+
+}
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 e72f273d2..43cce095b 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
@@ -35,11 +35,11 @@ public class XmlRpcServer {
public abstract void delete() throws Exception;
protected void itemCreated() {
- fixture.items.add(this);
+ data.items.add(this);
}
protected void itemDeleted() {
- fixture.items.remove(this);
+ data.items.remove(this);
}
}
@@ -123,10 +123,14 @@ public class XmlRpcServer {
/**
* Records changes to the repository.
*/
- public class TestFixture {
+ public class TestData {
+ // all created items
List<AbstractTracItem> items = new ArrayList<AbstractTracItem>();
-
+
+ // all created tickets
+ public List<Ticket> tickets = new ArrayList<Ticket>();
+
/**
* Undo all changes.
*/
@@ -187,6 +191,18 @@ public class XmlRpcServer {
return id;
}
+ @Override
+ protected void itemCreated() {
+ super.itemCreated();
+ data.tickets.add(this);
+ }
+
+ @Override
+ protected void itemDeleted() {
+ super.itemDeleted();
+ data.tickets.remove(this);
+ }
+
public Ticket update(String comment, String key, String value) throws Exception {
Hashtable<String, Object> attrs = new Hashtable<String, Object>();
attrs.put(key, value);
@@ -258,7 +274,7 @@ public class XmlRpcServer {
private XmlRpcClient client;
- private TestFixture fixture;
+ private TestData data;
private String password;
@@ -273,7 +289,7 @@ public class XmlRpcServer {
this.username = username;
this.password = password;
- this.fixture = new TestFixture();
+ this.data = new TestData();
this.repository = new TracXmlRpcClient(new URL(url), Version.XML_RPC, username, password);
this.client = repository.getClient();
@@ -292,8 +308,8 @@ public class XmlRpcServer {
return result;
}
- public TestFixture getFixture() {
- return fixture;
+ public TestData getData() {
+ return data;
}
public String getPassword() {

Back to the top