Skip to content

Commit 018e718

Browse files
authored
fix: choiceType response in question (#184)
1 parent aac0dd9 commit 018e718

4 files changed

Lines changed: 30 additions & 21 deletions

File tree

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>fr.insee.pogues</groupId>
66
<artifactId>pogues-model</artifactId>
7-
<version>1.15.0</version>
7+
<version>1.15.1</version>
88
<packaging>jar</packaging>
99

1010
<name>Pogues Model</name>

‎src/main/resources/xsd/Questionnaire.xsd‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,6 @@
244244
</xs:element>
245245
</xs:sequence>
246246
<xs:attribute name="questionType" type="QuestionTypeEnum"/>
247-
<xs:attribute name="choiceType" type="ChoiceTypeEnum" default="CODE_LIST">
248-
<xs:annotation>
249-
<xs:documentation>
250-
choiceType specifies whether the response options are defined by a static
251-
code list (CODE_LIST) or dynamically generated from a collected variable
252-
(VARIABLE). The default value is CODE_LIST.
253-
</xs:documentation>
254-
</xs:annotation>
255-
</xs:attribute>
256247
<xs:attribute name="mandatory" type="xs:boolean">
257248
<xs:annotation>
258249
<xs:documentation>Whether the question is mandatory. Only used by multiple choice question for now:
@@ -664,6 +655,15 @@
664655
to a single response.</xs:documentation>
665656
</xs:annotation>
666657
</xs:attribute>
658+
<xs:attribute name="choiceType" type="ChoiceTypeEnum" default="CODE_LIST">
659+
<xs:annotation>
660+
<xs:documentation>
661+
choiceType specifies whether the response options are defined by a static
662+
code list (CODE_LIST) or dynamically generated from a collected variable
663+
(VARIABLE). The default value is CODE_LIST.
664+
</xs:documentation>
665+
</xs:annotation>
666+
</xs:attribute>
667667
</xs:complexType>
668668

669669
<xs:complexType name="NonResponseModalityType">

‎src/test/java/fr/insee/pogues/test/JSONDeserializerTest.java‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,18 @@ void testChoiceTypeVariableResponses() throws JAXBException {
417417
"Child": [
418418
{
419419
"type": "QuestionType",
420-
"choiceType": "VARIABLE"
420+
"Response": [
421+
{
422+
"choiceType": "VARIABLE"
423+
}
424+
]
421425
}
422426
]
423427
}
424428
""";
425429
JSONDeserializer deserializer = new JSONDeserializer();
426430
Questionnaire questionnaire = deserializer.deserializeString(json);
427-
assertEquals(ChoiceTypeEnum.VARIABLE, ((QuestionType) questionnaire.getChild().getFirst()).getChoiceType());
431+
assertEquals(ChoiceTypeEnum.VARIABLE, ((QuestionType) questionnaire.getChild().getFirst()).getResponse().getFirst().getChoiceType());
428432
}
429433

430434
@Test
@@ -434,15 +438,19 @@ void testChoiceTypeSuggester() throws JAXBException {
434438
"Child": [
435439
{
436440
"type": "QuestionType",
437-
"choiceType": "SUGGESTER"
441+
"Response": [
442+
{
443+
"choiceType": "SUGGESTER"
444+
}
445+
]
438446
}
439447
]
440448
}
441449
""";
442450

443451
JSONDeserializer deserializer = new JSONDeserializer();
444452
Questionnaire questionnaire = deserializer.deserializeString(json);
445-
assertEquals(ChoiceTypeEnum.SUGGESTER, ((QuestionType) questionnaire.getChild().getFirst()).getChoiceType());
453+
assertEquals(ChoiceTypeEnum.SUGGESTER, ((QuestionType) questionnaire.getChild().getFirst()).getResponse().getFirst().getChoiceType());
446454
}
447455

448456
@Test
@@ -451,14 +459,15 @@ void testChoiceTypeDefaultValue() throws JAXBException {
451459
{
452460
"Child": [
453461
{
454-
"type": "QuestionType"
462+
"type": "QuestionType",
463+
"Response": [{}]
455464
}
456465
]
457466
}
458467
""";
459468
JSONDeserializer deserializer = new JSONDeserializer();
460469
Questionnaire questionnaire = deserializer.deserializeString(json);
461-
assertEquals(ChoiceTypeEnum.CODE_LIST, ((QuestionType) questionnaire.getChild().getFirst()).getChoiceType());
470+
assertEquals(ChoiceTypeEnum.CODE_LIST, ((QuestionType) questionnaire.getChild().getFirst()).getResponse().getFirst().getChoiceType());
462471
}
463472

464473
@Test
@@ -508,9 +517,9 @@ void testVariableResponsesFullConfiguration() throws JAXBException {
508517
{
509518
"type": "QuestionType",
510519
"questionType": "SINGLE_CHOICE",
511-
"choiceType": "VARIABLE",
512520
"OptionFilter": "nvl($AGE$, 0) > 18",
513521
"Response": {
522+
"choiceType": "VARIABLE",
514523
"VariableReference": "id-loop-variable"
515524
}
516525
}
@@ -526,7 +535,7 @@ void testVariableResponsesFullConfiguration() throws JAXBException {
526535

527536

528537
assertEquals(QuestionTypeEnum.SINGLE_CHOICE, question.getQuestionType());
529-
assertEquals(ChoiceTypeEnum.VARIABLE, question.getChoiceType());
538+
assertEquals(ChoiceTypeEnum.VARIABLE, question.getResponse().getFirst().getChoiceType());
530539
assertEquals("nvl($AGE$, 0) > 18", question.getOptionFilter());
531540
assertNotNull(question.getResponse());
532541
assertFalse(question.getResponse().isEmpty());

‎src/test/java/fr/insee/pogues/test/JSONSerializerTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,11 @@ void serializePairwiseSourceVariableReferences() throws JAXBException, Unsupport
680680
void testSerializeVariableResponsesFullConfiguration() throws Exception {
681681
QuestionType question = new QuestionType();
682682
question.setQuestionType(QuestionTypeEnum.SINGLE_CHOICE);
683-
question.setChoiceType(ChoiceTypeEnum.VARIABLE);
684683
question.setOptionFilter("nvl($AGE$, 0) > 18");
685684

686685
ResponseType response = new ResponseType();
687686
response.setVariableReference("id-loop-variable");
687+
response.setChoiceType(ChoiceTypeEnum.VARIABLE);
688688

689689
question.getResponse().add(response);
690690

@@ -700,11 +700,11 @@ void testSerializeVariableResponsesFullConfiguration() throws Exception {
700700
{
701701
"type": "QuestionType",
702702
"questionType": "SINGLE_CHOICE",
703-
"choiceType": "VARIABLE",
704703
"OptionFilter": "nvl($AGE$, 0) > 18",
705704
"Response": [
706705
{
707-
"VariableReference": "id-loop-variable"
706+
"VariableReference": "id-loop-variable",
707+
"choiceType": "VARIABLE"
708708
}
709709
]
710710
}

0 commit comments

Comments
 (0)