Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-04-15 13:57:55 +0000
committerSteffen Pingel2013-04-16 00:06:09 +0000
commita0fad711183c44b82edcb5df816856beaddf5079 (patch)
treeefab01ddbfb5a3e9a7a730ef6c73578b87c5f51e /org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn
parentdab45ebad385f4ee7320c58a7462995eafe6af35 (diff)
downloadorg.eclipse.mylyn.tasks-a0fad711183c44b82edcb5df816856beaddf5079.tar.gz
org.eclipse.mylyn.tasks-a0fad711183c44b82edcb5df816856beaddf5079.tar.xz
org.eclipse.mylyn.tasks-a0fad711183c44b82edcb5df816856beaddf5079.zip
400396: fix additional Trac fixture test failures
* Handle empty value when parsing tickets on 1.0 in web mode. * Ensure correct token is submitted for form based authentication. * Exclude tests that don't apply in specialized fixtures. Change-Id: Idc7ae6934a3a6a590fd867f995a69d537690bb28 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=400396
Diffstat (limited to 'org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn')
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientFactoryTest.java35
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientTest.java27
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcClientTest.java7
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracFixture.java6
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracHarness.java95
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracTestUtil.java12
6 files changed, 121 insertions, 61 deletions
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientFactoryTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientFactoryTest.java
index 49e567f1e..5be3afc8c 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientFactoryTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientFactoryTest.java
@@ -61,25 +61,42 @@ public class TracClientFactoryTest extends TestCase {
WebLocation location = new WebLocation(url, credentials.getUserName(), credentials.getPassword());
Version version = TracClientFactory.probeClient(location);
if (fixture.isXmlRpcEnabled()) {
+ // assertion is only meaningful for XML-RPC since web fixtures will also probe XML-RPC if available
assertEquals(Version.XML_RPC, version);
- } else {
- assertEquals(Version.TRAC_0_9, version);
}
+ }
- location = new WebLocation(url, "", "");
- version = TracClientFactory.probeClient(location);
- assertEquals(Version.TRAC_0_9, version);
+ public void testProbeClientNoCredentials() throws Exception {
+ String url = fixture.getRepositoryUrl();
+ WebLocation location = new WebLocation(url, "", "");
+ try {
+ Version version = TracClientFactory.probeClient(location);
+ if (fixture.requiresAuthentication()) {
+ fail("Expected TracLoginException");
+ }
+ assertEquals(Version.TRAC_0_9, version);
+ } catch (TracLoginException e) {
+ if (fixture.requiresAuthentication()) {
+ // the remainder of the
+ return;
+ }
+ throw e;
+ }
+ }
+ public void testProbeClientInvalidCredentials() throws Exception {
try {
- location = new WebLocation(url, "invaliduser", "password");
- version = TracClientFactory.probeClient(location);
+ WebLocation location = new WebLocation(fixture.getRepositoryUrl(), "invaliduser", "password");
+ Version version = TracClientFactory.probeClient(location);
fail("Expected TracLoginException, got " + version);
} catch (TracLoginException e) {
}
+ }
+ public void testProbeClientInvalidLocation() throws Exception {
try {
- location = new WebLocation(url + "/nonexistant", "", "");
- version = TracClientFactory.probeClient(location);
+ WebLocation location = new WebLocation(fixture.getRepositoryUrl() + "/nonexistant", "", "");
+ Version version = TracClientFactory.probeClient(location);
fail("Expected TracException, got " + version);
} catch (TracException e) {
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientTest.java
index db64b287e..a2ad3903c 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientTest.java
@@ -75,7 +75,7 @@ public class TracClientTest extends TestCase {
public void testGetTicket() throws Exception {
TracTicket expectedTicket = harness.createTicket("getTicket");
TracTicket ticket = client.getTicket(expectedTicket.getId(), null);
- TracTestUtil.assertTicketEquals(expectedTicket, ticket);
+ TracTestUtil.assertTicketEquals(client.getAccessMode(), expectedTicket, ticket);
}
public void testGetTicketInvalidId() throws Exception {
@@ -87,12 +87,13 @@ public class TracClientTest extends TestCase {
}
public void testGetTicketUmlaute() throws Exception {
- TracTicket ticket = harness.createTicket("test html entities: \u00E4\u00F6\u00FC");
+ TracTicket ticket = harness.newTicket("test html entities: \u00E4\u00F6\u00FC");
+ ticket.putBuiltinValue(Key.DESCRIPTION, "\u00C4\u00D6\u00DC\n\nmulti\nline\n\n'''bold'''\n");
+ ticket = harness.createTicket(ticket);
+
+ ticket = client.getTicket(ticket.getId(), null);
assertEquals("test html entities: \u00E4\u00F6\u00FC", ticket.getValue(Key.SUMMARY));
if (client.getAccessMode() == Version.XML_RPC) {
- ticket.putBuiltinValue(Key.DESCRIPTION, "\u00C4\u00D6\u00DC\n\nmulti\nline\n\n'''bold'''\n");
- client.updateTicket(ticket, "", null);
- ticket = client.getTicket(ticket.getId(), null);
assertEquals("\u00C4\u00D6\u00DC\n\nmulti\nline\n\n'''bold'''\n", ticket.getValue(Key.DESCRIPTION));
} else {
assertEquals(null, ticket.getValue(Key.DESCRIPTION));
@@ -176,7 +177,11 @@ public class TracClientTest extends TestCase {
}
public void testSearchMilestoneAmpersand() throws Exception {
- harness.createMilestone("mile&stone");
+ if (!harness.hasMilestone("mile&stone")) {
+ // ignore test
+ return;
+ }
+
TracTicket ticket = harness.createTicketWithMilestone("searchMilestoneAmpersand", "mile&stone");
TracSearch search = new TracSearch();
@@ -201,7 +206,7 @@ public class TracClientTest extends TestCase {
TracTicket ticket = harness.createTicket("statusClosed");
ticket.putBuiltinValue(Key.STATUS, "closed");
ticket.putBuiltinValue(Key.RESOLUTION, "fixed");
- client.updateTicket(ticket, "", null);
+ harness.udpateTicket(ticket);
ticket = client.getTicket(ticket.getId(), null);
assertEquals("closed", ticket.getValue(Key.STATUS));
@@ -209,6 +214,10 @@ public class TracClientTest extends TestCase {
}
public void testUpdateAttributesAnonymous() throws Exception {
+ if (fixture.requiresAuthentication()) {
+ return;
+ }
+
client = fixture.connect(fixture.getRepositoryUrl(), "", "");
assertNull(client.getMilestones());
try {
@@ -285,6 +294,10 @@ public class TracClientTest extends TestCase {
}
public void testValidateAnonymousLogin() throws Exception {
+ if (fixture.requiresAuthentication()) {
+ return;
+ }
+
client = fixture.connect(fixture.getRepositoryUrl(), "", "");
try {
client.validate(new NullProgressMonitor());
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcClientTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcClientTest.java
index 670d483f7..1b440880d 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcClientTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcClientTest.java
@@ -65,6 +65,9 @@ public class TracXmlRpcClientTest extends TestCase {
}
public void testValidateFailNoAuth() throws Exception {
+ if (harness.getFixture().requiresAuthentication()) {
+ return;
+ }
client = (TracXmlRpcClient) TracFixture.current().connect(client.getUrl(), "", "");
try {
client.validate(new NullProgressMonitor());
@@ -121,8 +124,8 @@ public class TracXmlRpcClientTest extends TestCase {
List<TracTicket> result = new ArrayList<TracTicket>();
client.search(search, result, null);
assertEquals(1, result.size());
- // work around missing value
- ticket.putBuiltinValue(Key.OWNER, "somebody");
+ // the value varies between Trac versions, e.g. "somebody", "< default >"
+ ticket.putBuiltinValue(Key.OWNER, result.get(0).getValue(Key.OWNER));
TracTestUtil.assertTicketEquals(ticket, result.get(0));
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracFixture.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracFixture.java
index 8d1eecf5e..ea221777c 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracFixture.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracFixture.java
@@ -144,7 +144,7 @@ public class TracFixture extends TestFixture {
}
public boolean isXmlRpcEnabled() {
- return true;
+ return Version.XML_RPC.name().equals(getAccessMode());
}
public TaskRepository singleRepository(TracRepositoryConnector connector) {
@@ -189,4 +189,8 @@ public class TracFixture extends TestFixture {
return tags.contains(tag);
}
+ public boolean requiresAuthentication() {
+ return getInfo().contains("AllBasicAuth");
+ }
+
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracHarness.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracHarness.java
index eb3dfcfc1..2216784e4 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracHarness.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracHarness.java
@@ -40,15 +40,27 @@ public class TracHarness {
this.fixture = fixture;
}
- public TracFixture getFixture() {
- return fixture;
+ public void attachFile(int ticketId, String name, String content) throws Exception {
+ priviledgedClient().putAttachmentData(ticketId, name, "", new ByteArrayInputStream(content.getBytes("UTF-8")),
+ null, true);
}
- private TracXmlRpcClient priviledgedClient() throws Exception {
- if (priviledgedClient == null) {
- priviledgedClient = (TracXmlRpcClient) fixture.connectXmlRpc(PrivilegeLevel.USER);
- }
- return priviledgedClient;
+ public TracRepositoryConnector connector() {
+ return fixture.connector();
+ }
+
+ public void createMilestone(String milestone) throws Exception {
+ new XmlRpcServer(priviledgedClient()).ticketMilestone(milestone).deleteAndCreate();
+ }
+
+ public ITask createTask(String summary) throws Exception {
+ TracTicket ticket = createTicket(summary);
+ return getTask(ticket);
+ }
+
+ public TaskData createTaskData(String summary) throws Exception {
+ TracTicket ticket = createTicket(summary);
+ return fixture.connector().getTaskData(repository(), Integer.toString(ticket.getId()), null);
}
public TracTicket createTicket(String summary) throws Exception {
@@ -61,23 +73,24 @@ public class TracHarness {
return priviledgedClient().getTicket(id, null);
}
- public TracTicket newTicket(String summary) throws InvalidTicketException {
- TracTicket ticket = new TracTicket();
- ticket.putBuiltinValue(Key.SUMMARY, summary);
- ticket.putBuiltinValue(Key.DESCRIPTION, "");
- return ticket;
- }
-
- public void createMilestone(String milestone) throws Exception {
- new XmlRpcServer(priviledgedClient()).ticketMilestone(milestone).deleteAndCreate();
- }
-
public TracTicket createTicketWithMilestone(String summary, String milestone) throws Exception {
TracTicket ticket = newTicket(summary);
ticket.putBuiltinValue(Key.MILESTONE, milestone);
return createTicket(ticket);
}
+ public void createWikiPage(String pageName, String content) throws Exception {
+ priviledgedClient().putWikipage(pageName, content, Collections.<String, Object> emptyMap(), null);
+ }
+
+ public void dispose() {
+ // TODO delete created tickets
+ }
+
+ public TracFixture getFixture() {
+ return fixture;
+ }
+
public ITask getTask(String taskId) throws Exception {
TaskRepository repository = repository();
TaskData taskData = fixture.connector().getTaskData(repository, taskId, null);
@@ -86,22 +99,28 @@ public class TracHarness {
return task;
}
- public void dispose() {
-
- }
-
public ITask getTask(TracTicket ticket) throws Exception {
return getTask(Integer.toString(ticket.getId()));
}
- public ITask createTask(String summary) throws Exception {
- TracTicket ticket = createTicket(summary);
- return getTask(ticket);
+ public boolean hasMilestone(String milestone) {
+ try {
+ new XmlRpcServer(priviledgedClient()).ticketMilestone(milestone).get();
+ } catch (Exception e) {
+ return false;
+ }
+ return true;
}
- public TaskData createTaskData(String summary) throws Exception {
- TracTicket ticket = createTicket(summary);
- return fixture.connector().getTaskData(repository(), Integer.toString(ticket.getId()), null);
+ public boolean isXmlRpc() {
+ return Version.XML_RPC.name().equals(repository().getVersion());
+ }
+
+ public TracTicket newTicket(String summary) throws InvalidTicketException {
+ TracTicket ticket = new TracTicket();
+ ticket.putBuiltinValue(Key.SUMMARY, summary);
+ ticket.putBuiltinValue(Key.DESCRIPTION, "");
+ return ticket;
}
public TaskRepository repository() {
@@ -111,21 +130,15 @@ public class TracHarness {
return repository;
}
- public TracRepositoryConnector connector() {
- return fixture.connector();
+ public void udpateTicket(TracTicket ticket) throws Exception {
+ priviledgedClient().updateTicket(ticket, "", null);
}
- public void attachFile(int ticketId, String name, String content) throws Exception {
- priviledgedClient().putAttachmentData(ticketId, name, "", new ByteArrayInputStream(content.getBytes("UTF-8")),
- null, true);
- }
-
- public boolean isXmlRpc() {
- return Version.XML_RPC.name().equals(repository().getVersion());
- }
-
- public void createWikiPage(String pageName, String content) throws Exception {
- priviledgedClient().putWikipage(pageName, content, Collections.<String, Object> emptyMap(), null);
+ private TracXmlRpcClient priviledgedClient() throws Exception {
+ if (priviledgedClient == null) {
+ priviledgedClient = (TracXmlRpcClient) fixture.connectXmlRpc(PrivilegeLevel.USER);
+ }
+ return priviledgedClient;
}
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracTestUtil.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracTestUtil.java
index b991ecd1f..22caea303 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracTestUtil.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracTestUtil.java
@@ -20,6 +20,7 @@ import java.util.Map;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version;
import org.eclipse.mylyn.internal.trac.core.model.TracTicket;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
@@ -74,7 +75,8 @@ public class TracTestUtil {
}
}
- public static void assertTicketEquals(TracTicket expectedTicket, TracTicket actualTicket) throws Exception {
+ public static void assertTicketEquals(Version accessMode, TracTicket expectedTicket, TracTicket actualTicket)
+ throws Exception {
assertTrue(actualTicket.isValid());
Map<?, ?> expectedValues = expectedTicket.getValues();
@@ -96,8 +98,16 @@ public class TracTestUtil {
// ignore internal values
continue;
}
+ if (accessMode == Version.TRAC_0_9 && expected == null && "".equals(actual)) {
+ // the web-client handles some values as the empty string that are represented as null in XML-RPC
+ continue;
+ }
assertEquals("Values for key '" + key + "' did not match", expected, actual);
}
}
+ public static void assertTicketEquals(TracTicket expectedTicket, TracTicket actualTicket) throws Exception {
+ assertTicketEquals(null, expectedTicket, actualTicket);
+ }
+
}

Back to the top