-
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(label type): proper type in condition filter too
- Loading branch information
Showing
2 changed files
with
69 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
68 changes: 68 additions & 0 deletions
68
src/test/java/fr/insee/lunatic/conversion/ConditionFilterSerializationTest.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,68 @@ | ||
package fr.insee.lunatic.conversion; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import fr.insee.lunatic.model.flat.ConditionFilterType; | ||
import fr.insee.lunatic.model.flat.LabelTypeEnum; | ||
import org.json.JSONException; | ||
import org.junit.jupiter.api.Test; | ||
import org.skyscreamer.jsonassert.JSONAssert; | ||
import org.skyscreamer.jsonassert.JSONCompareMode; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class ConditionFilterSerializationTest { | ||
|
||
@Test | ||
void serializeConditionFilter() throws JsonProcessingException, JSONException { | ||
// | ||
ConditionFilterType conditionFilterType = new ConditionFilterType(); | ||
conditionFilterType.setValue("if FOO then BAR else BAZ"); | ||
conditionFilterType.setType(LabelTypeEnum.VTL); | ||
conditionFilterType.setBindingDependencies(List.of("FOO", "BAR", "BAZ")); | ||
// | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
String result = objectMapper.writerFor(ConditionFilterType.class).writeValueAsString(conditionFilterType); | ||
// | ||
String expected = """ | ||
{"value": "if FOO then BAR else BAZ", "type": "VTL"} | ||
"""; // (binding dependencies are ignored) | ||
JSONAssert.assertEquals(expected, result, JSONCompareMode.STRICT); | ||
} | ||
|
||
@Test // to be removed when string type is removed | ||
void serializeConditionFilter_stringType() throws JsonProcessingException, JSONException { | ||
// | ||
ConditionFilterType conditionFilterType = new ConditionFilterType(); | ||
conditionFilterType.setValue("if FOO then BAR else BAZ"); | ||
conditionFilterType.setType("VTL"); | ||
conditionFilterType.setBindingDependencies(List.of("FOO", "BAR", "BAZ")); | ||
// | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
String result = objectMapper.writerFor(ConditionFilterType.class).writeValueAsString(conditionFilterType); | ||
// | ||
String expected = """ | ||
{"value": "if FOO then BAR else BAZ", "type": "VTL"} | ||
"""; // (binding dependencies are ignored) | ||
JSONAssert.assertEquals(expected, result, JSONCompareMode.STRICT); | ||
} | ||
|
||
@Test | ||
void deserializeConditionFilter() throws JsonProcessingException { | ||
// | ||
String jsonInput = """ | ||
{"value": "if FOO then BAR else BAZ", "type": "VTL"} | ||
"""; | ||
// | ||
ConditionFilterType conditionFilterType = new ObjectMapper().readValue(jsonInput, ConditionFilterType.class); | ||
// | ||
assertEquals("if FOO then BAR else BAZ", conditionFilterType.getValue()); | ||
assertEquals(LabelTypeEnum.VTL, conditionFilterType.getTypeEnum()); | ||
assertEquals("VTL", conditionFilterType.getType()); // to be removed when string type is removed | ||
assertTrue(conditionFilterType.getBindingDependencies().isEmpty()); | ||
} | ||
|
||
} |