use of org.apache.jena.rdf.model.EmptyListException in project jena by apache.
the class SecuredRDFListImpl method removeHead.
/**
* @sec.graph Update
* @sec.triple Delete for the head triple.
* @throws UpdateDeniedException
* @throws DeleteDeniedException
* @throws EmptyListException
* @throws ListIndexException
* @throws InvalidListException
* @throws AuthenticationRequiredException if user is not authenticated and is
* required to be.
*/
@Override
public SecuredRDFList removeHead() throws UpdateDeniedException, DeleteDeniedException, AuthenticationRequiredException {
checkUpdate();
final ExtendedIterator<RDFList> iter = getFilteredRDFListIterator(Action.Read);
try {
if (!iter.hasNext()) {
throw new EmptyListException("Attempted to delete the head of a nil list");
}
final RDFList cell = iter.next();
final Statement s = cell.getRequiredProperty(RDF.first);
checkDelete(s);
return SecuredRDFListImpl.getInstance(getModel(), baseRemove(cell));
} finally {
iter.close();
}
}
use of org.apache.jena.rdf.model.EmptyListException in project jena by apache.
the class SecuredRDFListTest method testSetHead.
@Test
public void testSetHead() {
try {
RDFNode result = getSecuredRDFList().setHead(newResource1);
if (!shouldRead() || !securityEvaluator.evaluate(Action.Update)) {
fail("Should have thrown AccessDeniedException");
}
assertEquals(resource1, result);
List<RDFNode> lst = ((RDFList) getBaseRDFNode()).asJavaList();
Iterator<RDFNode> iter = lst.iterator();
assertEquals(newResource1, iter.next());
assertEquals(resource2, iter.next());
assertEquals(resource3, iter.next());
assertEquals(resource4, iter.next());
assertFalse(iter.hasNext());
} catch (final AccessDeniedException e) {
if (shouldRead() && securityEvaluator.evaluate(Action.Update) && securityEvaluator.evaluate(Action.Delete)) {
fail("Should not have thrown AccessDeniedException");
}
} catch (final EmptyListException e) {
if (securityEvaluator.evaluate(Action.Read)) {
fail("Should not have thrown EmptyListException");
}
}
}
use of org.apache.jena.rdf.model.EmptyListException in project jena by apache.
the class SecuredRDFListTest method testRemoveHead.
@Test
public void testRemoveHead() {
try {
RDFList rdfList = getSecuredRDFList().removeHead();
if (!shouldRead() || !securityEvaluator.evaluate(Action.Update) || !securityEvaluator.evaluate(Action.Delete)) {
fail("Should have thrown AccessDeniedException");
}
Iterator<RDFNode> iter = rdfList.asJavaList().iterator();
assertEquals(resource2, iter.next());
assertEquals(resource3, iter.next());
assertEquals(resource4, iter.next());
assertFalse(iter.hasNext());
} catch (final AccessDeniedException e) {
if (shouldRead() && securityEvaluator.evaluate(Action.Update) && securityEvaluator.evaluate(Action.Delete)) {
fail("Should not have thrown AccessDeniedException");
}
} catch (final EmptyListException e) {
if (securityEvaluator.evaluate(Action.Read)) {
fail("Should not have thrown EmptyListException");
}
}
}
Aggregations