http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/graph/BulkUpdateHandlerTest.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/BulkUpdateHandlerTest.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/BulkUpdateHandlerTest.java deleted file mode 100644 index 46f8b0b..0000000 --- a/jena-permissions/src/test/java/org/apache/jena/security/graph/BulkUpdateHandlerTest.java +++ /dev/null @@ -1,372 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jena.security.graph; - -import java.util.Arrays; -import java.util.Set; - -import org.junit.Assert; -import org.apache.jena.graph.Graph ; -import org.apache.jena.graph.NodeFactory ; -import org.apache.jena.graph.Triple ; -import org.apache.jena.graph.impl.CollectionGraph ; -import org.apache.jena.security.AccessDeniedException; -import org.apache.jena.security.Factory; -import org.apache.jena.security.SecurityEvaluator; -import org.apache.jena.security.SecurityEvaluatorParameters; -import org.apache.jena.security.SecurityEvaluator.Action; -import org.apache.jena.security.graph.SecuredBulkUpdateHandler; -import org.apache.jena.security.graph.SecuredGraph; -import org.apache.jena.sparql.graph.GraphFactory ; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith( value = SecurityEvaluatorParameters.class ) -public class BulkUpdateHandlerTest -{ - protected SecuredBulkUpdateHandler handler; - private final SecurityEvaluator securityEvaluator; - private final Triple[] tripleArray; - private final Set<Action> deleteAndUpdate; - private final Set<Action> createAndUpdate; - - public BulkUpdateHandlerTest( final SecurityEvaluator securityEvaluator ) - { - this.securityEvaluator = securityEvaluator; - - tripleArray = new Triple[] { - new Triple(NodeFactory.createURI("http://example.com/1"), - NodeFactory.createURI("http://example.com/v"), - NodeFactory.createAnon()), - new Triple(NodeFactory.createURI("http://example.com/2"), - NodeFactory.createURI("http://example.com/v"), - NodeFactory.createAnon()), - new Triple(NodeFactory.createURI("http://example.com/3"), - NodeFactory.createURI("http://example.com/v"), - NodeFactory.createAnon()) }; - createAndUpdate = SecurityEvaluator.Util.asSet(new Action[] { - Action.Create, Action.Update }); - deleteAndUpdate = SecurityEvaluator.Util.asSet(new Action[] { - Action.Delete, Action.Update }); - } - - @Before - public void setup() - { - final Graph g = GraphFactory.createDefaultGraph(); - - final SecuredGraph sg = Factory.getInstance(securityEvaluator, - "http://example.com/testGraph", g); - handler = sg.getBulkUpdateHandler(); - } - - @Test - public void testAdd() - { - Object principal = securityEvaluator.getPrincipal(); - try - { - handler.add(tripleArray); - if (!securityEvaluator.evaluate(principal, createAndUpdate, - handler.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, createAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - handler.add(Arrays.asList(tripleArray)); - if (!securityEvaluator.evaluate(principal, createAndUpdate, - handler.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, createAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - handler.add(Arrays.asList(tripleArray).iterator()); - if (!securityEvaluator.evaluate(principal, createAndUpdate, - handler.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, createAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - handler.add(new CollectionGraph(Arrays.asList(tripleArray))); - if (!securityEvaluator.evaluate(principal, createAndUpdate, - handler.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, createAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - handler.add(new CollectionGraph(Arrays.asList(tripleArray))); - if (!securityEvaluator.evaluate(principal, createAndUpdate, - handler.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, createAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - handler.add(new CollectionGraph(Arrays.asList(tripleArray)), true); - if (!securityEvaluator.evaluate(principal, createAndUpdate, - handler.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, createAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testDelete() - { - Object principal = securityEvaluator.getPrincipal(); - try - { - handler.delete(tripleArray); - if (!securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - handler.delete(Arrays.asList(tripleArray)); - if (!securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - handler.delete(Arrays.asList(tripleArray).iterator()); - if (!securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - handler.delete(new CollectionGraph(Arrays.asList(tripleArray))); - if (!securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - handler.delete(new CollectionGraph(Arrays.asList(tripleArray)), - true); - if (!securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - } - - public void testRemove() - { - Object principal = securityEvaluator.getPrincipal(); - try - { - handler.remove(NodeFactory.createURI("http://example.com/1"), - NodeFactory.createURI("http://example.com/v"), NodeFactory.createAnon()); - if (!securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - public void testRemoveAll() - { - Object principal = securityEvaluator.getPrincipal(); - try - { - handler.removeAll(); - if (!securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, deleteAndUpdate, - handler.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - -}
http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/graph/CrossIDGraphEventManagerTest.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/CrossIDGraphEventManagerTest.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/CrossIDGraphEventManagerTest.java deleted file mode 100644 index b8da8e4..0000000 --- a/jena-permissions/src/test/java/org/apache/jena/security/graph/CrossIDGraphEventManagerTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jena.security.graph; - -import org.apache.jena.graph.Graph ; -import org.apache.jena.graph.GraphEventManager ; -import org.apache.jena.graph.NodeFactory ; -import org.apache.jena.graph.Triple ; -import org.apache.jena.security.Factory; -import org.apache.jena.security.StaticSecurityEvaluator; -import org.apache.jena.sparql.graph.GraphFactory ; -import org.junit.Assert; -import org.junit.Test; - -public class CrossIDGraphEventManagerTest { - - private final GraphEventManager manager; - private final Graph g; - private final SecuredGraph sg; - private final StaticSecurityEvaluator securityEvaluator; - - private final RecordingGraphListener annListener; - private final RecordingGraphListener bobListener; - - public CrossIDGraphEventManagerTest() { - this.securityEvaluator = new StaticSecurityEvaluator("ann"); - - g = GraphFactory.createDefaultGraph(); - g.add(new Triple(NodeFactory.createURI("urn:ann"), NodeFactory - .createURI("http://example.com/v"), NodeFactory.createAnon())); - g.add(new Triple(NodeFactory.createURI("urn:bob"), NodeFactory - .createURI("http://example.com/v"), NodeFactory.createAnon())); - g.add(new Triple(NodeFactory.createURI("urn:ann"), NodeFactory - .createURI("http://example.com/v2"), NodeFactory.createAnon())); - - sg = Factory.getInstance(securityEvaluator, - "http://example.com/testGraph", g); - manager = sg.getEventManager(); - annListener = new RecordingGraphListener(); - manager.register(annListener); - this.securityEvaluator.setUser("bob"); - bobListener = new RecordingGraphListener(); - manager.register(bobListener); - } - - @Test - public void notificationsTest() { - sg.add(new Triple(NodeFactory.createURI("urn:bob"), NodeFactory - .createURI("http://example.com/v2"), NodeFactory.createAnon())); - - Assert.assertTrue("Should recorded add", bobListener.isAdd()); - Assert.assertFalse("Should not have recorded add", annListener.isAdd()); - - sg.delete(new Triple(NodeFactory.createURI("urn:bob"), NodeFactory - .createURI("http://example.com/v2"), NodeFactory.createAnon())); - - Assert.assertTrue("Should recorded delete", bobListener.isDelete()); - Assert.assertFalse("Should not have recorded delete", - annListener.isDelete()); - } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/graph/GraphEventManagerTest.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/GraphEventManagerTest.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/GraphEventManagerTest.java deleted file mode 100644 index 10ffd42..0000000 --- a/jena-permissions/src/test/java/org/apache/jena/security/graph/GraphEventManagerTest.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jena.security.graph; - -import java.util.Arrays; -import java.util.Set; - -import org.apache.jena.graph.Graph ; -import org.apache.jena.graph.GraphEventManager ; -import org.apache.jena.graph.NodeFactory ; -import org.apache.jena.graph.Triple ; -import org.apache.jena.graph.impl.CollectionGraph ; -import org.apache.jena.security.Factory; -import org.apache.jena.security.MockSecurityEvaluator; -import org.apache.jena.security.SecurityEvaluator; -import org.apache.jena.security.SecurityEvaluatorParameters; -import org.apache.jena.security.SecurityEvaluator.Action; -import org.apache.jena.security.graph.SecuredGraph; -import org.apache.jena.sparql.graph.GraphFactory ; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Verifies that messages are properly filtered when sent to listeners. - * - */ -@RunWith( value = SecurityEvaluatorParameters.class ) -public class GraphEventManagerTest -{ - private final GraphEventManager manager; - private final Graph g; - private final SecuredGraph sg; - private final SecurityEvaluator securityEvaluator; - private Triple[] tripleArray; - - private final RecordingGraphListener listener; - - public GraphEventManagerTest( final MockSecurityEvaluator securityEvaluator ) - { - this.securityEvaluator = securityEvaluator; - g = GraphFactory.createDefaultGraph(); - - sg = Factory.getInstance(securityEvaluator, - "http://example.com/testGraph", g); - manager = sg.getEventManager(); - listener = new RecordingGraphListener(); - manager.register(listener); - - } - - @Test - @SuppressWarnings("deprecation") - public void notifyAddTest() - { - Object principal = securityEvaluator.getPrincipal(); - final Set<Action> ADD = SecurityEvaluator.Util.asSet(new Action[] { - Action.Create, Action.Read }); - g.add(tripleArray[0]); - if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode())) - { - Assert.assertTrue("Should recorded add", listener.isAdd()); - } - else - { - Assert.assertFalse("Should not have recorded add", listener.isAdd()); - } - g.delete(Triple.ANY); - listener.reset(); - - g.getBulkUpdateHandler().add(tripleArray); - if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode())) - { - Assert.assertTrue("Should recorded add", listener.isAdd()); - } - else - { - Assert.assertFalse("Should not have recorded add", listener.isAdd()); - } - g.delete(Triple.ANY); - listener.reset(); - - g.getBulkUpdateHandler().add(Arrays.asList(tripleArray)); - if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode())) - { - Assert.assertTrue("Should recorded add", listener.isAdd()); - } - else - { - Assert.assertFalse("Should not have recorded add", listener.isAdd()); - } - g.delete(Triple.ANY); - listener.reset(); - - g.getBulkUpdateHandler().add(Arrays.asList(tripleArray).iterator()); - if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode())) - { - Assert.assertTrue("Should recorded add", listener.isAdd()); - } - else - { - Assert.assertFalse("Should not have recorded add", listener.isAdd()); - } - g.delete(Triple.ANY); - listener.reset(); - - g.getBulkUpdateHandler().add( - new CollectionGraph(Arrays.asList(tripleArray))); - if (securityEvaluator.evaluateAny(principal, ADD, sg.getModelNode())) - { - Assert.assertTrue("Should recorded add", listener.isAdd()); - } - else - { - Assert.assertFalse("Should not have recorded add", listener.isAdd()); - } - g.delete(Triple.ANY); - listener.reset(); - } - - @SuppressWarnings("deprecation") - @Test - public void notifyDeleteTest() - { - Object principal = securityEvaluator.getPrincipal(); - final Set<Action> DELETE = SecurityEvaluator.Util.asSet(new Action[] { - Action.Delete, Action.Read }); - g.delete(tripleArray[0]); - if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode())) - { - Assert.assertTrue("Should have recorded delete", - listener.isDelete()); - } - else - { - Assert.assertFalse("Should not have recorded delete", - listener.isDelete()); - } - - listener.reset(); - - g.getBulkUpdateHandler().delete(tripleArray); - if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode())) - { - Assert.assertTrue("Should recorded delete", listener.isDelete()); - } - else - { - Assert.assertFalse("Should not have recorded delete", - listener.isDelete()); - } - listener.reset(); - - g.getBulkUpdateHandler().delete(Arrays.asList(tripleArray)); - if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode())) - { - Assert.assertTrue("Should recorded delete", listener.isDelete()); - } - else - { - Assert.assertFalse("Should not have recorded delete", - listener.isDelete()); - } - listener.reset(); - - g.getBulkUpdateHandler().delete(Arrays.asList(tripleArray).iterator()); - if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode())) - { - Assert.assertTrue("Should recorded delete", listener.isDelete()); - } - else - { - Assert.assertFalse("Should not have recorded delete", - listener.isDelete()); - } - listener.reset(); - - g.getBulkUpdateHandler().delete( - new CollectionGraph(Arrays.asList(tripleArray))); - if (securityEvaluator.evaluateAny(principal, DELETE, sg.getModelNode())) - { - Assert.assertTrue("Should recorded delete", listener.isDelete()); - } - else - { - Assert.assertFalse("Should not have recorded delete", - listener.isDelete()); - } - listener.reset(); - } - - @Test - public void notifyEventTest() - { - g.getEventManager().notifyEvent(g, "Foo"); - Assert.assertTrue("Should recorded delete", listener.isEvent()); - listener.reset(); - // final RecordingGraphListener listener2 = new - // RecordingGraphListener(); - // g.getEventManager().register(listener2); - sg.getEventManager().notifyEvent(sg, "Foo"); - Assert.assertTrue("Should recorded delete", listener.isEvent()); - // Assert.assertTrue("Should recorded delete", listener2.isEvent()); - listener.reset(); - - } - - @Before - public void setup() - { - tripleArray = new Triple[] { - new Triple(NodeFactory.createURI("http://example.com/1"), - NodeFactory.createURI("http://example.com/v"), - NodeFactory.createAnon()), - new Triple(NodeFactory.createURI("http://example.com/2"), - NodeFactory.createURI("http://example.com/v"), - NodeFactory.createAnon()), - new Triple(NodeFactory.createURI("http://example.com/3"), - NodeFactory.createURI("http://example.com/v"), - NodeFactory.createAnon()) }; - - } -} http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/graph/MemGraphTest.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/MemGraphTest.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/MemGraphTest.java deleted file mode 100644 index 3f4685a..0000000 --- a/jena-permissions/src/test/java/org/apache/jena/security/graph/MemGraphTest.java +++ /dev/null @@ -1,387 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jena.security.graph; - -import java.lang.reflect.Method; -import java.util.Set; - -import org.apache.jena.graph.* ; -import org.apache.jena.security.AccessDeniedException; -import org.apache.jena.security.EqualityTester; -import org.apache.jena.security.MockSecurityEvaluator; -import org.apache.jena.security.SecurityEvaluator; -import org.apache.jena.security.SecurityEvaluatorParameters; -import org.apache.jena.security.SecurityEvaluator.Action; -import org.apache.jena.security.graph.SecuredBulkUpdateHandler; -import org.apache.jena.security.graph.SecuredGraph; -import org.apache.jena.sparql.graph.GraphFactory ; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith( value = SecurityEvaluatorParameters.class ) -public class MemGraphTest -{ - private SecuredGraph securedGraph; - private final MockSecurityEvaluator securityEvaluator; - private Node s; - private Node p; - private Node o; - private Triple t; - - private Graph baseGraph; - - public MemGraphTest( final MockSecurityEvaluator securityEvaluator ) - { - this.securityEvaluator = securityEvaluator; - } - - protected Graph createGraph() throws Exception - { - return GraphFactory.createDefaultGraph(); - } - - @SuppressWarnings("deprecation") - @Before - public void setUp() throws Exception - { - baseGraph = createGraph(); - baseGraph.getBulkUpdateHandler().removeAll(); - securedGraph = org.apache.jena.security.Factory - .getInstance(securityEvaluator, - "http://example.com/securedGraph", baseGraph); - s = NodeFactory.createURI("http://example.com/securedGraph/s"); - p = NodeFactory.createURI("http://example.com/securedGraph/p"); - o = NodeFactory.createURI("http://example.com/securedGraph/o"); - t = new Triple(s, p, o); - baseGraph.add(t); - } - - @Test - public void testBulkUpdateHandler() throws Exception - { - final BulkUpdateHandler buh = securedGraph.getBulkUpdateHandler(); - Assert.assertNotNull("BulkUpdateHandler may not be null", buh); - Assert.assertTrue("BulkUpdateHandler should be secured", - buh instanceof SecuredBulkUpdateHandler); - final BulkUpdateHandlerTest buhTest = new BulkUpdateHandlerTest( - securityEvaluator) { - @Override - public void setup() - { - this.handler = (SecuredBulkUpdateHandler) buh; - } - }; - for (final Method m : buhTest.getClass().getMethods()) - { - if (m.isAnnotationPresent(Test.class)) - { - buhTest.setup(); - m.invoke(buhTest); - } - } - } - - @Test - public void testContainsNodes() throws Exception - { - try - { - Assert.assertTrue(securedGraph.contains(s, p, o)); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testContainsTriple() throws Exception - { - try - { - Assert.assertTrue(securedGraph.contains(t)); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - } - - @Test - public void testDelete() throws Exception - { - final Set<Action> UD = SecurityEvaluator.Util.asSet(new Action[] { - Action.Update, Action.Delete }); - try - { - securedGraph.delete(t); - - if (!securityEvaluator.evaluate(UD)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - Assert.assertEquals(0, baseGraph.size()); - - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(UD)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testDependsOn() throws Exception - { - try - { - Assert.assertFalse(securedGraph.dependsOn(GraphFactory - .createDefaultGraph())); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - try - { - Assert.assertTrue(securedGraph.dependsOn(baseGraph)); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testFindNodes() throws Exception - { - try - { - - Assert.assertFalse(securedGraph.find(Node.ANY, Node.ANY, Node.ANY) - .toList().isEmpty()); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testFindTriple() throws Exception - { - try - { - Assert.assertFalse(securedGraph.find(t).toList().isEmpty()); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testGetPrefixMapping() throws Exception - { - SecuredPrefixMappingTest.runTests(securityEvaluator, - securedGraph.getPrefixMapping()); - } - - @Test - public void testInequality() - { - EqualityTester - .testInequality("proxy and base", securedGraph, baseGraph); - final Graph g2 = org.apache.jena.security.graph.impl.Factory - .getInstance(securityEvaluator, - "http://example.com/securedGraph", baseGraph); - EqualityTester.testEquality("proxy and proxy2", securedGraph, g2); - EqualityTester.testInequality("base and proxy2", baseGraph, g2); - } - - @Test - public void testIsIsomorphicWith() throws Exception - { - try - { - Assert.assertFalse(securedGraph.isIsomorphicWith(GraphFactory - .createDefaultGraph())); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - try - { - Assert.assertTrue(securedGraph.isIsomorphicWith(baseGraph)); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testSize() throws Exception - { - try - { - Assert.assertEquals(1, securedGraph.size()); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testTripleMatch() throws Exception - { - try - { - Assert.assertFalse(securedGraph.find(new TripleMatch() { - - @Override - public Triple asTriple() - { - return Triple.ANY; - } - - @Override - public Node getMatchObject() - { - return Node.ANY; - } - - @Override - public Node getMatchPredicate() - { - return Node.ANY; - } - - @Override - public Node getMatchSubject() - { - return Node.ANY; - } - }).toList().isEmpty()); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/graph/RecordingGraphListener.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/RecordingGraphListener.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/RecordingGraphListener.java deleted file mode 100644 index d65d814..0000000 --- a/jena-permissions/src/test/java/org/apache/jena/security/graph/RecordingGraphListener.java +++ /dev/null @@ -1,124 +0,0 @@ -package org.apache.jena.security.graph; - -import java.util.Iterator; -import java.util.List; - -import org.apache.jena.graph.Graph ; -import org.apache.jena.graph.GraphListener ; -import org.apache.jena.graph.Triple ; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -public class RecordingGraphListener implements GraphListener -{ - - private boolean add; - private boolean delete; - private boolean event; - - public boolean isAdd() - { - return add; - } - - public boolean isDelete() - { - return delete; - } - - public boolean isEvent() - { - return event; - } - - @Override - public void notifyAddArray( final Graph g, final Triple[] triples ) - { - add = true; - } - - @Override - public void notifyAddGraph( final Graph g, final Graph added ) - { - add = true; - } - - @Override - public void notifyAddIterator( final Graph g, final Iterator<Triple> it ) - { - add = true; - } - - @Override - public void notifyAddList( final Graph g, final List<Triple> triples ) - { - add = true; - } - - @Override - public void notifyAddTriple( final Graph g, final Triple t ) - { - add = true; - } - - @Override - public void notifyDeleteArray( final Graph g, final Triple[] triples ) - { - delete = true; - } - - @Override - public void notifyDeleteGraph( final Graph g, final Graph removed ) - { - delete = true; - } - - @Override - public void notifyDeleteIterator( final Graph g, - final Iterator<Triple> it ) - { - delete = true; - } - - @Override - public void notifyDeleteList( final Graph g, final List<Triple> L ) - { - delete = true; - } - - @Override - public void notifyDeleteTriple( final Graph g, final Triple t ) - { - delete = true; - } - - @Override - public void notifyEvent( final Graph source, final Object value ) - { - event = true; - } - - public void reset() - { - add = false; - delete = false; - event = false; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/graph/SecuredPrefixMappingTest.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/SecuredPrefixMappingTest.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/SecuredPrefixMappingTest.java deleted file mode 100644 index 7ad4e84..0000000 --- a/jena-permissions/src/test/java/org/apache/jena/security/graph/SecuredPrefixMappingTest.java +++ /dev/null @@ -1,440 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jena.security.graph; - -import java.lang.reflect.Method; -import java.util.HashMap; - -import org.junit.Assert; -import org.apache.jena.graph.Graph ; -import org.apache.jena.security.AccessDeniedException; -import org.apache.jena.security.Factory; -import org.apache.jena.security.SecurityEvaluator; -import org.apache.jena.security.SecurityEvaluatorParameters; -import org.apache.jena.security.SecurityEvaluator.Action; -import org.apache.jena.security.graph.SecuredGraph; -import org.apache.jena.security.graph.SecuredPrefixMapping; -import org.apache.jena.shared.PrefixMapping ; -import org.apache.jena.shared.impl.PrefixMappingImpl ; -import org.apache.jena.sparql.graph.GraphFactory ; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith( value = SecurityEvaluatorParameters.class ) -public class SecuredPrefixMappingTest -{ - public static void runTests( final SecurityEvaluator securityEvaluator, - final PrefixMapping prefixMapping ) throws Exception - { - final PrefixMapping pm = prefixMapping; - Assert.assertNotNull("PrefixMapping may not be null", pm); - Assert.assertTrue("PrefixMapping should be secured", - pm instanceof SecuredPrefixMapping); - final SecuredPrefixMappingTest pmTest = new SecuredPrefixMappingTest( - securityEvaluator) { - @Override - public void setup() - { - this.securedMapping = (SecuredPrefixMapping) pm; - } - }; - Method lockTest = null; - for (final Method m : pmTest.getClass().getMethods()) - { - if (m.isAnnotationPresent(Test.class)) - { - // lock test must come last - if (m.getName().equals("testLock")) - { - lockTest = m; - } - else - { - pmTest.setup(); - m.invoke(pmTest); - } - - } - } - Assert.assertNotNull( "Did not find 'testLock' method", lockTest ); - pmTest.setup(); - lockTest.invoke(pmTest); - - } - - private final SecurityEvaluator securityEvaluator; - private final Object principal; - - protected SecuredPrefixMapping securedMapping; - - public SecuredPrefixMappingTest( final SecurityEvaluator securityEvaluator ) - { - this.securityEvaluator = securityEvaluator; - this.principal = securityEvaluator.getPrincipal(); - } - - @Before - public void setup() - { - final Graph g = GraphFactory.createDefaultGraph(); - - final SecuredGraph sg = Factory.getInstance(securityEvaluator, - "http://example.com/testGraph", g); - this.securedMapping = sg.getPrefixMapping(); - } - - @Test - public void testExpandPrefix() - { - try - { - securedMapping.expandPrefix("foo"); - if (!securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testGetNsPrefixMap() - { - try - { - securedMapping.getNsPrefixMap(); - if (!securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testGetNsPrefixURI() - { - try - { - securedMapping.getNsPrefixURI("foo"); - if (!securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - } - - @Test - public void testGetNsURIPrefix() - { - try - { - securedMapping.getNsURIPrefix("http://example.com/foo"); - if (!securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testLock() - { - try - { - securedMapping.lock(); - if (!securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - } - - @Test - public void testQnameFor() - { - try - { - securedMapping.qnameFor("http://example.com/foo/bar"); - if (!securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testRemoveNsPrefix() - { - try - { - securedMapping.removeNsPrefix("foo"); - if (!securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - } - - @Test - public void testSamePrefixMappingAs() - { - try - { - securedMapping.samePrefixMappingAs(GraphFactory - .createDefaultGraph().getPrefixMapping()); - if (!securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testSetNsPrefix() - { - try - { - securedMapping.setNsPrefix("foo", "http://example.com/foo"); - if (!securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - securedMapping.setNsPrefixes(GraphFactory.createDefaultGraph() - .getPrefixMapping()); - if (!securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - securedMapping.setNsPrefixes(new HashMap<String, String>()); - if (!securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testShortForm() - { - try - { - securedMapping.shortForm("http://example.com/foo/bar"); - if (!securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Read, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testWithDefaultMappings() - { - PrefixMapping pm = new PrefixMappingImpl(); - pm.setNsPrefix( "example", "http://example.com"); - try - { - // make sure that it must update - securedMapping.withDefaultMappings(pm); - if (!securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testWithDefaultMappingsNoAdd() - { - PrefixMapping pm = new PrefixMappingImpl(); - try - { - // make sure that it must update - securedMapping.withDefaultMappings(pm); -// if (!securityEvaluator.evaluate(Action.Update, -// securedMapping.getModelNode())) -// { -// Assert.fail("Should have thrown AccessDenied Exception"); -// } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(principal, Action.Update, - securedMapping.getModelNode())) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } -} http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/graph/TDBGraphTest.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/test/java/org/apache/jena/security/graph/TDBGraphTest.java b/jena-permissions/src/test/java/org/apache/jena/security/graph/TDBGraphTest.java deleted file mode 100644 index 5fb7178..0000000 --- a/jena-permissions/src/test/java/org/apache/jena/security/graph/TDBGraphTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jena.security.graph; - -import java.io.File; -import java.io.IOException; - -import org.apache.jena.graph.Graph ; -import org.apache.jena.security.MockSecurityEvaluator; -import org.apache.jena.sparql.core.DatasetGraph ; -import org.apache.jena.tdb.TDB ; -import org.apache.jena.tdb.TDBFactory ; -import org.junit.After; - -public class TDBGraphTest extends MemGraphTest -{ - - private DatasetGraph dsGraph; - - private File f; - - public TDBGraphTest( final MockSecurityEvaluator securityEvaluator ) - { - super(securityEvaluator); - } - - @Override - protected Graph createGraph() throws IOException - { - TDB.init(); - dsGraph = TDBFactory.createDataset().asDatasetGraph(); - return dsGraph.getDefaultGraph(); - } - - @After - public void tearDown() - { - TDB.sync(dsGraph); - dsGraph.close(); - TDB.closedown(); - } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredAltTest.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredAltTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredAltTest.java deleted file mode 100644 index 4a33885..0000000 --- a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredAltTest.java +++ /dev/null @@ -1,657 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jena.security.model; - -import java.util.Set; - -import org.apache.jena.rdf.model.Alt ; -import org.apache.jena.rdf.model.ResourceFactory ; -import org.apache.jena.security.AccessDeniedException; -import org.apache.jena.security.MockSecurityEvaluator; -import org.apache.jena.security.SecurityEvaluator; -import org.apache.jena.security.SecurityEvaluatorParameters; -import org.apache.jena.security.SecurityEvaluator.Action; -import org.apache.jena.security.model.SecuredAlt; -import org.apache.jena.security.model.impl.SecuredAltImpl; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith( value = SecurityEvaluatorParameters.class ) -public class SecuredAltTest extends SecuredContainerTest -{ - private Alt alt; - - public SecuredAltTest( final MockSecurityEvaluator securityEvaluator ) - { - super(securityEvaluator); - } - - private SecuredAlt getSecuredAlt() - { - return (SecuredAlt) getSecuredRDFNode(); - } - - @Override - @Before - public void setup() - { - super.setup(); - alt = baseModel.getAlt("http://example.com/testContainer"); - setSecuredRDFNode(SecuredAltImpl.getInstance(securedModel, alt), alt); - } - - /** - * @sec.graph Read - * @sec.triple Read SecTriple(this, RDF.li(1), o ) - * @throws AccessDeniedException - */ - @Test - public void testGetDefault() - { - alt.add("SomeDummyItem"); - try - { - getSecuredAlt().getDefault(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredAlt().getDefaultAlt(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredAlt().getDefaultBag(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredAlt().getDefaultSeq(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testGetDefaultBoolean() - { - alt.add(true); - try - { - getSecuredAlt().getDefaultBoolean(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testGetDefaultByte() - { - alt.add(Byte.MAX_VALUE); - try - { - getSecuredAlt().getDefaultByte(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testGetDefaultChar() - { - alt.add('c'); - try - { - getSecuredAlt().getDefaultChar(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testGetDefaultDouble() - { - alt.add(3.14d); - try - { - getSecuredAlt().getDefaultDouble(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testGetDefaultFloat() - { - alt.add(3.14f); - try - { - getSecuredAlt().getDefaultFloat(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testGetDefaultInt() - { - alt.add(2); - try - { - getSecuredAlt().getDefaultInt(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testGetDefaultLanguage() - { - alt.add("SomeDummyItem"); - try - { - getSecuredAlt().getDefaultLanguage(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredAlt().getDefaultLiteral(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - } - - @Test - public void testGetDefaultLong() - { - alt.add(3L); - - try - { - getSecuredAlt().getDefaultLong(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testGetDefaultResource() - { - alt.setDefault(ResourceFactory - .createResource("http://example.com/exampleResourec")); - try - { - getSecuredAlt().getDefaultResource(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - /* - * try - * { - * ResourceF f = ResourceFactory.getInstance(); - * getSecuredAlt().getDefaultResource( f ); - * if (!securityEvaluator.evaluate(Action.Read)) - * { - * Assert.fail("Should have thrown AccessDenied Exception"); - * } - * } - * catch (final AccessDeniedException e) - * { - * if (securityEvaluator.evaluate(Action.Read)) - * { - * Assert.fail(String - * .format("Should not have thrown AccessDenied Exception: %s - %s", - * e, e.getTriple())); - * } - * } - */ - - @Test - public void testGetDefaultShort() - { - alt.setDefault(Short.MAX_VALUE); - try - { - getSecuredAlt().getDefaultShort(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testGetDefaultString() - { - alt.setDefault("Hello World"); - try - { - getSecuredAlt().getDefaultString(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - } - - @Test - public void testSetDefaultBoolean() - { - final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { - Action.Update, Action.Create }); - try - { - getSecuredAlt().setDefault(true); - if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() )) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testSetDefaultChar() - { - final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { - Action.Update, Action.Create }); - try - { - getSecuredAlt().setDefault('c'); - if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() )) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testSetDefaultDouble() - { - final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { - Action.Update, Action.Create }); - try - { - getSecuredAlt().setDefault(3.14d); - if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() )) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testSetDefaultFloat() - { - final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { - Action.Update, Action.Create }); - try - { - getSecuredAlt().setDefault(3.14f); - if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() )) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testSetDefaultLong() - { - final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { - Action.Update, Action.Create }); - try - { - getSecuredAlt().setDefault(2L); - if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() )) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testSetDefaultObject() - { - final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { - Action.Update, Action.Create }); - try - { - final Object o = 2; - getSecuredAlt().setDefault(o); - if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() )) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testSetDefaultResource() - { - final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { - Action.Update, Action.Create }); - try - { - getSecuredAlt().setDefault( - ResourceFactory - .createResource("http://example.com/resource")); - if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() )) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testSetDefaultString() - { - final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { - Action.Update, Action.Create }); - try - { - getSecuredAlt().setDefault("test"); - if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() )) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testSetDefaultStringAndLang() - { - final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { - Action.Update, Action.Create }); - try - { - getSecuredAlt().setDefault("dos", "es"); - if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() )) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredBagTest.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredBagTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredBagTest.java deleted file mode 100644 index 6c3ac5c..0000000 --- a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredBagTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jena.security.model; - -import org.apache.jena.rdf.model.Bag ; -import org.apache.jena.security.MockSecurityEvaluator; -import org.apache.jena.security.SecurityEvaluatorParameters; -import org.apache.jena.security.model.impl.SecuredBagImpl; -import org.junit.Before; -import org.junit.runner.RunWith; - -@RunWith( value = SecurityEvaluatorParameters.class ) -public class SecuredBagTest extends SecuredContainerTest -{ - - public SecuredBagTest( final MockSecurityEvaluator securityEvaluator ) - { - super(securityEvaluator); - } - - @Override - @Before - public void setup() - { - super.setup(); - final Bag bag = baseModel.getBag("http://example.com/testContainer"); - bag.add("SomeDummyItem"); - setSecuredRDFNode(SecuredBagImpl.getInstance(securedModel, bag), bag); - } - -} http://git-wip-us.apache.org/repos/asf/jena/blob/c4b0113d/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredContainerTest.java ---------------------------------------------------------------------- diff --git a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredContainerTest.java b/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredContainerTest.java deleted file mode 100644 index 9f00757..0000000 --- a/jena-permissions/src/test/java/org/apache/jena/security/model/SecuredContainerTest.java +++ /dev/null @@ -1,480 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.jena.security.model; - -import java.util.Set; - -import org.apache.jena.rdf.model.Container ; -import org.apache.jena.rdf.model.ResourceFactory ; -import org.apache.jena.rdf.model.Statement ; -import org.apache.jena.security.AccessDeniedException; -import org.apache.jena.security.MockSecurityEvaluator; -import org.apache.jena.security.SecurityEvaluator; -import org.apache.jena.security.SecurityEvaluatorParameters; -import org.apache.jena.security.SecurityEvaluator.Action; -import org.apache.jena.security.model.SecuredContainer; -import org.apache.jena.security.model.impl.SecuredContainerImpl; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith( value = SecurityEvaluatorParameters.class ) -public abstract class SecuredContainerTest extends SecuredResourceTest -{ - - public SecuredContainerTest( final MockSecurityEvaluator securityEvaluator ) - { - super(securityEvaluator); - } - - private SecuredContainer getSecuredContainer() - { - return (SecuredContainer) getSecuredRDFNode(); - } - - @Override - @Before - public void setup() - { - super.setup(); - final Container container = baseModel - .getBag("http://example.com/testContainer"); - container.add("SomeDummyItem"); - setSecuredRDFNode( - SecuredContainerImpl.getInstance(securedModel, container), - container); - } - - @Test - public void test() - { - try - { - getSecuredContainer().size(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - /** - * @sec.graph Update - * @sec.triple Create SecTriple( this, RDF.li, o ); - * @throws AccessDeniedException - */ - @Test - public void testAdd() - { - final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { - Action.Update, Action.Create }); - try - { - getSecuredContainer().add(true); - if (!securityEvaluator.evaluate(perms)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().add('c'); - if (!securityEvaluator.evaluate(perms)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().add(3.14D); - if (!securityEvaluator.evaluate(perms)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().add(3.14F); - if (!securityEvaluator.evaluate(perms)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().add(2L); - if (!securityEvaluator.evaluate(perms)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - final Object o = Integer.valueOf("1234"); - try - { - getSecuredContainer().add(o); - if (!securityEvaluator.evaluate(perms)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().add( - ResourceFactory - .createResource("http://example.com/testResource")); - if (!securityEvaluator.evaluate(perms)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().add("foo"); - if (!securityEvaluator.evaluate(perms)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().add("dos", "esp"); - if (!securityEvaluator.evaluate(perms)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - } - - @Test - public void testContains() - { - try - { - getSecuredContainer().contains(true); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().contains('c'); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().contains(3.14D); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().contains(3.14F); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().contains(2L); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - final Object o = Integer.valueOf("1234"); - try - { - getSecuredContainer().contains(o); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().contains( - ResourceFactory - .createResource("http://example.com/testResource")); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().contains("foo"); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - try - { - getSecuredContainer().contains("dos", "esp"); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testIterator() - { - try - { - getSecuredContainer().iterator(); - if (!securityEvaluator.evaluate(Action.Read)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(Action.Read)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - } - - @Test - public void testRemove() - { - final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { - Action.Update, Action.Delete }); - final Statement s = baseModel.listStatements().next(); - try - { - getSecuredContainer().remove(s); - if (!securityEvaluator.evaluate(perms)) - { - Assert.fail("Should have thrown AccessDenied Exception"); - } - } - catch (final AccessDeniedException e) - { - if (securityEvaluator.evaluate(perms)) - { - Assert.fail(String - .format("Should not have thrown AccessDenied Exception: %s - %s", - e, e.getTriple())); - } - } - - } - -}
