embulk-input-zendesk 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/README.md +32 -2
  4. data/build.gradle +1 -1
  5. data/src/main/java/org/embulk/input/zendesk/RecordImporter.java +134 -0
  6. data/src/main/java/org/embulk/input/zendesk/ZendeskInputPlugin.java +182 -202
  7. data/src/main/java/org/embulk/input/zendesk/clients/ZendeskRestClient.java +54 -52
  8. data/src/main/java/org/embulk/input/zendesk/models/Target.java +3 -3
  9. data/src/main/java/org/embulk/input/zendesk/models/ZendeskException.java +1 -1
  10. data/src/main/java/org/embulk/input/zendesk/services/ZendeskCustomObjectService.java +110 -0
  11. data/src/main/java/org/embulk/input/zendesk/services/ZendeskNPSService.java +30 -0
  12. data/src/main/java/org/embulk/input/zendesk/services/ZendeskNormalServices.java +239 -0
  13. data/src/main/java/org/embulk/input/zendesk/services/ZendeskService.java +14 -0
  14. data/src/main/java/org/embulk/input/zendesk/services/ZendeskSupportAPIService.java +25 -83
  15. data/src/main/java/org/embulk/input/zendesk/services/ZendeskUserEventService.java +158 -0
  16. data/src/main/java/org/embulk/input/zendesk/stream/PagingSpliterator.java +40 -0
  17. data/src/main/java/org/embulk/input/zendesk/stream/paginator/sunshine/CustomObjectSpliterator.java +42 -0
  18. data/src/main/java/org/embulk/input/zendesk/stream/paginator/sunshine/SunshineSpliterator.java +66 -0
  19. data/src/main/java/org/embulk/input/zendesk/stream/paginator/sunshine/UserEventSpliterator.java +35 -0
  20. data/src/main/java/org/embulk/input/zendesk/stream/paginator/support/OrganizationSpliterator.java +13 -0
  21. data/src/main/java/org/embulk/input/zendesk/stream/paginator/support/SupportSpliterator.java +44 -0
  22. data/src/main/java/org/embulk/input/zendesk/stream/paginator/support/UserSpliterator.java +13 -0
  23. data/src/main/java/org/embulk/input/zendesk/utils/ZendeskConstants.java +13 -1
  24. data/src/main/java/org/embulk/input/zendesk/utils/ZendeskDateUtils.java +22 -11
  25. data/src/main/java/org/embulk/input/zendesk/utils/ZendeskUtils.java +52 -114
  26. data/src/test/java/org/embulk/input/zendesk/TestRecordImporter.java +114 -0
  27. data/src/test/java/org/embulk/input/zendesk/TestZendeskInputPlugin.java +184 -99
  28. data/src/test/java/org/embulk/input/zendesk/clients/TestZendeskRestClient.java +6 -20
  29. data/src/test/java/org/embulk/input/zendesk/services/TestZendeskCustomObjectService.java +161 -0
  30. data/src/test/java/org/embulk/input/zendesk/services/TestZendeskNPSService.java +56 -0
  31. data/src/test/java/org/embulk/input/zendesk/services/TestZendeskNormalService.java +189 -0
  32. data/src/test/java/org/embulk/input/zendesk/services/TestZendeskSupportAPIService.java +18 -60
  33. data/src/test/java/org/embulk/input/zendesk/services/TestZendeskUserEventService.java +158 -0
  34. data/src/test/java/org/embulk/input/zendesk/utils/TestZendeskDateUtils.java +50 -2
  35. data/src/test/java/org/embulk/input/zendesk/utils/TestZendeskUtil.java +0 -138
  36. data/src/test/java/org/embulk/input/zendesk/utils/ZendeskTestHelper.java +16 -0
  37. data/src/test/resources/config/nps.yml +29 -0
  38. data/src/test/resources/config/object_records.yml +24 -0
  39. data/src/test/resources/config/relationship_records.yml +23 -0
  40. data/src/test/resources/config/user_events.yml +29 -0
  41. data/src/test/resources/data/duplicate_user.json +0 -0
  42. data/src/test/resources/data/empty_result.json +7 -0
  43. data/src/test/resources/data/expected/user_events_column.json +40 -0
  44. data/src/test/resources/data/object_records.json +30 -0
  45. data/src/test/resources/data/organization.json +39 -0
  46. data/src/test/resources/data/relationship_records.json +57 -0
  47. data/src/test/resources/data/scores.json +21 -0
  48. data/src/test/resources/data/scores_share_same_time_with_next_page.json +35 -0
  49. data/src/test/resources/data/scores_share_same_time_without_next_page.json +35 -0
  50. data/src/test/resources/data/simple_organization.json +23 -0
  51. data/src/test/resources/data/simple_user.json +50 -0
  52. data/src/test/resources/data/simple_user_event.json +19 -0
  53. data/src/test/resources/data/ticket_events_share_same_time_with_next_page.json +279 -0
  54. data/src/test/resources/data/ticket_events_share_same_time_without_next_page.json +279 -0
  55. data/src/test/resources/data/ticket_events_updated_by_system_records.json +279 -0
  56. data/src/test/resources/data/ticket_share_same_time_with_next_page.json +232 -0
  57. data/src/test/resources/data/ticket_share_same_time_without_next_page.json +232 -0
  58. data/src/test/resources/data/ticket_with_updated_by_system_records.json +187 -0
  59. data/src/test/resources/data/user_event.json +19 -0
  60. data/src/test/resources/data/user_event_contain_latter_create_at.json +19 -0
  61. data/src/test/resources/data/user_event_multiple.json +33 -0
  62. metadata +46 -5
  63. data/src/main/java/org/embulk/input/zendesk/utils/ZendeskValidatorUtils.java +0 -79
  64. data/src/test/java/org/embulk/input/zendesk/utils/TestZendeskValidatorUtils.java +0 -130
