Search in sources :

Example 1 with SecuredStatementIterator

use of org.apache.jena.permissions.model.impl.SecuredStatementIterator in project jena by apache.

the class SecuredResourceTest method testListProperties.

@Test
public void testListProperties() {
    try {
        SecuredStatementIterator iter = getSecuredResource().listProperties();
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        assertTrue(iter.hasNext());
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
    try {
        SecuredStatementIterator iter = getSecuredResource().listProperties(SecuredRDFNodeTest.p);
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        if (hasP()) {
            assertTrue(iter.hasNext());
        } else {
            assertFalse(iter.hasNext());
        }
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : ReadDeniedException(org.apache.jena.shared.ReadDeniedException) SecuredStatementIterator(org.apache.jena.permissions.model.impl.SecuredStatementIterator) Test(org.junit.Test)

Example 2 with SecuredStatementIterator

use of org.apache.jena.permissions.model.impl.SecuredStatementIterator in project jena by apache.

the class SecuredResourceTest method testListPropertiesWithLang.

@Test
public void testListPropertiesWithLang() {
    try {
        SecuredStatementIterator iter = getSecuredResource().listProperties(SecuredRDFNodeTest.p2, "");
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        if (hasP2()) {
            assertTrue(iter.hasNext());
            Statement stmt = iter.next();
            assertEquals("yeehaw", stmt.getObject().asLiteral().getString());
        }
        assertFalse(iter.hasNext());
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
    try {
        SecuredStatementIterator iter = getSecuredResource().listProperties(SecuredRDFNodeTest.p2, "us");
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        if (hasP2()) {
            assertTrue(iter.hasNext());
            Statement stmt = iter.next();
            assertEquals("yeehaw yall", stmt.getObject().asLiteral().getString());
        }
        assertFalse(iter.hasNext());
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
    try {
        SecuredStatementIterator iter = getSecuredResource().listProperties(SecuredRDFNodeTest.p2, "uk");
        if (!securityEvaluator.evaluate(Action.Read)) {
            Assert.fail("Should have thrown ReadDeniedException Exception");
        }
        if (hasP2()) {
            assertTrue(iter.hasNext());
            Statement stmt = iter.next();
            assertEquals("whohoo", stmt.getObject().asLiteral().getString());
        }
        assertFalse(iter.hasNext());
    } catch (final ReadDeniedException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple()));
        }
    }
}
Also used : Statement(org.apache.jena.rdf.model.Statement) ReadDeniedException(org.apache.jena.shared.ReadDeniedException) SecuredStatementIterator(org.apache.jena.permissions.model.impl.SecuredStatementIterator) Test(org.junit.Test)

Aggregations

SecuredStatementIterator (org.apache.jena.permissions.model.impl.SecuredStatementIterator)2 ReadDeniedException (org.apache.jena.shared.ReadDeniedException)2 Test (org.junit.Test)2 Statement (org.apache.jena.rdf.model.Statement)1