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:12 UTC
[05/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/SecuredAltTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredAltTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredAltTest.java
index fd4331f..2915662 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredAltTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredAltTest.java
@@ -19,39 +19,36 @@ 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.SecuredAlt;
import org.apache.jena.permissions.model.impl.SecuredAltImpl;
-import org.apache.jena.rdf.model.Alt ;
-import org.apache.jena.rdf.model.ResourceFactory ;
+import org.apache.jena.rdf.model.Alt;
+import org.apache.jena.rdf.model.ResourceFactory;
+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 SecuredAltTest extends SecuredContainerTest
-{
+@RunWith(value = SecurityEvaluatorParameters.class)
+public class SecuredAltTest extends SecuredContainerTest {
private Alt alt;
- public SecuredAltTest( final MockSecurityEvaluator securityEvaluator )
- {
+ public SecuredAltTest(final MockSecurityEvaluator securityEvaluator) {
super(securityEvaluator);
}
- private SecuredAlt getSecuredAlt()
- {
+ private SecuredAlt getSecuredAlt() {
return (SecuredAlt) getSecuredRDFNode();
}
@Override
@Before
- public void setup()
- {
+ public void setup() {
super.setup();
alt = baseModel.getAlt("http://example.com/testContainer");
setSecuredRDFNode(SecuredAltImpl.getInstance(securedModel, alt), alt);
@@ -60,259 +57,190 @@ public class SecuredAltTest extends SecuredContainerTest
/**
* @sec.graph Read
* @sec.triple Read SecTriple(this, RDF.li(1), o )
- * @throws AccessDeniedException
*/
@Test
- public void testGetDefault()
- {
+ public void testGetDefault() {
alt.add("SomeDummyItem");
- try
- {
+ try {
getSecuredAlt().getDefault();
- 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 {
getSecuredAlt().getDefaultAlt();
- 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 {
getSecuredAlt().getDefaultBag();
- 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 {
getSecuredAlt().getDefaultSeq();
- 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 testGetDefaultBoolean()
- {
+ public void testGetDefaultBoolean() {
alt.add(true);
- try
- {
+ try {
getSecuredAlt().getDefaultBoolean();
- 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 testGetDefaultByte()
- {
+ public void testGetDefaultByte() {
alt.add(Byte.MAX_VALUE);
- try
- {
+ try {
getSecuredAlt().getDefaultByte();
- 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 testGetDefaultChar()
- {
+ public void testGetDefaultChar() {
alt.add('c');
- try
- {
+ try {
getSecuredAlt().getDefaultChar();
- 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 testGetDefaultDouble()
- {
+ public void testGetDefaultDouble() {
alt.add(3.14d);
- try
- {
+ try {
getSecuredAlt().getDefaultDouble();
- 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 testGetDefaultFloat()
- {
+ public void testGetDefaultFloat() {
alt.add(3.14f);
- try
- {
+ try {
getSecuredAlt().getDefaultFloat();
- 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 testGetDefaultInt()
- {
+ public void testGetDefaultInt() {
alt.add(2);
- try
- {
+ try {
getSecuredAlt().getDefaultInt();
- 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 testGetDefaultLanguage()
- {
+ public void testGetDefaultLanguage() {
alt.add("SomeDummyItem");
- try
- {
+ try {
getSecuredAlt().getDefaultLanguage();
- 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 {
getSecuredAlt().getDefaultLiteral();
- 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()));
}
}
@@ -320,115 +248,81 @@ public class SecuredAltTest extends SecuredContainerTest
}
@Test
- public void testGetDefaultLong()
- {
+ public void testGetDefaultLong() {
alt.add(3L);
- try
- {
+ try {
getSecuredAlt().getDefaultLong();
- 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 testGetDefaultResource()
- {
+ public void testGetDefaultResource() {
alt.setDefault(ResourceFactory
.createResource("http://example.com/exampleResourec"));
- try
- {
+ try {
getSecuredAlt().getDefaultResource();
- 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
- * {
- * ResourceF f = ResourceFactory.getInstance();
- * getSecuredAlt().getDefaultResource( f );
- * if (!securityEvaluator.evaluate(Action.Read))
- * {
- * Assert.fail("Should have thrown AccessDenied Exception");
- * }
- * }
- * catch (final AccessDeniedException e)
- * {
- * if (securityEvaluator.evaluate(Action.Read))
- * {
- * Assert.fail(String
- * .format("Should not have thrown AccessDenied Exception: %s - %s",
- * e, e.getTriple()));
- * }
- * }
+ * try { ResourceF f = ResourceFactory.getInstance();
+ * getSecuredAlt().getDefaultResource( f ); if
+ * (!securityEvaluator.evaluate(Action.Read)) {
+ * Assert.fail("Should have thrown AccessDenied Exception"); } } catch
+ * (final AccessDeniedException e) { if
+ * (securityEvaluator.evaluate(Action.Read)) { Assert.fail(String
+ * .format("Should not have thrown AccessDenied Exception: %s - %s", e,
+ * e.getTriple())); } }
*/
@Test
- public void testGetDefaultShort()
- {
+ public void testGetDefaultShort() {
alt.setDefault(Short.MAX_VALUE);
- try
- {
+ try {
getSecuredAlt().getDefaultShort();
- 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 testGetDefaultString()
- {
+ public void testGetDefaultString() {
alt.setDefault("Hello World");
- try
- {
+ try {
getSecuredAlt().getDefaultString();
- 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()));
}
}
@@ -436,219 +330,183 @@ public class SecuredAltTest extends SecuredContainerTest
}
@Test
- public void testSetDefaultBoolean()
- {
+ public void testSetDefaultBoolean() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredAlt().setDefault(true);
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)
+ || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt()
+ .iterator().hasNext())) {
+ 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 testSetDefaultChar()
- {
+ public void testSetDefaultChar() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredAlt().setDefault('c');
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)
+ || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt()
+ .iterator().hasNext())) {
+ 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 testSetDefaultDouble()
- {
+ public void testSetDefaultDouble() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredAlt().setDefault(3.14d);
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)
+ || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt()
+ .iterator().hasNext())) {
+ 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 testSetDefaultFloat()
- {
+ public void testSetDefaultFloat() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredAlt().setDefault(3.14f);
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)
+ || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt()
+ .iterator().hasNext())) {
+ 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 testSetDefaultLong()
- {
+ public void testSetDefaultLong() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredAlt().setDefault(2L);
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)
+ || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt()
+ .iterator().hasNext())) {
+ 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 testSetDefaultObject()
- {
+ public void testSetDefaultObject() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
final Object o = 2;
getSecuredAlt().setDefault(o);
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)
+ || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt()
+ .iterator().hasNext())) {
+ 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 testSetDefaultResource()
- {
+ public void testSetDefaultResource() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredAlt().setDefault(
ResourceFactory
.createResource("http://example.com/resource"));
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)
+ || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt()
+ .iterator().hasNext())) {
+ 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 testSetDefaultString()
- {
+ public void testSetDefaultString() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredAlt().setDefault("test");
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)
+ || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt()
+ .iterator().hasNext())) {
+ 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 testSetDefaultStringAndLang()
- {
+ public void testSetDefaultStringAndLang() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredAlt().setDefault("dos", "es");
- if (!securityEvaluator.evaluate(Action.Update) || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt().iterator().hasNext() ))
- {
- Assert.fail("Should have thrown AccessDenied Exception");
+ if (!securityEvaluator.evaluate(Action.Update)
+ || (!securityEvaluator.evaluate(Action.Create) && !getSecuredAlt()
+ .iterator().hasNext())) {
+ 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()));
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/fcf71889/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredBagTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredBagTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredBagTest.java
index 33c1fb0..83a905e 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredBagTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredBagTest.java
@@ -20,23 +20,20 @@ package org.apache.jena.permissions.model;
import org.apache.jena.permissions.MockSecurityEvaluator;
import org.apache.jena.permissions.SecurityEvaluatorParameters;
import org.apache.jena.permissions.model.impl.SecuredBagImpl;
-import org.apache.jena.rdf.model.Bag ;
+import org.apache.jena.rdf.model.Bag;
import org.junit.Before;
import org.junit.runner.RunWith;
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredBagTest extends SecuredContainerTest
-{
+@RunWith(value = SecurityEvaluatorParameters.class)
+public class SecuredBagTest extends SecuredContainerTest {
- public SecuredBagTest( final MockSecurityEvaluator securityEvaluator )
- {
+ public SecuredBagTest(final MockSecurityEvaluator securityEvaluator) {
super(securityEvaluator);
}
@Override
@Before
- public void setup()
- {
+ public void setup() {
super.setup();
final Bag bag = baseModel.getBag("http://example.com/testContainer");
bag.add("SomeDummyItem");
http://git-wip-us.apache.org/repos/asf/jena/blob/fcf71889/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredContainerTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredContainerTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredContainerTest.java
index 2d80725..e7ffa65 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredContainerTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredContainerTest.java
@@ -19,39 +19,36 @@ 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.SecuredContainer;
import org.apache.jena.permissions.model.impl.SecuredContainerImpl;
-import org.apache.jena.rdf.model.Container ;
-import org.apache.jena.rdf.model.ResourceFactory ;
-import org.apache.jena.rdf.model.Statement ;
+import org.apache.jena.rdf.model.Container;
+import org.apache.jena.rdf.model.ResourceFactory;
+import org.apache.jena.rdf.model.Statement;
+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 abstract class SecuredContainerTest extends SecuredResourceTest
-{
+@RunWith(value = SecurityEvaluatorParameters.class)
+public abstract class SecuredContainerTest extends SecuredResourceTest {
- public SecuredContainerTest( final MockSecurityEvaluator securityEvaluator )
- {
+ public SecuredContainerTest(final MockSecurityEvaluator securityEvaluator) {
super(securityEvaluator);
}
- private SecuredContainer getSecuredContainer()
- {
+ private SecuredContainer getSecuredContainer() {
return (SecuredContainer) getSecuredRDFNode();
}
@Override
@Before
- public void setup()
- {
+ public void setup() {
super.setup();
final Container container = baseModel
.getBag("http://example.com/testContainer");
@@ -62,22 +59,16 @@ public abstract class SecuredContainerTest extends SecuredResourceTest
}
@Test
- public void test()
- {
- try
- {
+ public void test() {
+ try {
getSecuredContainer().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()));
}
}
@@ -86,174 +77,127 @@ public abstract class SecuredContainerTest extends SecuredResourceTest
/**
* @sec.graph Update
* @sec.triple Create SecTriple( this, RDF.li, o );
- * @throws AccessDeniedException
*/
@Test
- public void testAdd()
- {
+ public void testAdd() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Create });
- try
- {
+ try {
getSecuredContainer().add(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()));
}
}
- try
- {
+ try {
getSecuredContainer().add('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 {
getSecuredContainer().add(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 {
getSecuredContainer().add(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 {
getSecuredContainer().add(2L);
- 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 Object o = Integer.valueOf("1234");
- try
- {
+ try {
getSecuredContainer().add(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 {
getSecuredContainer().add(
ResourceFactory
.createResource("http://example.com/testResource"));
- 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 {
getSecuredContainer().add("foo");
- 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 {
getSecuredContainer().add("dos", "esp");
- 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()));
}
}
@@ -261,216 +205,158 @@ public abstract class SecuredContainerTest extends SecuredResourceTest
}
@Test
- public void testContains()
- {
- try
- {
+ public void testContains() {
+ try {
getSecuredContainer().contains(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 {
getSecuredContainer().contains('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 {
getSecuredContainer().contains(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",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredContainer().contains(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 {
getSecuredContainer().contains(2L);
- 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 = Integer.valueOf("1234");
- try
- {
+ try {
getSecuredContainer().contains(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 {
getSecuredContainer().contains(
ResourceFactory
.createResource("http://example.com/testResource"));
- 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",
e, e.getTriple()));
}
}
- try
- {
+ try {
getSecuredContainer().contains("foo");
- 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 {
getSecuredContainer().contains("dos", "esp");
- 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 {
getSecuredContainer().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()));
}
}
}
@Test
- public void testRemove()
- {
+ public void testRemove() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
Action.Update, Action.Delete });
final Statement s = baseModel.listStatements().next();
- try
- {
+ try {
getSecuredContainer().remove(s);
- 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()));
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/fcf71889/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredLiteralTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredLiteralTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredLiteralTest.java
index 446bdc4..55d599d 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredLiteralTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredLiteralTest.java
@@ -17,55 +17,46 @@
*/
package org.apache.jena.permissions.model;
-import org.apache.jena.datatypes.DatatypeFormatException ;
-import org.apache.jena.permissions.AccessDeniedException;
+import org.apache.jena.datatypes.DatatypeFormatException;
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.SecuredLiteral;
import org.apache.jena.permissions.model.impl.SecuredLiteralImpl;
-import org.apache.jena.rdf.model.Literal ;
-import org.apache.jena.rdf.model.ResourceFactory ;
-import org.apache.jena.rdf.model.ResourceRequiredException ;
-import org.apache.jena.shared.BadBooleanException ;
-import org.apache.jena.shared.BadCharLiteralException ;
-import org.junit.Assert ;
-import org.junit.Before ;
-import org.junit.Test ;
-import org.junit.runner.RunWith ;
+import org.apache.jena.rdf.model.Literal;
+import org.apache.jena.rdf.model.ResourceFactory;
+import org.apache.jena.rdf.model.ResourceRequiredException;
+import org.apache.jena.shared.BadBooleanException;
+import org.apache.jena.shared.BadCharLiteralException;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
-@RunWith( value = SecurityEvaluatorParameters.class )
-public class SecuredLiteralTest extends SecuredRDFNodeTest
-{
+@RunWith(value = SecurityEvaluatorParameters.class)
+public class SecuredLiteralTest extends SecuredRDFNodeTest {
- public SecuredLiteralTest( final MockSecurityEvaluator securityEvaluator )
- {
+ public SecuredLiteralTest(final MockSecurityEvaluator securityEvaluator) {
super(securityEvaluator);
}
- private SecuredLiteral getSecuredLiteral()
- {
+ private SecuredLiteral getSecuredLiteral() {
return (SecuredLiteral) getSecuredRDFNode();
}
@Test
- public void sameValueAs()
- {
- try
- {
+ public void sameValueAs() {
+ try {
getSecuredLiteral().sameValueAs(
ResourceFactory.createPlainLiteral("Junk"));
- 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()));
}
}
@@ -73,395 +64,281 @@ public class SecuredLiteralTest extends SecuredRDFNodeTest
@Override
@Before
- public void setup()
- {
+ public void setup() {
super.setup();
Literal l = ResourceFactory.createTypedLiteral("literal");
setSecuredRDFNode(SecuredLiteralImpl.getInstance(securedModel, l), l);
}
@Test
- public void testAsLiteral()
- {
+ public void testAsLiteral() {
getSecuredLiteral().asLiteral();
}
@Test
- public void testAsResource()
- {
- try
- {
+ public void testAsResource() {
+ try {
getSecuredLiteral().asResource();
Assert.fail("Should have thrown ResoruceRequiredException");
- }
- catch (final ResourceRequiredException e)
- {
+ } catch (final ResourceRequiredException e) {
// expected
}
}
@Test
- public void testGetBoolean()
- {
- try
- {
+ public void testGetBoolean() {
+ try {
getSecuredLiteral().getBoolean();
- 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 DatatypeFormatException | BadBooleanException e )
- {
+ } catch (final DatatypeFormatException | BadBooleanException e) {
// expected
}
}
@Test
- public void testGetByte()
- {
- try
- {
+ public void testGetByte() {
+ try {
getSecuredLiteral().getByte();
- 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 DatatypeFormatException | NumberFormatException e )
- {
+ } catch (final DatatypeFormatException | NumberFormatException e) {
// expected
}
}
@Test
- public void testGetChar()
- {
- try
- {
+ public void testGetChar() {
+ try {
getSecuredLiteral().getChar();
- 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 DatatypeFormatException | BadCharLiteralException e )
- {
+ } catch (final DatatypeFormatException | BadCharLiteralException e) {
// expected
}
}
@Test
- public void testGetDatatype()
- {
- try
- {
+ public void testGetDatatype() {
+ try {
getSecuredLiteral().getDatatype();
- 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 testGetDatatypeURI()
- {
- try
- {
+ public void testGetDatatypeURI() {
+ try {
getSecuredLiteral().getDatatypeURI();
- 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 testGetDouble()
- {
- try
- {
+ public void testGetDouble() {
+ try {
getSecuredLiteral().getDouble();
- 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 DatatypeFormatException | NumberFormatException e )
- {
+ } catch (final DatatypeFormatException | NumberFormatException e) {
// expected
}
}
@Test
- public void testGetFloat()
- {
- try
- {
+ public void testGetFloat() {
+ try {
getSecuredLiteral().getFloat();
- 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 DatatypeFormatException | NumberFormatException e )
- {
+ } catch (final DatatypeFormatException | NumberFormatException e) {
// expected
}
}
@Test
- public void testGetInt()
- {
- try
- {
+ public void testGetInt() {
+ try {
getSecuredLiteral().getInt();
- 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 DatatypeFormatException | NumberFormatException e )
- {
+ } catch (final DatatypeFormatException | NumberFormatException e) {
// expected
}
}
@Test
- public void testGetLanguage()
- {
- try
- {
+ public void testGetLanguage() {
+ try {
getSecuredLiteral().getLanguage();
- 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 testGetLexicalForm()
- {
- try
- {
+ public void testGetLexicalForm() {
+ try {
getSecuredLiteral().getLexicalForm();
- 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 testGetLong()
- {
- try
- {
+ public void testGetLong() {
+ try {
getSecuredLiteral().getLong();
- 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 DatatypeFormatException | NumberFormatException e )
- {
+ } catch (final DatatypeFormatException | NumberFormatException e) {
// expected
}
}
@Test
- public void testGetShort()
- {
- try
- {
+ public void testGetShort() {
+ try {
getSecuredLiteral().getShort();
- 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 DatatypeFormatException | NumberFormatException e )
- {
+ } catch (final DatatypeFormatException | NumberFormatException e) {
// expected
}
}
@Test
- public void testGetString()
- {
- try
- {
+ public void testGetString() {
+ try {
getSecuredLiteral().getString();
- 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 DatatypeFormatException | NumberFormatException e )
- {
+ } catch (final DatatypeFormatException | NumberFormatException e) {
// expected
}
}
@Test
- public void testGetValue()
- {
- try
- {
+ public void testGetValue() {
+ try {
getSecuredLiteral().getValue();
- 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 testIsWellFormedXML()
- {
- try
- {
+ public void testIsWellFormedXML() {
+ try {
getSecuredLiteral().isWellFormedXML();
- 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/SecuredModelDetailTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelDetailTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelDetailTest.java
index 28b33ba..edd51ba 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelDetailTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelDetailTest.java
@@ -22,18 +22,18 @@ import java.security.Principal;
import java.util.Set;
import org.apache.http.auth.BasicUserPrincipal;
-import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.NodeFactory;
import org.apache.jena.permissions.Factory;
import org.apache.jena.permissions.SecurityEvaluator;
import org.apache.jena.permissions.model.SecuredModel;
-import org.apache.jena.rdf.model.* ;
-import org.apache.jena.vocabulary.RDF ;
+import org.apache.jena.rdf.model.*;
+import org.apache.jena.vocabulary.RDF;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
- * Tests secured model functions against graph where only partial data is
+ * Tests secured model functions against graph where only partial data is
* available to the user.
*
*/
@@ -43,288 +43,337 @@ public class SecuredModelDetailTest {
private Model baseModel;
private SecuredModel securedModel;
private DetailEvaluator secEval;
- private Property pTo = ResourceFactory.createProperty("http://example.com/to");
+ private Property pTo = ResourceFactory
+ .createProperty("http://example.com/to");
private Property pFrom = ResourceFactory
- .createProperty( "http://example.com/from");
-
+ .createProperty("http://example.com/from");
+
@Before
- public void setup()
- {
+ public void setup() {
baseModel = ModelFactory.createDefaultModel();
baseModel.removeAll();
- URL url = SecuredModelDetailTest.class.getClassLoader().getResource( "org/apache/jena/permissions/model/detail.ttl");
- baseModel.read( url.toExternalForm() );
- secEval = new DetailEvaluator( baseModel );
+ URL url = SecuredModelDetailTest.class.getClassLoader().getResource(
+ "org/apache/jena/permissions/model/detail.ttl");
+ baseModel.read(url.toExternalForm());
+ secEval = new DetailEvaluator(baseModel);
securedModel = Factory.getInstance(secEval,
"http://example.com/detailModelTest", baseModel);
}
-
@Test
- public void testContains()
- {
+ public void testContains() {
secEval.setPrincipal("darla");
- /* darla can only add values to msg4
- ex:msg4 rdf:type ex:msg;
- ex:to "darla" ;
- ex:from "bob" ;
- ex:subj "bob to darla 1"
+ /*
+ * darla can only add values to msg4 ex:msg4 rdf:type ex:msg; ex:to
+ * "darla" ; ex:from "bob" ; ex:subj "bob to darla 1"
*/
-
- Resource s = ResourceFactory.createResource( String.format( NS_FMT, "msg3") );
- Assert.assertTrue( "should contain msg3", baseModel.contains( s, null ));
- Assert.assertFalse( "should not see msg3", securedModel.contains( s, null ));
- Assert.assertTrue( "Sould contain a resource msg3", baseModel.containsResource( s));
- Assert.assertFalse( "Should not contain a resource msg3'", securedModel.containsResource( s) );
-
- s = ResourceFactory.createResource( String.format( NS_FMT, "msg4") );
- Assert.assertTrue( "should contain msg4", baseModel.contains( s, null ));
- Assert.assertTrue( "should see msg4", securedModel.contains( s, null ));
- Assert.assertTrue( "Sould contain a resource msg4", baseModel.containsResource( s));
- Assert.assertTrue( "Should contain a resource msg4'", securedModel.containsResource( s) );
-
- Assert.assertTrue( "Sould contain a to 'bob'", baseModel.contains( null, pTo, "bob"));
- Assert.assertFalse( "Should not see to 'bob'", securedModel.contains( null, pTo, "bob") );
-
- Assert.assertTrue( "Sould contain a from 'bob'", baseModel.contains( null, pFrom, "bob"));
- Assert.assertTrue( "Should see from 'bob'", securedModel.contains( null, pFrom, "bob") );
+
+ Resource s = ResourceFactory.createResource(String.format(NS_FMT,
+ "msg3"));
+ Assert.assertTrue("should contain msg3", baseModel.contains(s, null));
+ Assert.assertFalse("should not see msg3",
+ securedModel.contains(s, null));
+ Assert.assertTrue("Sould contain a resource msg3",
+ baseModel.containsResource(s));
+ Assert.assertFalse("Should not contain a resource msg3'",
+ securedModel.containsResource(s));
+
+ s = ResourceFactory.createResource(String.format(NS_FMT, "msg4"));
+ Assert.assertTrue("should contain msg4", baseModel.contains(s, null));
+ Assert.assertTrue("should see msg4", securedModel.contains(s, null));
+ Assert.assertTrue("Sould contain a resource msg4",
+ baseModel.containsResource(s));
+ Assert.assertTrue("Should contain a resource msg4'",
+ securedModel.containsResource(s));
+
+ Assert.assertTrue("Sould contain a to 'bob'",
+ baseModel.contains(null, pTo, "bob"));
+ Assert.assertFalse("Should not see to 'bob'",
+ securedModel.contains(null, pTo, "bob"));
+
+ Assert.assertTrue("Sould contain a from 'bob'",
+ baseModel.contains(null, pFrom, "bob"));
+ Assert.assertTrue("Should see from 'bob'",
+ securedModel.contains(null, pFrom, "bob"));
}
-
+
@Test
- public void testListObjects()
- {
+ public void testListObjects() {
secEval.setPrincipal("darla");
- /* darla can only add values to msg4
- ex:msg4 rdf:type ex:msg;
- ex:to "darla" ;
- ex:from "bob" ;
- ex:subj "bob to darla 1"
+ /*
+ * darla can only add values to msg4 ex:msg4 rdf:type ex:msg; ex:to
+ * "darla" ; ex:from "bob" ; ex:subj "bob to darla 1"
*/
-
- Assert.assertTrue( baseModel.listObjects().toList().size() > 4);
- Assert.assertEquals( 4, securedModel.listObjects().toList().size());
-
- Assert.assertTrue( baseModel.listObjectsOfProperty( pFrom ).toList().size() > 1);
- Assert.assertEquals( 1, securedModel.listObjectsOfProperty( pFrom ).toList().size());
-
- Resource s = ResourceFactory.createResource( String.format( NS_FMT, "msg3"));
- Assert.assertEquals( 1, baseModel.listObjectsOfProperty( s, pFrom).toList().size());
- Assert.assertEquals( 0, securedModel.listObjectsOfProperty( s, pFrom ).toList().size());
-
- s = ResourceFactory.createResource( String.format( NS_FMT, "msg4"));
- Assert.assertEquals( 1, baseModel.listObjectsOfProperty( s, pFrom).toList().size());
- Assert.assertEquals( 1, securedModel.listObjectsOfProperty( s, pFrom ).toList().size());
+
+ Assert.assertTrue(baseModel.listObjects().toList().size() > 4);
+ Assert.assertEquals(4, securedModel.listObjects().toList().size());
+
+ Assert.assertTrue(baseModel.listObjectsOfProperty(pFrom).toList()
+ .size() > 1);
+ Assert.assertEquals(1, securedModel.listObjectsOfProperty(pFrom)
+ .toList().size());
+
+ Resource s = ResourceFactory.createResource(String.format(NS_FMT,
+ "msg3"));
+ Assert.assertEquals(1, baseModel.listObjectsOfProperty(s, pFrom)
+ .toList().size());
+ Assert.assertEquals(0, securedModel.listObjectsOfProperty(s, pFrom)
+ .toList().size());
+
+ s = ResourceFactory.createResource(String.format(NS_FMT, "msg4"));
+ Assert.assertEquals(1, baseModel.listObjectsOfProperty(s, pFrom)
+ .toList().size());
+ Assert.assertEquals(1, securedModel.listObjectsOfProperty(s, pFrom)
+ .toList().size());
}
-
+
@Test
public void testListResources() {
secEval.setPrincipal("darla");
- /* darla can only add values to msg4
- ex:msg4 rdf:type ex:msg;
- ex:to "darla" ;
- ex:from "bob" ;
- ex:subj "bob to darla 1"
+ /*
+ * darla can only add values to msg4 ex:msg4 rdf:type ex:msg; ex:to
+ * "darla" ; ex:from "bob" ; ex:subj "bob to darla 1"
*/
- Assert.assertEquals( 5, baseModel.listResourcesWithProperty( pFrom ).toList().size());
- Assert.assertEquals( 1, securedModel.listResourcesWithProperty( pFrom ).toList().size());
-
+ Assert.assertEquals(5, baseModel.listResourcesWithProperty(pFrom)
+ .toList().size());
+ Assert.assertEquals(1, securedModel.listResourcesWithProperty(pFrom)
+ .toList().size());
+
RDFNode o = ResourceFactory.createPlainLiteral("bob");
- Assert.assertEquals( 3, baseModel.listResourcesWithProperty( pFrom, o ).toList().size());
- Assert.assertEquals( 1, securedModel.listResourcesWithProperty( pFrom, o ).toList().size());
- Assert.assertEquals( 1, baseModel.listResourcesWithProperty( pTo, o ).toList().size());
- Assert.assertEquals( 0, securedModel.listResourcesWithProperty( pTo, o ).toList().size());
-
- Assert.assertEquals( 4, baseModel.listResourcesWithProperty( null, o ).toList().size());
- Assert.assertEquals( 1, securedModel.listResourcesWithProperty( null, o ).toList().size());
-
+ Assert.assertEquals(3, baseModel.listResourcesWithProperty(pFrom, o)
+ .toList().size());
+ Assert.assertEquals(1, securedModel.listResourcesWithProperty(pFrom, o)
+ .toList().size());
+ Assert.assertEquals(1, baseModel.listResourcesWithProperty(pTo, o)
+ .toList().size());
+ Assert.assertEquals(0, securedModel.listResourcesWithProperty(pTo, o)
+ .toList().size());
+
+ Assert.assertEquals(4, baseModel.listResourcesWithProperty(null, o)
+ .toList().size());
+ Assert.assertEquals(1, securedModel.listResourcesWithProperty(null, o)
+ .toList().size());
+
o = ResourceFactory.createPlainLiteral("alice");
- Assert.assertEquals( 4, baseModel.listResourcesWithProperty( null, o ).toList().size());
- Assert.assertEquals( 0, securedModel.listResourcesWithProperty( null, o ).toList().size());
+ Assert.assertEquals(4, baseModel.listResourcesWithProperty(null, o)
+ .toList().size());
+ Assert.assertEquals(0, securedModel.listResourcesWithProperty(null, o)
+ .toList().size());
}
-
+
@Test
- public void testListStatements()
- {
+ public void testListStatements() {
secEval.setPrincipal("darla");
- /* darla can only add values to msg4
- ex:msg4 rdf:type ex:msg;
- ex:to "darla" ;
- ex:from "bob" ;
- ex:subj "bob to darla 1"
+ /*
+ * darla can only add values to msg4 ex:msg4 rdf:type ex:msg; ex:to
+ * "darla" ; ex:from "bob" ; ex:subj "bob to darla 1"
*/
- Assert.assertEquals( 20, baseModel.listStatements().toList().size());
- Assert.assertEquals( 4, securedModel.listStatements().toList().size());
-
+ Assert.assertEquals(20, baseModel.listStatements().toList().size());
+ Assert.assertEquals(4, securedModel.listStatements().toList().size());
+
RDFNode o = ResourceFactory.createPlainLiteral("bob");
- Assert.assertEquals( 1, baseModel.listStatements( null, pTo, o).toList().size());
- Assert.assertEquals( 0, securedModel.listStatements( null, pTo, o).toList().size());
- Assert.assertEquals( 3, baseModel.listStatements( null, pFrom, o).toList().size());
- Assert.assertEquals( 1, securedModel.listStatements( null, pFrom, o).toList().size());
-
- Resource s = ResourceFactory.createResource( String.format( NS_FMT, "msg3"));
- Assert.assertEquals( 4, baseModel.listStatements( s, null, (RDFNode)null).toList().size());
- Assert.assertEquals( 0, securedModel.listStatements( s, null, (RDFNode)null).toList().size());
-
- Assert.assertEquals( 1, baseModel.listStatements( s, pTo, (RDFNode)null).toList().size());
- Assert.assertEquals( 0, securedModel.listStatements( s, pTo, (RDFNode)null).toList().size());
-
- Assert.assertEquals( 0, baseModel.listStatements( s, pTo, o).toList().size());
- Assert.assertEquals( 0, securedModel.listStatements( s, pTo, o).toList().size());
+ Assert.assertEquals(1, baseModel.listStatements(null, pTo, o).toList()
+ .size());
+ Assert.assertEquals(0, securedModel.listStatements(null, pTo, o)
+ .toList().size());
+ Assert.assertEquals(3, baseModel.listStatements(null, pFrom, o)
+ .toList().size());
+ Assert.assertEquals(1, securedModel.listStatements(null, pFrom, o)
+ .toList().size());
+
+ Resource s = ResourceFactory.createResource(String.format(NS_FMT,
+ "msg3"));
+ Assert.assertEquals(4, baseModel
+ .listStatements(s, null, (RDFNode) null).toList().size());
+ Assert.assertEquals(0,
+ securedModel.listStatements(s, null, (RDFNode) null).toList()
+ .size());
+
+ Assert.assertEquals(1, baseModel.listStatements(s, pTo, (RDFNode) null)
+ .toList().size());
+ Assert.assertEquals(0,
+ securedModel.listStatements(s, pTo, (RDFNode) null).toList()
+ .size());
+
+ Assert.assertEquals(0, baseModel.listStatements(s, pTo, o).toList()
+ .size());
+ Assert.assertEquals(0, securedModel.listStatements(s, pTo, o).toList()
+ .size());
o = ResourceFactory.createPlainLiteral("chuck");
- Assert.assertEquals( 1, baseModel.listStatements( s, pTo, o).toList().size());
- Assert.assertEquals( 0, securedModel.listStatements( s, pTo, o).toList().size());
-
-
- s = ResourceFactory.createResource( String.format( NS_FMT, "msg4"));
- Assert.assertEquals( 4, baseModel.listStatements( s, null, (RDFNode)null).toList().size());
- Assert.assertEquals( 4, securedModel.listStatements( s, null, (RDFNode)null).toList().size());
-
- Assert.assertEquals( 1, baseModel.listStatements( s, pTo, (RDFNode)null).toList().size());
- Assert.assertEquals( 1, securedModel.listStatements( s, pTo, (RDFNode)null).toList().size());
-
- Assert.assertEquals( 0, baseModel.listStatements( s, pTo, o).toList().size());
- Assert.assertEquals( 0, securedModel.listStatements( s, pTo, o).toList().size());
+ Assert.assertEquals(1, baseModel.listStatements(s, pTo, o).toList()
+ .size());
+ Assert.assertEquals(0, securedModel.listStatements(s, pTo, o).toList()
+ .size());
+
+ s = ResourceFactory.createResource(String.format(NS_FMT, "msg4"));
+ Assert.assertEquals(4, baseModel
+ .listStatements(s, null, (RDFNode) null).toList().size());
+ Assert.assertEquals(4,
+ securedModel.listStatements(s, null, (RDFNode) null).toList()
+ .size());
+
+ Assert.assertEquals(1, baseModel.listStatements(s, pTo, (RDFNode) null)
+ .toList().size());
+ Assert.assertEquals(1,
+ securedModel.listStatements(s, pTo, (RDFNode) null).toList()
+ .size());
+
+ Assert.assertEquals(0, baseModel.listStatements(s, pTo, o).toList()
+ .size());
+ Assert.assertEquals(0, securedModel.listStatements(s, pTo, o).toList()
+ .size());
o = ResourceFactory.createPlainLiteral("darla");
- Assert.assertEquals( 1, baseModel.listStatements( s, pTo, o).toList().size());
- Assert.assertEquals( 1, securedModel.listStatements( s, pTo, o).toList().size());
+ Assert.assertEquals(1, baseModel.listStatements(s, pTo, o).toList()
+ .size());
+ Assert.assertEquals(1, securedModel.listStatements(s, pTo, o).toList()
+ .size());
}
-
+
@Test
- public void testListSubjects()
- {
+ public void testListSubjects() {
secEval.setPrincipal("darla");
- /* darla can only add values to msg4
- ex:msg4 rdf:type ex:msg;
- ex:to "darla" ;
- ex:from "bob" ;
- ex:subj "bob to darla 1"
+ /*
+ * darla can only add values to msg4 ex:msg4 rdf:type ex:msg; ex:to
+ * "darla" ; ex:from "bob" ; ex:subj "bob to darla 1"
*/
- Assert.assertEquals( 5, baseModel.listSubjects().toList().size());
- Assert.assertEquals( 1, securedModel.listSubjects().toList().size());
-
- Assert.assertEquals( 5, baseModel.listSubjectsWithProperty( pTo ).toList().size());
- Assert.assertEquals( 1, securedModel.listSubjectsWithProperty( pTo ).toList().size());
-
+ Assert.assertEquals(5, baseModel.listSubjects().toList().size());
+ Assert.assertEquals(1, securedModel.listSubjects().toList().size());
+
+ Assert.assertEquals(5, baseModel.listSubjectsWithProperty(pTo).toList()
+ .size());
+ Assert.assertEquals(1, securedModel.listSubjectsWithProperty(pTo)
+ .toList().size());
+
RDFNode o = ResourceFactory.createPlainLiteral("darla");
- Assert.assertEquals( 1, baseModel.listSubjectsWithProperty( pTo, o ).toList().size());
- Assert.assertEquals( 1, securedModel.listSubjectsWithProperty( pTo, o ).toList().size());
-
+ Assert.assertEquals(1, baseModel.listSubjectsWithProperty(pTo, o)
+ .toList().size());
+ Assert.assertEquals(1, securedModel.listSubjectsWithProperty(pTo, o)
+ .toList().size());
+
o = ResourceFactory.createPlainLiteral("bob");
- Assert.assertEquals( 1, baseModel.listSubjectsWithProperty( pTo, o ).toList().size());
- Assert.assertEquals( 0, securedModel.listSubjectsWithProperty( pTo, o ).toList().size());
-
- Assert.assertEquals( 4, baseModel.listSubjectsWithProperty( null, o ).toList().size());
- Assert.assertEquals( 1, securedModel.listSubjectsWithProperty( null, o ).toList().size());
-
+ Assert.assertEquals(1, baseModel.listSubjectsWithProperty(pTo, o)
+ .toList().size());
+ Assert.assertEquals(0, securedModel.listSubjectsWithProperty(pTo, o)
+ .toList().size());
+
+ Assert.assertEquals(4, baseModel.listSubjectsWithProperty(null, o)
+ .toList().size());
+ Assert.assertEquals(1, securedModel.listSubjectsWithProperty(null, o)
+ .toList().size());
+
}
-
+
/**
- * An example evaluator that only provides access ot messages in the graph that
- * are from or to the principal.
+ * An example evaluator that only provides access ot messages in the graph
+ * that are from or to the principal.
*
*/
private class DetailEvaluator implements SecurityEvaluator {
-
+
private Principal principal;
private Model model;
- private RDFNode msgType = ResourceFactory.createResource( "http://example.com/msg" );
- private Property pTo = ResourceFactory.createProperty( "http://example.com/to" );
- private Property pFrom = ResourceFactory.createProperty( "http://example.com/from" );
-
+ private RDFNode msgType = ResourceFactory
+ .createResource("http://example.com/msg");
+ private Property pTo = ResourceFactory
+ .createProperty("http://example.com/to");
+ private Property pFrom = ResourceFactory
+ .createProperty("http://example.com/from");
+
/**
*
- * @param model The graph we are going to evaluate against.
+ * @param model
+ * The graph we are going to evaluate against.
*/
- public DetailEvaluator( Model model )
- {
+ public DetailEvaluator(Model model) {
this.model = model;
}
-
+
@Override
- public boolean evaluate(Object principal, Action action, SecNode graphIRI) {
+ public boolean evaluate(Object principal, Action action,
+ SecNode graphIRI) {
// we allow any action on a graph.
return true;
}
- private boolean evaluate( Resource r )
- {
+ private boolean evaluate(Resource r) {
// a message is only available to sender or recipient
- if (r.hasProperty( RDF.type, msgType ))
- {
- return r.hasProperty( pTo, ((Principal)principal).getName() ) ||
- r.hasProperty( pFrom, ((Principal)principal).getName());
+ if (r.hasProperty(RDF.type, msgType)) {
+ return r.hasProperty(pTo, principal.getName())
+ || r.hasProperty(pFrom,
+ principal.getName());
}
- return true;
+ return true;
}
-
- private boolean evaluate( SecNode node )
- {
- if (node.equals( SecNode.ANY )) {
- return false; // all wild cards are false
- }
-
- if (node.getType().equals( SecNode.Type.URI)) {
- Resource r = model.createResource( node.getValue() );
- return evaluate( r );
- }
- else if (node.getType().equals( SecNode.Type.Anonymous)) {
- Resource r = model.getRDFNode( NodeFactory.createAnon( new AnonId( node.getValue()) ) ).asResource();
- return evaluate( r );
+
+ private boolean evaluate(SecNode node) {
+ if (node.equals(SecNode.ANY)) {
+ return false; // all wild cards are false
}
- else
- {
+
+ if (node.getType().equals(SecNode.Type.URI)) {
+ Resource r = model.createResource(node.getValue());
+ return evaluate(r);
+ } else if (node.getType().equals(SecNode.Type.Anonymous)) {
+ Resource r = model.getRDFNode(
+ NodeFactory.createAnon(new AnonId(node.getValue())))
+ .asResource();
+ return evaluate(r);
+ } else {
return true;
}
}
-
- private boolean evaluate( SecTriple triple ) {
- return evaluate( triple.getSubject()) &&
- evaluate( triple.getObject()) &&
- evaluate( triple.getPredicate());
+
+ private boolean evaluate(SecTriple triple) {
+ return evaluate(triple.getSubject())
+ && evaluate(triple.getObject())
+ && evaluate(triple.getPredicate());
}
-
+
@Override
- public boolean evaluate(Object principal, Action action, SecNode graphIRI, SecTriple triple) {
- return evaluate( triple );
+ public boolean evaluate(Object principal, Action action,
+ SecNode graphIRI, SecTriple triple) {
+ return evaluate(triple);
}
@Override
- public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI) {
+ public boolean evaluate(Object principal, Set<Action> actions,
+ SecNode graphIRI) {
return true;
}
@Override
- public boolean evaluate(Object principal, Set<Action> actions, SecNode graphIRI,
- SecTriple triple) {
- return evaluate( triple );
+ public boolean evaluate(Object principal, Set<Action> actions,
+ SecNode graphIRI, SecTriple triple) {
+ return evaluate(triple);
}
@Override
- public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI) {
+ public boolean evaluateAny(Object principal, Set<Action> actions,
+ SecNode graphIRI) {
return true;
}
@Override
- public boolean evaluateAny(Object principal, Set<Action> actions, SecNode graphIRI,
- SecTriple triple) {
- return evaluate( triple );
+ public boolean evaluateAny(Object principal, Set<Action> actions,
+ SecNode graphIRI, SecTriple triple) {
+ return evaluate(triple);
}
@Override
- public boolean evaluateUpdate(Object principal, SecNode graphIRI, SecTriple from, SecTriple to) {
- return evaluate( from ) && evaluate( to );
+ public boolean evaluateUpdate(Object principal, SecNode graphIRI,
+ SecTriple from, SecTriple to) {
+ return evaluate(from) && evaluate(to);
}
- public void setPrincipal( String userName )
- {
- if (userName == null)
- {
+ public void setPrincipal(String userName) {
+ if (userName == null) {
principal = null;
}
- principal = new BasicUserPrincipal( userName );
+ principal = new BasicUserPrincipal(userName);
}
+
@Override
public Principal getPrincipal() {
return principal;