diff options
Diffstat (limited to 'org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn')
31 files changed, 0 insertions, 4659 deletions
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtilStandaloneTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtilStandaloneTest.java deleted file mode 100644 index f6a8dd079..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/internal/trac/ui/TracHyperlinkUtilStandaloneTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 David Green 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: - * David Green - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.internal.trac.ui; - -import java.util.regex.Matcher; - -import junit.framework.TestCase; - -/** - * @author David Green - */ -public class TracHyperlinkUtilStandaloneTest extends TestCase { - - public void testWikiPattern2SinglePositiveMatch() { - Matcher matcher = TracHyperlinkUtil.wikiPattern2.matcher("a HyperLink there"); - assertTrue(matcher.find()); - assertEquals(matcher.group(0), "HyperLink"); - assertFalse(matcher.find()); - } - - public void testWikiPattern2MultiplePositiveMatch() { - Matcher matcher = TracHyperlinkUtil.wikiPattern2.matcher("a HyperLink there and ThereIsAnother"); - assertTrue(matcher.find()); - assertEquals(matcher.group(0), "HyperLink"); - assertTrue(matcher.find()); - assertEquals(matcher.group(0), "ThereIsAnother"); - assertFalse(matcher.find()); - } - - public void testWikiPattern2SingleNegativeMatch() { - Matcher matcher = TracHyperlinkUtil.wikiPattern2.matcher("no !HyperLink there"); - assertFalse(matcher.find()); - } - - public void testWikiPattern2SinglePositiveMatchAtStartOfLine() { - Matcher matcher = TracHyperlinkUtil.wikiPattern2.matcher("HyperLink there"); - assertTrue(matcher.find()); - assertEquals(matcher.group(0), "HyperLink"); - assertFalse(matcher.find()); - } - - public void testWikiPattern2SingleNegativeMatchAtStartOfLine() { - Matcher matcher = TracHyperlinkUtil.wikiPattern2.matcher("!HyperLink there"); - assertFalse(matcher.find()); - } - - public void testWikiPattern2MixedPositiveNegativeMatch() { - Matcher matcher = TracHyperlinkUtil.wikiPattern2.matcher("a HyperLink there and ThereIsAnother but !NotHere"); - assertTrue(matcher.find()); - assertEquals(matcher.group(0), "HyperLink"); - assertTrue(matcher.find()); - assertEquals(matcher.group(0), "ThereIsAnother"); - assertFalse(matcher.find()); - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracHeadlessStandaloneTests.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracHeadlessStandaloneTests.java deleted file mode 100644 index feb77b6a3..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracHeadlessStandaloneTests.java +++ /dev/null @@ -1,49 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.mylyn.trac.tests.client.TracClientFactoryTest; -import org.eclipse.mylyn.trac.tests.client.TracClientProxyTest; -import org.eclipse.mylyn.trac.tests.client.TracSearchTest; -import org.eclipse.mylyn.trac.tests.client.TracTicketTest; -import org.eclipse.mylyn.trac.tests.client.TracWebClientSearchTest; -import org.eclipse.mylyn.trac.tests.client.TracWebClientTest; -import org.eclipse.mylyn.trac.tests.client.TracXmlRpcClientSearchTest; -import org.eclipse.mylyn.trac.tests.client.TracXmlRpcClientTest; -import org.eclipse.mylyn.trac.tests.core.TracClientManagerTest; - -/** - * @author Mik Kersten - * @author Steffen Pingel - */ -public class AllTracHeadlessStandaloneTests { - - public static Test suite() { - TestSuite suite = new TestSuite("Headless Standalone Tests for org.eclipse.mylyn.trac.tests"); - // other - suite.addTestSuite(TracClientManagerTest.class); - // client - suite.addTestSuite(TracSearchTest.class); - suite.addTestSuite(TracTicketTest.class); - suite.addTestSuite(TracXmlRpcClientTest.class); - suite.addTestSuite(TracXmlRpcClientSearchTest.class); - suite.addTestSuite(TracWebClientTest.class); - suite.addTestSuite(TracWebClientSearchTest.class); - suite.addTestSuite(TracClientFactoryTest.class); - suite.addTestSuite(TracClientProxyTest.class); - return suite; - } - -}
\ No newline at end of file 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 deleted file mode 100644 index 0a524b9f6..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/AllTracTests.java +++ /dev/null @@ -1,47 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.mylyn.trac.tests.core.RepositorySearchTest; -import org.eclipse.mylyn.trac.tests.core.TracAttachmentHandlerTest; -import org.eclipse.mylyn.trac.tests.core.TracRepositoryConnectorTest; -import org.eclipse.mylyn.trac.tests.core.TracRepositoryQueryTest; -import org.eclipse.mylyn.trac.tests.core.TracTaskDataHandlerTest; -import org.eclipse.mylyn.trac.tests.core.TracUtilTest; -import org.eclipse.mylyn.trac.tests.ui.TracHyperlinkUtilTest; -import org.eclipse.mylyn.trac.tests.ui.TracRepositorySettingsPageTest; - -/** - * @author Mik Kersten - * @author Steffen Pingel - */ -public class AllTracTests { - - public static Test suite() { - TestSuite suite = new TestSuite("Tests for org.eclipse.mylyn.trac.tests"); - suite.addTest(AllTracHeadlessStandaloneTests.suite()); - suite.addTestSuite(TracRepositoryConnectorTest.class); - suite.addTestSuite(TracUtilTest.class); - suite.addTestSuite(TracRepositoryQueryTest.class); - suite.addTestSuite(TracAttachmentHandlerTest.class); - suite.addTestSuite(RepositorySearchTest.class); - suite.addTestSuite(TracTaskDataHandlerTest.class); - // XXX fails when run from continuous build: suite.addTestSuite(TracTaskEditorTest.class); - suite.addTestSuite(TracRepositorySettingsPageTest.class); - suite.addTestSuite(TracHyperlinkUtilTest.class); - return suite; - } - -}
\ No newline at end of file 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/AbstractTracClientRepositoryTest.java deleted file mode 100644 index e90fdee4d..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/AbstractTracClientRepositoryTest.java +++ /dev/null @@ -1,96 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.net.Proxy.Type; - -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.ITracClient.Version; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; - -/** - * Test cases for classes that implement {@link ITracClient}. - * - * @author Steffen Pingel - */ -public class AbstractTracClientRepositoryTest extends AbstractTracClientTest { - - public AbstractTracClientRepositoryTest(Version version) { - super(version); - } - - 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); - repository.validate(callback); - - // invalid url - connect("http://non.existant/repository"); - try { - repository.validate(callback); - fail("Expected TracException"); - } catch (TracException e) { - } - - // invalid password - connect(url, credentials.username, "wrongpassword"); - try { - repository.validate(callback); - fail("Expected TracLoginException"); - } catch (TracLoginException e) { - } - - // invalid username - connect(url, "wrongusername", credentials.password); - try { - repository.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 { - repository.validate(callback); - fail("Expected IOException"); - } catch (TracException e) { - } - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/AbstractTracClientSearchTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/AbstractTracClientSearchTest.java deleted file mode 100644 index 575706444..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/AbstractTracClientSearchTest.java +++ /dev/null @@ -1,268 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -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.internal.trac.core.model.TracSearch; -import org.eclipse.mylyn.internal.trac.core.model.TracTicket; -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.XmlRpcServer.TestData; -import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.Ticket; - -/** - * Test cases that validate search results for classes that implement {@link ITracClient}. - * - * @author Steffen Pingel - */ -public abstract class AbstractTracClientSearchTest extends AbstractTracClientTest { - - protected List<Ticket> tickets; - - private TestData data; - - public AbstractTracClientSearchTest(Version version) { - super(version); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - data = TestFixture.init010(); - tickets = data.tickets; - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - - // TestFixture.cleanupRepository1(); - } - - 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)); - } - } - - 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 { - TracTicket ticket = repository.getTicket(tickets.get(0).getId(), null); - assertTicketEquals(tickets.get(0), ticket); - - ticket = repository.getTicket(tickets.get(1).getId(), null); - 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 { - try { - repository.getTicket(Integer.MAX_VALUE, null); - fail("Expected TracException"); - } catch (TracException e) { - } - } - - 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 { - TracTicket ticket = repository.getTicket(data.htmlEntitiesTicketId, null); - assertEquals("test html entities: \u00E4\u00F6\u00FC", ticket.getValue(Key.SUMMARY)); - if (version == 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(); - } - - private void searchAll() throws Exception { - TracSearch search = new TracSearch(); - List<TracTicket> result = new ArrayList<TracTicket>(); - repository.search(search, result, null); - //assertEquals(tickets.size(), result.size()); - assertTrue(result.size() >= tickets.size()); - } - - public void testSearchEmpty010() throws Exception { - connect010(); - searchEmpty(); - } - - public void testSearchEmpty011() throws Exception { - connect011(); - searchEmpty(); - } - - private void searchEmpty() throws Exception { - TracSearch search = new TracSearch(); - search.addFilter("milestone", "does not exist"); - List<TracTicket> result = new ArrayList<TracTicket>(); - repository.search(search, result, null); - assertEquals(0, result.size()); - } - - public void testSearchMilestone1010() throws Exception { - connect010(); - searchMilestone1(); - } - - public void testSearchMilestone1011() throws Exception { - connect011(); - searchMilestone1(); - } - - private void searchMilestone1() throws Exception { - TracSearch search = new TracSearch(); - search.addFilter("milestone", "milestone1"); - List<TracTicket> result = new ArrayList<TracTicket>(); - repository.search(search, result, null); - assertEquals(1, result.size()); - assertTicketEquals(tickets.get(0), result.get(0)); - } - - public void testSearchMilestone2010() throws Exception { - connect010(); - searchMilestone2(); - } - - public void testSearchMilestone2011() throws Exception { - connect011(); - searchMilestone2(); - } - - private void searchMilestone2() throws Exception { - TracSearch search = new TracSearch(); - search.addFilter("milestone", "milestone1"); - search.addFilter("milestone", "milestone2"); - search.setOrderBy("id"); - List<TracTicket> result = new ArrayList<TracTicket>(); - repository.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(); - } - - private void searchExactMatch() throws Exception { - TracSearch search = new TracSearch(); - search.addFilter("milestone", "milestone1"); - search.addFilter("summary", "summary1"); - List<TracTicket> result = new ArrayList<TracTicket>(); - repository.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)); - } - - public void testStatusClosed010() throws Exception { - connect010(); - statusClosed(); - } - - public void testStatusClosed011() throws Exception { - connect011(); - statusClosed(); - } - - protected void statusClosed() throws Exception { - TracTicket ticket = repository.getTicket(data.offlineHandlerTicketId, null); - assertEquals("closed", ticket.getValue(Key.STATUS)); - assertEquals("fixed", ticket.getValue(Key.RESOLUTION)); - } - -} 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 0d3a526fa..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/AbstractTracClientTest.java +++ /dev/null @@ -1,113 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import java.net.Proxy; - -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.trac.tests.support.TracTestConstants; - -/** - * 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 repository; - - 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.repository = TracClientFactory.createClient(location, version); - - return this.repository; - } - -} 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 deleted file mode 100644 index 74d45ac7e..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientFactoryTest.java +++ /dev/null @@ -1,102 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import junit.framework.TestCase; - -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.TracException; -import org.eclipse.mylyn.internal.trac.core.client.TracLoginException; -import org.eclipse.mylyn.internal.trac.core.client.TracWebClient; -import org.eclipse.mylyn.internal.trac.core.client.TracXmlRpcClient; -import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; - -/** - * @author Steffen Pingel - */ -public class TracClientFactoryTest extends TestCase { - - public void testCreateClient() throws Exception { - WebLocation location = new WebLocation(TracTestConstants.TEST_TRAC_010_URL, "user", "password"); - ITracClient client = TracClientFactory.createClient(location, Version.TRAC_0_9); - assertTrue(client instanceof TracWebClient); - - location = new WebLocation(TracTestConstants.TEST_TRAC_010_SSL_URL, "user", "password"); - client = TracClientFactory.createClient(location, Version.TRAC_0_9); - assertTrue(client instanceof TracWebClient); - - location = new WebLocation(TracTestConstants.TEST_TRAC_010_URL, "user", "password"); - client = TracClientFactory.createClient(location, Version.XML_RPC); - assertTrue(client instanceof TracXmlRpcClient); - - location = new WebLocation(TracTestConstants.TEST_TRAC_010_SSL_URL, "user", "password"); - client = TracClientFactory.createClient(location, Version.XML_RPC); - assertTrue(client instanceof TracXmlRpcClient); - } - - public void testCreateClientNull() throws Exception { - try { - WebLocation location = new WebLocation(TracTestConstants.TEST_TRAC_010_URL, "user", "password"); - TracClientFactory.createClient(location, null); - fail("Expected Exception"); - } catch (Exception e) { - } - } - - public void testProbeClient096() throws Exception { - probeClient(TracTestConstants.TEST_TRAC_096_URL, false); - } - - public void testProbeClient010() throws Exception { - probeClient(TracTestConstants.TEST_TRAC_010_URL, true); - } - - public void testProbeClient010DigestAuth() throws Exception { - probeClient(TracTestConstants.TEST_TRAC_010_DIGEST_AUTH_URL, true); - } - - protected void probeClient(String url, boolean xmlrpcInstalled) throws Exception { - Credentials credentials = TestUtil.readCredentials(PrivilegeLevel.USER); - WebLocation location = new WebLocation(url, credentials.username, credentials.password); - Version version = TracClientFactory.probeClient(location); - if (xmlrpcInstalled) { - 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); - - try { - location = new WebLocation(url, "invaliduser", "password"); - version = TracClientFactory.probeClient(location); - fail("Expected TracLoginException, got " + version); - } catch (TracLoginException e) { - } - - try { - location = new WebLocation(url + "/nonexistant", "", ""); - 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/TracClientProxyTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientProxyTest.java deleted file mode 100644 index 7f2643ed1..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracClientProxyTest.java +++ /dev/null @@ -1,82 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.net.Proxy.Type; - -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 { - - private TestProxy testProxy; - - private Proxy proxy; - - private int proxyPort; - - public TracClientProxyTest() { - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - testProxy = new TestProxy(); - proxyPort = testProxy.startAndWait(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - - testProxy.stop(); - } - - public void testConnectProxyWeb() throws Exception { - version = Version.TRAC_0_9; - connectProxy(TracTestConstants.TEST_TRAC_010_URL, "GET"); - } - - public void testConnectProxyXmlRpc() throws Exception { - version = Version.XML_RPC; - connectProxy(TracTestConstants.TEST_TRAC_010_URL, "POST"); - } - - public void testConnectProxySslWeb() throws Exception { - version = Version.TRAC_0_9; - connectProxy(TracTestConstants.TEST_TRAC_010_SSL_URL, "CONNECT"); - } - - public void testConnectProxySslXmlRpc() throws Exception { - version = Version.XML_RPC; - connectProxy(TracTestConstants.TEST_TRAC_010_SSL_URL, "CONNECT"); - } - - 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); - try { - client.validate(callback); - } catch (TracException e) { - } - - assertEquals(expectedMethod, testProxy.getRequest().getMethod()); - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracSearchTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracSearchTest.java deleted file mode 100644 index 538f6cd81..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracSearchTest.java +++ /dev/null @@ -1,136 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import junit.framework.TestCase; - -import org.eclipse.mylyn.internal.trac.core.model.TracSearch; - -/** - * @author Steffen Pingel - */ -public class TracSearchTest extends TestCase { - - private static final String QUERY1 = "&status=new|assigned|reopened&milestone~=0.1"; - - private static final String URL1 = "&status=new&status=assigned&status=reopened&milestone=%7E0.1"; - - private TracSearch search1; - - @Override - protected void setUp() throws Exception { - super.setUp(); - - search1 = new TracSearch(); - search1.addFilter("status", "new"); - search1.addFilter("status", "assigned"); - search1.addFilter("status", "reopened"); - search1.addFilter("milestone", "~0.1"); - } - - public void testToQuery() { - assertEquals(QUERY1, search1.toQuery()); - } - - public void testToQueryEmpty() { - assertEquals("", new TracSearch().toQuery()); - } - - public void testToQueryOperators1() { - TracSearch search = new TracSearch(); - search.addFilter("is", "a"); - search.addFilter("contains", "~b"); - search.addFilter("starts", "^c"); - search.addFilter("ends", "$d"); - search.addFilter("nis", "!e"); - search.addFilter("ncontains", "!~f"); - search.addFilter("nstarts", "!^g"); - search.addFilter("nends", "!$h"); - - assertEquals("&is=a&contains~=b&starts^=c&ends$=d&nis!=e&ncontains!~=f&nstarts!^=g&nends!$=h", search.toQuery()); - } - - public void testToQueryOperators2() { - TracSearch search = new TracSearch(); - search.addFilter("nstarts", "!^g"); - search.addFilter("nis", "!e"); - search.addFilter("is", "a"); - - assertEquals("&nstarts!^=g&nis!=e&is=a", search.toQuery()); - } - - public void testToQuerySortOrder() { - search1.setOrderBy("id"); - assertEquals("&order=id" + QUERY1, search1.toQuery()); - - search1.setAscending(false); - assertEquals("&order=id&desc=1" + QUERY1, search1.toQuery()); - - search1.setOrderBy("summary"); - search1.setAscending(true); - assertEquals("&order=summary" + QUERY1, search1.toQuery()); - } - - public void testToUrl() { - assertEquals(URL1, search1.toUrl()); - } - - public void testToUrlEmpty() { - // assertEquals("", new TracSearch().toUrl()); - // returns non-empty string to work around a strange Trac behaviour, see - // TracSearch.toUrl() - assertEquals("&order=id", new TracSearch().toUrl()); - } - - public void testToUrlEncoding() { - search1.addFilter("encoded", "&"); - assertEquals(URL1 + "&encoded=%26", search1.toUrl()); - } - - public void testToUrlOperators1() { - TracSearch search = new TracSearch(); - search.addFilter("is", "a"); - search.addFilter("contains", "~b"); - search.addFilter("starts", "^c"); - search.addFilter("ends", "$d"); - search.addFilter("nis", "!e"); - search.addFilter("ncontains", "!~f"); - search.addFilter("nstarts", "!^g"); - search.addFilter("nends", "!$h"); - - assertEquals( - "&is=a&contains=%7Eb&starts=%5Ec&ends=%24d&nis=%21e&ncontains=%21%7Ef&nstarts=%21%5Eg&nends=%21%24h", - search.toUrl()); - } - - public void testToUrlOperators2() { - TracSearch search = new TracSearch(); - search.addFilter("nstarts", "!^g"); - search.addFilter("nis", "!e"); - search.addFilter("is", "a"); - - assertEquals("&nstarts=%21%5Eg&nis=%21e&is=a", search.toUrl()); - } - - public void testToUrlSortOrder() { - search1.setOrderBy("id"); - assertEquals("&order=id" + QUERY1, search1.toQuery()); - - search1.setAscending(false); - assertEquals("&order=id&desc=1" + QUERY1, search1.toQuery()); - - search1.setOrderBy("summary"); - search1.setAscending(true); - assertEquals("&order=summary" + QUERY1, search1.toQuery()); - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracTicketTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracTicketTest.java deleted file mode 100644 index 9c55e077d..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracTicketTest.java +++ /dev/null @@ -1,70 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import java.util.Calendar; -import java.util.Date; -import java.util.TimeZone; - -import junit.framework.TestCase; - -import org.eclipse.mylyn.internal.trac.core.client.InvalidTicketException; -import org.eclipse.mylyn.internal.trac.core.model.TracTicket; -import org.eclipse.mylyn.internal.trac.core.model.TracTicket.Key; -import org.eclipse.mylyn.internal.trac.core.util.TracUtil; - -/** - * @author Steffen Pingel - */ -public class TracTicketTest extends TestCase { - - public void testValid() { - TracTicket ticket = new TracTicket(); - assertFalse(ticket.isValid()); - - ticket.setId(1); - assertTrue(ticket.isValid()); - } - - public void testPutTracValue() throws InvalidTicketException { - TracTicket ticket = new TracTicket(1); - ticket.putValue("summary", "a"); - assertEquals("a", ticket.getValue(Key.SUMMARY)); - assertEquals(null, ticket.getCustomValue("summary")); - assertEquals(null, ticket.getCustomValue("a")); - - ticket.putValue("summary", "b"); - ticket.putValue("custom", "c"); - assertEquals("b", ticket.getValue(Key.SUMMARY)); - assertEquals(null, ticket.getCustomValue("summary")); - assertEquals("c", ticket.getCustomValue("custom")); - } - - public void testPutTracValueId() throws InvalidTicketException { - TracTicket ticket = new TracTicket(); - assertFalse(ticket.putValue("id", "1")); - } - - public void testSetCreated() throws InvalidTicketException { - TracTicket ticket = new TracTicket(1); - ticket.setCreated(TracUtil.parseDate(0)); - assertEquals(TimeZone.getTimeZone("GMT").getOffset(0) * 1000, ticket.getCreated().getTime()); - - Date date = new Date(); - Calendar utc = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - utc.setTime(date); - ticket.setCreated(TracUtil.parseDate((int) (utc.getTimeInMillis() / 1000))); - - assertEquals(date.getTime() / 1000, ticket.getCreated().getTime() / 1000); - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracWebClientSearchTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracWebClientSearchTest.java deleted file mode 100644 index 5cb7a4627..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracWebClientSearchTest.java +++ /dev/null @@ -1,56 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import java.util.ArrayList; -import java.util.List; - -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; - -/** - * @author Steffen Pingel - */ -public class TracWebClientSearchTest extends AbstractTracClientSearchTest { - - public TracWebClientSearchTest() { - super(Version.TRAC_0_9); - } - - // 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>(); - repository.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/TracWebClientTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracWebClientTest.java deleted file mode 100644 index c5784c49a..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracWebClientTest.java +++ /dev/null @@ -1,85 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import java.util.Arrays; -import java.util.Comparator; - -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.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 { - repository.validate(callback); - fail("Expected TracException"); - } catch (TracException e) { - } - } - - public void testValidateAnonymousLogin() throws Exception { - connect(TracTestConstants.TEST_TRAC_010_URL, "", ""); - repository.validate(callback); - - connect(TracTestConstants.TEST_TRAC_096_URL, "", ""); - repository.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(repository.getMilestones()); - repository.updateAttributes(new NullProgressMonitor(), true); - TracVersion[] versions = repository.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()); - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcClientSearchTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcClientSearchTest.java deleted file mode 100644 index 904d8f077..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcClientSearchTest.java +++ /dev/null @@ -1,56 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import java.util.ArrayList; -import java.util.List; - -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.TracTicket.Key; - -/** - * @author Steffen Pingel - */ -public class TracXmlRpcClientSearchTest extends AbstractTracClientSearchTest { - - public TracXmlRpcClientSearchTest() { - super(Version.XML_RPC); - } - - public void testSearchValidateTicket010() throws Exception { - connect010(); - searchValidateTicket(); - } - - public void testSearchValidateTicket011() throws Exception { - connect011(); - searchValidateTicket(); - } - - public void searchValidateTicket() throws Exception { - TracSearch search = new TracSearch(); - search.addFilter("summary", "summary1"); - List<TracTicket> result = new ArrayList<TracTicket>(); - repository.search(search, result, null); - assertEquals(1, result.size()); - 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)); - assertEquals("anonymous", result.get(0).getValue(Key.REPORTER)); - assertEquals("summary1", result.get(0).getValue(Key.SUMMARY)); - // assertEquals("", result.get(0).getValue(Key.VERSION)); - } - -} 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 deleted file mode 100644 index 4297dc52d..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcClientTest.java +++ /dev/null @@ -1,343 +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: - * Tasktop Technologies - initial API and implementation - * Xiaoyang Guan - improvements - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -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.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.TracVersion; -import org.eclipse.mylyn.internal.trac.core.model.TracWikiPage; -import org.eclipse.mylyn.internal.trac.core.model.TracWikiPageInfo; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; - -/** - * @author Steffen Pingel - * @author Xiaoyang Guan - */ -public class TracXmlRpcClientTest extends AbstractTracClientRepositoryTest { - - public TracXmlRpcClientTest() { - super(Version.XML_RPC); - } - - @Override - public void testValidate011() throws Exception { - validate(TracTestConstants.TEST_TRAC_011_URL); - } - - public void testValidateFailNoAuth() throws Exception { - connect(TracTestConstants.TEST_TRAC_010_URL, "", ""); - try { - repository.validate(callback); - fail("Expected TracPermissiongDeniedException"); - } catch (TracPermissionDeniedException e) { - } - } - - public void testMulticallExceptions() throws Exception { - connect010(); - try { - ((TracXmlRpcClient) repository).getTickets(new int[] { 1, Integer.MAX_VALUE }, null); - fail("Expected TracRemoteException"); - } catch (TracRemoteException e) { - } - } - - public void testUpdateAttributes010() throws Exception { - connect010(); - updateAttributes(); - } - - public void testUpdateAttributes011() throws Exception { - connect011(); - updateAttributes(); - } - - public void updateAttributes() throws Exception { - assertNull(repository.getMilestones()); - repository.updateAttributes(new NullProgressMonitor(), true); - TracVersion[] versions = repository.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("", versions[0].getDescription()); - assertEquals(new Date(0), versions[0].getTime()); - assertEquals("2.0", versions[1].getName()); - assertEquals("", versions[1].getDescription()); - assertEquals(new Date(0), versions[1].getTime()); - } - - public void testWikiToHtml010() throws Exception { - connect010(); - wikiToHtml(TracTestConstants.TEST_TRAC_010_URL); - } - - public void testWikiToHtml011() throws Exception { - connect011(); - wikiToHtml("/trac011"); - } - - public void wikiToHtml(String tracUrl) throws Exception { - String html = ((TracXmlRpcClient) repository).wikiToHtml("", null); - assertEquals("", html); - - html = ((TracXmlRpcClient) repository).wikiToHtml("A simple line of text.", null); - assertEquals("<p>\nA simple line of text.\n</p>\n", html); - - String source = "= WikiFormattingTesting =\n" + " * '''bold''', '''!''' can be bold too''', and '''! '''\n" - + " * ''italic''\n" + " * '''''bold italic'''''\n" + " * __underline__\n" - + " * {{{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"; - - html = ((TracXmlRpcClient) repository).wikiToHtml(source, null); - assertEquals(expectedHtml, html); - } - - public void testValidateWikiAPI010() throws Exception { - connect010(); - ((TracXmlRpcClient) repository).validateWikiRpcApi(null); - } - - public void testValidateWikiAPI011() throws Exception { - connect011(); - ((TracXmlRpcClient) repository).validateWikiRpcApi(null); - } - - public void testGetAllWikiPageNames010() throws Exception { - connect010(); - getAllWikiPageNames(); - } - - public void testGetAllWikiPageNames011() throws Exception { - connect011(); - getAllWikiPageNames(); - } - - private void getAllWikiPageNames() throws Exception { - String[] names = ((TracXmlRpcClient) repository).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 { - TracWikiPage page = ((TracXmlRpcClient) repository).getWikiPage("TestGetPage", null); - assertEquals("TestGetPage", page.getPageInfo().getPageName()); - assertEquals("tests@mylyn.eclipse.org", page.getPageInfo().getAuthor()); - assertEquals(2, 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()); - assertEquals("Version 2", page.getContent()); - assertTrue(page.getPageHTML().startsWith("<html>")); - - page = ((TracXmlRpcClient) repository).getWikiPage("TestGetPage", 1, null); - assertEquals("TestGetPage", page.getPageInfo().getPageName()); - assertEquals("anonymous", page.getPageInfo().getAuthor()); - assertEquals(1, page.getPageInfo().getVersion()); - assertEquals("Version 1", page.getContent()); - 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, null); - fail("Expected TracRemoteException"); - } catch (TracRemoteException e) { - } - - // get info -- non-existing page name - try { - ((TracXmlRpcClient) repository).getWikiPageInfo("NoSuchPage", null); - fail("Expected TracRemoteException"); - } catch (TracRemoteException e) { - } - - // get info -- null parameter - try { - ((TracXmlRpcClient) repository).getWikiPageInfo(null, null); - fail("Expected RuntimeException"); - } catch (IllegalArgumentException e) { - } - - // get content -- non-existing version - try { - ((TracXmlRpcClient) repository).getWikiPageContent("Test", 10, null); - fail("Expected TracRemoteException"); - } catch (TracRemoteException e) { - } - - // get content -- non-existing page name - try { - ((TracXmlRpcClient) repository).getWikiPageContent("NoSuchPage", null); - fail("Expected TracRemoteException"); - } catch (TracRemoteException e) { - } - - // get content -- null parameter - try { - ((TracXmlRpcClient) repository).getWikiPageContent(null, null); - fail("Expected RuntimeException"); - } catch (IllegalArgumentException e) { - } - - // get HTML -- non-existing version - try { - ((TracXmlRpcClient) repository).getWikiPageHtml("Test", 10, null); - fail("Expected TracRemoteException"); - } catch (TracRemoteException e) { - } - - // get HTML -- non-existing page name - try { - ((TracXmlRpcClient) repository).getWikiPageHtml("NoSuchPage", null); - fail("Expected TracRemoteException"); - } catch (TracRemoteException e) { - } - - // get HTML -- null parameter - try { - ((TracXmlRpcClient) repository).getWikiPageHtml(null, null); - fail("Expected RuntimeException"); - } catch (IllegalArgumentException e) { - } - - // get a page -- non-existing version - try { - ((TracXmlRpcClient) repository).getWikiPage("Test", 10, null); - fail("Expected TracRemoteException"); - } catch (TracRemoteException e) { - } - - // get a page -- non-existing page name - try { - ((TracXmlRpcClient) repository).getWikiPage("NoSuchPage", null); - fail("Expected TracRemoteException"); - } catch (TracRemoteException e) { - } - - // get a page -- null parameter - try { - ((TracXmlRpcClient) repository).getWikiPage(null, null); - fail("Expected RuntimeException"); - } catch (IllegalArgumentException e) { - } - - // get all versions of a page -- non-existing page name - try { - ((TracXmlRpcClient) repository).getWikiPageInfoAllVersions("NoSuchPage", null); - fail("Expected TracRemoteException"); - } catch (TracRemoteException e) { - } - - // get all versions of a page -- null parameter - try { - ((TracXmlRpcClient) repository).getWikiPageInfoAllVersions(null, 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"; - - TracWikiPageInfo[] versions = ((TracXmlRpcClient) repository).getWikiPageInfoAllVersions(pageName, null); - assertTrue(versions.length >= 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 { - TracWikiPageInfo[] changes = ((TracXmlRpcClient) repository).getRecentWikiChanges(new Date(0), null); - TracWikiPageInfo testPage = null; - for (TracWikiPageInfo item : changes) { - assertTrue(item.getPageName() != null); - if (item.getPageName().equals("Test")) { - testPage = item; - } - } - assertTrue(testPage != null); - } - - public void testPutWikiPage010() throws Exception { - connect010(); - putWikiPage(); - } - - public void testPutWikiPage011() throws Exception { - connect011(); - putWikiPage(); - } - - private void putWikiPage() throws Exception { - // TODO testing wiki.putPage() - } -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcTest.java deleted file mode 100644 index 160e6c2ad..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/client/TracXmlRpcTest.java +++ /dev/null @@ -1,509 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.client; - -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Date; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import junit.framework.TestCase; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.xmlrpc.XmlRpcException; -import org.apache.xmlrpc.client.XmlRpcClient; -import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; -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.util.TracHttpClientTransportFactory; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; - -/** - * Test cases for <a href="http://trac-hacks.org/wiki/XmlRpcPlugin">Trac XML-RPC Plugin</a> (revision 1188 or higher is - * required). - * - * <p> - * This class does not depend on any Mylyn (connector) classes except for TracHttpClientTransportFactory which is needed - * for initialization of HttpClient. - * - * @author Steffen Pingel - */ -public class TracXmlRpcTest extends TestCase { - - public static final String XMLRPC_URL = "/login/xmlrpc"; - - private XmlRpcClient xmlrpc; - - private String username; - - // private String password; - - private Random random; - - private ArrayList<Integer> tickets; - - @Override - protected void setUp() throws Exception { - super.setUp(); - - random = new Random(); - - Credentials credentials = TestUtil.readCredentials(PrivilegeLevel.ADMIN); - createConnection(new URL(TracTestConstants.TEST_TRAC_010_URL + XMLRPC_URL), credentials.username, - credentials.password); - - tickets = new ArrayList<Integer>(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - - for (int id : tickets) { - call("ticket.delete", id); - } - } - - private void createConnection(URL url, String username, String password) throws Exception { - XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); - config.setEncoding("UTF-8"); - config.setBasicUserName(username); - config.setBasicPassword(password); - config.setServerURL(url); - - xmlrpc = new XmlRpcClient(); - xmlrpc.setConfig(config); - - TracHttpClientTransportFactory factory = new TracHttpClientTransportFactory(xmlrpc, new HttpClient()); - xmlrpc.setTransportFactory(factory); - - this.username = username; - // this.password = password; - } - - private int createTicket(String summary, String description, Map<String, Object> attributes) - throws XmlRpcException, IOException { - int id = (Integer) call("ticket.create", summary, description, attributes); - tickets.add(id); - return id; - } - - private Object call(String method, Object... parameters) throws XmlRpcException, IOException { - Object result = xmlrpc.execute(method, parameters); - if (result instanceof XmlRpcException) { - throw (XmlRpcException) result; - } - return result; - } - - public Map<String, Object> createMultiCall(String methodName, Object... parameters) throws XmlRpcException, - IOException { - Map<String, Object> table = new Hashtable<String, Object>(); - table.put("methodName", methodName); - table.put("params", parameters); - return table; - } - - private void internalTestCrud(String module) throws XmlRpcException, IOException { - try { - call(module + ".delete", "foo"); - } catch (XmlRpcException e) { - } - - call(module + ".create", "foo", "bar"); - try { - assertHasValue((Object[]) call(module + ".getAll"), "foo"); - assertEquals("bar", (String) (call(module + ".get", "foo"))); - - call(module + ".update", "foo", "baz"); - assertEquals("baz", (String) (call(module + ".get", "foo"))); - } finally { - call(module + ".delete", "foo"); - } - } - - private Object createValue(Object fieldName, Object clazz) { - if (clazz == String.class) { - return fieldName.toString() + random.nextInt(); - } else if (clazz == Date.class) { - return new Date(); - } else if (clazz == Boolean.class) { - return random.nextBoolean(); - } else if (clazz == Double.class) { - return random.nextDouble(); - } else if (clazz == Integer.class) { - return random.nextInt(); - } - - throw new RuntimeException("Invalid test data: " + fieldName + ", " + clazz); - } - - private void internalTestComponent(String module, Object... fields) throws XmlRpcException, IOException { - try { - call(module + ".delete", "foo"); - } catch (XmlRpcException e) { - } - - Map<String, Object> attributes = new Hashtable<String, Object>(); - for (int i = 0; i < fields.length; i += 2) { - attributes.put((String) fields[i], createValue(fields[i], fields[i + 1])); - } - - call(module + ".create", "foo", attributes); - - try { - assertHasValue((Object[]) call(module + ".getAll"), "foo"); - Map<?, ?> values = (Map<?, ?>) call(module + ".get", "foo"); - for (String attribute : attributes.keySet()) { - assertEquals(attributes.get(attribute), values.get(attribute)); - } - - for (int i = 0; i < fields.length; i += 2) { - attributes.put((String) fields[i], createValue(fields[i], fields[i + 1])); - } - - call(module + ".update", "foo", attributes); - values = (Map<?, ?>) call(module + ".get", "foo"); - for (String attribute : attributes.keySet()) { - assertEquals(attributes.get(attribute), values.get(attribute)); - } - } finally { - call(module + ".delete", "foo"); - } - } - - public void testMilestoneDate() throws XmlRpcException, IOException { - try { - call("ticket.milestone.delete", "foo"); - } catch (XmlRpcException e) { - } - - int due = (int) (System.currentTimeMillis() / 1000) + 1000; - int completed = (int) (System.currentTimeMillis() / 1000); - - Map<String, Object> attributes = new Hashtable<String, Object>(); - attributes.put("description", "description"); - attributes.put("due", due); - attributes.put("completed", completed); - - call("ticket.milestone.create", "foo", attributes); - - Map<?, ?> values = (Map<?, ?>) call("ticket.milestone.get", "foo"); - assertEquals(new Integer(due), values.get("due")); - assertEquals(new Integer(completed), values.get("completed")); - - call("ticket.milestone.delete", "foo"); - } - - private void assertHasValue(Object[] items, Object value) { - for (Object item : items) { - if (item.equals(value)) { - return; - } - } - fail("Could not find expected value: " + value); - } - - private void assertTicketHasAttributes(Map<String, Object> attributes, int id, Object[] ticket) { - assertTicketHasAttributes(attributes, id, ticket, true); - } - - private void assertTicketHasAttributes(Map<String, Object> attributes, int id, Object[] ticket, boolean newTicket) { - assertEquals(id, ticket[0]); - assertTrue(ticket[1] instanceof Integer); // time created - // time changed - if (newTicket) { - assertEquals(ticket[1], ticket[2]); - } else { - assertTrue((Integer) ticket[2] >= (Integer) ticket[1]); - } - Map<?, ?> values = (Map<?, ?>) ticket[3]; - for (String attribute : attributes.keySet()) { - assertEquals(attributes.get(attribute), values.get(attribute)); - } - } - - public void testGetTicket() throws XmlRpcException, IOException { - Map<String, Object> attributes = new Hashtable<String, Object>(); - attributes.put("type", "task"); - attributes.put("status", "closed"); - int id = createTicket("summary", "description", attributes); - - attributes.put("summary", "summary"); - attributes.put("description", "description"); - - Object[] ticket = (Object[]) call("ticket.get", id); - assertTicketHasAttributes(attributes, id, ticket); - } - - public void testGetTicketNonExistant() throws XmlRpcException, IOException { - try { - call("ticket.delete", Integer.MAX_VALUE); - } catch (Exception e) { - // ignore - } - - try { - List<?> ticket = (List<?>) call("ticket.get", Integer.MAX_VALUE); - fail("Expected XmlRpcException, got ticket instead: " + ticket); - } catch (XmlRpcException e) { - // ignore - } - } - - public void testGetTicketUmlaute() throws XmlRpcException, IOException { - Map<String, Object> attributes = new Hashtable<String, Object>(); - int id = createTicket("summarya\u0308O\u030b", "\u00d8", attributes); - - attributes.put("summary", "summarya\u0308O\u030b"); - attributes.put("description", "\u00d8"); - - Object[] ticket = (Object[]) call("ticket.get", id); - assertTicketHasAttributes(attributes, id, ticket); - } - - public void testUpdateTicket() throws XmlRpcException, IOException { - int id = createTicket("summary", "description", new Hashtable<String, Object>()); - - Map<String, Object> attributes = new Hashtable<String, Object>(); - attributes.put("summary", "changed"); - call("ticket.update", id, "my comment", attributes); - - attributes.put("description", "description"); - - Object[] ticket = (Object[]) call("ticket.get", id); - Map<?, ?> values = (Map<?, ?>) ticket[3]; - for (String attribute : attributes.keySet()) { - assertEquals(attributes.get(attribute), values.get(attribute)); - } - } - - public void testTicketCustomFields() throws XmlRpcException, IOException { - Map<String, Object> attributes = new Hashtable<String, Object>(); - attributes.put("custom_text_field", "myvalue"); - int id = createTicket("summary", "description", attributes); - - // check for default values - attributes.put("custom_checkbox_field", "1"); - attributes.put("custom_select_field", "two"); - attributes.put("custom_radio_field", "baz"); - attributes.put("custom_textarea_field", "default text"); - - Object[] ticket = (Object[]) call("ticket.get", id); - assertTicketHasAttributes(attributes, id, ticket); - - attributes.put("custom_text_field", "myvalue2"); - attributes.put("custom_checkbox_field", "0"); - attributes.put("custom_select_field", "one"); - attributes.put("custom_radio_field", "foo"); - attributes.put("custom_textarea_field", "mytext"); - - call("ticket.update", id, "my comment", attributes); - - ticket = (Object[]) call("ticket.get", id); - assertTicketHasAttributes(attributes, id, ticket, false); - } - - public void testGetChangeLog() throws XmlRpcException, IOException { - int id = createTicket("summary", "description", new Hashtable<String, Object>()); - - Map<String, Object> attributes = new Hashtable<String, Object>(); - attributes.put("summary", "changed"); - call("ticket.update", id, "my comment", attributes); - - Object[] log = (Object[]) call("ticket.changeLog", id, 0); - Object[] entry = (Object[]) log[0]; - assertTrue(entry[0] instanceof Integer); // time - assertEquals(username, entry[1]); // author - assertEquals("summary", entry[2]); // field - assertEquals("summary", entry[3]); // old value - assertEquals("changed", entry[4]); // new value - } - - public void testMultiGetTicket() throws XmlRpcException, IOException { - int id1 = createTicket("summary1", "description1", new Hashtable<String, Object>()); - int id2 = createTicket("summary2", "description2", new Hashtable<String, Object>()); - - List<Map<?, ?>> calls = new ArrayList<Map<?, ?>>(); - calls.add(createMultiCall("ticket.get", id1)); - calls.add(createMultiCall("ticket.get", id2)); - Object[] ret = (Object[]) call("system.multicall", calls); - - Object[] ticket = (Object[]) ((Object[]) ret[0])[0]; - Map<String, Object> attributes = new Hashtable<String, Object>(); - attributes.put("summary", "summary1"); - attributes.put("description", "description1"); - assertTicketHasAttributes(attributes, id1, ticket); - - ticket = (Object[]) ((Object[]) ret[1])[0]; - attributes.clear(); - attributes.put("summary", "summary2"); - attributes.put("description", "description2"); - assertTicketHasAttributes(attributes, id2, ticket); - } - - public void testAttachment() throws XmlRpcException, IOException { - int id = createTicket("summary", "description", new Hashtable<String, Object>()); - - String filename = (String) call("ticket.putAttachment", id, "attach.txt", "description", "data".getBytes(), - true); - // the returned filename may differ, since another ticket may have an - // attachment named "attach.txt" - // assertEquals("attach.txt", filename); - - Object[] ret = (Object[]) call("ticket.listAttachments", id); - assertEquals(1, ret.length); - Object[] attachment = (Object[]) ret[0]; - assertEquals("attach.txt", attachment[0]); - assertEquals("description", attachment[1]); - assertEquals(4, attachment[2]); - // date - assertEquals(username, attachment[4]); - - byte[] bytes = (byte[]) call("ticket.getAttachment", id, filename); - String data = new String(bytes); - assertEquals("data", data); - - // test override - - String filename2 = (String) call("ticket.putAttachment", id, filename, "newdescription", "newdata".getBytes(), - true); - assertEquals(filename, filename2); - ret = (Object[]) call("ticket.listAttachments", id); - assertEquals(1, ret.length); - attachment = (Object[]) ret[0]; - assertEquals("attach.txt", attachment[0]); - assertEquals("newdescription", attachment[1]); - assertEquals(7, attachment[2]); - // date - assertEquals(username, attachment[4]); - bytes = (byte[]) call("ticket.getAttachment", id, filename); - data = new String(bytes); - assertEquals("newdata", data); - - String filename3 = (String) call("ticket.putAttachment", id, "attach.txt", "description", "data".getBytes(), - false); - assertFalse("attach.txt".equals(filename3)); - ret = (Object[]) call("ticket.listAttachments", id); - assertEquals(2, ret.length); - } - - public void testDeleteAttachment() throws XmlRpcException, IOException { - int id = createTicket("summary", "description", new Hashtable<String, Object>()); - - String filename = (String) call("ticket.putAttachment", id, "attach.txt", "description", "data".getBytes(), - true); - - Object[] ret = (Object[]) call("ticket.listAttachments", id); - assertEquals(1, ret.length); - - call("ticket.deleteAttachment", id, filename); - - ret = (Object[]) call("ticket.listAttachments", id); - assertEquals(0, ret.length); - } - - public void testDuplicateAttachment() throws XmlRpcException, IOException { - int id1 = createTicket("summary", "description", new Hashtable<String, Object>()); - int id2 = createTicket("summary", "description", new Hashtable<String, Object>()); - - String filename1 = (String) call("ticket.putAttachment", id1, "attach.txt", "description", "data".getBytes(), - true); - String filename2 = (String) call("ticket.putAttachment", id2, "attach.txt", "description", "data2".getBytes(), - true); - assertEquals("attach.txt", filename1); - assertEquals(filename1, filename2); - - byte[] bytes = (byte[]) call("ticket.getAttachment", id1, "attach.txt"); - String data = new String(bytes); - assertEquals("data", data); - - bytes = (byte[]) call("ticket.getAttachment", id2, "attach.txt"); - data = new String(bytes); - assertEquals("data2", data); - } - - public void testQuery() throws XmlRpcException, IOException { - Object[] ret = (Object[]) call("ticket.query", "summary~=foo|bar|baz"); - for (Object id : ret) { - call("ticket.delete", (Integer) id); - } - - int id1 = createTicket("foobarsum1", "description", new Hashtable<String, Object>()); - int id2 = createTicket("foobaz sum2", "description", new Hashtable<String, Object>()); - int id3 = createTicket("foobarbaz3", "foobarbaz description3", new Hashtable<String, Object>()); - - ret = (Object[]) call("ticket.query", "summary=foobarsum1|foobaz sum2"); - assertEquals(2, ret.length); - assertEquals(id1, ret[0]); - assertEquals(id2, ret[1]); - - // the first criterium is ignored - ret = (Object[]) call("ticket.query", "summary~=foobarsum1&summary~=foobaz sum2"); - assertEquals(1, ret.length); - assertEquals(id2, ret[0]); - - ret = (Object[]) call("ticket.query", "summary~=bar|baz"); - assertEquals(3, ret.length); - - ret = (Object[]) call("ticket.query", "description~=foobarbaz description3"); - assertEquals(1, ret.length); - assertEquals(id3, ret[0]); - } - - public void testQueryAll() throws XmlRpcException, IOException { - int id = createTicket("foo", "description", new Hashtable<String, Object>()); - - Object[] ret = (Object[]) call("ticket.query", "order=id"); - assertTrue(ret.length > 0); - assertHasValue(ret, id); - } - - public void testPriorities() throws XmlRpcException, IOException { - internalTestCrud("ticket.priority"); - } - - public void testSeverities() throws XmlRpcException, IOException { - internalTestCrud("ticket.severity"); - } - - public void testType() throws XmlRpcException, IOException { - internalTestCrud("ticket.type"); - } - - public void testStatus() throws XmlRpcException, IOException { - internalTestCrud("ticket.status"); - } - - public void testResolutions() throws XmlRpcException, IOException { - internalTestCrud("ticket.resolution"); - } - - public void testVersions() throws XmlRpcException, IOException { - internalTestComponent("ticket.version", "time", Integer.class, "description", String.class); - } - - public void testComponents() throws XmlRpcException, IOException { - internalTestComponent("ticket.component", "owner", String.class, "description", String.class); - } - - public void testMilestones() throws XmlRpcException, IOException { - internalTestComponent("ticket.milestone", "due", Integer.class, "completed", Integer.class, "description", - String.class); - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/RepositorySearchTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/RepositorySearchTest.java deleted file mode 100644 index 8412b899d..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/RepositorySearchTest.java +++ /dev/null @@ -1,90 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.core; - -import junit.framework.TestCase; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.mylyn.commons.net.AuthenticationCredentials; -import org.eclipse.mylyn.commons.net.AuthenticationType; -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.tasks.core.TaskRepositoryManager; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.mylyn.internal.tasks.ui.search.RepositorySearchResult; -import org.eclipse.mylyn.internal.tasks.ui.search.SearchHitCollector; -import org.eclipse.mylyn.internal.trac.core.TracCorePlugin; -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.TracSearch; -import org.eclipse.mylyn.tasks.core.IRepositoryQuery; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.trac.tests.support.TestFixture; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; -import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.TestData; - -/** - * @author Steffen Pingel - */ -public class RepositorySearchTest extends TestCase { - - private TestData data; - - private TaskRepositoryManager manager; - - private TaskRepository repository; - - public RepositorySearchTest() { - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - data = TestFixture.init010(); - manager = TasksUiPlugin.getRepositoryManager(); - manager.clearRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath()); - } - - protected void init(String url, Version version) { - Credentials credentials = TestUtil.readCredentials(PrivilegeLevel.USER); - - repository = new TaskRepository(TracCorePlugin.CONNECTOR_KIND, url); - repository.setCredentials(AuthenticationType.REPOSITORY, new AuthenticationCredentials(credentials.username, - credentials.password), false); - repository.setTimeZoneId(ITracClient.TIME_ZONE); - repository.setCharacterEncoding(ITracClient.CHARSET); - repository.setVersion(version.name()); - - manager.addRepository(repository); - } - - public void testSearch() { - init(TracTestConstants.TEST_TRAC_096_URL, Version.TRAC_0_9); - - TracSearch search = new TracSearch(); - String queryUrl = repository.getRepositoryUrl() + ITracClient.QUERY_URL + search.toUrl(); - IRepositoryQuery query = TasksUi.getRepositoryModel().createRepositoryQuery(repository); - query.setUrl(queryUrl); - SearchHitCollector collector = new SearchHitCollector(TasksUiPlugin.getTaskList(), repository, query); - collector.run(new NullProgressMonitor()); - RepositorySearchResult searchResult = (RepositorySearchResult) collector.getSearchResult(); - assertEquals(data.tickets.size(), searchResult.getMatchCount()); - for (Object match : searchResult.getElements()) { - ITask task = (ITask) match; - assertEquals(TracTestConstants.TEST_TRAC_096_URL, task.getRepositoryUrl()); - } - } -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracAttachmentHandlerTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracAttachmentHandlerTest.java deleted file mode 100644 index 5e5888cf3..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracAttachmentHandlerTest.java +++ /dev/null @@ -1,165 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.core; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.mylyn.internal.tasks.core.data.FileTaskAttachmentSource; -import org.eclipse.mylyn.internal.trac.core.TracCorePlugin; -import org.eclipse.mylyn.internal.trac.core.TracRepositoryConnector; -import org.eclipse.mylyn.internal.trac.core.client.ITracClient; -import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.ITaskAttachment; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentHandler; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.trac.tests.support.TestFixture; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; -import org.eclipse.mylyn.trac.tests.support.TracTestUtil; -import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.TestData; - -/** - * @author Steffen Pingel - */ -public class TracAttachmentHandlerTest extends TestCase { - - private TaskRepository repository; - - private TracRepositoryConnector connector; - - private AbstractTaskAttachmentHandler attachmentHandler; - - private TestData data; - - @Override - protected void setUp() throws Exception { - super.setUp(); - data = TestFixture.init010(); - connector = (TracRepositoryConnector) TasksUi.getRepositoryConnector(TracCorePlugin.CONNECTOR_KIND); - attachmentHandler = connector.getTaskAttachmentHandler(); - } - - protected void init(String url, Version version) { - repository = TracTestUtil.init(url, version); - } - - public void testDownloadAttachmentXmlRpc010() throws Exception { - downloadAttachmentXmlRpc(TracTestConstants.TEST_TRAC_010_URL); - } - - public void testDownloadAttachmentXmlRpc011() throws Exception { - downloadAttachmentXmlRpc(TracTestConstants.TEST_TRAC_011_URL); - } - - private void downloadAttachmentXmlRpc(String url) throws Exception { - init(url, Version.XML_RPC); - ITask task = TracTestUtil.createTask(repository, data.attachmentTicketId + ""); - List<ITaskAttachment> attachments = TracTestUtil.getTaskAttachments(task); - assertTrue(attachments.size() > 0); - InputStream in = attachmentHandler.getContent(repository, task, attachments.get(0).getTaskAttribute(), null); - try { - byte[] result = new byte[6]; - in.read(result); - assertEquals("Mylar\n", new String(result)); - assertEquals(-1, in.read()); - } finally { - in.close(); - } - } - - public void testGetAttachmentDataXmlRpc010() throws Exception { - getAttachmentDataXmlRpc(TracTestConstants.TEST_TRAC_010_URL); - } - - public void testGetAttachmentDataXmlRpc011() throws Exception { - getAttachmentDataXmlRpc(TracTestConstants.TEST_TRAC_011_URL); - } - - private void getAttachmentDataXmlRpc(String url) throws Exception { - init(url, Version.XML_RPC); - ITask task = TracTestUtil.createTask(repository, data.attachmentTicketId + ""); - List<ITaskAttachment> attachments = TracTestUtil.getTaskAttachments(task); - assertTrue(attachments.size() > 0); - InputStream in = attachmentHandler.getContent(repository, task, attachments.get(0).getTaskAttribute(), null); - byte[] result = new byte[6]; - try { - in.read(result); - } finally { - in.close(); - } - assertEquals("Mylar\n", new String(result)); - } - - public void testUploadAttachmentXmlRpc010() throws Exception { - uploadAttachmentXmlRpc(TracTestConstants.TEST_TRAC_010_URL); - } - - public void testUploadAttachmentXmlRpc011() throws Exception { - uploadAttachmentXmlRpc(TracTestConstants.TEST_TRAC_011_URL); - } - - private void uploadAttachmentXmlRpc(String url) throws Exception { - init(url, Version.XML_RPC); - ITask task = TracTestUtil.createTask(repository, data.attachmentTicketId + ""); - File file = File.createTempFile("attachment", null); - file.deleteOnExit(); - OutputStream out = new FileOutputStream(file); - try { - out.write("Mylar".getBytes()); - } finally { - out.close(); - } - attachmentHandler.postContent(repository, task, new FileTaskAttachmentSource(file), "comment", null, null); - - ITracClient client = connector.getClientManager().getTracClient(repository); - InputStream in = client.getAttachmentData(data.attachmentTicketId, file.getName(), null); - try { - byte[] result = new byte[5]; - in.read(result); - assertEquals("Mylar", new String(result)); - } finally { - in.close(); - } - } - - public void testCanUploadAttachmentXmlRpc() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - ITask task = TracTestUtil.createTask(repository, data.attachmentTicketId + ""); - assertTrue(attachmentHandler.canPostContent(repository, task)); - } - - public void testCanUploadAttachmentWeb() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.TRAC_0_9); - ITask task = TracTestUtil.createTask(repository, data.attachmentTicketId + ""); - assertFalse(attachmentHandler.canPostContent(repository, task)); - } - - public void testCanDownloadAttachmentXmlRpc() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - ITask task = TracTestUtil.createTask(repository, data.attachmentTicketId + ""); - assertTrue(attachmentHandler.canGetContent(repository, task)); - } - - public void testCanDownloadAttachmentWeb() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.TRAC_0_9); - ITask task = TracTestUtil.createTask(repository, data.attachmentTicketId + ""); - assertFalse(attachmentHandler.canGetContent(repository, task)); - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracClientManagerTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracClientManagerTest.java deleted file mode 100644 index 0b4368528..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracClientManagerTest.java +++ /dev/null @@ -1,83 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.core; - -import java.io.File; -import java.util.Arrays; - -import junit.framework.TestCase; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.mylyn.commons.net.AuthenticationType; -import org.eclipse.mylyn.internal.trac.core.TracClientManager; -import org.eclipse.mylyn.internal.trac.core.TracCorePlugin; -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.TracMilestone; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.TaskRepositoryLocationFactory; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; - -/** - * @author Steffen Pingel - */ -public class TracClientManagerTest extends TestCase { - - public void testNullCache() throws Exception { - TaskRepository taskRepository = new TaskRepository(TracCorePlugin.CONNECTOR_KIND, - TracTestConstants.TEST_TRAC_096_URL); - taskRepository.setVersion(Version.TRAC_0_9.name()); - - TracClientManager manager = new TracClientManager(null, new TaskRepositoryLocationFactory()); - ITracClient client = manager.getTracClient(taskRepository); - assertNull(client.getMilestones()); - - manager.writeCache(); - assertNull(client.getMilestones()); - } - - public void testReadCache() throws Exception { - TaskRepository taskRepository = new TaskRepository(TracCorePlugin.CONNECTOR_KIND, - TracTestConstants.TEST_TRAC_096_URL); - taskRepository.setVersion(Version.TRAC_0_9.name()); - - File file = File.createTempFile("mylyn", null); - file.deleteOnExit(); - - TracClientManager manager = new TracClientManager(file, new TaskRepositoryLocationFactory()); - ITracClient client = manager.getTracClient(taskRepository); - assertNull(client.getMilestones()); - } - - public void testWriteCache() throws Exception { - TaskRepository taskRepository = new TaskRepository(TracCorePlugin.CONNECTOR_KIND, - TracTestConstants.TEST_TRAC_096_URL); - taskRepository.setVersion(Version.TRAC_0_9.name()); - taskRepository.setCredentials(AuthenticationType.REPOSITORY, null, false); - - File file = File.createTempFile("mylyn", null); - file.deleteOnExit(); - - TracClientManager manager = new TracClientManager(file, new TaskRepositoryLocationFactory()); - ITracClient client = manager.getTracClient(taskRepository); - assertNull(client.getMilestones()); - - client.updateAttributes(new NullProgressMonitor(), false); - assertTrue(client.getMilestones().length > 0); - TracMilestone[] milestones = client.getMilestones(); - - manager.writeCache(); - manager = new TracClientManager(file, new TaskRepositoryLocationFactory()); - assertEquals(Arrays.asList(milestones), Arrays.asList(client.getMilestones())); - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracRepositoryConnectorTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracRepositoryConnectorTest.java deleted file mode 100644 index e129d717b..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracRepositoryConnectorTest.java +++ /dev/null @@ -1,384 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.core; - -import java.io.File; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.Date; -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.NullProgressMonitor; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.mylyn.internal.context.core.ContextCorePlugin; -import org.eclipse.mylyn.internal.tasks.core.AbstractTask; -import org.eclipse.mylyn.internal.tasks.core.TaskTask; -import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil; -import org.eclipse.mylyn.internal.tasks.ui.wizards.EditRepositoryWizard; -import org.eclipse.mylyn.internal.trac.core.TracCorePlugin; -import org.eclipse.mylyn.internal.trac.core.TracRepositoryConnector; -import org.eclipse.mylyn.internal.trac.core.TracTaskDataHandler; -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.TracPriority; -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.internal.trac.ui.wizard.TracRepositorySettingsPage; -import org.eclipse.mylyn.tasks.core.IRepositoryQuery; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.ITaskAttachment; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.data.TaskData; -import org.eclipse.mylyn.tasks.core.data.TaskDataCollector; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.trac.tests.support.TestFixture; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; -import org.eclipse.mylyn.trac.tests.support.TracTestUtil; -import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.TestData; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; - -/** - * @author Steffen Pingel - */ -public class TracRepositoryConnectorTest extends TestCase { - - private TestData data; - - private TaskRepository repository; - - private TracRepositoryConnector connector; - - @Override - protected void setUp() throws Exception { - super.setUp(); - data = TestFixture.init010(); - connector = (TracRepositoryConnector) TasksUi.getRepositoryConnector(TracCorePlugin.CONNECTOR_KIND); - } - - protected void init(String url, Version version) { - repository = TracTestUtil.init(url, version); - } - - public void testGetRepositoryUrlFromTaskUrl() { - assertEquals("http://host/repo", connector.getRepositoryUrlFromTaskUrl("http://host/repo/ticket/1")); - assertEquals("http://host", connector.getRepositoryUrlFromTaskUrl("http://host/ticket/2342")); - assertEquals(null, connector.getRepositoryUrlFromTaskUrl("http://host/repo/2342")); - assertEquals(null, connector.getRepositoryUrlFromTaskUrl("http://host/repo/ticket-2342")); - } - - public void testCreateTaskFromExistingKeyXmlRpc011() throws CoreException { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - createTaskFromExistingKey(); - } - - public void testCreateTaskFromExistingKeyXmlRpc010() throws CoreException { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - createTaskFromExistingKey(); - } - - public void testCreateTaskFromExistingKeyTracWeb011() throws CoreException { - init(TracTestConstants.TEST_TRAC_010_URL, Version.TRAC_0_9); - createTaskFromExistingKey(); - } - - public void testCreateTaskFromExistingKeyTracWeb010() throws CoreException { - init(TracTestConstants.TEST_TRAC_010_URL, Version.TRAC_0_9); - createTaskFromExistingKey(); - } - - public void testCreateTaskFromExistingKeyTracWeb096() throws CoreException { - init(TracTestConstants.TEST_TRAC_096_URL, Version.TRAC_0_9); - createTaskFromExistingKey(); - } - - protected void createTaskFromExistingKey() throws CoreException { - String taskId = data.tickets.get(0).getId() + ""; - TaskData taskData = connector.getTaskData(repository, taskId, null); - ITask task = TasksUi.getRepositoryModel().createTask(repository, taskData.getTaskId()); - assertNotNull(task); - connector.updateTaskFromTaskData(repository, task, taskData); - assertEquals(TaskTask.class, task.getClass()); - assertTrue(task.getSummary().contains("summary1")); - assertEquals(repository.getRepositoryUrl() + ITracClient.TICKET_URL + taskId, task.getUrl()); - } - - public void testClientManagerChangeTaskRepositorySettings() throws MalformedURLException { - init(TracTestConstants.TEST_TRAC_010_URL, Version.TRAC_0_9); - ITracClient client = connector.getClientManager().getTracClient(repository); - assertEquals(Version.TRAC_0_9, client.getVersion()); - - EditRepositoryWizard wizard = new EditRepositoryWizard(repository); - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - WizardDialog dialog = new WizardDialog(shell, wizard); - try { - dialog.create(); - - ((TracRepositorySettingsPage) wizard.getSettingsPage()).setTracVersion(Version.XML_RPC); - assertTrue(wizard.performFinish()); - - client = connector.getClientManager().getTracClient(repository); - assertEquals(Version.XML_RPC, client.getVersion()); - } finally { - dialog.close(); - } - } - - public void testPerformQueryXmlRpc011() { - performQuery(TracTestConstants.TEST_TRAC_011_URL, Version.XML_RPC); - } - - public void testPerformQueryXmlRpc010() { - performQuery(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - } - - public void testPerformQueryWeb011() { - performQuery(TracTestConstants.TEST_TRAC_010_URL, Version.TRAC_0_9); - } - - public void testPerformQueryWeb010() { - performQuery(TracTestConstants.TEST_TRAC_010_URL, Version.TRAC_0_9); - } - - public void testPerformQueryWeb096() { - performQuery(TracTestConstants.TEST_TRAC_096_URL, Version.TRAC_0_9); - } - - protected void performQuery(String url, Version version) { - init(url, version); - - TracSearch search = new TracSearch(); - search.addFilter("milestone", "milestone1"); - search.addFilter("milestone", "milestone2"); - search.setOrderBy("id"); - IRepositoryQuery query = TasksUi.getRepositoryModel().createRepositoryQuery(repository); - query.setUrl(url + ITracClient.QUERY_URL + search.toUrl()); - - final List<TaskData> result = new ArrayList<TaskData>(); - TaskDataCollector hitCollector = new TaskDataCollector() { - @Override - public void accept(TaskData hit) { - result.add(hit); - } - }; - IStatus queryStatus = connector.performQuery(repository, query, hitCollector, null, new NullProgressMonitor()); - assertTrue(queryStatus.isOK()); - assertEquals(3, result.size()); - assertEquals(data.tickets.get(0).getId() + "", result.get(0).getTaskId()); - assertEquals(data.tickets.get(1).getId() + "", result.get(1).getTaskId()); - assertEquals(data.tickets.get(2).getId() + "", result.get(2).getTaskId()); - } - - public void testUpdateAttributesWeb011() throws Exception { - init(TracTestConstants.TEST_TRAC_011_URL, Version.TRAC_0_9); - updateAttributes(); - } - - public void testUpdateAttributesWeb010() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.TRAC_0_9); - updateAttributes(); - } - - public void testUpdateAttributesWeb096() throws Exception { - init(TracTestConstants.TEST_TRAC_096_URL, Version.TRAC_0_9); - updateAttributes(); - } - - public void testUpdateAttributesXmlRpc011() throws Exception { - init(TracTestConstants.TEST_TRAC_011_URL, Version.XML_RPC); - updateAttributes(); - } - - public void testUpdateAttributesXmlRpc010() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - updateAttributes(); - } - - protected void updateAttributes() throws Exception { - connector.updateRepositoryConfiguration(repository, new NullProgressMonitor()); - - ITracClient server = connector.getClientManager().getTracClient(repository); - TracVersion[] versions = server.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 testContextXmlRpc010() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - String taskId = data.attachmentTicketId + ""; - ITask task = TracTestUtil.createTask(repository, taskId); - File sourceContextFile = ContextCorePlugin.getContextStore().getFileForContext(task.getHandleIdentifier()); - sourceContextFile.createNewFile(); - sourceContextFile.deleteOnExit(); - - boolean result = AttachmentUtil.postContext(connector, repository, task, "", null, null); - assertTrue(result); - - task = TracTestUtil.createTask(repository, taskId); - List<ITaskAttachment> attachments = TracTestUtil.getTaskAttachments(task); - // TODO attachment may have been overridden therefore size may not have changed - //assertEquals(size + 1, task.getTaskData().getAttachments().size()); - ITaskAttachment attachment = attachments.get(attachments.size() - 1); - result = AttachmentUtil.downloadContext(task, attachment, PlatformUI.getWorkbench().getProgressService()); - assertTrue(result); - assertTrue(task.isActive()); - } - - public void testContextWeb096() throws Exception { - init(TracTestConstants.TEST_TRAC_096_URL, Version.TRAC_0_9); - String taskId = data.attachmentTicketId + ""; - ITask task = TracTestUtil.createTask(repository, taskId); - File sourceContextFile = ContextCorePlugin.getContextStore().getFileForContext(task.getHandleIdentifier()); - sourceContextFile.createNewFile(); - sourceContextFile.deleteOnExit(); - - try { - AttachmentUtil.postContext(connector, repository, task, "", null, null); - fail("expected CoreException"); // operation should not be supported - } catch (CoreException e) { - } - } - - public void testIsCompleted() { - assertTrue(TracRepositoryConnector.isCompleted("closed")); - assertFalse(TracRepositoryConnector.isCompleted("Closed")); - assertFalse(TracRepositoryConnector.isCompleted("new")); - assertFalse(TracRepositoryConnector.isCompleted("assigned")); - assertFalse(TracRepositoryConnector.isCompleted("reopened")); - assertFalse(TracRepositoryConnector.isCompleted("foobar")); - assertFalse(TracRepositoryConnector.isCompleted("")); - assertFalse(TracRepositoryConnector.isCompleted(null)); - } - - public void testGetTaskPriority() { - assertEquals("P1", TracRepositoryConnector.getTaskPriority("blocker").toString()); - assertEquals("P2", TracRepositoryConnector.getTaskPriority("critical").toString()); - assertEquals("P3", TracRepositoryConnector.getTaskPriority("major").toString()); - assertEquals("P3", TracRepositoryConnector.getTaskPriority(null).toString()); - assertEquals("P3", TracRepositoryConnector.getTaskPriority("").toString()); - assertEquals("P3", TracRepositoryConnector.getTaskPriority("foo bar").toString()); - assertEquals("P4", TracRepositoryConnector.getTaskPriority("minor").toString()); - assertEquals("P5", TracRepositoryConnector.getTaskPriority("trivial").toString()); - } - - public void testGetTaskPriorityFromTracPriorities() { - TracPriority p1 = new TracPriority("a", 1); - TracPriority p2 = new TracPriority("b", 2); - TracPriority p3 = new TracPriority("c", 3); - TracPriority[] priorities = new TracPriority[] { p1, p2, p3 }; - assertEquals("P1", TracRepositoryConnector.getTaskPriority("a", priorities).toString()); - assertEquals("P3", TracRepositoryConnector.getTaskPriority("b", priorities).toString()); - assertEquals("P5", TracRepositoryConnector.getTaskPriority("c", priorities).toString()); - assertEquals("P3", TracRepositoryConnector.getTaskPriority("foo", priorities).toString()); - assertEquals("P3", TracRepositoryConnector.getTaskPriority(null, priorities).toString()); - - p1 = new TracPriority("a", 10); - priorities = new TracPriority[] { p1 }; - assertEquals("P1", TracRepositoryConnector.getTaskPriority("a", priorities).toString()); - assertEquals("P3", TracRepositoryConnector.getTaskPriority("b", priorities).toString()); - assertEquals("P3", TracRepositoryConnector.getTaskPriority(null, priorities).toString()); - - p1 = new TracPriority("1", 10); - p2 = new TracPriority("2", 20); - p3 = new TracPriority("3", 30); - TracPriority p4 = new TracPriority("4", 40); - TracPriority p5 = new TracPriority("5", 70); - TracPriority p6 = new TracPriority("6", 100); - priorities = new TracPriority[] { p1, p2, p3, p4, p5, p6 }; - assertEquals("P1", TracRepositoryConnector.getTaskPriority("1", priorities).toString()); - assertEquals("P1", TracRepositoryConnector.getTaskPriority("2", priorities).toString()); - assertEquals("P2", TracRepositoryConnector.getTaskPriority("3", priorities).toString()); - assertEquals("P2", TracRepositoryConnector.getTaskPriority("4", priorities).toString()); - assertEquals("P4", TracRepositoryConnector.getTaskPriority("5", priorities).toString()); - assertEquals("P5", TracRepositoryConnector.getTaskPriority("6", priorities).toString()); - } - - public void testUpdateTaskFromTaskData() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.TRAC_0_9); - - TracTicket ticket = new TracTicket(123); - ticket.putBuiltinValue(Key.DESCRIPTION, "mydescription"); - ticket.putBuiltinValue(Key.PRIORITY, "mypriority"); - ticket.putBuiltinValue(Key.SUMMARY, "mysummary"); - ticket.putBuiltinValue(Key.TYPE, "mytype"); - - TracTaskDataHandler taskDataHandler = connector.getTaskDataHandler(); - ITracClient client = connector.getClientManager().getTracClient(repository); - TaskData taskData = taskDataHandler.createTaskDataFromTicket(client, repository, ticket, null); - ITask task = TasksUi.getRepositoryModel().createTask(repository, taskData.getTaskId()); - - connector.updateTaskFromTaskData(repository, task, taskData); - assertEquals(TracTestConstants.TEST_TRAC_010_URL + ITracClient.TICKET_URL + "123", task.getUrl()); - assertEquals("123", task.getTaskKey()); - assertEquals("mysummary", task.getSummary()); - assertEquals("P3", task.getPriority()); - assertEquals("mytype", task.getTaskKind()); - } - - public void testUpdateTaskFromTaskDataSummaryOnly() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.TRAC_0_9); - - TracTicket ticket = new TracTicket(456); - ticket.putBuiltinValue(Key.SUMMARY, "mysummary"); - - TracTaskDataHandler taskDataHandler = connector.getTaskDataHandler(); - ITracClient client = connector.getClientManager().getTracClient(repository); - TaskData taskData = taskDataHandler.createTaskDataFromTicket(client, repository, ticket, null); - ITask task = TasksUi.getRepositoryModel().createTask(repository, taskData.getTaskId()); - - connector.updateTaskFromTaskData(repository, task, taskData); - assertEquals(TracTestConstants.TEST_TRAC_010_URL + ITracClient.TICKET_URL + "456", task.getUrl()); - assertEquals("456", task.getTaskKey()); - assertEquals("mysummary", task.getSummary()); - assertEquals("P3", task.getPriority()); - assertEquals(AbstractTask.DEFAULT_TASK_KIND, task.getTaskKind()); - } - - public void testUpdateTaskFromTaskDataClosed() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.TRAC_0_9); - TracTaskDataHandler taskDataHandler = connector.getTaskDataHandler(); - ITracClient client = connector.getClientManager().getTracClient(repository); - ITask task = TasksUi.getRepositoryModel().createTask(repository, "1"); - - TracTicket ticket = new TracTicket(123); - ticket.putBuiltinValue(Key.STATUS, "resolved"); - TaskData taskData = taskDataHandler.createTaskDataFromTicket(client, repository, ticket, null); - connector.updateTaskFromTaskData(repository, task, taskData); - assertEquals(null, task.getCompletionDate()); - - ticket.putBuiltinValue(Key.STATUS, "closed"); - taskData = taskDataHandler.createTaskDataFromTicket(client, repository, ticket, null); - connector.updateTaskFromTaskData(repository, task, taskData); - assertEquals(new Date(0), task.getCompletionDate()); - - ticket.putBuiltinValue(Key.STATUS, "closed"); - ticket.putBuiltinValue(Key.CHANGE_TIME, "123"); - taskData = taskDataHandler.createTaskDataFromTicket(client, repository, ticket, null); - connector.updateTaskFromTaskData(repository, task, taskData); - assertEquals(new Date(123 * 1000), task.getCompletionDate()); - } - -}
\ No newline at end of file diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracRepositoryQueryTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracRepositoryQueryTest.java deleted file mode 100644 index e361711c3..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracRepositoryQueryTest.java +++ /dev/null @@ -1,58 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.core; - -import junit.framework.TestCase; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery; -import org.eclipse.mylyn.internal.tasks.ui.RefactorRepositoryUrlOperation; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -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.TracSearch; -import org.eclipse.mylyn.tasks.core.IRepositoryQuery; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; -import org.eclipse.mylyn.trac.tests.support.TracTestUtil; - -/** - * @author Steffen Pingel - */ -public class TracRepositoryQueryTest extends TestCase { - - public void testChangeRepositoryUrl() throws Exception { - TaskRepository repository = TracTestUtil.init(TracTestConstants.TEST_TRAC_096_URL, Version.XML_RPC); - - TracSearch search = new TracSearch(); - String queryUrl = repository.getRepositoryUrl() + ITracClient.QUERY_URL + search.toUrl(); - IRepositoryQuery query = TasksUi.getRepositoryModel().createRepositoryQuery(repository); - query.setUrl(queryUrl); - TasksUiPlugin.getTaskList().addQuery((RepositoryQuery) query); - - String taskId = "123"; - ITask task = TasksUi.getRepositoryModel().createTask(repository, taskId); - task.setUrl(repository.getRepositoryUrl() + ITracClient.TICKET_URL + taskId); - TasksUiPlugin.getTaskList().addTask(task); - - String oldUrl = repository.getRepositoryUrl(); - String newUrl = TracTestConstants.TEST_TRAC_010_URL; - new RefactorRepositoryUrlOperation(oldUrl, newUrl).run(new NullProgressMonitor()); - repository.setRepositoryUrl(newUrl); - - assertEquals(newUrl, query.getRepositoryUrl()); - assertEquals(newUrl + ITracClient.QUERY_URL + search.toUrl(), query.getUrl()); - assertEquals(newUrl + ITracClient.TICKET_URL + taskId, task.getUrl()); - } -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracTaskDataHandlerTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracTaskDataHandlerTest.java deleted file mode 100644 index b75a03650..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracTaskDataHandlerTest.java +++ /dev/null @@ -1,406 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.core; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import junit.framework.TestCase; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.mylyn.commons.net.AuthenticationCredentials; -import org.eclipse.mylyn.commons.net.AuthenticationType; -import org.eclipse.mylyn.internal.tasks.core.TaskTask; -import org.eclipse.mylyn.internal.tasks.core.data.TextTaskAttachmentSource; -import org.eclipse.mylyn.internal.tasks.core.sync.SynchronizationSession; -import org.eclipse.mylyn.internal.trac.core.TracAttribute; -import org.eclipse.mylyn.internal.trac.core.TracAttributeMapper; -import org.eclipse.mylyn.internal.trac.core.TracCorePlugin; -import org.eclipse.mylyn.internal.trac.core.TracRepositoryConnector; -import org.eclipse.mylyn.internal.trac.core.TracTaskDataHandler; -import org.eclipse.mylyn.internal.trac.core.TracTaskMapper; -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.internal.trac.core.model.TracTicket.Key; -import org.eclipse.mylyn.internal.trac.core.util.TracUtil; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.ITaskAttachment; -import org.eclipse.mylyn.tasks.core.RepositoryStatus; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentHandler; -import org.eclipse.mylyn.tasks.core.data.TaskAttribute; -import org.eclipse.mylyn.tasks.core.data.TaskData; -import org.eclipse.mylyn.tasks.core.data.TaskMapper; -import org.eclipse.mylyn.tasks.core.data.TaskRelation; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.trac.tests.support.TestFixture; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; -import org.eclipse.mylyn.trac.tests.support.TracTestUtil; -import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.TestData; - -/** - * @author Steffen Pingel - */ -public class TracTaskDataHandlerTest extends TestCase { - - private TracRepositoryConnector connector; - - private TaskRepository repository; - - private TestData data; - - private TracTaskDataHandler taskDataHandler; - - private ITracClient client; - - public TracTaskDataHandlerTest() { - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - data = TestFixture.init010(); - connector = (TracRepositoryConnector) TasksUi.getRepositoryConnector(TracCorePlugin.CONNECTOR_KIND); - taskDataHandler = connector.getTaskDataHandler(); - } - - protected void init(String url, Version version) { - repository = TracTestUtil.init(url, version); - client = connector.getClientManager().getTracClient(repository); - } - - private SynchronizationSession createSession(ITask... tasks) { - SynchronizationSession session = new SynchronizationSession(); - session.setNeedsPerformQueries(true); - session.setTaskRepository(repository); - session.setFullSynchronization(true); - session.setTasks(new HashSet<ITask>(Arrays.asList(tasks))); - return session; - } - - public void testPreSynchronizationWeb096() throws Exception { - init(TracTestConstants.TEST_TRAC_096_URL, Version.TRAC_0_9); - ITask task = TracTestUtil.createTask(repository, data.offlineHandlerTicketId + ""); - - Set<ITask> tasks = new HashSet<ITask>(); - tasks.add(task); - SynchronizationSession session = createSession(); - session.setTasks(tasks); - - assertEquals(null, repository.getSynchronizationTimeStamp()); - connector.preSynchronization(session, null); - assertTrue(session.needsPerformQueries()); - assertEquals(null, repository.getSynchronizationTimeStamp()); - // bug 238043: assertEquals(Collections.emptySet(), session.getStaleTasks()); - assertEquals(null, session.getStaleTasks()); - - int time = (int) (System.currentTimeMillis() / 1000) + 1; - repository.setSynchronizationTimeStamp(time + ""); - connector.preSynchronization(session, null); - assertTrue(session.needsPerformQueries()); - // bug 238043: assertEquals(Collections.emptySet(), session.getStaleTasks()); - assertEquals(null, session.getStaleTasks()); - } - - public void testMarkStaleTasksXmlRpc010() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - markStaleTasks(); - } - - public void testMarkStaleTasksXmlRpc011() throws Exception { - init(TracTestConstants.TEST_TRAC_011_URL, Version.XML_RPC); - markStaleTasks(); - } - - private void markStaleTasks() throws Exception { - SynchronizationSession session; - TracTicket ticket = TracTestUtil.createTicket(client, "markStaleTasks"); - ITask task = TracTestUtil.createTask(repository, ticket.getId() + ""); - long lastModified = TracUtil.toTracTime(task.getModificationDate()); - - // an empty set should not cause contact to the repository - repository.setSynchronizationTimeStamp(null); - session = createSession(task); - connector.preSynchronization(session, null); - assertTrue(session.needsPerformQueries()); - assertNull(repository.getSynchronizationTimeStamp()); - - repository.setSynchronizationTimeStamp(null); - session = createSession(task); - connector.preSynchronization(session, null); - assertTrue(session.needsPerformQueries()); - assertEquals(Collections.singleton(task), session.getStaleTasks()); - - // always returns the ticket because time comparison mode is >= - repository.setSynchronizationTimeStamp(lastModified + ""); - session = createSession(task); - connector.preSynchronization(session, null); - // TODO this was fixed so it returns false now but only if the - // query returns a single task - assertFalse(session.needsPerformQueries()); - // bug 238043: assertEquals(Collections.emptySet(), session.getStaleTasks()); - assertEquals(null, session.getStaleTasks()); - - repository.setSynchronizationTimeStamp((lastModified + 1) + ""); - session = createSession(task); - connector.preSynchronization(session, null); - assertFalse(session.needsPerformQueries()); - // bug 238043: assertEquals(Collections.emptySet(), session.getStaleTasks()); - assertEquals(null, session.getStaleTasks()); - - // change ticket making sure it gets a new change time - Thread.sleep(1000); - ticket.putBuiltinValue(Key.DESCRIPTION, lastModified + ""); - client.updateTicket(ticket, "comment", null); - - repository.setSynchronizationTimeStamp((lastModified + 1) + ""); - session = createSession(task); - connector.preSynchronization(session, null); - assertTrue(session.needsPerformQueries()); - assertEquals(Collections.singleton(task), session.getStaleTasks()); - } - - public void testMarkStaleTasksNoTimeStampXmlRpc010() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - markStaleTasksNoTimeStamp(); - } - - public void testMarkStaleTasksNoTimeStampXmlRpc011() throws Exception { - init(TracTestConstants.TEST_TRAC_011_URL, Version.XML_RPC); - markStaleTasksNoTimeStamp(); - } - - private void markStaleTasksNoTimeStamp() throws Exception { - SynchronizationSession session; - ITask task = TracTestUtil.createTask(repository, data.offlineHandlerTicketId + ""); - - session = createSession(task); - repository.setSynchronizationTimeStamp(null); - connector.preSynchronization(session, null); - assertTrue(session.needsPerformQueries()); - assertEquals(Collections.singleton(task), session.getStaleTasks()); - - session = createSession(task); - repository.setSynchronizationTimeStamp(""); - connector.preSynchronization(session, null); - assertTrue(session.needsPerformQueries()); - assertEquals(Collections.singleton(task), session.getStaleTasks()); - - session = createSession(task); - repository.setSynchronizationTimeStamp("0"); - connector.preSynchronization(session, null); - assertTrue(session.needsPerformQueries()); - assertEquals(Collections.singleton(task), session.getStaleTasks()); - - session = createSession(task); - repository.setSynchronizationTimeStamp("abc"); - connector.preSynchronization(session, null); - assertTrue(session.needsPerformQueries()); - assertEquals(Collections.singleton(task), session.getStaleTasks()); - } - - public void testNonNumericTaskId() { - try { - connector.getTaskData(repository, "abc", null); - fail("Expected CoreException"); - } catch (CoreException e) { - } - } - - public void testAttachmentChangesLastModifiedDate010() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - attachmentChangesLastModifiedDate(); - } - - public void testAttachmentChangesLastModifiedDate011() throws Exception { - init(TracTestConstants.TEST_TRAC_011_URL, Version.XML_RPC); - attachmentChangesLastModifiedDate(); - } - - private void attachmentChangesLastModifiedDate() throws Exception { - AbstractTaskAttachmentHandler attachmentHandler = connector.getTaskAttachmentHandler(); - ITask task = TracTestUtil.createTask(repository, data.attachmentTicketId + ""); - Date lastModified = task.getModificationDate(); - // XXX the test case fails when comment == null - attachmentHandler.postContent(repository, task, new TextTaskAttachmentSource("abc"), "comment", null, null); - - task = TracTestUtil.createTask(repository, data.attachmentTicketId + ""); - Date newLastModified = task.getModificationDate(); - assertTrue("Expected " + newLastModified + " to be more recent than " + lastModified, - newLastModified.after(lastModified)); - } - - public void testAttachmentUrlEncoding010() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - attachmentUrlEncoding(); - } - - public void testAttachmentUrlEncoding011() throws Exception { - init(TracTestConstants.TEST_TRAC_011_URL, Version.XML_RPC); - attachmentUrlEncoding(); - } - - private void attachmentUrlEncoding() throws Exception { - AbstractTaskAttachmentHandler attachmentHandler = connector.getTaskAttachmentHandler(); - TracTicket ticket = TracTestUtil.createTicket(client, "attachment url test"); - ITask task = TracTestUtil.createTask(repository, ticket.getId() + ""); - attachmentHandler.postContent(repository, task, new TextTaskAttachmentSource("abc") { - @Override - public String getName() { - return "https%3A%2F%2Fbugs.eclipse.org%2Fbugs.xml.zip"; - } - }, "comment", null, null); - - task = TracTestUtil.createTask(repository, ticket.getId() + ""); - List<ITaskAttachment> attachments = TracTestUtil.getTaskAttachments(task); - assertEquals(1, attachments.size()); - assertEquals(repository.getUrl() + "/attachment/ticket/" + ticket.getId() - + "/https%253A%252F%252Fbugs.eclipse.org%252Fbugs.xml.zip", attachments.get(0).getUrl()); - } - - public void testPostTaskDataInvalidCredentials010() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - postTaskDataInvalidCredentials(); - } - - public void testPostTaskDataInvalidCredentials011() throws Exception { - init(TracTestConstants.TEST_TRAC_011_URL, Version.XML_RPC); - postTaskDataInvalidCredentials(); - } - - private void postTaskDataInvalidCredentials() throws Exception { - ITask task = TracTestUtil.createTask(repository, data.offlineHandlerTicketId + ""); - TaskData taskData = TasksUi.getTaskDataManager().getTaskData(task); - taskData.getRoot().getMappedAttribute(TaskAttribute.COMMENT_NEW).setValue("new comment"); - repository.setCredentials(AuthenticationType.REPOSITORY, new AuthenticationCredentials("foo", "bar"), false); - try { - taskDataHandler.postTaskData(repository, taskData, null, null); - } catch (CoreException expected) { - assertEquals(RepositoryStatus.ERROR_REPOSITORY_LOGIN, expected.getStatus().getCode()); - } - assertEquals("new comment", taskData.getRoot().getMappedAttribute(TaskAttribute.COMMENT_NEW).getValue()); - } - - public void testCanInitializeTaskData() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - - ITask task = new TaskTask(TracCorePlugin.CONNECTOR_KIND, "", ""); - assertFalse(taskDataHandler.canInitializeSubTaskData(repository, task)); - task.setAttribute(TracRepositoryConnector.TASK_KEY_SUPPORTS_SUBTASKS, Boolean.TRUE.toString()); - assertTrue(taskDataHandler.canInitializeSubTaskData(repository, task)); - - task = TracTestUtil.createTask(repository, data.offlineHandlerTicketId + ""); - TaskData taskData = taskDataHandler.getTaskData(repository, data.offlineHandlerTicketId + "", null); - assertFalse(taskDataHandler.canInitializeSubTaskData(repository, task)); - - taskData.getRoot().createAttribute(TracTaskDataHandler.ATTRIBUTE_BLOCKED_BY); - connector.updateTaskFromTaskData(repository, task, taskData); - assertTrue(taskDataHandler.canInitializeSubTaskData(repository, task)); - - task.setAttribute(TracRepositoryConnector.TASK_KEY_SUPPORTS_SUBTASKS, Boolean.FALSE.toString()); - connector.updateTaskFromTaskData(repository, task, taskData); - assertTrue(taskDataHandler.canInitializeSubTaskData(repository, task)); - } - - public void testInitializeSubTaskDataInvalidParent() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - TaskData parentTaskData = taskDataHandler.getTaskData(repository, data.offlineHandlerTicketId + "", - new NullProgressMonitor()); - try { - taskDataHandler.initializeSubTaskData(repository, parentTaskData, parentTaskData, null); - fail("expected CoreException"); - } catch (CoreException expected) { - } - } - - public void testInitializeSubTaskData() throws Exception { - init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - TaskData parentTaskData = taskDataHandler.getTaskData(repository, data.offlineHandlerTicketId + "", null); - TaskMapper parentTaskMapper = new TracTaskMapper(parentTaskData, null); - parentTaskMapper.setSummary("abc"); - parentTaskMapper.setDescription("def"); - String component = parentTaskData.getRoot() - .getMappedAttribute(TracAttribute.COMPONENT.getTracKey()) - .getOptions() - .get(0); - parentTaskMapper.setComponent(component); - parentTaskData.getRoot().createAttribute(TracTaskDataHandler.ATTRIBUTE_BLOCKED_BY); - TaskData subTaskData = new TaskData(parentTaskData.getAttributeMapper(), TracCorePlugin.CONNECTOR_KIND, "", ""); - subTaskData.getRoot().createAttribute(TracTaskDataHandler.ATTRIBUTE_BLOCKING); - taskDataHandler.initializeSubTaskData(repository, subTaskData, parentTaskData, new NullProgressMonitor()); - TaskMapper subTaskMapper = new TracTaskMapper(subTaskData, null); - assertEquals("", subTaskMapper.getSummary()); - assertEquals("", subTaskMapper.getDescription()); - assertEquals(component, subTaskMapper.getComponent()); - assertEquals(parentTaskData.getTaskId(), subTaskData.getRoot().getMappedAttribute( - TracTaskDataHandler.ATTRIBUTE_BLOCKING).getValue()); - assertEquals("", parentTaskData.getRoot() - .getMappedAttribute(TracTaskDataHandler.ATTRIBUTE_BLOCKED_BY) - .getValue()); - } - - public void testGetSubTaskIds() throws Exception { - TaskData taskData = new TaskData(new TracAttributeMapper(new TaskRepository("", "")), - TracCorePlugin.CONNECTOR_KIND, "", ""); - TaskAttribute blockedBy = taskData.getRoot().createAttribute(TracTaskDataHandler.ATTRIBUTE_BLOCKED_BY); - Collection<String> subTaskIds; - - blockedBy.setValue("123 456"); - subTaskIds = getSubTaskIds(taskData); - assertEquals(2, subTaskIds.size()); - assertTrue(subTaskIds.contains("123")); - assertTrue(subTaskIds.contains("456")); - - blockedBy.setValue("7,8"); - subTaskIds = getSubTaskIds(taskData); - assertEquals(2, subTaskIds.size()); - assertTrue(subTaskIds.contains("7")); - assertTrue(subTaskIds.contains("8")); - - blockedBy.setValue(" 7 , 8, "); - subTaskIds = getSubTaskIds(taskData); - assertEquals(2, subTaskIds.size()); - assertTrue(subTaskIds.contains("7")); - assertTrue(subTaskIds.contains("8")); - - blockedBy.setValue("7"); - subTaskIds = getSubTaskIds(taskData); - assertEquals(1, subTaskIds.size()); - assertTrue(subTaskIds.contains("7")); - - blockedBy.setValue(""); - subTaskIds = getSubTaskIds(taskData); - assertEquals(0, subTaskIds.size()); - - blockedBy.setValue(" "); - subTaskIds = getSubTaskIds(taskData); - assertEquals(0, subTaskIds.size()); - } - - private Collection<String> getSubTaskIds(TaskData taskData) { - List<String> subTaskIds = new ArrayList<String>(); - Collection<TaskRelation> relations = connector.getTaskRelations(taskData); - for (TaskRelation taskRelation : relations) { - subTaskIds.add(taskRelation.getTaskId()); - } - return subTaskIds; - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracUtilTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracUtilTest.java deleted file mode 100644 index b00729a13..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracUtilTest.java +++ /dev/null @@ -1,78 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.core; - -import java.util.Arrays; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.mylyn.internal.trac.core.TracCorePlugin; -import org.eclipse.mylyn.internal.trac.core.client.ITracClient; -import org.eclipse.mylyn.internal.trac.core.model.TracSearch; -import org.eclipse.mylyn.internal.trac.core.model.TracSearchFilter; -import org.eclipse.mylyn.internal.trac.core.util.TracUtil; -import org.eclipse.mylyn.tasks.core.IRepositoryQuery; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; - -/** - * @author Steffen Pingel - */ -public class TracUtilTest extends TestCase { - - private TaskRepository taskRepository; - - @Override - protected void setUp() throws Exception { - taskRepository = new TaskRepository(TracCorePlugin.CONNECTOR_KIND, TracTestConstants.TEST_TRAC_010_URL); - } - - public void testToTracSearch() { - String queryParameter = "&order=priority&status=new&status=assigned&status=reopened&milestone=M1&owner=%7E%C3%A4%C3%B6%C3%BC"; - IRepositoryQuery query = TasksUi.getRepositoryModel().createRepositoryQuery(taskRepository); - query.setUrl(taskRepository.getRepositoryUrl() + ITracClient.QUERY_URL + queryParameter); - - TracSearch search = TracUtil.toTracSearch(query); - assertNotNull(search); - assertEquals(queryParameter, search.toUrl()); - } - - public void testToTracSearchFilterList() { - String parameterUrl = "&status=new&status=assigned&status=reopened&milestone=0.1"; - String queryUrl = taskRepository.getRepositoryUrl() + ITracClient.QUERY_URL + parameterUrl; - IRepositoryQuery query = TasksUi.getRepositoryModel().createRepositoryQuery(taskRepository); - query.setUrl(queryUrl); - - TracSearch filterList = TracUtil.toTracSearch(query); - assertEquals(parameterUrl, filterList.toUrl()); - assertEquals("&status=new|assigned|reopened&milestone=0.1", filterList.toQuery()); - - List<TracSearchFilter> list = filterList.getFilters(); - TracSearchFilter filter = list.get(0); - assertEquals("status", filter.getFieldName()); - assertEquals(Arrays.asList("new", "assigned", "reopened"), filter.getValues()); - filter = list.get(1); - assertEquals("milestone", filter.getFieldName()); - assertEquals(Arrays.asList("0.1"), filter.getValues()); - } - - public void testEncodeUrl() { - assertEquals("encode", TracUtil.encodeUrl("encode")); - assertEquals("sp%20ace%20", TracUtil.encodeUrl("sp ace ")); - assertEquals("%2B%2B", TracUtil.encodeUrl("++")); - assertEquals("%2520", TracUtil.encodeUrl("%20")); - assertEquals("%2Fslash", TracUtil.encodeUrl("/slash")); - } - -} 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 deleted file mode 100644 index 88dcdb40d..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestFixture.java +++ /dev/null @@ -1,94 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.support; - -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; - -/** - * 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 data010; - - /** - * Adds the existing repository content to the test data of <code>server</code>. - */ - private static void initializeTestData(XmlRpcServer server) throws Exception { - server.ticketMilestone("milestone1").itemCreated(); - server.ticketMilestone("milestone2").itemCreated(); - server.ticketMilestone("milestone3").itemCreated(); - server.ticketMilestone("milestone4").itemCreated(); - server.ticketMilestone("mile&stone").itemCreated(); - - server.ticketVersion("1.0").itemCreated(); - server.ticketVersion("2.0").itemCreated(); - - server.ticket(1).itemCreated(); - server.ticket(2).itemCreated(); - server.ticket(3).itemCreated(); - server.ticket(4).itemCreated(); - server.ticket(5).itemCreated(); - server.ticket(6).itemCreated(); - server.ticket(7).itemCreated(); - server.ticket(8).itemCreated(); - } - -// private static void initializeRepository(XmlRpcServer server) throws Exception { -// server.ticketVersion(null).deleteAll(); -// server.ticketVersion("1.0").create(0, ""); -// server.ticketVersion("2.0").create(0, ""); -// -// server.ticketMilestone(null).deleteAll(); -// server.ticketMilestone("milestone1").create(); -// server.ticketMilestone("milestone2").create(); -// server.ticketMilestone("milestone3").create(); -// server.ticketMilestone("milestone4").create(); -// -// server.ticket().deleteAll(); -// Ticket ticket = server.ticket().create("summary1", "description1"); -// ticket.update("comment", "milestone", "milestone1"); -// ticket = server.ticket().create("summary2", "description2"); -// ticket.update("comment", "milestone", "milestone2"); -// ticket = server.ticket().create("summary3", "description3"); -// ticket.update("comment", "milestone", "milestone2"); -// ticket = server.ticket().create("summary4", "description4"); -// -// ticket = server.ticket().create("test html entities: ���", "���\n\nmulti\nline\n\n'''bold'''\n"); -// ticket = server.ticket().create("offline handler test", ""); -// } - - public static XmlRpcServer.TestData init010() throws Exception { - if (data010 == null) { - Credentials credentials = TestUtil.readCredentials(PrivilegeLevel.USER); - XmlRpcServer server = new XmlRpcServer(TracTestConstants.TEST_TRAC_010_URL, credentials.username, - credentials.password); - - initializeTestData(server); - data010 = server.getData(); - } - return data010; - } - - public static void cleanup010() throws Exception { - if (data010 != null) { - // data010.cleanup(); - data010 = null; - } - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestProxy.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestProxy.java deleted file mode 100644 index e3e3d231c..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TestProxy.java +++ /dev/null @@ -1,238 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.support; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.InterruptedIOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.HashMap; -import java.util.Map; -import java.util.StringTokenizer; - -public class TestProxy implements Runnable { - - public static final String NOT_FOUND = "HTTP/1.1 404 Not Found"; - - private int listenPort; - - private Message request; - - private Message response; - - private Thread runner; - - private IOException exception; - - private volatile boolean stopped = false; - - public TestProxy(int listenPort) { - this.listenPort = listenPort; - } - - public TestProxy() { - } - - public synchronized int getListenPort() throws InterruptedException { - while (listenPort == 0) { - wait(); - } - return listenPort; - } - - public void start() { - runner = new Thread(this, "TestProxy :" + listenPort); - runner.start(); - } - - public int startAndWait() throws InterruptedException { - start(); - int port = getListenPort(); - // wait for socket to enter accept call - Thread.sleep(100); - return port; - } - - public void run() { - ServerSocket serverSocket = null; - try { - serverSocket = new ServerSocket(listenPort); - synchronized (this) { - listenPort = serverSocket.getLocalPort(); - notifyAll(); - } - while (!stopped) { - Socket socket = serverSocket.accept(); - try { - Message request = readMessage(socket.getInputStream()); - setRequest(request); - - Message response = waitForResponse(); - writeMessage(response, socket.getOutputStream()); - } finally { - try { - socket.close(); - } catch (IOException e1) { - } - } - } - } catch (InterruptedIOException e) { - } catch (IOException e) { - setException(e); - } catch (InterruptedException e) { - } finally { - if (serverSocket != null) { - try { - serverSocket.close(); - } catch (IOException e) { - } - } - } - - } - - private void writeMessage(Message message, OutputStream out) throws IOException { - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)); - writer.write(message.toString()); - } - - private synchronized void setException(IOException exception) { - this.exception = exception; - notifyAll(); - } - - public synchronized void checkForException() throws IOException { - if (exception != null) { - throw exception; - } - } - - private Message readMessage(InputStream in) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - Message message = null; - String line; - while ((line = reader.readLine()) != null) { - if (line.length() == 0) { - if (message == null) { - throw new IOException("Incomplete message"); - } - return message; - } - - if (message == null) { - message = new Message(line); - } else { - StringTokenizer t = new StringTokenizer(line, ":"); - message.headers.put(t.nextToken(), t.nextToken().trim()); - } - } - throw new EOFException(); - } - - public void stop() { - stopped = true; - runner.interrupt(); - try { - runner.join(500); - } catch (InterruptedException e) { - } - } - - public Message getRequest() { - return request; - } - - public synchronized Message waitForRequest() throws InterruptedException { - while (request == null) { - wait(); - } - return request; - } - - public synchronized Message waitForResponse() throws InterruptedException { - while (response == null) { - wait(); - } - return response; - } - - public synchronized void setResponse(Message response) { - this.response = response; - notifyAll(); - } - - public synchronized void setResponse(String response) { - this.response = new Message(response); - notifyAll(); - } - - public synchronized void setRequest(Message request) { - this.request = request; - notifyAll(); - } - - public static class Message { - - public Message(String request) { - this.request = request; - } - - public String request; - - public Map<String, String> headers = new HashMap<String, String>(); - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(request); - sb.append("\n"); - if (headers != null) { - for (String key : headers.keySet()) { - sb.append(key + ": " + headers.get(key)); - sb.append("\n"); - } - } - sb.append("\n"); - return sb.toString(); - } - - public String getMethod() { - int i = request.indexOf(" "); - return (i != -1) ? request.substring(0, i) : request; - } - - } - - public static void main(String[] args) { - TestProxy proxy = new TestProxy(8080); - proxy.start(); - try { - proxy.setResponse(new Message("404 / HTTP 1.1")); - try { - System.out.println(proxy.waitForRequest()); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } finally { - proxy.stop(); - } - - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracTestCleanupUtil.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracTestCleanupUtil.java deleted file mode 100644 index de8a4c90e..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracTestCleanupUtil.java +++ /dev/null @@ -1,62 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.support; - -import org.eclipse.mylyn.context.tests.support.TestUtil.PrivilegeLevel; -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.TracAttachment; -import org.eclipse.mylyn.internal.trac.core.model.TracTicket; -import org.eclipse.mylyn.trac.tests.client.AbstractTracClientTest; -import org.eclipse.mylyn.trac.tests.support.XmlRpcServer.TestData; - -/** - * Utility that cleans up artifacts created by the Trac test suite. This class should be run periodically to speed up - * execution of (attachment) tests. - * - * @author Steffen Pingel - */ -public class TracTestCleanupUtil extends AbstractTracClientTest { - - private TestData data; - - public TracTestCleanupUtil() { - super(Version.XML_RPC, PrivilegeLevel.ADMIN); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - data = TestFixture.init010(); - } - - public void testCleanup010() throws Exception { - connect010(); - cleanup(); - } - - public void testCleanup011() throws Exception { - connect011(); - cleanup(); - } - - private void cleanup() throws TracException { - TracTicket ticket = repository.getTicket(data.attachmentTicketId, null); - TracAttachment[] attachments = ticket.getAttachments(); - // skips the first attachment - for (int i = 1; i < attachments.length; i++) { - repository.deleteAttachment(data.attachmentTicketId, attachments[i].getFilename(), null); - } - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracTestConstants.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracTestConstants.java deleted file mode 100644 index 5df0e5bd6..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracTestConstants.java +++ /dev/null @@ -1,35 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.support; - -/** - * @author Steffen Pingel - */ -public class TracTestConstants { - - public static final String SERVER = System.getProperty("mylyn.trac.server", "mylyn.eclipse.org"); - - public static final String TEST_TRAC_096_URL = "http://" + SERVER + "/trac096"; - - public static final String TEST_TRAC_010_URL = "http://" + SERVER + "/trac010"; - - public static final String TEST_TRAC_010_SSL_URL = "https://" + SERVER + "/trac010"; - - public static final String TEST_TRAC_010_DIGEST_AUTH_URL = "http://" + SERVER + "/trac010digest"; - - public static final String TEST_TRAC_010_FORM_AUTH_URL = "http://" + SERVER + "/trac010formauth"; - - public static final String TEST_TRAC_011_URL = "http://" + SERVER + "/trac011"; - - public static final String TEST_TRAC_INVALID_URL = "http://" + SERVER + "/doesnotexist"; - -} 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 deleted file mode 100644 index 57532b13c..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/TracTestUtil.java +++ /dev/null @@ -1,93 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.support; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.mylyn.commons.net.AuthenticationCredentials; -import org.eclipse.mylyn.commons.net.AuthenticationType; -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.tasks.core.TaskRepositoryManager; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.mylyn.internal.trac.core.TracCorePlugin; -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.internal.trac.core.model.TracTicket.Key; -import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.ITaskAttachment; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.data.TaskAttribute; -import org.eclipse.mylyn.tasks.core.data.TaskData; -import org.eclipse.mylyn.tasks.ui.TasksUi; - -/** - * @author Steffen Pingel - */ -public class TracTestUtil { - - public static TracTicket createTicket(ITracClient client, String summary) throws Exception { - TracTicket ticket = new TracTicket(); - ticket.putBuiltinValue(Key.SUMMARY, summary); - ticket.putBuiltinValue(Key.DESCRIPTION, ""); - int id = client.createTicket(ticket, null); - return client.getTicket(id, null); - } - - public static ITask createTask(TaskRepository taskRepository, String taskId) throws Exception { - AbstractRepositoryConnector connector = TasksUi.getRepositoryConnector(TracCorePlugin.CONNECTOR_KIND); - TaskData taskData = connector.getTaskData(taskRepository, taskId, null); - ITask task = TasksUi.getRepositoryModel().createTask(taskRepository, taskData.getTaskId()); - TasksUiPlugin.getTaskDataManager().putUpdatedTaskData(task, taskData, true); - return task; - } - - public static TaskRepository init(String repositoryUrl, Version version) { - TracCorePlugin.getDefault().getConnector().getClientManager().writeCache(); - TaskRepositoryManager manager = TasksUiPlugin.getRepositoryManager(); - manager.clearRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath()); - - Credentials credentials = TestUtil.readCredentials(PrivilegeLevel.USER); - TaskRepository repository = new TaskRepository(TracCorePlugin.CONNECTOR_KIND, repositoryUrl); - repository.setCredentials(AuthenticationType.REPOSITORY, new AuthenticationCredentials(credentials.username, - credentials.password), false); - repository.setTimeZoneId(ITracClient.TIME_ZONE); - repository.setCharacterEncoding(ITracClient.CHARSET); - repository.setVersion(version.name()); - - manager.addRepository(repository); - TracCorePlugin.getDefault().getConnector().getClientManager().readCache(); - - return repository; - } - - public static List<ITaskAttachment> getTaskAttachments(ITask task) throws CoreException { - TaskData taskData = TasksUi.getTaskDataManager().getTaskData(task); - List<ITaskAttachment> attachments = new ArrayList<ITaskAttachment>(); - List<TaskAttribute> attributes = taskData.getAttributeMapper().getAttributesByType(taskData, - TaskAttribute.TYPE_ATTACHMENT); - if (attributes != null) { - for (TaskAttribute taskAttribute : attributes) { - ITaskAttachment taskAttachment = TasksUiPlugin.getRepositoryModel().createTaskAttachment(taskAttribute); - taskData.getAttributeMapper().updateTaskAttachment(taskAttachment, taskAttribute); - attachments.add(taskAttachment); - } - } - return attachments; - } - -} 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 deleted file mode 100644 index 8acb55813..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/support/XmlRpcServer.java +++ /dev/null @@ -1,367 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.support; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import org.apache.xmlrpc.XmlRpcException; -import org.apache.xmlrpc.client.XmlRpcClient; -import org.eclipse.mylyn.commons.net.WebLocation; -import org.eclipse.mylyn.internal.trac.core.client.TracXmlRpcClient; -import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version; - -/** - * @author Steffen Pingel - */ -public class XmlRpcServer { - - public abstract class AbstractTracItem { - - public abstract void delete() throws Exception; - - void itemCreated() { - data.items.add(this); - } - - void itemDeleted() { - data.items.remove(this); - } - - } - - /** - * Represents a Trac type with multiple attributes such as a milestone. - */ - public class ModelEnum extends AbstractTracItem { - - private final String[] attributes; - - private final String id; - - private final String module; - - public ModelEnum(String module, String id, String... attributes) { - this.module = module; - this.id = id; - this.attributes = attributes; - } - - public ModelEnum create(Object... params) throws Exception { - call(module + ".create", id, toMap(params)); - itemCreated(); - return this; - } - - @Override - public void delete() throws Exception { - call(module + ".delete", id); - itemDeleted(); - } - - public void deleteAll() throws Exception { - String[] ids = getAll(); - for (String id : ids) { - call(module + ".delete", id); - } - } - - public ModelEnum deleteAndCreate(Object... params) throws Exception { - if (Arrays.asList(getAll()).contains(id)) { - delete(); - } - - return create(params); - } - - @SuppressWarnings("unchecked") - public Object[] get() throws Exception { - Hashtable values = (Hashtable) call(module + ".get", id); - Object[] result = new Object[values.size()]; - for (int i = 0; i < result.length && i < attributes.length; i++) { - result[i] = values.get(attributes[i]); - } - return result; - } - - public String[] getAll() throws Exception { - return Arrays.asList((Object[]) call(module + ".getAll")).toArray(new String[0]); - } - - private Hashtable<String, Object> toMap(Object... params) { - Hashtable<String, Object> attrs = new Hashtable<String, Object>(); - for (int i = 0; i < attributes.length && i < params.length; i++) { - attrs.put(attributes[i], params[i]); - } - return attrs; - } - - public ModelEnum update(Object... params) throws Exception { - call(module + ".update", id, toMap(params)); - return this; - } - - } - - /** - * Records changes to the repository. - */ - public class TestData { - - // all created items - List<AbstractTracItem> items = new ArrayList<AbstractTracItem>(); - - // all created tickets - public List<Ticket> tickets = new ArrayList<Ticket>(); - - public int attachmentTicketId = 5; - - public int htmlEntitiesTicketId = 6; - - public int offlineHandlerTicketId = 7; - - /** - * Undo all changes. - */ - public void cleanup() throws Exception { - while (!items.isEmpty()) { - items.get(0).delete(); - } - } - - } - - /** - * Represents a Trac ticket. - */ - public class Ticket extends AbstractTracItem { - - private Integer id; - - public Ticket(Integer id) { - this.id = id; - } - - public Ticket create(String summary, String description) throws Exception { - this.id = (Integer) call("ticket.create", summary, description, new Hashtable<String, Object>()); - if (id == null) { - throw new RuntimeException("Could not create ticket: " + summary); - } - itemCreated(); - return this; - } - - @Override - public void delete() throws Exception { - call("ticket.delete", id); - itemDeleted(); - } - - public void deleteAll() throws Exception { - Integer[] ids = getAll(); - for (Integer id : ids) { - call("ticket.delete", id); - } - } - - public Object getValue(String key) throws Exception { - return getValues().get(key); - } - - public Map<?, ?> getValues() throws Exception { - return (Map<?, ?>) ((Object[]) call("ticket.get", id))[3]; - } - - public Integer[] getAll() throws Exception { - return Arrays.asList((Object[]) call("ticket.query", "order=id")).toArray(new Integer[0]); - } - - public int getId() { - 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); - call("ticket.update", id, comment, attrs); - return this; - } - - } - - /** - * Represents a Trac type that has a single attribute such as a priority. - */ - public class TicketEnum extends AbstractTracItem { - - private final String id; - - private final String module; - - public TicketEnum(String module, String id) { - this.module = module; - this.id = id; - } - - public TicketEnum create(String param) throws Exception { - call(module + ".create", id, param); - itemCreated(); - return this; - } - - @Override - public void delete() throws Exception { - call(module + ".delete", id); - itemDeleted(); - } - - public void deleteAll() throws Exception { - String[] ids = getAll(); - for (String id : ids) { - call(module + ".delete", id); - } - } - - public TicketEnum deleteAndCreate(String param) throws Exception { - if (Arrays.asList(getAll()).contains(id)) { - delete(); - } - - return create(param); - } - - public String get() throws Exception { - return (String) call(module + ".get", id); - } - - public String[] getAll() throws Exception { - return Arrays.asList((Object[]) call(module + ".getAll")).toArray(new String[0]); - } - - public TicketEnum update(String param) throws Exception { - call(module + ".update", id, param); - return this; - } - - } - - private final XmlRpcClient client; - - private final TestData data; - - private final String password; - - private final TracXmlRpcClient repository; - - private final String url; - - private final String username; - - public XmlRpcServer(String url, String username, String password) throws Exception { - this.url = url; - this.username = username; - this.password = password; - - this.data = new TestData(); - - this.repository = new TracXmlRpcClient(new WebLocation(url, username, password), Version.XML_RPC); - this.client = repository.getClient(); - } - - private Object call(String method, Object... parameters) throws XmlRpcException, IOException { - Vector<Object> params = new Vector<Object>(parameters.length); - for (Object parameter : parameters) { - params.add(parameter); - } - - Object result = client.execute(method, params); - if (result instanceof XmlRpcException) { - throw (XmlRpcException) result; - } - return result; - } - - public TestData getData() { - return data; - } - - public String getPassword() { - return password; - } - - public TracXmlRpcClient getRepository() throws MalformedURLException { - return repository; - } - - public String getUrl() { - return url; - } - - public String getUsername() { - return username; - } - - public Ticket ticket() throws Exception { - return new Ticket(null); - } - - public Ticket ticket(int id) throws Exception { - return new Ticket(id); - } - - public ModelEnum ticketComponent(String id) throws Exception { - return new ModelEnum("ticket.component", id, "owner", "description"); - } - - public ModelEnum ticketMilestone(String id) throws Exception { - return new ModelEnum("ticket.milestone", id, "due", "completed", "description"); - } - - public TicketEnum ticketPriority(String id) throws Exception { - return new TicketEnum("ticket.priority", id); - } - - public TicketEnum ticketSeverity(String id) throws Exception { - return new TicketEnum("ticket.severity", id); - } - - public TicketEnum ticketStatus(String id) throws Exception { - return new TicketEnum("ticket.status", id); - } - - public TicketEnum ticketType(String id) throws Exception { - return new TicketEnum("ticket.type", id); - } - - public ModelEnum ticketVersion(String id) throws Exception { - return new ModelEnum("ticket.version", id, "time", "description"); - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/ui/TracHyperlinkUtilTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/ui/TracHyperlinkUtilTest.java deleted file mode 100644 index 87c0db555..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/ui/TracHyperlinkUtilTest.java +++ /dev/null @@ -1,270 +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: - * Tasktop Technologies - initial API and implementation - * David Green - improvements - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.ui; - -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.mylyn.internal.trac.core.TracCorePlugin; -import org.eclipse.mylyn.internal.trac.ui.TracHyperlinkUtil; -import org.eclipse.mylyn.internal.trac.ui.WebHyperlink; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.ui.TaskHyperlink; - -/** - * @author Steffen Pingel - * @author David Green - * @see http://trac.edgewall.org/wiki/TracLinks - */ -public class TracHyperlinkUtilTest extends TestCase { - - private TaskRepository repository; - - @Override - protected void setUp() throws Exception { - repository = new TaskRepository(TracCorePlugin.CONNECTOR_KIND, "http://localhost"); - } - - public void testFindHyperlinksComment() { - IHyperlink[] links = findTracHyperlinks(repository, "comment:ticket:12:34", 0, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals(new Region(0, 20), links[0].getHyperlinkRegion()); - assertEquals("12", ((TaskHyperlink) links[0]).getTaskId()); - } - - public void testFindHyperlinksTicket() { - IHyperlink[] links = TracHyperlinkUtil.findTicketHyperlinks(repository, "#11", 0, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals(new Region(0, 3), links[0].getHyperlinkRegion()); - assertEquals("11", ((TaskHyperlink) links[0]).getTaskId()); - - links = TracHyperlinkUtil.findTicketHyperlinks(repository, "#11, #234", 6, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals("234", ((TaskHyperlink) links[0]).getTaskId()); - - links = TracHyperlinkUtil.findTicketHyperlinks(repository, " ticket:123 ", 2, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals(new Region(2, 10), links[0].getHyperlinkRegion()); - assertEquals("123", ((TaskHyperlink) links[0]).getTaskId()); - } - - public void testFindHyperlinksNoTicket() { - IHyperlink[] links = findTracHyperlinks(repository, "#11", 0, 0); - assertNull(links); - - links = findTracHyperlinks(repository, "#11, #234", 6, 0); - assertNull(links); - - links = findTracHyperlinks(repository, " ticket:123 ", 2, 0); - assertNull(links); - - links = findTracHyperlinks(repository, "#123 report:123", -1, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals("http://localhost/report/123", ((WebHyperlink) links[0]).getURLString()); - } - - public void testFindHyperlinksReport() { - IHyperlink[] links = findTracHyperlinks(repository, "report:123", 0, 0); - assertEquals(1, links.length); - assertEquals(new Region(0, 10), links[0].getHyperlinkRegion()); - assertEquals("http://localhost/report/123", ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "{123}", 0, 0); - assertEquals(1, links.length); - assertEquals(new Region(0, 5), links[0].getHyperlinkRegion()); - assertEquals("http://localhost/report/123", ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "{{123}}", -1, 0); - assertEquals(1, links.length); - assertEquals(new Region(1, 5), links[0].getHyperlinkRegion()); - - links = findTracHyperlinks(repository, "{abc}", -1, 0); - assertNull(links); - - links = findTracHyperlinks(repository, "{{abc}}", -1, 0); - assertNull(links); - } - - public void testFindHyperlinksChangeset() { - IHyperlink[] links = findTracHyperlinks(repository, "r123", 0, 0); - assertEquals(1, links.length); - assertEquals(new Region(0, 4), links[0].getHyperlinkRegion()); - assertEquals("http://localhost/changeset/123", ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "alr123", 0, 0); - assertNull(links); - - links = findTracHyperlinks(repository, "[123]", 0, 0); - assertEquals(1, links.length); - assertEquals(new Region(0, 5), links[0].getHyperlinkRegion()); - assertEquals("http://localhost/changeset/123", ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "![123]", 0, 0); - assertNull(links); - - links = findTracHyperlinks(repository, "![123]", 1, 0); - assertNull(links); - - links = findTracHyperlinks(repository, "changeset:123", 0, 0); - assertEquals(1, links.length); - assertEquals(new Region(0, 13), links[0].getHyperlinkRegion()); - assertEquals("http://localhost/changeset/123", ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "[123/trunk]", 0, 0); - assertEquals(1, links.length); - assertEquals(new Region(0, 11), links[0].getHyperlinkRegion()); - assertEquals("http://localhost/changeset/123/trunk", ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "changeset:123/trunk", 0, 0); - assertEquals(1, links.length); - assertEquals(new Region(0, 19), links[0].getHyperlinkRegion()); - assertEquals("http://localhost/changeset/123/trunk", ((WebHyperlink) links[0]).getURLString()); - } - - public void testFindHyperlinksRevisionLog() { - IHyperlink[] links = findTracHyperlinks(repository, "r123:456", 0, 0); - assertEquals(2, links.length); - assertEquals("http://localhost/log/?rev=123&stop_rev=456", ((WebHyperlink) links[0]).getURLString()); - assertEquals(new Region(0, 8), links[0].getHyperlinkRegion()); - - links = findTracHyperlinks(repository, "[123:456]", 0, 0); - assertEquals(1, links.length); - assertEquals("http://localhost/log/?rev=123&stop_rev=456", ((WebHyperlink) links[0]).getURLString()); - assertEquals(new Region(0, 9), links[0].getHyperlinkRegion()); - - links = findTracHyperlinks(repository, "log:@123:456", 0, 0); - assertEquals(1, links.length); - assertEquals("http://localhost/log/?rev=123&stop_rev=456", ((WebHyperlink) links[0]).getURLString()); - assertEquals(new Region(0, 12), links[0].getHyperlinkRegion()); - - links = findTracHyperlinks(repository, "log:trunk@123:456", 0, 0); - assertEquals(1, links.length); - assertEquals("http://localhost/log/trunk?rev=123&stop_rev=456", ((WebHyperlink) links[0]).getURLString()); - assertEquals(new Region(0, 17), links[0].getHyperlinkRegion()); - } - - public void testFindHyperlinksDiff() { - IHyperlink[] links = findTracHyperlinks(repository, "diff:@123:456", 0, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals("http://localhost/changeset/?new=456&old=123", ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "diff:trunk/trac@3538//sandbox/vc-refactoring/trac@3539", 0, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals( - "http://localhost/changeset/?new_path=sandbox%2Fvc-refactoring%2Ftrac&old_path=trunk%2Ftrac&new=3539&old=3538", - ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "diff:tags/trac-0.9.2/wiki-default//tags/trac-0.9.3/wiki-default", 0, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals( - "http://localhost/changeset/?new_path=tags%2Ftrac-0.9.3%2Fwiki-default&old_path=tags%2Ftrac-0.9.2%2Fwiki-default", - ((WebHyperlink) links[0]).getURLString()); - } - - public void testFindHyperlinksWiki() { - IHyperlink[] links = findTracHyperlinks(repository, "[wiki:page]", 1, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals("http://localhost/wiki/page", ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "wiki:page", 0, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals("http://localhost/wiki/page", ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "Page", 0, 0); - assertNull(links); - - links = findTracHyperlinks(repository, "!Page", 0, 0); - assertNull(links); - - links = findTracHyperlinks(repository, "ab Page dc", 0, 0); - assertNull(links); - - links = findTracHyperlinks(repository, "paGe", 0, 0); - assertNull(links); - - links = findTracHyperlinks(repository, "WikiPage", 0, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals("http://localhost/wiki/WikiPage", ((WebHyperlink) links[0]).getURLString()); - assertEquals(new Region(0, 8), links[0].getHyperlinkRegion()); - - links = findTracHyperlinks(repository, "!WikiPage", 0, 0); - assertNull(links); - - links = findTracHyperlinks(repository, "!WikiPage", 1, 0); - assertNull(links); - - links = findTracHyperlinks(repository, "a WikiPage is here", 4, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals("http://localhost/wiki/WikiPage", ((WebHyperlink) links[0]).getURLString()); - assertEquals(new Region(2, 8), links[0].getHyperlinkRegion()); - - links = findTracHyperlinks(repository, "a !WikiPage is here", 4, 0); - assertNull(links); - } - - public void testFindHyperlinksMilestone() { - IHyperlink[] links = findTracHyperlinks(repository, "milestone:1.0", 1, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals("http://localhost/milestone/1.0", ((WebHyperlink) links[0]).getURLString()); - } - - public void testFindHyperlinksAttachment() { - IHyperlink[] links = findTracHyperlinks(repository, "attachment:ticket:123:foo.bar", 1, 0); - assertNotNull(links); - assertEquals("123", ((TaskHyperlink) links[0]).getTaskId()); - } - - public void testFindHyperlinksFiles() { - IHyperlink[] links = findTracHyperlinks(repository, "source:trunk/foo", 1, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals("http://localhost/browser/trunk/foo", ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "source:trunk/foo@123", 1, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals("http://localhost/browser/trunk/foo?rev=123", ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "source:trunk/foo@123#L456", 1, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals("http://localhost/browser/trunk/foo?rev=123#L456", ((WebHyperlink) links[0]).getURLString()); - - links = findTracHyperlinks(repository, "source:/tags/foo_bar-1.1", 1, 0); - assertNotNull(links); - assertEquals(1, links.length); - assertEquals("http://localhost/browser/tags/foo_bar-1.1", ((WebHyperlink) links[0]).getURLString()); - } - - private IHyperlink[] findTracHyperlinks(TaskRepository repository, String text, int offsetInText, int textOffset) { - List<IHyperlink> links = TracHyperlinkUtil.findTracHyperlinks(repository, text, offsetInText, textOffset); - return (links.isEmpty()) ? null : links.toArray(new IHyperlink[0]); - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/ui/TracRepositorySettingsPageTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/ui/TracRepositorySettingsPageTest.java deleted file mode 100644 index 8e730b2ae..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/ui/TracRepositorySettingsPageTest.java +++ /dev/null @@ -1,105 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.ui; - -import java.net.Proxy; - -import org.eclipse.core.runtime.NullProgressMonitor; -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.ui.wizard.TracRepositorySettingsPage; -import org.eclipse.mylyn.internal.trac.ui.wizard.TracRepositorySettingsPage.TracValidator; -import org.eclipse.mylyn.trac.tests.client.AbstractTracClientTest; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; - -/** - * @author Steffen Pingel - */ -public class TracRepositorySettingsPageTest extends AbstractTracClientTest { - - private TracRepositorySettingsPage page; - - private TracValidator validator; - - public TracRepositorySettingsPageTest() { - super(null); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - page = new TracRepositorySettingsPage(null); - - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - page.createControl(shell); - page.setVisible(true); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - - // TestFixture.cleanupRepository1(); - } - - @Override - public ITracClient connect(String url, String username, String password, Proxy proxy, Version version) - throws Exception { - page.setAnonymous(false); - page.setUrl(url); - page.setUserId(username); - page.setPassword(password); - page.setTracVersion(version); - validator = page.new TracValidator(page.createTaskRepository(), version); - return null; - } - - public void testValidateXmlRpc() throws Exception { - version = Version.XML_RPC; - connect010(); - - validator.run(new NullProgressMonitor()); - assertNull(validator.getResult()); - assertNull(validator.getStatus()); - } - - public void testValidateWeb() throws Exception { - version = Version.TRAC_0_9; - connect010(); - - validator.run(new NullProgressMonitor()); - assertNull(validator.getResult()); - assertNull(validator.getStatus()); - } - - public void testValidateAutomaticUser() throws Exception { - version = null; - connect010(); - - validator.run(new NullProgressMonitor()); - assertEquals(Version.XML_RPC, validator.getResult()); - assertNull(validator.getStatus()); - } - - public void testValidateAutomaticAnonymous() throws Exception { - version = null; - connect(TracTestConstants.TEST_TRAC_010_URL, "", ""); - - validator.run(new NullProgressMonitor()); - assertEquals(Version.TRAC_0_9, validator.getResult()); - assertNotNull(validator.getStatus()); - } - -} diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/ui/TracTaskEditorTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/ui/TracTaskEditorTest.java deleted file mode 100644 index d90cd6942..000000000 --- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/ui/TracTaskEditorTest.java +++ /dev/null @@ -1,54 +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: - * Tasktop Technologies - initial API and implementation - *******************************************************************************/ - -package org.eclipse.mylyn.trac.tests.ui; - -import junit.framework.TestCase; - -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView; -import org.eclipse.mylyn.internal.trac.core.client.ITracClient.Version; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.tests.TaskTestUtil; -import org.eclipse.mylyn.tasks.ui.TasksUiUtil; -import org.eclipse.mylyn.trac.tests.support.TracTestConstants; -import org.eclipse.mylyn.trac.tests.support.TracTestUtil; - -/** - * @author Steffen Pingel - */ -public class TracTaskEditorTest extends TestCase { - - @Override - protected void setUp() throws Exception { - TaskTestUtil.resetTaskList(); - } - - public void testGetSelectedRepository() throws Exception { - TaskRepository repository = TracTestUtil.init(TracTestConstants.TEST_TRAC_010_URL, Version.XML_RPC); - - ITask task = TracTestUtil.createTask(repository, "1"); - TasksUiPlugin.getTaskList().addTask(task); - TasksUiUtil.openTask(task); - - TaskListView taskListView = TaskListView.getFromActivePerspective(); - // force refresh since automatic refresh is delayed - taskListView.getViewer().refresh(); - taskListView.getViewer().expandAll(); - taskListView.getViewer().setSelection(new StructuredSelection(task)); - - assertFalse(taskListView.getViewer().getSelection().isEmpty()); - assertEquals(repository, TasksUiUtil.getSelectedRepository(taskListView.getViewer())); - } - -} |