Skip to content

Commit b43803a

Browse files
committedFeb 27, 2025
test(reporter): Add a Jira REST API client test
This test is using the actual Jira REST API client which allors to test if the JavaEE integration is working properly. Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.com>
1 parent b35f0e3 commit b43803a

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed
 

‎notifier/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ dependencies {
5050

5151
testImplementation(libs.greenmail)
5252
testImplementation(libs.mockk)
53+
testImplementation(libs.wiremock)
5354
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"id" : "676006f7-ac23-4e6f-859d-de24c7101492",
3+
"name" : "getissue",
4+
"request" : {
5+
"url" : "/rest/api/latest/issue/ISSUE-1?expand=schema%2Cnames%2Ctransitions",
6+
"method" : "GET"
7+
},
8+
"response" : {
9+
"status" : 200,
10+
"body" : "{ \"expand\": \"renderedFields,names,schema,transitions,operations,editmeta,changelog,versionedRepresentations\", \"id\": \"10000001\", \"self\": \"https://example.com/tracker01/rest/api/latest/issue/4008135\", \"key\": \"ISSUE-1\", \"fields\": { \"lastViewed\": \"2025-02-26T15:58:59.729+0100\", \"aggregatetimeoriginalestimate\": null, \"issuelinks\": [], \"assignee\": null, \"subtasks\": [], \"votes\": { \"self\": \"https://example.com/tracker01/rest/api/2/issue/ISSUE-1/votes\", \"votes\": 0, \"hasVoted\": false }, \"worklog\": { \"startAt\": 0, \"maxResults\": 20, \"total\": 0, \"worklogs\": [] }, \"issuetype\": { \"self\": \"https://example.com/tracker01/rest/api/2/issuetype/203\", \"id\": \"203\", \"description\": \"\", \"iconUrl\": \"https://example.com/tracker01/secure/viewavatar?size=xsmall&avatarId=22915&avatarType=issuetype\", \"name\": \"User Story\", \"subtask\": false, \"avatarId\": 22915 }, \"timetracking\": {}, \"environment\": null, \"duedate\": null, \"timeestimate\": null, \"status\": { \"self\": \"https://example.com/tracker01/rest/api/2/status/10036\", \"description\": \"\", \"iconUrl\": \"https://example.com/tracker01/images/icons/statuses/invisible.png\", \"name\": \"Backlog\", \"id\": \"10036\", \"statusCategory\": { \"self\": \"https://example.com/tracker01/rest/api/2/statuscategory/2\", \"id\": 2, \"key\": \"new\", \"colorName\": \"default\", \"name\": \"To Do\" } }, \"archiveddate\": null, \"aggregatetimeestimate\": null, \"creator\": { \"self\": \"https://example.com/tracker01/rest/api/2/user?username=John\", \"name\": \"John\", \"key\": \"john\", \"emailAddress\": \"John.Doe@example.com\", \"avatarUrls\": { \"48x48\": \"https://example.com/tracker01/secure/useravatar?ownerId=john&avatarId=53720\", \"24x24\": \"https://example.com/tracker01/secure/useravatar?size=small&ownerId=john&avatarId=53720\", \"16x16\": \"https://example.com/tracker01/secure/useravatar?size=xsmall&ownerId=john&avatarId=53720\", \"32x32\": \"https://example.com/tracker01/secure/useravatar?size=medium&ownerId=john&avatarId=53720\" }, \"displayName\": \"John Doe\", \"active\": true, \"timeZone\": \"Europe/Berlin\" }, \"timespent\": null, \"aggregatetimespent\": null, \"workratio\": -1, \"labels\": [ \"none\" ], \"components\": [], \"reporter\": { \"self\": \"https://example.com/tracker01/rest/api/2/user?username=JohnDoe\", \"name\": \"John\", \"key\": \"john\", \"emailAddress\": \"John.Doe@example.com\", \"avatarUrls\": { \"48x48\": \"https://example.com/tracker01/secure/useravatar?ownerId=john&avatarId=53720\", \"24x24\": \"https://example.com/tracker01/secure/useravatar?size=small&ownerId=john&avatarId=53720\", \"16x16\": \"https://example.com/tracker01/secure/useravatar?size=xsmall&ownerId=john&avatarId=53720\", \"32x32\": \"https://example.com/tracker01/secure/useravatar?size=medium&ownerId=john&avatarId=53720\" }, \"displayName\": \"John Doe\", \"active\": true, \"timeZone\": \"Europe/Berlin\" }, \"progress\": { \"progress\": 0, \"total\": 0 }, \"archivedby\": null, \"project\": { \"self\": \"https://example.com/tracker01/rest/api/2/project/56710\", \"id\": \"56710\", \"key\": \"EXAMPLEDEV\", \"name\": \"EXAMPLE Development\", \"projectTypeKey\": \"software\", \"avatarUrls\": { \"48x48\": \"https://example.com/tracker01/secure/projectavatar?pid=56710&avatarId=22801\", \"24x24\": \"https://example.com/tracker01/secure/projectavatar?size=small&pid=56710&avatarId=22801\", \"16x16\": \"https://example.com/tracker01/secure/projectavatar?size=xsmall&pid=56710&avatarId=22801\", \"32x32\": \"https://example.com/tracker01/secure/projectavatar?size=medium&pid=56710&avatarId=22801\" }, \"projectCategory\": { \"self\": \"https://example.com/tracker01/rest/api/2/projectCategory/19180\", \"id\": \"19180\", \"description\": \"EX\", \"name\": \"EX\" } }, \"resolutiondate\": null, \"watches\": { \"self\": \"https://example.com/tracker01/rest/api/2/issue/ISSUE-1/watchers\", \"watchCount\": 0, \"isWatching\": false }, \"updated\": \"2025-01-15T12:05:36.000+0100\", \"timeoriginalestimate\": null, \"description\": \"description.\", \"summary\": \"summary\", \"comment\": { \"comments\": [ ], \"maxResults\": 2, \"total\": 2, \"startAt\": 0 }, \"fixVersions\": [], \"priority\": { \"self\": \"https://example.com/tracker01/rest/api/2/priority/10000\", \"iconUrl\": \"https://example.com/tracker01/images/icons/priorities/major.svg\", \"name\": \"Medium\", \"id\": \"10000\" }, \"versions\": [], \"aggregateprogress\": { \"progress\": 0, \"total\": 0 }, \"created\": \"2024-05-16T06:53:58.000+0200\", \"attachment\": [ { \"self\": \"https://example.com/tracker01/rest/api/2/attachment/2111583\", \"id\": \"2111583\", \"filename\": \"htmlhelp.zip\", \"author\": { \"self\": \"https://example.com/tracker01/rest/api/2/user?username=JohnDoe\", \"name\": \"JohnDoe\", \"key\": \"john\", \"emailAddress\": \"John.Doe@example.com\", \"avatarUrls\": { \"48x48\": \"https://example.com/tracker01/secure/useravatar?ownerId=john&avatarId=53720\", \"24x24\": \"https://example.com/tracker01/secure/useravatar?size=small&ownerId=john&avatarId=53720\", \"16x16\": \"https://example.com/tracker01/secure/useravatar?size=xsmall&ownerId=john&avatarId=53720\", \"32x32\": \"https://example.com/tracker01/secure/useravatar?size=medium&ownerId=john&avatarId=53720\" }, \"displayName\": \"John Doe\", \"active\": true, \"timeZone\": \"Europe/Berlin\" }, \"created\": \"2024-05-16T06:56:35.000+0200\", \"size\": 44375587, \"mimeType\": \"application/zip\", \"content\": \"https://example.com/tracker01/secure/attachment/2111583/htmlhelp.zip\" }, { \"self\": \"https://example.com/tracker01/rest/api/2/attachment/2111579\", \"id\": \"2111579\", \"filename\": \"openapi3_1.yaml\", \"author\": { \"self\": \"https://example.com/tracker01/rest/api/2/user?username=JohnDoe\", \"name\": \"JohnDoe\", \"key\": \"john\", \"emailAddress\": \"John.Doe@example.com\", \"avatarUrls\": { \"48x48\": \"https://example.com/tracker01/secure/useravatar?ownerId=john&avatarId=53720\", \"24x24\": \"https://example.com/tracker01/secure/useravatar?size=small&ownerId=john&avatarId=53720\", \"16x16\": \"https://example.com/tracker01/secure/useravatar?size=xsmall&ownerId=john&avatarId=53720\", \"32x32\": \"https://example.com/tracker01/secure/useravatar?size=medium&ownerId=john&avatarId=53720\" }, \"displayName\": \"John Doe\", \"active\": true, \"timeZone\": \"Europe/Berlin\" }, \"created\": \"2024-05-16T06:55:54.000+0200\", \"size\": 632868, \"mimeType\": \"application/x-yaml\", \"content\": \"https://example.com/tracker01/secure/attachment/2111579/openapi3_1.yaml\" } ] }, \"names\": { \"resolution\": \"Resolution\", \"lastViewed\": \"Last Viewed\", \"aggregatetimeoriginalestimate\": \"Σ Original Estimate\", \"issuelinks\": \"Linked Issues\", \"assignee\": \"Assignee\", \"subtasks\": \"Sub-Tasks\", \"votes\": \"Votes\", \"worklog\": \"Log Work\", \"issuetype\": \"Issue Type\", \"timetracking\": \"Time Tracking\", \"environment\": \"Environment\", \"duedate\": \"Due Date\", \"timeestimate\": \"Remaining Estimate\", \"status\": \"Status\", \"archiveddate\": \"Archived\", \"aggregatetimeestimate\": \"Σ Remaining Estimate\", \"creator\": \"Creator\", \"timespent\": \"Time Spent\", \"aggregatetimespent\": \"Σ Time Spent\", \"workratio\": \"Work Ratio\", \"labels\": \"Labels\", \"components\": \"Component/s\", \"reporter\": \"Reporter\", \"progress\": \"Progress\", \"archivedby\": \"Archiver\", \"project\": \"Project\", \"resolutiondate\": \"Resolved\", \"watches\": \"Watchers\", \"updated\": \"Updated\", \"timeoriginalestimate\": \"Original Estimate\", \"description\": \"Description\", \"summary\": \"Summary\", \"comment\": \"Comment\", \"fixVersions\": \"Fix Version/s\", \"priority\": \"Priority\", \"versions\": \"Affects Version/s\", \"aggregateprogress\": \"Σ Progress\", \"created\": \"Created\", \"attachment\": \"Attachment\" }, \"schema\": {}, \"transitions\": [ { \"id\": \"731\", \"name\": \"To Do\", \"description\": \"\", \"opsbarSequence\": 2147483647, \"to\": { \"self\": \"https://example.com/tracker01/rest/api/2/status/10159\", \"description\": \"This status is managed internally by JIRA Software\", \"iconUrl\": \"https://example.com/tracker01/images/icons/subtask.gif\", \"name\": \"To Do\", \"id\": \"10159\", \"statusCategory\": { \"self\": \"https://example.com/tracker01/rest/api/2/statuscategory/2\", \"id\": 2, \"key\": \"new\", \"colorName\": \"default\", \"name\": \"To Do\" } } } ]}",
11+
"headers" : {
12+
"Content-Type" : "text/html; charset=UTF-8",
13+
"Date" : "Thu, 03 Dec 2020 08:03:43 GMT",
14+
"Server" : "Apache/2.4.38 (Debian)",
15+
"Vary" : "Accept-Encoding"
16+
}
17+
},
18+
"uuid" : "676006f7-ac23-4e6f-859d-de24c7101492",
19+
"persistent" : true,
20+
"insertionIndex" : 8
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (C) 2025 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
package org.ossreviewtoolkit.notifier.modules
21+
22+
import com.atlassian.jira.rest.client.api.JiraRestClient
23+
import com.atlassian.jira.rest.client.auth.AnonymousAuthenticationHandler
24+
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory
25+
26+
import com.github.tomakehurst.wiremock.WireMockServer
27+
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
28+
29+
import io.kotest.core.spec.style.WordSpec
30+
import io.kotest.matchers.nulls.shouldNotBeNull
31+
import io.kotest.matchers.shouldBe
32+
33+
import java.net.URI
34+
35+
/**
36+
* This test uses as much as possible the [JiraRestClient] of the JIRA REST API, using only Wiremock to simulate the
37+
* response. Contrary to the [JiraNotifier] test which is mocking the client, this test is using the actual client,
38+
* allowing to test if the JavaEE integration is working properly.
39+
*/
40+
class JiraClientTest : WordSpec({
41+
val server = WireMockServer(
42+
WireMockConfiguration.options()
43+
.dynamicPort()
44+
.usingFilesUnderDirectory("src/test/assets/clientTest")
45+
)
46+
47+
lateinit var client: JiraRestClient
48+
49+
beforeSpec {
50+
server.start()
51+
client = AsynchronousJiraRestClientFactory().createWithAuthenticationHandler(
52+
URI.create("http://localhost:${server.port()}"),
53+
AnonymousAuthenticationHandler()
54+
)
55+
}
56+
57+
afterSpec {
58+
server.stop()
59+
}
60+
61+
beforeTest {
62+
server.resetAll()
63+
}
64+
65+
"JIRA Rest client" should {
66+
"query an issue" {
67+
val issue = client.issueClient.getIssue("ISSUE-1").claim()
68+
69+
issue shouldNotBeNull {
70+
summary shouldBe "summary"
71+
id shouldBe 10000001L
72+
}
73+
}
74+
}
75+
})

0 commit comments

Comments
 (0)
Please sign in to comment.