1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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);
}
}
|