Search in sources :

Example 6 with RDFList

use of org.apache.jena.rdf.model.RDFList 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");
        }
    }
}
Also used : AccessDeniedException(org.apache.jena.shared.AccessDeniedException) RDFList(org.apache.jena.rdf.model.RDFList) EmptyListException(org.apache.jena.rdf.model.EmptyListException) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test)

Example 7 with RDFList

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

the class RDFListIterator method next.

@Override
public RDFList next() {
    if (hasNext()) {
        found = null;
        final RDFList retval = current;
        incrementCurrent();
        return retval;
    }
    throw new NoSuchElementException();
}
Also used : RDFList(org.apache.jena.rdf.model.RDFList) NoSuchElementException(java.util.NoSuchElementException)

Example 8 with RDFList

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

the class SecuredRDFListTest method testAppendRDFList.

@Test
public void testAppendRDFList() {
    final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
    Model m = ModelFactory.createDefaultModel();
    RDFList lst = m.createList(newResource1, newResource2, newResource3, newResource4);
    try {
        SecuredRDFList actual = (SecuredRDFList) getSecuredRDFList().append(lst);
        if (!securityEvaluator.evaluate(perms) || !shouldRead()) {
            fail("Should have thrown AccessDeniedException");
        }
        Iterator<RDFNode> iter = ((RDFList) actual.getBaseItem()).iterator();
        if (securityEvaluator.evaluate(Action.Read)) {
            assertEquals(resource1, iter.next());
            assertEquals(resource2, iter.next());
            assertEquals(resource3, iter.next());
            assertEquals(resource4, iter.next());
        }
        assertEquals(newResource1, iter.next());
        assertEquals(newResource2, iter.next());
        assertEquals(newResource3, iter.next());
        assertEquals(newResource4, iter.next());
        assertFalse(iter.hasNext());
    } catch (final AccessDeniedException e) {
        if (securityEvaluator.evaluate(perms) && shouldRead()) {
            fail("Should not have thrown AccessDeniedException");
        }
    }
}
Also used : Action(org.apache.jena.permissions.SecurityEvaluator.Action) AccessDeniedException(org.apache.jena.shared.AccessDeniedException) RDFList(org.apache.jena.rdf.model.RDFList) Model(org.apache.jena.rdf.model.Model) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test)

Example 9 with RDFList

use of org.apache.jena.rdf.model.RDFList 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");
        }
    }
}
Also used : AccessDeniedException(org.apache.jena.shared.AccessDeniedException) RDFList(org.apache.jena.rdf.model.RDFList) EmptyListException(org.apache.jena.rdf.model.EmptyListException) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test)

Example 10 with RDFList

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

the class SecuredRDFListTest method testReplace.

@Test
public void testReplace() {
    try {
        RDFNode result = getSecuredRDFList().replace(1, newResource1);
        if (!shouldRead() || !securityEvaluator.evaluate(Action.Update)) {
            fail("Should have thrown AccessDeniedException");
        }
        assertEquals(resource2, result);
        List<RDFNode> lst = ((RDFList) getBaseRDFNode()).asJavaList();
        Iterator<RDFNode> iter = lst.iterator();
        assertEquals(resource1, iter.next());
        assertEquals(newResource1, 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 ListIndexException e) {
        if (securityEvaluator.evaluate(Action.Read)) {
            fail("Should not have thrown ListIndexException");
        }
    }
}
Also used : AccessDeniedException(org.apache.jena.shared.AccessDeniedException) RDFList(org.apache.jena.rdf.model.RDFList) ListIndexException(org.apache.jena.rdf.model.ListIndexException) RDFNode(org.apache.jena.rdf.model.RDFNode) Test(org.junit.Test)

Aggregations

RDFList (org.apache.jena.rdf.model.RDFList)13 RDFNode (org.apache.jena.rdf.model.RDFNode)8 SecuredRDFList (org.apache.jena.permissions.model.SecuredRDFList)6 Test (org.junit.Test)5 AccessDeniedException (org.apache.jena.shared.AccessDeniedException)4 Triple (org.apache.jena.graph.Triple)3 EmptyListException (org.apache.jena.rdf.model.EmptyListException)3 ListIndexException (org.apache.jena.rdf.model.ListIndexException)3 SecuredRDFNode (org.apache.jena.permissions.model.SecuredRDFNode)2 Statement (org.apache.jena.rdf.model.Statement)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 NoSuchElementException (java.util.NoSuchElementException)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Assembler (org.apache.jena.assembler.Assembler)1 Mode (org.apache.jena.assembler.Mode)1 AssemblerBase (org.apache.jena.assembler.assemblers.AssemblerBase)1 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)1