embulk-input-marketo 0.5.7.alpha.6 → 0.6.0.alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/build.gradle +6 -6
  3. data/src/main/java/org/embulk/input/marketo/MarketoService.java +1 -1
  4. data/src/main/java/org/embulk/input/marketo/MarketoServiceImpl.java +4 -5
  5. data/src/main/java/org/embulk/input/marketo/MarketoUtils.java +45 -14
  6. data/src/main/java/org/embulk/input/marketo/delegate/ActivityBulkExtractInputPlugin.java +12 -11
  7. data/src/main/java/org/embulk/input/marketo/delegate/CampaignInputPlugin.java +4 -23
  8. data/src/main/java/org/embulk/input/marketo/delegate/LeadBulkExtractInputPlugin.java +18 -11
  9. data/src/main/java/org/embulk/input/marketo/delegate/LeadWithListInputPlugin.java +3 -18
  10. data/src/main/java/org/embulk/input/marketo/delegate/LeadWithProgramInputPlugin.java +5 -20
  11. data/src/main/java/org/embulk/input/marketo/delegate/MarketoBaseBulkExtractInputPlugin.java +213 -87
  12. data/src/main/java/org/embulk/input/marketo/delegate/MarketoBaseInputPluginDelegate.java +22 -0
  13. data/src/main/java/org/embulk/input/marketo/model/MarketoBulkExtractRequest.java +12 -1
  14. data/src/main/java/org/embulk/input/marketo/model/MarketoField.java +28 -2
  15. data/src/main/java/org/embulk/input/marketo/model/MarketoResponse.java +2 -1
  16. data/src/main/java/org/embulk/input/marketo/model/filter/DateRangeFilter.java +9 -0
  17. data/src/main/java/org/embulk/input/marketo/rest/MarketoBaseRestClient.java +4 -0
  18. data/src/main/java/org/embulk/input/marketo/rest/{MarketoFileResponseEntityReader.java → MarketoInputStreamResponseEntityReader.java} +2 -2
  19. data/src/main/java/org/embulk/input/marketo/rest/MarketoResponseJetty92EntityReader.java +4 -1
  20. data/src/main/java/org/embulk/input/marketo/rest/MarketoRestClient.java +76 -42
  21. data/src/main/java/org/embulk/input/marketo/rest/RecordPagingIterable.java +35 -11
  22. data/src/test/java/org/embulk/input/marketo/MarketoServiceImplTest.java +159 -0
  23. data/src/test/java/org/embulk/input/marketo/MarketoUtilsTest.java +87 -0
  24. data/src/test/java/org/embulk/input/marketo/delegate/ActivityBulkExtractInputPluginTest.java +84 -0
  25. data/src/test/java/org/embulk/input/marketo/delegate/CampaignInputPluginTest.java +73 -0
  26. data/src/test/java/org/embulk/input/marketo/delegate/LeadBulkExtractInputPluginTest.java +94 -0
  27. data/src/test/java/org/embulk/input/marketo/delegate/LeadWithListInputPluginTest.java +99 -0
  28. data/src/test/java/org/embulk/input/marketo/delegate/LeadWithProgramInputPluginTest.java +101 -0
  29. data/src/test/java/org/embulk/input/marketo/delegate/MarketoBaseBulkExtractInputPluginTest.java +114 -0
  30. data/src/test/java/org/embulk/input/marketo/rest/MarketoBaseRestClientTest.java +3 -15
  31. data/src/test/java/org/embulk/input/marketo/rest/MarketoRestClientTest.java +450 -0
  32. data/src/test/resources/config/activity_bulk_extract_config.yaml +7 -0
  33. data/src/test/resources/config/lead_bulk_extract_config.yaml +8 -0
  34. data/src/test/resources/config/rest_config.yaml +3 -0
  35. data/src/test/resources/fixtures/activity_extract1.csv +35 -0
  36. data/src/test/resources/fixtures/activity_extract2.csv +22 -0
  37. data/src/test/resources/fixtures/all_program_full.json +53 -0
  38. data/src/test/resources/fixtures/campaign_response.json +38 -0
  39. data/src/test/resources/fixtures/campaign_response_full.json +102 -0
  40. data/src/test/resources/fixtures/lead_by_list.json +33 -0
  41. data/src/test/resources/fixtures/lead_by_program_response.json +47 -0
  42. data/src/test/resources/fixtures/lead_describe.json +221 -0
  43. data/src/test/resources/fixtures/lead_describe_expected.json +66 -0
  44. data/src/test/resources/fixtures/lead_describe_marketo_fields_full.json +518 -0
  45. data/src/test/resources/fixtures/lead_extract1.csv +11 -0
  46. data/src/test/resources/fixtures/lead_response_full.json +2402 -0
  47. data/src/test/resources/fixtures/lead_with_program_full.json +17 -0
  48. data/src/test/resources/fixtures/leads_extract2.csv +10 -0
  49. data/src/test/resources/fixtures/lists_response.json +31 -0
  50. data/src/test/resources/fixtures/program_response.json +71 -0
  51. metadata +39 -8
  52. data/src/main/java/org/embulk/input/marketo/model/filter/ListFilter.java +0 -10
