-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: create enum class for label type
- Loading branch information
Showing
4 changed files
with
131 additions
and
3 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
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
10 changes: 10 additions & 0 deletions
10
src/main/java/fr/insee/lunatic/model/flat/LabelTypeEnum.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,10 @@ | ||
package fr.insee.lunatic.model.flat; | ||
|
||
public enum LabelTypeEnum { | ||
|
||
/** Label that is a VTL expression and contains Markdown formatting. */ | ||
VTL_MD, | ||
/** Label that is a VTL expression. */ | ||
VTL | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/test/java/fr/insee/lunatic/conversion/LabelSerializationTest.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,69 @@ | ||
package fr.insee.lunatic.conversion; | ||
|
||
import fr.insee.lunatic.exception.SerializationException; | ||
import fr.insee.lunatic.model.flat.LabelType; | ||
import fr.insee.lunatic.model.flat.LabelTypeEnum; | ||
import fr.insee.lunatic.model.flat.Questionnaire; | ||
import org.json.JSONException; | ||
import org.junit.jupiter.api.Test; | ||
import org.skyscreamer.jsonassert.JSONAssert; | ||
import org.skyscreamer.jsonassert.JSONCompareMode; | ||
|
||
import java.io.ByteArrayInputStream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class LabelSerializationTest { | ||
|
||
@Test | ||
void serializeFromQuestionnaire_usingEnumType() throws SerializationException, JSONException { | ||
// | ||
Questionnaire questionnaire = new Questionnaire(); | ||
LabelType label = new LabelType(); | ||
label.setValue("Foo label"); | ||
label.setType(LabelTypeEnum.VTL_MD); | ||
questionnaire.setLabel(label); | ||
// | ||
JsonSerializer jsonSerializer = new JsonSerializer(); | ||
String result = jsonSerializer.serialize(questionnaire); | ||
// | ||
String expected = """ | ||
{"label": {"value": "Foo label", "type": "VTL_MD"}} | ||
"""; | ||
JSONAssert.assertEquals(expected, result, JSONCompareMode.STRICT); | ||
} | ||
|
||
@Test | ||
void serializeFromQuestionnaire_usingStringType() throws SerializationException, JSONException { | ||
// | ||
Questionnaire questionnaire = new Questionnaire(); | ||
LabelType label = new LabelType(); | ||
label.setValue("Foo label"); | ||
label.setType("VTL_MD"); | ||
questionnaire.setLabel(label); | ||
// | ||
JsonSerializer jsonSerializer = new JsonSerializer(); | ||
String result = jsonSerializer.serialize(questionnaire); | ||
// | ||
String expected = """ | ||
{"label": {"value": "Foo label", "type": "VTL_MD"}} | ||
"""; | ||
JSONAssert.assertEquals(expected, result, JSONCompareMode.STRICT); | ||
} | ||
|
||
@Test | ||
void deserializeFromQuestionnaire() throws SerializationException { | ||
// | ||
String jsonInput = """ | ||
{"label": {"value": "Foo label", "type": "VTL_MD"}} | ||
"""; | ||
// | ||
JsonDeserializer jsonDeserializer = new JsonDeserializer(); | ||
Questionnaire questionnaire = jsonDeserializer.deserialize(new ByteArrayInputStream(jsonInput.getBytes())); | ||
// | ||
LabelType label = questionnaire.getLabel(); | ||
assertEquals(LabelTypeEnum.VTL_MD, label.getTypeEnum()); | ||
assertEquals("VTL_MD", label.getType()); | ||
} | ||
|
||
} |