From 3feb3b7788c4672502930077d9fdeae5c2edebe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20Guti=C3=A9rrez?= Date: Wed, 21 Aug 2019 09:42:14 +0200 Subject: [PATCH] Add a regression test and fix by catching the NPE (#790) --- .../briefcase/export/FormDefinition.java | 6 +- ...ListWithRelativePredicateInRepeatTest.java | 26 +++++ ...edicate-relative-repeat-group.csv.expected | 2 + ...s-predicate-relative-repeat-submission.xml | 9 ++ ...sts-predicate-relative-repeat.csv.expected | 2 + ...choice-lists-predicate-relative-repeat.xml | 95 +++++++++++++++++++ 6 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 test/java/org/opendatakit/briefcase/export/ExportToCsvExplodeChoiceListWithRelativePredicateInRepeatTest.java create mode 100644 test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat-group.csv.expected create mode 100644 test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat-submission.xml create mode 100644 test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat.csv.expected create mode 100644 test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat.xml diff --git a/src/org/opendatakit/briefcase/export/FormDefinition.java b/src/org/opendatakit/briefcase/export/FormDefinition.java index a0109fe05..430e75ccf 100644 --- a/src/org/opendatakit/briefcase/export/FormDefinition.java +++ b/src/org/opendatakit/briefcase/export/FormDefinition.java @@ -163,7 +163,11 @@ private static Map getFormControls(FormDef formDef) { // Populate choices of any control using a secondary // instance that is not external if (secondaryInstance != null && !(secondaryInstance instanceof ExternalDataInstance)) - formDef.populateDynamicChoices(itemsetBinding, (TreeReference) control.getBind().getReference()); + try { + formDef.populateDynamicChoices(itemsetBinding, (TreeReference) control.getBind().getReference()); + } catch (NullPointerException e) { + // Ignore (see https://github.com/opendatakit/briefcase/issues/789) + } } }) .collect(toMap(FormDefinition::controlFqn, e -> e)); diff --git a/test/java/org/opendatakit/briefcase/export/ExportToCsvExplodeChoiceListWithRelativePredicateInRepeatTest.java b/test/java/org/opendatakit/briefcase/export/ExportToCsvExplodeChoiceListWithRelativePredicateInRepeatTest.java new file mode 100644 index 000000000..b28128278 --- /dev/null +++ b/test/java/org/opendatakit/briefcase/export/ExportToCsvExplodeChoiceListWithRelativePredicateInRepeatTest.java @@ -0,0 +1,26 @@ +package org.opendatakit.briefcase.export; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class ExportToCsvExplodeChoiceListWithRelativePredicateInRepeatTest { + private ExportToCsvScenario scenario; + + @Before + public void setUp() { + scenario = ExportToCsvScenario.setUp("choice-lists-predicate-relative-repeat"); + } + + @After + public void tearDown() { + scenario.tearDown(); + } + + @Test + public void exports_forms_with_all_data_types() { + scenario.runExportExplodedChoiceLists(); + scenario.assertSameContent(); + scenario.assertSameContentRepeats("", "group"); + } +} diff --git a/test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat-group.csv.expected b/test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat-group.csv.expected new file mode 100644 index 000000000..131a9cb97 --- /dev/null +++ b/test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat-group.csv.expected @@ -0,0 +1,2 @@ +category,item,PARENT_KEY,KEY,SET-OF-group +1,1,uuid:a21ca0ad-db7e-4ef5-b7ea-d73dd4a42bf0,uuid:a21ca0ad-db7e-4ef5-b7ea-d73dd4a42bf0/group[1],uuid:a21ca0ad-db7e-4ef5-b7ea-d73dd4a42bf0/group diff --git a/test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat-submission.xml b/test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat-submission.xml new file mode 100644 index 000000000..2f5c0671e --- /dev/null +++ b/test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat-submission.xml @@ -0,0 +1,9 @@ + + + 1 + 1 + + + uuid:a21ca0ad-db7e-4ef5-b7ea-d73dd4a42bf0 + + diff --git a/test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat.csv.expected b/test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat.csv.expected new file mode 100644 index 000000000..60af42acc --- /dev/null +++ b/test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat.csv.expected @@ -0,0 +1,2 @@ +SubmissionDate,SET-OF-group,meta-instanceID,KEY +"Mar 17, 2019 10:14:18 AM",uuid:a21ca0ad-db7e-4ef5-b7ea-d73dd4a42bf0/group,uuid:a21ca0ad-db7e-4ef5-b7ea-d73dd4a42bf0,uuid:a21ca0ad-db7e-4ef5-b7ea-d73dd4a42bf0 diff --git a/test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat.xml b/test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat.xml new file mode 100644 index 000000000..43fc655df --- /dev/null +++ b/test/resources/org/opendatakit/briefcase/export/choice-lists-predicate-relative-repeat.xml @@ -0,0 +1,95 @@ + + + + Populate dynamic choices in repeat groups with relative paths + + + + + + + + + + + + + + + + 1 + 1 + + + 2 + 1 + + + 3 + 1 + + + 4 + 1 + + + 5 + 2 + + + 6 + 2 + + + 7 + 2 + + + 8 + 3 + + + 9 + 3 + + + 10 + 3 + + + + + + + + + + + + + + + + + 1 + + + + 2 + + + + 3 + + + + + + + + + + + +