Search in sources :

Example 26 with Literal

use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.

the class LiteralsTest method testCreateLiteralObjectDate.

/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.util.Literals#createLiteral(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
 * .
 */
@Test
public void testCreateLiteralObjectDate() throws Exception {
    Object obj = new Date();
    Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj);
    assertNotNull(l);
    assertEquals(l.getDatatype(), XMLSchema.DATETIME);
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Date(java.util.Date) Test(org.junit.Test)

Example 27 with Literal

use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.

the class LiteralsTest method testCreateLiteralOrFailObjectXMLGregorianCalendar.

/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.util.Literals#createLiteralOrFail(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
 * .
 */
@Test
public void testCreateLiteralOrFailObjectXMLGregorianCalendar() throws Exception {
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(new Date());
    try {
        Object obj = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
        Literal l = Literals.createLiteralOrFail(SimpleValueFactory.getInstance(), obj);
        assertNotNull(l);
        assertEquals(l.getDatatype(), XMLSchema.DATETIME);
    // TODO check lexical value?
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
        fail("Could not instantiate javax.xml.datatype.DatatypeFactory");
    }
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Literal(org.eclipse.rdf4j.model.Literal) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) Test(org.junit.Test)

Example 28 with Literal

use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.

the class LiteralsTest method testCreateLiteralObjectFloat.

/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.util.Literals#createLiteral(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
 * .
 */
@Test
public void testCreateLiteralObjectFloat() throws Exception {
    Object obj = new Float(42);
    Literal l = Literals.createLiteral(SimpleValueFactory.getInstance(), obj);
    assertNotNull(l);
    assertEquals(l.getDatatype(), XMLSchema.FLOAT);
    assertEquals(l.getLabel(), "42.0");
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Test(org.junit.Test)

Example 29 with Literal

use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.

the class LiteralsTest method testCreateLiteralOrFailObjectBoolean.

/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.util.Literals#createLiteralOrFail(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
 * .
 */
@Test
public void testCreateLiteralOrFailObjectBoolean() throws Exception {
    Object obj = Boolean.TRUE;
    Literal l = Literals.createLiteralOrFail(SimpleValueFactory.getInstance(), obj);
    assertNotNull(l);
    assertEquals(l.getDatatype(), XMLSchema.BOOLEAN);
    assertTrue(l.booleanValue());
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Test(org.junit.Test)

Example 30 with Literal

use of org.eclipse.rdf4j.model.Literal in project rdf4j by eclipse.

the class LiteralsTest method testCreateLiteralOrFailObjectString.

/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.util.Literals#createLiteralOrFail(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
 * .
 */
@Test
public void testCreateLiteralOrFailObjectString() throws Exception {
    Object obj = "random unique string";
    Literal l = Literals.createLiteralOrFail(SimpleValueFactory.getInstance(), obj);
    assertNotNull(l);
    assertEquals(l.getDatatype(), XMLSchema.STRING);
    assertEquals(l.getLabel(), "random unique string");
}
Also used : Literal(org.eclipse.rdf4j.model.Literal) Test(org.junit.Test)

Aggregations

Literal (org.eclipse.rdf4j.model.Literal)98 Test (org.junit.Test)52 IRI (org.eclipse.rdf4j.model.IRI)34 Value (org.eclipse.rdf4j.model.Value)17 BNode (org.eclipse.rdf4j.model.BNode)14 Statement (org.eclipse.rdf4j.model.Statement)14 Model (org.eclipse.rdf4j.model.Model)13 Resource (org.eclipse.rdf4j.model.Resource)9 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)8 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)7 InputStream (java.io.InputStream)6 Date (java.util.Date)6 BindingSet (org.eclipse.rdf4j.query.BindingSet)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)4 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)4 AbstractQueryResultIOTupleTest (org.eclipse.rdf4j.query.resultio.AbstractQueryResultIOTupleTest)4 QueryResultCollector (org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector)4 SPARQLResultsJSONParser (org.eclipse.rdf4j.query.resultio.sparqljson.SPARQLResultsJSONParser)4