Skip to content

Commit

Permalink
test: InseeFr/Pogues#660 add test on failing case
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave committed Mar 15, 2023
1 parent 313055c commit 542e315
Show file tree
Hide file tree
Showing 5 changed files with 4,375 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package fr.insee.pogues.transforms.visualize;

import fr.insee.pogues.conversion.JSONDeserializer;
import fr.insee.pogues.conversion.JSONSerializer;
import fr.insee.pogues.conversion.XMLSerializer;
import fr.insee.pogues.model.ComponentType;
import fr.insee.pogues.model.FlowControlType;
import fr.insee.pogues.model.Questionnaire;
Expand All @@ -9,6 +12,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.io.ByteArrayInputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -79,4 +83,59 @@ void testJsonQuestionnaireComposition() throws Exception {
assertEquals(filteredReferenceEndMember, flowControlType.getIfTrue().split("-")[1]);
}

/**
* Deserialization issue on the output questionnaire after composition in this case.
* The reason has not been identified yet.
*/
@Test
void testJsonQuestionnaireComposition_issue() throws Exception {
// Given
String testRelativePath = "transforms/PoguesJSONToPoguesJSONDeref/translation_issue";
// Load test questionnaire into json objects
ClassLoader classLoader = this.getClass().getClassLoader();
URL url1 = classLoader.getResource(testRelativePath+"/referenced1.json");
URL url2 = classLoader.getResource(testRelativePath+"/referenced2.json");
assert url1 != null;
assert url2 != null;
JSONParser jsonParser = new JSONParser();
JSONObject jsonQuestionnaire1 = (JSONObject) jsonParser.parse(Files.readString(Path.of(url1.toURI())));
JSONObject jsonQuestionnaire2 = (JSONObject) jsonParser.parse(Files.readString(Path.of(url2.toURI())));
// Mock questionnaire service
QuestionnairesService questionnairesService = Mockito.mock(QuestionnairesService.class);
Mockito.when(questionnairesService.getQuestionnaireByID("le2v7xet")).thenReturn(jsonQuestionnaire1);
Mockito.when(questionnairesService.getQuestionnaireByID("le8ffc6k")).thenReturn(jsonQuestionnaire2);
// Read tested questionnaire
URL url = classLoader.getResource(testRelativePath+"/reference.json");
assert url != null;
String testedInput = Files.readString(Path.of(url.toURI()));

// When
// Apply de-referencing service
PoguesJSONToPoguesJSONDerefImpl deref = new PoguesJSONToPoguesJSONDerefImpl(questionnairesService);
Questionnaire outQuestionnaire = deref.transformAsQuestionnaire(testedInput);

// Then
assertNotNull(outQuestionnaire);
// (Temp)
Path testFolder = Path.of("src/test/resources/"+testRelativePath);
//
JSONSerializer jsonSerializer = new JSONSerializer();
String resJson = jsonSerializer.serialize(outQuestionnaire);
Files.writeString(testFolder.resolve("out/result.json"), resJson);
//
XMLSerializer xmlSerializer = new XMLSerializer();
String resXml = xmlSerializer.serialize(outQuestionnaire);
Files.writeString(testFolder.resolve("out/result.xml"), resXml);
//
PoguesJSONToPoguesXMLImpl poguesJSONToPoguesXML = new PoguesJSONToPoguesXMLImpl();
String resXmlFromJson = poguesJSONToPoguesXML.transform(new ByteArrayInputStream(resJson.getBytes()), null, null);
Files.writeString(testFolder.resolve("out/result_from_json.xml"), resXmlFromJson);
//
JSONDeserializer jsonDeserializer = new JSONDeserializer();
Questionnaire questionnaireFromJson = jsonDeserializer.deserialize(
testFolder.resolve("out/result.json").toAbsolutePath().toString());
String resXmlFromObjectFromJson = xmlSerializer.serialize(questionnaireFromJson);
Files.writeString(testFolder.resolve("out/result_from_object_from_json.xml"), resXmlFromObjectFromJson);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"owner": "FAKEPERMISSION",
"FlowControl": [],
"ComponentGroup": [
{
"MemberReference": [
"lepvg4hm",
"lepv3wix",
"le2v7xet",
"idendquest",
"le8ffc6k"
],
"Label": [
"Components for page 1"
],
"id": "lepvhvq0",
"Name": "PAGE_1"
}
],
"agency": "fr.insee",
"genericName": "QUESTIONNAIRE",
"Label": [
"Test Romain"
],
"childQuestionnaireRef": [
"le2v7xet",
"le8ffc6k"
],
"Name": "TESTROMAIN",
"Variables": {
"Variable": [
{
"Label": "Q1 label",
"id": "lepv5jud",
"type": "CollectedVariableType",
"Name": "Q1",
"Datatype": {
"Pattern": "",
"typeName": "TEXT",
"type": "TextDatatypeType",
"MaxLength": 249
}
}
]
},
"lastUpdatedDate": "Wed Mar 01 2023 16:59:15 GMT+0100 (heure normale d’Europe centrale)",
"DataCollection": [
{
"id": "d5225468-f2c0-4a1b-a662-7b892d9bd734",
"uri": "http://ddi:fr.insee:DataCollection.d5225468-f2c0-4a1b-a662-7b892d9bd734",
"Name": "Investissements et depenses courantes pour proteger l'environnement 2016"
}
],
"final": false,
"flowLogic": "FILTER",
"id": "lepv605i",
"TargetMode": [
"CAPI",
"CATI",
"CAWI",
"PAPI"
],
"CodeLists": {
"CodeList": []
},
"formulasLanguage": "VTL",
"Child": [
{
"Control": [],
"depth": 1,
"FlowControl": [],
"genericName": "MODULE",
"Label": [
"S1"
],
"id": "lepvg4hm",
"TargetMode": [
"CAPI",
"CATI",
"CAWI",
"PAPI"
],
"Declaration": [],
"type": "SequenceType",
"Child": [
{
"Response": [
{
"CollectedVariableReference": "lepv5jud",
"id": "lepvabpu",
"mandatory": false,
"Datatype": {
"Pattern": "",
"typeName": "TEXT",
"type": "TextDatatypeType",
"MaxLength": 249
}
}
],
"Control": [],
"depth": 2,
"FlowControl": [],
"Label": [
"\"Q1\""
],
"id": "lepv3wix",
"TargetMode": [
"CAPI",
"CATI",
"CAWI",
"PAPI"
],
"Declaration": [],
"type": "QuestionType",
"questionType": "SIMPLE",
"Name": "Q1"
}
],
"Name": "S1"
},
{
"Control": [],
"depth": 1,
"FlowControl": [],
"genericName": "EXTERNAL_ELEMENT",
"Label": [
"TCM_DL_Description du logement"
],
"id": "le2v7xet",
"TargetMode": [
""
],
"Declaration": [],
"type": "SequenceType",
"Child": [],
"Name": "TCM_DL_DES"
},
{
"Control": [],
"depth": 1,
"FlowControl": [],
"genericName": "EXTERNAL_ELEMENT",
"Label": [
"L120 - TCM transversal - Enfants de parents séparés"
],
"id": "le8ffc6k",
"TargetMode": [
""
],
"Declaration": [],
"type": "SequenceType",
"Child": [],
"Name": "L120TCMTRA"
},
{
"Control": [],
"depth": 1,
"FlowControl": [],
"genericName": "MODULE",
"Label": [
"QUESTIONNAIRE_END"
],
"id": "idendquest",
"TargetMode": [
"CAPI",
"CATI",
"CAWI",
"PAPI"
],
"Declaration": [],
"type": "SequenceType",
"Child": [],
"Name": "QUESTIONNAIRE_END"
}
]
}
Loading

0 comments on commit 542e315

Please sign in to comment.