Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Add a regression test and fix by catching the NPE (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggalmazor authored Aug 21, 2019
1 parent 7b8bca9 commit 3feb3b7
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/org/opendatakit/briefcase/export/FormDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ private static Map<String, QuestionDef> 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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<data id="choice-lists-predicate-relative-repeat" instanceID="uuid:a21ca0ad-db7e-4ef5-b7ea-d73dd4a42bf0" submissionDate="2019-03-17T10:14:18.820Z" isComplete="true" markedAsCompleteDate="2019-03-17T10:14:18.820Z" xmlns="http://opendatakit.org/submissions">
<group>
<category>1</category>
<item>1</item>
</group>
<n0:meta xmlns:n0="http://openrosa.org/xforms">
<n0:instanceID>uuid:a21ca0ad-db7e-4ef5-b7ea-d73dd4a42bf0</n0:instanceID>
</n0:meta>
</data>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa">
<h:head>
<h:title>Populate dynamic choices in repeat groups with relative paths</h:title>
<model>
<instance>
<data id="choice-lists-predicate-relative-repeat">
<group jr:template="">
<category/>
<item/>
</group>
<meta>
<instanceID/>
</meta>
</data>
</instance>
<instance id="items">
<root>
<item>
<name>1</name>
<category>1</category>
</item>
<item>
<name>2</name>
<category>1</category>
</item>
<item>
<name>3</name>
<category>1</category>
</item>
<item>
<name>4</name>
<category>1</category>
</item>
<item>
<name>5</name>
<category>2</category>
</item>
<item>
<name>6</name>
<category>2</category>
</item>
<item>
<name>7</name>
<category>2</category>
</item>
<item>
<name>8</name>
<category>3</category>
</item>
<item>
<name>9</name>
<category>3</category>
</item>
<item>
<name>10</name>
<category>3</category>
</item>
</root>
</instance>
<bind nodeset="/data/group/category" required="true()" type="select1"/>
<bind nodeset="/data/group/item" required="true()" type="select1"/>
<bind nodeset="/data/meta/instanceID" jr:preload="uid" readonly="true()" type="string"/>
</model>
</h:head>
<h:body>
<group ref="/data/group">
<label>Repeat group</label>
<repeat nodeset="/data/group">
<select1 ref="/data/group/category">
<label>Category</label>
<item>
<label>1</label>
<value>1</value>
</item>
<item>
<label>2</label>
<value>2</value>
</item>
<item>
<label>3</label>
<value>3</value>
</item>
</select1>
<select1 ref="/data/group/item">
<label>Item</label>
<itemset nodeset="instance('items')/root/item[category= current()/../category ]">
<value ref="name"/>
<label ref="name"/>
</itemset>
</select1>
</repeat>
</group>
</h:body>
</h:html>

0 comments on commit 3feb3b7

Please sign in to comment.