-
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.
Added serialization tests for MultiChoiceControlDataDto
- Loading branch information
1 parent
0258e29
commit ebfcabf
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/test/java/edu/stanford/protege/webprotege/forms/data/MultiChoiceControlDataDtoTest.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,56 @@ | ||
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; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@JsonTest | ||
@AutoConfigureJsonTesters | ||
@Import(WebProtegeJacksonApplication.class) | ||
class MultiChoiceControlDataDtoTest { | ||
|
||
@Autowired | ||
private JacksonTester<MultiChoiceControlDataDto> tester; | ||
|
||
@Test | ||
void shouldSerialize() throws IOException { | ||
var data = MultiChoiceControlDataDto.get(MultiChoiceControlDescriptor.get(FixedChoiceListSourceDescriptor.get( | ||
ImmutableList.of()), ImmutableList.of()), | ||
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']", "MultiChoiceControlDataDto"); | ||
assertThat(written).hasJsonPathValue("control"); | ||
assertThat(written).hasJsonPathValue("values"); | ||
assertThat(written).hasJsonPathValue("depth"); | ||
|
||
} | ||
|
||
@Test | ||
void shouldDeserialize() throws IOException { | ||
var expected = MultiChoiceControlDataDto.get(MultiChoiceControlDescriptor.get(FixedChoiceListSourceDescriptor.get( | ||
ImmutableList.of()), ImmutableList.of()), | ||
ImmutableList.of(PrimitiveFormControlDataDto.get(IRIData.get(IRI.create( | ||
"http://example.org/A"), ImmutableMap.of()))), | ||
3); | ||
var json = """ | ||
{"@type":"MultiChoiceControlDataDto","depth":3,"control":{"@type":"MULTI_CHOICE","choicesSource":{"type":"Fixed","choices":[]},"defaultChoice":[]},"values":[{"type":"IriFormControlDataDto","iri":{"@type":"IRIData","iri":"http://example.org/A"}}]} | ||
"""; | ||
var read = tester.read(new StringReader(json)); | ||
assertThat(read.getObject()).isEqualTo(expected); | ||
} | ||
} |