Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Check

on:
workflow_dispatch:
push:
branches: [ "master" ]
pull_request:
Expand Down
19 changes: 11 additions & 8 deletions src/test/java/org/embulk/input/jira/JiraInputPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public void test_runDynamicSchema_withResult() throws IOException
.thenReturn(new StringEntity(searchResponse.get("body").toString()));

plugin.transaction(TestHelpers.dynamicSchemaConfig(), new Control());
// Check credential 1 + getTotal 1 + loadData 2
verify(jiraClient, times(4)).createHttpClient();
// Check credential 1 + loadData 2
verify(jiraClient, times(3)).createHttpClient();
verify(pageBuilder, times(1)).addRecord();
verify(pageBuilder, times(1)).finish();
}
Expand All @@ -137,8 +137,8 @@ public void test_run_with1RecordsResult() throws IOException
.thenReturn(new StringEntity(searchResponse.get("body").toString()));

plugin.transaction(config, new Control());
// Check credential 1 + getTotal 1 + loadData 1
verify(jiraClient, times(3)).createHttpClient();
// Check credential 1 + loadData 1
verify(jiraClient, times(2)).createHttpClient();
verify(pageBuilder, times(1)).addRecord();
verify(pageBuilder, times(1)).finish();
}
Expand All @@ -148,17 +148,20 @@ public void test_run_with2PagesResult() throws IOException
{
final JsonObject authorizeResponse = data.get("authenticateSuccess").getAsJsonObject();
final JsonObject searchResponse = data.get("2PagesResult").getAsJsonObject();
final JsonObject searchSecondResponse = data.get("2PagesSecondResult").getAsJsonObject();

when(statusLine.getStatusCode())
.thenReturn(authorizeResponse.get("statusCode").getAsInt())
.thenReturn(searchResponse.get("statusCode").getAsInt());
.thenReturn(searchResponse.get("statusCode").getAsInt())
.thenReturn(searchSecondResponse.get("statusCode").getAsInt());
when(response.getEntity())
.thenReturn(new StringEntity(authorizeResponse.get("body").toString()))
.thenReturn(new StringEntity(searchResponse.get("body").toString()));
.thenReturn(new StringEntity(searchResponse.get("body").toString()))
.thenReturn(new StringEntity(searchSecondResponse.get("body").toString()));

plugin.transaction(config, new Control());
// Check credential 1 + getTotal 1 + loadData 2
verify(jiraClient, times(4)).createHttpClient();
// Check credential 1 + loadData 2
verify(jiraClient, times(3)).createHttpClient();
verify(pageBuilder, times(2)).addRecord();
verify(pageBuilder, times(1)).finish();
}
Expand Down
79 changes: 8 additions & 71 deletions src/test/java/org/embulk/input/jira/client/JiraClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.JsonObject;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.entity.StringEntity;
Expand Down Expand Up @@ -124,73 +125,6 @@ public void test_checkUserCredentials_failOn500() throws IOException
assertThrows("Could not authorize with your credential due to problems when contacting JIRA API.", ConfigException.class, () -> jiraClient.checkUserCredentials(task));
}

@Test
public void test_getTotalCount_success() throws IOException
{
String dataName = "totalCountSuccess";
JsonObject messageResponse = data.get(dataName).getAsJsonObject();
int statusCode = messageResponse.get("statusCode").getAsInt();
String body = messageResponse.get("body").toString();

when(statusLine.getStatusCode()).thenReturn(statusCode);
when(response.getEntity()).thenReturn(new StringEntity(body));

int totalCount = jiraClient.getTotalCount(task);
assertEquals(totalCount, messageResponse.get("body").getAsJsonObject().get("total").getAsInt());
}

@Test
public void test_getTotalCount_failOnRetry() throws IOException
{
String dataName = "totalCountFailAllTime";
JsonObject messageResponse = data.get(dataName).getAsJsonObject();
int statusCode = messageResponse.get("statusCode").getAsInt();
String body = messageResponse.get("body").toString();

when(statusLine.getStatusCode()).thenReturn(statusCode);
when(response.getEntity()).thenReturn(new StringEntity(body));

assertThrows(RuntimeException.class, () -> jiraClient.getTotalCount(task));

// First try + 3 retry_limit
int expectedInvocation = 3 + 1;
verify(jiraClient, times(expectedInvocation)).createHttpClient();
verify(statusLine, times(expectedInvocation)).getStatusCode();
}

