embulk-input-zendesk 0.2.14 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -3
- data/.travis.yml +5 -44
- data/CHANGELOG.md +3 -0
- data/README.md +5 -5
- data/build.gradle +123 -0
- data/classpath/commons-codec-1.10.jar +0 -0
- data/classpath/commons-logging-1.2.jar +0 -0
- data/classpath/embulk-input-zendesk-0.3.0.jar +0 -0
- data/classpath/httpclient-4.5.6.jar +0 -0
- data/classpath/httpcore-4.4.10.jar +0 -0
- data/config/checkstyle/checkstyle.xml +128 -0
- data/config/checkstyle/default.xml +108 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +5 -0
- data/gradlew +172 -0
- data/gradlew.bat +84 -0
- data/lib/embulk/guess/zendesk.rb +21 -0
- data/lib/embulk/input/zendesk.rb +3 -9
- data/src/main/java/org/embulk/input/zendesk/ZendeskInputPlugin.java +471 -0
- data/src/main/java/org/embulk/input/zendesk/clients/ZendeskRestClient.java +268 -0
- data/src/main/java/org/embulk/input/zendesk/models/AuthenticationMethod.java +23 -0
- data/src/main/java/org/embulk/input/zendesk/models/Target.java +46 -0
- data/src/main/java/org/embulk/input/zendesk/models/ZendeskException.java +25 -0
- data/src/main/java/org/embulk/input/zendesk/services/ZendeskSupportAPIService.java +109 -0
- data/src/main/java/org/embulk/input/zendesk/utils/ZendeskConstants.java +61 -0
- data/src/main/java/org/embulk/input/zendesk/utils/ZendeskDateUtils.java +51 -0
- data/src/main/java/org/embulk/input/zendesk/utils/ZendeskUtils.java +150 -0
- data/src/main/java/org/embulk/input/zendesk/utils/ZendeskValidatorUtils.java +92 -0
- data/src/test/java/org/embulk/input/zendesk/TestZendeskInputPlugin.java +232 -0
- data/src/test/java/org/embulk/input/zendesk/clients/TestZendeskRestClient.java +351 -0
- data/src/test/java/org/embulk/input/zendesk/services/TestZendeskSupportAPIService.java +172 -0
- data/src/test/java/org/embulk/input/zendesk/utils/TestZendeskDateUtils.java +36 -0
- data/src/test/java/org/embulk/input/zendesk/utils/TestZendeskUtil.java +160 -0
- data/src/test/java/org/embulk/input/zendesk/utils/TestZendeskValidatorUtils.java +138 -0
- data/src/test/java/org/embulk/input/zendesk/utils/ZendeskPluginTestRuntime.java +133 -0
- data/src/test/java/org/embulk/input/zendesk/utils/ZendeskTestHelper.java +63 -0
- data/src/test/resources/config/base.yml +14 -0
- data/src/test/resources/config/base_validator.yml +48 -0
- data/src/test/resources/config/incremental.yml +54 -0
- data/src/test/resources/config/non-incremental.yml +39 -0
- data/src/test/resources/config/util.yml +18 -0
- data/src/test/resources/data/client.json +293 -0
- data/src/test/resources/data/error_data.json +187 -0
- data/src/test/resources/data/expected/ticket_column.json +148 -0
- data/src/test/resources/data/expected/ticket_column_with_related_objects.json +152 -0
- data/src/test/resources/data/expected/ticket_fields_column.json +92 -0
- data/src/test/resources/data/expected/ticket_metrics_column.json +98 -0
- data/src/test/resources/data/ticket_fields.json +225 -0
- data/src/test/resources/data/ticket_metrics.json +397 -0
- data/src/test/resources/data/ticket_with_related_objects.json +67 -0
- data/src/test/resources/data/tickets.json +232 -0
- data/src/test/resources/data/tickets_continue.json +52 -0
- data/src/test/resources/data/util.json +19 -0
- data/src/test/resources/data/util_page.json +227 -0
- metadata +65 -221
- data/.ruby-version +0 -1
- data/.travis.yml.erb +0 -43
- data/Gemfile +0 -2
- data/Rakefile +0 -21
- data/embulk-input-zendesk.gemspec +0 -29
- data/gemfiles/embulk-0.8.0-latest +0 -4
- data/gemfiles/embulk-0.8.1 +0 -4
- data/gemfiles/embulk-latest +0 -4
- data/gemfiles/template.erb +0 -4
- data/lib/embulk/input/zendesk/client.rb +0 -434
- data/lib/embulk/input/zendesk/plugin.rb +0 -199
- data/test/capture_io.rb +0 -45
- data/test/embulk/input/zendesk/test_client.rb +0 -722
- data/test/embulk/input/zendesk/test_plugin.rb +0 -628
- data/test/fixture_helper.rb +0 -11
- data/test/fixtures/invalid_app_marketplace_lack_one_property.yml +0 -13
- data/test/fixtures/invalid_app_marketplace_lack_two_property.yml +0 -12
- data/test/fixtures/invalid_lack_username.yml +0 -9
- data/test/fixtures/invalid_unknown_auth.yml +0 -9
- data/test/fixtures/tickets.json +0 -44
- data/test/fixtures/valid_app_marketplace.yml +0 -14
- data/test/fixtures/valid_auth_basic.yml +0 -11
- data/test/fixtures/valid_auth_oauth.yml +0 -10
- data/test/fixtures/valid_auth_token.yml +0 -11
- data/test/override_assert_raise.rb +0 -21
- data/test/run-test.rb +0 -26
@@ -0,0 +1,351 @@
|
|
1
|
+
package org.embulk.input.zendesk.clients;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.databind.JsonNode;
|
4
|
+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
5
|
+
import org.apache.http.Header;
|
6
|
+
|
7
|
+
import org.apache.http.HttpResponse;
|
8
|
+
import org.apache.http.StatusLine;
|
9
|
+
import org.apache.http.client.HttpClient;
|
10
|
+
import org.apache.http.client.methods.HttpRequestBase;
|
11
|
+
import org.apache.http.entity.StringEntity;
|
12
|
+
|
13
|
+
import org.embulk.config.ConfigException;
|
14
|
+
import org.embulk.config.ConfigSource;
|
15
|
+
import org.embulk.input.zendesk.ZendeskInputPlugin;
|
16
|
+
import org.embulk.input.zendesk.ZendeskInputPlugin.PluginTask;
|
17
|
+
import org.embulk.input.zendesk.utils.ZendeskPluginTestRuntime;
|
18
|
+
import org.embulk.input.zendesk.utils.ZendeskTestHelper;
|
19
|
+
|
20
|
+
import org.embulk.input.zendesk.utils.ZendeskUtils;
|
21
|
+
import org.embulk.spi.InputPlugin;
|
22
|
+
import org.embulk.test.TestingEmbulk;
|
23
|
+
|
24
|
+
import org.junit.Before;
|
25
|
+
import org.junit.Rule;
|
26
|
+
import org.junit.Test;
|
27
|
+
|
28
|
+
import org.junit.rules.ExpectedException;
|
29
|
+
import org.junit.rules.RuleChain;
|
30
|
+
import org.junit.rules.TestRule;
|
31
|
+
|
32
|
+
import org.mockito.ArgumentCaptor;
|
33
|
+
import org.mockito.Mockito;
|
34
|
+
|
35
|
+
import static org.apache.http.HttpHeaders.AUTHORIZATION;
|
36
|
+
import static org.junit.Assert.assertEquals;
|
37
|
+
import static org.junit.Assert.assertThrows;
|
38
|
+
import static org.junit.Assert.fail;
|
39
|
+
import static org.mockito.ArgumentMatchers.any;
|
40
|
+
import static org.mockito.Mockito.doReturn;
|
41
|
+
import static org.mockito.Mockito.mock;
|
42
|
+
import static org.mockito.Mockito.spy;
|
43
|
+
import static org.mockito.Mockito.times;
|
44
|
+
import static org.mockito.Mockito.verify;
|
45
|
+
import static org.mockito.Mockito.when;
|
46
|
+
|
47
|
+
import java.io.IOException;
|
48
|
+
import java.util.Optional;
|
49
|
+
|
50
|
+
public class TestZendeskRestClient
|
51
|
+
{
|
52
|
+
private final ExpectedException thrown = ExpectedException.none();
|
53
|
+
private final TestingEmbulk embulk = TestingEmbulk.builder()
|
54
|
+
.registerPlugin(InputPlugin.class, "zendesk", ZendeskInputPlugin.class)
|
55
|
+
.build();
|
56
|
+
public ZendeskPluginTestRuntime runtime = new ZendeskPluginTestRuntime();
|
57
|
+
|
58
|
+
@Rule
|
59
|
+
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
60
|
+
public TestRule chain = RuleChain.outerRule(embulk).around(runtime).around(thrown);
|
61
|
+
|
62
|
+
private ZendeskRestClient zendeskRestClient;
|
63
|
+
private PluginTask task = ZendeskTestHelper.getConfigSource("incremental.yml").loadConfig(PluginTask.class);
|
64
|
+
private JsonNode data = ZendeskTestHelper.getJsonFromFile("data/client.json");
|
65
|
+
|
66
|
+
private HttpClient client = Mockito.mock(HttpClient.class);
|
67
|
+
private HttpResponse response = Mockito.mock(HttpResponse.class);
|
68
|
+
private Header header = mock(Header.class);
|
69
|
+
private StatusLine statusLine = Mockito.mock(StatusLine.class);
|
70
|
+
|
71
|
+
@Before
|
72
|
+
public void prepare() throws IOException
|
73
|
+
{
|
74
|
+
zendeskRestClient = spy(new ZendeskRestClient());
|
75
|
+
|
76
|
+
when(zendeskRestClient.createHttpClient()).thenReturn(client);
|
77
|
+
when(client.execute(any())).thenReturn(response);
|
78
|
+
when(response.getStatusLine()).thenReturn(statusLine);
|
79
|
+
}
|
80
|
+
|
81
|
+
@Test
|
82
|
+
public void doGetSuccess()
|
83
|
+
{
|
84
|
+
setup("doGet200");
|
85
|
+
JsonNode expectedResult = ZendeskTestHelper.getJsonFromFile("data/tickets.json");
|
86
|
+
String result = zendeskRestClient.doGet("dummyString", task, false);
|
87
|
+
assertEquals(expectedResult.toString(), result);
|
88
|
+
}
|
89
|
+
|
90
|
+
@Test
|
91
|
+
public void doGetRetryFail429WithoutRetryAfter()
|
92
|
+
{
|
93
|
+
String expectedMessage = "Number of allowed incremental export API requests per minute exceeded";
|
94
|
+
int expectedRetryTime = 3;
|
95
|
+
testExceptionMessageForDoGet("doGet429", expectedMessage, expectedRetryTime);
|
96
|
+
}
|
97
|
+
|
98
|
+
@Test
|
99
|
+
public void doGetRetryFail429WithRetryAfter()
|
100
|
+
{
|
101
|
+
String expectedMessage = "Number of allowed incremental export API requests per minute exceeded";
|
102
|
+
int expectedRetryTime = 3;
|
103
|
+
|
104
|
+
when(response.containsHeader("x-rate-limit")).thenReturn(true);
|
105
|
+
when(response.getFirstHeader("x-rate-limit")).thenReturn(header);
|
106
|
+
when(response.getFirstHeader("Retry-After")).thenReturn(header);
|
107
|
+
when(header.getValue())
|
108
|
+
.thenReturn("5");
|
109
|
+
|
110
|
+
setupData("doGet429");
|
111
|
+
verifyData(expectedMessage, expectedRetryTime);
|
112
|
+
}
|
113
|
+
|
114
|
+
@Test
|
115
|
+
public void doGetRetry405()
|
116
|
+
{
|
117
|
+
String expectedMessage = "Status '405', message 'dummy text'";
|
118
|
+
int expectedRetryTime = 1;
|
119
|
+
|
120
|
+
testExceptionMessageForDoGet("doGet405", expectedMessage, expectedRetryTime);
|
121
|
+
}
|
122
|
+
|
123
|
+
@Test
|
124
|
+
public void doGetRetry422FailBecauseNotContainTooRecentStartTime()
|
125
|
+
{
|
126
|
+
String expectedMessage = "Status: '422', error message 'dummy text'";
|
127
|
+
int expectedRetryTime = 1;
|
128
|
+
testExceptionMessageForDoGet("doGet422NotContainTooRecentStartTime", expectedMessage, expectedRetryTime);
|
129
|
+
}
|
130
|
+
|
131
|
+
@Test
|
132
|
+
public void doGetNotRetry422BecauseContainTooRecentStartTime()
|
133
|
+
{
|
134
|
+
String expectedMessage = "Status: '422', error message 'dummy text'";
|
135
|
+
int expectedRetryTime = 1;
|
136
|
+
testExceptionMessageForDoGet("doGet422ContainTooRecentStartTime", expectedMessage, expectedRetryTime);
|
137
|
+
}
|
138
|
+
|
139
|
+
@Test
|
140
|
+
public void doGetRetrySuccess429()
|
141
|
+
{
|
142
|
+
setupReTrySuccess("doGet429");
|
143
|
+
}
|
144
|
+
|
145
|
+
@Test
|
146
|
+
public void doGetRetry500()
|
147
|
+
{
|
148
|
+
setupReTrySuccess("doGet500");
|
149
|
+
}
|
150
|
+
|
151
|
+
@Test
|
152
|
+
public void doGetRetry503()
|
153
|
+
{
|
154
|
+
setupReTrySuccess("doGet503");
|
155
|
+
}
|
156
|
+
|
157
|
+
@Test
|
158
|
+
public void doGetRetry404()
|
159
|
+
{
|
160
|
+
setup("doGet404");
|
161
|
+
String expectedMessage = "dummy text";
|
162
|
+
int expectedRetryTime = 1;
|
163
|
+
try {
|
164
|
+
zendeskRestClient.doGet("any", task, false);
|
165
|
+
fail("Should not reach here");
|
166
|
+
}
|
167
|
+
catch (final Exception e) {
|
168
|
+
assertEquals(expectedMessage, e.getMessage());
|
169
|
+
}
|
170
|
+
verify(zendeskRestClient, times(expectedRetryTime)).createHttpClient();
|
171
|
+
}
|
172
|
+
|
173
|
+
@Test
|
174
|
+
public void doGetRetry409()
|
175
|
+
{
|
176
|
+
setupReTrySuccess("doGet409");
|
177
|
+
}
|
178
|
+
|
179
|
+
@Test
|
180
|
+
public void doGetRetryWhenStatusNot400s()
|
181
|
+
{
|
182
|
+
setupReTrySuccess("doGet502");
|
183
|
+
}
|
184
|
+
|
185
|
+
@Test
|
186
|
+
public void doGetRetry503WithRetryAfterNegative()
|
187
|
+
{
|
188
|
+
setup("doGet503");
|
189
|
+
|
190
|
+
int expectedRetryTime = 3;
|
191
|
+
when(response.getFirstHeader("Retry-After")).thenReturn(header);
|
192
|
+
when(header.getValue())
|
193
|
+
.thenReturn("5")
|
194
|
+
.thenReturn("-5");
|
195
|
+
|
196
|
+
try {
|
197
|
+
zendeskRestClient.doGet("any", task, false);
|
198
|
+
}
|
199
|
+
catch (final Exception e) {
|
200
|
+
}
|
201
|
+
verify(zendeskRestClient, times(expectedRetryTime)).createHttpClient();
|
202
|
+
}
|
203
|
+
|
204
|
+
@Test
|
205
|
+
public void doGetRetryWhenThrowIOException() throws IOException
|
206
|
+
{
|
207
|
+
setupRateLimit();
|
208
|
+
|
209
|
+
when(client.execute(any()))
|
210
|
+
.thenThrow(new IOException());
|
211
|
+
|
212
|
+
int expectedRetryTime = 3;
|
213
|
+
assertThrows(ConfigException.class, () -> zendeskRestClient.doGet("any", task, false));
|
214
|
+
verify(zendeskRestClient, times(expectedRetryTime)).createHttpClient();
|
215
|
+
}
|
216
|
+
|
217
|
+
@Test
|
218
|
+
public void authenticationOauthSuccess() throws IOException
|
219
|
+
{
|
220
|
+
setup("doGet200");
|
221
|
+
|
222
|
+
String accessToken = "testzendesk";
|
223
|
+
|
224
|
+
ConfigSource configSource = ZendeskTestHelper.getConfigSource("incremental.yml");
|
225
|
+
configSource.set("auth_method", "oauth");
|
226
|
+
configSource.set("access_token", accessToken);
|
227
|
+
PluginTask pluginTask = configSource.loadConfig(PluginTask.class);
|
228
|
+
|
229
|
+
String expectedValue = "Bearer " + accessToken;
|
230
|
+
setupAndVerifyAuthenticationString(expectedValue, pluginTask);
|
231
|
+
}
|
232
|
+
|
233
|
+
@Test
|
234
|
+
public void authenticationBasicSuccess() throws IOException
|
235
|
+
{
|
236
|
+
setup("doGet200");
|
237
|
+
|
238
|
+
String username = "zendesk_username";
|
239
|
+
String password = "zendesk_password";
|
240
|
+
|
241
|
+
ConfigSource configSource = ZendeskTestHelper.getConfigSource("incremental.yml");
|
242
|
+
configSource.set("auth_method", "basic");
|
243
|
+
configSource.set("username", Optional.of(username));
|
244
|
+
configSource.set("password", password);
|
245
|
+
PluginTask pluginTask = configSource.loadConfig(PluginTask.class);
|
246
|
+
|
247
|
+
String expectedValue = "Basic " + ZendeskUtils.convertBase64(String.format("%s:%s", username, password));
|
248
|
+
setupAndVerifyAuthenticationString(expectedValue, pluginTask);
|
249
|
+
}
|
250
|
+
|
251
|
+
@Test
|
252
|
+
public void authenticationTokenSuccess() throws IOException
|
253
|
+
{
|
254
|
+
setup("doGet200");
|
255
|
+
|
256
|
+
String username = "zendesk_username";
|
257
|
+
String token = "zendesk_token";
|
258
|
+
|
259
|
+
ConfigSource configSource = ZendeskTestHelper.getConfigSource("incremental.yml");
|
260
|
+
configSource.set("auth_method", "token");
|
261
|
+
configSource.set("username", username);
|
262
|
+
configSource.set("token", token);
|
263
|
+
PluginTask pluginTask = configSource.loadConfig(PluginTask.class);
|
264
|
+
|
265
|
+
String expectedValue = "Basic " + ZendeskUtils.convertBase64(String.format("%s/token:%s", username, token));
|
266
|
+
setupAndVerifyAuthenticationString(expectedValue, pluginTask);
|
267
|
+
}
|
268
|
+
|
269
|
+
private void setupRateLimit()
|
270
|
+
{
|
271
|
+
when(response.containsHeader("x-rate-limit")).thenReturn(true);
|
272
|
+
when(response.getFirstHeader("x-rate-limit")).thenReturn(header);
|
273
|
+
when(header.getValue()).thenReturn("400");
|
274
|
+
}
|
275
|
+
|
276
|
+
private void setup(String name)
|
277
|
+
{
|
278
|
+
setupRateLimit();
|
279
|
+
setupData(name);
|
280
|
+
}
|
281
|
+
|
282
|
+
private void setupData(String name)
|
283
|
+
{
|
284
|
+
JsonNode messageResponse = data.get(name);
|
285
|
+
when(statusLine.getStatusCode()).thenReturn(messageResponse.get("statusCode").asInt());
|
286
|
+
try {
|
287
|
+
if (name.equals("doGet200")) {
|
288
|
+
doReturn(new StringEntity(messageResponse.get("body").toString())).when(response).getEntity();
|
289
|
+
}
|
290
|
+
else {
|
291
|
+
doReturn(new StringEntity(messageResponse.get("description").asText())).when(response).getEntity();
|
292
|
+
}
|
293
|
+
}
|
294
|
+
catch (Exception e) {
|
295
|
+
fail("fail to setup client for UT");
|
296
|
+
}
|
297
|
+
}
|
298
|
+
|
299
|
+
private void testExceptionMessageForDoGet(String name, String expectedMessage, int expectedRetryTime)
|
300
|
+
{
|
301
|
+
setup(name);
|
302
|
+
verifyData(expectedMessage, expectedRetryTime);
|
303
|
+
}
|
304
|
+
|
305
|
+
private void verifyData(String expectedMessage, int expectedRetryTime)
|
306
|
+
{
|
307
|
+
try {
|
308
|
+
zendeskRestClient.doGet("any", task, false);
|
309
|
+
fail("Should not reach here");
|
310
|
+
}
|
311
|
+
catch (final Exception e) {
|
312
|
+
assertEquals(expectedMessage, e.getMessage());
|
313
|
+
}
|
314
|
+
verify(zendeskRestClient, times(expectedRetryTime)).createHttpClient();
|
315
|
+
}
|
316
|
+
|
317
|
+
private void setupReTrySuccess(String entityName)
|
318
|
+
{
|
319
|
+
setupRateLimit();
|
320
|
+
|
321
|
+
JsonNode messageResponse = data.get(entityName);
|
322
|
+
JsonNode messageResponseSuccess = data.get("doGet200");
|
323
|
+
|
324
|
+
when(statusLine.getStatusCode())
|
325
|
+
.thenReturn(messageResponse.get("statusCode").asInt())
|
326
|
+
.thenReturn(messageResponseSuccess.get("statusCode").asInt());
|
327
|
+
|
328
|
+
try {
|
329
|
+
when(response.getEntity())
|
330
|
+
.thenReturn(new StringEntity(messageResponse.get("description").asText()))
|
331
|
+
.thenReturn(new StringEntity(messageResponseSuccess.get("body").toString()));
|
332
|
+
}
|
333
|
+
catch (Exception e) {
|
334
|
+
fail("fail to setup client for UT");
|
335
|
+
}
|
336
|
+
|
337
|
+
int expectedRetryTime = 2;
|
338
|
+
zendeskRestClient.doGet("any", task, false);
|
339
|
+
verify(zendeskRestClient, times(expectedRetryTime)).createHttpClient();
|
340
|
+
}
|
341
|
+
|
342
|
+
private void setupAndVerifyAuthenticationString(String expectedString, PluginTask pluginTask) throws IOException
|
343
|
+
{
|
344
|
+
zendeskRestClient.doGet("any", pluginTask, false);
|
345
|
+
final ArgumentCaptor<HttpRequestBase> request = ArgumentCaptor.forClass(HttpRequestBase.class);
|
346
|
+
verify(client).execute(request.capture());
|
347
|
+
|
348
|
+
String credential = request.getValue().getFirstHeader(AUTHORIZATION).getValue();
|
349
|
+
assertEquals(expectedString, credential);
|
350
|
+
}
|
351
|
+
}
|
@@ -0,0 +1,172 @@
|
|
1
|
+
package org.embulk.input.zendesk.services;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.databind.JsonNode;
|
4
|
+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
5
|
+
import org.embulk.EmbulkTestRuntime;
|
6
|
+
import org.embulk.config.ConfigSource;
|
7
|
+
import org.embulk.input.zendesk.ZendeskInputPlugin;
|
8
|
+
import org.embulk.input.zendesk.clients.ZendeskRestClient;
|
9
|
+
import org.embulk.input.zendesk.utils.ZendeskTestHelper;
|
10
|
+
import org.junit.Before;
|
11
|
+
import org.junit.Rule;
|
12
|
+
import org.junit.Test;
|
13
|
+
import org.mockito.ArgumentCaptor;
|
14
|
+
|
15
|
+
import static org.junit.Assert.assertEquals;
|
16
|
+
import static org.mockito.ArgumentMatchers.any;
|
17
|
+
import static org.mockito.ArgumentMatchers.anyBoolean;
|
18
|
+
import static org.mockito.Mockito.mock;
|
19
|
+
import static org.mockito.Mockito.spy;
|
20
|
+
import static org.mockito.Mockito.verify;
|
21
|
+
import static org.mockito.Mockito.when;
|
22
|
+
|
23
|
+
import java.util.Collections;
|
24
|
+
|
25
|
+
public class TestZendeskSupportAPIService
|
26
|
+
{
|
27
|
+
@Rule
|
28
|
+
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
29
|
+
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
|
30
|
+
|
31
|
+
private ZendeskRestClient zendeskRestClient;
|
32
|
+
|
33
|
+
private ZendeskSupportAPIService zendeskSupportAPIService;
|
34
|
+
|
35
|
+
@Before
|
36
|
+
public void prepare()
|
37
|
+
{
|
38
|
+
zendeskRestClient = mock(ZendeskRestClient.class);
|
39
|
+
}
|
40
|
+
|
41
|
+
@Test
|
42
|
+
public void buildPathWithIncrementalForPreview()
|
43
|
+
{
|
44
|
+
String expectURL = "https://abc.zendesk.com/api/v2/incremental/tickets.json?start_time=0";
|
45
|
+
setup("incremental.yml");
|
46
|
+
loadData("data/tickets.json");
|
47
|
+
setupTestAndVerifyURL(expectURL, 0, true);
|
48
|
+
}
|
49
|
+
|
50
|
+
@Test
|
51
|
+
public void buildPathWithNonIncrementalForPreview()
|
52
|
+
{
|
53
|
+
String expectURL = "https://abc.zendesk.com/api/v2/ticket_fields.json?sort_by=id&per_page=100&page=0";
|
54
|
+
setup("non-incremental.yml");
|
55
|
+
loadData("data/ticket_fields.json");
|
56
|
+
setupTestAndVerifyURL(expectURL, 0, true);
|
57
|
+
}
|
58
|
+
|
59
|
+
@Test
|
60
|
+
public void buildPathWithIncrementalForPreviewWithTicketMetrics()
|
61
|
+
{
|
62
|
+
String expectURL = "https://abc.zendesk.com/api/v2/incremental/tickets.json?start_time=0&include=metric_sets";
|
63
|
+
loadData("data/ticket_metrics.json");
|
64
|
+
|
65
|
+
ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
|
66
|
+
src.set("target", "ticket_metrics");
|
67
|
+
ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
68
|
+
setupZendeskSupportAPIService(task);
|
69
|
+
|
70
|
+
setupTestAndVerifyURL(expectURL, 0, true);
|
71
|
+
}
|
72
|
+
|
73
|
+
@Test
|
74
|
+
public void buildPathWithIncrementalForRun()
|
75
|
+
{
|
76
|
+
String expectURL = "https://abc.zendesk.com/api/v2/incremental/tickets.json?start_time=0";
|
77
|
+
setup("incremental.yml");
|
78
|
+
loadData("data/tickets.json");
|
79
|
+
setupTestAndVerifyURL(expectURL, 0, false);
|
80
|
+
}
|
81
|
+
|
82
|
+
@Test
|
83
|
+
public void buildPathWithIncrementalForRunWithTicketMetrics()
|
84
|
+
{
|
85
|
+
String expectURL = "https://abc.zendesk.com/api/v2/incremental/tickets.json?start_time=0&include=metric_sets";
|
86
|
+
loadData("data/ticket_metrics.json");
|
87
|
+
|
88
|
+
ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
|
89
|
+
src.set("target", "ticket_metrics");
|
90
|
+
ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
91
|
+
setupZendeskSupportAPIService(task);
|
92
|
+
|
93
|
+
setupTestAndVerifyURL(expectURL, 0, false);
|
94
|
+
}
|
95
|
+
|
96
|
+
@Test
|
97
|
+
public void buildPathWithIncrementalForRunIncludeRelatedObject()
|
98
|
+
{
|
99
|
+
String expectURL = "https://abc.zendesk.com/api/v2/incremental/tickets.json?start_time=0";
|
100
|
+
loadData("data/tickets.json");
|
101
|
+
|
102
|
+
ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
|
103
|
+
src.set("includes", Collections.singletonList("organizations"));
|
104
|
+
ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
105
|
+
setupZendeskSupportAPIService(task);
|
106
|
+
|
107
|
+
setupTestAndVerifyURL(expectURL, 0, false);
|
108
|
+
}
|
109
|
+
|
110
|
+
@Test
|
111
|
+
public void buildPathWithIncrementalForRunTimeChange()
|
112
|
+
{
|
113
|
+
long time = 100;
|
114
|
+
String expectURL = "https://abc.zendesk.com/api/v2/incremental/tickets.json?start_time=100";
|
115
|
+
loadData("data/tickets.json");
|
116
|
+
|
117
|
+
ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
|
118
|
+
ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
119
|
+
setupZendeskSupportAPIService(task);
|
120
|
+
|
121
|
+
zendeskSupportAPIService.getData("", 0, false, time);
|
122
|
+
final ArgumentCaptor<String> url = ArgumentCaptor.forClass(String.class);
|
123
|
+
verify(zendeskRestClient).doGet(url.capture(), any(), anyBoolean());
|
124
|
+
assertEquals(expectURL, url.getValue());
|
125
|
+
}
|
126
|
+
|
127
|
+
@Test
|
128
|
+
public void buildPathWithNonIncrementalForRun()
|
129
|
+
{
|
130
|
+
String expectURL = "https://abc.zendesk.com/api/v2/ticket_fields.json?sort_by=id&per_page=100&page=0";
|
131
|
+
setup("non-incremental.yml");
|
132
|
+
loadData("data/ticket_fields.json");
|
133
|
+
|
134
|
+
setupTestAndVerifyURL(expectURL, 0, false);
|
135
|
+
}
|
136
|
+
|
137
|
+
@Test
|
138
|
+
public void buildPathWithNonIncrementalForRunChangePageNumber()
|
139
|
+
{
|
140
|
+
String expectURL = "https://abc.zendesk.com/api/v2/ticket_fields.json?sort_by=id&per_page=100&page=2";
|
141
|
+
setup("non-incremental.yml");
|
142
|
+
loadData("data/ticket_fields.json");
|
143
|
+
setupTestAndVerifyURL(expectURL, 2, false);
|
144
|
+
}
|
145
|
+
|
146
|
+
private void loadData(String fileName)
|
147
|
+
{
|
148
|
+
JsonNode dataJson = ZendeskTestHelper.getJsonFromFile(fileName);
|
149
|
+
when(zendeskRestClient.doGet(any(), any(), anyBoolean())).thenReturn(dataJson.toString());
|
150
|
+
}
|
151
|
+
|
152
|
+
private void setupZendeskSupportAPIService(ZendeskInputPlugin.PluginTask task)
|
153
|
+
{
|
154
|
+
zendeskSupportAPIService = spy(new ZendeskSupportAPIService(task));
|
155
|
+
when(zendeskSupportAPIService.getZendeskRestClient()).thenReturn(zendeskRestClient);
|
156
|
+
}
|
157
|
+
|
158
|
+
private void setup(String file)
|
159
|
+
{
|
160
|
+
ZendeskInputPlugin.PluginTask task = ZendeskTestHelper.getConfigSource(file)
|
161
|
+
.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
162
|
+
setupZendeskSupportAPIService(task);
|
163
|
+
}
|
164
|
+
|
165
|
+
private void setupTestAndVerifyURL(String expectURL, int page, boolean isPreview)
|
166
|
+
{
|
167
|
+
zendeskSupportAPIService.getData("", page, isPreview, 0);
|
168
|
+
final ArgumentCaptor<String> url = ArgumentCaptor.forClass(String.class);
|
169
|
+
verify(zendeskRestClient).doGet(url.capture(), any(), anyBoolean());
|
170
|
+
assertEquals(expectURL, url.getValue());
|
171
|
+
}
|
172
|
+
}
|