embulk-output-kintone 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/classpath/embulk-output-kintone-1.2.0.jar +0 -0
- data/classpath/{shadow-kintone-java-client-1.1.0-all.jar → shadow-kintone-java-client-1.2.0-all.jar} +0 -0
- data/src/main/java/org/embulk/output/kintone/KintoneClient.java +117 -0
- data/src/main/java/org/embulk/output/kintone/KintoneColumnType.java +30 -13
- data/src/main/java/org/embulk/output/kintone/KintoneColumnVisitor.java +54 -4
- data/src/main/java/org/embulk/output/kintone/KintoneMode.java +52 -4
- data/src/main/java/org/embulk/output/kintone/KintoneOutputPlugin.java +0 -17
- data/src/main/java/org/embulk/output/kintone/KintonePageOutput.java +106 -118
- data/src/main/java/org/embulk/output/kintone/PluginTask.java +5 -0
- data/src/main/java/org/embulk/output/kintone/record/Id.java +18 -0
- data/src/main/java/org/embulk/output/kintone/record/IdOrUpdateKey.java +45 -0
- data/src/main/java/org/embulk/output/kintone/record/Skip.java +14 -0
- data/src/main/java/org/embulk/output/kintone/util/Lazy.java +20 -0
- data/src/test/java/org/embulk/output/kintone/KintoneClientTest.java +139 -0
- data/src/test/java/org/embulk/output/kintone/KintoneColumnVisitorTest.java +33 -33
- data/src/test/java/org/embulk/output/kintone/KintoneColumnVisitorVerifier.java +6 -6
- data/src/test/java/org/embulk/output/kintone/KintonePageOutputVerifier.java +79 -53
- data/src/test/java/org/embulk/output/kintone/MockClient.java +112 -0
- data/src/test/java/org/embulk/output/kintone/TestKintoneOutputPlugin.java +64 -16
- data/src/test/java/org/embulk/output/kintone/TestTaskMode.java +1 -0
- data/src/test/java/org/embulk/output/kintone/TestTaskReduce.java +1 -0
- data/src/test/java/org/embulk/output/kintone/TestTaskReduceSubtable.java +1 -0
- data/src/test/java/org/embulk/output/kintone/TestTaskSkip.java +80 -0
- data/src/test/java/org/embulk/output/kintone/TestTaskSkipId.java +80 -0
- data/src/test/resources/org/embulk/output/kintone/client/config.yml +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/config.yml +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/mode/upsert_never_skip_double_single_line_text_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce/upsert_never_skip_double_single_line_text_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/config.yml +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/input.csv +7 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/insert_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/insert_always_skip_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/insert_always_skip_prefer_nulls_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/insert_never_skip_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/insert_never_skip_prefer_nulls_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/insert_prefer_nulls_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/update_always_skip_long_number_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/update_always_skip_long_number_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/update_always_skip_prefer_nulls_long_number_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/update_always_skip_prefer_nulls_long_number_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/update_always_skip_prefer_nulls_update_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/update_always_skip_update_records.jsonl +5 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/update_never_skip_update_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/update_prefer_nulls_update_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/update_update_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_add_records.jsonl +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_always_skip_prefer_nulls_string_single_line_text_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_always_skip_prefer_nulls_string_single_line_text_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_always_skip_prefer_nulls_update_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_always_skip_string_single_line_text_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_always_skip_string_single_line_text_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_always_skip_update_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_never_skip_add_records.jsonl +4 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_never_skip_prefer_nulls_add_records.jsonl +4 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_never_skip_prefer_nulls_string_single_line_text_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_never_skip_prefer_nulls_string_single_line_text_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_never_skip_prefer_nulls_update_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_never_skip_string_single_line_text_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_never_skip_string_single_line_text_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_never_skip_update_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_prefer_nulls_add_records.jsonl +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_prefer_nulls_string_single_line_text_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_prefer_nulls_string_single_line_text_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_prefer_nulls_update_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_string_single_line_text_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_string_single_line_text_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip/upsert_update_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/config.yml +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/input.csv +7 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/insert_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/insert_always_skip_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/insert_always_skip_prefer_nulls_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/insert_never_skip_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/insert_never_skip_prefer_nulls_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/insert_prefer_nulls_add_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/update_always_skip__id_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/update_always_skip__id_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/update_always_skip_prefer_nulls__id_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/update_always_skip_prefer_nulls__id_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/update_always_skip_prefer_nulls_update_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/update_always_skip_update_records.jsonl +5 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/update_never_skip_update_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/update_prefer_nulls_update_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/update_update_records.jsonl +6 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert__id_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert__id_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_always_skip__id_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_always_skip__id_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_always_skip_prefer_nulls__id_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_always_skip_prefer_nulls__id_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_always_skip_prefer_nulls_update_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_always_skip_update_records.jsonl +5 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_never_skip__id_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_never_skip__id_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_never_skip_add_records.jsonl +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_never_skip_prefer_nulls__id_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_never_skip_prefer_nulls__id_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_never_skip_prefer_nulls_add_records.jsonl +4 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_never_skip_prefer_nulls_update_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_never_skip_update_records.jsonl +5 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_prefer_nulls__id_add_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_prefer_nulls__id_values.json +1 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_prefer_nulls_add_records.jsonl +3 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_prefer_nulls_update_records.jsonl +2 -0
- data/src/test/resources/org/embulk/output/kintone/task/skip_id/upsert_update_records.jsonl +5 -0
- metadata +131 -43
- data/classpath/embulk-output-kintone-1.1.0.jar +0 -0
- data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/upsert_add_records.jsonl +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{insert_add_ignore_nulls_records.jsonl → insert_ignore_nulls_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{insert_add_prefer_nulls_records.jsonl → insert_prefer_nulls_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{update_update_ignore_nulls_records.jsonl → update_ignore_nulls_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{update_update_prefer_nulls_records.jsonl → update_prefer_nulls_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{upsert_add_records.jsonl → upsert_never_skip_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{values.json → upsert_never_skip_double_single_line_text_values.json} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{upsert_add_ignore_nulls_records.jsonl → upsert_never_skip_ignore_nulls_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{values_ignore_nulls.json → upsert_never_skip_ignore_nulls_double_single_line_text_values.json} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{upsert_update_ignore_nulls_records.jsonl → upsert_never_skip_ignore_nulls_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{upsert_add_prefer_nulls_records.jsonl → upsert_never_skip_prefer_nulls_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{values_prefer_nulls.json → upsert_never_skip_prefer_nulls_double_single_line_text_values.json} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{upsert_update_prefer_nulls_records.jsonl → upsert_never_skip_prefer_nulls_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/mode/{upsert_update_records.jsonl → upsert_never_skip_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{insert_add_ignore_nulls_records.jsonl → insert_ignore_nulls_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{insert_add_prefer_nulls_records.jsonl → insert_prefer_nulls_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{update_update_ignore_nulls_records.jsonl → update_ignore_nulls_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{update_update_prefer_nulls_records.jsonl → update_prefer_nulls_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{upsert_add_records.jsonl → upsert_never_skip_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{values.json → upsert_never_skip_double_single_line_text_values.json} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{upsert_add_ignore_nulls_records.jsonl → upsert_never_skip_ignore_nulls_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{values_ignore_nulls.json → upsert_never_skip_ignore_nulls_double_single_line_text_values.json} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{upsert_update_ignore_nulls_records.jsonl → upsert_never_skip_ignore_nulls_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{upsert_add_prefer_nulls_records.jsonl → upsert_never_skip_prefer_nulls_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{values_prefer_nulls.json → upsert_never_skip_prefer_nulls_double_single_line_text_values.json} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{upsert_update_prefer_nulls_records.jsonl → upsert_never_skip_prefer_nulls_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce/{upsert_update_records.jsonl → upsert_never_skip_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/{insert_add_ignore_nulls_records.jsonl → insert_ignore_nulls_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/{insert_add_prefer_nulls_records.jsonl → insert_prefer_nulls_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/{update_update_ignore_nulls_records.jsonl → update_ignore_nulls_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/{update_update_prefer_nulls_records.jsonl → update_prefer_nulls_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/{values.json → upsert_never_skip_double_single_line_text_values.json} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/{upsert_add_ignore_nulls_records.jsonl → upsert_never_skip_ignore_nulls_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/{values_ignore_nulls.json → upsert_never_skip_ignore_nulls_double_single_line_text_values.json} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/{upsert_update_ignore_nulls_records.jsonl → upsert_never_skip_ignore_nulls_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/{upsert_add_prefer_nulls_records.jsonl → upsert_never_skip_prefer_nulls_add_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/{values_prefer_nulls.json → upsert_never_skip_prefer_nulls_double_single_line_text_values.json} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/{upsert_update_prefer_nulls_records.jsonl → upsert_never_skip_prefer_nulls_update_records.jsonl} +0 -0
- /data/src/test/resources/org/embulk/output/kintone/task/reduce_subtable/{upsert_update_records.jsonl → upsert_never_skip_update_records.jsonl} +0 -0
@@ -44,7 +44,7 @@ public class KintoneColumnVisitorTest {
|
|
44
44
|
public void test() {
|
45
45
|
KintoneColumnVisitorVerifier verifier = verifier(null, "STRING|SINGLE_LINE_TEXT");
|
46
46
|
verifier.verify(
|
47
|
-
(record,
|
47
|
+
(record, idOrUpdateKey) -> {
|
48
48
|
assertThat(record.getSingleLineTextFieldValue("BOOLEAN|SINGLE_LINE_TEXT"), is("false"));
|
49
49
|
assertThat(record.getNumberFieldValue("BOOLEAN"), is(number("0")));
|
50
50
|
assertThat(record.getSingleLineTextFieldValue("LONG|SINGLE_LINE_TEXT"), is("0"));
|
@@ -104,11 +104,11 @@ public class KintoneColumnVisitorTest {
|
|
104
104
|
assertThat(record.getSubtableFieldValue("JSON|SUBTABLE"), is(list()));
|
105
105
|
assertThat(
|
106
106
|
record.getSingleLineTextFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), is("\"\""));
|
107
|
-
assertThat(
|
108
|
-
assertThat(
|
107
|
+
assertThat(idOrUpdateKey.getField(), is("STRING|SINGLE_LINE_TEXT"));
|
108
|
+
assertThat(idOrUpdateKey.getValue(), is(""));
|
109
109
|
});
|
110
110
|
verifier.verify(
|
111
|
-
(record,
|
111
|
+
(record, idOrUpdateKey) -> {
|
112
112
|
assertThat(record.getSingleLineTextFieldValue("BOOLEAN|SINGLE_LINE_TEXT"), is("false"));
|
113
113
|
assertThat(record.getNumberFieldValue("BOOLEAN"), is(number("0")));
|
114
114
|
assertThat(record.getSingleLineTextFieldValue("LONG|SINGLE_LINE_TEXT"), is("0"));
|
@@ -168,11 +168,11 @@ public class KintoneColumnVisitorTest {
|
|
168
168
|
assertThat(record.getSubtableFieldValue("JSON|SUBTABLE"), is(list()));
|
169
169
|
assertThat(
|
170
170
|
record.getSingleLineTextFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), is("\"\""));
|
171
|
-
assertThat(
|
172
|
-
assertThat(
|
171
|
+
assertThat(idOrUpdateKey.getField(), is("STRING|SINGLE_LINE_TEXT"));
|
172
|
+
assertThat(idOrUpdateKey.getValue(), is(""));
|
173
173
|
});
|
174
174
|
verifier.verify(
|
175
|
-
(record,
|
175
|
+
(record, idOrUpdateKey) -> {
|
176
176
|
assertThat(record.getSingleLineTextFieldValue("BOOLEAN|SINGLE_LINE_TEXT"), is("true"));
|
177
177
|
assertThat(record.getNumberFieldValue("BOOLEAN"), is(number("1")));
|
178
178
|
assertThat(record.getSingleLineTextFieldValue("LONG|SINGLE_LINE_TEXT"), is("123"));
|
@@ -233,11 +233,11 @@ public class KintoneColumnVisitorTest {
|
|
233
233
|
assertTableRows(record.getSubtableFieldValue("JSON|SUBTABLE"), rows(0L, 1L, 2L));
|
234
234
|
assertThat(
|
235
235
|
record.getSingleLineTextFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), is("\"abc\""));
|
236
|
-
assertThat(
|
237
|
-
assertThat(
|
236
|
+
assertThat(idOrUpdateKey.getField(), is("STRING|SINGLE_LINE_TEXT"));
|
237
|
+
assertThat(idOrUpdateKey.getValue(), is("abc"));
|
238
238
|
});
|
239
239
|
verifier.verify(
|
240
|
-
(record,
|
240
|
+
(record, idOrUpdateKey) -> {
|
241
241
|
assertThat(record.getSingleLineTextFieldValue("BOOLEAN|SINGLE_LINE_TEXT"), is("false"));
|
242
242
|
assertThat(record.getNumberFieldValue("BOOLEAN"), is(number("0")));
|
243
243
|
assertThat(record.getSingleLineTextFieldValue("LONG|SINGLE_LINE_TEXT"), is("456"));
|
@@ -298,8 +298,8 @@ public class KintoneColumnVisitorTest {
|
|
298
298
|
assertTableRows(record.getSubtableFieldValue("JSON|SUBTABLE"), rows(3L, 4L, 5L));
|
299
299
|
assertThat(
|
300
300
|
record.getSingleLineTextFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), is("\"def\""));
|
301
|
-
assertThat(
|
302
|
-
assertThat(
|
301
|
+
assertThat(idOrUpdateKey.getField(), is("STRING|SINGLE_LINE_TEXT"));
|
302
|
+
assertThat(idOrUpdateKey.getValue(), is("def"));
|
303
303
|
});
|
304
304
|
}
|
305
305
|
|
@@ -307,7 +307,7 @@ public class KintoneColumnVisitorTest {
|
|
307
307
|
public void testPreferNulls() {
|
308
308
|
KintoneColumnVisitorVerifier verifier = verifier(null, "LONG", true, false);
|
309
309
|
verifier.verify(
|
310
|
-
(record,
|
310
|
+
(record, idOrUpdateKey) -> {
|
311
311
|
assertThat(
|
312
312
|
record.getFieldType("BOOLEAN|SINGLE_LINE_TEXT"), is(FieldType.SINGLE_LINE_TEXT));
|
313
313
|
assertThat(record.getFieldType("BOOLEAN"), is(FieldType.NUMBER));
|
@@ -415,8 +415,8 @@ public class KintoneColumnVisitorTest {
|
|
415
415
|
assertThat(record.getSubtableFieldValue("JSON|SUBTABLE"), is(list()));
|
416
416
|
assertThat(
|
417
417
|
record.getSingleLineTextFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), nullValue());
|
418
|
-
assertThat(
|
419
|
-
assertThat(
|
418
|
+
assertThat(idOrUpdateKey.getField(), is("LONG"));
|
419
|
+
assertThat(idOrUpdateKey.getValue(), nullValue());
|
420
420
|
});
|
421
421
|
}
|
422
422
|
|
@@ -424,7 +424,7 @@ public class KintoneColumnVisitorTest {
|
|
424
424
|
public void testIgnoreNulls() {
|
425
425
|
KintoneColumnVisitorVerifier verifier = verifier("JSON", "JSON", false, true);
|
426
426
|
verifier.verify(
|
427
|
-
(record,
|
427
|
+
(record, idOrUpdateKey) -> {
|
428
428
|
assertThat(record.getFieldValue("BOOLEAN|SINGLE_LINE_TEXT"), nullValue());
|
429
429
|
assertThat(record.getFieldValue("BOOLEAN"), nullValue());
|
430
430
|
assertThat(record.getFieldValue("LONG|SINGLE_LINE_TEXT"), nullValue());
|
@@ -475,8 +475,8 @@ public class KintoneColumnVisitorTest {
|
|
475
475
|
assertThat(record.getFieldValue("JSON"), nullValue());
|
476
476
|
assertThat(record.getFieldValue("JSON|SUBTABLE"), nullValue());
|
477
477
|
assertThat(record.getFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), nullValue());
|
478
|
-
assertThat(
|
479
|
-
assertThat(
|
478
|
+
assertThat(idOrUpdateKey.getField(), nullValue());
|
479
|
+
assertThat(idOrUpdateKey.getValue(), nullValue());
|
480
480
|
},
|
481
481
|
true);
|
482
482
|
}
|
@@ -485,7 +485,7 @@ public class KintoneColumnVisitorTest {
|
|
485
485
|
public void testReduceKey() {
|
486
486
|
KintoneColumnVisitorVerifier verifier = verifier("JSON|SUBTABLE", null);
|
487
487
|
verifier.verify(
|
488
|
-
(record,
|
488
|
+
(record, idOrUpdateKey) -> {
|
489
489
|
assertThat(record.getSingleLineTextFieldValue("BOOLEAN|SINGLE_LINE_TEXT"), is("false"));
|
490
490
|
assertThat(record.getNumberFieldValue("BOOLEAN"), is(number("0")));
|
491
491
|
assertThat(record.getSingleLineTextFieldValue("LONG|SINGLE_LINE_TEXT"), is("0"));
|
@@ -544,8 +544,8 @@ public class KintoneColumnVisitorTest {
|
|
544
544
|
assertThat(record.getMultiLineTextFieldValue("JSON"), is("\"\""));
|
545
545
|
assertThat(record.getSubtableFieldValue("JSON|SUBTABLE"), is(list()));
|
546
546
|
assertThat(record.getFieldValue("JSON|SUBTABLE.SINGLE_LINE_TEXT"), nullValue());
|
547
|
-
assertThat(
|
548
|
-
assertThat(
|
547
|
+
assertThat(idOrUpdateKey.getField(), nullValue());
|
548
|
+
assertThat(idOrUpdateKey.getValue(), nullValue());
|
549
549
|
},
|
550
550
|
true);
|
551
551
|
}
|
@@ -555,24 +555,24 @@ public class KintoneColumnVisitorTest {
|
|
555
555
|
assertThrows(UnsupportedOperationException.class, () -> verifier(null, "TIMESTAMP").verify());
|
556
556
|
KintoneColumnVisitorVerifier verifier = verifier(null, "TIMESTAMP|NUMBER");
|
557
557
|
verifier.verify(
|
558
|
-
(record,
|
559
|
-
assertThat(
|
560
|
-
assertThat(
|
558
|
+
(record, idOrUpdateKey) -> {
|
559
|
+
assertThat(idOrUpdateKey.getField(), is("TIMESTAMP|NUMBER"));
|
560
|
+
assertThat(idOrUpdateKey.getValue(), is(number("0")));
|
561
561
|
});
|
562
562
|
verifier.verify(
|
563
|
-
(record,
|
564
|
-
assertThat(
|
565
|
-
assertThat(
|
563
|
+
(record, idOrUpdateKey) -> {
|
564
|
+
assertThat(idOrUpdateKey.getField(), is("TIMESTAMP|NUMBER"));
|
565
|
+
assertThat(idOrUpdateKey.getValue(), is(number("0")));
|
566
566
|
});
|
567
567
|
verifier.verify(
|
568
|
-
(record,
|
569
|
-
assertThat(
|
570
|
-
assertThat(
|
568
|
+
(record, idOrUpdateKey) -> {
|
569
|
+
assertThat(idOrUpdateKey.getField(), is("TIMESTAMP|NUMBER"));
|
570
|
+
assertThat(idOrUpdateKey.getValue(), is(number("946684799")));
|
571
571
|
});
|
572
572
|
verifier.verify(
|
573
|
-
(record,
|
574
|
-
assertThat(
|
575
|
-
assertThat(
|
573
|
+
(record, idOrUpdateKey) -> {
|
574
|
+
assertThat(idOrUpdateKey.getField(), is("TIMESTAMP|NUMBER"));
|
575
|
+
assertThat(idOrUpdateKey.getValue(), is(number("946684800")));
|
576
576
|
});
|
577
577
|
}
|
578
578
|
|
@@ -2,11 +2,11 @@ package org.embulk.output.kintone;
|
|
2
2
|
|
3
3
|
import com.kintone.client.model.record.FieldType;
|
4
4
|
import com.kintone.client.model.record.Record;
|
5
|
-
import com.kintone.client.model.record.UpdateKey;
|
6
5
|
import java.util.Map;
|
7
6
|
import java.util.Set;
|
8
7
|
import java.util.function.BiConsumer;
|
9
8
|
import javax.validation.UnexpectedTypeException;
|
9
|
+
import org.embulk.output.kintone.record.IdOrUpdateKey;
|
10
10
|
import org.embulk.spi.Column;
|
11
11
|
import org.embulk.spi.Page;
|
12
12
|
import org.embulk.spi.PageReader;
|
@@ -50,21 +50,21 @@ public class KintoneColumnVisitorVerifier {
|
|
50
50
|
verify((record, updateKey) -> {});
|
51
51
|
}
|
52
52
|
|
53
|
-
public void verify(BiConsumer<Record,
|
53
|
+
public void verify(BiConsumer<Record, IdOrUpdateKey> consumer) {
|
54
54
|
verify(consumer, false);
|
55
55
|
}
|
56
56
|
|
57
|
-
public void verify(BiConsumer<Record,
|
57
|
+
public void verify(BiConsumer<Record, IdOrUpdateKey> consumer, boolean nullable) {
|
58
58
|
if (!reader.nextRecord()) {
|
59
59
|
throw new IllegalStateException();
|
60
60
|
}
|
61
61
|
Record record = new Record();
|
62
62
|
visitor.setRecord(record);
|
63
|
-
|
64
|
-
visitor.
|
63
|
+
IdOrUpdateKey idOrUpdateKey = new IdOrUpdateKey();
|
64
|
+
visitor.setIdOrUpdateKey(idOrUpdateKey);
|
65
65
|
schema.visitColumns(visitor);
|
66
66
|
schema.getColumns().forEach(column -> verify(record, column, nullable));
|
67
|
-
consumer.accept(record,
|
67
|
+
consumer.accept(record, idOrUpdateKey);
|
68
68
|
}
|
69
69
|
|
70
70
|
private void verify(Record record, Column column, boolean nullable) {
|
@@ -3,24 +3,13 @@ package org.embulk.output.kintone;
|
|
3
3
|
import static org.embulk.output.kintone.deserializer.DeserializerTest.assertTableRows;
|
4
4
|
import static org.hamcrest.MatcherAssert.assertThat;
|
5
5
|
import static org.hamcrest.Matchers.is;
|
6
|
-
import static org.mockito.ArgumentMatchers.anyList;
|
7
6
|
import static org.mockito.ArgumentMatchers.eq;
|
8
|
-
import static org.mockito.ArgumentMatchers.matches;
|
9
7
|
import static org.mockito.Mockito.CALLS_REAL_METHODS;
|
10
8
|
import static org.mockito.Mockito.atLeast;
|
11
|
-
import static org.mockito.Mockito.mock;
|
12
9
|
import static org.mockito.Mockito.mockStatic;
|
13
10
|
import static org.mockito.Mockito.verify;
|
14
|
-
import static org.mockito.Mockito.when;
|
15
11
|
|
16
|
-
import com.kintone.client.AppClient;
|
17
|
-
import com.kintone.client.KintoneClient;
|
18
|
-
import com.kintone.client.KintoneClientBuilder;
|
19
12
|
import com.kintone.client.RecordClient;
|
20
|
-
import com.kintone.client.api.record.GetRecordsByCursorResponseBody;
|
21
|
-
import com.kintone.client.model.app.field.FieldProperty;
|
22
|
-
import com.kintone.client.model.app.field.NumberFieldProperty;
|
23
|
-
import com.kintone.client.model.app.field.SingleLineTextFieldProperty;
|
24
13
|
import com.kintone.client.model.record.FieldType;
|
25
14
|
import com.kintone.client.model.record.FieldValue;
|
26
15
|
import com.kintone.client.model.record.NumberFieldValue;
|
@@ -33,23 +22,27 @@ import java.math.BigDecimal;
|
|
33
22
|
import java.util.Collection;
|
34
23
|
import java.util.Collections;
|
35
24
|
import java.util.List;
|
36
|
-
import java.util.
|
25
|
+
import java.util.function.Function;
|
37
26
|
import java.util.stream.Collectors;
|
38
27
|
import java.util.stream.IntStream;
|
39
28
|
import org.embulk.config.TaskReport;
|
40
29
|
import org.embulk.deps.buffer.PooledBufferAllocator;
|
30
|
+
import org.embulk.output.kintone.record.Id;
|
41
31
|
import org.embulk.spi.BufferAllocator;
|
42
32
|
import org.embulk.spi.Exec;
|
43
33
|
import org.embulk.spi.Page;
|
44
34
|
import org.embulk.spi.TransactionalPageOutput;
|
45
35
|
import org.mockito.ArgumentCaptor;
|
46
36
|
import org.mockito.MockedStatic;
|
37
|
+
import org.msgpack.value.StringValue;
|
38
|
+
import org.msgpack.value.ValueFactory;
|
47
39
|
|
48
40
|
public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
49
41
|
private final TransactionalPageOutput transactionalPageOutput;
|
50
42
|
private final String domain;
|
51
43
|
private final String field;
|
52
44
|
private final List<String> values;
|
45
|
+
private final List<String> addValues;
|
53
46
|
private final List<Record> addRecords;
|
54
47
|
private final List<RecordForUpdate> updateRecords;
|
55
48
|
|
@@ -57,9 +50,10 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
57
50
|
String domain,
|
58
51
|
String field,
|
59
52
|
List<String> values,
|
53
|
+
List<String> addValues,
|
60
54
|
List<Record> addRecords,
|
61
55
|
List<RecordForUpdate> updateRecords) {
|
62
|
-
this(null, domain, field, values, addRecords, updateRecords);
|
56
|
+
this(null, domain, field, values, addValues, addRecords, updateRecords);
|
63
57
|
}
|
64
58
|
|
65
59
|
public KintonePageOutputVerifier(
|
@@ -67,12 +61,14 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
67
61
|
String domain,
|
68
62
|
String field,
|
69
63
|
List<String> values,
|
64
|
+
List<String> addValues,
|
70
65
|
List<Record> addRecords,
|
71
66
|
List<RecordForUpdate> updateRecords) {
|
72
67
|
this.transactionalPageOutput = transactionalPageOutput;
|
73
68
|
this.domain = domain;
|
74
69
|
this.field = field;
|
75
70
|
this.values = values;
|
71
|
+
this.addValues = addValues;
|
76
72
|
this.addRecords = addRecords;
|
77
73
|
this.updateRecords = updateRecords;
|
78
74
|
}
|
@@ -105,7 +101,7 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
105
101
|
return transactionalPageOutput.commit();
|
106
102
|
}
|
107
103
|
|
108
|
-
public void runWithMock(Runnable runnable) {
|
104
|
+
public void runWithMock(MockClient.Runnable runnable) {
|
109
105
|
try {
|
110
106
|
runWithMockExec(runnable);
|
111
107
|
} catch (Exception e) {
|
@@ -113,7 +109,7 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
113
109
|
}
|
114
110
|
}
|
115
111
|
|
116
|
-
private void runWithMockExec(Runnable runnable) throws Exception {
|
112
|
+
private void runWithMockExec(MockClient.Runnable runnable) throws Exception {
|
117
113
|
BufferAllocator bufferAllocator = PooledBufferAllocator.create(1024 * 1024);
|
118
114
|
try (MockedStatic<Exec> mocked = mockStatic(Exec.class, CALLS_REAL_METHODS)) {
|
119
115
|
mocked.when(Exec::getBufferAllocator).thenReturn(bufferAllocator);
|
@@ -121,37 +117,11 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
121
117
|
}
|
122
118
|
}
|
123
119
|
|
124
|
-
private void runWithMockClient(Runnable runnable) throws Exception {
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
when(mockFormFields.get(matches("^.*_number$"))).thenReturn(new NumberFieldProperty());
|
130
|
-
AppClient mockAppClient = mock(AppClient.class);
|
131
|
-
when(mockAppClient.getFormFields(eq(0L))).thenReturn(mockFormFields);
|
132
|
-
GetRecordsByCursorResponseBody mockGetRecordsByCursorResponseBody =
|
133
|
-
mock(GetRecordsByCursorResponseBody.class);
|
134
|
-
when(mockGetRecordsByCursorResponseBody.getRecords())
|
135
|
-
.thenReturn(updateRecords.stream().map(this::getRecord).collect(Collectors.toList()));
|
136
|
-
when(mockGetRecordsByCursorResponseBody.hasNext()).thenReturn(false);
|
137
|
-
RecordClient mockRecordClient = mock(RecordClient.class);
|
138
|
-
when(mockRecordClient.createCursor(eq(0L), eq(getFields()), eq(getQuery()))).thenReturn("id");
|
139
|
-
when(mockRecordClient.getRecordsByCursor(eq("id")))
|
140
|
-
.thenReturn(mockGetRecordsByCursorResponseBody);
|
141
|
-
when(mockRecordClient.addRecords(eq(0L), anyList())).thenReturn(Collections.emptyList());
|
142
|
-
when(mockRecordClient.updateRecords(eq(0L), anyList())).thenReturn(Collections.emptyList());
|
143
|
-
KintoneClient mockKintoneClient = mock(KintoneClient.class);
|
144
|
-
when(mockKintoneClient.app()).thenReturn(mockAppClient);
|
145
|
-
when(mockKintoneClient.record()).thenReturn(mockRecordClient);
|
146
|
-
KintoneClientBuilder mockKintoneClientBuilder = mock(KintoneClientBuilder.class);
|
147
|
-
when(mockKintoneClientBuilder.authByApiToken(eq("token"))).thenReturn(mockKintoneClientBuilder);
|
148
|
-
when(mockKintoneClientBuilder.build()).thenReturn(mockKintoneClient);
|
149
|
-
try (MockedStatic<KintoneClientBuilder> mocked = mockStatic(KintoneClientBuilder.class)) {
|
150
|
-
mocked
|
151
|
-
.when(() -> KintoneClientBuilder.create(String.format("https://%s", domain)))
|
152
|
-
.thenReturn(mockKintoneClientBuilder);
|
153
|
-
runnable.run();
|
154
|
-
}
|
120
|
+
private void runWithMockClient(MockClient.Runnable runnable) throws Exception {
|
121
|
+
assertValues(domain, getValues(), sorted(values));
|
122
|
+
MockClient mockClient = new MockClient(domain, getRecords(), getFields(), getQuery());
|
123
|
+
RecordClient mockRecordClient = mockClient.getMockRecordClient();
|
124
|
+
mockClient.run(runnable);
|
155
125
|
@SuppressWarnings("unchecked")
|
156
126
|
ArgumentCaptor<List<Record>> addRecordsArgumentCaptor = ArgumentCaptor.forClass(List.class);
|
157
127
|
verify(mockRecordClient, atLeast(0)).addRecords(eq(0L), addRecordsArgumentCaptor.capture());
|
@@ -174,8 +144,40 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
174
144
|
updateRecords);
|
175
145
|
}
|
176
146
|
|
147
|
+
private List<String> getValues() {
|
148
|
+
if (values.isEmpty() || updateRecords.isEmpty()) {
|
149
|
+
return values;
|
150
|
+
}
|
151
|
+
Function<FieldValue, StringValue> toValue =
|
152
|
+
value ->
|
153
|
+
field.matches("^.*_number$")
|
154
|
+
? ValueFactory.newString(((NumberFieldValue) value).getValue().toPlainString())
|
155
|
+
: ValueFactory.newString(((SingleLineTextFieldValue) value).getValue());
|
156
|
+
Function<Record, String> toJson =
|
157
|
+
record ->
|
158
|
+
Id.FIELD.equals(field)
|
159
|
+
? ValueFactory.newString(record.getId().toString()).toJson()
|
160
|
+
: toValue.apply(record.getFieldValue(field)).toJson();
|
161
|
+
List<String> values = getRecords().stream().map(toJson).collect(Collectors.toList());
|
162
|
+
values.addAll(addValues);
|
163
|
+
return sorted(values);
|
164
|
+
}
|
165
|
+
|
166
|
+
private List<Record> getRecords() {
|
167
|
+
return updateRecords.stream().map(this::getRecord).collect(Collectors.toList());
|
168
|
+
}
|
169
|
+
|
177
170
|
private Record getRecord(RecordForUpdate updateRecord) {
|
171
|
+
Long id = updateRecord.getId();
|
178
172
|
UpdateKey key = updateRecord.getUpdateKey();
|
173
|
+
return id != null ? getRecord(id) : getRecord(key);
|
174
|
+
}
|
175
|
+
|
176
|
+
private Record getRecord(Long id) {
|
177
|
+
return new Record(id, null);
|
178
|
+
}
|
179
|
+
|
180
|
+
private Record getRecord(UpdateKey key) {
|
179
181
|
String field = key.getField();
|
180
182
|
Object value = key.getValue();
|
181
183
|
return new Record()
|
@@ -194,6 +196,18 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
194
196
|
return String.format("%s in (%s)", field, String.join(",", values));
|
195
197
|
}
|
196
198
|
|
199
|
+
private static void assertValues(String domain, List<String> actual, List<String> expected) {
|
200
|
+
assertThat(domain, actual.size(), is(expected.size()));
|
201
|
+
// spotless:off
|
202
|
+
IntStream.range(0, actual.size()).forEach(index -> assertValue(domain, index, actual.get(index), expected.get(index)));
|
203
|
+
// spotless:on
|
204
|
+
}
|
205
|
+
|
206
|
+
private static void assertValue(String domain, int index, String actual, String expected) {
|
207
|
+
String reason = String.format("%s:%d", domain, index);
|
208
|
+
assertThat(reason, actual, is(expected));
|
209
|
+
}
|
210
|
+
|
197
211
|
private static void assertRecords(String domain, List<Record> actual, List<Record> expected) {
|
198
212
|
assertThat(domain, actual.size(), is(expected.size()));
|
199
213
|
// spotless:off
|
@@ -245,20 +259,32 @@ public class KintonePageOutputVerifier implements TransactionalPageOutput {
|
|
245
259
|
private static void assertRecordForUpdate(
|
246
260
|
String domain, int index, RecordForUpdate actual, RecordForUpdate expected) {
|
247
261
|
String reason = String.format("%s:%d", domain, index);
|
248
|
-
|
249
|
-
assertUpdateKey(domain, index, actual
|
262
|
+
assertId(domain, index, actual, expected);
|
263
|
+
assertUpdateKey(domain, index, actual, expected);
|
250
264
|
assertRecord(domain, index, actual.getRecord(), expected.getRecord());
|
251
265
|
assertThat(reason, actual.getRevision(), is(expected.getRevision()));
|
252
266
|
}
|
253
267
|
|
268
|
+
private static void assertId(
|
269
|
+
String domain, int index, RecordForUpdate actual, RecordForUpdate expected) {
|
270
|
+
if (actual.getUpdateKey() != null && expected.getUpdateKey() != null) {
|
271
|
+
return;
|
272
|
+
}
|
273
|
+
String reason = String.format("%s:%d", domain, index);
|
274
|
+
assertThat(reason, actual.getId(), is(expected.getId()));
|
275
|
+
}
|
276
|
+
|
254
277
|
private static void assertUpdateKey(
|
255
|
-
String domain, int index,
|
278
|
+
String domain, int index, RecordForUpdate actual, RecordForUpdate expected) {
|
279
|
+
if (actual.getId() != null && expected.getId() != null) {
|
280
|
+
return;
|
281
|
+
}
|
256
282
|
String reason = String.format("%s:%d", domain, index);
|
257
|
-
assertThat(reason, actual.getField(), is(expected.getField()));
|
258
|
-
assertThat(reason, actual.getValue(), is(expected.getValue()));
|
283
|
+
assertThat(reason, actual.getUpdateKey().getField(), is(expected.getUpdateKey().getField()));
|
284
|
+
assertThat(reason, actual.getUpdateKey().getValue(), is(expected.getUpdateKey().getValue()));
|
259
285
|
}
|
260
286
|
|
261
|
-
|
262
|
-
|
287
|
+
private static <T> List<T> sorted(List<T> list) {
|
288
|
+
return list.stream().sorted().collect(Collectors.toList());
|
263
289
|
}
|
264
290
|
}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
package org.embulk.output.kintone;
|
2
|
+
|
3
|
+
import static org.mockito.ArgumentMatchers.anyList;
|
4
|
+
import static org.mockito.ArgumentMatchers.eq;
|
5
|
+
import static org.mockito.ArgumentMatchers.matches;
|
6
|
+
import static org.mockito.Mockito.mock;
|
7
|
+
import static org.mockito.Mockito.mockStatic;
|
8
|
+
import static org.mockito.Mockito.when;
|
9
|
+
|
10
|
+
import com.kintone.client.AppClient;
|
11
|
+
import com.kintone.client.KintoneClient;
|
12
|
+
import com.kintone.client.KintoneClientBuilder;
|
13
|
+
import com.kintone.client.RecordClient;
|
14
|
+
import com.kintone.client.api.record.GetRecordsByCursorResponseBody;
|
15
|
+
import com.kintone.client.model.app.field.CheckBoxFieldProperty;
|
16
|
+
import com.kintone.client.model.app.field.DateFieldProperty;
|
17
|
+
import com.kintone.client.model.app.field.DateTimeFieldProperty;
|
18
|
+
import com.kintone.client.model.app.field.DropDownFieldProperty;
|
19
|
+
import com.kintone.client.model.app.field.FieldProperty;
|
20
|
+
import com.kintone.client.model.app.field.FileFieldProperty;
|
21
|
+
import com.kintone.client.model.app.field.GroupSelectFieldProperty;
|
22
|
+
import com.kintone.client.model.app.field.LinkFieldProperty;
|
23
|
+
import com.kintone.client.model.app.field.MultiLineTextFieldProperty;
|
24
|
+
import com.kintone.client.model.app.field.MultiSelectFieldProperty;
|
25
|
+
import com.kintone.client.model.app.field.NumberFieldProperty;
|
26
|
+
import com.kintone.client.model.app.field.OrganizationSelectFieldProperty;
|
27
|
+
import com.kintone.client.model.app.field.RadioButtonFieldProperty;
|
28
|
+
import com.kintone.client.model.app.field.RichTextFieldProperty;
|
29
|
+
import com.kintone.client.model.app.field.SingleLineTextFieldProperty;
|
30
|
+
import com.kintone.client.model.app.field.SubtableFieldProperty;
|
31
|
+
import com.kintone.client.model.app.field.TimeFieldProperty;
|
32
|
+
import com.kintone.client.model.app.field.UserSelectFieldProperty;
|
33
|
+
import com.kintone.client.model.record.Record;
|
34
|
+
import java.util.Collections;
|
35
|
+
import java.util.List;
|
36
|
+
import java.util.Map;
|
37
|
+
import org.mockito.MockedStatic;
|
38
|
+
|
39
|
+
public class MockClient {
|
40
|
+
private final String domain;
|
41
|
+
private final List<Record> records;
|
42
|
+
private final List<String> fields;
|
43
|
+
private final String query;
|
44
|
+
private final RecordClient mockRecordClient;
|
45
|
+
|
46
|
+
public MockClient(String domain, List<Record> records, List<String> fields, String query) {
|
47
|
+
this.domain = domain;
|
48
|
+
this.records = records;
|
49
|
+
this.fields = fields;
|
50
|
+
this.query = query;
|
51
|
+
mockRecordClient = mock(RecordClient.class);
|
52
|
+
}
|
53
|
+
|
54
|
+
public RecordClient getMockRecordClient() {
|
55
|
+
return mockRecordClient;
|
56
|
+
}
|
57
|
+
|
58
|
+
public void run(Runnable runnable) throws Exception {
|
59
|
+
@SuppressWarnings("unchecked")
|
60
|
+
Map<String, FieldProperty> mockFormFields = mock(Map.class);
|
61
|
+
when(mockFormFields.get(matches("^.*_single_line_text$")))
|
62
|
+
.thenReturn(new SingleLineTextFieldProperty());
|
63
|
+
when(mockFormFields.get(matches("^.*_multi_line_text$")))
|
64
|
+
.thenReturn(new MultiLineTextFieldProperty());
|
65
|
+
when(mockFormFields.get(matches("^.*_rich_text$"))).thenReturn(new RichTextFieldProperty());
|
66
|
+
when(mockFormFields.get(matches("^.*_number$"))).thenReturn(new NumberFieldProperty());
|
67
|
+
when(mockFormFields.get(matches("^.*_check_box$"))).thenReturn(new CheckBoxFieldProperty());
|
68
|
+
when(mockFormFields.get(matches("^.*_radio_button$")))
|
69
|
+
.thenReturn(new RadioButtonFieldProperty());
|
70
|
+
when(mockFormFields.get(matches("^.*_multi_select$")))
|
71
|
+
.thenReturn(new MultiSelectFieldProperty());
|
72
|
+
when(mockFormFields.get(matches("^.*_drop_down$"))).thenReturn(new DropDownFieldProperty());
|
73
|
+
when(mockFormFields.get(matches("^.*_user_select$"))).thenReturn(new UserSelectFieldProperty());
|
74
|
+
when(mockFormFields.get(matches("^.*_organization_select$")))
|
75
|
+
.thenReturn(new OrganizationSelectFieldProperty());
|
76
|
+
when(mockFormFields.get(matches("^.*_group_select$")))
|
77
|
+
.thenReturn(new GroupSelectFieldProperty());
|
78
|
+
when(mockFormFields.get(matches("^.*_date$"))).thenReturn(new DateFieldProperty());
|
79
|
+
when(mockFormFields.get(matches("^.*_time$"))).thenReturn(new TimeFieldProperty());
|
80
|
+
when(mockFormFields.get(matches("^.*_datetime$"))).thenReturn(new DateTimeFieldProperty());
|
81
|
+
when(mockFormFields.get(matches("^.*_link$"))).thenReturn(new LinkFieldProperty());
|
82
|
+
when(mockFormFields.get(matches("^.*_file$"))).thenReturn(new FileFieldProperty());
|
83
|
+
when(mockFormFields.get(matches("^.*_subtable$"))).thenReturn(new SubtableFieldProperty());
|
84
|
+
AppClient mockAppClient = mock(AppClient.class);
|
85
|
+
when(mockAppClient.getFormFields(eq(0L))).thenReturn(mockFormFields);
|
86
|
+
GetRecordsByCursorResponseBody mockGetRecordsByCursorResponseBody =
|
87
|
+
mock(GetRecordsByCursorResponseBody.class);
|
88
|
+
when(mockGetRecordsByCursorResponseBody.getRecords()).thenReturn(records);
|
89
|
+
when(mockGetRecordsByCursorResponseBody.hasNext()).thenReturn(false);
|
90
|
+
when(mockRecordClient.createCursor(eq(0L), eq(fields), eq(query))).thenReturn("id");
|
91
|
+
when(mockRecordClient.getRecordsByCursor(eq("id")))
|
92
|
+
.thenReturn(mockGetRecordsByCursorResponseBody);
|
93
|
+
when(mockRecordClient.addRecords(eq(0L), anyList())).thenReturn(Collections.emptyList());
|
94
|
+
when(mockRecordClient.updateRecords(eq(0L), anyList())).thenReturn(Collections.emptyList());
|
95
|
+
com.kintone.client.KintoneClient mockKintoneClient = mock(KintoneClient.class);
|
96
|
+
when(mockKintoneClient.app()).thenReturn(mockAppClient);
|
97
|
+
when(mockKintoneClient.record()).thenReturn(mockRecordClient);
|
98
|
+
KintoneClientBuilder mockKintoneClientBuilder = mock(KintoneClientBuilder.class);
|
99
|
+
when(mockKintoneClientBuilder.authByApiToken(eq("token"))).thenReturn(mockKintoneClientBuilder);
|
100
|
+
when(mockKintoneClientBuilder.build()).thenReturn(mockKintoneClient);
|
101
|
+
try (MockedStatic<KintoneClientBuilder> mocked = mockStatic(KintoneClientBuilder.class)) {
|
102
|
+
mocked
|
103
|
+
.when(() -> KintoneClientBuilder.create(String.format("https://%s", domain)))
|
104
|
+
.thenReturn(mockKintoneClientBuilder);
|
105
|
+
runnable.run();
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
public interface Runnable {
|
110
|
+
void run() throws Exception;
|
111
|
+
}
|
112
|
+
}
|