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());
}
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()));
}
}
}
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()));
}
}
}
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()));
}
}
}
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()));
}
}
}
Aggregations