|
| 1 | +package fr.insee.lunatic.conversion; |
| 2 | + |
| 3 | +import fr.insee.lunatic.exception.SerializationException; |
| 4 | +import fr.insee.lunatic.model.flat.PairwiseLinks; |
| 5 | +import fr.insee.lunatic.model.flat.Questionnaire; |
| 6 | +import org.json.JSONException; |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | +import org.skyscreamer.jsonassert.JSONAssert; |
| 9 | +import org.skyscreamer.jsonassert.JSONCompareMode; |
| 10 | + |
| 11 | +class PairwiseLinksSerializationTest { |
| 12 | + |
| 13 | + @Test |
| 14 | + void serializePairwiseLinks() throws SerializationException, JSONException { |
| 15 | + // |
| 16 | + Questionnaire questionnaire = new Questionnaire(); |
| 17 | + PairwiseLinks pairwiseLinks = new PairwiseLinks(); |
| 18 | + pairwiseLinks.setId("foo-id"); |
| 19 | + PairwiseLinks.SourceVariables sourceVariables = new PairwiseLinks.SourceVariables(); |
| 20 | + sourceVariables.setName("FIRST_NAME_VAR"); |
| 21 | + sourceVariables.setGender("GENDER_VAR"); |
| 22 | + pairwiseLinks.setSourceVariables(sourceVariables); |
| 23 | + questionnaire.getComponents().add(pairwiseLinks); |
| 24 | + // |
| 25 | + String result = new JsonSerializer().serialize(questionnaire); |
| 26 | + // |
| 27 | + String expected = """ |
| 28 | +{ |
| 29 | + "componentType": "Questionnaire", |
| 30 | + "components": [ |
| 31 | + { |
| 32 | + "id": "foo-id", |
| 33 | + "componentType": "PairwiseLinks", |
| 34 | + "sourceVariables": { |
| 35 | + "name": "FIRST_NAME_VAR", |
| 36 | + "gender": "GENDER_VAR" |
| 37 | + }, |
| 38 | + "components": [] |
| 39 | + } |
| 40 | + ] |
| 41 | +} |
| 42 | +"""; |
| 43 | + JSONAssert.assertEquals(expected, result, JSONCompareMode.STRICT); |
| 44 | + } |
| 45 | + |
| 46 | +} |
0 commit comments