@@ -7,25 +7,32 @@ import org.embulk.config.ConfigException;
7
7
  import org.embulk.config.ConfigSource;
8
8
  import org.embulk.config.TaskReport;
9
9
  import org.embulk.config.TaskSource;
10
+ import org.embulk.input.zendesk.models.Target;
11
+ import org.embulk.input.zendesk.services.ZendeskCustomObjectService;
12
+ import org.embulk.input.zendesk.services.ZendeskNPSService;
13
+ import org.embulk.input.zendesk.services.ZendeskService;
10
14
  import org.embulk.input.zendesk.services.ZendeskSupportAPIService;
15
+ import org.embulk.input.zendesk.services.ZendeskUserEventService;
11
16
  import org.embulk.input.zendesk.utils.ZendeskConstants;
12
17
  import org.embulk.input.zendesk.utils.ZendeskPluginTestRuntime;
13
18
  import org.embulk.input.zendesk.utils.ZendeskTestHelper;
14
19
 
20
+ import org.embulk.spi.Exec;
15
21
  import org.embulk.spi.InputPlugin;
16
22
  import org.embulk.spi.PageBuilder;
17
23
  import org.embulk.spi.PageOutput;
18
24
  import org.embulk.spi.Schema;
25
+
19
26
  import org.embulk.spi.TestPageBuilderReader;
20
27
  import org.junit.Assert;
21
-
22
28
  import org.junit.Before;
23
29
  import org.junit.Rule;
24
30
  import org.junit.Test;
25
- import org.mockito.Mockito;
26
31
 
27
32
  import static org.junit.Assert.assertEquals;
28
33
 
34
+ import static org.junit.Assert.assertTrue;
35
+ import static org.junit.Assert.fail;
29
36
  import static org.mockito.ArgumentMatchers.any;
30
37
  import static org.mockito.ArgumentMatchers.anyBoolean;
31
38
  import static org.mockito.ArgumentMatchers.anyInt;
@@ -35,10 +42,15 @@ import static org.mockito.ArgumentMatchers.anyString;
35
42
  import static org.mockito.Mockito.doReturn;
36
43
  import static org.mockito.Mockito.mock;
37
44
  import static org.mockito.Mockito.spy;
45
+
38
46
  import static org.mockito.Mockito.times;
39
47
  import static org.mockito.Mockito.verify;
40
48
  import static org.mockito.Mockito.when;
41
49
 
50
+ import java.time.Instant;
51
+ import java.time.OffsetDateTime;
52
+ import java.time.ZoneOffset;
53
+ import java.time.format.DateTimeFormatter;
42
54
  import java.util.Collections;
43
55
  import java.util.List;
44
56
  import java.util.stream.Collectors;
@@ -50,19 +62,19 @@ public class TestZendeskInputPlugin
50
62
  @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
