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
@@ -0,0 +1,158 @@
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.input.zendesk.RecordImporter;
7
+ import org.embulk.input.zendesk.ZendeskInputPlugin.PluginTask;
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 java.util.Arrays;
16
+ import java.util.List;
17
+
18
+ import static org.junit.Assert.assertEquals;
19
+ import static org.junit.Assert.assertFalse;
20
+ import static org.junit.Assert.assertTrue;
21
+ import static org.mockito.ArgumentMatchers.any;
22
+ import static org.mockito.ArgumentMatchers.anyBoolean;
23
+ import static org.mockito.ArgumentMatchers.eq;
24
+ import static org.mockito.Mockito.mock;
25
+ import static org.mockito.Mockito.spy;
26
+ import static org.mockito.Mockito.times;
27
+ import static org.mockito.Mockito.verify;
28
+ import static org.mockito.Mockito.when;
29
+
30
+ public class TestZendeskUserEventService
31
+ {
32
+ private RecordImporter recordImporter;
33
+
34
+ @Rule
35
+ @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
36
+ public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
37
+ private ZendeskRestClient zendeskRestClient;
38
+ private ZendeskUserEventService zendeskUserEventService;
39
+
40
+ @Before
41
+ public void prepare()
42
+ {
43
+ zendeskRestClient = mock(ZendeskRestClient.class);
44
+ recordImporter = mock(RecordImporter.class);
45
+ }
46
+
47
+ @Test
48
+ public void testGetData()
49
+ {
50
+ setup();
51
+
52
+ JsonNode jsonNode = zendeskUserEventService.getDataFromPath("https://abc.zendesk.com/api/sunshine/objects/records?type=user&per_page=1000", 0, true, 0);
53
+ assertFalse(jsonNode.isNull());
54
+ assertTrue(jsonNode.has("data"));
55
+ assertTrue(jsonNode.get("data").isArray());
56
+ }
57
+
58
+ @Test
59
+ public void testAddRecordToImporterInPreviewMode()
60
+ {
61
+ setup();
62
+ ZendeskTestHelper.setPreviewMode(runtime, true);
63
+ zendeskUserEventService.addRecordToImporter(0, recordImporter);
64
+ verify(recordImporter, times(1)).addRecord(any());
65
+ }
66
+
67
+ @Test
68
+ public void testUrlForUserEvent()
69
+ {
70
+ ZendeskTestHelper.setPreviewMode(runtime, false);
71
+ setup();
72
+ JsonNode dataJsonOrganization = ZendeskTestHelper.getJsonFromFile("data/simple_organization.json");
73
+ JsonNode dataJsonUser = ZendeskTestHelper.getJsonFromFile("data/simple_user.json");
74
+ JsonNode dataJsonUserEventWithLatterTime = ZendeskTestHelper.getJsonFromFile("data/user_event_contain_latter_create_at.json");
75
+
76
+ when(zendeskRestClient.doGet(any(), any(), anyBoolean()))
77
+ .thenReturn(dataJsonOrganization.toString())
78
+ .thenReturn(dataJsonUser.toString())
79
+ .thenReturn(dataJsonUserEventWithLatterTime.toString());
80
+
81
+ String expectedURIForOrganization = "https://abc.zendesk.com/api/v2/organizations?per_page=100&page=1";
82
+ String expectedURIForUser = "https://abc.zendesk.com/api/v2/organizations/360857467053/users.json?per_page=100&page=1";
83
+ String expectedURIForUserEvent = "https://abc.zendesk.com/api/sunshine/events?identifier=support%3Auser_id%3A1194092277&start_time=2019-01-20T07%3A14%3A50Z&end_time=2019-06-20T07%3A14%3A53Z";
84
+ List<String> expectedURI = Arrays.asList(expectedURIForOrganization, expectedURIForUser, expectedURIForUserEvent);
85
+
86
+ zendeskUserEventService.addRecordToImporter(0, recordImporter);
87
+ ArgumentCaptor<String> uri = ArgumentCaptor.forClass(String.class);
88
+ verify(zendeskRestClient, times(3)).doGet(uri.capture(), any(), anyBoolean());
89
+ assertEquals(expectedURI, uri.getAllValues());
90
+ }
91
+
92
+ @Test
93
+ public void testAddRecordToImporterInNonPreviewMode()
94
+ {
95
+ ZendeskTestHelper.setPreviewMode(runtime, false);
96
+ PluginTask task = setup();
97
+
98
+ JsonNode dataJsonOrganization = ZendeskTestHelper.getJsonFromFile("data/organization.json");
99
+ JsonNode dataJsonUser = ZendeskTestHelper.getJsonFromFile("data/simple_user.json");
100
+ JsonNode dataJsonUserEvent = ZendeskTestHelper.getJsonFromFile("data/user_event.json");
101
+
102
+ // 2 organizations but return the same user.
103
+ when(zendeskRestClient.doGet(eq("https://abc.zendesk.com/api/v2/organizations?per_page=100&page=1"), eq(task), eq(false)))
104
+ .thenReturn(dataJsonOrganization.toString());
105
+ when(zendeskRestClient.doGet(eq("https://abc.zendesk.com/api/v2/organizations/360857467053/users.json?per_page=100&page=1"), eq(task), eq(false)))
106
+ .thenReturn(dataJsonUser.toString());
107
+ when(zendeskRestClient.doGet(eq("https://abc.zendesk.com/api/v2/organizations/360857467055/users.json?per_page=100&page=1"), eq(task), eq(false)))
108
+ .thenReturn(dataJsonUser.toString());
109
+ when(zendeskRestClient.doGet(eq("https://abc.zendesk.com/api/sunshine/events?identifier=support%3Auser_id%3A1194092277&start_time=2019-01-20T07%3A14%3A50Z&end_time=2019-06-20T07%3A14%3A53Z"), eq(task), eq(false)))
110
+ .thenReturn(dataJsonUserEvent.toString());
111
+
112
+ zendeskUserEventService.addRecordToImporter(0, recordImporter);
113
+ // non dedup
114
+ verify(recordImporter, times(2)).addRecord(any());
115
+ }
116
+
117
+ @Test
118
+ public void testAddRecordToImporterWithDuplicateUser()
119
+ {
120
+ ZendeskTestHelper.setPreviewMode(runtime, false);
121
+ PluginTask task = ZendeskTestHelper.getConfigSource("user_events.yml")
122
+ .set("dedup", true)
123
+ .loadConfig(PluginTask.class);
124
+ setupZendeskSupportAPIService(task);
125
+
126
+ JsonNode dataJsonOrganization = ZendeskTestHelper.getJsonFromFile("data/organization.json");
127
+ JsonNode dataJsonUser = ZendeskTestHelper.getJsonFromFile("data/simple_user.json");
128
+ JsonNode dataJsonUserEvent = ZendeskTestHelper.getJsonFromFile("data/user_event.json");
129
+ // 2 organizations but return the same user.
130
+ when(zendeskRestClient.doGet(eq("https://abc.zendesk.com/api/v2/organizations?per_page=100&page=1"), eq(task), eq(false)))
131
+ .thenReturn(dataJsonOrganization.toString());
132
+ when(zendeskRestClient.doGet(eq("https://abc.zendesk.com/api/v2/organizations/360857467053/users.json?per_page=100&page=1"), eq(task), eq(false)))
133
+ .thenReturn(dataJsonUser.toString());
134
+ when(zendeskRestClient.doGet(eq("https://abc.zendesk.com/api/v2/organizations/360857467055/users.json?per_page=100&page=1"), eq(task), eq(false)))
135
+ .thenReturn(dataJsonUser.toString());
136
+ when(zendeskRestClient.doGet(eq("https://abc.zendesk.com/api/sunshine/events?identifier=support%3Auser_id%3A1194092277&start_time=2019-01-20T07%3A14%3A50Z&end_time=2019-06-20T07%3A14%3A53Z"), eq(task), eq(false)))
137
+ .thenReturn(dataJsonUserEvent.toString());
138
+
139
+ zendeskUserEventService.addRecordToImporter(0, recordImporter);
140
+
141
+ // expected to call fetchUserEvent only one time
142
+ verify(recordImporter, times(1)).addRecord(any());
143
+ }
144
+
145
+ private void setupZendeskSupportAPIService(PluginTask task)
146
+ {
147
+ zendeskUserEventService = spy(new ZendeskUserEventService(task));
148
+ when(zendeskUserEventService.getZendeskRestClient()).thenReturn(zendeskRestClient);
149
+ }
150
+
151
+ private PluginTask setup()
152
+ {
153
+ PluginTask task = ZendeskTestHelper.getConfigSource("user_events.yml")
154
+ .loadConfig(PluginTask.class);
155
+ setupZendeskSupportAPIService(task);
156
+ return task;
157
+ }
158
+ }
@@ -3,12 +3,18 @@ package org.embulk.input.zendesk.utils;
3
3
  import org.embulk.spi.DataException;
