-
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.
* feat: add text component * chore: bump version
- Loading branch information
Showing
8 changed files
with
164 additions
and
4 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package fr.insee.lunatic.model.flat; | ||
|
||
/** | ||
* Non-response component designed to display a label. | ||
*/ | ||
public class Text extends ComponentType { | ||
|
||
public Text() { | ||
this.componentType = ComponentTypeEnum.TEXT; | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
src/test/java/fr/insee/lunatic/conversion/TableSerializationTest.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,75 @@ | ||
package fr.insee.lunatic.conversion; | ||
|
||
import fr.insee.lunatic.exception.SerializationException; | ||
import fr.insee.lunatic.model.flat.*; | ||
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; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
|
||
class TableSerializationTest { | ||
|
||
private final String tableWithText = """ | ||
{ | ||
"componentType": "Questionnaire", | ||
"components": [ | ||
{ | ||
"componentType": "Table", | ||
"body": [ | ||
[ | ||
{ | ||
"componentType": "Text", | ||
"id": "text-cell-id", | ||
"label": { | ||
"value": "\\"Label value.\\"", | ||
"type": "VTL|MD" | ||
} | ||
} | ||
] | ||
] | ||
} | ||
] | ||
}"""; | ||
|
||
@Test | ||
void serializeTableWithTextCells() throws SerializationException, JSONException { | ||
// | ||
Questionnaire questionnaire = new Questionnaire(); | ||
Table table = new Table(); | ||
table.setComponentType(ComponentTypeEnum.TABLE); | ||
table.getBodyLines().add(new BodyLine()); | ||
BodyCell textCell = new BodyCell(); | ||
textCell.setId("text-cell-id"); | ||
textCell.setComponentType(ComponentTypeEnum.TEXT); | ||
textCell.setLabel(new LabelType()); | ||
textCell.getLabel().setType(LabelTypeEnum.VTL_MD); | ||
textCell.getLabel().setValue("\"Label value.\""); | ||
table.getBodyLines().getFirst().getBodyCells().add(textCell); | ||
questionnaire.getComponents().add(table); | ||
// | ||
String result = new JsonSerializer().serialize(questionnaire); | ||
// | ||
JSONAssert.assertEquals(tableWithText, result, JSONCompareMode.STRICT); | ||
} | ||
|
||
@Test | ||
void deserializeTableWithTextCells() throws SerializationException { | ||
// | ||
Questionnaire questionnaire = new JsonDeserializer().deserialize( | ||
new ByteArrayInputStream(tableWithText.getBytes())); | ||
// | ||
Table table = assertInstanceOf(Table.class, questionnaire.getComponents().getFirst()); | ||
assertEquals(1, table.getBodyLines().size()); | ||
assertEquals(1, table.getBodyLines().getFirst().getBodyCells().size()); | ||
BodyCell textCell = table.getBodyLines().getFirst().getBodyCells().getFirst(); | ||
assertEquals(ComponentTypeEnum.TEXT, textCell.getComponentType()); | ||
assertEquals("\"Label value.\"", textCell.getLabel().getValue()); | ||
assertEquals(LabelTypeEnum.VTL_MD, textCell.getLabel().getType()); | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
src/test/java/fr/insee/lunatic/conversion/TextSerializationTest.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,60 @@ | ||
package fr.insee.lunatic.conversion; | ||
|
||
import fr.insee.lunatic.exception.SerializationException; | ||
import fr.insee.lunatic.model.flat.*; | ||
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; | ||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
|
||
class TextSerializationTest { | ||
|
||
private final String textComponentJson = """ | ||
{ | ||
"componentType": "Questionnaire", | ||
"components": [ | ||
{ | ||
"id": "text-component-id", | ||
"componentType": "Text", | ||
"label": { | ||
"value": "\\"Non-editable text.\\"", | ||
"type": "VTL|MD" | ||
} | ||
} | ||
] | ||
}"""; | ||
|
||
@Test | ||
void serializeTextComponent() throws SerializationException, JSONException { | ||
// | ||
Questionnaire questionnaire = new Questionnaire(); | ||
Text text = new Text(); | ||
text.setId("text-component-id"); | ||
text.setLabel(new LabelType()); | ||
text.getLabel().setValue("\"Non-editable text.\""); | ||
text.getLabel().setType(LabelTypeEnum.VTL_MD); | ||
questionnaire.getComponents().add(text); | ||
// | ||
String result = new JsonSerializer().serialize(questionnaire); | ||
// | ||
JSONAssert.assertEquals(textComponentJson, result, JSONCompareMode.STRICT); | ||
} | ||
|
||
@Test | ||
void deserializeTextComponent() throws SerializationException { | ||
// | ||
Questionnaire questionnaire = new JsonDeserializer().deserialize( | ||
new ByteArrayInputStream(textComponentJson.getBytes())); | ||
// | ||
Text text = assertInstanceOf(Text.class, questionnaire.getComponents().getFirst()); | ||
assertEquals(ComponentTypeEnum.TEXT, text.getComponentType()); | ||
assertEquals("\"Non-editable text.\"", text.getLabel().getValue()); | ||
assertEquals(LabelTypeEnum.VTL_MD, text.getLabel().getType()); | ||
} | ||
|
||
} |