diff options
author | spingel | 2009-08-29 06:28:52 +0000 |
---|---|---|
committer | spingel | 2009-08-29 06:28:52 +0000 |
commit | 7e356e2c6a7bdf8e92457c62f68ed019fbdfc3a1 (patch) | |
tree | ba06583f1915c670c3330c1268ebbe6859b78669 /org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client | |
parent | 73b181c9568fe77a1be2122afed7ee8553d77218 (diff) | |
download | org.eclipse.mylyn.tasks-7e356e2c6a7bdf8e92457c62f68ed019fbdfc3a1.tar.gz org.eclipse.mylyn.tasks-7e356e2c6a7bdf8e92457c62f68ed019fbdfc3a1.tar.xz org.eclipse.mylyn.tasks-7e356e2c6a7bdf8e92457c62f68ed019fbdfc3a1.zip |
NEW - bug 287225: implement test suite driver for multiple repositories
https://bugs.eclipse.org/bugs/show_bug.cgi?id=287225
Diffstat (limited to 'org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client')
-rw-r--r-- | org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/AbstractTracClientTest.java | 126 | ||||
-rw-r--r-- | org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientProxyTest.java | 23 | ||||
-rw-r--r-- | org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientTest.java (renamed from org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/AbstractTracClientRepositoryTest.java) | 344 | ||||
-rw-r--r-- | org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracWebClientTest.java | 115 | ||||
-rw-r--r-- | org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcClientTest.java | 254 |
5 files changed, 248 insertions, 614 deletions
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/AbstractTracClientTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/AbstractTracClientTest.java deleted file mode 100644 index 3c73f2374..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/AbstractTracClientTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Steffen Pingel 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: - * Steffen Pingel - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import java.net.Proxy; -import java.util.Map; - -import junit.framework.TestCase; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.mylyn.commons.net.IProxyProvider; -import org.eclipse.mylyn.commons.net.WebLocation; -import org.eclipse.mylyn.context.tests.support.TestUtil; -import org.eclipse.mylyn.context.tests.support.TestUtil.Credentials; -import org.eclipse.mylyn.context.tests.support.TestUtil.PrivilegeLevel; -import org.eclipse.mylyn.internal.trac.core.TracClientFactory; -import org.eclipse.mylyn.internal.trac.core.client.ITracClient; -import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version; -import org.eclipse.mylyn.internal.trac.core.model.TracTicket; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; -import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.Ticket; - -/** - * Provides a base implementation for test cases that access trac repositories. - * - * @author Steffen Pingel - */ -public abstract class AbstractTracClientTest extends TestCase { - - public String repositoryUrl; - - public ITracClient client; - - public String username; - - public String password; - - public Version version; - - private final PrivilegeLevel level; - - final IProgressMonitor callback = new NullProgressMonitor(); - - public AbstractTracClientTest(Version version, PrivilegeLevel level) { - this.version = version; - this.level = level; - } - - public AbstractTracClientTest(Version version) { - this(version, PrivilegeLevel.USER); - } - - public AbstractTracClientTest() { - this(null, PrivilegeLevel.USER); - } - - public ITracClient connect096() throws Exception { - return connect(TracTestConstants.TEST_TRAC_096_URL); - } - - public ITracClient connect010() throws Exception { - return connect(TracTestConstants.TEST_TRAC_010_URL); - } - - public ITracClient connect010DigestAuth() throws Exception { - return connect(TracTestConstants.TEST_TRAC_010_DIGEST_AUTH_URL); - } - - public ITracClient connect011() throws Exception { - return connect(TracTestConstants.TEST_TRAC_011_URL); - } - - public ITracClient connect(String url) throws Exception { - return connect(url, Proxy.NO_PROXY); - } - - public ITracClient connect(String url, Proxy proxy) throws Exception { - Credentials credentials = TestUtil.readCredentials(level); - return connect(url, credentials.username, credentials.password, proxy); - } - - public ITracClient connect(String url, String username, String password) throws Exception { - return connect(url, username, password, Proxy.NO_PROXY); - } - - public ITracClient connect(String url, String username, String password, Proxy proxy) throws Exception { - return connect(url, username, password, proxy, version); - } - - public ITracClient connect(String url, String username, String password, final Proxy proxy, Version version) - throws Exception { - this.repositoryUrl = url; - this.username = username; - this.password = password; - - WebLocation location = new WebLocation(url, username, password, new IProxyProvider() { - public Proxy getProxyForHost(String host, String proxyType) { - return proxy; - } - }); - this.client = TracClientFactory.createClient(location, version); - - return this.client; - } - - protected void assertTicketEquals(Ticket ticket, TracTicket tracTicket) throws Exception { - assertTrue(tracTicket.isValid()); - - Map<?, ?> expectedValues = ticket.getValues(); - Map<String, String> values = tracTicket.getValues(); - for (String key : values.keySet()) { - assertEquals("Values for key '" + key + "' did not match", expectedValues.get(key), values.get(key)); - } - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientProxyTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientProxyTest.java index 3f3c1dfe9..c2db49dba 100644 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientProxyTest.java +++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientProxyTest.java @@ -15,13 +15,22 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.Proxy.Type; +import junit.framework.TestCase; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.mylyn.commons.net.IProxyProvider; +import org.eclipse.mylyn.commons.net.WebLocation; +import org.eclipse.mylyn.internal.trac.core.TracClientFactory; import org.eclipse.mylyn.internal.trac.core.client.ITracClient; import org.eclipse.mylyn.internal.trac.core.client.TracException; import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version; import org.eclipse.mylyn.trac.tests.support.TestProxy; import org.eclipse.mylyn.trac.tests.support.TracTestConstants; -public class TracClientProxyTest extends AbstractTracClientTest { +/** + * @author Steffen Pingel + */ +public class TracClientProxyTest extends TestCase { private TestProxy testProxy; @@ -29,6 +38,8 @@ public class TracClientProxyTest extends AbstractTracClientTest { private int proxyPort; + private Version version; + public TracClientProxyTest() { } @@ -70,12 +81,16 @@ public class TracClientProxyTest extends AbstractTracClientTest { private void connectProxy(String url, String expectedMethod) throws Exception { testProxy.setResponse(TestProxy.NOT_FOUND); proxy = new Proxy(Type.HTTP, new InetSocketAddress("localhost", proxyPort)); - ITracClient client = connect(url, proxy); + WebLocation location = new WebLocation(url, "", "", new IProxyProvider() { + public Proxy getProxyForHost(String host, String proxyType) { + return proxy; + } + }); + ITracClient client = TracClientFactory.createClient(location, version); try { - client.validate(callback); + client.validate(new NullProgressMonitor()); } catch (TracException e) { } - assertEquals(expectedMethod, testProxy.getRequest().getMethod()); } diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/AbstractTracClientRepositoryTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientTest.java index 93bd7029b..53d7edce2 100644 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/AbstractTracClientRepositoryTest.java +++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientTest.java @@ -15,20 +15,27 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.Proxy.Type; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; import java.util.List; +import junit.framework.TestCase; + +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.mylyn.context.tests.support.TestUtil; import org.eclipse.mylyn.context.tests.support.TestUtil.Credentials; import org.eclipse.mylyn.context.tests.support.TestUtil.PrivilegeLevel; import org.eclipse.mylyn.internal.trac.core.client.ITracClient; import org.eclipse.mylyn.internal.trac.core.client.TracException; import org.eclipse.mylyn.internal.trac.core.client.TracLoginException; +import org.eclipse.mylyn.internal.trac.core.client.TracPermissionDeniedException; import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version; import org.eclipse.mylyn.internal.trac.core.model.TracSearch; import org.eclipse.mylyn.internal.trac.core.model.TracTicket; +import org.eclipse.mylyn.internal.trac.core.model.TracVersion; import org.eclipse.mylyn.internal.trac.core.model.TracTicket.Key; -import org.eclipse.mylyn.trac.tests.support.TestFixture; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; +import org.eclipse.mylyn.trac.tests.support.TracFixture; +import org.eclipse.mylyn.trac.tests.support.TracTestUtil; import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.TestData; import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.Ticket; @@ -37,21 +44,26 @@ import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.Ticket; * * @author Steffen Pingel */ -public class AbstractTracClientRepositoryTest extends AbstractTracClientTest { +public class TracClientTest extends TestCase { - protected List<Ticket> tickets; + private ITracClient client; private TestData data; - public AbstractTracClientRepositoryTest(Version version) { - super(version); + private TracFixture fixture; + + protected List<Ticket> tickets; + + public TracClientTest() { } @Override protected void setUp() throws Exception { super.setUp(); - data = TestFixture.init010(); + fixture = TracFixture.current(); + client = fixture.connect(); + data = TracFixture.init010(); tickets = data.tickets; } @@ -62,116 +74,18 @@ public class AbstractTracClientRepositoryTest extends AbstractTracClientTest { // TestFixture.cleanupRepository1(); } - public void testValidate010() throws Exception { - validate(TracTestConstants.TEST_TRAC_010_URL); - } - - public void testValidate010DigestAuth() throws Exception { - validate(TracTestConstants.TEST_TRAC_010_DIGEST_AUTH_URL); - } - - public void testValidate011() throws Exception { - validate(TracTestConstants.TEST_TRAC_011_URL); - } - - public void testValidate010FormAuth() throws Exception { - validate(TracTestConstants.TEST_TRAC_010_FORM_AUTH_URL); - } - - protected void validate(String url) throws Exception { - Credentials credentials = TestUtil.readCredentials(PrivilegeLevel.USER); - - // standard connect - connect(url); - client.validate(callback); - - // invalid url - connect("http://non.existant/repository"); - try { - client.validate(callback); - fail("Expected TracException"); - } catch (TracException e) { - } - - // invalid password - connect(url, credentials.username, "wrongpassword"); - try { - client.validate(callback); - fail("Expected TracLoginException"); - } catch (TracLoginException e) { - } - - // invalid username - connect(url, "wrongusername", credentials.password); - try { - client.validate(callback); - fail("Expected TracLoginException"); - } catch (TracLoginException e) { - } - } - - public void testProxy() throws Exception { - connect(TracTestConstants.TEST_TRAC_010_URL, "", "", new Proxy(Type.HTTP, new InetSocketAddress( - "invalidhostname", 8080))); - try { - client.validate(callback); - fail("Expected IOException"); - } catch (TracException e) { - } - } - - public void testGetTicket096() throws Exception { - if (version == Version.XML_RPC) { - return; - } - - connect096(); - getTicket(); - } - - public void testGetTicket010() throws Exception { - connect010(); - getTicket(); - } - - public void testGetTicket011() throws Exception { - if (version == Version.TRAC_0_9) { - // XXX web mode is broken for Trac 0.11: need to fix bug 175211 - return; - } - - connect011(); - getTicket(); - } - - private void getTicket() throws Exception { + public void testGetTicket() throws Exception { TracTicket ticket = client.getTicket(tickets.get(0).getId(), null); - assertTicketEquals(tickets.get(0), ticket); + TracTestUtil.assertTicketEquals(tickets.get(0), ticket); ticket = client.getTicket(tickets.get(1).getId(), null); - assertTicketEquals(tickets.get(1), ticket); + TracTestUtil.assertTicketEquals(tickets.get(1), ticket); } - public void testGetTicketInvalidId096() throws Exception { - if (version == Version.XML_RPC) { - return; - } - - connect096(); - getTicketInvalidId(); - } - - public void testGetTicketInvalidId010() throws Exception { - connect010(); - getTicketInvalidId(); - } - - public void testGetTicketInvalidId011() throws Exception { - connect011(); - getTicketInvalidId(); - } - - private void getTicketInvalidId() throws Exception { + public void testGetTicketInvalidId() throws Exception { +// if (version == Version.XML_RPC) { +// return; +// } try { client.getTicket(Integer.MAX_VALUE, null); fail("Expected TracException"); @@ -180,41 +94,30 @@ public class AbstractTracClientRepositoryTest extends AbstractTracClientTest { } public void testGetTicketUmlaute010() throws Exception { - connect010(); - getTicketUmlaute(); - } - - public void testGetTicketUmlaute011() throws Exception { - if (version == Version.TRAC_0_9) { - // XXX need to fix bug 175211 - return; - } - - connect011(); - getTicketUmlaute(); - } - - private void getTicketUmlaute() throws Exception { +// if (version == Version.TRAC_0_9) { +// // XXX need to fix bug 175211 +// return; +// } TracTicket ticket = client.getTicket(data.htmlEntitiesTicketId, null); assertEquals("test html entities: \u00E4\u00F6\u00FC", ticket.getValue(Key.SUMMARY)); - if (version == Version.XML_RPC) { + if (client.getAccessMode() == Version.XML_RPC) { assertEquals("\u00C4\u00D6\u00DC\n\nmulti\nline\n\n'''bold'''\n", ticket.getValue(Key.DESCRIPTION)); } else { assertEquals(null, ticket.getValue(Key.DESCRIPTION)); } } - public void testSearchAll010() throws Exception { - connect010(); - searchAll(); - } - - public void testSearchAll011() throws Exception { - connect011(); - searchAll(); + public void testProxy() throws Exception { + client = fixture.connect(fixture.getRepositoryUrl(), "", "", new Proxy(Type.HTTP, new InetSocketAddress( + "invalidhostname", 8080))); + try { + client.validate(new NullProgressMonitor()); + fail("Expected IOException"); + } catch (TracException e) { + } } - private void searchAll() throws Exception { + public void testSearchAll() throws Exception { TracSearch search = new TracSearch(); List<TracTicket> result = new ArrayList<TracTicket>(); client.search(search, result, null); @@ -222,17 +125,7 @@ public class AbstractTracClientRepositoryTest extends AbstractTracClientTest { assertTrue(result.size() >= tickets.size()); } - public void testSearchEmpty010() throws Exception { - connect010(); - searchEmpty(); - } - - public void testSearchEmpty011() throws Exception { - connect011(); - searchEmpty(); - } - - private void searchEmpty() throws Exception { + public void testSearchEmpty() throws Exception { TracSearch search = new TracSearch(); search.addFilter("milestone", "does not exist"); List<TracTicket> result = new ArrayList<TracTicket>(); @@ -240,36 +133,28 @@ public class AbstractTracClientRepositoryTest extends AbstractTracClientTest { assertEquals(0, result.size()); } - public void testSearchMilestone1_010() throws Exception { - connect010(); - searchMilestone1(); - } - - public void testSearchMilestone1_011() throws Exception { - connect011(); - searchMilestone1(); - } - - private void searchMilestone1() throws Exception { + public void testSearchExactMatch010() throws Exception { TracSearch search = new TracSearch(); search.addFilter("milestone", "milestone1"); + search.addFilter("summary", "summary1"); List<TracTicket> result = new ArrayList<TracTicket>(); client.search(search, result, null); assertEquals(1, result.size()); - assertTicketEquals(tickets.get(0), result.get(0)); - } - - public void testSearchMilestone2_0_10() throws Exception { - connect010(); - searchMilestone2(); + TracTestUtil.assertTicketEquals(tickets.get(0), result.get(0)); + assertEquals("milestone1", result.get(0).getValue(Key.MILESTONE)); + assertEquals("summary1", result.get(0).getValue(Key.SUMMARY)); } - public void testSearchMilestone2_0_11() throws Exception { - connect011(); - searchMilestone2(); + public void testSearchMilestone1() throws Exception { + TracSearch search = new TracSearch(); + search.addFilter("milestone", "milestone1"); + List<TracTicket> result = new ArrayList<TracTicket>(); + client.search(search, result, null); + assertEquals(1, result.size()); + TracTestUtil.assertTicketEquals(tickets.get(0), result.get(0)); } - private void searchMilestone2() throws Exception { + public void testSearchMilestone2() throws Exception { TracSearch search = new TracSearch(); search.addFilter("milestone", "milestone1"); search.addFilter("milestone", "milestone2"); @@ -277,47 +162,110 @@ public class AbstractTracClientRepositoryTest extends AbstractTracClientTest { List<TracTicket> result = new ArrayList<TracTicket>(); client.search(search, result, null); assertEquals(3, result.size()); - assertTicketEquals(tickets.get(0), result.get(0)); - assertTicketEquals(tickets.get(1), result.get(1)); - assertTicketEquals(tickets.get(2), result.get(2)); - } - - public void testSearchExactMatch010() throws Exception { - connect010(); - searchExactMatch(); - } - - public void testSearchExactMatch011() throws Exception { - connect011(); - searchExactMatch(); + TracTestUtil.assertTicketEquals(tickets.get(0), result.get(0)); + TracTestUtil.assertTicketEquals(tickets.get(1), result.get(1)); + TracTestUtil.assertTicketEquals(tickets.get(2), result.get(2)); } - private void searchExactMatch() throws Exception { + public void testSearchMilestoneAmpersand() throws Exception { + // XXX re-enable for XML-RPC when bug 162094 is resolved + if (client.getAccessMode() == Version.XML_RPC) { + return; + } TracSearch search = new TracSearch(); - search.addFilter("milestone", "milestone1"); - search.addFilter("summary", "summary1"); + search.addFilter("milestone", "mile&stone"); + search.setOrderBy("id"); List<TracTicket> result = new ArrayList<TracTicket>(); client.search(search, result, null); assertEquals(1, result.size()); - assertTicketEquals(tickets.get(0), result.get(0)); - assertEquals("milestone1", result.get(0).getValue(Key.MILESTONE)); - assertEquals("summary1", result.get(0).getValue(Key.SUMMARY)); + TracTestUtil.assertTicketEquals(tickets.get(7), result.get(0)); + } + + public void testStatusClosed() throws Exception { + TracTicket ticket = client.getTicket(data.offlineHandlerTicketId, null); + assertEquals("closed", ticket.getValue(Key.STATUS)); + assertEquals("fixed", ticket.getValue(Key.RESOLUTION)); } - public void testStatusClosed010() throws Exception { - connect010(); - statusClosed(); + public void testUpdateAttributesAnonymous() throws Exception { + client = fixture.connect(fixture.getRepositoryUrl(), "", ""); + assertNull(client.getMilestones()); + try { + client.updateAttributes(new NullProgressMonitor(), true); + if (fixture.getAccessMode() == Version.XML_RPC) { + fail("Expected anonymous access to be denied"); + } + } catch (TracPermissionDeniedException e) { + if (fixture.getAccessMode() == Version.XML_RPC) { + return; // expected exception, done here + } + throw e; + } + TracVersion[] versions = client.getVersions(); + assertEquals(2, versions.length); + Arrays.sort(versions, new Comparator<TracVersion>() { + public int compare(TracVersion o1, TracVersion o2) { + return o1.getName().compareTo(o2.getName()); + } + }); + assertEquals("1.0", versions[0].getName()); + assertEquals("2.0", versions[1].getName()); + } + + public void testValidate() throws Exception { + Credentials credentials = TestUtil.readCredentials(PrivilegeLevel.USER); + + // standard connect + client.validate(new NullProgressMonitor()); + + // invalid url + client = TracFixture.current().connect("http://non.existant/repository"); + try { + client.validate(new NullProgressMonitor()); + fail("Expected TracException"); + } catch (TracException e) { + } + + String url = TracFixture.current().getRepositoryUrl(); + + // invalid password + client = TracFixture.current().connect(url, credentials.username, "wrongpassword"); + try { + client.validate(new NullProgressMonitor()); + fail("Expected TracLoginException"); + } catch (TracLoginException e) { + } + + // invalid username + client = TracFixture.current().connect(url, "wrongusername", credentials.password); + try { + client.validate(new NullProgressMonitor()); + fail("Expected TracLoginException"); + } catch (TracLoginException e) { + } } - public void testStatusClosed011() throws Exception { - connect011(); - statusClosed(); + public void testValidateAnonymousLogin() throws Exception { + client = fixture.connect(fixture.getRepositoryUrl(), "", ""); + try { + client.validate(new NullProgressMonitor()); + if (fixture.getAccessMode() == Version.XML_RPC) { + fail("Expected anonymous access to be denied"); + } + } catch (TracPermissionDeniedException e) { + if (fixture.getAccessMode() == Version.TRAC_0_9) { + fail("Expected anonymous access to be allowed"); + } + } } - protected void statusClosed() throws Exception { - TracTicket ticket = client.getTicket(data.offlineHandlerTicketId, null); - assertEquals("closed", ticket.getValue(Key.STATUS)); - assertEquals("fixed", ticket.getValue(Key.RESOLUTION)); + public void testValidateAnyPage() throws Exception { + client = fixture.connect("http://mylyn.eclipse.org/"); + try { + client.validate(new NullProgressMonitor()); + fail("Expected TracException"); + } catch (TracException e) { + } } } diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracWebClientTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracWebClientTest.java deleted file mode 100644 index 23990ace4..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracWebClientTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Steffen Pingel 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: - * Steffen Pingel - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.mylyn.internal.trac.core.client.TracException; -import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version; -import org.eclipse.mylyn.internal.trac.core.model.TracSearch; -import org.eclipse.mylyn.internal.trac.core.model.TracTicket; -import org.eclipse.mylyn.internal.trac.core.model.TracVersion; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; - -/** - * @author Steffen Pingel - */ -public class TracWebClientTest extends AbstractTracClientRepositoryTest { - - public TracWebClientTest() { - super(Version.TRAC_0_9); - } - - public void testValidate096() throws Exception { - validate(TracTestConstants.TEST_TRAC_096_URL); - } - - @Override - public void testValidate011() throws Exception { - try { - validate(TracTestConstants.TEST_TRAC_011_URL); - } catch (TracException e) { - } - } - - public void testValidateAnyPage() throws Exception { - connect("http://mylyn.eclipse.org/"); - try { - client.validate(callback); - fail("Expected TracException"); - } catch (TracException e) { - } - } - - public void testValidateAnonymousLogin() throws Exception { - connect(TracTestConstants.TEST_TRAC_010_URL, "", ""); - client.validate(callback); - - connect(TracTestConstants.TEST_TRAC_096_URL, "", ""); - client.validate(callback); - } - - public void testUpdateAttributesAnonymous096() throws Exception { - connect(TracTestConstants.TEST_TRAC_096_URL, "", ""); - updateAttributes(); - } - - public void testUpdateAttributesAnonymous010() throws Exception { - connect(TracTestConstants.TEST_TRAC_010_URL, "", ""); - updateAttributes(); - } - - private void updateAttributes() throws TracException { - assertNull(client.getMilestones()); - client.updateAttributes(new NullProgressMonitor(), true); - TracVersion[] versions = client.getVersions(); - assertEquals(2, versions.length); - Arrays.sort(versions, new Comparator<TracVersion>() { - public int compare(TracVersion o1, TracVersion o2) { - return o1.getName().compareTo(o2.getName()); - } - }); - assertEquals("1.0", versions[0].getName()); - assertEquals("2.0", versions[1].getName()); - } - - // TODO move this test to AbstracTracClientTest when bug 162094 is resolved - public void testSearchMilestoneAmpersand010() throws Exception { - connect010(); - searchMilestoneAmpersand(); - } - - public void testSearchMilestoneAmpersand011() throws Exception { - connect011(); - searchMilestoneAmpersand(); - } - - private void searchMilestoneAmpersand() throws Exception { - TracSearch search = new TracSearch(); - search.addFilter("milestone", "mile&stone"); - search.setOrderBy("id"); - List<TracTicket> result = new ArrayList<TracTicket>(); - client.search(search, result, null); - assertEquals(1, result.size()); - assertTicketEquals(tickets.get(7), result.get(0)); - } - - public void testStatusClosed096() throws Exception { - connect096(); - statusClosed(); - } - -} 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 0fc8da47d..8ff51c784 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 @@ -18,11 +18,13 @@ import java.util.Comparator; import java.util.Date; import java.util.List; +import junit.framework.TestCase; + import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.mylyn.internal.trac.core.client.ITracClient; import org.eclipse.mylyn.internal.trac.core.client.TracPermissionDeniedException; import org.eclipse.mylyn.internal.trac.core.client.TracRemoteException; import org.eclipse.mylyn.internal.trac.core.client.TracXmlRpcClient; -import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version; import org.eclipse.mylyn.internal.trac.core.model.TracAction; import org.eclipse.mylyn.internal.trac.core.model.TracSearch; import org.eclipse.mylyn.internal.trac.core.model.TracTicket; @@ -32,33 +34,42 @@ 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.trac.tests.support.TracTestConstants; +import org.eclipse.mylyn.trac.tests.support.TracFixture; +import org.eclipse.mylyn.trac.tests.support.TracTestUtil; +import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.TestData; +import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.Ticket; /** * @author Steffen Pingel * @author Xiaoyang Guan */ -public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest { +public class TracXmlRpcClientTest extends TestCase { - public TracXmlRpcClientTest() { - super(Version.XML_RPC); - } + protected List<Ticket> tickets; + + private TestData data; + + private ITracClient client; @Override - public void testValidate011() throws Exception { - validate(TracTestConstants.TEST_TRAC_011_URL); + protected void setUp() throws Exception { + super.setUp(); + + client = TracFixture.current().connect(); + data = TracFixture.init010(); + tickets = data.tickets; } public void testValidateFailNoAuth() throws Exception { - connect(TracTestConstants.TEST_TRAC_010_URL, "", ""); + client = TracFixture.current().connect(TracTestConstants.TEST_TRAC_010_URL, "", ""); try { - client.validate(callback); + client.validate(new NullProgressMonitor()); fail("Expected TracPermissiongDeniedException"); } catch (TracPermissionDeniedException e) { } } public void testMulticallExceptions() throws Exception { - connect010(); try { ((TracXmlRpcClient) client).getTickets(new int[] { 1, Integer.MAX_VALUE }, null); fail("Expected TracRemoteException"); @@ -66,17 +77,7 @@ public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest { } } - public void testUpdateAttributes010() throws Exception { - connect010(); - updateAttributes(); - } - - public void testUpdateAttributes011() throws Exception { - connect011(); - updateAttributes(); - } - - public void updateAttributes() throws Exception { + public void testUpdateAttributes() throws Exception { assertNull(client.getMilestones()); client.updateAttributes(new NullProgressMonitor(), true); TracVersion[] versions = client.getVersions(); @@ -94,23 +95,13 @@ public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest { assertEquals(new Date(0), versions[1].getTime()); } - public void testSearchValidateTicket010() throws Exception { - connect010(); - searchValidateTicket(); - } - - public void testSearchValidateTicket011() throws Exception { - connect011(); - searchValidateTicket(); - } - - public void searchValidateTicket() throws Exception { + public void testSearchValidateTicket() throws Exception { TracSearch search = new TracSearch(); search.addFilter("summary", "summary1"); List<TracTicket> result = new ArrayList<TracTicket>(); client.search(search, result, null); assertEquals(1, result.size()); - assertTicketEquals(tickets.get(0), result.get(0)); + TracTestUtil.assertTicketEquals(tickets.get(0), result.get(0)); assertEquals("component1", result.get(0).getValue(Key.COMPONENT)); assertEquals("description1", result.get(0).getValue(Key.DESCRIPTION)); assertEquals("milestone1", result.get(0).getValue(Key.MILESTONE)); @@ -120,73 +111,60 @@ public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest { } public void testGetTicketActions010() throws Exception { - connect010(); - - TracTicket ticket = client.getTicket(tickets.get(0).getId(), null); - TracAction[] actions = ticket.getActions(); - assertNotNull(actions); - assertEquals(4, actions.length); - assertEquals("leave", actions[0].getId()); - assertNull(actions[0].getLabel()); - assertEquals(0, actions[0].getFields().size()); - assertEquals("resolve", actions[1].getId()); - assertNull(actions[1].getLabel()); - assertEquals(0, actions[1].getFields().size()); - assertEquals("reassign", actions[2].getId()); - assertNull(actions[2].getLabel()); - assertEquals(0, actions[2].getFields().size()); - assertEquals("accept", actions[3].getId()); - assertNull(actions[3].getLabel()); - assertEquals(0, actions[3].getFields().size()); - - ticket = client.getTicket(tickets.get(1).getId(), null); - actions = ticket.getActions(); - assertNotNull(actions); - assertEquals(2, actions.length); - assertEquals("leave", actions[0].getId()); - assertEquals("reopen", actions[1].getId()); - } - - public void testGetTicketActions011() throws Exception { - connect011(); - - TracTicket ticket = client.getTicket(tickets.get(0).getId(), null); - TracAction[] actions = ticket.getActions(); - assertNotNull(actions); - assertEquals(4, actions.length); - assertEquals("leave", actions[0].getId()); - assertEquals("resolve", actions[1].getId()); - assertEquals("resolve", actions[1].getLabel()); - assertNotNull(actions[1].getHint()); - List<TracTicketField> fields = actions[1].getFields(); - assertEquals(1, fields.size()); - assertEquals(5, fields.get(0).getOptions().length); - assertEquals("fixed", fields.get(0).getOptions()[0]); - assertEquals("reassign", actions[2].getId()); - fields = actions[2].getFields(); - assertEquals(1, fields.size()); - assertNull(fields.get(0).getOptions()); - assertEquals("accept", actions[3].getId()); - - ticket = client.getTicket(tickets.get(1).getId(), null); - actions = ticket.getActions(); - assertNotNull(actions); - assertEquals(2, actions.length); - assertEquals("leave", actions[0].getId()); - assertEquals("reopen", actions[1].getId()); - } - - public void testWikiToHtml010() throws Exception { - connect010(); - wikiToHtml(TracTestConstants.TEST_TRAC_010_URL); - } - - public void testWikiToHtml011() throws Exception { - connect011(); - wikiToHtml("http://mylyn.eclipse.org/trac011"); + if (client.getUrl().equals(TracTestConstants.TEST_TRAC_010_URL)) { + TracTicket ticket = client.getTicket(tickets.get(0).getId(), null); + TracAction[] actions = ticket.getActions(); + assertNotNull(actions); + assertEquals(4, actions.length); + assertEquals("leave", actions[0].getId()); + assertNull(actions[0].getLabel()); + assertEquals(0, actions[0].getFields().size()); + assertEquals("resolve", actions[1].getId()); + assertNull(actions[1].getLabel()); + assertEquals(0, actions[1].getFields().size()); + assertEquals("reassign", actions[2].getId()); + assertNull(actions[2].getLabel()); + assertEquals(0, actions[2].getFields().size()); + assertEquals("accept", actions[3].getId()); + assertNull(actions[3].getLabel()); + assertEquals(0, actions[3].getFields().size()); + + ticket = client.getTicket(tickets.get(1).getId(), null); + actions = ticket.getActions(); + assertNotNull(actions); + assertEquals(2, actions.length); + assertEquals("leave", actions[0].getId()); + assertEquals("reopen", actions[1].getId()); + } else { + TracTicket ticket = client.getTicket(tickets.get(0).getId(), null); + TracAction[] actions = ticket.getActions(); + assertNotNull(actions); + assertEquals(4, actions.length); + assertEquals("leave", actions[0].getId()); + assertEquals("resolve", actions[1].getId()); + assertEquals("resolve", actions[1].getLabel()); + assertNotNull(actions[1].getHint()); + List<TracTicketField> fields = actions[1].getFields(); + assertEquals(1, fields.size()); + assertEquals(5, fields.get(0).getOptions().length); + assertEquals("fixed", fields.get(0).getOptions()[0]); + assertEquals("reassign", actions[2].getId()); + fields = actions[2].getFields(); + assertEquals(1, fields.size()); + assertNull(fields.get(0).getOptions()); + assertEquals("accept", actions[3].getId()); + + ticket = client.getTicket(tickets.get(1).getId(), null); + actions = ticket.getActions(); + assertNotNull(actions); + assertEquals(2, actions.length); + assertEquals("leave", actions[0].getId()); + assertEquals("reopen", actions[1].getId()); + } } - public void wikiToHtml(String tracUrl) throws Exception { + public void testWikiToHtml() throws Exception { + String tracUrl = client.getUrl(); String html = ((TracXmlRpcClient) client).wikiToHtml("", null); assertEquals("", html); @@ -206,43 +184,17 @@ public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest { assertEquals(expectedHtml, html); } - public void testValidateWikiAPI010() throws Exception { - connect010(); - ((TracXmlRpcClient) client).validateWikiRpcApi(null); - } - - public void testValidateWikiAPI011() throws Exception { - connect011(); + public void testValidateWikiAPI() throws Exception { ((TracXmlRpcClient) client).validateWikiRpcApi(null); } - public void testGetAllWikiPageNames010() throws Exception { - connect010(); - getAllWikiPageNames(); - } - - public void testGetAllWikiPageNames011() throws Exception { - connect011(); - getAllWikiPageNames(); - } - - private void getAllWikiPageNames() throws Exception { + public void testGetAllWikiPageNames() throws Exception { String[] names = ((TracXmlRpcClient) client).getAllWikiPageNames(null); 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 { + public void testGetWikiPage() throws Exception { TracWikiPage page = ((TracXmlRpcClient) client).getWikiPage("TestGetPage", null); assertEquals("TestGetPage", page.getPageInfo().getPageName()); assertEquals("tests@mylyn.eclipse.org", page.getPageInfo().getAuthor()); @@ -261,17 +213,7 @@ public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest { assertTrue(page.getPageHTML().startsWith("<html>")); } - public void testGetWikiPageInvalid010() throws Exception { - connect010(); - getWikiPageInvalid(); - } - - public void testGetWikiPageInvalid011() throws Exception { - connect011(); - getWikiPageInvalid(); - } - - private void getWikiPageInvalid() throws Exception { + public void testGetWikiPageInvalid() throws Exception { // get info -- non-existing version try { ((TracXmlRpcClient) client).getWikiPageInfo("Test", 10, null); @@ -371,17 +313,7 @@ public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest { } } - public void testGetWikiPageInfoAllVersions010() throws Exception { - connect010(); - getWikiPageInfoAllVersions(); - } - - public void testGetWikiPageInfoAllVersions011() throws Exception { - connect011(); - getWikiPageInfoAllVersions(); - } - - private void getWikiPageInfoAllVersions() throws Exception { + public void testGetWikiPageInfoAllVersions() throws Exception { String pageName = "Test"; TracWikiPageInfo[] versions = ((TracXmlRpcClient) client).getWikiPageInfoAllVersions(pageName, null); @@ -393,17 +325,7 @@ public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest { } } - public void testGetRecentWikiChanges010() throws Exception { - connect010(); - getRecentWikiChanges(); - } - - public void testGetRecentWikiChanges011() throws Exception { - connect011(); - getRecentWikiChanges(); - } - - private void getRecentWikiChanges() throws Exception { + public void testGetRecentWikiChanges() throws Exception { TracWikiPageInfo[] changes = ((TracXmlRpcClient) client).getRecentWikiChanges(new Date(0), null); TracWikiPageInfo testPage = null; for (TracWikiPageInfo item : changes) { @@ -415,17 +337,7 @@ public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest { assertTrue(testPage != null); } - public void testPutWikiPage010() throws Exception { - connect010(); - putWikiPage(); - } - - public void testPutWikiPage011() throws Exception { - connect011(); - putWikiPage(); - } - - private void putWikiPage() throws Exception { + public void testPutWikiPage() throws Exception { // TODO testing wiki.putPage() } |