4
4
  import org.junit.Assert;
5
5
  import org.junit.Test;
6
+
7
+ import java.util.Optional;
8
+
9
+ import static org.junit.Assert.assertEquals;
10
+ import static org.junit.Assert.assertFalse;
6
11
  import static org.junit.Assert.assertThrows;
12
+ import static org.junit.Assert.assertTrue;
7
13
 
8
14
  public class TestZendeskDateUtils
9
15
  {
10
16
  @Test
11
- public void isoToEpochSecondShouldReturnCorrectValue()
17
+ public void testIsoToEpochSecondShouldReturnCorrectValue()
12
18
  {
13
19
  long expectedValue = 1550645445;
14
20
 
@@ -29,11 +35,53 @@ public class TestZendeskDateUtils
29
35
  }
30
36
 
31
37
  @Test
32
- public void isoToEpochSecondShouldThrowException()
38
+ public void testIsoToEpochSecondShouldThrowException()
33
39
  {
34
40
  assertThrows(DataException.class, () -> ZendeskDateUtils.isoToEpochSecond("2019-02asdasdasd-20T06:50:45Z"));
35
41
  assertThrows(DataException.class, () -> ZendeskDateUtils.isoToEpochSecond("2019-002-20T06:50:45Z"));
36
42
  assertThrows(DataException.class, () -> ZendeskDateUtils.isoToEpochSecond("2019-02-200T06:50:45.000Z"));
37
43
  assertThrows(DataException.class, () -> ZendeskDateUtils.isoToEpochSecond("2019-02-20T24:01:00Z"));
38
44
  }
45
+
46
+ @Test
47
+ public void testConvertToDateTimeFormat()
48
+ {
49
+ String expectedString = "2019-05-01T07:14:50Z";
50
+
51
+ String actualString = ZendeskDateUtils.convertToDateTimeFormat("2019-05-01 07:14:50 +0000", ZendeskConstants.Misc.ISO_INSTANT);
52
+ assertEquals(expectedString, actualString);
53
+
54
+ actualString = ZendeskDateUtils.convertToDateTimeFormat("2019-05-01 07:14:50+0000", ZendeskConstants.Misc.ISO_INSTANT);
55
+ assertEquals(expectedString, actualString);
56
+
57
+ actualString = ZendeskDateUtils.convertToDateTimeFormat("2019-05-01T07:14:50.000Z", ZendeskConstants.Misc.ISO_INSTANT);
58
+ assertEquals(expectedString, actualString);
59
+
60
+ actualString = ZendeskDateUtils.convertToDateTimeFormat("2019-05-01T07:14:50+00:00", ZendeskConstants.Misc.ISO_INSTANT);
61
+ assertEquals(expectedString, actualString);
62
+ }
63
+
64
+ @Test
65
+ public void testSupportedTimeFormat()
66
+ {
67
+ Optional optional = ZendeskDateUtils.supportedTimeFormat("2019-05-01 07:14:50+0000");
68
+ assertTrue(optional.isPresent());
69
+
70
+ optional = ZendeskDateUtils.supportedTimeFormat("2019-05-01T07:14:50");
71
+ assertFalse(optional.isPresent());
72
+ }
73
+
74
+ @Test
75
+ public void testGetStartTime()
76
+ {
77
+ long expectedValue = 1550645445;
78
+ long actualValue = ZendeskDateUtils.getStartTime("2019-02-20 06:512310:45 +0000");
79
+ assertEquals(0, actualValue);
80
+
81
+ actualValue = ZendeskDateUtils.getStartTime("2019-02-30 06:50:45 +0000");
82
+ assertEquals(ZendeskDateUtils.getStartTime("2019-02-28 06:50:45 +0000"), actualValue);
83
+
84
+ actualValue = ZendeskDateUtils.getStartTime("2019-02-20 06:50:45 +0000");
85
+ assertEquals(expectedValue, actualValue);
86
+ }
39
87
  }
