Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #57 #60

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,23 @@ else if(node.isObject()) {
}
switch (type) {
case "owl:Class" :
case "Class" :
return PrimitiveFormControlData.get(df.getOWLClass(iri));
case "owl:ObjectProperty":
case "ObjectProperty" :
return PrimitiveFormControlData.get(df.getOWLObjectProperty(iri));
case "owl:DatatypeProperty" :
case "DatatypeProperty" :
case "DataProperty" :
return PrimitiveFormControlData.get(df.getOWLDataProperty(iri));
case "owl:AnnotationProperty":
case "AnnotationProperty" :
return PrimitiveFormControlData.get(df.getOWLAnnotationProperty(iri));
case "rdfs:Datatype" :
case "Datatype" :
return PrimitiveFormControlData.get(df.getOWLDatatype(iri));
case "owl:NamedIndividual" :
case "NamedIndividual" :
return PrimitiveFormControlData.get(df.getOWLNamedIndividual(iri));
}
throw new JsonParseException(p, "Unrecognised entity type: " + type);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package edu.stanford.bmir.protege.web.server.form;

import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.stanford.bmir.protege.web.MockingUtils;
import edu.stanford.bmir.protege.web.server.jackson.ObjectMapperProvider;
Expand All @@ -10,13 +8,15 @@
import edu.stanford.bmir.protege.web.shared.form.data.LiteralFormControlData;
import edu.stanford.bmir.protege.web.shared.form.data.PrimitiveFormControlData;
import edu.stanford.bmir.protege.web.shared.match.JsonSerializationTestUtil;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.semanticweb.owlapi.model.*;

import java.io.IOException;
import java.io.StringReader;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;

public class FormControlValueDeserializer_TestCase {

Expand Down Expand Up @@ -47,33 +47,127 @@ public void shouldRoundTripOwlClass() throws IOException {
JsonSerializationTestUtil.testSerialization(value, PrimitiveFormControlData.class);
}

@Test
public void shouldDeserializeOwlClass() throws IOException {
var json = "{\"@type\":\"owl:Class\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLClass.class);
}

@Test
public void shouldDeserializeClass() throws IOException {
var json = "{\"@type\":\"Class\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLClass.class);
}

@Test
public void shouldRoundTripOwlObjectProperty() throws IOException {
var value = EntityFormControlData.get(MockingUtils.mockOWLObjectProperty());
JsonSerializationTestUtil.testSerialization(value, PrimitiveFormControlData.class);
}



@Test
public void shouldDeserializeOwlObjectProperty() throws IOException {
var json = "{\"@type\":\"owl:ObjectProperty\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLObjectProperty.class);
}

@Test
public void shouldDeserializeObjectProperty() throws IOException {
var json = "{\"@type\":\"ObjectProperty\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLObjectProperty.class);
}


@Test
public void shouldRoundTripOwlDataProperty() throws IOException {
var value = EntityFormControlData.get(MockingUtils.mockOWLDataProperty());
JsonSerializationTestUtil.testSerialization(value, PrimitiveFormControlData.class);
}

@Test
public void shouldDeserializeOwlDatatypeProperty() throws IOException {
var json = "{\"@type\":\"owl:DatatypeProperty\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLDataProperty.class);
}

@Test
public void shouldDeserializeDatatypeProperty() throws IOException {
var json = "{\"@type\":\"DatatypeProperty\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLDataProperty.class);
}

@Test
public void shouldDeserializeDataProperty() throws IOException {
var json = "{\"@type\":\"DataProperty\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLDataProperty.class);
}

@Test
public void shouldRoundTripOwlAnnotationProperty() throws IOException {
var value = EntityFormControlData.get(MockingUtils.mockOWLAnnotationProperty());
JsonSerializationTestUtil.testSerialization(value, PrimitiveFormControlData.class);
}

@Test
public void shouldDeserializeOwlAnnotationProperty() throws IOException {
var json = "{\"@type\":\"owl:AnnotationProperty\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLAnnotationProperty.class);
}

@Test
public void shouldDeserializeAnnotationProperty() throws IOException {
var json = "{\"@type\":\"AnnotationProperty\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLAnnotationProperty.class);
}

@Test
public void shouldRoundTripOwlNamedIndividual() throws IOException {
var value = EntityFormControlData.get(MockingUtils.mockOWLNamedIndividual());
JsonSerializationTestUtil.testSerialization(value, PrimitiveFormControlData.class);
}

@Test
public void shouldDeserializeOwlNamedIndividual() throws IOException {
var json = "{\"@type\":\"owl:NamedIndividual\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLNamedIndividual.class);
}

@Test
public void shouldDeserializeNamedIndividual() throws IOException {
var json = "{\"@type\":\"NamedIndividual\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLNamedIndividual.class);
}

@Test
public void shouldRoundTripOwlDatatype() throws IOException {
var value = EntityFormControlData.get(MockingUtils.mockOWLDatatype());
JsonSerializationTestUtil.testSerialization(value, PrimitiveFormControlData.class);
}

@Test
public void shouldDeserializeRdfsDatatype() throws IOException {
var json = "{\"@type\":\"rdfs:Datatype\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLDatatype.class);
}

@Test
public void shouldDeserializeDatatype() throws IOException {
var json = "{\"@type\":\"Datatype\",\"iri\":\"http://stuff.com/I1\"}";
var value = objectMapper.readValue(new StringReader(json), PrimitiveFormControlData.class);
Assertions.assertThat(value.asEntity()).containsInstanceOf(OWLDatatype.class);
}
}
Loading