-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed serialization of SingleChoiceControlDataDto
- Loading branch information
1 parent
ebfcabf
commit 5929251
Showing
2 changed files
with
65 additions
and
2 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
62 changes: 62 additions & 0 deletions
62
src/test/java/edu/stanford/protege/webprotege/forms/data/SingleChoiceControlDataDtoTest.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,62 @@ | ||
package edu.stanford.protege.webprotege.forms.data; | ||
|
||
import com.google.common.collect.*; | ||
import edu.stanford.protege.webprotege.entity.IRIData; | ||
import edu.stanford.protege.webprotege.forms.field.*; | ||
import edu.stanford.protege.webprotege.jackson.WebProtegeJacksonApplication; | ||
import org.junit.jupiter.api.Test; | ||
import org.semanticweb.owlapi.model.IRI; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.json.*; | ||
import org.springframework.boot.test.json.JacksonTester; | ||
import org.springframework.context.annotation.Import; | ||
|
||
import java.io.*; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Matthew Horridge | ||
* Stanford Center for Biomedical Informatics Research | ||
* 2024-07-03 | ||
*/ | ||
@JsonTest | ||
@AutoConfigureJsonTesters | ||
@Import(WebProtegeJacksonApplication.class) | ||
public class SingleChoiceControlDataDtoTest { | ||
|
||
@Autowired | ||
private JacksonTester<SingleChoiceControlDataDto> tester; | ||
|
||
@Test | ||
void shouldSerialize() throws IOException { | ||
var data = SingleChoiceControlDataDto.get(SingleChoiceControlDescriptor.get( | ||
SingleChoiceControlType.COMBO_BOX, | ||
FixedChoiceListSourceDescriptor.get(ImmutableList.of())), | ||
PrimitiveFormControlDataDto.get(IRIData.get(IRI.create( | ||
"http://example.org/A"), ImmutableMap.of())), | ||
3); | ||
var written = tester.write(data); | ||
System.out.println(written.getJson()); | ||
assertThat(written).hasJsonPathStringValue("['@type']", "SingleChoiceControlDataDto"); | ||
assertThat(written).hasJsonPathValue("control"); | ||
assertThat(written).hasJsonPathValue("value"); | ||
assertThat(written).hasJsonPathValue("depth"); | ||
|
||
} | ||
|
||
@Test | ||
void shouldDeserialize() throws IOException { | ||
var expected = SingleChoiceControlDataDto.get(SingleChoiceControlDescriptor.get( | ||
SingleChoiceControlType.COMBO_BOX, | ||
FixedChoiceListSourceDescriptor.get(ImmutableList.of())), | ||
PrimitiveFormControlDataDto.get(IRIData.get(IRI.create( | ||
"http://example.org/A"), ImmutableMap.of())), | ||
3); | ||
var json = """ | ||
{"@type":"SingleChoiceControlDataDto","depth":3,"control":{"@type":"SINGLE_CHOICE","widgetType":"ComboBox","choicesSource":{"type":"Fixed","choices":[]},"defaultChoice":null},"value":{"type":"IriFormControlDataDto","iri":{"@type":"IRIData","iri":"http://example.org/A"}}} | ||
"""; | ||
var read = tester.read(new StringReader(json)); | ||
assertThat(read.getObject()).isEqualTo(expected); | ||
} | ||
} |