51
63
  public ZendeskPluginTestRuntime embulk = new ZendeskPluginTestRuntime();
52
64
 
53
- private ZendeskSupportAPIService zendeskSupportAPIService = mock(ZendeskSupportAPIService.class);
65
+ private ZendeskService zendeskSupportAPIService;
54
66
 
55
67
  private ZendeskInputPlugin zendeskInputPlugin;
56
68
 
57
- private TestPageBuilderReader.MockPageOutput output = new TestPageBuilderReader.MockPageOutput();
69
+ private PageBuilder pageBuilder = mock(PageBuilder.class);
58
70
 
59
- private PageBuilder pageBuilder = Mockito.mock(PageBuilder.class);
71
+ private TestPageBuilderReader.MockPageOutput output = new TestPageBuilderReader.MockPageOutput();
60
72
 
61
73
  @Before
62
74
  public void prepare()
63
75
  {
64
76
  zendeskInputPlugin = spy(new ZendeskInputPlugin());
65
- when(zendeskInputPlugin.getZendeskSupportAPIService(any(ZendeskInputPlugin.PluginTask.class))).thenReturn(zendeskSupportAPIService);
77
+ setupSupportAPIService();
66
78
  doReturn(pageBuilder).when(zendeskInputPlugin).getPageBuilder(any(Schema.class), any(PageOutput.class));
67
79
  }
68
80
 
@@ -91,6 +103,15 @@ public class TestZendeskInputPlugin
91
103
  setupTestGuessGenerateColumn(src, "data/ticket_metrics.json", "data/expected/ticket_metrics_column.json");
92
104
  }
93
105
 
106
+ @Test
107
+ public void testGuessGenerateColumnsForUserEvents()
108
+ {
109
+ final ConfigSource src = ZendeskTestHelper.getConfigSource("base.yml");
110
+ src.set("target", "user_events");
111
+ src.set("profile_source", "dummy");
112
+ setupTestGuessGenerateColumn(src, "data/user_event.json", "data/expected/user_events_column.json");
113
+ }
114
+
94
115
  @Test
95
116
  public void testGuessGenerateColumnsForNonIncrementalTarget()
96
117
  {
@@ -110,153 +131,199 @@ public class TestZendeskInputPlugin
110
131
  }
111
132
 
112
133
  @Test
113
- public void testRunIncrementalDedup()
134
+ public void testRunSupportAPINonIncremental()
114
135
  {
115
- final ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
116
- JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/tickets.json");
117
-
118
- when(zendeskSupportAPIService.getData(anyString(), anyInt(), anyBoolean(), anyLong())).thenReturn(dataJson);
136
+ final ConfigSource src = ZendeskTestHelper.getConfigSource("non-incremental.yml");
137
+ loadData("data/ticket_fields.json");
119
138
 
120
139
  ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
121
- String nextStartTime = configDiff.get(String.class, ZendeskConstants.Field.START_TIME);
122
- verify(pageBuilder, times(4)).addRecord();
123
- verify(pageBuilder, times(1)).finish();
124
- assertEquals("2019-02-20 07:17:34 +0000", nextStartTime);
140
+ // running in 2 pages
141
+ verify(pageBuilder, times(2)).finish();
142
+ Assert.assertTrue(configDiff.isEmpty());
125
143
  }
126
144
 
127
145
  @Test
128
- public void testRunIncrementalWithNextPage()
146
+ public void testRunIncrementalStoreStartTime()
129
147
  {
130
148
  final ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
131
- JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/tickets_continue.json");
132
- JsonNode dataJsonNext = ZendeskTestHelper.getJsonFromFile("data/tickets.json");
133
- when(zendeskSupportAPIService.getData(anyString(), anyInt(), anyBoolean(), anyLong()))
134
- .thenReturn(dataJson)
135
- .thenReturn(dataJsonNext);
149
+ TaskReport taskReport = Exec.newTaskReport();
150
+ taskReport.set(ZendeskConstants.Field.START_TIME, 1557026576);
151
+
152
+ when(zendeskSupportAPIService.isSupportIncremental()).thenReturn(true);
153
+ when(zendeskSupportAPIService.addRecordToImporter(anyInt(), any())).thenReturn(taskReport);
136
154
 
137
155
  ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
138
156
  String nextStartTime = configDiff.get(String.class, ZendeskConstants.Field.START_TIME);
139
- verify(pageBuilder, times(1)).addRecord();
140
157
  verify(pageBuilder, times(1)).finish();
141
- assertEquals("2019-02-20 07:17:34 +0000", nextStartTime);
158
+ assertEquals("2019-05-05 03:22:56 +0000", nextStartTime);
142
159
  }
