Skip to content

Commit

Permalink
Added serialization tests for FormSubjectFactoryDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed Jul 3, 2024
1 parent 7c4442c commit b296714
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package edu.stanford.protege.webprotege.forms;

import edu.stanford.protege.webprotege.jackson.WebProtegeJacksonApplication;
import org.junit.jupiter.api.*;
import org.semanticweb.owlapi.model.*;
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.OWLClassImpl;

import java.io.*;
import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;

@JsonTest
@AutoConfigureJsonTesters
@Import(WebProtegeJacksonApplication.class)
class FormSubjectFactoryDescriptorTest {

@Autowired
private JacksonTester<FormSubjectFactoryDescriptor> tester;

@Test
void shouldSerialize() throws IOException {
var descriptor = FormSubjectFactoryDescriptor.get(
EntityType.NAMED_INDIVIDUAL,
new OWLClassImpl(IRI.create("http://example.org/A")),
Optional.empty()
);
var written = tester.write(descriptor);
System.out.println(written.getJson());
assertThat(written).hasJsonPathValue("entityType");
assertThat(written).hasJsonPathValue("parent");
assertThat(written).hasJsonPath("targetOntologyIri");
}

@Test
void shouldDeserialize() throws IOException {
var json = """
{"entityType":"NamedIndividual","parent":{"@type":"Class","iri":"http://example.org/A"},"targetOntologyIri":null}
""";
var expected = FormSubjectFactoryDescriptor.get(
EntityType.NAMED_INDIVIDUAL,
new OWLClassImpl(IRI.create("http://example.org/A")),
Optional.empty()
);
var read = tester.read(new StringReader(json));
assertThat(read.getObject()).isEqualTo(expected);

}
}

0 comments on commit b296714

Please sign in to comment.