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 2016/10/08 00:02:00 UTC
[2/8] jena git commit: Added code to properly filter the new literal
language filtering methods. Added test code for the above.
http://git-wip-us.apache.org/repos/asf/jena/blob/dabc43f6/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelTest.java
index b0e6be3..dd3b1c6 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredModelTest.java
@@ -17,6 +17,9 @@
*/
package org.apache.jena.permissions.model;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.io.*;
import java.net.URL;
import java.util.ArrayList;
@@ -48,6 +51,7 @@ public class SecuredModelTest {
protected Model baseModel;
protected Resource s;
protected Property p;
+ protected Property p2;
protected Resource o;
public SecuredModelTest(final MockSecurityEvaluator securityEvaluator) {
@@ -67,19 +71,22 @@ public class SecuredModelTest {
public void setup() {
baseModel = createModel();
baseModel.removeAll();
- securedModel = Factory.getInstance(securityEvaluator,
- "http://example.com/securedGraph", baseModel);
+ securedModel = Factory.getInstance(securityEvaluator, "http://example.com/securedGraph", baseModel);
s = ResourceFactory.createResource("http://example.com/graph/s");
p = ResourceFactory.createProperty("http://example.com/graph/p");
o = ResourceFactory.createResource("http://example.com/graph/o");
baseModel.add(s, p, o);
+ p2 = ResourceFactory.createProperty("http://example.com/graph/p2");
+ baseModel.add(s, p2, "yeehaw");
+ baseModel.add(s, p2, "yeehaw yall", "us");
+ baseModel.add(s, p2, "whohoo", "uk");
+
}
@Test
public void testAdd() throws Exception {
final List<Statement> stmt = baseModel.listStatements().toList();
- final Set<Action> createAndUpdate = SecurityEvaluator.Util
- .asSet(new Action[] { Action.Update, Action.Create });
+ final Set<Action> createAndUpdate = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
try {
securedModel.add(stmt);
if (!securityEvaluator.evaluate(createAndUpdate)) {
@@ -87,9 +94,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -99,9 +105,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -111,9 +116,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -124,9 +128,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -136,9 +139,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -148,9 +150,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -160,9 +161,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -172,9 +172,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -184,9 +183,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -196,9 +194,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -208,9 +205,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -221,15 +217,12 @@ public class SecuredModelTest {
// test anonymous
final RDFNode rdfNode = ResourceFactory.createResource();
final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
- Assert.assertEquals(
- "Should have placed RDFNode in secured securedModel",
- securedModel, rdfNode2.getModel());
+ Assert.assertEquals("Should have placed RDFNode in secured securedModel", securedModel, rdfNode2.getModel());
}
@Test
public void testAsRDFNode() throws Exception {
- securedModel.asRDFNode(NodeFactory
- .createURI("http://example.com/rdfNode"));
+ securedModel.asRDFNode(NodeFactory.createURI("http://example.com/rdfNode"));
}
@Test
@@ -242,9 +235,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -259,9 +251,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -272,9 +263,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -284,9 +274,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -296,9 +285,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -308,9 +296,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -325,9 +312,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -337,17 +323,15 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testCreateAlt() throws Exception {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] { Action.Create, Action.Update });
try {
securedModel.createAlt();
if (!securityEvaluator.evaluate(CU)) {
@@ -355,9 +339,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -367,17 +350,15 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testCreateBag() throws Exception {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] { Action.Create, Action.Update });
try {
securedModel.createBag();
if (!securityEvaluator.evaluate(CU)) {
@@ -385,9 +366,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -397,29 +377,26 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testCreateList() throws Exception {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
final List<RDFNode> nodeList = new ArrayList<RDFNode>();
try {
securedModel.createList();
- if ( ! securityEvaluator.evaluate(CU)) {
+ if (!securityEvaluator.evaluate(CU)) {
Assert.fail("Should have thrown UpdateDeniedException Exception");
}
} catch (final AccessDeniedException e) {
- if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ if (securityEvaluator.evaluate(CU)) {
+ Assert.fail(String.format("Should not have thrown UpdateDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
baseModel.removeAll();
@@ -431,19 +408,15 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
baseModel.removeAll();
try {
- final RDFNode[] list = new RDFNode[] {
- ResourceFactory.createResource(),
- ResourceFactory.createResource(),
- ResourceFactory.createResource(),
- ResourceFactory.createResource(), };
+ final RDFNode[] list = new RDFNode[] { ResourceFactory.createResource(), ResourceFactory.createResource(),
+ ResourceFactory.createResource(), ResourceFactory.createResource(), };
securedModel.createList(list);
if (!securityEvaluator.evaluate(CU)) {
@@ -451,9 +424,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
baseModel.removeAll();
@@ -468,8 +440,7 @@ public class SecuredModelTest {
@Test
public void testCreateLiteralBoolean() throws Exception {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] { Action.Create, Action.Update });
try {
securedModel.createLiteralStatement(s, p, true);
@@ -478,17 +449,15 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testCreateLiteralChar() throws Exception {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] { Action.Create, Action.Update });
try {
securedModel.createLiteralStatement(s, p, 'a');
if (!securityEvaluator.evaluate(CU)) {
@@ -496,17 +465,15 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testCreateLiteralDouble() throws Exception {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] { Action.Create, Action.Update });
try {
securedModel.createLiteralStatement(s, p, 1.0d);
@@ -515,17 +482,15 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testCreateLiteralFloat() throws Exception {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] { Action.Create, Action.Update });
try {
securedModel.createLiteralStatement(s, p, 1.0f);
@@ -534,17 +499,15 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testCreateLiteralInt() throws Exception {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] { Action.Create, Action.Update });
try {
securedModel.createLiteralStatement(s, p, 1);
@@ -553,9 +516,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -563,8 +525,7 @@ public class SecuredModelTest {
@Test
public void testCreateLiteralLong() throws Exception {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] { Action.Create, Action.Update });
try {
securedModel.createLiteralStatement(s, p, 1L);
@@ -573,30 +534,26 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testCreateLiteralObject() throws Exception {
- final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Create, Action.Update });
+ final Set<Action> CU = SecurityEvaluator.Util.asSet(new Action[] { Action.Create, Action.Update });
try {
- securedModel.createLiteralStatement(s, p, new URL(
- "http://example.com/testing/URIType"));
+ securedModel.createLiteralStatement(s, p, new URL("http://example.com/testing/URIType"));
if (!securityEvaluator.evaluate(CU)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(CU)) {
e.printStackTrace();
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -610,9 +567,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -632,17 +588,15 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testGetAlt() throws Exception {
- final Resource a = baseModel
- .createAlt("http://example.com/securedModel/alt");
+ final Resource a = baseModel.createAlt("http://example.com/securedModel/alt");
try {
securedModel.getAlt(a);
@@ -651,9 +605,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -664,9 +617,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -674,20 +626,18 @@ public class SecuredModelTest {
@Test
public void testGetAnyReifiedStmt() {
// first with create.
- final Set<Action> UCR = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create, Action.Read });
+ final Set<Action> UCR = SecurityEvaluator.Util
+ .asSet(new Action[] { Action.Update, Action.Create, Action.Read });
try {
- securedModel.getAnyReifiedStatement(baseModel.listStatements()
- .next());
+ securedModel.getAnyReifiedStatement(baseModel.listStatements().next());
if (!securityEvaluator.evaluate(UCR)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(UCR)) {
e.printStackTrace();
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -701,17 +651,15 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testGetBag() {
- final Resource b = baseModel
- .createBag("http://example.com/securedModel/bag");
+ final Resource b = baseModel.createBag("http://example.com/securedModel/bag");
try {
securedModel.getBag(b);
if (!securityEvaluator.evaluate(Action.Read)) {
@@ -719,9 +667,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -732,9 +679,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -761,9 +707,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -773,9 +718,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -785,9 +729,53 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetPropertyWithLang() {
+
+ try {
+ SecuredStatement stmt = securedModel.getProperty(s, p2, "");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
+ }
+ assertNotNull(stmt);
+ assertEquals("yeehaw", stmt.getObject().asLiteral().getString());
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
+ }
+ }
+ try {
+ SecuredStatement stmt = securedModel.getProperty(s, p2, "us");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
+ }
+ assertNotNull(stmt);
+ assertEquals("yeehaw yall", stmt.getObject().asLiteral().getString());
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
+ }
+ }
+
+ try {
+ SecuredStatement stmt = securedModel.getProperty(s, p2, "uk");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
+ }
+ assertNotNull(stmt);
+ assertEquals("whohoo", stmt.getObject().asLiteral().getString());
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -801,15 +789,14 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
- public void testgetRDFNode() {
+ public void testGetRDFNode() {
try {
securedModel.getRDFNode(NodeFactory.createURI("foo"));
@@ -818,9 +805,8 @@ public class SecuredModelTest {
}
} catch (final UpdateDeniedException e) {
if (securityEvaluator.evaluate(Action.Update)) {
- Assert.fail(String
- .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown UpdateDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -838,8 +824,7 @@ public class SecuredModelTest {
@Test
public void testGetSeq() {
- final Resource s = baseModel
- .createSeq("http://example.com/securedModel/seq");
+ final Resource s = baseModel.createSeq("http://example.com/securedModel/seq");
try {
securedModel.getSeq(s);
if (!securityEvaluator.evaluate(Action.Read)) {
@@ -847,9 +832,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -859,9 +843,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -886,9 +869,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -907,9 +889,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -923,9 +904,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -936,9 +916,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -952,9 +931,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -969,9 +947,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -981,9 +958,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -993,9 +969,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -1005,9 +980,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -1017,9 +991,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -1033,9 +1006,8 @@ public class SecuredModelTest {
}
} catch (final UpdateDeniedException e) {
if (securityEvaluator.evaluate(Action.Update)) {
- Assert.fail(String
- .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown UpdateDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -1055,9 +1027,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -1065,26 +1036,20 @@ public class SecuredModelTest {
@Test
public void testRDFNodeInModel() {
// test uri
- final RDFNode rdfNode = ResourceFactory
- .createResource("http://exmple.com/testInModel");
+ final RDFNode rdfNode = ResourceFactory.createResource("http://exmple.com/testInModel");
final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
- Assert.assertEquals(
- "Should have placed RDFNode in secured securedModel",
- securedModel, rdfNode2.getModel());
+ Assert.assertEquals("Should have placed RDFNode in secured securedModel", securedModel, rdfNode2.getModel());
}
@Test
public void testReadEmpty() throws Exception {
- final Set<Action> createAndUpdate = SecurityEvaluator.Util
- .asSet(new Action[] { Action.Update, Action.Create });
+ final Set<Action> createAndUpdate = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
- final String XML_INPUT = "<rdf:RDF"
- + " xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' "
- + " xmlns:rt='http://example.com/readTest#' "
- + " xmlns:j.0='http://example.com/readTest#3' > "
+ final String XML_INPUT = "<rdf:RDF" + " xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' "
+ + " xmlns:rt='http://example.com/readTest#' " + " xmlns:j.0='http://example.com/readTest#3' > "
+ " <rdf:Description rdf:about='http://example.com/readTest#1'> "
- + " <rdf:type rdf:resource='http://example.com/readTest#3'/>"
- + " </rdf:Description>" + "</rdf:RDF>";
+ + " <rdf:type rdf:resource='http://example.com/readTest#3'/>" + " </rdf:Description>"
+ + "</rdf:RDF>";
final String TTL_INPUT = "@prefix rt: <http://example.com/readTest#> . rt:1 a rt:3 .";
final String base = "http://example.com/test";
final String lang = "TURTLE";
@@ -1096,26 +1061,23 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} finally {
baseModel.removeAll();
}
try {
- final InputStream in = new ByteArrayInputStream(
- XML_INPUT.getBytes());
+ final InputStream in = new ByteArrayInputStream(XML_INPUT.getBytes());
securedModel.read(in, base);
if (!securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} finally {
baseModel.removeAll();
@@ -1129,9 +1091,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} finally {
baseModel.removeAll();
@@ -1145,26 +1106,23 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} finally {
baseModel.removeAll();
}
try {
- final InputStream in = new ByteArrayInputStream(
- TTL_INPUT.getBytes());
+ final InputStream in = new ByteArrayInputStream(TTL_INPUT.getBytes());
securedModel.read(in, base, lang);
if (!securityEvaluator.evaluate(createAndUpdate)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} finally {
baseModel.removeAll();
@@ -1178,9 +1136,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} finally {
baseModel.removeAll();
@@ -1194,9 +1151,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(createAndUpdate)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} finally {
baseModel.removeAll();
@@ -1206,8 +1162,7 @@ public class SecuredModelTest {
@Test
public void testRemove() throws Exception {
- final Set<Action> DU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Delete, Action.Update });
+ final Set<Action> DU = SecurityEvaluator.Util.asSet(new Action[] { Action.Delete, Action.Update });
final List<Statement> stmt = baseModel.listStatements().toList();
try {
@@ -1217,9 +1172,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(DU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -1230,9 +1184,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(DU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -1242,9 +1195,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(DU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -1255,9 +1207,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(DU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -1268,9 +1219,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(DU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -1281,9 +1231,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(DU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -1294,9 +1243,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(DU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -1304,8 +1252,7 @@ public class SecuredModelTest {
@Test
public void testRemoveAll() throws Exception {
- final Set<Action> DU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Delete, Action.Update });
+ final Set<Action> DU = SecurityEvaluator.Util.asSet(new Action[] { Action.Delete, Action.Update });
try {
securedModel.removeAll();
@@ -1314,9 +1261,8 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(DU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -1329,17 +1275,15 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(DU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testRemoveAllReifications() {
- final Set<Action> DU = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Delete, Action.Update });
+ final Set<Action> DU = SecurityEvaluator.Util.asSet(new Action[] { Action.Delete, Action.Update });
final List<Statement> stmt = baseModel.listStatements().toList();
baseModel.createReifiedStatement(stmt.get(0));
@@ -1351,15 +1295,14 @@ public class SecuredModelTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(DU)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
- public void testRequiredProperty() {
+ public void testGetRequiredProperty() {
try {
securedModel.getRequiredProperty(s, p);
@@ -1368,9 +1311,54 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
+ }
+ }
+ }
+
+ @Test
+ public void testGetRequiredPropertyWithLang() {
+
+ try {
+ SecuredStatement stmt = securedModel.getRequiredProperty(s, p2, "");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
+ }
+ assertNotNull(stmt);
+ assertEquals("yeehaw", stmt.getObject().asLiteral().getString());
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
+ }
+ }
+
+ try {
+ SecuredStatement stmt = securedModel.getRequiredProperty(s, p2, "us");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
+ }
+ assertNotNull(stmt);
+ assertEquals("yeehaw yall", stmt.getObject().asLiteral().getString());
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
+ }
+ }
+
+ try {
+ SecuredStatement stmt = securedModel.getRequiredProperty(s, p2, "uk");
+ if (!securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail("Should have thrown ReadDeniedException Exception");
+ }
+ assertNotNull(stmt);
+ assertEquals("whohoo", stmt.getObject().asLiteral().getString());
+ } catch (final ReadDeniedException e) {
+ if (securityEvaluator.evaluate(Action.Read)) {
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -1384,9 +1372,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -1400,9 +1387,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -1413,9 +1399,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -1423,29 +1408,25 @@ public class SecuredModelTest {
@Test
public void testVariableInModel() {
try {
- final RDFNode rdfNode = ResourceFactory
- .createTypedLiteral("yeehaw");
+ final RDFNode rdfNode = ResourceFactory.createTypedLiteral("yeehaw2");
final RDFNode rdfNode2 = rdfNode.inModel(securedModel);
if (!securityEvaluator.evaluate(Action.Update)) {
Assert.fail("Should have thrown UpdateDeniedException Exception");
}
- Assert.assertEquals(
- "Should have placed RDFNode in secured securedModel",
- securedModel, rdfNode2.getModel());
+ Assert.assertEquals("Should have placed RDFNode in secured securedModel", securedModel,
+ rdfNode2.getModel());
} catch (final UpdateDeniedException e) {
if (securityEvaluator.evaluate(Action.Update)) {
- Assert.fail(String
- .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown UpdateDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testWrapAsResource() throws Exception {
- securedModel.wrapAsResource(NodeFactory
- .createURI("http://example.com/rdfNode"));
+ securedModel.wrapAsResource(NodeFactory.createURI("http://example.com/rdfNode"));
}
@Test
@@ -1460,9 +1441,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -1472,9 +1452,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -1484,9 +1463,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -1496,9 +1474,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -1508,9 +1485,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
@@ -1520,9 +1496,8 @@ public class SecuredModelTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/dabc43f6/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredPropertyTest.java
----------------------------------------------------------------------
diff --git a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredPropertyTest.java b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredPropertyTest.java
index 089cd77..071e80e 100644
--- a/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredPropertyTest.java
+++ b/jena-permissions/src/test/java/org/apache/jena/permissions/model/SecuredPropertyTest.java
@@ -45,9 +45,12 @@ public class SecuredPropertyTest extends SecuredResourceTest {
@Before
public void setup() {
super.setup();
- final Property p = ResourceFactory
- .createProperty("http://example.com/testProperty");
+ final Property p = ResourceFactory.createProperty("http://example.com/testProperty");
setSecuredRDFNode(SecuredPropertyImpl.getInstance(securedModel, p), p);
+ baseModel.add(p, SecuredRDFNodeTest.p, SecuredRDFNodeTest.o);
+ baseModel.add(p, SecuredRDFNodeTest.p2, "yeehaw");
+ baseModel.add(p, SecuredRDFNodeTest.p2, "yeehaw yall", "us");
+ baseModel.add(p, SecuredRDFNodeTest.p2, "whohoo", "uk");
}
@Test
@@ -59,9 +62,8 @@ public class SecuredPropertyTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/dabc43f6/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 f4fcb75..4b775e5 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
@@ -51,23 +51,15 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
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();
+ final Iterator<RDFList> iter = new RDFListIterator((RDFList) getBaseRDFNode());
+ return WrappedIterator.create(iter).filterKeep(new RDFListSecFilter<RDFList>(getSecuredRDFList(), action))
+ .toList().size();
}
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();
+ final Iterator<RDFList> iter = new RDFListIterator((RDFList) getBaseRDFNode());
+ return WrappedIterator.create(iter).filterKeep(new RDFListSecFilter<RDFList>(getSecuredRDFList(), action))
+ .toList().size();
}
private SecuredRDFList getSecuredRDFList() {
@@ -75,24 +67,30 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
@Override
+ protected boolean hasP() {
+ return false;
+ }
+
+ @Override
+ protected boolean hasP2() {
+ return false;
+ }
+
+ @Override
@Before
public void setup() {
super.setup();
- final RDFNode[] listElements = {
- ResourceFactory.createResource("http://example.com/ListNode1"),
+ final RDFNode[] listElements = { ResourceFactory.createResource("http://example.com/ListNode1"),
ResourceFactory.createResource("http://example.com/ListNode2"),
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() {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
try {
getSecuredRDFList().add(baseModel.createResource());
if (!securityEvaluator.evaluate(perms)) {
@@ -100,9 +98,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -110,8 +107,7 @@ public class SecuredRDFListTest extends SecuredResourceTest {
@Test
public void testAppendNodeIterator() {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
try {
getSecuredRDFList().append(baseModel.listObjects());
if (!securityEvaluator.evaluate(perms)) {
@@ -119,17 +115,15 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testAppendRDFList() {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
try {
getSecuredRDFList().append(baseModel.createList());
@@ -137,16 +131,14 @@ public class SecuredRDFListTest extends SecuredResourceTest {
Assert.fail("Should have thrown UpdateDeniedException Exception");
}
if (!securityEvaluator.evaluate(Action.Create)
- && (baseList.size() > 0 && securityEvaluator
- .evaluate(Action.Read))) {
+ && (baseList.size() > 0 && securityEvaluator.evaluate(Action.Read))) {
Assert.fail("Should have thrown AddDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -169,14 +161,12 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.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 });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Read });
try {
getSecuredRDFList().apply(perms, fn);
if (!securityEvaluator.evaluate(Action.Read)) {
@@ -184,9 +174,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -200,9 +189,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
@@ -210,8 +198,7 @@ public class SecuredRDFListTest extends SecuredResourceTest {
@Test
public void testConcatenate() {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
try {
getSecuredRDFList().concatenate(baseModel.listObjects());
if (!securityEvaluator.evaluate(perms)) {
@@ -219,34 +206,29 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
try {
final List<Resource> lst = new ArrayList<Resource>();
- lst.add(ResourceFactory
- .createResource("http://example.com/dummyList"));
- getSecuredRDFList().concatenate(
- baseModel.createList(lst.iterator()));
+ lst.add(ResourceFactory.createResource("http://example.com/dummyList"));
+ getSecuredRDFList().concatenate(baseModel.createList(lst.iterator()));
if (!securityEvaluator.evaluate(perms)) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testCons() {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
try {
getSecuredRDFList().cons(SecuredRDFNodeTest.s);
if (!securityEvaluator.evaluate(perms)) {
@@ -254,9 +236,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -270,24 +251,22 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testCopy() {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Read, Action.Update, Action.Create });
+ final Set<Action> perms = SecurityEvaluator.Util
+ .asSet(new Action[] { Action.Read, Action.Update, Action.Create });
try {
getSecuredRDFList().copy();
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -301,9 +280,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} catch (final ListIndexException e) {
if (((RDFList) getBaseRDFNode()).size() < 0) {
@@ -323,9 +301,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} catch (final ListIndexException e) {
if (((RDFList) getBaseRDFNode()).size() == 0) {
@@ -345,9 +322,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} catch (final ListIndexException e) {
if (((RDFList) getBaseRDFNode()).size() == 0) {
@@ -367,9 +343,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -383,9 +358,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} catch (final ListIndexException e) {
if (((RDFList) getBaseRDFNode()).size() == 0) {
@@ -402,9 +376,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} catch (final ListIndexException e) {
if (((RDFList) getBaseRDFNode()).size() <= 0)
@@ -426,9 +399,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -442,14 +414,12 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
try {
getSecuredRDFList().iterator(perms);
@@ -458,9 +428,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -482,14 +451,12 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
try {
getSecuredRDFList().reduce(perms, fn, "Hello");
@@ -498,31 +465,27 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testRemove() {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Delete });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Delete });
try {
final int count = count(Action.Delete);
getSecuredRDFList().remove(SecuredRDFNodeTest.s);
if (!securityEvaluator.evaluate(Action.Update)
- || ((count > 0) && !securityEvaluator
- .evaluate(Action.Delete))) {
+ || ((count > 0) && !securityEvaluator.evaluate(Action.Delete))) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -531,23 +494,19 @@ public class SecuredRDFListTest extends SecuredResourceTest {
@Override
@Test
public void testRemoveAll() {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Delete });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Delete });
try {
- final int count = count(SecurityEvaluator.Util.asSet(new Action[] {
- Action.Delete, Action.Read }));
+ 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))) {
+ || ((count > 0) && !securityEvaluator.evaluate(Action.Delete))) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} catch (final EmptyListException e) {
if (count(Action.Read) == 0) {
@@ -560,8 +519,7 @@ public class SecuredRDFListTest extends SecuredResourceTest {
@Test
public void testRemoveHead() {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Delete });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Delete });
try {
getSecuredRDFList().removeHead();
@@ -570,9 +528,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} catch (final EmptyListException e) {
if (count(Action.Read) == 0) {
@@ -585,22 +542,19 @@ public class SecuredRDFListTest extends SecuredResourceTest {
@Test
public void testRemoveList() {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Delete });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Delete });
try {
final int count = count(Action.Delete);
getSecuredRDFList().removeList();
if (!securityEvaluator.evaluate(Action.Update)
- || ((count > 0) && !securityEvaluator
- .evaluate(Action.Delete))) {
+ || ((count > 0) && !securityEvaluator.evaluate(Action.Delete))) {
Assert.fail("Should have thrown AccessDeniedException Exception");
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -614,9 +568,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final UpdateDeniedException e) {
if (securityEvaluator.evaluate(Action.Update)) {
- Assert.fail(String
- .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown UpdateDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} catch (final ListIndexException e) {
if (count(Action.Read) == 0) {
@@ -636,9 +589,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -653,9 +605,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final UpdateDeniedException e) {
if (securityEvaluator.evaluate(Action.Update)) {
- Assert.fail(String
- .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown UpdateDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
} catch (final EmptyListException e) {
if (count(Action.Read) == 0) {
@@ -675,9 +626,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final UpdateDeniedException e) {
if (securityEvaluator.evaluate(Action.Update)) {
- Assert.fail(String
- .format("Should not have thrown UpdateDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown UpdateDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -691,9 +641,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -707,17 +656,15 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@Test
public void testWith() {
- final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] {
- Action.Update, Action.Create });
+ final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
try {
getSecuredRDFList().with(SecuredRDFNodeTest.s);
@@ -726,9 +673,8 @@ public class SecuredRDFListTest extends SecuredResourceTest {
}
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms)) {
- Assert.fail(String
- .format("Should not have thrown AccessDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
http://git-wip-us.apache.org/repos/asf/jena/blob/dabc43f6/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 68c889e..91e6925 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
@@ -40,14 +40,10 @@ public class SecuredRDFNodeTest {
private SecuredRDFNode securedRDFNode;
private RDFNode baseRDFNode;
- public static Resource s = ResourceFactory
- .createResource("http://example.com/graph/s");
- public static Property p = ResourceFactory
- .createProperty("http://example.com/graph/p");
- public static Property p2 = ResourceFactory
- .createProperty("http://example.com/graph/p2");
- public static Resource o = ResourceFactory
- .createResource("http://example.com/graph/o");
+ public static Resource s = ResourceFactory.createResource("http://example.com/graph/s");
+ public static Property p = ResourceFactory.createProperty("http://example.com/graph/p");
+ public static Property p2 = ResourceFactory.createProperty("http://example.com/graph/p2");
+ public static Resource o = ResourceFactory.createResource("http://example.com/graph/o");
public SecuredRDFNodeTest(final MockSecurityEvaluator securityEvaluator) {
this.securityEvaluator = securityEvaluator;
@@ -65,8 +61,7 @@ public class SecuredRDFNodeTest {
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;
}
@@ -75,15 +70,14 @@ public class SecuredRDFNodeTest {
public void setup() {
baseModel = createModel();
baseModel.removeAll();
- baseModel.add(SecuredRDFNodeTest.s, SecuredRDFNodeTest.p,
- SecuredRDFNodeTest.o);
+ baseModel.add(SecuredRDFNodeTest.s, SecuredRDFNodeTest.p, SecuredRDFNodeTest.o);
baseModel.add(SecuredRDFNodeTest.s, SecuredRDFNodeTest.p2, "yeehaw");
- securedModel = Factory.getInstance(securityEvaluator,
- "http://example.com/securedGraph", baseModel);
- securedRDFNode = SecuredRDFNodeImpl.getInstance(
- securedModel,
- baseModel.listObjectsOfProperty(SecuredRDFNodeTest.s,
- SecuredRDFNodeTest.p).next());
+ baseModel.add(SecuredRDFNodeTest.s, SecuredRDFNodeTest.p2, "yeehaw yall", "us");
+ baseModel.add(SecuredRDFNodeTest.s, SecuredRDFNodeTest.p2, "whohoo", "uk");
+
+ securedModel = Factory.getInstance(securityEvaluator, "http://example.com/securedGraph", baseModel);
+ baseRDFNode = baseModel.getResource(SecuredRDFNodeTest.o.getURI());
+ securedRDFNode = SecuredRDFNodeImpl.getInstance(securedModel, baseRDFNode);
}
@After
@@ -101,9 +95,8 @@ public class SecuredRDFNodeTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -117,9 +110,8 @@ public class SecuredRDFNodeTest {
}
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
}
@@ -127,8 +119,7 @@ public class SecuredRDFNodeTest {
@Test
public void testGetModel() {
final Model m2 = securedRDFNode.getModel();
- Assert.assertTrue("Model should have been secured",
- m2 instanceof SecuredModel);
+ Assert.assertTrue("Model should have been secured", m2 instanceof SecuredModel);
}
@Test
@@ -139,36 +130,29 @@ public class SecuredRDFNodeTest {
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);
+ Assert.assertFalse("RDFNode should not have been secured", n2 instanceof SecuredRDFNode);
+ Assert.assertEquals("Wrong securedModel returned", n2.getModel(), m2);
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}
m2.removeAll();
- final SecuredModel m3 = Factory.getInstance(securityEvaluator,
- "http://example.com/securedGraph2", m2);
+ final SecuredModel m3 = Factory.getInstance(securityEvaluator, "http://example.com/securedGraph2", m2);
try {
final RDFNode n2 = securedRDFNode.inModel(m3);
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);
+ Assert.assertTrue("RDFNode should have been secured", n2 instanceof SecuredRDFNode);
+ Assert.assertEquals("Wrong securedModel returned", n2.getModel(), m3);
} catch (final ReadDeniedException e) {
if (securityEvaluator.evaluate(Action.Read)) {
- Assert.fail(String
- .format("Should not have thrown ReadDeniedException Exception: %s - %s",
- e, e.getTriple()));
+ Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e,
+ e.getTriple()));
}
}