143
160
 
144
161
  @Test
145
- public void testRunIncrementalNonDedup()
162
+ public void testDispatchPerTargetShouldReturnSupportAPIService()
146
163
  {
147
- final ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
148
- src.set("dedup", false);
149
-
150
- JsonNode dataJsonNext = ZendeskTestHelper.getJsonFromFile("data/tickets.json");
151
- when(zendeskSupportAPIService.getData(anyString(), anyInt(), anyBoolean(), anyLong())).thenReturn(dataJsonNext);
152
-
153
- ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
154
- String nextStartTime = configDiff.get(String.class, ZendeskConstants.Field.START_TIME);
155
- verify(pageBuilder, times(5)).addRecord();
156
- verify(pageBuilder, times(1)).finish();
157
- assertEquals("2019-02-20 07:17:34 +0000", nextStartTime);
164
+ // create a new one so it doesn't mock the ZendeskService
165
+ zendeskInputPlugin = spy(new ZendeskInputPlugin());
166
+ testReturnSupportAPIService(Target.TICKETS);
167
+ testReturnSupportAPIService(Target.TICKET_METRICS);
168
+ testReturnSupportAPIService(Target.TICKET_EVENTS);
169
+ testReturnSupportAPIService(Target.TICKET_FORMS);
170
+ testReturnSupportAPIService(Target.TICKET_FIELDS);
171
+ testReturnSupportAPIService(Target.USERS);
172
+ testReturnSupportAPIService(Target.ORGANIZATIONS);
158
173
  }
159
174
 
160
175
  @Test
161
- public void testRunIncrementalForTicketMetrics()
176
+ public void testDispatchPerTargetShouldReturnNPSService()
162
177
  {
163
- final ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
164
- src.set("target", "ticket_metrics");
165
- JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/ticket_metrics.json");
166
-
167
- when(zendeskSupportAPIService.getData(anyString(), anyInt(), anyBoolean(), anyLong())).thenReturn(dataJson);
168
-
169
- ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
170
- String nextStartTime = configDiff.get(String.class, ZendeskConstants.Field.START_TIME);
171
- verify(pageBuilder, times(3)).addRecord();
172
- verify(pageBuilder, times(1)).finish();
173
- assertEquals("2019-02-20 07:17:34 +0000", nextStartTime);
178
+ // create a new one so it doesn't mock the ZendeskService
179
+ zendeskInputPlugin = spy(new ZendeskInputPlugin());
180
+ testReturnNPSService(Target.SCORES);
181
+ testReturnNPSService(Target.RECIPIENTS);
174
182
  }
175
183
 
176
184
  @Test
177
- public void testRunIncrementalWithRelatedObject()
185
+ public void testDispatchPerTargetShouldReturnCustomObjectService()
178
186
  {
179
- final ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
180
- src.set("includes", Collections.singletonList("organizations"));
181
-
182
- JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/tickets.json");
183
- JsonNode dataJsonObject = ZendeskTestHelper.getJsonFromFile("data/ticket_with_related_objects.json");
184
- when(zendeskSupportAPIService.getData(anyString(), anyInt(), anyBoolean(), anyLong()))
185
- .thenReturn(dataJson)
186
- .thenReturn(dataJsonObject);
187
+ // create a new one so it doesn't mock the ZendeskService
188
+ zendeskInputPlugin = spy(new ZendeskInputPlugin());
189
+ testReturnCustomObjectService(Target.OBJECT_RECORDS);
190
+ testReturnCustomObjectService(Target.RELATIONSHIP_RECORDS);
191
+ }
187
192
 
188
- ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
193
+ @Test
194
+ public void testDispatchPerTargetShouldReturnUserEventService()
195
+ {
196
+ // create a new one so it doesn't mock the ZendeskService
197
+ zendeskInputPlugin = spy(new ZendeskInputPlugin());
198
+ final ConfigSource src = ZendeskTestHelper.getConfigSource("base.yml");
199
+ src.set("target", Target.USER_EVENTS.name().toLowerCase());
200
+ src.set("profile_source", "dummy");
201
+ src.set("columns", Collections.EMPTY_LIST);
202
+ ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
203
+ ZendeskService zendeskService = zendeskInputPlugin.dispatchPerTarget(task);
204
+ assertTrue(zendeskService instanceof ZendeskUserEventService);
205
+ }
189
206
 
