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:10 UTC
[03/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/SecuredRDFListTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredRDFListTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredRDFListTest.java
index b83fd41..9ff79a6 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredRDFListTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredRDFListTest.java
@@ -22,61 +22,61 @@ import java.util.Iterator;
import java.util.List;
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.SecuredRDFList;
import org.apache.jena.permissions.model.impl.SecuredRDFListImpl;
import org.apache.jena.permissions.utils.RDFListIterator;
import org.apache.jena.permissions.utils.RDFListSecFilter;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.rdf.model.RDFList.ApplyFn ;
-import org.apache.jena.rdf.model.RDFList.ReduceFn ;
-import org.apache.jena.util.iterator.WrappedIterator ;
+import org.apache.jena.rdf.model.*;
+import org.apache.jena.rdf.model.RDFList.ApplyFn;
+import org.apache.jena.rdf.model.RDFList.ReduceFn;
+import org.apache.jena.shared.AccessDeniedException;
+import org.apache.jena.util.iterator.WrappedIterator;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredRDFListTest extends SecuredResourceTest
-{
+@RunWith(value = SecurityEvaluatorParameters.class)
+public class SecuredRDFListTest extends SecuredResourceTest {
private RDFList baseList;
-
- public SecuredRDFListTest( final MockSecurityEvaluator securityEvaluator )
- {
+
+ public SecuredRDFListTest(final MockSecurityEvaluator securityEvaluator) {
super(securityEvaluator);
}
- private int count( final Action action )
- {
+ private int count(final Action action) {
final Iterator<RDFList> iter = new RDFListIterator(
(RDFList) getBaseRDFNode());
- return WrappedIterator.create(iter)
- .filterKeep(new RDFListSecFilter<RDFList>(getSecuredRDFList(), action))
- .toList().size();
+ return WrappedIterator
+ .create(iter)
+ .filterKeep(
+ new RDFListSecFilter<RDFList>(getSecuredRDFList(),
+ action)).toList().size();
}
- private int count( final Set<Action> action )
- {
+ private int count(final Set<Action> action) {
final Iterator<RDFList> iter = new RDFListIterator(
(RDFList) getBaseRDFNode());
- return WrappedIterator.create(iter)
- .filterKeep(new RDFListSecFilter<RDFList>(getSecuredRDFList(), action))
- .toList().size();
+ return WrappedIterator
+ .create(iter)
+ .filterKeep(
+ new RDFListSecFilter<RDFList>(getSecuredRDFList(),
+ action)).toList().size();
}
- private SecuredRDFList getSecuredRDFList()
- {
+ private SecuredRDFList getSecuredRDFList() {
return (SecuredRDFList) getSecuredRDFNode();
}
@Override
@Before
- public void setup()
- {
+ public void setup() {
super.setup();
final RDFNode[] listElements = {
ResourceFactory.createResource("http://example.com/ListNode1"),
@@ -84,28 +84,24 @@ public class SecuredRDFListTest extends SecuredResourceTest
ResourceFactory.createResource("http://example.com/ListNode3"),
ResourceFactory.createResource("http://example.com/ListNode4") };
baseList = baseModel.createList(listElements);
- setSecuredRDFNode(SecuredRDFListImpl.getInstance(securedModel, baseList), baseList);
+ setSecuredRDFNode(
+ SecuredRDFListImpl.getInstance(securedModel, baseList),
+ baseList);
}
@Test
- public void testAdd()
- {
+ public void testAdd() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredRDFList().add(baseModel.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()));
}
}
@@ -113,127 +109,99 @@ public class SecuredRDFListTest extends SecuredResourceTest
}
@Test
- public void testAppendNodeIterator()
- {
+ public void testAppendNodeIterator() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredRDFList().append(baseModel.listObjects());
- 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 testAppendRDFList()
- {
+ public void testAppendRDFList() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
try {
getSecuredRDFList().append(baseModel.createList());
- if (!securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- if (!securityEvaluator.evaluate(Action.Create) && (baseList.size()>0 && securityEvaluator.evaluate(Action.Read) ))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Create)
+ && (baseList.size() > 0 && securityEvaluator
+ .evaluate(Action.Read))) {
+ Assert.fail("Should have thrown AddDeniedException 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 testApply()
- {
+ public void testApply() {
final ApplyFn fn = new ApplyFn() {
@Override
- public void apply( final RDFNode node )
- {
+ public void apply(final RDFNode node) {
// do nothing
}
};
- try
- {
+ try {
getSecuredRDFList().apply(fn);
- 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()));
}
}
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Read });
- try
- {
+ try {
getSecuredRDFList().apply(perms, fn);
- 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 testAsJaveList()
- {
- try
- {
+ public void testAsJaveList() {
+ try {
getSecuredRDFList().asJavaList();
- 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()));
}
}
@@ -241,340 +209,241 @@ public class SecuredRDFListTest extends SecuredResourceTest
}
@Test
- public void testConcatenate()
- {
+ public void testConcatenate() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredRDFList().concatenate(baseModel.listObjects());
- 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 List<Resource> lst = new ArrayList<Resource>();
lst.add(ResourceFactory
.createResource("http://example.com/dummyList"));
getSecuredRDFList().concatenate(
baseModel.createList(lst.iterator()));
- 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 testCons()
- {
+ public void testCons() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredRDFList().cons(SecuredRDFNodeTest.s);
- 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 testContains()
- {
- try
- {
+ public void testContains() {
+ try {
getSecuredRDFList().contains(SecuredRDFNodeTest.s);
- 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 testCopy()
- {
+ public void testCopy() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Read, Action.Update, Action.Create });
- try
- {
+ try {
getSecuredRDFList().copy();
- }
- 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 testGet()
- {
- try
- {
+ public void testGet() {
+ try {
getSecuredRDFList().get(0);
- 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()));
}
- }
- catch (final ListIndexException e)
- {
- if (((RDFList) getBaseRDFNode()).size() < 0)
- {
+ } catch (final ListIndexException e) {
+ if (((RDFList) getBaseRDFNode()).size() < 0) {
// acceptable exception
- }
- else
- {
+ } else {
throw e;
}
}
}
@Test
- public void testGetHead()
- {
- try
- {
+ public void testGetHead() {
+ try {
getSecuredRDFList().getHead();
- 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()));
}
- }
- catch (final ListIndexException e)
- {
- if (((RDFList) getBaseRDFNode()).size() == 0)
- {
+ } catch (final ListIndexException e) {
+ if (((RDFList) getBaseRDFNode()).size() == 0) {
// acceptable exception
- }
- else
- {
+ } else {
throw e;
}
}
}
@Test
- public void testGetTail()
- {
- try
- {
+ public void testGetTail() {
+ try {
getSecuredRDFList().getTail();
- 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()));
}
- }
- catch (final ListIndexException e)
- {
- if (((RDFList) getBaseRDFNode()).size() == 0)
- {
+ } catch (final ListIndexException e) {
+ if (((RDFList) getBaseRDFNode()).size() == 0) {
// acceptable exception
- }
- else
- {
+ } else {
throw e;
}
}
}
@Test
- public void testGetValidityErrorMessage()
- {
- try
- {
+ public void testGetValidityErrorMessage() {
+ try {
getSecuredRDFList().getValidityErrorMessage();
- 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 testIndexOf()
- {
- try
- {
+ public void testIndexOf() {
+ try {
getSecuredRDFList().indexOf(SecuredRDFNodeTest.s);
- 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()));
}
- }
- catch (final ListIndexException e)
- {
- if (((RDFList) getBaseRDFNode()).size() == 0)
- {
+ } catch (final ListIndexException e) {
+ if (((RDFList) getBaseRDFNode()).size() == 0) {
// acceptable exception
- }
- else
- {
+ } else {
throw e;
}
}
- try
- {
+ try {
getSecuredRDFList().indexOf(SecuredRDFNodeTest.s, 1);
- 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()));
}
- }
- catch (final ListIndexException e)
- {
+ } catch (final ListIndexException e) {
if (((RDFList) getBaseRDFNode()).size() <= 0)
{
// acceptable exception
- }
- else
- {
+ } else {
throw e;
}
}
}
@Test
- public void testIsEmpty()
- {
- try
- {
+ public void testIsEmpty() {
+ try {
getSecuredRDFList().isEmpty();
- 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 testIterator()
- {
- try
- {
+ public void testIterator() {
+ try {
getSecuredRDFList().iterator();
- 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()));
}
}
@@ -582,51 +451,39 @@ public class SecuredRDFListTest extends SecuredResourceTest
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredRDFList().iterator(perms);
- 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 testReduce()
- {
+ public void testReduce() {
final ReduceFn fn = new ReduceFn() {
@Override
- public Object reduce( final RDFNode node, final Object accumulator )
- {
+ public Object reduce(final RDFNode node, final Object accumulator) {
return accumulator;
}
};
- try
- {
+ try {
getSecuredRDFList().reduce(fn, "Hello");
- 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()));
}
}
@@ -634,334 +491,243 @@ public class SecuredRDFListTest extends SecuredResourceTest
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredRDFList().reduce(perms, fn, "Hello");
- 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 testRemove()
- {
+ public void testRemove() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Delete });
- try
- {
+ try {
final int count = count(Action.Delete);
getSecuredRDFList().remove(SecuredRDFNodeTest.s);
if (!securityEvaluator.evaluate(Action.Update)
|| ((count > 0) && !securityEvaluator
- .evaluate(Action.Delete)))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ .evaluate(Action.Delete))) {
+ 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()));
}
}
}
@SuppressWarnings("deprecation")
- @Override
+ @Override
@Test
- public void testRemoveAll()
- {
+ public void testRemoveAll() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Delete });
- try
- {
+ try {
final int count = count(SecurityEvaluator.Util.asSet(new Action[] {
Action.Delete, Action.Read }));
getSecuredRDFList().removeAll();
if (!securityEvaluator.evaluate(Action.Update)
|| ((count > 0) && !securityEvaluator
- .evaluate(Action.Delete)))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ .evaluate(Action.Delete))) {
+ 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()));
}
- }
- catch (final EmptyListException e)
- {
- if (count(Action.Read) == 0)
- {
+ } catch (final EmptyListException e) {
+ if (count(Action.Read) == 0) {
// expected.
- }
- else
- {
+ } else {
throw e;
}
}
}
@Test
- public void testRemoveHead()
- {
+ public void testRemoveHead() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Delete });
- try
- {
+ try {
getSecuredRDFList().removeHead();
- 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()));
}
- }
- catch (final EmptyListException e)
- {
- if (count(Action.Read) == 0)
- {
+ } catch (final EmptyListException e) {
+ if (count(Action.Read) == 0) {
// expected.
- }
- else
- {
+ } else {
throw e;
}
}
}
@Test
- public void testRemoveList()
- {
+ public void testRemoveList() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Delete });
- try
- {
+ try {
final int count = count(Action.Delete);
getSecuredRDFList().removeList();
if (!securityEvaluator.evaluate(Action.Update)
|| ((count > 0) && !securityEvaluator
- .evaluate(Action.Delete)))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ .evaluate(Action.Delete))) {
+ 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 testReplace()
- {
- try
- {
+ public void testReplace() {
+ try {
getSecuredRDFList().replace(1, SecuredRDFNodeTest.s);
- if (!securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Update))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Update)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
- }
- catch (final ListIndexException e)
- {
- if (count(Action.Read) == 0)
- {
+ } catch (final ListIndexException e) {
+ if (count(Action.Read) == 0) {
// expected.
- }
- else
- {
+ } else {
throw e;
}
}
}
@Test
- public void testSameListAs()
- {
- try
- {
+ public void testSameListAs() {
+ try {
getSecuredRDFList().sameListAs(baseModel.createList());
- 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 testSetHead()
- {
+ public void testSetHead() {
- try
- {
+ try {
getSecuredRDFList().setHead(SecuredRDFNodeTest.s);
- if (!securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Update))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Update)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
- }
- catch (final EmptyListException e)
- {
- if (count(Action.Read) == 0)
- {
+ } catch (final EmptyListException e) {
+ if (count(Action.Read) == 0) {
// expected.
- }
- else
- {
+ } else {
throw e;
}
}
}
@Test
- public void testSetStrict()
- {
- try
- {
+ public void testSetStrict() {
+ try {
getSecuredRDFList().setStrict(true);
- if (!securityEvaluator.evaluate(Action.Update))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)) {
+ Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- }
- catch (final AccessDeniedException e)
- {
- if (securityEvaluator.evaluate(Action.Update))
- {
+ } catch (final UpdateDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Update)) {
Assert.fail(String
- .format("Should not have thrown AccessDenied Exception: %s - %s",
+ .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
e, e.getTriple()));
}
}
}
@Test
- public void testSize()
- {
- try
- {
+ public void testSize() {
+ try {
getSecuredRDFList().size();
- 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 testValid()
- {
- try
- {
+ public void testValid() {
+ try {
getSecuredRDFList().isValid();
- 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 testWith()
- {
+ public void testWith() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredRDFList().with(SecuredRDFNodeTest.s);
- 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()));
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/fcf71889/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredRDFNodeTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredRDFNodeTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredRDFNodeTest.java
index 3c1f3db..0f2893c 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredRDFNodeTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredRDFNodeTest.java
@@ -17,24 +17,23 @@
*/
package org.apache.jena.permissions.model;
-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.SecurityEvaluatorParameters;
import org.apache.jena.permissions.SecurityEvaluator.Action;
import org.apache.jena.permissions.model.SecuredModel;
import org.apache.jena.permissions.model.SecuredRDFNode;
import org.apache.jena.permissions.model.impl.SecuredRDFNodeImpl;
-import org.apache.jena.rdf.model.* ;
+import org.apache.jena.rdf.model.*;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredRDFNodeTest
-{
+@RunWith(value = SecurityEvaluatorParameters.class)
+public class SecuredRDFNodeTest {
protected final MockSecurityEvaluator securityEvaluator;
protected Model baseModel;
protected SecuredModel securedModel;
@@ -50,36 +49,30 @@ public class SecuredRDFNodeTest
public static Resource o = ResourceFactory
.createResource("http://example.com/graph/o");
- public SecuredRDFNodeTest( final MockSecurityEvaluator securityEvaluator )
- {
+ public SecuredRDFNodeTest(final MockSecurityEvaluator securityEvaluator) {
this.securityEvaluator = securityEvaluator;
}
- protected Model createModel()
- {
+ protected Model createModel() {
return ModelFactory.createDefaultModel();
}
- protected RDFNode getBaseRDFNode()
- {
+ protected RDFNode getBaseRDFNode() {
return baseRDFNode;
}
- protected SecuredRDFNode getSecuredRDFNode()
- {
+ protected SecuredRDFNode getSecuredRDFNode() {
return securedRDFNode;
}
- protected void setSecuredRDFNode( final SecuredRDFNode securedRDFNode,
- final RDFNode baseRDFNode )
- {
+ protected void setSecuredRDFNode(final SecuredRDFNode securedRDFNode,
+ final RDFNode baseRDFNode) {
this.securedRDFNode = securedRDFNode;
this.baseRDFNode = baseRDFNode;
}
@Before
- public void setup()
- {
+ public void setup() {
baseModel = createModel();
baseModel.removeAll();
baseModel.add(SecuredRDFNodeTest.s, SecuredRDFNodeTest.p,
@@ -94,86 +87,66 @@ public class SecuredRDFNodeTest
}
@After
- public void teardown()
- {
+ public void teardown() {
securedModel.close();
securedModel = null;
}
@Test
- public void testAsNode()
- {
- try
- {
+ public void testAsNode() {
+ try {
securedRDFNode.asNode();
- 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 testCanAs()
- {
- try
- {
+ public void testCanAs() {
+ try {
securedRDFNode.canAs(Resource.class);
- 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 testGetModel()
- {
+ public void testGetModel() {
final Model m2 = securedRDFNode.getModel();
Assert.assertTrue("Model should have been secured",
m2 instanceof SecuredModel);
}
@Test
- public void testInModel()
- {
+ public void testInModel() {
final Model m2 = ModelFactory.createDefaultModel();
- try
- {
+ try {
final RDFNode n2 = securedRDFNode.inModel(m2);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
Assert.assertFalse("RDFNode should not have been secured",
n2 instanceof SecuredRDFNode);
Assert.assertEquals("Wrong securedModel returned", n2.getModel(),
m2);
- }
- 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()));
}
}
@@ -182,24 +155,19 @@ public class SecuredRDFNodeTest
final SecuredModel m3 = Factory.getInstance(securityEvaluator,
"http://example.com/securedGraph2", m2);
- try
- {
+ try {
final RDFNode n2 = securedRDFNode.inModel(m3);
- if (!securityEvaluator.evaluate(Action.Read))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
}
Assert.assertTrue("RDFNode should have been secured",
n2 instanceof SecuredRDFNode);
Assert.assertEquals("Wrong securedModel returned", n2.getModel(),
m3);
- }
- 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()));
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/fcf71889/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredReifiedStatementTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredReifiedStatementTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredReifiedStatementTest.java
index 73055fe..697aecc 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredReifiedStatementTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredReifiedStatementTest.java
@@ -17,37 +17,33 @@
*/
package org.apache.jena.permissions.model;
-import org.apache.jena.permissions.AccessDeniedException;
import org.apache.jena.permissions.MockSecurityEvaluator;
+import org.apache.jena.permissions.ReadDeniedException;
import org.apache.jena.permissions.SecurityEvaluatorParameters;
import org.apache.jena.permissions.SecurityEvaluator.Action;
import org.apache.jena.permissions.model.SecuredReifiedStatement;
import org.apache.jena.permissions.model.impl.SecuredReifiedStatementImpl;
-import org.apache.jena.rdf.model.ReifiedStatement ;
+import org.apache.jena.rdf.model.ReifiedStatement;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredReifiedStatementTest extends SecuredResourceTest
-{
+@RunWith(value = SecurityEvaluatorParameters.class)
+public class SecuredReifiedStatementTest extends SecuredResourceTest {
public SecuredReifiedStatementTest(
- final MockSecurityEvaluator securityEvaluator )
- {
+ final MockSecurityEvaluator securityEvaluator) {
super(securityEvaluator);
}
- private SecuredReifiedStatement getSecuredReifiedStatement()
- {
+ private SecuredReifiedStatement getSecuredReifiedStatement() {
return (SecuredReifiedStatement) getSecuredRDFNode();
}
@Override
@Before
- public void setup()
- {
+ public void setup() {
super.setup();
final ReifiedStatement stmt = baseModel.listStatements().next()
.createReifiedStatement();
@@ -58,25 +54,19 @@ public class SecuredReifiedStatementTest extends SecuredResourceTest
/**
* @sec.graph Read
- * @throws AccessDeniedException
+ * @throws AccessDeniedRuntimeException
*/
@Test
- public void testGetStatement()
- {
- try
- {
+ public void testGetStatement() {
+ try {
getSecuredReifiedStatement().getStatement();
- 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()));
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/fcf71889/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredResourceTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredResourceTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredResourceTest.java
index c893f4e..4004ece 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredResourceTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredResourceTest.java
@@ -19,41 +19,38 @@ 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.model.SecuredResource;
import org.apache.jena.permissions.model.impl.SecuredResourceImpl;
-import org.apache.jena.rdf.model.Literal ;
-import org.apache.jena.rdf.model.RDFNode ;
-import org.apache.jena.rdf.model.ResourceFactory ;
-import org.apache.jena.rdf.model.StmtIterator ;
-import org.apache.jena.shared.PropertyNotFoundException ;
+import org.apache.jena.rdf.model.Literal;
+import org.apache.jena.rdf.model.RDFNode;
+import org.apache.jena.rdf.model.ResourceFactory;
+import org.apache.jena.rdf.model.StmtIterator;
+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 SecuredResourceTest extends SecuredRDFNodeTest
-{
+@RunWith(value = SecurityEvaluatorParameters.class)
+public class SecuredResourceTest extends SecuredRDFNodeTest {
- public SecuredResourceTest( final MockSecurityEvaluator securityEvaluator )
- {
+ public SecuredResourceTest(final MockSecurityEvaluator securityEvaluator) {
super(securityEvaluator);
}
- private SecuredResource getSecuredResource()
- {
+ private SecuredResource getSecuredResource() {
return (SecuredResource) getSecuredRDFNode();
}
@Override
@Before
- public void setup()
- {
+ public void setup() {
super.setup();
setSecuredRDFNode(SecuredResourceImpl.getInstance(securedModel,
SecuredRDFNodeTest.s), SecuredRDFNodeTest.s);
@@ -62,172 +59,130 @@ public class SecuredResourceTest extends SecuredRDFNodeTest
/**
* @sec.graph Update
* @sec.triple Create (this, p, o )
- * @throws AccessDeniedException
+ * @throws AccessDeniedRuntimeException
*/
@Test
- public void testAddLiteralBoolean()
- {
+ public void testAddLiteralBoolean() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredResource().addLiteral(SecuredRDFNodeTest.p, true);
- if (!securityEvaluator.evaluate(perms))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(perms)) {
+ Assert.fail("Should have thrown AccessDeniedException");
}
- }
- 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: %s - %s",
e, e.getTriple()));
}
}
}
-
- public void testAddLiteralChar()
- {
+
+ public void testAddLiteralChar() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredResource().addLiteral(SecuredRDFNodeTest.p, '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()));
}
}
-}
-
- public void testAddLiteralDouble()
- {
+ }
+
+ public void testAddLiteralDouble() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
-
- try
- {
+
+ try {
getSecuredResource().addLiteral(SecuredRDFNodeTest.p, 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()));
}
}
-}
-
- public void testAddLiteralFloat()
- {
+ }
+
+ public void testAddLiteralFloat() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
-
- try
- {
+
+ try {
getSecuredResource().addLiteral(SecuredRDFNodeTest.p, 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()));
}
}
-}
-
- public void testAddLiteral()
- {
+ }
+
+ public void testAddLiteral() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
-
- try
- {
+
+ try {
getSecuredResource().addLiteral(SecuredRDFNodeTest.p,
ResourceFactory.createTypedLiteral("Yee haw"));
- 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()));
}
}
-}
-
- public void testAddLiteralLong()
- {
+ }
+
+ public void testAddLiteralLong() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
-
- try
- {
+
+ try {
getSecuredResource().addLiteral(SecuredRDFNodeTest.p, 1L);
- 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()));
}
}
-}
-
- public void testAddLiteralObject()
- {
+ }
+
+ public void testAddLiteralObject() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
-
+
final Object o = Integer.valueOf("1234");
- try
- {
+ try {
getSecuredResource().addLiteral(SecuredRDFNodeTest.p, 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()));
}
}
@@ -235,591 +190,436 @@ public class SecuredResourceTest extends SecuredRDFNodeTest
}
@Test
- public void testAddProperty()
- {
+ public void testAddProperty() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
final RDFNode rdfNode = ResourceFactory
.createResource("http://example.com/newResource");
- try
- {
+ try {
getSecuredResource().addLiteral(SecuredRDFNodeTest.p, rdfNode);
- 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 {
getSecuredResource().addLiteral(SecuredRDFNodeTest.p, "string");
- 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()));
}
}
- final Literal l = ResourceFactory.createTypedLiteral( 3.14F );
- try
- {
+ final Literal l = ResourceFactory.createTypedLiteral(3.14F);
+ try {
getSecuredResource().addProperty(SecuredRDFNodeTest.p,
l.getLexicalForm(), l.getDatatype());
- 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 {
getSecuredResource().addProperty(SecuredRDFNodeTest.p, "dos", "sp");
- 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 testAnonFuncs()
- {
+ public void testAnonFuncs() {
final SecuredResource anonResource = securedModel.createResource();
setSecuredRDFNode(anonResource, null);
- try
- {
+ try {
getSecuredResource().getId();
- 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 testAsResource()
- {
+ public void testAsResource() {
getSecuredResource().asResource();
}
@Test
- public void testEquals()
- {
- try
- {
+ public void testEquals() {
+ try {
getSecuredResource().equals(SecuredRDFNodeTest.s);
- 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()));
}
}
}
- public void testGetLocalName()
- {
- try
- {
+ public void testGetLocalName() {
+ try {
getSecuredResource().getLocalName();
- 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()));
}
}
}
- public void testGetNameSpace()
- {
- try
- {
+ public void testGetNameSpace() {
+ try {
getSecuredResource().getNameSpace();
- 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 testGetProperty()
- {
- try
- {
+ public void testGetProperty() {
+ try {
getSecuredResource().getProperty(SecuredRDFNodeTest.p);
- 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 {
getSecuredResource().getPropertyResourceValue(SecuredRDFNodeTest.p);
- 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 {
getSecuredResource().getRequiredProperty(SecuredRDFNodeTest.p);
- 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()));
}
- }
- catch (final PropertyNotFoundException e)
- {
+ } catch (final PropertyNotFoundException e) {
// expected if (this, "p", ANY) is not in the base securedModel.
final StmtIterator iter = baseModel.listStatements(
getSecuredResource(), SecuredRDFNodeTest.p, (RDFNode) null);
- try
- {
- if (iter.hasNext())
- {
+ try {
+ if (iter.hasNext()) {
throw e;
}
- }
- finally
- {
+ } finally {
iter.close();
}
}
}
@Test
- public void testGetURI()
- {
- try
- {
+ public void testGetURI() {
+ try {
getSecuredResource().getURI();
- 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 testHasLiteral()
- {
- try
- {
+ public void testHasLiteral() {
+ try {
getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 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 {
getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, '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 {
getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 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 {
getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 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 {
getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 6l);
- 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()));
}
}
final Object o = 6;
- try
- {
+ try {
getSecuredResource().hasLiteral(SecuredRDFNodeTest.p, 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()));
}
}
}
@Test
- public void testHasProperty()
- {
+ public void testHasProperty() {
- try
- {
+ try {
getSecuredResource().hasProperty(SecuredRDFNodeTest.p);
- 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 {
getSecuredResource().hasProperty(SecuredRDFNodeTest.p,
SecuredRDFNodeTest.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 {
getSecuredResource().hasProperty(SecuredRDFNodeTest.p, "yeee haw");
- 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 {
getSecuredResource().hasProperty(SecuredRDFNodeTest.p, "dos", "sp");
- 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 testHasURI()
- {
- try
- {
+ public void testHasURI() {
+ try {
getSecuredResource().hasURI("http://example.com/yeeHaw");
- 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 testListProperties()
- {
- try
- {
+ public void testListProperties() {
+ try {
getSecuredResource().listProperties();
- 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 {
getSecuredResource().listProperties(SecuredRDFNodeTest.p);
- 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 testRemoveAll()
- {
+ public void testRemoveAll() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Delete });
final int count = baseModel
.listStatements(getBaseRDFNode().asResource(),
SecuredRDFNodeTest.p, (RDFNode) null).toSet().size();
- try
- {
+ try {
getSecuredResource().removeAll(SecuredRDFNodeTest.p);
// only throw on delete if count > 0
if (!securityEvaluator.evaluate(Action.Update)
|| ((count > 0) && !securityEvaluator
- .evaluate(Action.Delete)))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ .evaluate(Action.Delete))) {
+ Assert.fail("Should have thrown AccessDeniedException");
}
- }
- 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: %s - %s",
e, e.getTriple()));
}
}
}
@Test
- public void testRemoveProperties()
- {
+ public void testRemoveProperties() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Delete });
final int count = baseModel
.listStatements(getBaseRDFNode().asResource(),
SecuredRDFNodeTest.p, (RDFNode) null).toSet().size();
- try
- {
+ try {
getSecuredResource().removeProperties();
// only throw on delete if count > 0
if (!securityEvaluator.evaluate(Action.Update)
|| ((count > 0) && !securityEvaluator
- .evaluate(Action.Delete)))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ .evaluate(Action.Delete))) {
+ Assert.fail("Should have thrown AccessDeniedException");
}
- }
- 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: %s - %s",
e, e.getTriple()));
}
}