@Test
public void test_getTotalCount_doNotRetryOn400Status() throws IOException
{
String dataName = "totalCountFail400";
JsonObject messageResponse = data.get(dataName).getAsJsonObject();
int statusCode = messageResponse.get("statusCode").getAsInt();
String body = messageResponse.get("body").toString();

when(statusLine.getStatusCode()).thenReturn(statusCode);
when(response.getEntity()).thenReturn(new StringEntity(body));

assertThrows(RuntimeException.class, () -> jiraClient.getTotalCount(task));

// No retry
int expectedInvocation = 1;
verify(jiraClient, times(expectedInvocation)).createHttpClient();
verify(statusLine, times(expectedInvocation)).getStatusCode();
}

@Test
public void test_getTotalCount_retryOnIOException() throws IOException
{
when(client.execute(Mockito.any())).thenThrow(new IOException("test exeception"));

assertThrows(RuntimeException.class, () -> jiraClient.getTotalCount(task));

// First try + 3 retry_limit
int expectedInvocation = 3 + 1;
verify(jiraClient, times(expectedInvocation)).createHttpClient();
// getStatusCode is not triggered
verify(statusLine, times(0)).getStatusCode();
}

@Test
public void test_searchIssues() throws IOException
{
Expand All @@ -203,7 +137,8 @@ public void test_searchIssues() throws IOException
when(statusLine.getStatusCode()).thenReturn(statusCode);
when(response.getEntity()).thenReturn(new StringEntity(body));

List<Issue> issues = jiraClient.searchIssues(task, 0, 50);
Pair<List<Issue>, String> result = jiraClient.searchIssues(task, null, 50);
List<Issue> issues = result.getLeft();
assertEquals(issues.size(), 2);
}

Expand All @@ -219,7 +154,7 @@ public void test_searchIssues_failJql() throws IOException
when(statusLine.getStatusCode()).thenReturn(statusCode);
when(response.getEntity()).thenReturn(new StringEntity(body));

assertThrows(ConfigException.class, () -> jiraClient.searchIssues(task, 0, 50));
assertThrows(ConfigException.class, () -> jiraClient.searchIssues(task, null, 50));
}

@Test
Expand All @@ -236,13 +171,15 @@ public void test_searchIssues_emptyJql() throws IOException
ConfigSource config = TestHelpers.config().remove("jql");
task = CONFIG_MAPPER.map(config, PluginTask.class);

List<Issue> issues = jiraClient.searchIssues(task, 0, 50);
Pair<List<Issue>, String> result = jiraClient.searchIssues(task, null, 50);
List<Issue> issues = result.getLeft();
assertEquals(issues.size(), 2);

config = TestHelpers.config().set("jql", "");
task = CONFIG_MAPPER.map(config, PluginTask.class);

issues = jiraClient.searchIssues(task, 0, 50);
result = jiraClient.searchIssues(task, null, 50);
issues = result.getLeft();
assertEquals(issues.size(), 2);
}
}
2 changes: 1 addition & 1 deletion src/test/java/org/embulk/input/jira/util/JiraUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void test_buildPermissionUrl()
public void test_buildSearchUrl() throws IOException
{
PluginTask task = CONFIG_MAPPER.map(TestHelpers.config(), PluginTask.class);
String expected = "https://example.com/rest/api/latest/search";
String expected = "https://example.com/rest/api/latest/search/jql";
String actual = JiraUtil.buildSearchUrl(task.getUri());
assertEquals(expected, actual);
}
Expand Down
24 changes: 22 additions & 2 deletions src/test/resources/jira_input_plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@
"2PagesResult": {
"statusCode": 200,
"body": {
"startAt": 0,
"maxResults": 50,
"total": 51,
"nextPageToken": "aaa",
"issues": [
{
"id": "id1",
Expand All @@ -110,5 +109,26 @@
}
]
}
},
"2PagesSecondResult": {
"statusCode": 200,
"body": {
"maxResults": 50,
"issues": [
{
"id": "id1",
"key": "key1",
"self": "self1",
"fields": {
"boolean": true,
"long": 1,
"double": 1,
"string": "string1",
"date": "2019-01-01T00:00:00.000Z",
"json": {}
}
}
]
}
}
}