use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.
the class LiteralsTest method testCreateLiteralObjectDouble.
/**
* Test method for
* {@link org.eclipse.rdf4j.model.util.Literals#createLiteral(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
* .
*/
@Test
public void testCreateLiteralObjectDouble() throws Exception {
Object obj = new Double(42);
Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj);
assertNotNull(l);
assertEquals(l.getDatatype(), XMLSchema.DOUBLE);
assertEquals(l.getLabel(), "42.0");
}
use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.
the class LiteralsTest method testCreateLiteralOrFailObjectObject.
/**
* Test method for
* {@link org.eclipse.rdf4j.model.util.Literals#createLiteralOrFail(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
* .
*/
@Test
public void testCreateLiteralOrFailObjectObject() throws Exception {
Object obj = new Object();
try {
Literal l = Literals.createLiteralOrFail(SimpleValueFactory.getInstance(), obj);
fail("Did not receive expected exception");
} catch (LiteralUtilException e) {
assertTrue(e.getMessage().contains("Did not recognise object when creating literal"));
}
}
use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.
the class LiteralsTest method testCreateLiteralOrFailObjectInteger.
/**
* Test method for
* {@link org.eclipse.rdf4j.model.util.Literals#createLiteralOrFail(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
* .
*/
@Test
public void testCreateLiteralOrFailObjectInteger() throws Exception {
Object obj = new Integer(4);
Literal l = Literals.createLiteralOrFail(SimpleValueFactory.getInstance(), obj);
assertNotNull(l);
assertEquals(l.getDatatype(), XMLSchema.INT);
assertEquals(l.getLabel(), "4");
}
use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.
the class LiteralsTest method testCreateLiteralObjectShort.
/**
* Test method for
* {@link org.eclipse.rdf4j.model.util.Literals#createLiteral(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
* .
*/
@Test
public void testCreateLiteralObjectShort() throws Exception {
Object obj = Short.parseShort("42");
Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj);
assertNotNull(l);
assertEquals(l.getDatatype(), XMLSchema.SHORT);
assertEquals("42", l.getLabel());
}
use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.
the class ModelsTest method testGetProperty.
@Test
public void testGetProperty() {
Literal lit1 = VF.createLiteral(1.0);
model1.add(foo, bar, lit1);
model1.add(foo, bar, foo);
Value v = Models.getProperty(model1, foo, bar).orElse(null);
assertNotNull(v);
assertTrue(lit1.equals(v) || foo.equals(v));
}
Aggregations