@@ -1,35 +1,10 @@
1
1
  package org.embulk.input.zendesk.utils;
2
2
 
3
- import com.fasterxml.jackson.databind.JsonNode;
4
3
  import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
5
4
  import org.embulk.EmbulkTestRuntime;
6
- import org.embulk.input.zendesk.ZendeskInputPlugin.PluginTask;
7
- import org.embulk.input.zendesk.models.Target;
8
- import org.embulk.input.zendesk.services.ZendeskSupportAPIService;
9
- import org.embulk.spi.Column;
10
- import org.embulk.spi.PageBuilder;
11
- import org.embulk.spi.Schema;
12
- import org.embulk.spi.json.JsonParser;
13
- import org.embulk.spi.time.Timestamp;
14
- import org.embulk.spi.time.TimestampParser;
15
-
16
- import org.junit.Assert;
17
- import org.junit.BeforeClass;
18
5
  import org.junit.Rule;
19
6
  import org.junit.Test;
20
- import org.mockito.Mockito;
21
- import org.msgpack.value.Value;
22
-
23
7
  import static org.junit.Assert.assertEquals;
24
- import static org.mockito.ArgumentMatchers.anyBoolean;
25
- import static org.mockito.ArgumentMatchers.anyInt;
26
- import static org.mockito.ArgumentMatchers.anyLong;
27
- import static org.mockito.ArgumentMatchers.anyString;
28
-
29
- import static org.mockito.Mockito.mock;
30
- import static org.mockito.Mockito.times;
31
- import static org.mockito.Mockito.verify;
32
- import static org.mockito.Mockito.when;
33
8
 
