Skip to content

Commit 0c6e2e3

Browse files
committed
chore: test clients with WireMock
1 parent 319253e commit 0c6e2e3

File tree

8 files changed

+228
-223
lines changed

8 files changed

+228
-223
lines changed

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@ dependencies {
2323

2424
testImplementation 'org.slf4j:slf4j-simple:2.0.17'
2525
testImplementation "org.junit.jupiter:junit-jupiter:5.13.4"
26-
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
26+
testRuntimeOnly "org.junit.platform:junit-platform-launcher:1.13.4"
2727
testImplementation 'org.assertj:assertj-core:3.27.6'
2828
testImplementation 'com.approvaltests:approvaltests:25.4.3'
2929
testImplementation 'org.mockito:mockito-core:5.20.0'
30+
testImplementation 'org.wiremock:wiremock-standalone:3.13.1'
3031
}
3132

3233
test {
3334
useJUnitPlatform()
3435
}
3536

36-
sourceCompatibility=17
37-
targetCompatibility=17
37+
javaExtension {
38+
javaVersion = 17
39+
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ pluginManagement {
77
}
88

99
plugins {
10-
id "se.bjurr.gradle.bundle-jar" version "1.1.2" apply false
10+
id "se.bjurr.gradle.bundle-jar" version "latest-SNAPSHOT" apply false
1111
}

src/test/java/se/bjurr/gitchangelog/internal/integrations/jira/JiraClientIntegrationTest.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/test/java/se/bjurr/gitchangelog/internal/integrations/jira/JiraClientTest.java

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package se.bjurr.gitchangelog.internal.integrations.jira;
2+
3+
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
4+
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
5+
import static com.github.tomakehurst.wiremock.client.WireMock.get;
6+
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
import com.github.tomakehurst.wiremock.WireMockServer;
10+
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
11+
import java.util.Optional;
12+
import org.junit.jupiter.api.AfterEach;
13+
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.Test;
15+
import se.bjurr.gitchangelog.api.exceptions.GitChangelogIntegrationException;
16+
17+
public class JiraClientWireMockTest {
18+
19+
private WireMockServer wireMockServer;
20+
private DefaultJiraClient jiraClient;
21+
private String baseUrl;
22+
23+
@BeforeEach
24+
public void setUp() {
25+
wireMockServer = new WireMockServer(WireMockConfiguration.options().dynamicPort());
26+
wireMockServer.start();
27+
baseUrl = "http://localhost:" + wireMockServer.port();
28+
jiraClient = new DefaultJiraClient(baseUrl);
29+
}
30+
31+
@AfterEach
32+
public void tearDown() {
33+
if (wireMockServer != null) {
34+
wireMockServer.stop();
35+
}
36+
}
37+
38+
@Test
39+
public void testGetIssueSuccess() throws GitChangelogIntegrationException {
40+
String mockResponse =
41+
"""
42+
{
43+
"key": "TEST-123",
44+
"fields": {
45+
"summary": "Test Summary",
46+
"description": "Test Description",
47+
"issuetype": {"name": "Bug"},
48+
"labels": ["test"],
49+
"parent": null,
50+
"issuelinks": []
51+
}
52+
}
53+
""";
54+
55+
wireMockServer.stubFor(
56+
get(urlPathEqualTo("/rest/api/2/issue/TEST-123"))
57+
.withQueryParam(
58+
"fields", equalTo("parent,summary,issuetype,labels,description,issuelinks"))
59+
.willReturn(
60+
aResponse()
61+
.withStatus(200)
62+
.withHeader("Content-Type", "application/json")
63+
.withBody(mockResponse)));
64+
65+
Optional<JiraIssue> result = jiraClient.getIssue("TEST-123");
66+
67+
assertThat(result).isPresent();
68+
JiraIssue issue = result.get();
69+
assertThat(issue.getIssue()).isEqualTo("TEST-123");
70+
assertThat(issue.getTitle()).isEqualTo("Test Summary");
71+
assertThat(issue.getDescription()).isEqualTo("Test Description");
72+
assertThat(issue.getIssueType()).isEqualTo("Bug");
73+
assertThat(issue.getLink()).isEqualTo(baseUrl + "/browse/TEST-123");
74+
}
75+
76+
@Test
77+
public void testGetIssueNotFound() throws GitChangelogIntegrationException {
78+
wireMockServer.stubFor(
79+
get(urlPathEqualTo("/rest/api/2/issue/NOTFOUND-123"))
80+
.willReturn(aResponse().withStatus(404).withBody("Issue not found")));
81+
82+
Optional<JiraIssue> result = jiraClient.getIssue("NOTFOUND-123");
83+
84+
assertThat(result).isEmpty();
85+
}
86+
87+
@Test
88+
public void testGetIssueServerError() throws GitChangelogIntegrationException {
89+
wireMockServer.stubFor(
90+
get(urlPathEqualTo("/rest/api/2/issue/ERROR-123"))
91+
.willReturn(aResponse().withStatus(500).withBody("Internal Server Error")));
92+
93+
Optional<JiraIssue> result = jiraClient.getIssue("ERROR-123");
94+
95+
assertThat(result).isEmpty();
96+
}
97+
}

src/test/java/se/bjurr/gitchangelog/internal/integrations/redmine/RedmineClientIntegrationTest.java

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/test/java/se/bjurr/gitchangelog/internal/integrations/redmine/RedmineClientTest.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)