Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ec17c1d

Browse filesBrowse files
committed
Update PullRequestTest for WireMocking
1 parent 8d6daef commit ec17c1d
Copy full SHA for ec17c1d

File tree

Expand file treeCollapse file tree

1 file changed

+73
-54
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+73
-54
lines changed
+73-54Lines changed: 73 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.kohsuke.github;
22

33
import org.junit.After;
4+
import org.junit.Before;
45
import org.junit.Test;
56

67
import java.io.IOException;
@@ -12,29 +13,42 @@
1213
/**
1314
* @author Kohsuke Kawaguchi
1415
*/
15-
public class PullRequestTest extends AbstractGitHubApiTestBase {
16+
public class PullRequestTest extends AbstractGitHubApiWireMockTest {
17+
1618
@Test
1719
public void createPullRequest() throws Exception {
18-
String name = rnd.next();
19-
GHPullRequest p = getRepository().createPullRequest(name, "stable", "master", "## test");
20+
String name = "createPullRequest";
21+
GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "master", "## test");
2022
System.out.println(p.getUrl());
2123
assertEquals(name, p.getTitle());
2224
}
2325

2426
@Test
2527
public void createPullRequestComment() throws Exception {
26-
String name = rnd.next();
27-
GHPullRequest p = getRepository().createPullRequest(name, "stable", "master", "## test");
28+
String name = "createPullRequestComment";
29+
GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "master", "## test");
2830
p.comment("Some comment");
2931
}
3032

