Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e8c0a70f94a6d7259d4a0c11c097f547a08a29ae (plain) (blame)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*******************************************************************************
 *  Copyright (c) 2011 GitHub Inc.
 *  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:
 *    Kevin Sawicki (GitHub Inc.) - initial API and implementation
 *******************************************************************************/
package org.eclipse.egit.github.core.tests.live;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.egit.github.core.Issue;
import org.eclipse.egit.github.core.IssueEvent;
import org.eclipse.egit.github.core.RepositoryIssue;
import org.eclipse.egit.github.core.client.PageIterator;
import org.eclipse.egit.github.core.service.IssueService;
import org.junit.Test;

/**
 * Unit tests of {@link IssueService}
 */
public class IssueTest extends LiveTest {

	/**
	 * Test fetching an issue
	 *
	 * @throws IOException
	 */
	@Test
	public void fetchIssue() throws IOException {
		IssueService service = new IssueService(client);
		Issue issue = service.getIssue("schacon", "showoff", "1");
		assertNotNull(issue);
		assertNotNull(issue.getUpdatedAt());
		assertNotNull(issue.getCreatedAt());
		assertTrue(issue.getNumber() > 0);
		assertNotNull(issue.getBody());
		assertNotNull(issue.getTitle());
		assertNotNull(issue.getHtmlUrl());
		assertTrue(issue.getNumber() >= 0);
		assertNotNull(issue.getUser());
	}

	/**
	 * Test issue events
	 *
	 * @throws IOException
	 */
	@Test
	public void getIssueEvents() throws IOException {
		IssueService service = new IssueService(client);
		PageIterator<IssueEvent> iter = service.pageIssueEvents("schacon",
				"showoff", 1);
		assertNotNull(iter);
		assertTrue(iter.hasNext());
		for (Collection<IssueEvent> page : iter) {
			assertNotNull(page);
			assertFalse(page.isEmpty());
			for (IssueEvent event : page) {
				assertNotNull(event);
				assertTrue(event.getId() > 0);
				assertNotNull(event.getActor());
				if (event.getIssue() != null)
					assertTrue(event.getIssue().getNumber() > 0);
				assertNotNull(event.getCreatedAt());
				assertNotNull(event.getEvent());
				assertNotNull(event.getUrl());
				IssueEvent fetched = service.getIssueEvent("schacon",
						"showoff", event.getId());
				assertNotNull(fetched);
				assertEquals(event.getId(), fetched.getId());
				assertNotNull(fetched.getActor());
				assertEquals(event.getActor().getLogin(), fetched.getActor()
						.getLogin());
				if (event.getCommitId() != null)
					assertEquals(event.getCommitId(), fetched.getCommitId());
				assertEquals(event.getCreatedAt(), fetched.getCreatedAt());
				assertEquals(event.getEvent(), fetched.getEvent());
				assertEquals(event.getUrl(), fetched.getUrl());
			}
		}
	}

	/**
	 * Get single page of repository issue events
	 *
	 * @throws IOException
	 */
	@Test
	public void pageAllIssueEvents() throws IOException {
		IssueService service = new IssueService(client);
		PageIterator<IssueEvent> iter = service.pageEvents("schacon",
				"showoff", 10);
		assertNotNull(iter);
		assertTrue(iter.hasNext());
		Collection<IssueEvent> firstPage = iter.next();
		assertNotNull(firstPage);
		assertFalse(firstPage.isEmpty());
		for (IssueEvent event : firstPage) {
			assertNotNull(event);
			assertTrue(event.getId() > 0);
			assertNotNull(event.getActor());
			assertNotNull(event.getCreatedAt());
			assertNotNull(event.getEvent());
			assertNotNull(event.getUrl());
		}
	}

	/**
	 * Test fetching multiple issues
	 *
	 * @throws IOException
	 */
	@Test
	public void fetchAllIssues() throws IOException {
		IssueService service = new IssueService(client);
		List<Issue> issues = service.getIssues("schacon", "showoff",
				Collections.singletonMap(IssueService.FILTER_STATE,
						IssueService.STATE_OPEN));
		assertFalse(issues.isEmpty());
		for (Issue issue : issues)
			assertNotNull(issue);
	}

	/**
	 * Test paging of requests
	 *
	 * @throws Exception
	 */
	@Test
	public void testPaging() throws Exception {
		IssueService service = new IssueService(client);
		Map<String, String> params = new HashMap<String, String>();
		params.put(IssueService.FILTER_STATE, IssueService.STATE_CLOSED);
		PageIterator<Issue> iterator = service.pageIssues("schacon", "showoff",
				params, 1);
		assertNotNull(iterator);
		assertTrue(iterator.hasNext());
		Collection<Issue> page = iterator.next();
		int pages = iterator.getLastPage();
		int read = 1;
		assertNotNull(page);
		assertEquals(1, page.size());
		assertNotNull(iterator.getRequest());
		assertNotNull(iterator.getNextUri());
		assertTrue(iterator.getNextPage() > 1);
		assertNotNull(iterator.getLastUri());
		assertTrue(iterator.getLastPage() > iterator.getNextPage());
		assertTrue(iterator.hasNext());
		Collection<Issue> page2 = iterator.next();
		read++;
		assertNotNull(page2);
		assertFalse(page.equals(page2));
		while (iterator.hasNext()) {
			iterator.next();
			read++;
		}
		assertEquals(pages, read);
	}

	/**
	 * Testing page current user's issues
	 *
	 * @throws Exception
	 */
	@Test
	public void pageCurrentUsersIssues() throws Exception {
		checkUser();
		IssueService service = new IssueService(client);
		Collection<RepositoryIssue> issues = service.pageIssues(null, 1).next();
		assertNotNull(issues);
		assertEquals(1, issues.size());
		assertNotNull(issues.toArray()[0]);
	}
}

Back to the top