From c339a8a5101f962cb24d7ed3d8d854033af7166e Mon Sep 17 00:00:00 2001 From: Martin Ledvinka Date: Mon, 26 Aug 2024 15:01:52 +0200 Subject: [PATCH] [Enhancement #69] Add acceptance test. --- .../ExpandedJsonLdDeserializerTest.java | 18 ++++++++++++++- ...objectWithSingularReferenceWithIdOnly.json | 22 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/objectWithSingularReferenceWithIdOnly.json diff --git a/src/test/java/cz/cvut/kbss/jsonld/deserialization/expanded/ExpandedJsonLdDeserializerTest.java b/src/test/java/cz/cvut/kbss/jsonld/deserialization/expanded/ExpandedJsonLdDeserializerTest.java index a292050..87ac45d 100644 --- a/src/test/java/cz/cvut/kbss/jsonld/deserialization/expanded/ExpandedJsonLdDeserializerTest.java +++ b/src/test/java/cz/cvut/kbss/jsonld/deserialization/expanded/ExpandedJsonLdDeserializerTest.java @@ -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; @@ -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) @@ -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()); + } } diff --git a/src/test/resources/objectWithSingularReferenceWithIdOnly.json b/src/test/resources/objectWithSingularReferenceWithIdOnly.json new file mode 100644 index 0000000..cf77f54 --- /dev/null +++ b/src/test/resources/objectWithSingularReferenceWithIdOnly.json @@ -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": "halsey@unsc.org", + "firstName": "Catherine", + "lastName": "Halsey" +}