use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestStatisticsAggregates method test.
private static void test(Query query, double expected, DatasetGraph dsg) {
try (QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.wrap(dsg))) {
Literal literal = qExec.execSelect().next().getLiteral("X");
double result = literal.getDouble();
assertEquals(expected, result, 0.001);
}
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestLiteralImpl method testInModel.
public void testInModel() {
final Model m1 = createModel();
final Model m2 = createModel();
final Literal l1 = m1.createLiteral("17");
final Literal l2 = l1.inModel(m2);
Assert.assertEquals(l1, l2);
Assert.assertSame(m2, l2.getModel());
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestLiteralImpl method testTypedLiteralTypesAndValues.
// Tests are not necessarily run in order so use UniqueValueClass2
public void testTypedLiteralTypesAndValues() {
// Resource r = model.createResource( "eh:/rhubarb" );
final UniqueValueClass2 r = new UniqueValueClass2("rhubarb");
Assert.assertNull("not expecting registered RDF Datatype", TypeMapper.getInstance().getTypeByValue(r));
// Sets the type
final Literal typed = model.createTypedLiteral(r);
// mapper -
// contaminates it
// with
// UniqueValueClass2
final Literal string = model.createLiteral(r.value);
Assert.assertEquals(string.getLexicalForm(), typed.getLexicalForm());
Assert.assertEquals(string.getLanguage(), typed.getLanguage());
JenaTestBase.assertDiffer(string.getDatatypeURI(), typed.getDatatypeURI());
Assert.assertNotNull("a datatype should have been invented for Resource[Impl]", typed.getDatatype());
JenaTestBase.assertDiffer(typed, string);
JenaTestBase.assertDiffer(typed.getValue(), string.getValue());
Assert.assertEquals(r, typed.getValue());
JenaTestBase.assertDiffer(typed.hashCode(), string.hashCode());
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestLiterals method testLanguagedString.
protected void testLanguagedString(final Model model, final String tv, final String lang) {
final Literal l = model.createLiteral(tv, lang);
Assert.assertEquals(tv, l.getString());
Assert.assertEquals(tv, l.getLexicalForm());
Assert.assertEquals(lang, l.getLanguage());
}
use of org.apache.jena.rdf.model.Literal in project jena by apache.
the class TestLiterals method testByte.
protected void testByte(final Model model, final byte tv) {
final Literal l = model.createTypedLiteral(tv);
Assert.assertEquals(tv, l.getByte());
Assert.assertEquals(tv, l.getShort());
Assert.assertEquals(tv, l.getInt());
Assert.assertEquals(tv, l.getLong());
}
Aggregations