Skip to content

Commit

Permalink
test(pairwise): integration test ddi to lunatic
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave committed Oct 28, 2023
1 parent 4180fb8 commit 3cae00f
Show file tree
Hide file tree
Showing 6 changed files with 1,343 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public static void computeLunaticAxes(PairwiseLinks lunaticPairwiseLinks, String
LabelType yAxis = new LabelType();
String vtlExpression = "count("+loopVariableName+")";
xAxis.setValue(vtlExpression);
xAxis.setType(Constant.LUNATIC_LABEL_VTL_MD);
xAxis.setType(Constant.LUNATIC_LABEL_VTL);
yAxis.setValue(vtlExpression);
yAxis.setType(Constant.LUNATIC_LABEL_VTL_MD);
yAxis.setType(Constant.LUNATIC_LABEL_VTL);
lunaticPairwiseLinks.setXAxisIterations(xAxis);
lunaticPairwiseLinks.setYAxisIterations(yAxis);
}
Expand Down
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());
}

}
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
}

}
Loading

0 comments on commit 3cae00f

Please sign in to comment.