@@ -0,0 +1,94 @@
1
+ package org.embulk.input.marketo.delegate;
2
+
3
+ import com.fasterxml.jackson.databind.JavaType;
4
+ import com.fasterxml.jackson.databind.ObjectMapper;
5
+ import org.embulk.EmbulkTestRuntime;
6
+ import org.embulk.base.restclient.ServiceResponseMapper;
7
+ import org.embulk.base.restclient.record.ValueLocator;
8
+ import org.embulk.config.ConfigLoader;
9
+ import org.embulk.config.ConfigSource;
10
+ import org.embulk.config.TaskReport;
11
+ import org.embulk.input.marketo.MarketoUtils;
12
+ import org.embulk.input.marketo.model.MarketoField;
13
+ import org.embulk.input.marketo.rest.MarketoRestClient;
14
+ import org.embulk.spi.Column;
15
+ import org.embulk.spi.PageBuilder;
16
+ import org.joda.time.DateTime;
17
+ import org.junit.Before;
18
+ import org.junit.Rule;
19
+ import org.junit.Test;
20
+ import org.mockito.ArgumentCaptor;
21
+
22
+ import java.io.IOException;
23
+ import java.util.Date;
24
+ import java.util.List;
25
+ import java.util.Set;
26
+
27
+ import static org.junit.Assert.*;
28
+ import static org.mockito.ArgumentMatchers.any;
29
+ import static org.mockito.ArgumentMatchers.eq;
30
+ import static org.mockito.Mockito.*;
31
+
32
+ /**
33
+ * Created by khuutantaitai on 10/3/17.
34
+ */
35
+ public class LeadBulkExtractInputPluginTest
36
+ {
37
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
38
+
39
+ @Rule
40
+ public EmbulkTestRuntime embulkTestRuntime = new EmbulkTestRuntime();
41
+
42
+ private LeadBulkExtractInputPlugin bulkExtractInputPlugin;
43
+
44
+ private ConfigSource configSource;
45
+
46
+ private MarketoRestClient mockMarketoRestclient;
47
+
48
+ @Before
49
+ public void prepare() throws IOException
50
+ {
51
+ bulkExtractInputPlugin = spy(new LeadBulkExtractInputPlugin());
52
+ ConfigLoader configLoader = embulkTestRuntime.getInjector().getInstance(ConfigLoader.class);
53
+ configSource = configLoader.fromYaml(this.getClass().getResourceAsStream("/config/lead_bulk_extract_config.yaml"));
54
+ mockMarketoRestclient = mock(MarketoRestClient.class);
55
+ doReturn(mockMarketoRestclient).when(bulkExtractInputPlugin).createMarketoRestClient(any(LeadBulkExtractInputPlugin.PluginTask.class));
56
+ }
57
+
58
+ @Test
59
+ public void testRun() throws InterruptedException, IOException
60
+ {
61
+ LeadBulkExtractInputPlugin.PluginTask task = configSource.loadConfig(LeadBulkExtractInputPlugin.PluginTask.class);
62
+ DateTime startDate = new DateTime(task.getFromDate());
63
+ PageBuilder pageBuilder = mock(PageBuilder.class);
64
+ String exportId1 = "exportId1";
65
+ String exportId2 = "exportId2";
66
+ JavaType javaType = OBJECT_MAPPER.getTypeFactory().constructParametrizedType(List.class, List.class, MarketoField.class);
67
+ List<MarketoField> marketoFields = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/fixtures/lead_describe_marketo_fields_full.json"), javaType);
68
+ List<String> fieldNameFromMarketoFields = MarketoUtils.getFieldNameFromMarketoFields(marketoFields);
69
+ when(mockMarketoRestclient.describeLead()).thenReturn(marketoFields);
70
+ when(mockMarketoRestclient.createLeadBulkExtract(any(Date.class), any(Date.class), any(List.class), any(String.class))).thenReturn(exportId1).thenReturn(exportId2).thenReturn(null);
71
+ when(mockMarketoRestclient.getLeadBulkExtractResult(eq(exportId1))).thenReturn(this.getClass().getResourceAsStream("/fixtures/lead_extract1.csv"));
72
+ when(mockMarketoRestclient.getLeadBulkExtractResult(eq(exportId2))).thenReturn(this.getClass().getResourceAsStream("/fixtures/leads_extract2.csv"));
73
+ ServiceResponseMapper<? extends ValueLocator> mapper = bulkExtractInputPlugin.buildServiceResponseMapper(task);
74
+ bulkExtractInputPlugin.validateInputTask(task);
75
+ TaskReport taskReport = bulkExtractInputPlugin.ingestServiceData(task, mapper.createRecordImporter(), 1, pageBuilder);
76
+ ArgumentCaptor<Long> argumentCaptor = ArgumentCaptor.forClass(Long.class);
77
+ Column idColumn = mapper.getEmbulkSchema().lookupColumn("mk_id");
78
+ verify(pageBuilder, times(19)).setLong(eq(idColumn), argumentCaptor.capture());
79
+ verify(mockMarketoRestclient, times(1)).startLeadBulkExtract(eq(exportId1));
80
+ verify(mockMarketoRestclient, times(1)).waitLeadExportJobComplete(eq(exportId1), eq(task.getPollingIntervalSecond()), eq(task.getBulkJobTimeoutSecond()));
81
+ verify(mockMarketoRestclient, times(1)).startLeadBulkExtract(eq(exportId2));
82
+ verify(mockMarketoRestclient, times(1)).waitLeadExportJobComplete(eq(exportId2), eq(task.getPollingIntervalSecond()), eq(task.getBulkJobTimeoutSecond()));
83
+ String filterField = "updatedAt";
84
+ verify(mockMarketoRestclient, times(1)).createLeadBulkExtract(startDate.toDate(), startDate.plusDays(30).toDate(), fieldNameFromMarketoFields, filterField);
85
+ DateTime startDate2 = startDate.plusDays(30).plusSeconds(1);
86
+ verify(mockMarketoRestclient, times(1)).createLeadBulkExtract(startDate2.toDate(), startDate.plusDays(task.getFetchDays()).toDate(), fieldNameFromMarketoFields, filterField);
87
+ List<Long> leadIds = argumentCaptor.getAllValues();
88
+ assertEquals(19, leadIds.size());
89
+ long latestFetchTime = taskReport.get(Long.class, "latest_fetch_time");
90
+ assertTrue(taskReport.get(Set.class, "latest_uids").isEmpty());
91
+ assertEquals(1504888753000L, latestFetchTime);
92
+ assertArrayEquals(new Long[]{102488L, 102456L, 102445L, 102439L, 102471L, 102503L, 102424L, 102473L, 102505L, 102492L, 102495L, 102452L, 102435L, 102467L, 102420L, 102496L, 102448L, 102499L, 102431L}, leadIds.toArray());
93
+ }
94
+ }
@@ -0,0 +1,99 @@
1
+ package org.embulk.input.marketo.delegate;
2
+
3
+ import com.fasterxml.jackson.databind.JavaType;
4
+ import com.fasterxml.jackson.databind.ObjectMapper;
5
+ import com.fasterxml.jackson.databind.node.ObjectNode;
6
+ import org.embulk.EmbulkTestRuntime;
7
+ import org.embulk.base.restclient.ServiceResponseMapper;
8
+ import org.embulk.base.restclient.record.RecordImporter;
9
+ import org.embulk.base.restclient.record.ValueLocator;
10
+ import org.embulk.config.ConfigLoader;
11
+ import org.embulk.config.ConfigSource;
12
+ import org.embulk.input.marketo.MarketoUtils;
13
+ import org.embulk.input.marketo.model.MarketoField;
14
+ import org.embulk.input.marketo.rest.MarketoRestClient;
15
+ import org.embulk.input.marketo.rest.RecordPagingIterable;
16
+ import org.embulk.spi.PageBuilder;
17
+ import org.embulk.spi.Schema;
18
+ import org.junit.Before;
19
+ import org.junit.Rule;
20
+ import org.junit.Test;
21
+ import org.mockito.ArgumentCaptor;
22
+
23
+ import java.io.IOException;
24
+ import java.util.ArrayList;
25
+ import java.util.List;
26
+
27
+ import static org.junit.Assert.assertEquals;
28
+ import static org.mockito.ArgumentMatchers.any;
29
+ import static org.mockito.ArgumentMatchers.eq;
30
+ import static org.mockito.Mockito.*;
31
+
32
+ /**
33
+ * Created by tai.khuu on 10/10/17.
34
+ */
35
+ public class LeadWithListInputPluginTest
36
+ {
37
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
38
+
39
+ @Rule
40
+ public EmbulkTestRuntime embulkTestRuntime = new EmbulkTestRuntime();
41
+
42
+ private ConfigSource configSource;
43
+
44
+ private LeadWithListInputPlugin leadWithListInputPlugin;
45
+
46
+ private MarketoRestClient mockMarketoRestClient;
47
+
48
+ @Before
49
+ public void setUp() throws Exception
50
+ {
51
+ leadWithListInputPlugin = spy(new LeadWithListInputPlugin());
52
+ ConfigLoader configLoader = embulkTestRuntime.getInjector().getInstance(ConfigLoader.class);
53
+ configSource = configLoader.fromYaml(this.getClass().getResourceAsStream("/config/rest_config.yaml"));
54
+ mockMarketoRestClient = mock(MarketoRestClient.class);
55
+ doReturn(mockMarketoRestClient).when(leadWithListInputPlugin).createMarketoRestClient(any(LeadWithListInputPlugin.PluginTask.class));
56
+ }
57
+
58
+ @Test
59
+ public void testRun() throws IOException
60
+ {
61
+ RecordPagingIterable<ObjectNode> mockLeadRecordPagingIterable = mock(RecordPagingIterable.class);
62
+ RecordPagingIterable<ObjectNode> mockLeadEmptyRecordPagingIterable = mock(RecordPagingIterable.class);
63
+ RecordPagingIterable<ObjectNode> mocklistRecords = mock(RecordPagingIterable.class);
64
+
65
+ when(mockLeadEmptyRecordPagingIterable.iterator()).thenReturn(new ArrayList<ObjectNode>().iterator());
66
+ JavaType objectNodeListType = OBJECT_MAPPER.getTypeFactory().constructParametrizedType(List.class, List.class, ObjectNode.class);
67
+ JavaType marketoFieldsType = OBJECT_MAPPER.getTypeFactory().constructParametrizedType(List.class, List.class, MarketoField.class);
68
+ List<ObjectNode> leads = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/fixtures/lead_response_full.json"), objectNodeListType);
69
+ List<ObjectNode> lists = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/fixtures/list_reponse_full.json"), objectNodeListType);
70
+ when(mocklistRecords.iterator()).thenReturn(lists.iterator());
71
+ List<MarketoField> marketoFields = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/fixtures/lead_describe_marketo_fields_full.json"), marketoFieldsType);
72
+ when(mockLeadRecordPagingIterable.iterator()).thenReturn(leads.iterator());
73
+ when(mockMarketoRestClient.describeLead()).thenReturn(marketoFields);
74
+ when(mockMarketoRestClient.getLists()).thenReturn(mocklistRecords);
75
+ List<String> fieldNameFromMarketoFields = MarketoUtils.getFieldNameFromMarketoFields(marketoFields);
76
+ when(mockMarketoRestClient.getLeadsByList(anyString(), eq(fieldNameFromMarketoFields))).thenReturn(mockLeadEmptyRecordPagingIterable);
77
+ when(mockMarketoRestClient.getLeadsByList("1009", fieldNameFromMarketoFields)).thenReturn(mockLeadRecordPagingIterable);
78
+
79
+ LeadWithListInputPlugin.PluginTask task = configSource.loadConfig(LeadWithListInputPlugin.PluginTask.class);
80
+ ServiceResponseMapper<? extends ValueLocator> mapper = leadWithListInputPlugin.buildServiceResponseMapper(task);
81
+
82
+ RecordImporter recordImporter = mapper.createRecordImporter();
83
+ PageBuilder mockPageBuilder = mock(PageBuilder.class);
84
+ leadWithListInputPlugin.ingestServiceData(task, recordImporter, 1, mockPageBuilder);
85
+ verify(mockMarketoRestClient, times(1)).getLists();
86
+ verify(mockMarketoRestClient, times(24)).getLeadsByList(anyString(), eq(fieldNameFromMarketoFields));
87
+ verify(mockMarketoRestClient, times(1)).describeLead();
88
+
89
+ Schema embulkSchema = mapper.getEmbulkSchema();
90
+ ArgumentCaptor<Long> longArgumentCaptor = ArgumentCaptor.forClass(Long.class);
91
+
92
+ verify(mockPageBuilder, times(300)).setLong(eq(embulkSchema.lookupColumn("mk_id")), longArgumentCaptor.capture());
93
+ verify(mockPageBuilder, times(300)).setString(eq(embulkSchema.lookupColumn("mk_listId")), eq("1009"));
94
+
95
+ List<Long> allValues = longArgumentCaptor.getAllValues();
96
+ long actualValue = allValues.get(0);
97
+ assertEquals(103280L, actualValue);
98
+ }
99
+ }
@@ -0,0 +1,101 @@
1
+ package org.embulk.input.marketo.delegate;
2
+
3
+ import com.fasterxml.jackson.databind.JavaType;
4
+ import com.fasterxml.jackson.databind.ObjectMapper;
5
+ import com.fasterxml.jackson.databind.node.ObjectNode;
6
+ import org.embulk.EmbulkTestRuntime;
7
+ import org.embulk.base.restclient.ServiceResponseMapper;
8
+ import org.embulk.base.restclient.record.RecordImporter;
9
+ import org.embulk.base.restclient.record.ValueLocator;
10
+ import org.embulk.config.ConfigLoader;
11
+ import org.embulk.config.ConfigSource;
12
+ import org.embulk.input.marketo.MarketoUtils;
13
+ import org.embulk.input.marketo.model.MarketoField;
14
+ import org.embulk.input.marketo.rest.MarketoRestClient;
15
+ import org.embulk.input.marketo.rest.RecordPagingIterable;
16
+ import org.embulk.spi.PageBuilder;
17
+ import org.embulk.spi.Schema;
18
+ import org.junit.Before;
19
+ import org.junit.Rule;
20
+ import org.junit.Test;
21
+ import org.mockito.ArgumentCaptor;
22
+
23
+ import java.io.IOException;
24
+ import java.util.ArrayList;
25
+ import java.util.List;
26
+
27
+ import static org.junit.Assert.assertEquals;
28
+ import static org.mockito.ArgumentMatchers.any;
29
+ import static org.mockito.ArgumentMatchers.anyString;
30
+ import static org.mockito.ArgumentMatchers.eq;
31
+ import static org.mockito.Mockito.*;
32
+
33
+ /**
34
+ * Created by tai.khuu on 10/10/17.
35
+ */
36
+ public class LeadWithProgramInputPluginTest
37
+ {
38
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
39
+
40
+ @Rule
41
+ public EmbulkTestRuntime embulkTestRuntime = new EmbulkTestRuntime();
42
+
43
+ private ConfigSource configSource;
44
+
45
+ private LeadWithProgramInputPlugin leadWithProgramInputPlugin;
46
+
47
+ private MarketoRestClient mockMarketoRestClient;
48
+
49
+ @Before
50
+ public void setUp() throws Exception
51
+ {
52
+ leadWithProgramInputPlugin = spy(new LeadWithProgramInputPlugin());
53
+ ConfigLoader configLoader = embulkTestRuntime.getInjector().getInstance(ConfigLoader.class);
54
+ configSource = configLoader.fromYaml(this.getClass().getResourceAsStream("/config/rest_config.yaml"));
55
+ mockMarketoRestClient = mock(MarketoRestClient.class);
56
+ doReturn(mockMarketoRestClient).when(leadWithProgramInputPlugin).createMarketoRestClient(any(LeadWithProgramInputPlugin.PluginTask.class));
57
+ }
58
+
59
+ @Test
60
+ public void testRun() throws IOException
61
+ {
62
+ RecordPagingIterable<ObjectNode> mockLeadRecordPagingIterable = mock(RecordPagingIterable.class);
63
+ RecordPagingIterable<ObjectNode> mockLeadEmptyRecordPagingIterable = mock(RecordPagingIterable.class);
64
+ RecordPagingIterable<ObjectNode> mockProgramRecords = mock(RecordPagingIterable.class);
65
+
66
+ when(mockLeadEmptyRecordPagingIterable.iterator()).thenReturn(new ArrayList<ObjectNode>().iterator());
67
+ JavaType objectNodeListType = OBJECT_MAPPER.getTypeFactory().constructParametrizedType(List.class, List.class, ObjectNode.class);
68
+ JavaType marketoFieldsType = OBJECT_MAPPER.getTypeFactory().constructParametrizedType(List.class, List.class, MarketoField.class);
69
+ List<ObjectNode> leads = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/fixtures/lead_with_program_full.json"), objectNodeListType);
70
+ List<ObjectNode> programs = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/fixtures/all_program_full.json"), objectNodeListType);
71
+ when(mockProgramRecords.iterator()).thenReturn(programs.iterator());
72
+ List<MarketoField> marketoFields = OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/fixtures/lead_describe_marketo_fields_full.json"), marketoFieldsType);
73
+ when(mockLeadRecordPagingIterable.iterator()).thenReturn(leads.iterator());
74
+ when(mockMarketoRestClient.describeLead()).thenReturn(marketoFields);
75
+ when(mockMarketoRestClient.getPrograms()).thenReturn(mockProgramRecords);
76
+ List<String> fieldNameFromMarketoFields = MarketoUtils.getFieldNameFromMarketoFields(marketoFields);
77
+ when(mockMarketoRestClient.getLeadsByProgram(anyString(), eq(fieldNameFromMarketoFields))).thenReturn(mockLeadEmptyRecordPagingIterable);
78
+ when(mockMarketoRestClient.getLeadsByProgram("1003", fieldNameFromMarketoFields)).thenReturn(mockLeadRecordPagingIterable);
79
+
80
+ LeadWithProgramInputPlugin.PluginTask task = configSource.loadConfig(LeadWithProgramInputPlugin.PluginTask.class);
81
+ ServiceResponseMapper<? extends ValueLocator> mapper = leadWithProgramInputPlugin.buildServiceResponseMapper(task);
82
+
83
+ RecordImporter recordImporter = mapper.createRecordImporter();
84
+ PageBuilder mockPageBuilder = mock(PageBuilder.class);
85
+
86
+ leadWithProgramInputPlugin.ingestServiceData(task, recordImporter, 1, mockPageBuilder);
87
+ verify(mockMarketoRestClient, times(1)).getPrograms();
88
+ verify(mockMarketoRestClient, times(3)).getLeadsByProgram(anyString(), eq(fieldNameFromMarketoFields));
89
+ verify(mockMarketoRestClient, times(1)).describeLead();
90
+
91
+ Schema embulkSchema = mapper.getEmbulkSchema();
92
+ ArgumentCaptor<Long> longArgumentCaptor = ArgumentCaptor.forClass(Long.class);
93
+
94
+ verify(mockPageBuilder, times(1)).setLong(eq(embulkSchema.lookupColumn("mk_id")), longArgumentCaptor.capture());
95
+ verify(mockPageBuilder, times(1)).setString(eq(embulkSchema.lookupColumn("mk_programId")), eq("1003"));
96
+
97
+ List<Long> allValues = longArgumentCaptor.getAllValues();
98
+ long actualValue = allValues.get(0);
99
+ assertEquals(102519L, actualValue);
100
+ }
101
+ }
@@ -0,0 +1,114 @@
1
+ package org.embulk.input.marketo.delegate;
2
+
3
+ import com.google.common.base.Optional;
4
+ import com.google.common.collect.Sets;
5
+ import org.embulk.EmbulkTestRuntime;
6
+ import org.embulk.config.ConfigDiff;
7
+ import org.embulk.config.ConfigException;
8
+ import org.embulk.config.TaskReport;
9
+ import org.embulk.input.marketo.MarketoInputPluginDelegate;
10
+ import org.embulk.input.marketo.MarketoUtils;
11
+ import org.embulk.spi.Schema;
12
+ import org.joda.time.DateTime;
13
+ import org.junit.Before;
14
+ import org.junit.Rule;
15
+ import org.junit.Test;
16
+ import org.mockito.ArgumentCaptor;
17
+ import org.mockito.Mockito;
18
+
19
+ import java.text.DateFormat;
20
+ import java.text.SimpleDateFormat;
21
+ import java.util.Arrays;
22
+ import java.util.Date;
23
+ import java.util.Set;
24
+
25
+ import static org.junit.Assert.assertEquals;
26
+ import static org.mockito.Mockito.*;
27
+
28
+ /**
29
+ * Created by khuutantaitai on 10/3/17.
30
+ */
31
+ public class MarketoBaseBulkExtractInputPluginTest
32
+ {
33
+ @Rule
34
+ public EmbulkTestRuntime embulkTestRuntime = new EmbulkTestRuntime();
35
+
36
+ private MarketoBaseBulkExtractInputPlugin<MarketoBaseBulkExtractInputPlugin.PluginTask> baseBulkExtractInputPlugin;
37
+
38
+ @Before
39
+ public void prepare()
40
+ {
41
+ baseBulkExtractInputPlugin = mock(MarketoBaseBulkExtractInputPlugin.class, Mockito.CALLS_REAL_METHODS);
42
+ }
43
+
44
+ @Test(expected = ConfigException.class)
45
+ public void validateInputTaskError()
46
+ {
47
+ MarketoBaseBulkExtractInputPlugin.PluginTask pluginTask = mock(MarketoBaseBulkExtractInputPlugin.PluginTask.class);
48
+ when(pluginTask.getFromDate()).thenReturn(null);
49
+ baseBulkExtractInputPlugin.validateInputTask(pluginTask);
50
+ }
51
+
52
+ @Test()
53
+ public void validateInputTaskToDateLessThanJobStartTime()
54
+ {
55
+ Date fromDate = new Date(1504224000000L);
56
+ MarketoBaseBulkExtractInputPlugin.PluginTask pluginTask = mock(MarketoBaseBulkExtractInputPlugin.PluginTask.class);
57
+ when(pluginTask.getFromDate()).thenReturn(fromDate);
58
+ when(pluginTask.getFetchDays()).thenReturn(7);
59
+ baseBulkExtractInputPlugin.validateInputTask(pluginTask);
60
+ ArgumentCaptor<Optional<Date>> argumentCaptor = ArgumentCaptor.forClass(Optional.class);
61
+ verify(pluginTask, times(1)).setToDate(argumentCaptor.capture());
62
+ assertEquals(1504828800000L, argumentCaptor.getValue().get().getTime());
63
+ }
64
+
65
+ @Test()
66
+ public void validateInputTaskToDateMoreThanJobStartTime()
67
+ {
68
+ Date fromDate = new Date(1504224000000L);
69
+ DateTime jobStartTime = new DateTime(1504396800000L);
70
+ MarketoBaseBulkExtractInputPlugin.PluginTask pluginTask = mock(MarketoBaseBulkExtractInputPlugin.PluginTask.class);
71
+ when(pluginTask.getFromDate()).thenReturn(fromDate);
72
+ when(pluginTask.getFetchDays()).thenReturn(7);
73
+ when(pluginTask.getJobStartTime()).thenReturn(jobStartTime);
74
+ baseBulkExtractInputPlugin.validateInputTask(pluginTask);
75
+ ArgumentCaptor<Optional<Date>> toDateArgumentCaptor = ArgumentCaptor.forClass(Optional.class);
76
+ verify(pluginTask, times(1)).setToDate(toDateArgumentCaptor.capture());
77
+ assertEquals(jobStartTime.minusHours(1).getMillis(), toDateArgumentCaptor.getValue().get().getTime());
78
+ }
79
+
80
+ @Test
81
+ public void getToDate() throws Exception
82
+ {
83
+ DateTime date = new DateTime(1505033728000L);
84
+ DateTime jobStartTime = new DateTime(1507625728000L);
85
+ MarketoBaseBulkExtractInputPlugin.PluginTask pluginTask = mock(MarketoInputPluginDelegate.PluginTask.class);
86
+ when(pluginTask.getFromDate()).thenReturn(date.toDate());
87
+ when(pluginTask.getFetchDays()).thenReturn(30);
88
+ when(pluginTask.getJobStartTime()).thenReturn(jobStartTime);
89
+ DateTime toDate = baseBulkExtractInputPlugin.getToDate(pluginTask);
90
+ assertEquals(toDate, jobStartTime);
91
+ }
92
+
93
+ @Test
94
+ public void buildConfigDiff() throws Exception
95
+ {
96
+ TaskReport taskReport1 = mock(TaskReport.class);
97
+ TaskReport taskReport2 = mock(TaskReport.class);
98
+ when(taskReport1.get(Set.class, "latest_uids")).thenReturn(Sets.newHashSet("id1", "id2"));
99
+ when(taskReport2.get(Set.class, "latest_uids")).thenReturn(Sets.newHashSet("id3", "id4"));
100
+ when(taskReport1.get(Long.class, "latest_fetch_time")).thenReturn(1507539328000L);
101
+ when(taskReport2.get(Long.class, "latest_fetch_time")).thenReturn(1507625728000L);
102
+ MarketoInputPluginDelegate.PluginTask task = mock(MarketoInputPluginDelegate.PluginTask.class);
103
+ when(task.getIncremental()).thenReturn(true);
104
+ when(task.getIncrementalColumn()).thenReturn(Optional.of("createdAt"));
105
+ Date toDate = new Date(1507625728000L);
106
+ when(task.getToDate()).thenReturn(Optional.of(toDate));
107
+ ConfigDiff configDiff = baseBulkExtractInputPlugin.buildConfigDiff(task, mock(Schema.class), 1, Arrays.asList(taskReport1, taskReport2));
108
+ long latestFetchTime = configDiff.get(Long.class, "latest_fetch_time");
109
+ assertEquals(1507625728000L, latestFetchTime);
110
+ assertEquals(Sets.newHashSet("id3", "id4"), configDiff.get(Set.class, "latest_uids"));
111
+ DateFormat df = new SimpleDateFormat(MarketoUtils.MARKETO_DATE_SIMPLE_DATE_FORMAT);
112
+ assertEquals(df.format(toDate), configDiff.get(String.class, "from_date"));
113
+ }
114
+ }
@@ -36,14 +36,12 @@ import static org.mockito.Mockito.*;
36
36
  */