34
9
  public class TestZendeskUtil
35
10
  {
@@ -37,119 +12,6 @@ public class TestZendeskUtil
37
12
  @SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
38
13
  public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
39
14
 
40
- private static Schema schema;
41
- private static Column booleanColumn;
42
- private static Column longColumn;
43
- private static Column doubleColumn;
44
- private static Column stringColumn;
45
- private static Column dateColumn;
46
- private static Column jsonColumn;
47
-
48
- private static ZendeskSupportAPIService zendeskSupportAPIService;
49
-
50
- @BeforeClass
51
- public static void setUp()
52
- {
53
- zendeskSupportAPIService = mock(ZendeskSupportAPIService.class);
54
- PluginTask pluginTask = ZendeskTestHelper.getConfigSource("util.yml").loadConfig(PluginTask.class);
55
- schema = pluginTask.getColumns().toSchema();
56
- booleanColumn = schema.getColumn(0);
57
- longColumn = schema.getColumn(1);
58
- doubleColumn = schema.getColumn(2);
59
- stringColumn = schema.getColumn(3);
60
- dateColumn = schema.getColumn(4);
61
- jsonColumn = schema.getColumn(5);
62
- }
63
-
64
- @Test
65
- public void testIsSupportIncrementalShouldReturnTrue()
66
- {
67
- boolean result = ZendeskUtils.isSupportAPIIncremental(Target.TICKETS);
68
- Assert.assertTrue(result);
69
-
70
- result = ZendeskUtils.isSupportAPIIncremental(Target.USERS);
71
- Assert.assertTrue(result);
72
-
73
- result = ZendeskUtils.isSupportAPIIncremental(Target.ORGANIZATIONS);
74
- Assert.assertTrue(result);
75
-
76
- result = ZendeskUtils.isSupportAPIIncremental(Target.TICKET_EVENTS);
77
- Assert.assertTrue(result);
78
-
79
- result = ZendeskUtils.isSupportAPIIncremental(Target.TICKET_METRICS);
80
- Assert.assertTrue(result);
81
- }
82
-
83
- @Test
84
- public void testNumberToSplitWithHintingInTaskWithNonIncrementalTarget()
85
- {
86
- JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/util_page.json");
87
- when(zendeskSupportAPIService.getData(anyString(), anyInt(), anyBoolean(), anyLong())).thenReturn(dataJson);
88
- int number = ZendeskUtils.numberToSplitWithHintingInTask(2101);
89
- assertEquals(22, number);
90
-
91
- number = ZendeskUtils.numberToSplitWithHintingInTask(2100);
92
- assertEquals(21, number);
93
-
94
- number = ZendeskUtils.numberToSplitWithHintingInTask(2099);
95
- assertEquals(21, number);
96
- }
97
-
98
- @Test
99
- public void testAddRecordAllRight()
100
- {
101
- String name = "allRight";
102
- JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/util.json").get(name);
103
- PageBuilder mock = Mockito.mock(PageBuilder.class);
104
-
105
- Boolean boolValue = Boolean.TRUE;
106
- long longValue = 1;
107
- double doubleValue = 1;
108
- String stringValue = "string";
109
- Timestamp dateValue = TimestampParser.of("%Y-%m-%dT%H:%M:%S%z", "UTC").parse("2019-01-01T00:00:00Z");
110
- Value jsonValue = new JsonParser().parse("{}");
111
-
112
- ZendeskUtils.addRecord(dataJson, schema, mock);
113
-
114
- verify(mock, times(1)).setBoolean(booleanColumn, boolValue);
115
- verify(mock, times(1)).setLong(longColumn, longValue);
116
- verify(mock, times(1)).setDouble(doubleColumn, doubleValue);
117
- verify(mock, times(1)).setString(stringColumn, stringValue);
118
- verify(mock, times(1)).setTimestamp(dateColumn, dateValue);
119
- verify(mock, times(1)).setJson(jsonColumn, jsonValue);
120
- }
121
-
122
- @Test
123
- public void testAddRecordAllWrong()
124
- {
125
- String name = "allWrong";
126
- JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/util.json").get(name);
127
- PageBuilder mock = Mockito.mock(PageBuilder.class);
128
-
129
- Value jsonValue = new JsonParser().parse("{}");
130
-
131
- ZendeskUtils.addRecord(dataJson, schema, mock);
132
-
133
- verify(mock, times(1)).setNull(booleanColumn);
134
- verify(mock, times(1)).setNull(longColumn);
135
- verify(mock, times(1)).setNull(doubleColumn);
136
- verify(mock, times(1)).setNull(stringColumn);
137
- verify(mock, times(1)).setNull(dateColumn);
138
- verify(mock, times(1)).setJson(jsonColumn, jsonValue);
139
- }
140
-
141
- @Test
142
- public void testAddRecordAllMissing()
143
- {
144
- String name = "allMissing";
145
- JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/util.json").get(name);
146
- PageBuilder mock = Mockito.mock(PageBuilder.class);
147
-
148
- ZendeskUtils.addRecord(dataJson, schema, mock);
149
-
150
- verify(mock, times(6)).setNull(Mockito.any(Column.class));
151
- }
152
-
153
15
  @Test
154
16
  public void testConvertBase64()
155
17
  {
@@ -4,14 +4,17 @@ import com.fasterxml.jackson.databind.JsonNode;
4
4
  import com.fasterxml.jackson.databind.ObjectMapper;
5
5
  import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
6
6
 
7
+ import org.embulk.EmbulkTestRuntime;
7
8
  import org.embulk.config.ConfigLoader;
8
9
  import org.embulk.config.ConfigSource;
9
10
  import org.embulk.config.ModelManager;
11
+ import org.embulk.spi.ExecSession;
10
12
  import org.embulk.test.EmbulkTests;
11
13
  import org.junit.Assert;
12
14
 
13
15
  import java.io.IOException;
14
16
  import java.io.InputStream;
17
+ import java.lang.reflect.Field;
15
18
 
16
19
  import static junit.framework.TestCase.fail;
17
20
 
@@ -60,4 +63,17 @@ public final class ZendeskTestHelper
60
63
  }
61
64
  return configSource;
62
65
  }
