Skip to content

Commit

Permalink
Merge branch 'v3-next' into feat/improve-date-generated-control
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave committed Dec 5, 2024
2 parents 2729823 + b6f918c commit 959a90c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,11 @@ private void computeHorizontalSizes(CodeItem codeItem) {
}
}

@Override
public String toString() {
return "CodeList[" +
"id='" + this.getId() + '\'' +
", name='" + name + '\'' +
']';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public abstract class Question extends EnoIdentifiableObject implements EnoCompo

@Override
public String toString() {
return this.getClass() + "[id="+this.getId()+", name="+getName()+"]";
return this.getClass().getSimpleName() + "[id="+this.getId()+", name="+getName()+"]";
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.insee.eno.core.processing.in.steps.ddi;

import fr.insee.eno.core.exceptions.business.IllegalDDIElementException;
import fr.insee.eno.core.model.EnoQuestionnaire;
import fr.insee.eno.core.model.code.CodeItem;
import fr.insee.eno.core.model.code.CodeList;
Expand Down Expand Up @@ -37,7 +38,14 @@ public void apply(EnoQuestionnaire enoQuestionnaire) {

private void insertModalityLabels(SimpleMultipleChoiceQuestion simpleMultipleChoiceQuestion) {
CodeList codeList = codeListMap.get(simpleMultipleChoiceQuestion.getCodeListReference());
for (int i = 0; i < codeList.size(); i ++) {
int codeListSize = codeList.size();
int responsesSize = simpleMultipleChoiceQuestion.getCodeResponses().size();
if (codeListSize != responsesSize)
throw new IllegalDDIElementException(String.format(
"Code list '%s' (id=%s) has %s codes, and is used in multiple choice question '%s' (id=%s) that has %s responses.",
codeList.getName(), codeList.getId(), codeListSize,
simpleMultipleChoiceQuestion.getName(), simpleMultipleChoiceQuestion.getId(), responsesSize));
for (int i = 0; i < codeListSize; i ++) {
CodeItem codeItem = codeList.getCodeItems().get(i);
CodeResponse codeResponse = simpleMultipleChoiceQuestion.getCodeResponses().get(i);
codeResponse.setLabel(codeItem.getLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,51 @@

import fr.insee.ddi.lifecycle33.instance.DDIInstanceDocument;
import fr.insee.eno.core.exceptions.business.DDIParsingException;
import fr.insee.eno.core.exceptions.business.IllegalDDIElementException;
import fr.insee.eno.core.mappers.DDIMapper;
import fr.insee.eno.core.model.EnoQuestionnaire;
import fr.insee.eno.core.model.code.CodeItem;
import fr.insee.eno.core.model.code.CodeList;
import fr.insee.eno.core.model.question.SimpleMultipleChoiceQuestion;
import fr.insee.eno.core.model.response.CodeResponse;
import fr.insee.eno.core.serialize.DDIDeserializer;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;

class DDIInsertMultipleChoiceLabelsTest {

@Test
void failingCase_tooManyCodes() {
// Given
EnoQuestionnaire enoQuestionnaire = new EnoQuestionnaire();
//
CodeList codeList = new CodeList();
codeList.setId("code-list-id");
codeList.setName("CODE_LIST_NAME");
codeList.getCodeItems().add(new CodeItem());
codeList.getCodeItems().add(new CodeItem());
enoQuestionnaire.getCodeLists().add(codeList);
//
SimpleMultipleChoiceQuestion simpleMCQ = new SimpleMultipleChoiceQuestion();
simpleMCQ.setId("question-id");
simpleMCQ.setName("QUESTION_NAME");
simpleMCQ.setCodeListReference("code-list-id");
simpleMCQ.getCodeResponses().add(new CodeResponse());
enoQuestionnaire.getMultipleResponseQuestions().add(simpleMCQ);
// When + Then
DDIInsertMultipleChoiceLabels processing = new DDIInsertMultipleChoiceLabels();
assertThatThrownBy(() -> processing.apply(enoQuestionnaire))
.isInstanceOf(IllegalDDIElementException.class)
.hasMessageContaining("code-list-id")
.hasMessageContaining("CODE_LIST_NAME")
.hasMessageContaining("question-id")
.hasMessageContaining("QUESTION_NAME");
}

@Test
void integrationTest() throws DDIParsingException {
//
Expand Down

0 comments on commit 959a90c

Please sign in to comment.