Skip to content

Commit

Permalink
Merge pull request #55 from treasure-data/support_empty_jql_fix_check…
Browse files Browse the repository at this point in the history
…_host

Support empty JQL
  • Loading branch information
minidragon88 authored Mar 4, 2019
2 parents b368bf5 + 0d99dd6 commit 3a8158b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 0.2.5 - 2019-03-05
## 0.2.7 - 2019-03-05

* [enhancement] Support empty JQL [#55](https://github.com/treasure-data/embulk-input-jira/pull/55)

## 0.2.6 - 2019-03-01

* [enhancement] Change from ruby to java plugin [#53](https://github.com/treasure-data/embulk-input-jira/pull/53)

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ configurations {
provided
}

version = "0.2.6"
version = "0.2.7"

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/embulk/input/jira/JiraInputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
Expand Down Expand Up @@ -74,7 +75,8 @@ public interface PluginTask
public int getRetryLimit();

@Config("jql")
public String getJQL();
@ConfigDefault("null")
public Optional<String> getJQL();

@Config("columns")
public SchemaConfig getColumns();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/embulk/input/jira/client/JiraClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.embulk.input.jira.client;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -243,7 +244,8 @@ private HttpRequestBase createGetRequest(PluginTask task, String url)
private String createSearchIssuesBody(PluginTask task, int startAt, int maxResults)
{
JsonObject body = new JsonObject();
body.add("jql", new JsonPrimitive(task.getJQL()));
Optional<String> jql = task.getJQL();
body.add("jql", new JsonPrimitive(jql.or("")));
body.add("startAt", new JsonPrimitive(startAt));
body.add("maxResults", new JsonPrimitive(maxResults));
JsonArray fields = new JsonArray();
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/embulk/input/jira/util/JiraUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ public static void validateTaskConfig(final PluginTask task)
connection.disconnect();
}
}
String jql = task.getJQL();
if (isNullOrEmpty(jql)) {
throw new ConfigException("JQL could not be empty");
}
int retryInitialWaitSec = task.getInitialRetryIntervalMillis();
if (retryInitialWaitSec < 1) {
throw new ConfigException("Initial retry delay should be equal or greater than 1");
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/org/embulk/input/jira/client/JiraClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.http.entity.StringEntity;
import org.embulk.EmbulkTestRuntime;
import org.embulk.config.ConfigException;
import org.embulk.config.ConfigSource;
import org.embulk.input.jira.Issue;
import org.embulk.input.jira.JiraInputPlugin.PluginTask;
import org.embulk.input.jira.TestHelpers;
Expand Down Expand Up @@ -219,4 +220,28 @@ public void test_searchIssues_failJql() throws IOException

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

@Test
public void test_searchIssues_emptyJql() throws IOException
{
String dataName = "searchIssuesSuccess";
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));
ConfigSource config = TestHelpers.config().remove("jql");
task = config.loadConfig(PluginTask.class);

List<Issue> issues = jiraClient.searchIssues(task, 0, 50);
assertEquals(issues.size(), 2);

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

issues = jiraClient.searchIssues(task, 0, 50);
assertEquals(issues.size(), 2);
}
}
16 changes: 13 additions & 3 deletions src/test/java/org/embulk/input/jira/util/JiraUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,19 @@ public void test_validateTaskConfig() throws IOException
catch (Exception e) {
exception = e;
}
assertNotNull(exception);
assertTrue(exception instanceof ConfigException);
assertEquals("JQL could not be empty", exception.getMessage());
assertNull(exception);

configSource = TestHelpers.config();
configSource.remove("jql");
task = configSource.loadConfig(PluginTask.class);
exception = null;
try {
JiraUtil.validateTaskConfig(task);
}
catch (Exception e) {
exception = e;
}
assertNull(exception);

// initial_retry_interval_millis = 0
configSource = TestHelpers.config();
Expand Down

0 comments on commit 3a8158b

Please sign in to comment.