Search in sources :

Example 96 with Statement

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

the class TestConcurrentAccess method mrswGraph1.

@Test
public void mrswGraph1() {
    Model m = create().getDefaultModel();
    Resource r = m.createResource("x");
    ExtendedIterator<Statement> iter1 = m.listStatements(r, null, (RDFNode) null);
    assertNotNull(iter1.next());
    ExtendedIterator<Statement> iter2 = m.listStatements(r, null, (RDFNode) null);
    assertNotNull(iter2.next());
    for (; iter2.hasNext(); ) iter2.next();
    assertNotNull(iter1.next());
}
Also used : Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Test(org.junit.Test)

Example 97 with Statement

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

the class SecuredModelTest method testAsStatement_Exists.

@Test
public void testAsStatement_Exists() {
    Triple t = new Triple(s.asNode(), p.asNode(), o.asNode());
    try {
        Statement stmt = securedModel.asStatement(t);
        assertEquals(securedModel, stmt.getModel());
        if (securedModel.canRead(t)) {
            assertEquals(s, stmt.getSubject());
            assertEquals(p, stmt.getPredicate());
            assertEquals(o, stmt.getObject());
        }
        if (!securityEvaluator.evaluate(Action.Read) && !securityEvaluator.evaluate(Action.Update)) {
            Assert.fail("Should have thrown AccessDeniedException Exception");
        }
    } catch (final AccessDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read) && securityEvaluator.evaluate(Action.Update)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : Triple(org.apache.jena.graph.Triple) AccessDeniedException(org.apache.jena.shared.AccessDeniedException) ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) Statement(org.apache.jena.rdf.model.Statement) Test(org.junit.Test) SecuredPrefixMappingTest(org.apache.jena.permissions.graph.SecuredPrefixMappingTest)

Example 98 with Statement

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

the class SecuredModelTest method testGetAnyReifiedStmt_one.

@Test
public void testGetAnyReifiedStmt_one() {
    final Statement st = baseModel.listStatements().next();
    ReifiedStatement s = baseModel.createReifiedStatement(st);
    try {
        Resource r = securedModel.getAnyReifiedStatement(st);
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.assertEquals(s.getURI(), r.getURI());
        }
        if (!securityEvaluator.evaluate(Action.Update) && !securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown UpdateDeniedException Exception");
        }
        if (!securityEvaluator.evaluate(Action.Create) && !securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown AddDeniedException Exception");
        }
    } catch (final UpdateDeniedException e) {
        if (securityEvaluator.evaluate(Action.Update)) {
            Assert.fail(String.format("Should not have thrown UpdateDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    } catch (final AddDeniedException e) {
        if (securityEvaluator.evaluate(Action.Create)) {
            Assert.fail(String.format("Should not have thrown AddDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) Statement(org.apache.jena.rdf.model.Statement) Resource(org.apache.jena.rdf.model.Resource) UpdateDeniedException(org.apache.jena.shared.UpdateDeniedException) AddDeniedException(org.apache.jena.shared.AddDeniedException) Test(org.junit.Test) SecuredPrefixMappingTest(org.apache.jena.permissions.graph.SecuredPrefixMappingTest)

Example 99 with Statement

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

the class SecuredModelTest method testIsReified.

@Test
public void testIsReified() {
    Statement stmt = baseModel.listStatements().next();
    try {
        boolean actual = securedModel.isReified(stmt);
        assertFalse(actual);
        if (!shouldRead()) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
    } catch (final ReadDeniedException e) {
        if (shouldRead()) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
    baseModel.createReifiedStatement(stmt);
    try {
        boolean actual = securedModel.isReified(stmt);
        if (securityEvaluator.evaluate(Action.Read)) {
            assertTrue(actual);
        } else {
            assertFalse(actual);
        }
        if (!shouldRead()) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
    } catch (final ReadDeniedException e) {
        if (shouldRead()) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) Statement(org.apache.jena.rdf.model.Statement) ReadDeniedException(org.apache.jena.shared.ReadDeniedException) Test(org.junit.Test) SecuredPrefixMappingTest(org.apache.jena.permissions.graph.SecuredPrefixMappingTest)

Example 100 with Statement

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

the class SecuredModelTest method __testGetProperty_lang.

private void __testGetProperty_lang(Supplier<Statement> supplier, String expected) {
    try {
        Statement stmt = supplier.get();
        if (securityEvaluator.evaluate(Action.Read) && expected != null) {
            assertNotNull(stmt);
            assertEquals(expected, stmt.getObject().asLiteral().getString());
        } else {
            assertNull(stmt);
        }
        if (!shouldRead()) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
    } catch (final ReadDeniedException e) {
        if (shouldRead()) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : ReifiedStatement(org.apache.jena.rdf.model.ReifiedStatement) Statement(org.apache.jena.rdf.model.Statement) ReadDeniedException(org.apache.jena.shared.ReadDeniedException)

Aggregations

Statement (org.apache.jena.rdf.model.Statement)141 Model (org.apache.jena.rdf.model.Model)56 Resource (org.apache.jena.rdf.model.Resource)46 StmtIterator (org.apache.jena.rdf.model.StmtIterator)46 Test (org.junit.Test)39 RDFNode (org.apache.jena.rdf.model.RDFNode)29 Dataset (org.apache.jena.query.Dataset)28 ArrayList (java.util.ArrayList)25 Property (org.apache.jena.rdf.model.Property)18 ReifiedStatement (org.apache.jena.rdf.model.ReifiedStatement)17 Triple (org.apache.jena.graph.Triple)16 WonMessageValidator (won.protocol.validation.WonMessageValidator)14 TextIndexException (org.apache.jena.query.text.TextIndexException)12 Ignore (org.junit.Ignore)10 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)8 Iterator (java.util.Iterator)7 SecuredReifiedStatement (org.apache.jena.permissions.model.SecuredReifiedStatement)7 SecuredStatement (org.apache.jena.permissions.model.SecuredStatement)7 Literal (org.apache.jena.rdf.model.Literal)7 SecuredPrefixMappingTest (org.apache.jena.permissions.graph.SecuredPrefixMappingTest)6