diff options
author | Chris Aniszczyk | 2011-03-23 23:04:34 +0000 |
---|---|---|
committer | Chris Aniszczyk | 2011-03-23 23:04:34 +0000 |
commit | 8758fb2dd13ed6031ead593e4fc092c9c2e7f1eb (patch) | |
tree | c20c312bdf7da473e6fe3e435c0670cd8dc0b82a /org.eclipse.mylyn.github.tests | |
download | egit-github-8758fb2dd13ed6031ead593e4fc092c9c2e7f1eb.tar.gz egit-github-8758fb2dd13ed6031ead593e4fc092c9c2e7f1eb.tar.xz egit-github-8758fb2dd13ed6031ead593e4fc092c9c2e7f1eb.zip |
Initial commit of Mylyn GitHub Integration
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.mylyn.github.tests')
11 files changed, 339 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.github.tests/.classpath b/org.eclipse.mylyn.github.tests/.classpath new file mode 100644 index 00000000..64c5e31b --- /dev/null +++ b/org.eclipse.mylyn.github.tests/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/org.eclipse.mylyn.github.tests/.gitignore b/org.eclipse.mylyn.github.tests/.gitignore new file mode 100644 index 00000000..d567ba01 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/.gitignore @@ -0,0 +1,2 @@ +bin +target diff --git a/org.eclipse.mylyn.github.tests/.project b/org.eclipse.mylyn.github.tests/.project new file mode 100644 index 00000000..c3fa2b20 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.mylyn.github.tests</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/org.eclipse.mylyn.github.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.mylyn.github.tests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..593ea92a --- /dev/null +++ b/org.eclipse.mylyn.github.tests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Wed Feb 03 20:29:30 PST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF new file mode 100644 index 00000000..2076b5bc --- /dev/null +++ b/org.eclipse.mylyn.github.tests/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Eclipse EGit Mylyn GitHub Tests (Incubation) +Bundle-SymbolicName: org.eclipse.mylyn.github.tests +Bundle-Version: 0.1.0.qualifier +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Require-Bundle: org.junit4;bundle-version="4.5.0", + org.eclipse.mylyn.github.core;bundle-version="0.1.0", + org.eclipse.mylyn.github.ui;bundle-version="0.1.0", + org.eclipse.jface.text;bundle-version="3.5.0", + org.eclipse.mylyn.tasks.ui;bundle-version="3.2.0", + org.eclipse.equinox.security;bundle-version="1.0.100", + org.eclipse.mylyn.tasks.core +Bundle-Vendor: Eclipse EGit +Import-Package: com.google.gson;version="1.6.0" diff --git a/org.eclipse.mylyn.github.tests/build.properties b/org.eclipse.mylyn.github.tests/build.properties new file mode 100644 index 00000000..34d2e4d2 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java new file mode 100644 index 00000000..009f6db0 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/AllHeadlessTests.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2011 Red Hat 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 <david.green@tasktop.com> - initial contribution + * Christian Trutz <christian.trutz@gmail.com> - initial contribution + * Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution + *******************************************************************************/ +package org.eclipse.mylyn.github.tests; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses( { // + GitHubServiceTest.class, + MarshalingTest.class + }) +public class AllHeadlessTests { + +} diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/GitHubServiceTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/GitHubServiceTest.java new file mode 100644 index 00000000..d05be84a --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/GitHubServiceTest.java @@ -0,0 +1,121 @@ +/******************************************************************************* + * Copyright (c) 2011 Red Hat 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 <david.green@tasktop.com> - initial contribution + * Christian Trutz <christian.trutz@gmail.com> - initial contribution + * Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution + *******************************************************************************/ +package org.eclipse.mylyn.github.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.eclipse.mylyn.github.internal.GitHubCredentials; +import org.eclipse.mylyn.github.internal.GitHubIssue; +import org.eclipse.mylyn.github.internal.GitHubIssues; +import org.eclipse.mylyn.github.internal.GitHubService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Run All the JUnit Tests for the GitHub API implementation + */ +@RunWith(JUnit4.class) +public class GitHubServiceTest { + + // GitHub API key for user "eclipse-github-plugin" + String API_KEY = "8b35af675fcdca9d254ae7a6ad4d0be8"; + + String TEST_USER = "eclipse-github-plugin"; + + String TEST_PASS = "plugin"; + + String TEST_PROJECT = "org.eclipse.mylyn.github.issues"; + + /** + * Test the GitHubService issue searching implementation + */ + @SuppressWarnings("restriction") + @Test + public void searchIssues() throws Exception { + final GitHubService service = new GitHubService(); + final GitHubIssues issues = service.searchIssues(TEST_USER, + TEST_PROJECT, "open", "test"); + assertEquals(0, issues.getIssues().length); + } + + /** + * Test the GitHubService implementation for opening a new issue. + */ + @Test + public void openIssue() throws Exception { + final GitHubService service = new GitHubService(); + final GitHubIssue issue = new GitHubIssue(); + issue.setUser(TEST_USER); + issue.setBody("This is a test body"); + issue.setTitle("Issue Title"); + GitHubIssue newIssue = service.openIssue(TEST_USER, TEST_PROJECT, issue, + new GitHubCredentials(TEST_USER,API_KEY)); + assertTrue(newIssue != null); + assertEquals(issue.getUser(),newIssue.getUser()); + assertEquals(issue.getBody(),newIssue.getBody()); + assertEquals(issue.getTitle(),newIssue.getTitle()); + assertTrue(newIssue.getNumber() != null && newIssue.getNumber().length() > 0); + } + /** + * Test the GitHubService implementation for opening a new issue. + */ + @Test + public void editIssue() throws Exception { + final GitHubService service = new GitHubService(); + final GitHubIssue issue = new GitHubIssue(); + issue.setUser(TEST_USER); + issue.setBody("This is a test body"); + issue.setTitle("Issue Title"); + GitHubIssue newIssue = service.openIssue(TEST_USER, TEST_PROJECT, issue, + new GitHubCredentials(TEST_USER,API_KEY)); + assertTrue(newIssue != null); + + newIssue.setTitle(newIssue.getTitle()+" - modified"); + newIssue.setBody(newIssue.getBody()+" - modified"); + + service.editIssue(TEST_USER, TEST_PROJECT, issue, new GitHubCredentials(TEST_USER,API_KEY)); + + GitHubIssue showIssue = service.showIssue(TEST_USER, TEST_PROJECT, issue.getNumber()); + + assertTrue(showIssue != null); + assertEquals(newIssue.getTitle(),showIssue.getTitle()); + } + + + + /** + * Test the GitHubService implementation for adding a label to an existing + * issue. + */ + @Test + public void addLabel() throws Exception { + final GitHubService service = new GitHubService(); + final boolean result = service.addLabel(TEST_USER, TEST_PROJECT, + "lame", 1, new GitHubCredentials(TEST_USER,API_KEY)); + assertTrue(result); + } + + /** + * Test the GitHubService implementation for removing an existing label from + * any GitHub issue. + */ + @Test + public void removeLable() throws Exception { + final GitHubService service = new GitHubService(); + final boolean result = service.removeLabel(TEST_USER, TEST_PROJECT, + "lame", 1, new GitHubCredentials(TEST_USER,API_KEY)); + assertTrue(result); + } +}
\ No newline at end of file diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/MarshalingTest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/MarshalingTest.java new file mode 100644 index 00000000..e6c80fe9 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/MarshalingTest.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2011 Red Hat 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 <david.green@tasktop.com> - initial contribution + * Christian Trutz <christian.trutz@gmail.com> - initial contribution + * Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution + *******************************************************************************/ +package org.eclipse.mylyn.github.tests; + +import static junit.framework.Assert.assertNull; +import static junit.framework.Assert.assertTrue; +import static org.junit.Assert.assertEquals; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringWriter; + +import org.eclipse.mylyn.github.internal.GitHubIssue; +import org.eclipse.mylyn.github.internal.GitHubIssues; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import com.google.gson.Gson; + +@SuppressWarnings("restriction") +@RunWith(JUnit4.class) +public class MarshalingTest { + + private Gson gson; + + @Before + public void beforeTest() { + gson = new Gson(); + } + + @Test + public void unmarshalIssues() { + GitHubIssues issues = gson.fromJson( + getResource("resources/issues.json"), GitHubIssues.class); + + assertTrue(issues != null); + assertTrue(issues.getIssues() != null); + + assertEquals(10,issues.getIssues().length); + + GitHubIssue issue = issues.getIssues()[9]; + //{"number":10,"votes":0,"created_at":"2010/02/04 21:03:54 -0800","body":"test description 2 ","title":"test issue for testing mylyn github connector2", + // "updated_at":"2010/02/04 21:09:37 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"}]} + assertEquals("10",issue.getNumber()); + assertEquals("2010/02/04 21:03:54 -0800",issue.getCreated_at()); + assertEquals("test description 2 ",issue.getBody()); + assertEquals("test issue for testing mylyn github connector2",issue.getTitle()); + assertEquals("2010/02/04 21:09:37 -0800",issue.getUpdated_at()); + assertNull(issue.getClosed_at()); + assertEquals("dgreen99",issue.getUser()); + assertEquals("open",issue.getState()); + } + + private String getResource(String resource) { + try { + InputStream stream = MarshalingTest.class + .getResourceAsStream(resource); + try { + StringWriter writer = new StringWriter(); + Reader reader = new InputStreamReader(stream); + int c; + while ((c = reader.read()) != -1) { + writer.write(c); + } + return writer.toString(); + } finally { + stream.close(); + } + } catch (Throwable t) { + throw new IllegalStateException(t); + } + } +} diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/resources/issues.json b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/resources/issues.json new file mode 100644 index 00000000..d99eb9f3 --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/resources/issues.json @@ -0,0 +1 @@ +{"issues":[{"number":1,"votes":0,"created_at":"2010/02/02 22:58:39 -0800","body":"","title":"Test objective-c marshaling code","updated_at":"2010/02/02 22:58:39 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":2,"votes":0,"created_at":"2010/02/02 22:59:02 -0800","body":"","title":"Provide instructions for use","updated_at":"2010/02/02 22:59:02 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":3,"votes":0,"created_at":"2010/02/02 22:59:26 -0800","body":"","title":"add support for JSON marshalling","updated_at":"2010/02/04 17:56:02 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":4,"votes":0,"created_at":"2010/02/02 22:59:45 -0800","body":"","title":"provide working sample project","updated_at":"2010/02/02 22:59:45 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":5,"votes":0,"created_at":"2010/02/02 23:00:19 -0800","body":"","title":"support object inheritance","updated_at":"2010/02/02 23:00:19 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":6,"votes":0,"created_at":"2010/02/02 23:00:37 -0800","body":"","title":"provide support for nested types","updated_at":"2010/02/02 23:00:37 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":7,"votes":0,"created_at":"2010/02/02 23:00:49 -0800","body":"","title":"client enum support","updated_at":"2010/02/02 23:00:49 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":8,"votes":0,"created_at":"2010/02/02 23:01:09 -0800","body":"","title":"refactor templates to use field iterator","updated_at":"2010/02/02 23:01:09 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":9,"votes":0,"created_at":"2010/02/02 23:01:35 -0800","body":"","title":"wiki should explain target architecture","updated_at":"2010/02/02 23:01:35 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"},{"number":10,"votes":0,"created_at":"2010/02/04 21:03:54 -0800","body":"test description 2 ","title":"test issue for testing mylyn github connector2","updated_at":"2010/02/04 21:09:37 -0800","closed_at":null,"user":"dgreen99","labels":[],"state":"open"}]}
\ No newline at end of file diff --git a/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/ui/GitHubRepositoryConnectorUITest.java b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/ui/GitHubRepositoryConnectorUITest.java new file mode 100644 index 00000000..fe58f09e --- /dev/null +++ b/org.eclipse.mylyn.github.tests/src/org/eclipse/mylyn/github/tests/ui/GitHubRepositoryConnectorUITest.java @@ -0,0 +1,41 @@ +package org.eclipse.mylyn.github.tests.ui; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertTrue; +import junit.framework.Assert; + +import org.eclipse.jface.text.Region; +import org.eclipse.jface.text.hyperlink.IHyperlink; +import org.eclipse.mylyn.github.internal.GitHub; +import org.eclipse.mylyn.github.ui.internal.GitHubRepositoryConnectorUI; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.ui.TaskHyperlink; +import org.junit.Before; +import org.junit.Test; + +public class GitHubRepositoryConnectorUITest { + + private GitHubRepositoryConnectorUI connectorUI; + private TaskRepository repository; + + @Before + public void before() { + connectorUI = new GitHubRepositoryConnectorUI(); + repository = new TaskRepository(GitHub.CONNECTOR_KIND, GitHub.createGitHubUrl("foo", "bar")); + } + + @Test + public void testFindHyperlinksTaskRepositoryStringIntInt() { + IHyperlink[] hyperlinks = connectorUI.findHyperlinks(repository, "one #2 three", -1, 0); + assertNotNull(hyperlinks); + assertEquals(1,hyperlinks.length); + assertEquals(new Region(4,2),hyperlinks[0].getHyperlinkRegion()); + + hyperlinks = connectorUI.findHyperlinks(repository, "one #2 three", -1, 4); + assertNotNull(hyperlinks); + assertEquals(1,hyperlinks.length); + assertEquals(new Region(8,2),hyperlinks[0].getHyperlinkRegion()); + } + +} |