33+
@Test
34+
public void closePullRequest() throws Exception {
35+
String name = "closePullRequest";
36+
GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "master", "## test");
37+
System.out.println(p.getUrl());
38+
assertEquals(name, p.getTitle());
39+
assertEquals(GHIssueState.OPEN, getRepository().getPullRequest(p.getNumber()).getState());
40+
p.close();
41+
assertEquals(GHIssueState.CLOSED, getRepository().getPullRequest(p.getNumber()).getState());
42+
}
43+
44+
3145
@Test
32-
public void testPullRequestReviews() throws Exception {
33-
String name = rnd.next();
34-
GHPullRequest p = getRepository().createPullRequest(name, "stable", "master", "## test");
46+
public void pullRequestReviews() throws Exception {
47+
String name = "testPullRequestReviews";
48+
GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "master", "## test");
3549
GHPullRequestReview draftReview = p.createReview()
3650
.body("Some draft review")
37-
.comment("Some niggle", "changelog.html", 1)
51+
.comment("Some niggle", "README.md", 1)
3852
.create();
3953
assertThat(draftReview.getState(), is(GHPullRequestReviewState.PENDING));
4054
assertThat(draftReview.getBody(), is("Some draft review"));
@@ -52,18 +66,18 @@ public void testPullRequestReviews() throws Exception {
5266
assertEquals("Some niggle", comment.getBody());
5367
draftReview = p.createReview()
5468
.body("Some new review")
55-
.comment("Some niggle", "changelog.html", 1)
69+
.comment("Some niggle", "README.md", 1)
5670
.create();
5771
draftReview.delete();
5872
}
5973

6074
@Test
61-
public void testPullRequestReviewComments() throws Exception {
62-
String name = rnd.next();
63-
GHPullRequest p = getRepository().createPullRequest(name, "stable", "master", "## test");
75+
public void pullRequestReviewComments() throws Exception {
76+
String name = "pullRequestReviewComments";
77+
GHPullRequest p = getRepository().createPullRequest(name, "test/stable", "master", "## test");
6478
System.out.println(p.getUrl());
6579
assertTrue(p.listReviewComments().asList().isEmpty());
66-
p.createReviewComment("Sample review comment", p.getHead().getSha(), "cli/pom.xml", 5);
80+
p.createReviewComment("Sample review comment", p.getHead().getSha(), "README.md", 1);
6781
List<GHPullRequestReviewComment> comments = p.listReviewComments().asList();
6882
assertEquals(1, comments.size());
6983
GHPullRequestReviewComment comment = comments.get(0);
@@ -81,93 +95,98 @@ public void testPullRequestReviewComments() throws Exception {
8195
}
8296

8397
@Test
84-
public void testMergeCommitSHA() throws Exception {
85-
String name = rnd.next();
86-
GHPullRequest p = getRepository().createPullRequest(name, "mergeable-branch", "master", "## test");
87-
for (int i=0; i<100; i++) {
98+
public void mergeCommitSHA() throws Exception {
99+
String name = "mergeCommitSHA";
100+
GHPullRequest p = getRepository().createPullRequest(name, "test/mergeable_branch", "master", "## test");
101+
p.getMergeable();
102+
// mergeability computation takes time. give it more chance
103+
Thread.sleep(1000);
104+
for (int i=0; i<10; i++) {
88105
GHPullRequest updated = getRepository().getPullRequest(p.getNumber());
89-
if (updated.getMergeCommitSha()!=null) {
106+
if (updated.getMergeable() && updated.getMergeCommitSha()!=null) {
90107
// make sure commit exists
91108
GHCommit commit = getRepository().getCommit(updated.getMergeCommitSha());
92109
assertNotNull(commit);
93110
return;
94111
}
95112

96113
// mergeability computation takes time. give it more chance
97-
Thread.sleep(100);
114+
Thread.sleep(1000);
98115
}
99116
// hmm?
100117
fail();
101118
}
102119

103120
@Test
104-
public void testSquashMerge() throws Exception {
105-
String name = rnd.next();
121+
public void squashMerge() throws Exception {
122+
String name = "squashMerge";
123+
String branchName = "test/" + name;
106124
GHRef masterRef = getRepository().getRef("heads/master");
107-
GHRef branchRef = getRepository().createRef("refs/heads/" + name, masterRef.getObject().getSha());
125+
GHRef branchRef = getRepository().createRef("refs/heads/" + branchName, masterRef.getObject().getSha());
108126

109-
getRepository().createContent(name, name, name, name);
127+
getRepository().createContent(name, name, name, branchName);
110128
Thread.sleep(1000);
111-
GHPullRequest p = getRepository().createPullRequest(name, name, "master", "## test squash");
129+
GHPullRequest p = getRepository().createPullRequest(name, branchName, "master", "## test squash");
112130
Thread.sleep(1000);
113131
p.merge("squash merge", null, GHPullRequest.MergeMethod.SQUASH);
114-
branchRef.delete();
115132
}
133+
116134
@Test
117-
public void testUpdateContentSquashMerge() throws Exception {
118-
String name = rnd.next();
135+
public void updateContentSquashMerge() throws Exception {
136+
String name = "updateContentSquashMerge";
137+
String branchName = "test/" + name;
138+
119139
GHRef masterRef = getRepository().getRef("heads/master");
120-
GHRef branchRef = getRepository().createRef("refs/heads/" + name, masterRef.getObject().getSha());
140+
GHRef branchRef = getRepository().createRef("refs/heads/" + branchName, masterRef.getObject().getSha());
121141

122-
GHContentUpdateResponse response = getRepository().createContent(name, name, name, name);
142+
GHContentUpdateResponse response = getRepository().createContent(name, name, name, branchName);
123143
Thread.sleep(1000);
124144

125145
getRepository().createContent()
126-
.content(name + name)
127-
.path(name)
128-
.branch(name)
129-
.message(name)
130-
.sha(response.getContent().getSha())
131-
.commit();
132-
GHPullRequest p = getRepository().createPullRequest(name, name, "master", "## test squash");
146+
.content(name + name)
147+
.path(name)
148+
.branch(branchName)
149+
.message(name)
150+
.sha(response.getContent().getSha())
151+
.commit();
152+
GHPullRequest p = getRepository().createPullRequest(name, branchName, "master", "## test squash");
133153
Thread.sleep(1000);
134154
p.merge("squash merge", null, GHPullRequest.MergeMethod.SQUASH);
135-
branchRef.delete();
136155
}
137156

138157
@Test
139-
public void testQueryPullRequestsQualifiedHead() throws Exception {
158+
public void queryPullRequestsQualifiedHead() throws Exception {
140159
GHRepository repo = getRepository();
141160
// Create PRs from two different branches to master
142-
repo.createPullRequest(rnd.next(), "stable", "master", null);
143-
repo.createPullRequest(rnd.next(), "rc", "master", null);
161+
repo.createPullRequest("queryPullRequestsQualifiedHead_stable", "test/stable", "master", null);
162+
repo.createPullRequest("queryPullRequestsQualifiedHead_rc", "test/rc", "master", null);
144163

145164
// Query by one of the heads and make sure we only get that branch's PR back.
146-
List<GHPullRequest> prs = repo.queryPullRequests().state(GHIssueState.OPEN).head("github-api-test-org:stable").base("master").list().asList();
165+
List<GHPullRequest> prs = repo.queryPullRequests().state(GHIssueState.OPEN).head("github-api-test-org:test/stable").base("master").list().asList();
147166
assertNotNull(prs);
148167
assertEquals(1, prs.size());
149-
assertEquals("stable", prs.get(0).getHead().getRef());
168+
assertEquals("test/stable", prs.get(0).getHead().getRef());
150169
}
151170

152171
@Test
153-
public void testQueryPullRequestsUnqualifiedHead() throws Exception {
172+
public void queryPullRequestsUnqualifiedHead() throws Exception {
154173
GHRepository repo = getRepository();
155174
// Create PRs from two different branches to master
156-
repo.createPullRequest(rnd.next(), "stable", "master", null);
157-
repo.createPullRequest(rnd.next(), "rc", "master", null);
175+
repo.createPullRequest("queryPullRequestsUnqualifiedHead_stable", "test/stable", "master", null);
176+
repo.createPullRequest("queryPullRequestsUnqualifiedHead_rc", "test/rc", "master", null);
158177

159178
// Query by one of the heads and make sure we only get that branch's PR back.
160-
List<GHPullRequest> prs = repo.queryPullRequests().state(GHIssueState.OPEN).head("stable").base("master").list().asList();
179+
List<GHPullRequest> prs = repo.queryPullRequests().state(GHIssueState.OPEN).head("test/stable").base("master").list().asList();
161180
assertNotNull(prs);
162181
assertEquals(1, prs.size());
163-
assertEquals("stable", prs.get(0).getHead().getRef());
182+
assertEquals("test/stable", prs.get(0).getHead().getRef());
164183
}
165184

166185
@Test
167186
// Requires push access to the test repo to pass
168187
public void setLabels() throws Exception {
169-
GHPullRequest p = getRepository().createPullRequest(rnd.next(), "stable", "master", "## test");
170-
String label = rnd.next();
188+
GHPullRequest p = getRepository().createPullRequest("setLabels", "test/stable", "master", "## test");
189+
String label = "setLabels_label_name";
171190
p.setLabels(label);
172191

173192
Collection<GHLabel> labels = getRepository().getPullRequest(p.getNumber()).getLabels();
@@ -178,16 +197,16 @@ public void setLabels() throws Exception {
178197
@Test
179198
// Requires push access to the test repo to pass
180199
public void setAssignee() throws Exception {
181-
GHPullRequest p = getRepository().createPullRequest(rnd.next(), "stable", "master", "## test");
200+
GHPullRequest p = getRepository().createPullRequest("setAssignee", "test/stable", "master", "## test");
182201
GHMyself user = gitHub.getMyself();
183202
p.assignTo(user);
184203

185204
assertEquals(user, getRepository().getPullRequest(p.getNumber()).getAssignee());
186205
}
187206

188207
@Test
189-
public void testGetUser() throws IOException {
190-
GHPullRequest p = getRepository().createPullRequest(rnd.next(), "stable", "master", "## test");
208+
public void getUser() throws IOException {
209+
GHPullRequest p = getRepository().createPullRequest("getUser", "test/stable", "master", "## test");
191210
GHPullRequest prSingle = getRepository().getPullRequest(p.getNumber());
192211
assertNotNull(prSingle.getUser().root);
193212
prSingle.getMergeable();
@@ -209,6 +228,6 @@ public void cleanUp() throws Exception {
209228
}
210229

211230
private GHRepository getRepository() throws IOException {
212-
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
231+
return gitHub.getOrganization("github-api-test-org").getRepository("github-api");
213232
}
214233
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.