37
37
  public class MarketoBaseRestClientTest
38
38
  {
39
-
40
39
  private static final String IDENTITY_END_POINT = "identityEndPoint";
41
40
 
42
41
  private static final int MARKETO_LIMIT_INTERVAL_MILIS = 1000;
43
42
 
44
43
  private MarketoBaseRestClient marketoBaseRestClient;
45
44
 
46
-
47
45
  private Jetty92RetryHelper mockJetty92;
48
46
 
49
47
  @Rule
@@ -55,12 +53,6 @@ public class MarketoBaseRestClientTest
55
53
  marketoBaseRestClient = new MarketoBaseRestClient("identityEndPoint", "clientId", "clientSecret", MARKETO_LIMIT_INTERVAL_MILIS, mockJetty92);
56
54
  }
57
55
 
58
- @Test
59
- public void doGet() throws Exception
60
- {
61
-
62
- }
63
-
64
56
  @Test
65
57
  public void testGetAccessToken()
66
58
  {
@@ -77,7 +69,6 @@ public class MarketoBaseRestClientTest
77
69
  @Test
78
70
  public void testGetAccessTokenRequester()
79
71
  {
80
-
81
72
  ArgumentCaptor<Jetty92SingleRequester> jetty92SingleRequesterArgumentCaptor = ArgumentCaptor.forClass(Jetty92SingleRequester.class);
82
73
  when(mockJetty92.requestWithRetry(any(StringJetty92ResponseEntityReader.class), jetty92SingleRequesterArgumentCaptor.capture())).thenReturn("{\"access_token\": \"access_token\"}");
83
74
  String accessToken = marketoBaseRestClient.getAccessToken();
@@ -105,7 +96,8 @@ public class MarketoBaseRestClientTest
105
96
  "}");
106
97
  try {
107
98
  marketoBaseRestClient.getAccessToken();
108
- } catch (DataException ex) {
99
+ }
100
+ catch (DataException ex) {
109
101
  assertEquals("Bad client credentials", ex.getMessage());
110
102
  return;
111
103
  }
@@ -163,7 +155,6 @@ public class MarketoBaseRestClientTest
163
155
  verify(mockRequest, times(1)).header(eq("Authorization"), eq("Bearer access_token"));
164
156
  verify(mockRequest, times(1)).param(eq("param"), eq("param1"));
165
157
  verify(mockRequest, times(1)).content(eq(contentProvider), eq("application/json"));
166
-
167
158
  }
