-
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.
Make type property "@type" for PrimitiveFormControlDataDto
- Loading branch information
1 parent
5929251
commit 7c4442c
Showing
2 changed files
with
88 additions
and
1 deletion.
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
87 changes: 87 additions & 0 deletions
87
...test/java/edu/stanford/protege/webprotege/forms/data/PrimitiveFormControlDataDtoTest.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,87 @@ | ||
package edu.stanford.protege.webprotege.forms.data; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import edu.stanford.protege.webprotege.entity.*; | ||
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 uk.ac.manchester.cs.owl.owlapi.*; | ||
|
||
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 PrimitiveFormControlDataDtoTest { | ||
|
||
@Autowired | ||
private JacksonTester<PrimitiveFormControlDataDto> tester; | ||
|
||
@Test | ||
public void shouldSerializeEntityData() throws IOException { | ||
var data = PrimitiveFormControlDataDto.get(OWLClassData.get(new OWLClassImpl(IRI.create("http://example.org/A")), ImmutableMap.of())); | ||
var written = tester.write(data); | ||
System.out.println(written.getJson()); | ||
assertThat(written).hasJsonPathStringValue("['@type']", "EntityFormControlDataDto"); | ||
assertThat(written).hasJsonPathValue("entity"); | ||
} | ||
|
||
@Test | ||
void shouldDeserializeEntityData() throws IOException { | ||
var expected = PrimitiveFormControlDataDto.get(OWLClassData.get(new OWLClassImpl(IRI.create("http://example.org/A")), ImmutableMap.of())); | ||
var json = """ | ||
{"@type":"EntityFormControlDataDto","entity":{"@type":"ClassData","iri":"http://example.org/A"}} | ||
"""; | ||
var read = tester.read(new StringReader(json)); | ||
assertThat(read.getObject()).isEqualTo(expected); | ||
} | ||
|
||
@Test | ||
public void shouldSerializeIriData() throws IOException { | ||
var data = PrimitiveFormControlDataDto.get(IRIData.get(IRI.create("http://example.org/A"), ImmutableMap.of())); | ||
var written = tester.write(data); | ||
System.out.println(written.getJson()); | ||
assertThat(written).hasJsonPathStringValue("['@type']", "IriFormControlDataDto"); | ||
assertThat(written).hasJsonPathValue("iri"); | ||
} | ||
|
||
@Test | ||
void shouldDeserializeIriData() throws IOException { | ||
var expected = PrimitiveFormControlDataDto.get(IRIData.get(IRI.create("http://example.org/A"), ImmutableMap.of())); | ||
var json = """ | ||
{"@type":"IriFormControlDataDto","iri":{"@type":"IRIData","iri":"http://example.org/A"}} | ||
"""; | ||
var read = tester.read(new StringReader(json)); | ||
assertThat(read.getObject()).isEqualTo(expected); | ||
} | ||
|
||
@Test | ||
public void shouldSerializeLiteralData() throws IOException { | ||
var data = PrimitiveFormControlDataDto.get(OWLLiteralData.get(new OWLLiteralImpl("abc", "en", null))); | ||
var written = tester.write(data); | ||
System.out.println(written.getJson()); | ||
assertThat(written).hasJsonPathStringValue("['@type']", "LiteralFormControlDataDto"); | ||
assertThat(written).hasJsonPathValue("literal"); | ||
} | ||
|
||
@Test | ||
void shouldDeserializeLiteralData() throws IOException { | ||
var expected = PrimitiveFormControlDataDto.get(OWLLiteralData.get(new OWLLiteralImpl("abc", "en", null))); | ||
var json = """ | ||
{"@type":"LiteralFormControlDataDto","literal":{"@type":"LiteralData","value":"abc","lang":"en"}} | ||
"""; | ||
var read = tester.read(new StringReader(json)); | ||
assertThat(read.getObject()).isEqualTo(expected); | ||
} | ||
} |