Search in sources :

Example 11 with Literal

use of org.apache.jena.rdf.model.Literal in project jena by apache.

the class TestLiterals method testLong.

protected void testLong(final Model model, final long tv) {
    final Literal l = model.createTypedLiteral(tv);
    try {
        Assert.assertEquals(tv, l.getByte());
        assertInRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
    } catch (final IllegalArgumentException e) {
        assertOutsideRange(Byte.MIN_VALUE, tv, Byte.MAX_VALUE);
    }
    try {
        Assert.assertEquals(tv, l.getShort());
        assertInRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
    } catch (final IllegalArgumentException e) {
        assertOutsideRange(Short.MIN_VALUE, tv, Short.MAX_VALUE);
    }
    try {
        Assert.assertEquals(tv, l.getInt());
        assertInRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
    } catch (final IllegalArgumentException e) {
        assertOutsideRange(Integer.MIN_VALUE, tv, Integer.MAX_VALUE);
    }
    Assert.assertEquals(tv, l.getLong());
}
Also used : Literal(org.apache.jena.rdf.model.Literal)

Example 12 with Literal

use of org.apache.jena.rdf.model.Literal in project jena by apache.

the class TestLiteralsInModel method testAddWithLiteralObject.

public void testAddWithLiteralObject() {
    final Literal lit = model.createLiteral("spoo");
    model.addLiteral(X, P, lit);
    Assert.assertTrue(model.contains(X, P, lit));
    Assert.assertTrue(model.containsLiteral(X, P, lit));
}
Also used : Literal(org.apache.jena.rdf.model.Literal)

Example 13 with Literal

use of org.apache.jena.rdf.model.Literal in project jena by apache.

the class SecuredResourceTest method testAddProperty.

@Test
public void testAddProperty() {
    final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
    final RDFNode rdfNode = ResourceFactory.createResource("http://example.com/newResource");
    try {
        getSecuredResource().addLiteral(SecuredRDFNodeTest.p, rdfNode);
        if (!securityEvaluator.evaluate(perms)) {
            Assert.fail("Should have thrown AccessDeniedException Exception");
        }
    } catch (final AccessDeniedException e) {
        if (securityEvaluator.evaluate(perms)) {
            Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
    try {
        getSecuredResource().addLiteral(SecuredRDFNodeTest.p, "string");
        if (!securityEvaluator.evaluate(perms)) {
            Assert.fail("Should have thrown AccessDeniedException Exception");
        }
    } catch (final AccessDeniedException e) {
        if (securityEvaluator.evaluate(perms)) {
            Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
    final Literal l = ResourceFactory.createTypedLiteral(3.14F);
    try {
        getSecuredResource().addProperty(SecuredRDFNodeTest.p, l.getLexicalForm(), l.getDatatype());
        if (!securityEvaluator.evaluate(perms)) {
            Assert.fail("Should have thrown AccessDeniedException Exception");
        }
    } catch (final AccessDeniedException e) {
        if (securityEvaluator.evaluate(perms)) {
            Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
    try {
        getSecuredResource().addProperty(SecuredRDFNodeTest.p, "dos", "sp");
        if (!securityEvaluator.evaluate(perms)) {
            Assert.fail("Should have thrown AccessDeniedException Exception");
        }
    } catch (final AccessDeniedException e) {
        if (securityEvaluator.evaluate(perms)) {
            Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : Action(org.apache.jena.permissions.SecurityEvaluator.Action) AccessDeniedException(org.apache.jena.shared.AccessDeniedException) Literal(org.apache.jena.rdf.model.Literal) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test)

Example 14 with Literal

use of org.apache.jena.rdf.model.Literal in project jena by apache.

the class SecuredLiteralTest method setup.

@Override
@Before
public void setup() {
    super.setup();
    Literal l = ResourceFactory.createTypedLiteral("literal");
    setSecuredRDFNode(SecuredLiteralImpl.getInstance(securedModel, l), l);
}
Also used : SecuredLiteral(org.apache.jena.permissions.model.SecuredLiteral) Literal(org.apache.jena.rdf.model.Literal) Before(org.junit.Before)

Example 15 with Literal

use of org.apache.jena.rdf.model.Literal in project jena by apache.

the class rdflangtest method insertMetaOld.

//OLD meta.
static void insertMetaOld(EarlReport report) {
    Model model = report.getModel();
    /*
        <> foaf:primaryTopic <http://jena.apache.org/#riot> ;
            dc:issued "..."^^xsd:dateTime;
            foaf:maker who.
        */
    // Update the EARL report. 
    Resource jena = model.createResource().addProperty(FOAF.homepage, model.createResource("http://jena.apache.org/"));
    // ARQ is part of Jena.
    Resource arq = report.getSystem().addProperty(DCTerms.isPartOf, jena);
    // Andy wrote the test software (updates the thing being tested as well as they are the same). 
    Resource who = model.createResource(FOAF.Person).addProperty(FOAF.name, "Andy Seaborne").addProperty(FOAF.homepage, model.createResource("http://people.apache.org/~andy"));
    Resource reporter = report.getReporter();
    reporter.addProperty(DC.creator, who);
    Resource system = report.getSystem();
    system.addProperty(RDF.type, DOAP.Project);
    system.addProperty(DOAP.name, name);
    system.addProperty(DOAP.homepage, homepage);
    system.addProperty(DOAP.maintainer, who);
    Resource release = model.createResource(DOAP.Version);
    system.addProperty(DOAP.release, release);
    Node today_node = NodeFactoryExtra.todayAsDate();
    Literal today = model.createTypedLiteral(today_node.getLiteralLexicalForm(), today_node.getLiteralDatatype());
    release.addProperty(DOAP.created, today);
    // Again
    release.addProperty(DOAP.name, releaseName);
}
Also used : Node(org.apache.jena.graph.Node) Literal(org.apache.jena.rdf.model.Literal) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource)

Aggregations

Literal (org.apache.jena.rdf.model.Literal)42 Resource (org.apache.jena.rdf.model.Resource)17 Test (org.junit.Test)15 Model (org.apache.jena.rdf.model.Model)12 Property (org.apache.jena.rdf.model.Property)9 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)7 RDFNode (org.apache.jena.rdf.model.RDFNode)7 Node (org.apache.jena.graph.Node)6 HashSet (java.util.HashSet)4 QuerySolution (org.apache.jena.query.QuerySolution)4 Store (org.apache.jena.sdb.Store)3 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)2 SecuredLiteral (org.apache.jena.permissions.model.SecuredLiteral)2 Dataset (org.apache.jena.query.Dataset)2 Query (org.apache.jena.query.Query)2 QueryExecution (org.apache.jena.query.QueryExecution)2 ResultSet (org.apache.jena.query.ResultSet)2