190
- verify(pageBuilder, times(1)).finish();
191
- String nextStartTime = configDiff.get(String.class, ZendeskConstants.Field.START_TIME);
192
- assertEquals("2019-02-20 07:17:34 +0000", nextStartTime);
207
+ @Test
208
+ public void validateCredentialOauthShouldThrowException()
209
+ {
210
+ ConfigSource configSource = ZendeskTestHelper.getConfigSource("base_validator.yml");
211
+ configSource.set("auth_method", "oauth");
212
+ configSource.remove("access_token");
213
+ assertValidation(configSource, "access_token is required for authentication method 'oauth'");
193
214
  }
194
215
 
195
216
  @Test
196
- public void testRunNonIncremental()
217
+ public void validateCredentialBasicShouldThrowException()
197
218
  {
198
- final ConfigSource src = ZendeskTestHelper.getConfigSource("non-incremental.yml");
199
- loadData("data/ticket_fields.json");
219
+ ConfigSource configSource = ZendeskTestHelper.getConfigSource("base_validator.yml");
220
+ configSource.set("auth_method", "basic");
221
+ configSource.remove("username");
222
+ assertValidation(configSource, "username and password are required for authentication method 'basic'");
223
+
224
+ configSource.set("username", "");
225
+ configSource.remove("password");
226
+ assertValidation(configSource, "username and password are required for authentication method 'basic'");
227
+ }
200
228
 
201
- ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
202
- // running in 2 pages
203
- verify(pageBuilder, times(7 * 2)).addRecord();
204
- verify(pageBuilder, times(2)).finish();
205
- Assert.assertTrue(configDiff.isEmpty());
229
+ @Test
230
+ public void validateCredentialTokenShouldThrowException()
231
+ {
232
+ ConfigSource configSource = ZendeskTestHelper.getConfigSource("base_validator.yml");
233
+ configSource.set("auth_method", "token");
234
+ configSource.remove("token");
235
+ assertValidation(configSource, "username and token are required for authentication method 'token'");
236
+
237
+ configSource.set("token", "");
238
+ configSource.remove("username");
239
+ assertValidation(configSource, "username and token are required for authentication method 'token'");
206
240
  }
207
241
 
208
242
  @Test
209
- public void testRunNotGenerateStartTimeWhenRunningInNonIncrementalModeAndTargetSupportIncremental()
243
+ public void validateAppMarketPlaceShouldThrowException()
210
244
  {
211
- final ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
212
- src.set("incremental", false);
213
- loadData("data/tickets.json");
245
+ ConfigSource configSource = ZendeskTestHelper.getConfigSource("base_validator.yml");
246
+ configSource.remove("app_marketplace_integration_name");
247
+ assertValidation(configSource, "All of app_marketplace_integration_name, app_marketplace_org_id, " +
248
+ "app_marketplace_app_id " +
249
+ "are required to fill out for Apps Marketplace API header");
250
+ }
214
251
 
215
- ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
252
+ @Test
253
+ public void validateCustomObjectShouldThrowException()
254
+ {
255
+ ConfigSource configSource = ZendeskTestHelper.getConfigSource("base_validator.yml");
256
+ configSource.set("target", Target.OBJECT_RECORDS.name().toLowerCase());
257
+ assertValidation(configSource, "Should have at least one Object Type");
216
258
 
217
- Assert.assertTrue(configDiff.isEmpty());
259
+ configSource.set("target", Target.RELATIONSHIP_RECORDS.name().toLowerCase());
260
+ assertValidation(configSource, "Should have at least one Relationship Type");
218
261
  }
219
262
 
220
263
  @Test
