-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(pairwise): integration test ddi to lunatic
- Loading branch information
Showing
6 changed files
with
1,343 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
eno-core/src/test/java/fr/insee/eno/core/mapping/in/ddi/PairwiseQuestionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package fr.insee.eno.core.mapping.in.ddi; | ||
|
||
import fr.insee.eno.core.exceptions.business.DDIParsingException; | ||
import fr.insee.eno.core.mappers.DDIMapper; | ||
import fr.insee.eno.core.model.EnoQuestionnaire; | ||
import fr.insee.eno.core.model.question.PairwiseQuestion; | ||
import fr.insee.eno.core.model.question.UniqueChoiceQuestion; | ||
import fr.insee.eno.core.serialize.DDIDeserializer; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class PairwiseQuestionTest { | ||
|
||
@Test | ||
void integrationTest_pairwise() throws DDIParsingException { | ||
// Given & When | ||
EnoQuestionnaire enoQuestionnaire = new EnoQuestionnaire(); | ||
DDIMapper ddiMapper = new DDIMapper(); | ||
ddiMapper.mapDDI( | ||
DDIDeserializer.deserialize(this.getClass().getClassLoader().getResourceAsStream( | ||
"integration/ddi/ddi-pairwise.xml")), | ||
enoQuestionnaire); | ||
|
||
// Then | ||
Optional<PairwiseQuestion> searchedPairwiseQuestion = enoQuestionnaire.getSingleResponseQuestions().stream() | ||
.filter(PairwiseQuestion.class::isInstance) | ||
.map(PairwiseQuestion.class::cast) | ||
.findAny(); | ||
assertTrue(searchedPairwiseQuestion.isPresent()); | ||
// | ||
PairwiseQuestion pairwiseQuestion = searchedPairwiseQuestion.get(); | ||
assertEquals("lo9tyy1v", pairwiseQuestion.getId()); | ||
assertEquals("PAIRWISE_QUESTION", pairwiseQuestion.getName()); | ||
assertNull(pairwiseQuestion.getResponse()); | ||
assertEquals("PAIRWISE_SOURCE", pairwiseQuestion.getLoopVariableName()); | ||
assertEquals(1, pairwiseQuestion.getUniqueChoiceQuestions().size()); | ||
// | ||
UniqueChoiceQuestion pairwiseUCQ = pairwiseQuestion.getUniqueChoiceQuestions().get(0); | ||
assertEquals("lo9tyy1v-pairwise-dropdown", pairwiseUCQ.getId()); | ||
assertEquals("PAIRWISE_QUESTION", pairwiseUCQ.getName()); | ||
assertEquals("PAIRWISE_QUESTION", pairwiseUCQ.getResponse().getVariableName()); | ||
assertEquals(UniqueChoiceQuestion.DisplayFormat.DROPDOWN, pairwiseUCQ.getDisplayFormat()); | ||
assertEquals("lo9tv7s6", pairwiseUCQ.getCodeListReference()); | ||
} | ||
|
||
} |
74 changes: 61 additions & 13 deletions
74
eno-core/src/test/java/fr/insee/eno/core/mapping/out/lunatic/PairwiseQuestionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,80 @@ | ||
package fr.insee.eno.core.mapping.out.lunatic; | ||
|
||
import fr.insee.eno.core.Constant; | ||
import fr.insee.eno.core.DDIToEno; | ||
import fr.insee.eno.core.exceptions.business.DDIParsingException; | ||
import fr.insee.eno.core.mappers.LunaticMapper; | ||
import fr.insee.eno.core.model.EnoQuestionnaire; | ||
import fr.insee.eno.core.model.question.PairwiseQuestion; | ||
import fr.insee.lunatic.model.flat.ComponentTypeEnum; | ||
import fr.insee.lunatic.model.flat.PairwiseLinks; | ||
import fr.insee.eno.core.parameter.EnoParameters; | ||
import fr.insee.lunatic.model.flat.*; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class PairwiseQuestionTest { | ||
|
||
private PairwiseQuestion enoPairwiseQuestion; | ||
private PairwiseLinks lunaticPairwiseLinks; | ||
@Nested | ||
class UnitTestsPairwise { | ||
private PairwiseQuestion enoPairwiseQuestion; | ||
private PairwiseLinks lunaticPairwiseLinks; | ||
|
||
@BeforeEach | ||
void pairwiseObjects() { | ||
enoPairwiseQuestion = new PairwiseQuestion(); | ||
lunaticPairwiseLinks = new PairwiseLinks(); | ||
} | ||
|
||
@BeforeEach | ||
void pairwiseObjects() { | ||
enoPairwiseQuestion = new PairwiseQuestion(); | ||
lunaticPairwiseLinks = new PairwiseLinks(); | ||
@Test | ||
void lunaticComponentType() { | ||
// | ||
LunaticMapper lunaticMapper = new LunaticMapper(); | ||
lunaticMapper.mapEnoObject(enoPairwiseQuestion, lunaticPairwiseLinks); | ||
// | ||
assertEquals(ComponentTypeEnum.PAIRWISE_LINKS, lunaticPairwiseLinks.getComponentType()); | ||
} | ||
} | ||
|
||
@Test | ||
void lunaticComponentType() { | ||
// | ||
void pairwiseMapping_integrationTest() throws DDIParsingException { | ||
// Given | ||
EnoQuestionnaire enoQuestionnaire = DDIToEno.transform( | ||
this.getClass().getClassLoader().getResourceAsStream("integration/ddi/ddi-pairwise.xml"), | ||
EnoParameters.of(EnoParameters.Context.HOUSEHOLD, EnoParameters.ModeParameter.CAWI)); | ||
Optional<PairwiseQuestion> enoPairwise = enoQuestionnaire.getSingleResponseQuestions().stream() | ||
.filter(PairwiseQuestion.class::isInstance) | ||
.map(PairwiseQuestion.class::cast) | ||
.findAny(); | ||
assert enoPairwise.isPresent(); | ||
|
||
// When | ||
PairwiseLinks lunaticPairwise = new PairwiseLinks(); | ||
LunaticMapper lunaticMapper = new LunaticMapper(); | ||
lunaticMapper.mapEnoObject(enoPairwiseQuestion, lunaticPairwiseLinks); | ||
lunaticMapper.mapEnoObject(enoPairwise.get(), lunaticPairwise); | ||
|
||
// Then | ||
assertEquals("lo9tyy1v", lunaticPairwise.getId()); | ||
assertEquals("count(PAIRWISE_SOURCE)", lunaticPairwise.getXAxisIterations().getValue()); | ||
assertEquals("count(PAIRWISE_SOURCE)", lunaticPairwise.getYAxisIterations().getValue()); | ||
assertEquals(Constant.LUNATIC_LABEL_VTL, lunaticPairwise.getXAxisIterations().getType()); | ||
assertEquals(Constant.LUNATIC_LABEL_VTL, lunaticPairwise.getYAxisIterations().getType()); | ||
assertEquals(1, lunaticPairwise.getComponents().size()); | ||
// | ||
assertEquals(ComponentTypeEnum.PAIRWISE_LINKS, lunaticPairwiseLinks.getComponentType()); | ||
ComponentType pairwiseInnerComponent = lunaticPairwise.getComponents().get(0); | ||
assertTrue(pairwiseInnerComponent instanceof Dropdown); | ||
assertEquals(ComponentTypeEnum.DROPDOWN, pairwiseInnerComponent.getComponentType()); | ||
Dropdown lunaticPairwiseDropDown = (Dropdown) pairwiseInnerComponent; | ||
assertEquals("lo9tyy1v-pairwise-dropdown", lunaticPairwiseDropDown.getId()); | ||
assertEquals("PAIRWISE_QUESTION", lunaticPairwiseDropDown.getResponse().getName()); | ||
assertEquals(4, lunaticPairwiseDropDown.getOptions().size()); | ||
assertEquals(List.of("linkA", "linkB", "linkC", "linkD"), | ||
lunaticPairwiseDropDown.getOptions().stream().map(Options::getValue).toList()); | ||
// Note: for now the symLinks property is added (hard-coded values) by Lunatic-Model | ||
} | ||
|
||
} |
Oops, something went wrong.