Skip to content

Commit 552edf8

Browse files
committed
Switch to WireMockMultiServerRule as base
1 parent 41c5164 commit 552edf8

21 files changed

Lines changed: 552 additions & 287 deletions

src/test/java/org/kohsuke/github/AbstractGitHubApiTestBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
/**
1818
* @author Kohsuke Kawaguchi
1919
*/
20-
public abstract class AbstractGitHubApiTestBase extends AbstractGitHubApiWireMockTest {
20+
public abstract class AbstractGitHubApiTestBase extends AbstractGitHubWireMockTest {
2121

2222
@Before
2323
public void setUp() throws Exception {
24-
assumeTrue("All tests inheriting from this class are not guaranteed to work without proxy", githubApi.isUseProxy());
24+
assumeTrue("All tests inheriting from this class are not guaranteed to work without proxy", mockGitHub.isUseProxy());
2525
}
2626

2727
protected void kohsuke() {

src/test/java/org/kohsuke/github/AbstractGitHubApiWireMockTest.java renamed to src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
11
package org.kohsuke.github;
22

3-
import com.github.tomakehurst.wiremock.common.FileSource;
43
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
5-
import com.github.tomakehurst.wiremock.extension.Parameters;
6-
import com.github.tomakehurst.wiremock.extension.ResponseTransformer;
7-
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
8-
import com.github.tomakehurst.wiremock.http.Request;
9-
import com.github.tomakehurst.wiremock.http.Response;
104
import org.apache.commons.io.IOUtils;
11-
import org.junit.After;
125
import org.junit.Assert;
136
import org.junit.Before;
147
import org.junit.Rule;
15-
import org.junit.rules.TestWatcher;
16-
import org.kohsuke.github.junit.GitHubApiWireMockRule;
17-
import org.kohsuke.github.junit.WireMockRule;
8+
import org.kohsuke.github.junit.GitHubWireMockRule;
189

1910
import java.io.File;
2011
import java.io.FileInputStream;
2112
import java.io.IOException;
2213
import java.util.Properties;
2314

24-
import static com.github.tomakehurst.wiremock.client.WireMock.*;
2515
import static org.junit.Assume.assumeFalse;
2616
import static org.junit.Assume.assumeTrue;
2717

2818
/**
2919
* @author Liam Newman
3020
*/
31-
public abstract class AbstractGitHubApiWireMockTest extends Assert {
21+
public abstract class AbstractGitHubWireMockTest extends Assert {
3222

3323
private final GitHubBuilder githubBuilder = createGitHubBuilder();
3424

@@ -56,10 +46,10 @@ public abstract class AbstractGitHubApiWireMockTest extends Assert {
5646
protected final String baseRecordPath = "src/test/resources/" + baseFilesClassPath + "/wiremock";
5747

5848
@Rule
59-
public final GitHubApiWireMockRule githubApi;
49+
public final GitHubWireMockRule mockGitHub;
6050

61-
public AbstractGitHubApiWireMockTest() {
62-
githubApi = new GitHubApiWireMockRule(
51+
public AbstractGitHubWireMockTest() {
52+
mockGitHub = new GitHubWireMockRule(
6353
this.getWireMockOptions()
6454
);
6555
}
@@ -103,7 +93,7 @@ private static GitHubBuilder createGitHubBuilder() {
10393
protected GitHubBuilder getGitHubBuilder() {
10494
GitHubBuilder builder = githubBuilder.clone();
10595

106-
if (!githubApi.isUseProxy()) {
96+
if (!mockGitHub.isUseProxy()) {
10797
// This sets the user and password to a placeholder for wiremock testing
10898
// This makes the tests believe they are running with permissions
10999
// The recorded stubs will behave like they running with permissions
@@ -117,14 +107,14 @@ protected GitHubBuilder getGitHubBuilder() {
117107
@Before
118108
public void wireMockSetup() throws Exception {
119109
GitHubBuilder builder = getGitHubBuilder()
120-
.withEndpoint(githubApi.baseUrl());
110+
.withEndpoint(mockGitHub.apiServer().baseUrl());
121111

122112
if (useDefaultGitHub) {
123113
gitHub = builder
124114
.build();
125115
}
126116

127-
if (githubApi.isUseProxy()) {
117+
if (mockGitHub.isUseProxy()) {
128118
gitHubBeforeAfter = getGitHubBuilder()
129119
.withEndpoint("https://api.github.com/")
130120
.build();
@@ -134,11 +124,11 @@ public void wireMockSetup() throws Exception {
134124
}
135125

136126
protected void snapshotNotAllowed() {
137-
assumeFalse("Test contains hand written mappings. Only valid when not taking a snapshot.", githubApi.isTakeSnapshot());
127+
assumeFalse("Test contains hand written mappings. Only valid when not taking a snapshot.", mockGitHub.isTakeSnapshot());
138128
}
139129

140130
protected void requireProxy(String reason) {
141-
assumeTrue("Test only valid when proxying (-Dtest.github.useProxy to enable): " + reason, githubApi.isUseProxy());
131+
assumeTrue("Test only valid when proxying (-Dtest.github.useProxy to enable): " + reason, mockGitHub.isUseProxy());
142132
}
143133

144134
protected GHUser getUser() {

src/test/java/org/kohsuke/github/AppTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Unit test for simple App.
2626
*/
27-
public class AppTest extends AbstractGitHubApiWireMockTest {
27+
public class AppTest extends AbstractGitHubWireMockTest {
2828
static final String GITHUB_API_TEST_REPO = "github-api-test";
2929

3030
private String getTestRepositoryName() throws IOException {
@@ -59,15 +59,15 @@ public void testRepositoryWithAutoInitializationCRUD() throws Exception {
5959
r.enableIssueTracker(false);
6060
r.enableDownloads(false);
6161
r.enableWiki(false);
62-
if (githubApi.isUseProxy()) {
62+
if (mockGitHub.isUseProxy()) {
6363
Thread.sleep(3000);
6464
}
6565
assertNotNull(r.getReadme());
6666
getUser().getRepository(name).delete();
6767
}
6868

6969
private void cleanupRepository(final String name) throws IOException {
70-
if (githubApi.isUseProxy()) {
70+
if (mockGitHub.isUseProxy()) {
7171
GHRepository repository = getUser(gitHubBeforeAfter).getRepository(name);
7272
if (repository != null) {
7373
repository.delete();
@@ -154,7 +154,7 @@ public void testGetIssues() throws Exception {
154154

155155

156156
private GHRepository getTestRepository() throws IOException {
157-
if (githubApi.isUseProxy()) {
157+
if (mockGitHub.isUseProxy()) {
158158
GHRepository repository = gitHubBeforeAfter
159159
.getOrganization(GITHUB_API_TEST_ORG)
160160
.getRepository(GITHUB_API_TEST_REPO);
@@ -460,7 +460,7 @@ public void tryHook() throws Exception {
460460
GHHook hook = r.createWebHook(new URL("http://www.google.com/"));
461461
System.out.println(hook);
462462

463-
if (githubApi.isUseProxy()) {
463+
if (mockGitHub.isUseProxy()) {
464464
r = gitHubBeforeAfter.getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api");
465465
for (GHHook h : r.getHooks()) {
466466
h.delete();

src/test/java/org/kohsuke/github/CommitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* @author Kohsuke Kawaguchi
1010
*/
11-
public class CommitTest extends AbstractGitHubApiWireMockTest {
11+
public class CommitTest extends AbstractGitHubWireMockTest {
1212
@Test // issue 152
1313
public void lastStatus() throws IOException {
1414
GHTag t = gitHub.getRepository("stapler/stapler").listTags().iterator().next();

src/test/java/org/kohsuke/github/GHAppTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* @author Paulo Miguel Almeida
1717
*/
18-
public class GHAppTest extends AbstractGitHubApiWireMockTest {
18+
public class GHAppTest extends AbstractGitHubWireMockTest {
1919

2020
protected GitHubBuilder getGitHubBuilder() {
2121
return super.getGitHubBuilder()

src/test/java/org/kohsuke/github/GHOrganizationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import java.io.IOException;
88

9-
public class GHOrganizationTest extends AbstractGitHubApiWireMockTest {
9+
public class GHOrganizationTest extends AbstractGitHubWireMockTest {
1010

1111
public static final String GITHUB_API_TEST = "github-api-test";
1212

@@ -36,7 +36,7 @@ public void testCreateRepositoryWithAutoInitialization() throws IOException {
3636

3737
@After
3838
public void cleanUp() throws IOException {
39-
if (githubApi.isUseProxy()) {
39+
if (mockGitHub.isUseProxy()) {
4040
GHRepository repository = gitHubBeforeAfter.getOrganization(GITHUB_API_TEST_ORG).getRepository(GITHUB_API_TEST);
4141
if (repository != null) {
4242
repository.delete();

src/test/java/org/kohsuke/github/GHProjectCardTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* @author Gunnar Skjold
1313
*/
14-
public class GHProjectCardTest extends AbstractGitHubApiWireMockTest {
14+
public class GHProjectCardTest extends AbstractGitHubWireMockTest {
1515
private GHOrganization org;
1616
private GHProject project;
1717
private GHProjectColumn column;
@@ -72,7 +72,7 @@ public void testDeleteCard() throws IOException {
7272

7373
@After
7474
public void after() throws IOException {
75-
if(githubApi.isUseProxy()) {
75+
if(mockGitHub.isUseProxy()) {
7676
if (card != null) {
7777
card = gitHubBeforeAfter.getProjectCard(card.getId());
7878
try {

src/test/java/org/kohsuke/github/GHProjectColumnTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* @author Gunnar Skjold
1313
*/
14-
public class GHProjectColumnTest extends AbstractGitHubApiWireMockTest {
14+
public class GHProjectColumnTest extends AbstractGitHubWireMockTest {
1515
private GHProject project;
1616
private GHProjectColumn column;
1717

@@ -48,7 +48,7 @@ public void testDeleteColumn() throws IOException {
4848

4949
@After
5050
public void after() throws IOException {
51-
if(githubApi.isUseProxy()) {
51+
if(mockGitHub.isUseProxy()) {
5252
if (column != null) {
5353
column = gitHubBeforeAfter
5454
.getProjectColumn(column.getId());

src/test/java/org/kohsuke/github/GHProjectTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* @author Gunnar Skjold
1313
*/
14-
public class GHProjectTest extends AbstractGitHubApiWireMockTest {
14+
public class GHProjectTest extends AbstractGitHubWireMockTest {
1515
private GHProject project;
1616

1717
@Before
@@ -69,7 +69,7 @@ public void testDeleteProject() throws IOException {
6969

7070
@After
7171
public void after() throws IOException {
72-
if (githubApi.isUseProxy()) {
72+
if (mockGitHub.isUseProxy()) {
7373
if (project != null) {
7474
project = gitHubBeforeAfter
7575
.getProject(project.getId());

src/test/java/org/kohsuke/github/GHPullRequestTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
/**
1414
* @author Kohsuke Kawaguchi
1515
*/
16-
public class GHPullRequestTest extends AbstractGitHubApiWireMockTest {
16+
public class GHPullRequestTest extends AbstractGitHubWireMockTest {
1717

1818
@Before
1919
@After
2020
public void cleanUp() throws Exception {
2121
// Cleanup is only needed when proxying
22-
if (!githubApi.isUseProxy()) {
22+
if (!mockGitHub.isUseProxy()) {
2323
return;
2424
}
2525

0 commit comments

Comments
 (0)