You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by cl...@apache.org on 2015/07/17 20:06:09 UTC
[02/10] jena git commit: Updates for JENA-990 Modified permissions to
use new Exceptions. Added ReadDeniedException Added UpdateDeniedException
http://git-wip-us.apache.org/repos/asf/jena/blob/fcf71889/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredSeqTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredSeqTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredSeqTest.java
index 54c365a..66c1468 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredSeqTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredSeqTest.java
@@ -19,44 +19,42 @@ package org.apache.jena.permissions.model;
import java.util.Set;
-import org.apache.jena.permissions.AccessDeniedException;
import org.apache.jena.permissions.MockSecurityEvaluator;
+import org.apache.jena.permissions.ReadDeniedException;
import org.apache.jena.permissions.SecurityEvaluator;
import org.apache.jena.permissions.SecurityEvaluatorParameters;
import org.apache.jena.permissions.SecurityEvaluator.Action;
+import org.apache.jena.permissions.UpdateDeniedException;
import org.apache.jena.permissions.model.SecuredAlt;
import org.apache.jena.permissions.model.SecuredBag;
import org.apache.jena.permissions.model.SecuredSeq;
import org.apache.jena.permissions.model.impl.SecuredSeqImpl;
-import org.apache.jena.rdf.model.Alt ;
-import org.apache.jena.rdf.model.Bag ;
-import org.apache.jena.rdf.model.ResourceFactory ;
-import org.apache.jena.rdf.model.Seq ;
+import org.apache.jena.rdf.model.Alt;
+import org.apache.jena.rdf.model.Bag;
+import org.apache.jena.rdf.model.ResourceFactory;
+import org.apache.jena.rdf.model.Seq;
+import org.apache.jena.shared.AccessDeniedException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredSeqTest extends SecuredContainerTest
-{
+@RunWith(value = SecurityEvaluatorParameters.class)
+public class SecuredSeqTest extends SecuredContainerTest {
private Seq seq;
- public SecuredSeqTest( final MockSecurityEvaluator securityEvaluator )
- {
+ public SecuredSeqTest(final MockSecurityEvaluator securityEvaluator) {
super(securityEvaluator);
// TODO Auto-generated constructor stub
}
- private SecuredSeq getSecuredSeq()
- {
+ private SecuredSeq getSecuredSeq() {
return (SecuredSeq) getSecuredRDFNode();
}
@Override
@Before
- public void setup()
- {
+ public void setup() {
super.setup();
seq = baseModel.getSeq("http://example.com/testContainer");
setSecuredRDFNode(SecuredSeqImpl.getInstance(securedModel, seq), seq);
@@ -64,217 +62,159 @@ public class SecuredSeqTest extends SecuredContainerTest
@Override
@Test
- public void testAdd()
- {
+ public void testAdd() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredSeq().add(2, true);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().add(2, 'c');
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().add(2, 3.14d);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().add(2, 3.14F);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().add(2, 3L);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
final Object o = Integer.MAX_VALUE;
getSecuredSeq().add(2, o);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().add(2, ResourceFactory.createResource());
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().add(2, "Waa hoo");
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().add(2, "dos", "es");
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
}
@Test
- public void testGetAlt()
- {
- try
- {
+ public void testGetAlt() {
+ try {
final Alt a = getSecuredSeq().getAlt(1);
Assert.assertTrue("Should be a secured Alt",
a instanceof SecuredAlt);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
}
@Test
- public void testGetBag()
- {
- try
- {
+ public void testGetBag() {
+ try {
final Bag a = getSecuredSeq().getBag(1);
Assert.assertTrue("Should be a secured Bag",
a instanceof SecuredBag);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -282,23 +222,17 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetBoolean()
- {
+ public void testGetBoolean() {
seq.add(2, true);
- try
- {
+ try {
getSecuredSeq().getBoolean(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -306,23 +240,17 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetByte()
- {
+ public void testGetByte() {
seq.add(2, Byte.MAX_VALUE);
- try
- {
+ try {
getSecuredSeq().getByte(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -330,23 +258,17 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetChar()
- {
+ public void testGetChar() {
seq.add(2, 'c');
- try
- {
+ try {
getSecuredSeq().getChar(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -354,23 +276,17 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetDouble()
- {
+ public void testGetDouble() {
seq.add(2, 3.14D);
- try
- {
+ try {
getSecuredSeq().getDouble(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -378,23 +294,17 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetFloat()
- {
+ public void testGetFloat() {
seq.add(2, 3.14F);
- try
- {
+ try {
getSecuredSeq().getFloat(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -402,23 +312,17 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetInt()
- {
+ public void testGetInt() {
seq.add(2, 2);
- try
- {
+ try {
getSecuredSeq().getInt(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -426,23 +330,17 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetLanguage()
- {
+ public void testGetLanguage() {
seq.add(2, "foo");
- try
- {
+ try {
getSecuredSeq().getLanguage(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -450,23 +348,17 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetLiteral()
- {
+ public void testGetLiteral() {
seq.add(2, "foo");
- try
- {
+ try {
getSecuredSeq().getLiteral(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -474,23 +366,17 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetLong()
- {
+ public void testGetLong() {
seq.add(2, 2L);
- try
- {
+ try {
getSecuredSeq().getLong(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -498,24 +384,18 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetObject()
- {
+ public void testGetObject() {
final Object o = Integer.MAX_VALUE;
seq.add(2, o);
- try
- {
+ try {
getSecuredSeq().getObject(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -523,73 +403,35 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetResource()
- {
+ public void testGetResource() {
seq.add(2, ResourceFactory.createResource());
- try
- {
+ try {
getSecuredSeq().getResource(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
}
- /*
- * @Test
- * public void testGetChar()
- * {
- * ResourceF f;
- * seq.add( 2, 'c' );
- * try
- * {
- * getSecuredSeq().getResource(2, 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 testGetSeq()
- {
+ public void testGetSeq() {
seq.add(2, 'c');
- try
- {
+ try {
getSecuredSeq().getSeq(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -597,23 +439,17 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetShort()
- {
+ public void testGetShort() {
seq.add(2, Short.MAX_VALUE);
- try
- {
+ try {
getSecuredSeq().getShort(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -621,23 +457,17 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testGetString()
- {
+ public void testGetString() {
seq.add(2, "Waaa hoo");
- try
- {
+ try {
getSecuredSeq().getString(2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -645,171 +475,125 @@ public class SecuredSeqTest extends SecuredContainerTest
}
@Test
- public void testIndexOf()
- {
- try
- {
+ public void testIndexOf() {
+ try {
getSecuredSeq().indexOf(true);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().indexOf('c');
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().indexOf(3.14D);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().indexOf(3.14F);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().indexOf(3L);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
final Object o = Integer.MAX_VALUE;
getSecuredSeq().indexOf(o);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq()
.indexOf(
ResourceFactory
.createResource("http://example.com/exampleResource"));
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().indexOf("waaa hooo");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().indexOf("dos", "es");
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -818,193 +602,141 @@ public class SecuredSeqTest extends SecuredContainerTest
@Override
@Test
- public void testRemove()
- {
+ public void testRemove() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Delete });
- try
- {
+ try {
getSecuredSeq().remove(1);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
}
@Test
- public void testSet()
- {
+ public void testSet() {
final Set<Action> perms = SecurityEvaluator.Util
.asSet(new Action[] { Action.Update });
- try
- {
+ try {
getSecuredSeq().set(1, true);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().set(1, 'c');
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().set(1, 3.14d);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().set(1, 3.14F);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().set(1, 3L);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
final Object o = Integer.MAX_VALUE;
getSecuredSeq().set(1, o);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().set(1, ResourceFactory.createResource());
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().set(1, "Waa hoo");
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredSeq().set(1, "dos", "es");
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/fcf71889/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredStatementTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredStatementTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredStatementTest.java
index b6a7737..63622b1 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredStatementTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredStatementTest.java
@@ -19,25 +19,26 @@ package org.apache.jena.permissions.model;
import java.util.Set;
-import org.apache.jena.permissions.AccessDeniedException;
import org.apache.jena.permissions.Factory;
import org.apache.jena.permissions.MockSecurityEvaluator;
+import org.apache.jena.permissions.ReadDeniedException;
import org.apache.jena.permissions.SecurityEvaluator;
import org.apache.jena.permissions.SecurityEvaluatorParameters;
import org.apache.jena.permissions.SecurityEvaluator.Action;
+import org.apache.jena.permissions.UpdateDeniedException;
import org.apache.jena.permissions.model.SecuredModel;
import org.apache.jena.permissions.model.SecuredStatement;
import org.apache.jena.permissions.model.impl.SecuredStatementImpl;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.shared.PropertyNotFoundException ;
+import org.apache.jena.rdf.model.*;
+import org.apache.jena.shared.AccessDeniedException;
+import org.apache.jena.shared.PropertyNotFoundException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredStatementTest
-{
+@RunWith(value = SecurityEvaluatorParameters.class)
+public class SecuredStatementTest {
private final MockSecurityEvaluator securityEvaluator;
private Statement baseStatement;
private SecuredStatement securedStatement;
@@ -45,19 +46,16 @@ public class SecuredStatementTest
private SecuredModel securedModel;
private Property property;
- public SecuredStatementTest( final MockSecurityEvaluator securityEvaluator )
- {
+ public SecuredStatementTest(final MockSecurityEvaluator securityEvaluator) {
this.securityEvaluator = securityEvaluator;
}
- protected Model createModel()
- {
+ protected Model createModel() {
return ModelFactory.createDefaultModel();
}
@Before
- public void setup()
- {
+ public void setup() {
baseModel = createModel();
property = ResourceFactory
.createProperty("http://example.com/property");
@@ -73,209 +71,153 @@ public class SecuredStatementTest
/**
* @sec.graph Update
* @sec.triple Update
- * @throws AccessDeniedException
+ * @throws AccessDeniedRuntimeException
*/
@Test
- public void testChangeLiteralObject()
- {
+ public void testChangeLiteralObject() {
final Set<Action> perms = SecurityEvaluator.Util
.asSet(new Action[] { Action.Update });
- try
- {
+ try {
securedStatement.changeLiteralObject(true);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
securedStatement.changeLiteralObject('c');
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
securedStatement.changeLiteralObject(3.14d);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
securedStatement.changeLiteralObject(3.14F);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
securedStatement.changeLiteralObject(2);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
securedStatement.changeLiteralObject(2L);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
securedStatement.changeObject(ResourceFactory.createResource());
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
securedStatement.changeObject("Waaa hooo");
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
final Literal l = ResourceFactory
.createTypedLiteral(Integer.MAX_VALUE);
securedStatement.changeObject(l.getLexicalForm(), true);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
securedStatement.changeObject("dos", "es");
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
securedStatement.changeObject("dos", "es", false);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
@@ -283,303 +225,229 @@ public class SecuredStatementTest
}
@Test
- public void testCreateReifiedStatement()
- {
+ public void testCreateReifiedStatement() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
securedStatement.createReifiedStatement();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
- try
- {
+ try {
securedStatement.createReifiedStatement("http://example.com/rsURI");
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
}
@Test
- public void testGetProperty()
- {
+ public void testGetProperty() {
// get property of the object
baseModel.add(baseStatement.getObject().asResource(), property,
ResourceFactory.createResource());
- try
- {
+ try {
securedStatement.getProperty(property);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown PropertyNotFound Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown PropertyNotFoundException Exception");
}
- }
- catch (final PropertyNotFoundException e)
- {
- if (securityEvaluator.evaluate(Action.Read))
- {
+ } catch (final PropertyNotFoundException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
Assert.fail(String
- .format("Should not have thrown PropertyNotFound Exception: %s - %s",
+ .format("Should not have thrown PropertyNotFoundException Exception: %s - %s",
e, securityEvaluator));
}
}
}
@Test
- public void testGets()
- {
+ public void testGets() {
final Set<Action> perms = SecurityEvaluator.Util
.asSet(new Action[] { Action.Read });
securedStatement = SecuredStatementImpl.getInstance(securedModel,
baseStatement.changeLiteralObject(true));
- try
- {
+ try {
securedStatement.getBoolean();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
securedStatement = SecuredStatementImpl.getInstance(securedModel,
baseStatement.changeLiteralObject(Byte.MAX_VALUE));
- try
- {
+ try {
securedStatement.getByte();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
securedStatement = SecuredStatementImpl.getInstance(securedModel,
baseStatement.changeLiteralObject('c'));
- try
- {
+ try {
securedStatement.getChar();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
securedStatement = SecuredStatementImpl.getInstance(securedModel,
baseStatement.changeLiteralObject(3.14d));
- try
- {
+ try {
securedStatement.getDouble();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
securedStatement = SecuredStatementImpl.getInstance(securedModel,
baseStatement.changeLiteralObject(3.14F));
- try
- {
+ try {
securedStatement.getFloat();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
securedStatement = SecuredStatementImpl.getInstance(securedModel,
baseStatement.changeLiteralObject(2));
- try
- {
+ try {
securedStatement.getInt();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
securedStatement = SecuredStatementImpl.getInstance(securedModel,
baseStatement.changeObject("dos", "es"));
- try
- {
+ try {
securedStatement.getLanguage();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
securedStatement = SecuredStatementImpl.getInstance(securedModel,
baseStatement.changeLiteralObject(2L));
- try
- {
+ try {
securedStatement.getLong();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
securedStatement = SecuredStatementImpl.getInstance(securedModel,
baseStatement.changeLiteralObject(Short.MAX_VALUE));
- try
- {
+ try {
securedStatement.getShort();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
securedStatement = SecuredStatementImpl.getInstance(securedModel,
baseStatement.changeObject("who hoo"));
- try
- {
+ try {
securedStatement.getString();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
securedStatement = SecuredStatementImpl.getInstance(securedModel,
baseStatement.changeObject("who hoo"));
- try
- {
+ try {
securedStatement.hasWellFormedXML();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
}
@Test
- public void testGetStatementProperty()
- {
+ public void testGetStatementProperty() {
// get property of the subject
final ReifiedStatement s = baseStatement.createReifiedStatement();
s.addLiteral(property, "yee haw");
@@ -588,109 +456,84 @@ public class SecuredStatementTest
}
@Test
- public void testIsReified()
- {
+ public void testIsReified() {
final Set<Action> perms = SecurityEvaluator.Util
.asSet(new Action[] { Action.Read });
- try
- {
+ try {
securedStatement.isReified();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
}
@Test
- public void testListReifiedStatements()
- {
+ public void testListReifiedStatements() {
final Set<Action> perms = SecurityEvaluator.Util
.asSet(new Action[] { Action.Read });
- try
- {
+ try {
securedStatement.listReifiedStatements();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown ReadDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
}
@Test
- public void testRemove()
- {
+ public void testRemove() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Delete });
- try
- {
+ try {
securedStatement.remove();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
}
@Test
- public void testRemoveReification()
- {
+ public void testRemoveReification() {
baseStatement.createReifiedStatement();
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Delete });
- try
- {
+ try {
securedStatement.removeReification();
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(perms))
- {
+ } catch (final AccessDeniedException e) {
+ if (securityEvaluator.evaluate(perms)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown AccessDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
}
@Test
- public void testUnsecuredGets()
- {
+ public void testUnsecuredGets() {
securedStatement.getAlt();
securedStatement.getBag();
securedStatement.getSeq();
http://git-wip-us.apache.org/repos/asf/jena/blob/fcf71889/jena-permissions/src/test/java/org/apache/jena/permissions/query/DataSetTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/query/DataSetTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/query/DataSetTest.java
index b179da4..ae9fcba 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/query/DataSetTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/query/DataSetTest.java
@@ -22,11 +22,11 @@ import org.apache.jena.permissions.MockSecurityEvaluator;
import org.apache.jena.permissions.SecurityEvaluator.SecNode.Type;
import org.apache.jena.permissions.model.SecuredModel;
import org.apache.jena.permissions.query.SecuredQueryEngineFactory;
-import org.apache.jena.query.* ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.tdb.TDB ;
-import org.apache.jena.tdb.TDBFactory ;
+import org.apache.jena.query.*;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.tdb.TDB;
+import org.apache.jena.tdb.TDBFactory;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -37,57 +37,48 @@ public class DataSetTest {
private Model baseModel;
private MockSecurityEvaluator eval;
private SecuredModel dftModel;
-
+
@BeforeClass
- public static void setupFactory()
- {
+ public static void setupFactory() {
SecuredQueryEngineFactory.register();
}
@AfterClass
- public static void teardownFactory()
- {
+ public static void teardownFactory() {
SecuredQueryEngineFactory.unregister();
}
-
-
+
public void setup() {
-
- DatasetGraph dsg = TDBFactory.createDatasetGraph() ;
-
-
- dsg.getContext().set(TDB.symUnionDefaultGraph, true) ;
- Dataset myDataset = DatasetFactory.create(dsg) ;
-
-// DatasetGraph dsg = DatasetGraphFactory.createMem() ;
-//
-// Dataset myDataset = TDBFactory.createDataset();
- baseModel = myDataset.getNamedModel( "http://example.com/baseModel");
- //baseModel = myDataset.getDefaultModel();
- baseModel = QueryEngineTest.populateModel( baseModel );
-
- dftModel = Factory.getInstance(eval,
- "http://example.com/securedModel", baseModel);
-
- dataset = DatasetFactory.createMem() ;
- dataset.setDefaultModel(dftModel) ;
-
-// // dataset.addNamedModel( dftModel.getModelIRI(), dftModel);
-
-
-
+
+ DatasetGraph dsg = TDBFactory.createDatasetGraph();
+
+ dsg.getContext().set(TDB.symUnionDefaultGraph, true);
+ Dataset myDataset = DatasetFactory.create(dsg);
+
+ // DatasetGraph dsg = DatasetGraphFactory.createMem() ;
+ //
+ // Dataset myDataset = TDBFactory.createDataset();
+ baseModel = myDataset.getNamedModel("http://example.com/baseModel");
+ // baseModel = myDataset.getDefaultModel();
+ baseModel = QueryEngineTest.populateModel(baseModel);
+
+ dftModel = Factory.getInstance(eval, "http://example.com/securedModel",
+ baseModel);
+
+ dataset = DatasetFactory.createMem();
+ dataset.setDefaultModel(dftModel);
+
+ // // dataset.addNamedModel( dftModel.getModelIRI(), dftModel);
+
}
-
+
@Test
- public void testOpenQueryType()
- {
- eval = new MockSecurityEvaluator(true, true,
- true, true, true, true);
-
+ public void testOpenQueryType() {
+ eval = new MockSecurityEvaluator(true, true, true, true, true, true);
+
setup();
-
- try
- {
+
+ try {
final String query = "prefix fn: <http://www.w3.org/2005/xpath-functions#> "
+ " SELECT ?foo ?bar WHERE "
+ " { ?foo a <http://example.com/class> ; "
@@ -95,51 +86,41 @@ public class DataSetTest {
+ " } ";
final QueryExecution qexec = QueryExecutionFactory.create(query,
dataset);
- try
- {
+ try {
final ResultSet results = qexec.execSelect();
int count = 0;
- for (; results.hasNext();)
- {
+ for (; results.hasNext();) {
count++;
final QuerySolution soln = results.nextSolution();
}
Assert.assertEquals(8, count);
- }
- finally
- {
+ } finally {
qexec.close();
}
- }
- finally
- {
+ } finally {
dataset.close();
}
}
@Test
- public void testRestrictedQueryType()
- {
- eval = new MockSecurityEvaluator(true, true,
- true, true, true, true) {
+ public void testRestrictedQueryType() {
+ eval = new MockSecurityEvaluator(true, true, true, true, true, true) {
@Override
- public boolean evaluate( final Object principal, final Action action,
- final SecNode graphIRI, final SecTriple triple )
- {
+ public boolean evaluate(final Object principal,
+ final Action action, final SecNode graphIRI,
+ final SecTriple triple) {
if (triple.getSubject().equals(
- new SecNode(Type.URI, "http://example.com/resource/1")))
- {
+ new SecNode(Type.URI, "http://example.com/resource/1"))) {
return false;
}
return super.evaluate(principal, action, graphIRI, triple);
}
};
-
+
setup();
-
- try
- {
+
+ try {
final String query = "prefix fn: <http://www.w3.org/2005/xpath-functions#> "
+ " SELECT ?foo ?bar WHERE "
+ " { ?foo a <http://example.com/class> ; "
@@ -147,98 +128,74 @@ public class DataSetTest {
+ " } ";
final QueryExecution qexec = QueryExecutionFactory.create(query,
dataset);
- try
- {
+ try {
final ResultSet results = qexec.execSelect();
int count = 0;
- for (; results.hasNext();)
- {
+ for (; results.hasNext();) {
count++;
results.nextSolution();
}
Assert.assertEquals(4, count);
- }
- finally
- {
+ } finally {
qexec.close();
}
- }
- finally
- {
+ } finally {
dataset.close();
}
}
-
+
@Test
- public void testSelectAllType()
- {
- eval = new MockSecurityEvaluator(true, true,
- true, true, true, true) {
+ public void testSelectAllType() {
+ eval = new MockSecurityEvaluator(true, true, true, true, true, true) {
@Override
- public boolean evaluate( final Object principal, final Action action,
- final SecNode graphIRI, final SecTriple triple )
- {
+ public boolean evaluate(final Object principal,
+ final Action action, final SecNode graphIRI,
+ final SecTriple triple) {
if (triple.getSubject().equals(
- new SecNode(Type.URI, "http://example.com/resource/1")))
- {
+ new SecNode(Type.URI, "http://example.com/resource/1"))) {
return false;
}
return super.evaluate(principal, action, graphIRI, triple);
}
};
-
+
setup();
-
- try
- {
- String query = "SELECT ?s ?p ?o WHERE "
- + " { ?s ?p ?o } ";
- QueryExecution qexec = QueryExecutionFactory.create(query,
- dataset);
- try
- {
+
+ try {
+ String query = "SELECT ?s ?p ?o WHERE " + " { ?s ?p ?o } ";
+ QueryExecution qexec = QueryExecutionFactory.create(query, dataset);
+ try {
final ResultSet results = qexec.execSelect();
int count = 0;
- for (; results.hasNext();)
- {
+ for (; results.hasNext();) {
count++;
final QuerySolution soln = results.nextSolution();
- //System.out.println( soln );
+ // System.out.println( soln );
}
// 2x 3 values + type triple
Assert.assertEquals(8, count);
- }
- finally
- {
+ } finally {
qexec.close();
}
-
- query = "SELECT ?g ?s ?p ?o WHERE "
- + " { GRAPH ?g {?s ?p ?o } }";
- qexec = QueryExecutionFactory.create(query,
- dataset);
- try
- {
+
+ query = "SELECT ?g ?s ?p ?o WHERE " + " { GRAPH ?g {?s ?p ?o } }";
+ qexec = QueryExecutionFactory.create(query, dataset);
+ try {
final ResultSet results = qexec.execSelect();
int count = 0;
- for (; results.hasNext();)
- {
+ for (; results.hasNext();) {
count++;
final QuerySolution soln = results.nextSolution();
- //System.out.println( soln );
+ // System.out.println( soln );
}
// 2x 3 values + type triple
// all are in the base graph so no named graphs
Assert.assertEquals(0, count);
- }
- finally
- {
+ } finally {
qexec.close();
}
- }
- finally
- {
+ } finally {
dataset.close();
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/fcf71889/jena-permissions/src/test/java/org/apache/jena/permissions/query/QueryEngineTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/query/QueryEngineTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/query/QueryEngineTest.java
index 11999a1..5d7172d 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/query/QueryEngineTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/query/QueryEngineTest.java
@@ -23,15 +23,15 @@ import org.apache.jena.permissions.SecurityEvaluator;
import org.apache.jena.permissions.SecurityEvaluator.SecNode.Type;
import org.apache.jena.permissions.model.SecuredModel;
import org.apache.jena.permissions.query.SecuredQueryEngineFactory;
-import org.apache.jena.query.QueryExecution ;
-import org.apache.jena.query.QueryExecutionFactory ;
-import org.apache.jena.query.QuerySolution ;
-import org.apache.jena.query.ResultSet ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.ModelFactory ;
-import org.apache.jena.rdf.model.Resource ;
-import org.apache.jena.rdf.model.ResourceFactory ;
-import org.apache.jena.vocabulary.RDF ;
+import org.apache.jena.query.QueryExecution;
+import org.apache.jena.query.QueryExecutionFactory;
+import org.apache.jena.query.QuerySolution;
+import org.apache.jena.query.ResultSet;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.rdf.model.ModelFactory;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.rdf.model.ResourceFactory;
+import org.apache.jena.vocabulary.RDF;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -57,9 +57,7 @@ public class QueryEngineTest {
}
-
- public static Model populateModel(Model baseModel)
- {
+ public static Model populateModel(Model baseModel) {
Resource r = ResourceFactory
.createResource("http://example.com/resource/1");
@@ -101,11 +99,10 @@ public class QueryEngineTest {
ResourceFactory.createTypedLiteral(9.42));
return baseModel;
}
-
+
@Before
- public void setUp()
- {
- baseModel = populateModel( ModelFactory.createDefaultModel());
+ public void setUp() {
+ baseModel = populateModel(ModelFactory.createDefaultModel());
}
@After
@@ -186,18 +183,15 @@ public class QueryEngineTest {
}
@Test
- public void testSelectAllType()
- {
+ public void testSelectAllType() {
final SecurityEvaluator eval = new MockSecurityEvaluator(true, true,
true, true, true, true) {
@Override
public boolean evaluate(Object principal, final Action action,
- final SecNode graphIRI, final SecTriple triple )
- {
+ final SecNode graphIRI, final SecTriple triple) {
if (triple.getSubject().equals(
- new SecNode(Type.URI, "http://example.com/resource/1")))
- {
+ new SecNode(Type.URI, "http://example.com/resource/1"))) {
return false;
}
return super.evaluate(principal, action, graphIRI, triple);
@@ -205,55 +199,40 @@ public class QueryEngineTest {
};
final SecuredModel model = Factory.getInstance(eval,
"http://example.com/securedModel", baseModel);
- try
- {
- String query = "SELECT ?s ?p ?o WHERE "
- + " { ?s ?p ?o } ";
- QueryExecution qexec = QueryExecutionFactory.create(query,
- model);
- try
- {
+ try {
+ String query = "SELECT ?s ?p ?o WHERE " + " { ?s ?p ?o } ";
+ QueryExecution qexec = QueryExecutionFactory.create(query, model);
+ try {
final ResultSet results = qexec.execSelect();
int count = 0;
- for (; results.hasNext();)
- {
+ for (; results.hasNext();) {
count++;
final QuerySolution soln = results.nextSolution();
- //System.out.println( soln );
+ // System.out.println( soln );
}
// 2x 3 values + type triple
Assert.assertEquals(8, count);
- }
- finally
- {
+ } finally {
qexec.close();
}
-
- query = "SELECT ?s ?p ?o WHERE "
- + " { GRAPH ?g {?s ?p ?o } }";
- qexec = QueryExecutionFactory.create(query,
- model);
- try
- {
+
+ query = "SELECT ?s ?p ?o WHERE " + " { GRAPH ?g {?s ?p ?o } }";
+ qexec = QueryExecutionFactory.create(query, model);
+ try {
final ResultSet results = qexec.execSelect();
int count = 0;
- for (; results.hasNext();)
- {
+ for (; results.hasNext();) {
count++;
final QuerySolution soln = results.nextSolution();
- //System.out.println( soln );
+ // System.out.println( soln );
}
// 2x 3 values + type triple
// no named graphs so no results.
Assert.assertEquals(0, count);
- }
- finally
- {
+ } finally {
qexec.close();
}
- }
- finally
- {
+ } finally {
model.close();
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/fcf71889/jena-permissions/src/test/java/org/apache/jena/permissions/query/rewriter/OpRewriterTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/query/rewriter/OpRewriterTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/query/rewriter/OpRewriterTest.java
index 3e5d0d4..f9b8326 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/query/rewriter/OpRewriterTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/query/rewriter/OpRewriterTest.java
@@ -19,92 +19,100 @@ package org.apache.jena.permissions.query.rewriter;
import java.util.Arrays;
-import org.apache.jena.graph.NodeFactory ;
-import org.apache.jena.graph.Triple ;
-import org.apache.jena.permissions.AccessDeniedException;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.graph.Triple;
import org.apache.jena.permissions.MockSecurityEvaluator;
+import org.apache.jena.permissions.ReadDeniedException;
import org.apache.jena.permissions.SecurityEvaluator;
import org.apache.jena.permissions.query.rewriter.OpRewriter;
import org.apache.jena.permissions.query.rewriter.SecuredFunction;
-import org.apache.jena.sparql.algebra.Op ;
-import org.apache.jena.sparql.algebra.op.OpBGP ;
-import org.apache.jena.sparql.algebra.op.OpFilter ;
-import org.apache.jena.sparql.core.BasicPattern ;
-import org.apache.jena.sparql.expr.ExprList ;
-import org.apache.jena.vocabulary.RDF ;
+import org.apache.jena.sparql.algebra.Op;
+import org.apache.jena.sparql.algebra.op.OpBGP;
+import org.apache.jena.sparql.algebra.op.OpFilter;
+import org.apache.jena.sparql.core.BasicPattern;
+import org.apache.jena.sparql.expr.ExprList;
+import org.apache.jena.vocabulary.RDF;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-public class OpRewriterTest
-{
+public class OpRewriterTest {
private OpRewriter rewriter;
private Triple[] triples;
-
- public OpRewriterTest()
- {
+
+ public OpRewriterTest() {
}
-
+
@Before
- public void setup()
- {
+ public void setup() {
triples = new Triple[] {
- new Triple( NodeFactory.createVariable("foo"), RDF.type.asNode(), NodeFactory.createURI( "http://example.com/class")),
- new Triple( NodeFactory.createVariable("foo"), NodeFactory.createAnon(), NodeFactory.createVariable("bar")),
- new Triple( NodeFactory.createVariable("bar"), NodeFactory.createAnon(), NodeFactory.createVariable("baz")),
- };
+ new Triple(NodeFactory.createVariable("foo"),
+ RDF.type.asNode(),
+ NodeFactory.createURI("http://example.com/class")),
+ new Triple(NodeFactory.createVariable("foo"),
+ NodeFactory.createAnon(),
+ NodeFactory.createVariable("bar")),
+ new Triple(NodeFactory.createVariable("bar"),
+ NodeFactory.createAnon(),
+ NodeFactory.createVariable("baz")), };
}
-
+
@Test
- public void testBGP()
- {
- SecurityEvaluator securityEvaluator = new MockSecurityEvaluator( true, true, true, true, true, true );
- rewriter = new OpRewriter( securityEvaluator, "http://example.com/dummy");
-
- rewriter.visit( new OpBGP( BasicPattern.wrap(Arrays.asList(triples))));
+ public void testBGP() {
+ SecurityEvaluator securityEvaluator = new MockSecurityEvaluator(true,
+ true, true, true, true, true);
+ rewriter = new OpRewriter(securityEvaluator, "http://example.com/dummy");
+
+ rewriter.visit(new OpBGP(BasicPattern.wrap(Arrays.asList(triples))));
Op op = rewriter.getResult();
- Assert.assertTrue( "Should have been an OpFilter", op instanceof OpFilter );
+ Assert.assertTrue("Should have been an OpFilter",
+ op instanceof OpFilter);
OpFilter filter = (OpFilter) op;
ExprList eLst = filter.getExprs();
- Assert.assertEquals( 1, eLst.size());
- Assert.assertTrue( "Should have been a SecuredFunction", eLst.get(0) instanceof SecuredFunction);
+ Assert.assertEquals(1, eLst.size());
+ Assert.assertTrue("Should have been a SecuredFunction",
+ eLst.get(0) instanceof SecuredFunction);
op = filter.getSubOp();
- Assert.assertTrue( "Should have been a OpBGP", op instanceof OpBGP);
- BasicPattern basicPattern = ((OpBGP)op).getPattern();
- Assert.assertEquals( 3, basicPattern.size() );
-
+ Assert.assertTrue("Should have been a OpBGP", op instanceof OpBGP);
+ BasicPattern basicPattern = ((OpBGP) op).getPattern();
+ Assert.assertEquals(3, basicPattern.size());
+
Triple t = basicPattern.get(0);
- Assert.assertEquals( NodeFactory.createVariable("foo"), t.getSubject());
- Assert.assertEquals( RDF.type.asNode(), t.getPredicate());
- Assert.assertEquals( NodeFactory.createURI( "http://example.com/class"), t.getObject());
-
+ Assert.assertEquals(NodeFactory.createVariable("foo"), t.getSubject());
+ Assert.assertEquals(RDF.type.asNode(), t.getPredicate());
+ Assert.assertEquals(NodeFactory.createURI("http://example.com/class"),
+ t.getObject());
+
t = basicPattern.get(1);
- Assert.assertEquals( NodeFactory.createVariable("foo"), t.getSubject());
- Assert.assertTrue( "Should have been blank", t.getPredicate().isBlank());
- Assert.assertEquals( NodeFactory.createVariable("bar"), t.getObject());
-
+ Assert.assertEquals(NodeFactory.createVariable("foo"), t.getSubject());
+ Assert.assertTrue("Should have been blank", t.getPredicate().isBlank());
+ Assert.assertEquals(NodeFactory.createVariable("bar"), t.getObject());
+
t = basicPattern.get(2);
- Assert.assertEquals( NodeFactory.createVariable("bar"), t.getSubject() );
- Assert.assertTrue( "Should have been blank", t.getPredicate().isBlank());
- Assert.assertEquals( NodeFactory.createVariable("baz"), t.getObject());
+ Assert.assertEquals(NodeFactory.createVariable("bar"), t.getSubject());
+ Assert.assertTrue("Should have been blank", t.getPredicate().isBlank());
+ Assert.assertEquals(NodeFactory.createVariable("baz"), t.getObject());
}
-
+
@Test
- public void testBGPNoReadAccess()
- {
- SecurityEvaluator securityEvaluator = new MockSecurityEvaluator( true, true, false, true, true, true );
- rewriter = new OpRewriter( securityEvaluator, "http://example.com/dummy");
+ public void testBGPNoReadAccess() {
+ SecurityEvaluator securityEvaluator = new MockSecurityEvaluator(true,
+ true, false, true, true, true);
+ rewriter = new OpRewriter(securityEvaluator, "http://example.com/dummy");
Triple[] triples = {
- new Triple( NodeFactory.createVariable("foo"), RDF.type.asNode(), NodeFactory.createURI( "http://example.com/class")),
- new Triple( NodeFactory.createVariable("foo"), NodeFactory.createAnon(), NodeFactory.createVariable("bar")),
- new Triple( NodeFactory.createVariable("bar"), NodeFactory.createAnon(), NodeFactory.createVariable("baz")),
- };
+ new Triple(NodeFactory.createVariable("foo"),
+ RDF.type.asNode(),
+ NodeFactory.createURI("http://example.com/class")),
+ new Triple(NodeFactory.createVariable("foo"),
+ NodeFactory.createAnon(),
+ NodeFactory.createVariable("bar")),
+ new Triple(NodeFactory.createVariable("bar"),
+ NodeFactory.createAnon(),
+ NodeFactory.createVariable("baz")), };
try {
- rewriter.visit( new OpBGP( BasicPattern.wrap(Arrays.asList(triples))));
- Assert.fail( "Should have thrown AccessDeniedException");
- }
- catch (AccessDeniedException e)
- {
+ rewriter.visit(new OpBGP(BasicPattern.wrap(Arrays.asList(triples))));
+ Assert.fail("Should have thrown AccessDeniedException");
+ } catch (ReadDeniedException e) {
// expected
}
}