Skip to content

Commit

Permalink
[Enhancement #69] Add acceptance test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Aug 26, 2024
1 parent 67eb895 commit 4e1a470
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
Expand Down Expand Up @@ -381,7 +382,7 @@ void deserializationSupportsPolymorphismForAttributes() throws Exception {
this.sut = JsonLdDeserializer.createExpandedDeserializer(config);
final JsonArray input = readAndExpand("objectWithSingularPolymorphicReference.json");
final PolymorphicPerson result = sut.deserialize(input, PolymorphicPerson.class);
assertTrue(result.friend instanceof Employee);
assertInstanceOf(Employee.class, result.friend);
}

@OWLClass(iri = Vocabulary.PERSON)
Expand Down Expand Up @@ -847,4 +848,19 @@ void deserializeSupportsMappingIndividualToEnumConstant() throws Exception {
assertThat(result.getPluralPropertyType(),
hasItems(OwlPropertyType.ANNOTATION_PROPERTY, OwlPropertyType.OBJECT_PROPERTY));
}

@Test
void deserializationUsesProvidedTargetTypeWhenNoTypeIsSpecifiedTypeAssumingIsEnabledAndObjectHasOnlyId() throws Exception {
final Configuration config = new Configuration();
config.set(ConfigParam.ASSUME_TARGET_TYPE, Boolean.TRUE.toString());
config.set(ConfigParam.SCAN_PACKAGE, "cz.cvut.kbss.jsonld");
this.sut = ExpandedJsonLdDeserializer.createExpandedDeserializer(config);
final JsonArray input = readAndExpand("objectWithSingularReferenceWithIdOnly.json");
final Employee result = sut.deserialize(input, Employee.class);
assertNotNull(result);
verifyUserAttributes(USERS.get(HALSEY_URI), result);
assertNotNull(result.getEmployer());
assertEquals(TestUtil.UNSC_URI, result.getEmployer().getUri());
assertNull(result.getEmployer().getName());
}
}
22 changes: 22 additions & 0 deletions src/test/resources/objectWithSingularReferenceWithIdOnly.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"@context": {
"firstName": "http://xmlns.com/foaf/0.1/firstName",
"lastName": "http://xmlns.com/foaf/0.1/lastName",
"accountName": "http://xmlns.com/foaf/0.1/accountName",
"isAdmin": "http://krizik.felk.cvut.cz/ontologies/jb4jsonld/isAdmin"
},
"@id": "http://krizik.felk.cvut.cz/ontologies/jb4jsonld#Catherine+Halsey",
"@type": [
"http://onto.fel.cvut.cz/ontologies/ufo/Person",
"http://krizik.felk.cvut.cz/ontologies/jb4jsonld/Employee",
"http://krizik.felk.cvut.cz/ontologies/jb4jsonld/User",
"http://krizik.felk.cvut.cz/ontologies/jb4jsonld/GenericMember"
],
"isAdmin": true,
"http://krizik.felk.cvut.cz/ontologies/jb4jsonld/isMemberOf": {
"@id": "http://krizik.felk.cvut.cz/ontologies/jb4jsonld#UNSC"
},
"accountName": "[email protected]",
"firstName": "Catherine",
"lastName": "Halsey"
}

0 comments on commit 4e1a470

Please sign in to comment.