221
- public void testRunNotGenerateStartTimeWhenRunningInIncrementalModeAndTargetDoesNotSupportIncremental()
264
+ public void validateUserEventShouldThrowException()
222
265
  {
223
- final ConfigSource src = ZendeskTestHelper.getConfigSource("non-incremental.yml");
224
- src.set("incremental", true);
225
- loadData("data/ticket_fields.json");
226
-
227
- ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
266
+ ConfigSource configSource = ZendeskTestHelper.getConfigSource("base_validator.yml");
267
+ configSource.set("target", Target.USER_EVENTS.name().toLowerCase());
268
+ assertValidation(configSource, "Profile Source is required for User Event Target");
269
+
270
+ configSource.set("profile_source", "");
271
+ configSource.set("start_time", OffsetDateTime.ofInstant(Instant.ofEpochSecond(Instant.now().getEpochSecond()), ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
272
+ configSource.set("end_time", "2019-12-2 22-12-22");
273
+ assertValidation(configSource, "End Time should follow these format " + ZendeskConstants.Misc.SUPPORT_DATE_TIME_FORMAT.toString());
274
+
275
+ configSource.set("start_time", OffsetDateTime.ofInstant(Instant.ofEpochSecond(Instant.now().getEpochSecond() + 3600), ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
276
+ configSource.set("end_time", OffsetDateTime.ofInstant(Instant.ofEpochSecond(Instant.now().getEpochSecond()), ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
277
+ assertValidation(configSource, "End Time should be later or equal than Start Time");
278
+ }
228
279
 
229
- Assert.assertTrue(configDiff.isEmpty());
280
+ private void assertValidation(final ConfigSource configSource, final String message)
281
+ {
282
+ try {
283
+ zendeskInputPlugin.guess(configSource);
284
+ fail("Should not reach here");
285
+ }
286
+ catch (final Exception e) {
287
+ assertEquals(message, e.getMessage());
288
+ }
230
289
  }
231
290
 
232
- @Test
233
- public void testRunIncrementalGenerateStartTimeWhenRunningInIncrementalModeAndTargetSupportIncremental()
291
+ private void testReturnSupportAPIService(Target target)
234
292
  {
235
- String expectedStartTime = "2019-02-20 07:17:34 +0000";
236
- final ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
237
- loadData("data/tickets.json");
293
+ final ConfigSource src = ZendeskTestHelper.getConfigSource("base.yml");
294
+ src.set("target", target.name().toLowerCase());
295
+ src.set("columns", Collections.EMPTY_LIST);
296
+ ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
297
+ ZendeskService zendeskService = zendeskInputPlugin.dispatchPerTarget(task);
298
+ assertTrue(zendeskService instanceof ZendeskSupportAPIService);
299
+ }
238
300
 
239
- ConfigDiff configDiff = zendeskInputPlugin.transaction(src, new Control());
240
- Assert.assertFalse(configDiff.isEmpty());
241
- Assert.assertEquals(expectedStartTime, configDiff.get(String.class, ZendeskConstants.Field.START_TIME));
301
+ private void testReturnNPSService(Target target)
302
+ {
303
+ final ConfigSource src = ZendeskTestHelper.getConfigSource("base.yml");
304
+ src.set("target", target.name().toLowerCase());
305
+ src.set("columns", Collections.EMPTY_LIST);
306
+ ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
307
+ ZendeskService zendeskService = zendeskInputPlugin.dispatchPerTarget(task);
308
+ assertTrue(zendeskService instanceof ZendeskNPSService);
242
309
  }
243
310
 
244
- private class Control implements InputPlugin.Control
311
+ private void testReturnCustomObjectService(Target target)
245
312
  {
246
- @Override
247
- public List<TaskReport> run(final TaskSource taskSource, final Schema schema, final int taskCount)
248
- {
249
- List<TaskReport> reports = IntStream.range(0, taskCount)
250
- .mapToObj(i -> zendeskInputPlugin.run(taskSource, schema, i, output))
251
- .collect(Collectors.toList());
252
- return reports;
253
- }
313
+ final ConfigSource src = ZendeskTestHelper.getConfigSource("base.yml");
314
+ src.set("target", target.name().toLowerCase());
315
+ src.set("relationship_types", Collections.singletonList("dummy"));
316
+ src.set("object_types", Collections.singletonList("account"));
317
+ src.set("columns", Collections.EMPTY_LIST);
318
+ ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
319
+ ZendeskService zendeskService = zendeskInputPlugin.dispatchPerTarget(task);
320
+ assertTrue(zendeskService instanceof ZendeskCustomObjectService);
254
321
  }
255
322
 
256
323
  private void loadData(String fileName)
257
324
  {
258
325
  JsonNode dataJson = ZendeskTestHelper.getJsonFromFile(fileName);
259
- when(zendeskSupportAPIService.getData(anyString(), anyInt(), anyBoolean(), anyLong())).thenReturn(dataJson);
326
+ when(zendeskSupportAPIService.getDataFromPath(anyString(), anyInt(), anyBoolean(), anyLong())).thenReturn(dataJson);
260
327
  }
261
328
 
262
329
  private void setupTestGuessGenerateColumn(ConfigSource src, String fileName, String expectedSource)
@@ -266,4 +333,22 @@ public class TestZendeskInputPlugin
266
333
  JsonNode columns = configDiff.get(JsonNode.class, "columns");
267
334
  assertEquals(ZendeskTestHelper.getJsonFromFile(expectedSource), columns);
268
335
  }
336
+
337
+ private void setupSupportAPIService()
338
+ {
339
+ zendeskSupportAPIService = mock(ZendeskSupportAPIService.class);
340
+ doReturn(zendeskSupportAPIService).when(zendeskInputPlugin).dispatchPerTarget(any(ZendeskInputPlugin.PluginTask.class));
341
+ }
342
+
343
+ private class Control implements InputPlugin.Control
344
+ {
345
+ @Override
346
+ public List<TaskReport> run(final TaskSource taskSource, final Schema schema, final int taskCount)
347
+ {
348
+ List<TaskReport> reports = IntStream.range(0, taskCount)
349
+ .mapToObj(i -> zendeskInputPlugin.run(taskSource, schema, i, output))
350
+ .collect(Collectors.toList());
351
+ return reports;
352
+ }
353
+ }
269
354
  }
@@ -10,27 +10,19 @@ import org.apache.http.client.HttpClient;
10
10
  import org.apache.http.client.methods.HttpRequestBase;
11
11
  import org.apache.http.entity.StringEntity;
12
12
 
13
+ import org.embulk.EmbulkTestRuntime;
13
14
  import org.embulk.config.ConfigException;
14
15
  import org.embulk.config.ConfigSource;
15
- import org.embulk.input.zendesk.ZendeskInputPlugin;
16
16
  import org.embulk.input.zendesk.ZendeskInputPlugin.PluginTask;
17
- import org.embulk.input.zendesk.utils.ZendeskPluginTestRuntime;
18
17
  import org.embulk.input.zendesk.utils.ZendeskTestHelper;
19
18
 
20
19
  import org.embulk.input.zendesk.utils.ZendeskUtils;
21
- import org.embulk.spi.InputPlugin;
22
- import org.embulk.test.TestingEmbulk;
23
20
 
24
21
  import org.junit.Before;
25
22
  import org.junit.Rule;
26
23
  import org.junit.Test;
27
24
 
28
- import org.junit.rules.ExpectedException;
29
- import org.junit.rules.RuleChain;
30
- import org.junit.rules.TestRule;
31
-
32
25
  import org.mockito.ArgumentCaptor;
33
- import org.mockito.Mockito;
34
26
 
35
27
  import static org.apache.http.HttpHeaders.AUTHORIZATION;
36
28
  import static org.junit.Assert.assertEquals;
@@ -49,24 +41,18 @@ import java.util.Optional;
49
41
 
50
42
  public class TestZendeskRestClient
51
43
  {
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
44
  @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
60
- public TestRule chain = RuleChain.outerRule(embulk).around(runtime).around(thrown);
45
+ @Rule
46
+ public EmbulkTestRuntime embulkTestRuntime = new EmbulkTestRuntime();
61
47
 
62
48
  private ZendeskRestClient zendeskRestClient;
63
49
  private PluginTask task = ZendeskTestHelper.getConfigSource("incremental.yml").loadConfig(PluginTask.class);
64
50
  private JsonNode data = ZendeskTestHelper.getJsonFromFile("data/client.json");
65
51
 
66
- private HttpClient client = Mockito.mock(HttpClient.class);
67
- private HttpResponse response = Mockito.mock(HttpResponse.class);
52
+ private HttpClient client = mock(HttpClient.class);
53
+ private HttpResponse response = mock(HttpResponse.class);
68
54
  private Header header = mock(Header.class);
69
- private StatusLine statusLine = Mockito.mock(StatusLine.class);
55
+ private StatusLine statusLine = mock(StatusLine.class);
70
56
 
71
57
  @Before
72
58
  public void prepare() throws IOException