66
+
67
+ public static void setPreviewMode(final EmbulkTestRuntime runtime, final boolean isPreview)
68
+ {
69
+ // A small hack to make the plugin executed in preview mode so
70
+ try {
71
+ final Field previewField = ExecSession.class.getDeclaredField("preview");
72
+ previewField.setAccessible(true);
73
+ previewField.set(runtime.getExec(), isPreview);
74
+ }
75
+ catch (NoSuchFieldException | IllegalAccessException e) {
76
+ Assert.fail(e.getMessage());
77
+ }
78
+ }
63
79
  }
@@ -0,0 +1,29 @@
1
+ type: zendesk
2
+ login_url: https://abc.zendesk.com
3
+ auth_method: oauth
4
+ username: dummy
5
+ password: dummy
6
+ token: dummy
7
+ access_token: dummy
8
+ target: scores
9
+ app_marketplace_integration_name: abc
10
+ app_marketplace_app_id: abc
11
+ app_marketplace_org_id: abc
12
+ incremental: true
13
+ retry_initial_wait_sec: 1
14
+ max_retry_wait_sec: 30
15
+ retry_limit: 2
16
+ columns:
17
+ - {name: id, type: long}
18
+ - {name: survey_id, type: string}
19
+ - {name: delivery_id, type: string}
20
+ - {name: recipient_id, type: string}
21
+ - {name: user_id, type: string}
22
+ - {name: rating, type: long}
23
+ - {name: comment, type: string}
24
+ - {name: delivered_at, type: timestamp, format: '%Y-%m-%dT%H:%M:%S%z'}
25
+ - {name: rated_at, type: timestamp, format: '%Y-%m-%dT%H:%M:%S%z'}
26
+ - {name: user_email, type: string}
27
+ - {name: user_name, type: string}
28
+ - {name: survey_name, type: string}
29
+ - {name: account, type: json}