You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openaz.apache.org by pd...@apache.org on 2015/05/13 18:02:41 UTC
[19/56] [abbrv] [partial] incubator-openaz git commit: Merging
re-factoring with PMD work
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/cfbe399c/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionHomogeneousSimpleTest.java
----------------------------------------------------------------------
diff --cc openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionHomogeneousSimpleTest.java
index 26411d8,0000000..9cc443e
mode 100644,000000..100644
--- a/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionHomogeneousSimpleTest.java
+++ b/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionHomogeneousSimpleTest.java
@@@ -1,159 -1,0 +1,163 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/*
+ * AT&T - PROPRIETARY
+ * THIS FILE CONTAINS PROPRIETARY INFORMATION OF
+ * AT&T AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN
+ * ACCORDANCE WITH APPLICABLE AGREEMENTS.
+ *
+ * Copyright (c) 2013 AT&T Knowledge Ventures
+ * Unpublished and Not for Publication
+ * All Rights Reserved
+ */
+package org.apache.openaz.xacml.pdp.std.functions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.openaz.xacml.api.Status;
+import org.apache.openaz.xacml.api.XACML3;
+import org.apache.openaz.xacml.pdp.policy.Bag;
+import org.apache.openaz.xacml.pdp.policy.FunctionArgument;
+import org.apache.openaz.xacml.pdp.policy.FunctionArgumentAttributeValue;
+import org.apache.openaz.xacml.pdp.policy.FunctionArgumentBag;
+import org.apache.openaz.xacml.pdp.std.functions.FunctionDefinitionEquality;
+import org.apache.openaz.xacml.std.datatypes.DataTypes;
+import org.junit.Test;
+
+/**
+ * FunctionDefinitionHomogeneousSimple is an abstract class, so we have to test it by creating a sub-class.
- * The constructor is tested by default when an instance of the sub-class is created for other tests.
- *
- * Each of these functions needs to be tested for each type of function to be sure the values are correct,
- * so this is just a simple test to see that the mechanism works.
- *
- * TO RUN - use jUnit
- * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
- *
- *
++ * The constructor is tested by default when an instance of the sub-class is created for other tests. Each of
++ * these functions needs to be tested for each type of function to be sure the values are correct, so this is
++ * just a simple test to see that the mechanism works. TO RUN - use jUnit In Eclipse select this file or the
++ * enclosing directory, right-click and select Run As/JUnit Test
+ */
+public class FunctionDefinitionHomogeneousSimpleTest {
+
-
-
+ @Test
+ public void testGetDataTypeArgs() {
+
+ // test a simple instance using the Equality class
- FunctionDefinitionEquality<String> fd = new FunctionDefinitionEquality<String>(XACML3.ID_FUNCTION_STRING_EQUAL, DataTypes.DT_STRING);
++ FunctionDefinitionEquality<String> fd = new FunctionDefinitionEquality<String>(
++ XACML3.ID_FUNCTION_STRING_EQUAL,
++ DataTypes.DT_STRING);
+ assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
+ }
+
+ @Test
+ public void testGetNumArgs() {
+ // test a simple instance using the Equality class
- FunctionDefinitionEquality<String> fd = new FunctionDefinitionEquality<String>(XACML3.ID_FUNCTION_STRING_EQUAL, DataTypes.DT_STRING);
++ FunctionDefinitionEquality<String> fd = new FunctionDefinitionEquality<String>(
++ XACML3.ID_FUNCTION_STRING_EQUAL,
++ DataTypes.DT_STRING);
+ assertEquals(new Integer(2), fd.getNumArgs());
+ }
+
+ @Test
+ public void testValidateArguments() {
+ // create some arguments to use later
+ FunctionArgumentAttributeValue stringAttr1 = null;
+ FunctionArgumentAttributeValue stringAttr2 = null;
+ FunctionArgumentAttributeValue stringAttr3 = null;
+ FunctionArgumentAttributeValue intAttr = null;
+ try {
+ stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc"));
+ stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def"));
+ stringAttr3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ghi"));
+ intAttr = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
+ } catch (Exception e) {
- fail("creating attribute e="+ e);
++ fail("creating attribute e=" + e);
+ }
+
- FunctionDefinitionEquality<String> fd = new FunctionDefinitionEquality<String>(XACML3.ID_FUNCTION_STRING_EQUAL, DataTypes.DT_STRING);
++ FunctionDefinitionEquality<String> fd = new FunctionDefinitionEquality<String>(
++ XACML3.ID_FUNCTION_STRING_EQUAL,
++ DataTypes.DT_STRING);
+ List<String> convertedValues = new ArrayList<String>();
+ List<FunctionArgument> listFunctionArguments = new ArrayList<FunctionArgument>();
+
+ // test correct # of args, both of them strings
+ listFunctionArguments.add(stringAttr1);
+ listFunctionArguments.add(stringAttr2);
+ Status status = fd.validateArguments(listFunctionArguments, convertedValues);
+ assertTrue(status.isOk());
- assertEquals(convertedValues.size(),2);
++ assertEquals(convertedValues.size(), 2);
+
+ // test too few args
+ listFunctionArguments.remove(1);
+ status = fd.validateArguments(listFunctionArguments, convertedValues);
+ assertFalse(status.isOk());
+ assertEquals("Expected 2 arguments, got 1", status.getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // test too many args
+ listFunctionArguments.add(stringAttr2);
+ listFunctionArguments.add(stringAttr3);
+ status = fd.validateArguments(listFunctionArguments, convertedValues);
+ assertFalse(status.isOk());
+ assertEquals("Expected 2 arguments, got 3", status.getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // test with null arg
+ listFunctionArguments.clear();
+ listFunctionArguments.add(null);
+ listFunctionArguments.add(stringAttr1);
+ status = fd.validateArguments(listFunctionArguments, convertedValues);
+ assertFalse(status.isOk());
+ assertEquals("Got null argument at arg index 0", status.getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // test function that takes 0 args
- //TODO test with func that specifies 0 args? ASSUME for now that there are no such functions since a function needs to operate on something
- // fail("need to test function with 0 args and various inputs - see validateArguments code");
-
++ // TODO test with func that specifies 0 args? ASSUME for now that there are no such functions since a
++ // function needs to operate on something
++ // fail("need to test function with 0 args and various inputs - see validateArguments code");
+
+ // test with one is a bag
+ listFunctionArguments.clear();
+ listFunctionArguments.add(stringAttr1);
+ Bag bag = new Bag();
+ FunctionArgument bagArg = new FunctionArgumentBag(bag);
+ listFunctionArguments.add(bagArg);
+ status = fd.validateArguments(listFunctionArguments, convertedValues);
+ assertFalse(status.isOk());
+ assertEquals("Expected a simple value, saw a bag at arg index 1", status.getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // test with string and int
+ listFunctionArguments.clear();
+ listFunctionArguments.add(stringAttr1);
+ listFunctionArguments.add(intAttr);
+ status = fd.validateArguments(listFunctionArguments, convertedValues);
+ assertFalse(status.isOk());
+ assertEquals("Expected data type 'string' saw 'integer' at arg index 1", status.getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", status.getStatusCode()
++ .getStatusCodeValue().stringValue());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/cfbe399c/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionLogicalTest.java
----------------------------------------------------------------------
diff --cc openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionLogicalTest.java
index 3733fb1,0000000..c86770a
mode 100644,000000..100644
--- a/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionLogicalTest.java
+++ b/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionLogicalTest.java
@@@ -1,421 -1,0 +1,419 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.openaz.xacml.pdp.std.functions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.openaz.xacml.api.XACML3;
+import org.apache.openaz.xacml.pdp.policy.ExpressionResult;
+import org.apache.openaz.xacml.pdp.policy.FunctionArgument;
+import org.apache.openaz.xacml.pdp.policy.FunctionArgumentAttributeValue;
+import org.apache.openaz.xacml.pdp.std.StdFunctions;
+import org.apache.openaz.xacml.pdp.std.functions.FunctionDefinitionLogical;
+import org.apache.openaz.xacml.std.datatypes.DataTypes;
+import org.junit.Test;
+
+/**
- * Test of PDP Functions (See XACML core spec section A.3)
- *
- * TO RUN - use jUnit
- * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
- *
- *
++ * Test of PDP Functions (See XACML core spec section A.3) TO RUN - use jUnit In Eclipse select this file or
++ * the enclosing directory, right-click and select Run As/JUnit Test
+ */
+public class FunctionDefinitionLogicalTest {
+
+ /*
+ * variables useful in the following tests
+ */
+ List<FunctionArgument> arguments = new ArrayList<FunctionArgument>();
+
+ // use the same args for each test
+ FunctionArgumentAttributeValue attrT = null;
+ FunctionArgumentAttributeValue attrF = null;
- public FunctionDefinitionLogicalTest () {
++
++ public FunctionDefinitionLogicalTest() {
+ try {
+ attrT = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(true));
+ attrF = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(false));
+ } catch (Exception e) {
- fail("creating attribute e="+ e);
++ fail("creating attribute e=" + e);
+ }
+ }
+
-
+ @Test
+ public void testOR() {
+ FunctionArgumentAttributeValue attr5 = null;
+ try {
+ attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5));
+
+ } catch (Exception e) {
- fail("creating attribute e="+ e);
++ fail("creating attribute e=" + e);
+ }
+
- FunctionDefinitionLogical fd = (FunctionDefinitionLogical) StdFunctions.FD_OR;
++ FunctionDefinitionLogical fd = (FunctionDefinitionLogical)StdFunctions.FD_OR;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_OR, fd.getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
+
- // just to be safe... If tests take too long these can probably be eliminated
++ // just to be safe... If tests take too long these can probably be eliminated
+ assertFalse(fd.returnsBag());
+
-
+ // test normal
+ arguments.add(attrT);
+ arguments.add(attrF);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ Boolean resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(true), resValue);
+
+ arguments.clear();
+ arguments.add(attrF);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(false), resValue);
+
- // test no args
++ // test no args
+ arguments.clear();
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(false), resValue);
+
+ // first true, second error
+ arguments.clear();
+ arguments.add(attrT);
+ arguments.add(null);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(true), resValue);
+
+ // first false, second error
+ arguments.clear();
+ arguments.add(attrF);
+ arguments.add(null);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:or Got null argument", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:or Got null argument", res.getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // multiple false
+ arguments.clear();
+ arguments.add(attrF);
+ arguments.add(attrF);
+ arguments.add(attrF);
+ arguments.add(attrF);
+ arguments.add(attrF);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(false), resValue);
+
+ // non-boolean
+ arguments.clear();
+ arguments.add(attrF);
+ arguments.add(attr5);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:or Expected data type 'boolean' saw 'integer'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:or Expected data type 'boolean' saw 'integer'", res.getStatus()
++ .getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // first arg error
+ arguments.clear();
+ arguments.add(null);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:or Got null argument", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:or Got null argument", res.getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ }
+
-
+ @Test
+ public void testAND() {
+ FunctionArgumentAttributeValue attr5 = null;
+ try {
+ attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5));
+
+ } catch (Exception e) {
- fail("creating attribute e="+ e);
++ fail("creating attribute e=" + e);
+ }
+
-
- FunctionDefinitionLogical fd = (FunctionDefinitionLogical) StdFunctions.FD_AND;
++ FunctionDefinitionLogical fd = (FunctionDefinitionLogical)StdFunctions.FD_AND;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_AND, fd.getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
+
- // just to be safe... If tests take too long these can probably be eliminated
++ // just to be safe... If tests take too long these can probably be eliminated
+ assertFalse(fd.returnsBag());
+
-
+ // test normal
+ arguments.add(attrT);
+ arguments.add(attrF);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ Boolean resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(false), resValue);
+
+ arguments.clear();
+ arguments.add(attrF);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(false), resValue);
+
- // test no args
++ // test no args
+ arguments.clear();
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(true), resValue);
+
+ // first true, second error
+ arguments.clear();
+ arguments.add(attrT);
+ arguments.add(null);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:and Got null argument", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:and Got null argument", res.getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // first false, second error
+ arguments.clear();
+ arguments.add(attrF);
+ arguments.add(null);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(false), resValue);
+
+ // multiple true
+ arguments.clear();
+ arguments.add(attrT);
+ arguments.add(attrT);
+ arguments.add(attrT);
+ arguments.add(attrT);
+ arguments.add(attrT);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(true), resValue);
+
+ // non-boolean
+ arguments.clear();
+ arguments.add(attrT);
+ arguments.add(attr5);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals("function:and Expected data type 'boolean' saw 'integer'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:and Expected data type 'boolean' saw 'integer'", res.getStatus()
++ .getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // first arg error
+ arguments.clear();
+ arguments.add(null);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
+ assertEquals("function:and Got null argument", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ }
+
-
-
-
+ @Test
+ public void testN_of() {
+ FunctionArgumentAttributeValue attr0 = null;
+ FunctionArgumentAttributeValue attr2 = null;
+ try {
+ attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2));
+ } catch (Exception e) {
- fail("creating attribute e="+ e);
++ fail("creating attribute e=" + e);
+ }
+
-
- FunctionDefinitionLogical fd = (FunctionDefinitionLogical) StdFunctions.FD_N_OF;
++ FunctionDefinitionLogical fd = (FunctionDefinitionLogical)StdFunctions.FD_N_OF;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_N_OF, fd.getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
+
- // just to be safe... If tests take too long these can probably be eliminated
++ // just to be safe... If tests take too long these can probably be eliminated
+ assertFalse(fd.returnsBag());
+
-
+ // test normal
+ arguments.add(attr2);
+ arguments.add(attrT);
+ arguments.add(attrF);
+ arguments.add(attrT);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ Boolean resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(true), resValue);
+
+ // normal fail
+ arguments.clear();
+ arguments.add(attr2);
+ arguments.add(attrT);
+ arguments.add(attrF);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(false), resValue);
+
-
+ // null count
+ arguments.clear();
+ arguments.add(null);
+ arguments.add(attrT);
+ arguments.add(attrF);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(true), resValue);
+
+ // 0 count
+ arguments.clear();
+ arguments.add(attr0);
+ arguments.add(attrT);
+ arguments.add(attrF);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(true), resValue);
+
+ // bad object type for count
+ arguments.clear();
+ arguments.add(attrT);
+ arguments.add(attrT);
+ arguments.add(attrF);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:n-of For input string: \"true\"", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:n-of For input string: \"true\"", res.getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // count larger than list
+ arguments.clear();
+ arguments.add(attr2);
+ arguments.add(attrT);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:n-of Expected 2 arguments but only 1 arguments in list after the count", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:n-of Expected 2 arguments but only 1 arguments in list after the count", res
++ .getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // aborts after find ok
+ arguments.clear();
+ arguments.add(attr2);
+ arguments.add(attrT);
+ arguments.add(attrT);
+ arguments.add(null);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(true), resValue);
+
+ // error before find ok
+ arguments.clear();
+ arguments.add(attr2);
+ arguments.add(null);
+ arguments.add(attrT);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:n-of Got null argument", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
-
++ assertEquals("function:n-of Got null argument", res.getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // non-boolean in list
+ arguments.clear();
+ arguments.add(attr2);
+ arguments.add(attrT);
+ arguments.add(attr0);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:n-of Expected data type 'boolean' saw 'integer'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:n-of Expected data type 'boolean' saw 'integer'", res.getStatus()
++ .getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ }
+
-
+ @Test
+ public void testNot() {
+
- FunctionDefinitionLogical fd = (FunctionDefinitionLogical) StdFunctions.FD_NOT;
++ FunctionDefinitionLogical fd = (FunctionDefinitionLogical)StdFunctions.FD_NOT;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_NOT, fd.getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
+
- // just to be safe... If tests take too long these can probably be eliminated
++ // just to be safe... If tests take too long these can probably be eliminated
+ assertFalse(fd.returnsBag());
+
-
+ // test normal
+ arguments.clear();
+ arguments.add(attrT);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ Boolean resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(false), resValue);
+
+ arguments.clear();
+ arguments.add(attrF);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(new Boolean(true), resValue);
+
-
+ // test null/0 args
+ arguments.clear();
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:not Expected 1 argument, got 0", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:not Expected 1 argument, got 0", res.getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // test 2 args
+ arguments.clear();
+ arguments.add(attrT);
+ arguments.add(attrF);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:not Expected 1 argument, got 2", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:not Expected 1 argument, got 2", res.getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/cfbe399c/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionNumberTypeConversionTest.java
----------------------------------------------------------------------
diff --cc openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionNumberTypeConversionTest.java
index fd0176b,0000000..1582ee9
mode 100644,000000..100644
--- a/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionNumberTypeConversionTest.java
+++ b/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionNumberTypeConversionTest.java
@@@ -1,118 -1,0 +1,110 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.openaz.xacml.pdp.std.functions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.openaz.xacml.api.XACML3;
+import org.apache.openaz.xacml.pdp.policy.ExpressionResult;
+import org.apache.openaz.xacml.pdp.policy.FunctionArgument;
+import org.apache.openaz.xacml.pdp.policy.FunctionArgumentAttributeValue;
+import org.apache.openaz.xacml.pdp.std.StdFunctions;
+import org.apache.openaz.xacml.pdp.std.functions.FunctionDefinitionNumberTypeConversion;
+import org.apache.openaz.xacml.std.datatypes.DataTypes;
+import org.junit.Test;
+
+/**
- * Tests for various classes containing only one function.
- *
- * TO RUN - use jUnit
- * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
- *
- *
++ * Tests for various classes containing only one function. TO RUN - use jUnit In Eclipse select this file or
++ * the enclosing directory, right-click and select Run As/JUnit Test
+ */
+public class FunctionDefinitionNumberTypeConversionTest {
+
+ /*
+ * variables useful in the following tests
+ */
+ List<FunctionArgument> arguments = new ArrayList<FunctionArgument>();
+
+ @Test
+ public void testDouble_to_integer() {
+ FunctionArgumentAttributeValue attr1 = null;
+ try {
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(5.432));
+
+ } catch (Exception e) {
- fail("creating attribute e="+ e);
++ fail("creating attribute e=" + e);
+ }
+
- FunctionDefinitionNumberTypeConversion<?, ?> fd = (FunctionDefinitionNumberTypeConversion<?, ?>) StdFunctions.FD_DOUBLE_TO_INTEGER;
++ FunctionDefinitionNumberTypeConversion<?, ?> fd = (FunctionDefinitionNumberTypeConversion<?, ?>)StdFunctions.FD_DOUBLE_TO_INTEGER;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_DOUBLE_TO_INTEGER, fd.getId());
+ assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
+ assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId());
+
- // just to be safe... If tests take too long these can probably be eliminated
++ // just to be safe... If tests take too long these can probably be eliminated
+ assertFalse(fd.returnsBag());
+ assertEquals(new Integer(1), fd.getNumArgs());
+
-
+ // test normal add
+ arguments.add(attr1);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ BigInteger resValue = (BigInteger)res.getValue().getValue();
+ assertEquals(BigInteger.valueOf(5), resValue);
+ }
+
-
+ @Test
+ public void testInteger_to_double() {
+ FunctionArgumentAttributeValue attr1 = null;
+ try {
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5));
+
+ } catch (Exception e) {
- fail("creating attribute e="+ e);
++ fail("creating attribute e=" + e);
+ }
+
- FunctionDefinitionNumberTypeConversion<?, ?> fd = (FunctionDefinitionNumberTypeConversion<?, ?>) StdFunctions.FD_INTEGER_TO_DOUBLE;
++ FunctionDefinitionNumberTypeConversion<?, ?> fd = (FunctionDefinitionNumberTypeConversion<?, ?>)StdFunctions.FD_INTEGER_TO_DOUBLE;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_INTEGER_TO_DOUBLE, fd.getId());
+ assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
+ assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId());
+
- // just to be safe... If tests take too long these can probably be eliminated
++ // just to be safe... If tests take too long these can probably be eliminated
+ assertFalse(fd.returnsBag());
+ assertEquals(new Integer(1), fd.getNumArgs());
+
-
+ // test normal add
+ arguments.add(attr1);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ Double resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(5.0), resValue);
+ }
+
-
+}
http://git-wip-us.apache.org/repos/asf/incubator-openaz/blob/cfbe399c/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionRegexpMatchTest.java
----------------------------------------------------------------------
diff --cc openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionRegexpMatchTest.java
index 2a01685,0000000..5587ffc
mode 100644,000000..100644
--- a/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionRegexpMatchTest.java
+++ b/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionRegexpMatchTest.java
@@@ -1,510 -1,0 +1,505 @@@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.openaz.xacml.pdp.std.functions;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.security.auth.x500.X500Principal;
+
+import org.apache.openaz.xacml.api.XACML3;
+import org.apache.openaz.xacml.pdp.policy.ExpressionResult;
+import org.apache.openaz.xacml.pdp.policy.FunctionArgument;
+import org.apache.openaz.xacml.pdp.policy.FunctionArgumentAttributeValue;
+import org.apache.openaz.xacml.pdp.std.StdFunctions;
+import org.apache.openaz.xacml.pdp.std.functions.FunctionDefinitionRegexpMatch;
+import org.apache.openaz.xacml.std.datatypes.DataTypes;
+import org.apache.openaz.xacml.std.datatypes.IPAddress;
+import org.apache.openaz.xacml.std.datatypes.RFC2396DomainName;
+import org.apache.openaz.xacml.std.datatypes.RFC822Name;
+import org.junit.Test;
+
+/**
- * Test of PDP Functions (See XACML core spec section A.3)
- *
- * TO RUN - use jUnit
- * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
- *
- *
++ * Test of PDP Functions (See XACML core spec section A.3) TO RUN - use jUnit In Eclipse select this file or
++ * the enclosing directory, right-click and select Run As/JUnit Test
+ */
+public class FunctionDefinitionRegexpMatchTest {
+
-
+ /*
+ * variables useful in the following tests
+ */
+ List<FunctionArgument> arguments = new ArrayList<FunctionArgument>();
+
-
+ @Test
+ public void testString() {
+ String v1 = new String("abc");
+ String v2 = new String("def");
+
-
+ FunctionArgumentAttributeValue attrV1 = null;
+ FunctionArgumentAttributeValue attrV2 = null;
+ FunctionArgumentAttributeValue attrNull = null;
+ FunctionArgumentAttributeValue attrInteger = null;
+ try {
+ attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1));
+ attrV2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v2));
+ attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null));
+ attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>) StdFunctions.FD_STRING_REGEXP_MATCH;
++ FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>)StdFunctions.FD_STRING_REGEXP_MATCH;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_STRING_REGEXP_MATCH, fd.getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
+
- // just to be safe... If tests take too long these can probably be eliminated
++ // just to be safe... If tests take too long these can probably be eliminated
+ assertFalse(fd.returnsBag());
+
-
+ // match
+ arguments.clear();
+ arguments.add(attrV1);
+ arguments.add(attrV1);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ Boolean resValue = (Boolean)res.getValue().getValue();
+ assertEquals(true, resValue);
+
+ // no match
+ arguments.clear();
+ arguments.add(attrV1);
+ arguments.add(attrV2);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(false, resValue);
+
+ // null regex
+ arguments.clear();
+ arguments.add(null);
+ arguments.add(attrV2);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
+ assertEquals("function:string-regexp-match Got null argument", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
-
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ arguments.clear();
+ arguments.add(attrNull);
+ arguments.add(attrV2);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
+ assertEquals("function:string-regexp-match Got null attribute", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // null object to match
+ arguments.clear();
+ arguments.add(attrV1);
+ arguments.add(null);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
+ assertEquals("function:string-regexp-match Got null argument", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ arguments.clear();
+ arguments.add(attrV1);
+ arguments.add(attrNull);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
+ assertEquals("function:string-regexp-match Got null attribute", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
-
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // regex not string
+ arguments.clear();
+ arguments.add(attrInteger);
+ arguments.add(attrV2);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
- assertEquals("function:string-regexp-match Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:string-regexp-match Expected data type 'string' saw 'integer'", res
++ .getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // object to match not correct type
+ arguments.clear();
+ arguments.add(attrV1);
+ arguments.add(attrInteger);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
- assertEquals("function:string-regexp-match Expected data type 'string' saw 'integer'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:string-regexp-match Expected data type 'string' saw 'integer'", res
++ .getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ }
+
+ @Test
+ public void testAnyURI() {
+ String regexp = new String("abc");
+ URI uri1 = null;
+ URI uri2 = null;
+ try {
+ uri1 = new URI("abc");
+ uri2 = new URI("def");
+ } catch (Exception e) {
- fail("Unable to create URIs, e="+e);
++ fail("Unable to create URIs, e=" + e);
+ }
+
-
+ FunctionArgumentAttributeValue attrRegexp = null;
+ FunctionArgumentAttributeValue attrUri1 = null;
+ FunctionArgumentAttributeValue attrUri2 = null;
+ FunctionArgumentAttributeValue attrInteger = null;
+ try {
+ attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp));
+ attrUri1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri1));
+ attrUri2 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri2));
+ attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>) StdFunctions.FD_ANYURI_REGEXP_MATCH;
++ FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>)StdFunctions.FD_ANYURI_REGEXP_MATCH;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_ANYURI_REGEXP_MATCH, fd.getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
+
- // just to be safe... If tests take too long these can probably be eliminated
++ // just to be safe... If tests take too long these can probably be eliminated
+ assertFalse(fd.returnsBag());
+
-
+ // match
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrUri1);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ Boolean resValue = (Boolean)res.getValue().getValue();
+ assertEquals(true, resValue);
+
+ // no match
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrUri2);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(false, resValue);
+
+ // object to match not correct type
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrInteger);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
- assertEquals("function:anyURI-regexp-match Expected data type 'anyURI' saw 'integer'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:anyURI-regexp-match Expected data type 'anyURI' saw 'integer'", res
++ .getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ }
+
-
+ @Test
+ public void testIpAddress() {
+ String regexp = new String(".*123.*");
+ IPAddress addr1 = null;
+ IPAddress addr2 = null;
+ try {
+ addr1 = IPAddress.newInstance("199.123.45.67");
+ addr2 = IPAddress.newInstance("12.34.67.87");
+ } catch (Exception e) {
- fail("Unable to create IPAddresses, e="+e);
++ fail("Unable to create IPAddresses, e=" + e);
+ }
+
-
+ FunctionArgumentAttributeValue attrRegexp = null;
+ FunctionArgumentAttributeValue attrAddr1 = null;
+ FunctionArgumentAttributeValue attrAddr2 = null;
+ FunctionArgumentAttributeValue attrInteger = null;
+ try {
+ attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp));
+ attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_IPADDRESS.createAttributeValue(addr1));
+ attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_IPADDRESS.createAttributeValue(addr2));
+ attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>) StdFunctions.FD_IPADDRESS_REGEXP_MATCH;
++ FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>)StdFunctions.FD_IPADDRESS_REGEXP_MATCH;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_IPADDRESS_REGEXP_MATCH, fd.getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
+
- // just to be safe... If tests take too long these can probably be eliminated
++ // just to be safe... If tests take too long these can probably be eliminated
+ assertFalse(fd.returnsBag());
+
-
+ // match
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrAddr1);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ Boolean resValue = (Boolean)res.getValue().getValue();
+ assertEquals(true, resValue);
+
+ // no match
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrAddr2);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(false, resValue);
+
+ // object to match not correct type
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrInteger);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
- assertEquals("function:ipAddress-regexp-match Expected data type 'ipAddress' saw 'integer'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:ipAddress-regexp-match Expected data type 'ipAddress' saw 'integer'", res
++ .getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ }
+
-
+ @Test
+ public void testDnsName() {
+ String regexp = new String("abc");
+ RFC2396DomainName addr1 = null;
+ RFC2396DomainName addr2 = null;
+ try {
+ addr1 = RFC2396DomainName.newInstance("abc");
+ addr2 = RFC2396DomainName.newInstance("def");
+ } catch (Exception e) {
- fail("Unable to create DNSNames, e="+e);
++ fail("Unable to create DNSNames, e=" + e);
+ }
+
-
+ FunctionArgumentAttributeValue attrRegexp = null;
+ FunctionArgumentAttributeValue attrAddr1 = null;
+ FunctionArgumentAttributeValue attrAddr2 = null;
+ FunctionArgumentAttributeValue attrInteger = null;
+ try {
+ attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp));
+ attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DNSNAME.createAttributeValue(addr1));
+ attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DNSNAME.createAttributeValue(addr2));
+ attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>) StdFunctions.FD_DNSNAME_REGEXP_MATCH;
++ FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>)StdFunctions.FD_DNSNAME_REGEXP_MATCH;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_DNSNAME_REGEXP_MATCH, fd.getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
+
- // just to be safe... If tests take too long these can probably be eliminated
++ // just to be safe... If tests take too long these can probably be eliminated
+ assertFalse(fd.returnsBag());
+
-
+ // match
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrAddr1);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ Boolean resValue = (Boolean)res.getValue().getValue();
+ assertEquals(true, resValue);
+
+ // no match
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrAddr2);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(false, resValue);
+
+ // object to match not correct type
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrInteger);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
- assertEquals("function:dnsName-regexp-match Expected data type 'dnsName' saw 'integer'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:dnsName-regexp-match Expected data type 'dnsName' saw 'integer'", res
++ .getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ }
+
-
+ @Test
+ public void testRfc822Name() {
+ String regexp = new String(".*abc.*");
+ RFC822Name addr1 = null;
+ RFC822Name addr2 = null;
+ try {
+ addr1 = RFC822Name.newInstance("abc@somewhere");
+ addr2 = RFC822Name.newInstance("def@somewhere");
+ } catch (Exception e) {
- fail("Unable to create RFC822Names, e="+e);
++ fail("Unable to create RFC822Names, e=" + e);
+ }
+
-
+ FunctionArgumentAttributeValue attrRegexp = null;
+ FunctionArgumentAttributeValue attrAddr1 = null;
+ FunctionArgumentAttributeValue attrAddr2 = null;
+ FunctionArgumentAttributeValue attrInteger = null;
+ try {
+ attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp));
- attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(addr1));
- attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(addr2));
++ attrAddr1 = new FunctionArgumentAttributeValue(
++ DataTypes.DT_RFC822NAME
++ .createAttributeValue(addr1));
++ attrAddr2 = new FunctionArgumentAttributeValue(
++ DataTypes.DT_RFC822NAME
++ .createAttributeValue(addr2));
+ attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>) StdFunctions.FD_RFC822NAME_REGEXP_MATCH;
++ FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>)StdFunctions.FD_RFC822NAME_REGEXP_MATCH;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_RFC822NAME_REGEXP_MATCH, fd.getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
+
- // just to be safe... If tests take too long these can probably be eliminated
++ // just to be safe... If tests take too long these can probably be eliminated
+ assertFalse(fd.returnsBag());
+
-
+ // match
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrAddr1);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ Boolean resValue = (Boolean)res.getValue().getValue();
+ assertEquals(true, resValue);
+
+ // no match
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrAddr2);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(false, resValue);
+
+ // object to match not correct type
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrInteger);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
- assertEquals("function:rfc822Name-regexp-match Expected data type 'rfc822Name' saw 'integer'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:rfc822Name-regexp-match Expected data type 'rfc822Name' saw 'integer'", res
++ .getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ }
+
-
+ @Test
+ public void testX500Name() {
+ String regexp = new String(".*Duke.*");
+ X500Principal addr1 = null;
+ X500Principal addr2 = null;
+ try {
+ addr1 = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US");
+ addr2 = new X500Principal("CN=Policy Engine, OU=Research, O=ATT, C=US");
+ } catch (Exception e) {
- fail("Unable to create X500Name, e="+e);
++ fail("Unable to create X500Name, e=" + e);
+ }
+
-
+ FunctionArgumentAttributeValue attrRegexp = null;
+ FunctionArgumentAttributeValue attrAddr1 = null;
+ FunctionArgumentAttributeValue attrAddr2 = null;
+ FunctionArgumentAttributeValue attrInteger = null;
+ try {
+ attrRegexp = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(regexp));
+ attrAddr1 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(addr1));
+ attrAddr2 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(addr2));
+ attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>) StdFunctions.FD_X500NAME_REGEXP_MATCH;
++ FunctionDefinitionRegexpMatch<?> fd = (FunctionDefinitionRegexpMatch<?>)StdFunctions.FD_X500NAME_REGEXP_MATCH;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_X500NAME_REGEXP_MATCH, fd.getId());
+ assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
+
- // just to be safe... If tests take too long these can probably be eliminated
++ // just to be safe... If tests take too long these can probably be eliminated
+ assertFalse(fd.returnsBag());
+
-
+ // match
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrAddr1);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ Boolean resValue = (Boolean)res.getValue().getValue();
+ assertEquals(true, resValue);
+
+ // no match
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrAddr2);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(false, resValue);
+
+ // object to match not correct type
+ arguments.clear();
+ arguments.add(attrRegexp);
+ arguments.add(attrInteger);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
- assertEquals("function:x500Name-regexp-match Expected data type 'x500Name' saw 'integer'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:x500Name-regexp-match Expected data type 'x500Name' saw 'integer'", res
++ .getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ }
+
-
-
-
+}