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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +32 -2
- data/build.gradle +1 -1
- data/src/main/java/org/embulk/input/zendesk/RecordImporter.java +134 -0
- data/src/main/java/org/embulk/input/zendesk/ZendeskInputPlugin.java +182 -202
- data/src/main/java/org/embulk/input/zendesk/clients/ZendeskRestClient.java +54 -52
- data/src/main/java/org/embulk/input/zendesk/models/Target.java +3 -3
- data/src/main/java/org/embulk/input/zendesk/models/ZendeskException.java +1 -1
- data/src/main/java/org/embulk/input/zendesk/services/ZendeskCustomObjectService.java +110 -0
- data/src/main/java/org/embulk/input/zendesk/services/ZendeskNPSService.java +30 -0
- data/src/main/java/org/embulk/input/zendesk/services/ZendeskNormalServices.java +239 -0
- data/src/main/java/org/embulk/input/zendesk/services/ZendeskService.java +14 -0
- data/src/main/java/org/embulk/input/zendesk/services/ZendeskSupportAPIService.java +25 -83
- data/src/main/java/org/embulk/input/zendesk/services/ZendeskUserEventService.java +158 -0
- data/src/main/java/org/embulk/input/zendesk/stream/PagingSpliterator.java +40 -0
- data/src/main/java/org/embulk/input/zendesk/stream/paginator/sunshine/CustomObjectSpliterator.java +42 -0
- data/src/main/java/org/embulk/input/zendesk/stream/paginator/sunshine/SunshineSpliterator.java +66 -0
- data/src/main/java/org/embulk/input/zendesk/stream/paginator/sunshine/UserEventSpliterator.java +35 -0
- data/src/main/java/org/embulk/input/zendesk/stream/paginator/support/OrganizationSpliterator.java +13 -0
- data/src/main/java/org/embulk/input/zendesk/stream/paginator/support/SupportSpliterator.java +44 -0
- data/src/main/java/org/embulk/input/zendesk/stream/paginator/support/UserSpliterator.java +13 -0
- data/src/main/java/org/embulk/input/zendesk/utils/ZendeskConstants.java +13 -1
- data/src/main/java/org/embulk/input/zendesk/utils/ZendeskDateUtils.java +22 -11
- data/src/main/java/org/embulk/input/zendesk/utils/ZendeskUtils.java +52 -114
- data/src/test/java/org/embulk/input/zendesk/TestRecordImporter.java +114 -0
- data/src/test/java/org/embulk/input/zendesk/TestZendeskInputPlugin.java +184 -99
- data/src/test/java/org/embulk/input/zendesk/clients/TestZendeskRestClient.java +6 -20
- data/src/test/java/org/embulk/input/zendesk/services/TestZendeskCustomObjectService.java +161 -0
- data/src/test/java/org/embulk/input/zendesk/services/TestZendeskNPSService.java +56 -0
- data/src/test/java/org/embulk/input/zendesk/services/TestZendeskNormalService.java +189 -0
- data/src/test/java/org/embulk/input/zendesk/services/TestZendeskSupportAPIService.java +18 -60
- data/src/test/java/org/embulk/input/zendesk/services/TestZendeskUserEventService.java +158 -0
- data/src/test/java/org/embulk/input/zendesk/utils/TestZendeskDateUtils.java +50 -2
- data/src/test/java/org/embulk/input/zendesk/utils/TestZendeskUtil.java +0 -138
- data/src/test/java/org/embulk/input/zendesk/utils/ZendeskTestHelper.java +16 -0
- data/src/test/resources/config/nps.yml +29 -0
- data/src/test/resources/config/object_records.yml +24 -0
- data/src/test/resources/config/relationship_records.yml +23 -0
- data/src/test/resources/config/user_events.yml +29 -0
- data/src/test/resources/data/duplicate_user.json +0 -0
- data/src/test/resources/data/empty_result.json +7 -0
- data/src/test/resources/data/expected/user_events_column.json +40 -0
- data/src/test/resources/data/object_records.json +30 -0
- data/src/test/resources/data/organization.json +39 -0
- data/src/test/resources/data/relationship_records.json +57 -0
- data/src/test/resources/data/scores.json +21 -0
- data/src/test/resources/data/scores_share_same_time_with_next_page.json +35 -0
- data/src/test/resources/data/scores_share_same_time_without_next_page.json +35 -0
- data/src/test/resources/data/simple_organization.json +23 -0
- data/src/test/resources/data/simple_user.json +50 -0
- data/src/test/resources/data/simple_user_event.json +19 -0
- data/src/test/resources/data/ticket_events_share_same_time_with_next_page.json +279 -0
- data/src/test/resources/data/ticket_events_share_same_time_without_next_page.json +279 -0
- data/src/test/resources/data/ticket_events_updated_by_system_records.json +279 -0
- data/src/test/resources/data/ticket_share_same_time_with_next_page.json +232 -0
- data/src/test/resources/data/ticket_share_same_time_without_next_page.json +232 -0
- data/src/test/resources/data/ticket_with_updated_by_system_records.json +187 -0
- data/src/test/resources/data/user_event.json +19 -0
- data/src/test/resources/data/user_event_contain_latter_create_at.json +19 -0
- data/src/test/resources/data/user_event_multiple.json +33 -0
- metadata +46 -5
- data/src/main/java/org/embulk/input/zendesk/utils/ZendeskValidatorUtils.java +0 -79
- data/src/test/java/org/embulk/input/zendesk/utils/TestZendeskValidatorUtils.java +0 -130
@@ -0,0 +1,161 @@
|
|
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
|
+
|
7
|
+
import org.embulk.config.TaskReport;
|
8
|
+
import org.embulk.input.zendesk.RecordImporter;
|
9
|
+
import org.embulk.input.zendesk.ZendeskInputPlugin;
|
10
|
+
import org.embulk.input.zendesk.clients.ZendeskRestClient;
|
11
|
+
import org.embulk.input.zendesk.utils.ZendeskTestHelper;
|
12
|
+
import org.junit.Assert;
|
13
|
+
import org.junit.Before;
|
14
|
+
import org.junit.Rule;
|
15
|
+
import org.junit.Test;
|
16
|
+
import org.mockito.ArgumentCaptor;
|
17
|
+
|
18
|
+
import java.util.Arrays;
|
19
|
+
import java.util.List;
|
20
|
+
|
21
|
+
import static org.junit.Assert.assertEquals;
|
22
|
+
import static org.junit.Assert.assertFalse;
|
23
|
+
import static org.junit.Assert.assertTrue;
|
24
|
+
import static org.mockito.ArgumentMatchers.any;
|
25
|
+
import static org.mockito.ArgumentMatchers.anyBoolean;
|
26
|
+
import static org.mockito.Mockito.atMost;
|
27
|
+
import static org.mockito.Mockito.mock;
|
28
|
+
import static org.mockito.Mockito.spy;
|
29
|
+
import static org.mockito.Mockito.times;
|
30
|
+
import static org.mockito.Mockito.verify;
|
31
|
+
import static org.mockito.Mockito.when;
|
32
|
+
|
33
|
+
public class TestZendeskCustomObjectService
|
34
|
+
{
|
35
|
+
@Rule
|
36
|
+
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
37
|
+
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
|
38
|
+
|
39
|
+
private ZendeskRestClient zendeskRestClient;
|
40
|
+
|
41
|
+
private ZendeskCustomObjectService zendeskCustomObjectService;
|
42
|
+
|
43
|
+
private RecordImporter recordImporter;
|
44
|
+
|
45
|
+
@Before
|
46
|
+
public void prepare()
|
47
|
+
{
|
48
|
+
zendeskRestClient = mock(ZendeskRestClient.class);
|
49
|
+
recordImporter = mock(RecordImporter.class);
|
50
|
+
}
|
51
|
+
|
52
|
+
@Test
|
53
|
+
public void testGetListPathForObjectRecord()
|
54
|
+
{
|
55
|
+
setup("object_records.yml");
|
56
|
+
List<String> expectedStrings = Arrays.asList(
|
57
|
+
"https://abc.zendesk.com/api/sunshine/objects/records?type=account&per_page=1000",
|
58
|
+
"https://abc.zendesk.com/api/sunshine/objects/records?type=user&per_page=1000"
|
59
|
+
);
|
60
|
+
|
61
|
+
zendeskCustomObjectService.addRecordToImporter(0, recordImporter);
|
62
|
+
final ArgumentCaptor<String> actualString = ArgumentCaptor.forClass(String.class);
|
63
|
+
verify(zendeskRestClient, times(2)).doGet(actualString.capture(), any(), anyBoolean());
|
64
|
+
assertTrue(actualString.getAllValues().contains(expectedStrings.get(0)));
|
65
|
+
assertTrue(actualString.getAllValues().contains(expectedStrings.get(1)));
|
66
|
+
}
|
67
|
+
|
68
|
+
@Test
|
69
|
+
public void testGetListPathForRelationshipRecord()
|
70
|
+
{
|
71
|
+
setup("relationship_records.yml");
|
72
|
+
String expectedStrings = "https://abc.zendesk.com/api/sunshine/relationships/records?type=ticket_to_account&per_page=1000";
|
73
|
+
zendeskCustomObjectService.addRecordToImporter(0, recordImporter);
|
74
|
+
final ArgumentCaptor<String> actualString = ArgumentCaptor.forClass(String.class);
|
75
|
+
verify(zendeskRestClient).doGet(actualString.capture(), any(), anyBoolean());
|
76
|
+
assertEquals(expectedStrings, actualString.getValue());
|
77
|
+
}
|
78
|
+
|
79
|
+
@Test
|
80
|
+
public void testAddRecordToImporterObjectRecord()
|
81
|
+
{
|
82
|
+
ZendeskTestHelper.setPreviewMode(runtime, false);
|
83
|
+
setup("object_records.yml");
|
84
|
+
loadData("data/object_records.json");
|
85
|
+
zendeskCustomObjectService.addRecordToImporter(0, recordImporter);
|
86
|
+
// 2 types - each type 2 records
|
87
|
+
verify(recordImporter, times(4)).addRecord(any());
|
88
|
+
}
|
89
|
+
|
90
|
+
@Test
|
91
|
+
public void testAddRecordToImporterRelationShipRecord()
|
92
|
+
{
|
93
|
+
ZendeskTestHelper.setPreviewMode(runtime, false);
|
94
|
+
setup("relationship_records.yml");
|
95
|
+
loadData("data/relationship_records.json");
|
96
|
+
zendeskCustomObjectService.addRecordToImporter(0, recordImporter);
|
97
|
+
// 7 records
|
98
|
+
verify(recordImporter, times(7)).addRecord(any());
|
99
|
+
}
|
100
|
+
|
101
|
+
@Test
|
102
|
+
public void testGetData()
|
103
|
+
{
|
104
|
+
setup("object_records.yml");
|
105
|
+
loadData("data/object_records.json");
|
106
|
+
JsonNode jsonNode = zendeskCustomObjectService.getDataFromPath("https://abc.zendesk.com/api/sunshine/objects/records?type=user&per_page=1000", 0, true, 0);
|
107
|
+
assertFalse(jsonNode.isNull());
|
108
|
+
assertTrue(jsonNode.has("data"));
|
109
|
+
assertTrue(jsonNode.get("data").isArray());
|
110
|
+
|
111
|
+
setup("relationship_records.yml");
|
112
|
+
loadData("data/relationship_records.json");
|
113
|
+
jsonNode = zendeskCustomObjectService.getDataFromPath("https://abc.zendesk.com/api/sunshine/relationships/records?type=user&per_page=1000", 0, true, 0);
|
114
|
+
assertFalse(jsonNode.isNull());
|
115
|
+
assertTrue(jsonNode.has("data"));
|
116
|
+
assertTrue(jsonNode.get("data").isArray());
|
117
|
+
}
|
118
|
+
|
119
|
+
@Test
|
120
|
+
public void testAddRecordToImporterInPreviewObjectRecord()
|
121
|
+
{
|
122
|
+
ZendeskTestHelper.setPreviewMode(runtime, true);
|
123
|
+
setup("object_records.yml");
|
124
|
+
loadData("data/object_records.json");
|
125
|
+
TaskReport taskReport = zendeskCustomObjectService.addRecordToImporter(0, recordImporter);
|
126
|
+
|
127
|
+
// expect to be break and don't import all records
|
128
|
+
verify(recordImporter, atMost(3)).addRecord(any());
|
129
|
+
Assert.assertTrue(taskReport.isEmpty());
|
130
|
+
}
|
131
|
+
|
132
|
+
@Test
|
133
|
+
public void testAddRecordToImporterInPreviewRelationshipRecord()
|
134
|
+
{
|
135
|
+
ZendeskTestHelper.setPreviewMode(runtime, true);
|
136
|
+
setup("relationship_records.yml");
|
137
|
+
loadData("data/relationship_records.json");
|
138
|
+
TaskReport taskReport = zendeskCustomObjectService.addRecordToImporter(0, recordImporter);
|
139
|
+
// 1 type contain data and break
|
140
|
+
verify(recordImporter, times(1)).addRecord(any());
|
141
|
+
Assert.assertTrue(taskReport.isEmpty());
|
142
|
+
}
|
143
|
+
|
144
|
+
private void loadData(String fileName)
|
145
|
+
{
|
146
|
+
JsonNode dataJson = ZendeskTestHelper.getJsonFromFile(fileName);
|
147
|
+
when(zendeskRestClient.doGet(any(), any(), anyBoolean())).thenReturn(dataJson.toString());
|
148
|
+
}
|
149
|
+
|
150
|
+
private void setupZendeskSupportAPIService(ZendeskInputPlugin.PluginTask task)
|
151
|
+
{
|
152
|
+
zendeskCustomObjectService = spy(new ZendeskCustomObjectService(task));
|
153
|
+
when(zendeskCustomObjectService.getZendeskRestClient()).thenReturn(zendeskRestClient);
|
154
|
+
}
|
155
|
+
|
156
|
+
private void setup(String file)
|
157
|
+
{
|
158
|
+
ZendeskInputPlugin.PluginTask task = ZendeskTestHelper.getConfigSource(file).loadConfig(ZendeskInputPlugin.PluginTask.class);
|
159
|
+
setupZendeskSupportAPIService(task);
|
160
|
+
}
|
161
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
package org.embulk.input.zendesk.services;
|
2
|
+
|
3
|
+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
4
|
+
import org.embulk.EmbulkTestRuntime;
|
5
|
+
import org.embulk.input.zendesk.ZendeskInputPlugin;
|
6
|
+
import org.embulk.input.zendesk.clients.ZendeskRestClient;
|
7
|
+
import org.embulk.input.zendesk.utils.ZendeskTestHelper;
|
8
|
+
import org.junit.Before;
|
9
|
+
import org.junit.Rule;
|
10
|
+
import org.junit.Test;
|
11
|
+
|
12
|
+
import static org.junit.Assert.assertEquals;
|
13
|
+
import static org.mockito.Mockito.mock;
|
14
|
+
import static org.mockito.Mockito.spy;
|
15
|
+
|
16
|
+
import static org.mockito.Mockito.when;
|
17
|
+
|
18
|
+
public class TestZendeskNPSService
|
19
|
+
{
|
20
|
+
@Rule
|
21
|
+
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
22
|
+
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
|
23
|
+
|
24
|
+
private ZendeskRestClient zendeskRestClient;
|
25
|
+
|
26
|
+
private ZendeskNPSService zendeskNPSService;
|
27
|
+
|
28
|
+
@Before
|
29
|
+
public void prepare()
|
30
|
+
{
|
31
|
+
zendeskRestClient = mock(ZendeskRestClient.class);
|
32
|
+
}
|
33
|
+
|
34
|
+
@Test
|
35
|
+
public void testBuildURL()
|
36
|
+
{
|
37
|
+
setup();
|
38
|
+
String expectedString = "https://abc.zendesk.com/api/v2/nps/incremental/responses.json?start_time=10000";
|
39
|
+
// only use start_time so page any value
|
40
|
+
String actualString = zendeskNPSService.buildURI(0, 10000);
|
41
|
+
assertEquals(expectedString, actualString);
|
42
|
+
}
|
43
|
+
|
44
|
+
private void setupZendeskNPSService(ZendeskInputPlugin.PluginTask task)
|
45
|
+
{
|
46
|
+
zendeskNPSService = spy(new ZendeskNPSService(task));
|
47
|
+
when(zendeskNPSService.getZendeskRestClient()).thenReturn(zendeskRestClient);
|
48
|
+
}
|
49
|
+
|
50
|
+
private void setup()
|
51
|
+
{
|
52
|
+
ZendeskInputPlugin.PluginTask task = ZendeskTestHelper.getConfigSource("nps.yml")
|
53
|
+
.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
54
|
+
setupZendeskNPSService(task);
|
55
|
+
}
|
56
|
+
}
|
@@ -0,0 +1,189 @@
|
|
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.config.TaskReport;
|
8
|
+
import org.embulk.input.zendesk.RecordImporter;
|
9
|
+
import org.embulk.input.zendesk.ZendeskInputPlugin;
|
10
|
+
import org.embulk.input.zendesk.clients.ZendeskRestClient;
|
11
|
+
import org.embulk.input.zendesk.models.Target;
|
12
|
+
import org.embulk.input.zendesk.utils.ZendeskConstants;
|
13
|
+
import org.embulk.input.zendesk.utils.ZendeskTestHelper;
|
14
|
+
import org.junit.Assert;
|
15
|
+
import org.junit.Before;
|
16
|
+
import org.junit.Rule;
|
17
|
+
import org.junit.Test;
|
18
|
+
import org.mockito.ArgumentCaptor;
|
19
|
+
|
20
|
+
import java.time.Instant;
|
21
|
+
|
22
|
+
import static org.junit.Assert.assertEquals;
|
23
|
+
import static org.mockito.ArgumentMatchers.any;
|
24
|
+
import static org.mockito.ArgumentMatchers.anyBoolean;
|
25
|
+
import static org.mockito.Mockito.mock;
|
26
|
+
import static org.mockito.Mockito.spy;
|
27
|
+
import static org.mockito.Mockito.times;
|
28
|
+
import static org.mockito.Mockito.verify;
|
29
|
+
import static org.mockito.Mockito.when;
|
30
|
+
|
31
|
+
public class TestZendeskNormalService
|
32
|
+
{
|
33
|
+
@Rule
|
34
|
+
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
35
|
+
public EmbulkTestRuntime runtime = new EmbulkTestRuntime();
|
36
|
+
|
37
|
+
private ZendeskRestClient zendeskRestClient;
|
38
|
+
|
39
|
+
private ZendeskSupportAPIService zendeskSupportAPIService;
|
40
|
+
|
41
|
+
private RecordImporter recordImporter;
|
42
|
+
|
43
|
+
@Before
|
44
|
+
public void prepare()
|
45
|
+
{
|
46
|
+
zendeskRestClient = mock(ZendeskRestClient.class);
|
47
|
+
recordImporter = mock(RecordImporter.class);
|
48
|
+
}
|
49
|
+
|
50
|
+
@Test
|
51
|
+
public void testAddRecordToImporterWithIncremental()
|
52
|
+
{
|
53
|
+
setupSupportAPIService("incremental.yml");
|
54
|
+
loadData("data/tickets.json");
|
55
|
+
|
56
|
+
TaskReport taskReport = zendeskSupportAPIService.addRecordToImporter(0, recordImporter);
|
57
|
+
verify(recordImporter, times(4)).addRecord(any());
|
58
|
+
Assert.assertFalse(taskReport.isEmpty());
|
59
|
+
Assert.assertEquals(1550647054, taskReport.get(JsonNode.class, ZendeskConstants.Field.START_TIME).asLong());
|
60
|
+
}
|
61
|
+
|
62
|
+
@Test
|
63
|
+
public void testAddRecordToImporterWithIncrementalAndWithoutDedup()
|
64
|
+
{
|
65
|
+
ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
|
66
|
+
src.set("dedup", false);
|
67
|
+
ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
68
|
+
setupZendeskSupportAPIService(task);
|
69
|
+
loadData("data/tickets.json");
|
70
|
+
|
71
|
+
TaskReport taskReport = zendeskSupportAPIService.addRecordToImporter(0, recordImporter);
|
72
|
+
verify(recordImporter, times(5)).addRecord(any());
|
73
|
+
Assert.assertFalse(taskReport.isEmpty());
|
74
|
+
Assert.assertEquals(1550647054, taskReport.get(JsonNode.class, ZendeskConstants.Field.START_TIME).asLong());
|
75
|
+
}
|
76
|
+
|
77
|
+
@Test
|
78
|
+
public void testAddRecordToImporterIncrementalContainUpdatedBySystemRecords()
|
79
|
+
{
|
80
|
+
setupSupportAPIService("incremental.yml");
|
81
|
+
loadData("data/ticket_with_updated_by_system_records.json");
|
82
|
+
|
83
|
+
TaskReport taskReport = zendeskSupportAPIService.addRecordToImporter(0, recordImporter);
|
84
|
+
verify(recordImporter, times(3)).addRecord(any());
|
85
|
+
Assert.assertFalse(taskReport.isEmpty());
|
86
|
+
Assert.assertEquals(1550647054, taskReport.get(JsonNode.class, ZendeskConstants.Field.START_TIME).asLong());
|
87
|
+
}
|
88
|
+
|
89
|
+
@Test
|
90
|
+
public void testAddRecordToImporterIncrementalUpdateStartTimeWhenEmptyResult()
|
91
|
+
{
|
92
|
+
ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
|
93
|
+
src.set("target", Target.TICKETS.toString());
|
94
|
+
|
95
|
+
src.set("start_time", "2219-02-20T06:52:00Z");
|
96
|
+
ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
97
|
+
setupZendeskSupportAPIService(task);
|
98
|
+
loadData("data/empty_result.json");
|
99
|
+
|
100
|
+
TaskReport taskReport = zendeskSupportAPIService.addRecordToImporter(0, recordImporter);
|
101
|
+
Assert.assertFalse(taskReport.isEmpty());
|
102
|
+
Assert.assertTrue(Instant.now().getEpochSecond() <= taskReport.get(JsonNode.class, ZendeskConstants.Field.START_TIME).asLong() + 50);
|
103
|
+
}
|
104
|
+
|
105
|
+
@Test
|
106
|
+
public void testAddRecordToImporterNonIncremental()
|
107
|
+
{
|
108
|
+
setupSupportAPIService("non-incremental.yml");
|
109
|
+
loadData("data/ticket_fields.json");
|
110
|
+
|
111
|
+
TaskReport taskReport = zendeskSupportAPIService.addRecordToImporter(0, recordImporter);
|
112
|
+
verify(recordImporter, times(7)).addRecord(any());
|
113
|
+
Assert.assertTrue(taskReport.isEmpty());
|
114
|
+
}
|
115
|
+
|
116
|
+
@Test
|
117
|
+
public void testAddRecordToImporterIncrementalForSupportAndAllRecordsShareTheSameTime()
|
118
|
+
{
|
119
|
+
setupSupportAPIService("incremental.yml");
|
120
|
+
loadData("data/ticket_share_same_time_without_next_page.json");
|
121
|
+
|
122
|
+
TaskReport taskReport = zendeskSupportAPIService.addRecordToImporter(0, recordImporter);
|
123
|
+
verify(recordImporter, times(4)).addRecord(any());
|
124
|
+
// api_end_time of ticket_share_same_time_without_next_page.json + 1
|
125
|
+
Assert.assertEquals(1551419520, taskReport.get(JsonNode.class, ZendeskConstants.Field.START_TIME).asLong());
|
126
|
+
}
|
127
|
+
|
128
|
+
@Test
|
129
|
+
public void testTicketEventsAddRecordToImporterIncrementalWithNextPageAndAllRecordsShareTheSameTime()
|
130
|
+
{
|
131
|
+
// api_end_time of ticket_events_share_same_time_with_next_page.json
|
132
|
+
String expectedURL = "https://abc.zendesk.com/api/v2/incremental/ticket_events.json?start_time=1550645443";
|
133
|
+
setupSupportAPIService("incremental.yml");
|
134
|
+
ZendeskInputPlugin.PluginTask task = ZendeskTestHelper.getConfigSource("incremental.yml")
|
135
|
+
.set("target", "ticket_events")
|
136
|
+
.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
137
|
+
setupZendeskSupportAPIService(task);
|
138
|
+
|
139
|
+
JsonNode dataJson = ZendeskTestHelper.getJsonFromFile("data/ticket_events_share_same_time_with_next_page.json");
|
140
|
+
JsonNode dataJsonNext = ZendeskTestHelper.getJsonFromFile("data/ticket_events_updated_by_system_records.json");
|
141
|
+
when(zendeskRestClient.doGet(any(), any(), anyBoolean()))
|
142
|
+
.thenReturn(dataJson.toString())
|
143
|
+
.thenReturn(dataJsonNext.toString());
|
144
|
+
|
145
|
+
TaskReport taskReport = zendeskSupportAPIService.addRecordToImporter(0, recordImporter);
|
146
|
+
final ArgumentCaptor<String> url = ArgumentCaptor.forClass(String.class);
|
147
|
+
verify(zendeskRestClient, times(2)).doGet(url.capture(), any(), anyBoolean());
|
148
|
+
assertEquals(expectedURL, url.getValue());
|
149
|
+
|
150
|
+
verify(recordImporter, times(4)).addRecord(any());
|
151
|
+
// api_end_time of ticket_events_updated_by_system_records.json + 1
|
152
|
+
Assert.assertEquals(1550645523, taskReport.get(JsonNode.class, ZendeskConstants.Field.START_TIME).asLong());
|
153
|
+
}
|
154
|
+
|
155
|
+
@Test
|
156
|
+
public void testTicketEventsAddRecordToImporterIncrementaAndAllRecordsShareTheSameTime()
|
157
|
+
{
|
158
|
+
setupSupportAPIService("incremental.yml");
|
159
|
+
ZendeskInputPlugin.PluginTask task = ZendeskTestHelper.getConfigSource("incremental.yml")
|
160
|
+
.set("target", "ticket_events")
|
161
|
+
.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
162
|
+
setupZendeskSupportAPIService(task);
|
163
|
+
loadData("data/ticket_events_share_same_time_without_next_page.json");
|
164
|
+
|
165
|
+
TaskReport taskReport = zendeskSupportAPIService.addRecordToImporter(0, recordImporter);
|
166
|
+
verify(recordImporter, times(4)).addRecord(any());
|
167
|
+
// api_end_time of ticket_events_share_same_time_without_next_page.json + 1
|
168
|
+
Assert.assertEquals(1550645444, taskReport.get(JsonNode.class, ZendeskConstants.Field.START_TIME).asLong());
|
169
|
+
}
|
170
|
+
|
171
|
+
private void setupSupportAPIService(String file)
|
172
|
+
{
|
173
|
+
ZendeskInputPlugin.PluginTask task = ZendeskTestHelper.getConfigSource(file)
|
174
|
+
.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
175
|
+
setupZendeskSupportAPIService(task);
|
176
|
+
}
|
177
|
+
|
178
|
+
private void loadData(String fileName)
|
179
|
+
{
|
180
|
+
JsonNode dataJson = ZendeskTestHelper.getJsonFromFile(fileName);
|
181
|
+
when(zendeskRestClient.doGet(any(), any(), anyBoolean())).thenReturn(dataJson.toString());
|
182
|
+
}
|
183
|
+
|
184
|
+
private void setupZendeskSupportAPIService(ZendeskInputPlugin.PluginTask task)
|
185
|
+
{
|
186
|
+
zendeskSupportAPIService = spy(new ZendeskSupportAPIService(task));
|
187
|
+
when(zendeskSupportAPIService.getZendeskRestClient()).thenReturn(zendeskRestClient);
|
188
|
+
}
|
189
|
+
}
|
@@ -10,14 +10,12 @@ import org.embulk.input.zendesk.utils.ZendeskTestHelper;
|
|
10
10
|
import org.junit.Before;
|
11
11
|
import org.junit.Rule;
|
12
12
|
import org.junit.Test;
|
13
|
-
import org.mockito.ArgumentCaptor;
|
14
13
|
|
15
14
|
import static org.junit.Assert.assertEquals;
|
16
15
|
import static org.mockito.ArgumentMatchers.any;
|
17
16
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
18
17
|
import static org.mockito.Mockito.mock;
|
19
18
|
import static org.mockito.Mockito.spy;
|
20
|
-
import static org.mockito.Mockito.verify;
|
21
19
|
import static org.mockito.Mockito.when;
|
22
20
|
|
23
21
|
import java.util.Collections;
|
@@ -39,25 +37,17 @@ public class TestZendeskSupportAPIService
|
|
39
37
|
}
|
40
38
|
|
41
39
|
@Test
|
42
|
-
public void
|
40
|
+
public void testBuildPathWithIncremental()
|
43
41
|
{
|
44
42
|
String expectURL = "https://abc.zendesk.com/api/v2/incremental/tickets.json?start_time=0";
|
45
43
|
setup("incremental.yml");
|
46
44
|
loadData("data/tickets.json");
|
47
|
-
|
45
|
+
String url = zendeskSupportAPIService.buildURI(0, 0);
|
46
|
+
assertEquals(expectURL, url);
|
48
47
|
}
|
49
48
|
|
50
49
|
@Test
|
51
|
-
public void
|
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()
|
50
|
+
public void testBuildPathWithIncrementalWithTicketMetrics()
|
61
51
|
{
|
62
52
|
String expectURL = "https://abc.zendesk.com/api/v2/incremental/tickets.json?start_time=0&include=metric_sets";
|
63
53
|
loadData("data/ticket_metrics.json");
|
@@ -67,34 +57,12 @@ public class TestZendeskSupportAPIService
|
|
67
57
|
ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
68
58
|
setupZendeskSupportAPIService(task);
|
69
59
|
|
70
|
-
|
60
|
+
String url = zendeskSupportAPIService.buildURI(0, 0);
|
61
|
+
assertEquals(expectURL, url);
|
71
62
|
}
|
72
63
|
|
73
64
|
@Test
|
74
|
-
public void
|
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()
|
65
|
+
public void testBuildPathWithIncrementalIncludeRelatedObject()
|
98
66
|
{
|
99
67
|
String expectURL = "https://abc.zendesk.com/api/v2/incremental/tickets.json?start_time=0";
|
100
68
|
loadData("data/tickets.json");
|
@@ -104,43 +72,41 @@ public class TestZendeskSupportAPIService
|
|
104
72
|
ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
105
73
|
setupZendeskSupportAPIService(task);
|
106
74
|
|
107
|
-
|
75
|
+
String url = zendeskSupportAPIService.buildURI(0, 0);
|
76
|
+
assertEquals(expectURL, url);
|
108
77
|
}
|
109
78
|
|
110
79
|
@Test
|
111
|
-
public void
|
80
|
+
public void testBuildPathWithIncrementalTimeChange()
|
112
81
|
{
|
113
|
-
long time = 100;
|
114
82
|
String expectURL = "https://abc.zendesk.com/api/v2/incremental/tickets.json?start_time=100";
|
115
83
|
loadData("data/tickets.json");
|
116
84
|
|
117
85
|
ConfigSource src = ZendeskTestHelper.getConfigSource("incremental.yml");
|
118
86
|
ZendeskInputPlugin.PluginTask task = src.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
119
87
|
setupZendeskSupportAPIService(task);
|
120
|
-
|
121
|
-
|
122
|
-
final ArgumentCaptor<String> url = ArgumentCaptor.forClass(String.class);
|
123
|
-
verify(zendeskRestClient).doGet(url.capture(), any(), anyBoolean());
|
124
|
-
assertEquals(expectURL, url.getValue());
|
88
|
+
String url = zendeskSupportAPIService.buildURI(0, 100);
|
89
|
+
assertEquals(expectURL, url);
|
125
90
|
}
|
126
91
|
|
127
92
|
@Test
|
128
|
-
public void
|
93
|
+
public void testBuildPathWithNonIncremental()
|
129
94
|
{
|
130
95
|
String expectURL = "https://abc.zendesk.com/api/v2/ticket_fields.json?sort_by=id&per_page=100&page=0";
|
131
96
|
setup("non-incremental.yml");
|
132
97
|
loadData("data/ticket_fields.json");
|
133
|
-
|
134
|
-
|
98
|
+
String url = zendeskSupportAPIService.buildURI(0, 0);
|
99
|
+
assertEquals(expectURL, url);
|
135
100
|
}
|
136
101
|
|
137
102
|
@Test
|
138
|
-
public void
|
103
|
+
public void testBuildPathWithNonIncrementalChangePageNumber()
|
139
104
|
{
|
140
105
|
String expectURL = "https://abc.zendesk.com/api/v2/ticket_fields.json?sort_by=id&per_page=100&page=2";
|
141
106
|
setup("non-incremental.yml");
|
142
107
|
loadData("data/ticket_fields.json");
|
143
|
-
|
108
|
+
String url = zendeskSupportAPIService.buildURI(2, 0);
|
109
|
+
assertEquals(expectURL, url);
|
144
110
|
}
|
145
111
|
|
146
112
|
private void loadData(String fileName)
|
@@ -161,12 +127,4 @@ public class TestZendeskSupportAPIService
|
|
161
127
|
.loadConfig(ZendeskInputPlugin.PluginTask.class);
|
162
128
|
setupZendeskSupportAPIService(task);
|
163
129
|
}
|
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
130
|
}
|