Skip to content

Commit

Permalink
test(data): add test on json to xml data conversion
Browse files Browse the repository at this point in the history
For a weird case in pairwise data.
  • Loading branch information
nsenave committed Dec 10, 2024
1 parent af23edf commit b2ae7e5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@

<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-matchers</artifactId>
<artifactId>xmlunit-assertj3</artifactId>
<version>2.10.0</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package fr.insee.lunatic.conversion.data;

import org.junit.jupiter.api.Test;
import org.xmlunit.assertj3.XmlAssert;

class JsonToXmlDataTest {

/**
* Lunatic bug: in some cases pairwise data can be inconsistent.
* Yet the data conversion shouldn't fail so as not to break the data extraction of client collection tools
* that uses the json to xml conversion.
*/
@Test
void convertInconsistentPairwiseData() throws Exception {
// Given
String jsonInconsistentData = """
{
"COLLECTED": {
"LIENS_MISSING": {
"COLLECTED": [
null,
[null, null]
]
}
},
"CALCULATED": {},
"EXTERNAL": {
"FOO_EXTERNAL": "some value"
}
}""";
// When
JSONLunaticDataToXML converter = new JSONLunaticDataToXML();
String result = converter.transform(jsonInconsistentData);
// Then
String expected = """
<?xml version="1.0" encoding="UTF-8"?>
<Data>
<COLLECTED>
<LIENS_MISSING>
<COLLECTED>
<COLLECTED type="null"/>
<COLLECTED>
<COLLECTED type="null"/>
<COLLECTED type="null"/>
</COLLECTED>
</COLLECTED>
</LIENS_MISSING>
</COLLECTED>
<CALCULATED/>
<EXTERNAL>
<FOO_EXTERNAL type="string">some value</FOO_EXTERNAL>
</EXTERNAL>
</Data>
""";
XmlAssert.assertThat(expected).and(result).ignoreWhitespace().areIdentical();
}

}

0 comments on commit b2ae7e5

Please sign in to comment.