SesameValueConverter { Value toSesameValue(Assertion assertion, cz.cvut.kbss.ontodriver.model.Value<?> val) throws SesameDriverException { switch (assertion.getType()) { case DATA_PROPERTY: return SesameUtils.createDataPropertyLiteral(val.getValue(), language(assertion), vf); case CLASS: case OBJECT_PROPERTY: return getValueAsSesameUri(val); case ANNOTATION_PROPERTY: case PROPERTY: return resolvePropertyValue(assertion, val); default: throw new IllegalArgumentException("Unsupported assertion type " + assertion.getType()); } } SesameValueConverter(ValueFactory vf);   }
@Test void convertsObjectPropertyNamedResourceToSesameUri() throws Exception { final Value res = converter.toSesameValue(assertion(Assertion.AssertionType.OBJECT_PROPERTY), value(NamedResource.create("http: assertTrue(res instanceof org.eclipse.rdf4j.model.IRI); }
@Test void convertsDataPropertyValueToSesameLiteral() throws Exception { final int val = 117; final Value res = converter.toSesameValue(assertion(Assertion.AssertionType.DATA_PROPERTY), value(val)); assertTrue(res instanceof Literal); assertEquals(val, ((Literal) res).intValue()); }
@Test void convertsAnnotationPropertyLiteralValueToSesameLiteral() throws Exception { final String val = "AnnotationValue"; final Value res = converter.toSesameValue(assertion(Assertion.AssertionType.ANNOTATION_PROPERTY), value(val)); assertTrue(res instanceof Literal); assertEquals(val, ((Literal) res).getLabel()); }
@Test void convertsAnnotationPropertyNamedResourceToSesameUri() throws Exception { final NamedResource val = NamedResource .create("http: final Value res = converter.toSesameValue(assertion(Assertion.AssertionType.ANNOTATION_PROPERTY), value(val)); assertTrue(res instanceof org.eclipse.rdf4j.model.IRI); assertEquals(val.toString(), res.toString()); }
@Test void conversionThrowsExceptionWhenObjectPropertyValueIsNotUri() { assertThrows(SesameDriverException.class, () -> converter.toSesameValue(assertion(Assertion.AssertionType.OBJECT_PROPERTY), value(117))); }
@Test void convertsStringLiteralIntoValueWithLanguageTagSpecifiedInAssertion() throws Exception { final String value = "hodnota v cestine"; final Assertion dpAssertion = Assertion.createDataPropertyAssertion(PROPERTY, LANG, false); final Value res = converter.toSesameValue(dpAssertion, value(value)); assertTrue(res instanceof Literal); final Literal literal = (Literal) res; assertTrue(literal.getLanguage().isPresent()); assertEquals(LANG, literal.getLanguage().get()); assertEquals(value, literal.stringValue()); }
@Test void convertsStringLiteralIntoValueWithoutLanguageWhenAssertionHasNoLanguage() throws Exception { final String value = "hodnota v cestine"; final Assertion dpAssertion = Assertion.createDataPropertyAssertion(PROPERTY, false); final Value res = converter.toSesameValue(dpAssertion, value(value)); assertTrue(res instanceof Literal); final Literal literal = (Literal) res; assertFalse(literal.getLanguage().isPresent()); }
@Test void convertsAnnotationLiteralIntoValueWithLanguageTagSpecifiedInAssertion() throws Exception { final String value = "hodnota v cestine"; final Assertion apAssertion = Assertion.createAnnotationPropertyAssertion(PROPERTY, LANG, false); final Value res = converter.toSesameValue(apAssertion, value(value)); assertTrue(res instanceof Literal); final Literal literal = (Literal) res; assertTrue(literal.getLanguage().isPresent()); assertEquals(LANG, literal.getLanguage().get()); assertEquals(value, literal.stringValue()); }
@Test void convertsAnnotationLiteralIntoValueWithoutLanguageWhenAssertionHasNoLanguage() throws Exception { final String value = "hodnota v cestine"; final Assertion apAssertion = Assertion.createAnnotationPropertyAssertion(PROPERTY, false); final Value res = converter.toSesameValue(apAssertion, value(value)); assertTrue(res instanceof Literal); final Literal literal = (Literal) res; assertFalse(literal.getLanguage().isPresent()); }