168
159
 
169
160
  @Test
@@ -188,7 +179,6 @@ public class MarketoBaseRestClientTest
188
179
  jetty92SingleRequester.requestOnce(client, listener);
189
180
  assertTrue(jetty92SingleRequester.toRetry(createHttpResponseException(502)));
190
181
 
191
-
192
182
  assertFalse(jetty92SingleRequester.toRetry(createHttpResponseException(400)));
193
183
 
194
184
  assertFalse(jetty92SingleRequester.toRetry(createMarketoAPIException("ERR", "ERR")));
@@ -197,7 +187,6 @@ public class MarketoBaseRestClientTest
197
187
  assertTrue(jetty92SingleRequester.toRetry(createMarketoAPIException("602", "")));
198
188
 
199
189
  verify(mockJetty92, times(2)).requestWithRetry(any(StringJetty92ResponseEntityReader.class), any(Jetty92SingleRequester.class));
200
-
201
190
  }
202
191
 
203
192
  private HttpResponseException createHttpResponseException(int statusCode)
@@ -216,5 +205,4 @@ public class MarketoBaseRestClientTest
216
205
  marketoError.setMessage(error);
217
206
  return new MarketoAPIException(Lists.newArrayList(marketoError));
218
207
  }
219
-
220
- }
208
+ }