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:47 UTC
[25/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/FunctionDefinitionAccessPermittedTest.java
----------------------------------------------------------------------
diff --cc openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionAccessPermittedTest.java
index 3ce4db7,0000000..42d1f18
mode 100644,000000..100644
--- a/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionAccessPermittedTest.java
+++ b/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionAccessPermittedTest.java
@@@ -1,522 -1,0 +1,498 @@@
+/*
+ * 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 org.apache.openaz.xacml.api.Request;
+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.StdEvaluationContext;
+import org.apache.openaz.xacml.pdp.std.StdFunctions;
+import org.apache.openaz.xacml.pdp.std.functions.FunctionDefinitionAccessPermitted;
+import org.apache.openaz.xacml.std.StdMutableRequest;
+import org.apache.openaz.xacml.std.datatypes.DataTypes;
+import org.apache.openaz.xacml.std.dom.DOMRequest;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import javax.xml.namespace.NamespaceContext;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+/**
- * 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
- *
- * NOT IMPLEMENTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- * This function is not yet implemented so these tests intentionally fail.
- *
- *
++ * 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 NOT
++ * IMPLEMENTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! This
++ * function is not yet implemented so these tests intentionally fail.
+ */
+public class FunctionDefinitionAccessPermittedTest {
+
+ //
+ // Strings for the Request contents
+ //
+
+ String reqStrMainStart = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
- + "<Request xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
- + " http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\""
- + " ReturnPolicyIdList=\"false\""
- + " CombinedDecision=\"false\""
- + " xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\""
- + " xmlns:md=\"http://www.medico.com/schemas/record\""
- + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
- + " <Attributes Category=\"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\">"
- + " <Attribute IncludeInResult=\"false\" AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject:subject-id\">"
- + " <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Julius Hibbert</AttributeValue>"
- + " </Attribute>"
- + " <Attribute IncludeInResult=\"false\" AttributeId=\"urn:oasis:names:tc:xacml:2.0:conformance-test:test-attr\">"
- + " <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\"> This is IT! </AttributeValue>"
- + " </Attribute>"
- + " <Attribute IncludeInResult=\"false\" AttributeId=\"urn:oasis:names:tc:xacml:2.0:conformance-test:test-attr\">"
- + " <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\"> This is IT! </AttributeValue>"
- + " </Attribute>"
- + "</Attributes>";
-
- String reqStrResourceStart = "<Attributes Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\">";
-
- String reqStrMdRecordSimpson =
- "<md:record>" +
- "<md:hospital_info>" +
- "<md:name>ABC Hospital</md:name>" +
- "<md:department>Surgery</md:department>" +
- "</md:hospital_info>" +
- "<md:patient_info>" +
- "<md:name>Bart Simpson</md:name>" +
- "<md:age>60</md:age>" +
- "<md:sex>male</md:sex>" +
- "<md:health_insurance>123456</md:health_insurance>" +
- "</md:patient_info>" +
- "<md:diagnosis_info>" +
- "<md:diagnosis>" +
- "<md:item type=\"primary\">Gastric Cancer</md:item>" +
- "<md:item type=\"secondary\">Hyper tension</md:item>" +
- "</md:diagnosis>" +
- "<md:pathological_diagnosis>" +
- "<md:diagnosis>" +
- "<md:item type=\"primary\">Well differentiated adeno carcinoma</md:item>" +
- "</md:diagnosis>" +
- "<md:date>2000-10-05</md:date>" +
- "<md:malignancy type=\"yes\"/>" +
- "</md:pathological_diagnosis>" +
- "</md:diagnosis_info>" +
- " </md:record>";
++ + "<Request xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
++ + " http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\""
++ + " ReturnPolicyIdList=\"false\""
++ + " CombinedDecision=\"false\""
++ + " xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\""
++ + " xmlns:md=\"http://www.medico.com/schemas/record\""
++ + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
++ + " <Attributes Category=\"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\">"
++ + " <Attribute IncludeInResult=\"false\" AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject:subject-id\">"
++ + " <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Julius Hibbert</AttributeValue>"
++ + " </Attribute>"
++ + " <Attribute IncludeInResult=\"false\" AttributeId=\"urn:oasis:names:tc:xacml:2.0:conformance-test:test-attr\">"
++ + " <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\"> This is IT! </AttributeValue>"
++ + " </Attribute>"
++ + " <Attribute IncludeInResult=\"false\" AttributeId=\"urn:oasis:names:tc:xacml:2.0:conformance-test:test-attr\">"
++ + " <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\"> This is IT! </AttributeValue>"
++ + " </Attribute>" + "</Attributes>";
++
++ String reqStrResourceStart = "<Attributes Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\">";
++
++ String reqStrMdRecordSimpson = "<md:record>"
++ + "<md:hospital_info>"
++ + "<md:name>ABC Hospital</md:name>"
++ + "<md:department>Surgery</md:department>"
++ + "</md:hospital_info>"
++ + "<md:patient_info>"
++ + "<md:name>Bart Simpson</md:name>"
++ + "<md:age>60</md:age>"
++ + "<md:sex>male</md:sex>"
++ + "<md:health_insurance>123456</md:health_insurance>"
++ + "</md:patient_info>"
++ + "<md:diagnosis_info>"
++ + "<md:diagnosis>"
++ + "<md:item type=\"primary\">Gastric Cancer</md:item>"
++ + "<md:item type=\"secondary\">Hyper tension</md:item>"
++ + "</md:diagnosis>"
++ + "<md:pathological_diagnosis>"
++ + "<md:diagnosis>"
++ + "<md:item type=\"primary\">Well differentiated adeno carcinoma</md:item>"
++ + "</md:diagnosis>" + "<md:date>2000-10-05</md:date>"
++ + "<md:malignancy type=\"yes\"/>" + "</md:pathological_diagnosis>"
++ + "</md:diagnosis_info>" + " </md:record>";
+ String reqStrContentMdRecordSimpson = "<Content>" + reqStrMdRecordSimpson + "</Content>";
- String reqStrMalformedContent =
- " <Content>" +
- "<md:record>" +
- "<md:hospital_info>" +
- "<md:name>ABC Hospital</md:name>" +
- "<md:malignancy type=\"yes\"/>" +
- "</Content>";
- String reqStrMdRecordSpringer =
- "<md:record>" +
- "<md:hospital_info>" +
- "<md:name>XYZ Hospital</md:name>" +
- "<md:department>Surgery</md:department>" +
- "</md:hospital_info>" +
- "<md:patient_info>" +
- "<md:name>Jerry Springer</md:name>" +
- "<md:age>65</md:age>" +
- "<md:sex>male</md:sex>" +
- "<md:health_insurance>765432</md:health_insurance>" +
- "</md:patient_info>" +
- "<md:diagnosis_info>" +
- "<md:diagnosis>" +
- "<md:item type=\"primary\">Hyatal Hernia</md:item>" +
- "<md:item type=\"secondary\">Diabetes</md:item>" +
- "<md:item type=\"tertiary\">Neuronal Collapse</md:item>" +
- "</md:diagnosis>" +
- "<md:pathological_diagnosis>" +
- "<md:diagnosis>" +
- "<md:item type=\"primary\">We have no idea</md:item>" +
- "</md:diagnosis>" +
- "<md:date>2012-07-22</md:date>" +
- "<md:malignancy type=\"no\"/>" +
- "</md:pathological_diagnosis>" +
- "</md:diagnosis_info>" +
- " </md:record>";
- String reqStrContentMdRecordSpringer =
- "<Content>" + reqStrMdRecordSpringer + "</Content>";
++ String reqStrMalformedContent = " <Content>" + "<md:record>" + "<md:hospital_info>"
++ + "<md:name>ABC Hospital</md:name>" + "<md:malignancy type=\"yes\"/>"
++ + "</Content>";
++ String reqStrMdRecordSpringer = "<md:record>" + "<md:hospital_info>" + "<md:name>XYZ Hospital</md:name>"
++ + "<md:department>Surgery</md:department>" + "</md:hospital_info>"
++ + "<md:patient_info>" + "<md:name>Jerry Springer</md:name>"
++ + "<md:age>65</md:age>" + "<md:sex>male</md:sex>"
++ + "<md:health_insurance>765432</md:health_insurance>"
++ + "</md:patient_info>" + "<md:diagnosis_info>" + "<md:diagnosis>"
++ + "<md:item type=\"primary\">Hyatal Hernia</md:item>"
++ + "<md:item type=\"secondary\">Diabetes</md:item>"
++ + "<md:item type=\"tertiary\">Neuronal Collapse</md:item>"
++ + "</md:diagnosis>" + "<md:pathological_diagnosis>" + "<md:diagnosis>"
++ + "<md:item type=\"primary\">We have no idea</md:item>"
++ + "</md:diagnosis>" + "<md:date>2012-07-22</md:date>"
++ + "<md:malignancy type=\"no\"/>" + "</md:pathological_diagnosis>"
++ + "</md:diagnosis_info>" + " </md:record>";
++ String reqStrContentMdRecordSpringer = "<Content>" + reqStrMdRecordSpringer + "</Content>";
+
+ String reqStrResourceEnd = " <Attribute IncludeInResult=\"false\" AttributeId=\"urn:oasis:names:tc:xacml:1.0:resource:resource-id\">"
- + " <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#anyURI\">http://medico.com/record/patient/BartSimpson</AttributeValue>"
- + " </Attribute>"
- + "</Attributes> ";
- String reqStrActionStart = "<Attributes Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:action\">";
++ + " <AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#anyURI\">http://medico.com/record/patient/BartSimpson</AttributeValue>"
++ + " </Attribute>" + "</Attributes> ";
++ String reqStrActionStart = "<Attributes Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:action\">";
+
+ String reqStrActionEnd = "<Attribute IncludeInResult=\"false\" AttributeId=\"urn:oasis:names:tc:xacml:1.0:action:action-id\">"
- + "<AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">read</AttributeValue>"
- + "</Attribute>"
- + "</Attributes> ";
++ + "<AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">read</AttributeValue>"
++ + "</Attribute>" + "</Attributes> ";
+ String reqStrEnvironmentStartEnd = " <Attributes Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\" />";
+ String reqStrMainEnd = " </Request>";
+
-
+ // combined strings for convenience
+ String reqStrMainResourceStart = reqStrMainStart + reqStrResourceStart;
- String reqStrResourceAllEnd = reqStrResourceEnd + reqStrActionStart + reqStrActionEnd + reqStrEnvironmentStartEnd + reqStrMainEnd;
-
++ String reqStrResourceAllEnd = reqStrResourceEnd + reqStrActionStart + reqStrActionEnd
++ + reqStrEnvironmentStartEnd + reqStrMainEnd;
+
+ /*
+ * variables useful in the following tests
+ */
+ List<FunctionArgument> arguments = new ArrayList<FunctionArgument>();
+
-
-
+ // Name Spaces used in the XML as part of these examples - needed for compiling XPaths
+ NamespaceContext nameSpaceContext = new NamespaceContext() {
+ @Override
+ public Iterator<?> getPrefixes(String arg0) {
+ return null;
+ }
+
+ @Override
+ public String getPrefix(String arg0) {
+ return null;
+ }
+
+ @Override
+ public String getNamespaceURI(String arg0) {
- if("md".equals(arg0)) {
++ if ("md".equals(arg0)) {
+ return "http://www.medico.com/schemas/record";
+ } else if ("xacml-context".equals(arg0)) {
+ return "urn:oasis:names:tc:xacml:3.0:context:schema:os";
+ } else if ("xsi".equals(arg0)) {
+ return "http://www.w3.org/2001/XMLSchema-instance";
+ }
+ return null;
+ }
+ };
+
-
-
+ //
+ // URIs for attribute categroies
+ //
+
+ FunctionArgumentAttributeValue attrUriNull = null;
+ FunctionArgumentAttributeValue attrUriEmpty = null;
+ FunctionArgumentAttributeValue attrUriResources = null;
+ FunctionArgumentAttributeValue attrUriAction = null;
+ FunctionArgumentAttributeValue attrUriNotInRequest = null;
+ FunctionArgumentAttributeValue attrUriNotCategory = null;
+
-
-
+ //
+ // XML Contents
+ //
+
+ FunctionArgumentAttributeValue attrXnull = null;
+ FunctionArgumentAttributeValue attrXEmpty = null;
+ FunctionArgumentAttributeValue attrXSimpson = null;
+ FunctionArgumentAttributeValue attrXSpringer = null;
+ FunctionArgumentAttributeValue attrXContentSimpson = null;
+ FunctionArgumentAttributeValue attrXContentSpringer = null;
+ FunctionArgumentAttributeValue attrXBadXML = null;
+
-
-
-
-
-
+ //
+ // REQUEST objects available for use in tests
+ //
+ Request requestEmpty = new StdMutableRequest();
+ Request requestMdRecord = null;
+ Request requestDoubleResources = null;
+ Request requestDoubleContent = null;
+ Request requestResourceActionContent = null;
+ Request requestContentInAction = null;
+
-
-
-
+ /**
+ * Set up all variables in one place because it is complicated (lots of steps needed for each attribute)
+ */
+ public FunctionDefinitionAccessPermittedTest() {
+ try {
+
-
+ // create Function Attributes for URIs
+ attrUriNull = null;
+ attrUriEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(""));
- attrUriResources = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("urn:oasis:names:tc:xacml:3.0:attribute-category:resource"));
- attrUriAction = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("urn:oasis:names:tc:xacml:3.0:attribute-category:action"));
- attrUriNotInRequest = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("NoSuchURI"));
- attrUriNotCategory = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("urn:oasis:names:tc:xacml:1.0:resource:resource-id"));
++ attrUriResources = new FunctionArgumentAttributeValue(
++ DataTypes.DT_ANYURI
++ .createAttributeValue("urn:oasis:names:tc:xacml:3.0:attribute-category:resource"));
++ attrUriAction = new FunctionArgumentAttributeValue(
++ DataTypes.DT_ANYURI
++ .createAttributeValue("urn:oasis:names:tc:xacml:3.0:attribute-category:action"));
++ attrUriNotInRequest = new FunctionArgumentAttributeValue(
++ DataTypes.DT_ANYURI
++ .createAttributeValue("NoSuchURI"));
++ attrUriNotCategory = new FunctionArgumentAttributeValue(
++ DataTypes.DT_ANYURI
++ .createAttributeValue("urn:oasis:names:tc:xacml:1.0:resource:resource-id"));
+
+ // create Function Attributes for XML Strings
+ attrXnull = new FunctionArgumentAttributeValue(null);
+ attrXEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(""));
- attrXSimpson = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrMdRecordSimpson));
- attrXSpringer = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrMdRecordSpringer));
- attrXContentSimpson = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrContentMdRecordSimpson));
- attrXContentSpringer = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrContentMdRecordSpringer));
- attrXBadXML = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(reqStrMalformedContent));
-
-
++ attrXSimpson = new FunctionArgumentAttributeValue(
++ DataTypes.DT_STRING
++ .createAttributeValue(reqStrMdRecordSimpson));
++ attrXSpringer = new FunctionArgumentAttributeValue(
++ DataTypes.DT_STRING
++ .createAttributeValue(reqStrMdRecordSpringer));
++ attrXContentSimpson = new FunctionArgumentAttributeValue(
++ DataTypes.DT_STRING
++ .createAttributeValue(reqStrContentMdRecordSimpson));
++ attrXContentSpringer = new FunctionArgumentAttributeValue(
++ DataTypes.DT_STRING
++ .createAttributeValue(reqStrContentMdRecordSpringer));
++ attrXBadXML = new FunctionArgumentAttributeValue(
++ DataTypes.DT_STRING
++ .createAttributeValue(reqStrMalformedContent));
+
+ // Request objects
- // to create a Request object the easiest way is to put the xml into a file and use the DOMRequest to load it.
++ // to create a Request object the easiest way is to put the xml into a file and use the DOMRequest
++ // to load it.
+
+ // single Content in the Resources section (normal valid request)
+ String reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrResourceAllEnd;
+ File tFile = File.createTempFile("functionJunit", "request");
+ BufferedWriter bw = new BufferedWriter(new FileWriter(tFile));
+ bw.append(reqString);
+ bw.flush();
+ bw.close();
+ requestMdRecord = DOMRequest.load(tFile);
+ tFile.delete();
+
+ // Resources included twice
- reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrResourceEnd + reqStrResourceStart + reqStrContentMdRecordSimpson +reqStrResourceAllEnd;
++ reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrResourceEnd
++ + reqStrResourceStart + reqStrContentMdRecordSimpson + reqStrResourceAllEnd;
+ tFile = File.createTempFile("functionJunit", "request");
+ bw = new BufferedWriter(new FileWriter(tFile));
+ bw.append(reqString);
+ bw.flush();
+ bw.close();
+ requestDoubleResources = DOMRequest.load(tFile);
+ tFile.delete();
+
+ // Content included twice - error
- reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrContentMdRecordSimpson +reqStrResourceAllEnd;
++ reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrContentMdRecordSimpson
++ + reqStrResourceAllEnd;
+ tFile = File.createTempFile("functionJunit", "request");
+ bw = new BufferedWriter(new FileWriter(tFile));
+ bw.append(reqString);
+ bw.flush();
+ bw.close();
+ try {
+ requestDoubleContent = DOMRequest.load(tFile);
+ tFile.delete();
+ } catch (org.apache.openaz.xacml.std.dom.DOMStructureException e) {
+ // this is what it should do, so just continue
+ } catch (Exception e) {
- fail("Unexpected exception for bad XML, e="+e);
++ fail("Unexpected exception for bad XML, e=" + e);
+ }
+
+ // content included in both Resource and Action - ok
- reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrResourceEnd + reqStrActionStart + reqStrContentMdRecordSimpson + reqStrActionEnd + reqStrMainEnd;
++ reqString = reqStrMainResourceStart + reqStrContentMdRecordSimpson + reqStrResourceEnd
++ + reqStrActionStart + reqStrContentMdRecordSimpson + reqStrActionEnd + reqStrMainEnd;
+ tFile = File.createTempFile("functionJunit", "request");
+ bw = new BufferedWriter(new FileWriter(tFile));
+ bw.append(reqString);
+ bw.flush();
+ bw.close();
+ requestResourceActionContent = DOMRequest.load(tFile);
+ tFile.delete();
+
+ // Content included only in Action - missing content produces non-error result according to spec
- reqString = reqStrMainResourceStart + reqStrResourceEnd + reqStrActionStart + reqStrContentMdRecordSimpson + reqStrActionEnd + reqStrMainEnd;
++ reqString = reqStrMainResourceStart + reqStrResourceEnd + reqStrActionStart
++ + reqStrContentMdRecordSimpson + reqStrActionEnd + reqStrMainEnd;
+ tFile = File.createTempFile("functionJunit", "request");
+ bw = new BufferedWriter(new FileWriter(tFile));
+ bw.append(reqString);
+ bw.flush();
+ bw.close();
+ requestContentInAction = DOMRequest.load(tFile);
+ tFile.delete();
+
-
-
+ // Test that Bad XML is caught
+ @SuppressWarnings("unused")
+ Request requestContentMisplaced = null;
+ @SuppressWarnings("unused")
+ Request requestMalformedContent = null;
+
-
+ // Bad XML - Content not under a Category
- reqString = reqStrMainStart + reqStrContentMdRecordSimpson + reqStrResourceStart + reqStrResourceEnd + reqStrActionStart + reqStrActionEnd + reqStrMainEnd;
++ reqString = reqStrMainStart + reqStrContentMdRecordSimpson + reqStrResourceStart
++ + reqStrResourceEnd + reqStrActionStart + reqStrActionEnd + reqStrMainEnd;
+ tFile = File.createTempFile("functionJunit", "request");
+ bw = new BufferedWriter(new FileWriter(tFile));
+ bw.append(reqString);
+ bw.flush();
+ bw.close();
+ try {
+ requestContentMisplaced = DOMRequest.load(tFile);
+ tFile.delete();
+ } catch (org.apache.openaz.xacml.std.dom.DOMStructureException e) {
+ // this is what it should do, so just continue
+ } catch (Exception e) {
- fail("Unexpected exception for bad XML, e="+e);
++ fail("Unexpected exception for bad XML, e=" + e);
+ }
+
+ // Bad XML - Content is not valid XML
+ reqString = reqStrMainResourceStart + reqStrMalformedContent + reqStrResourceAllEnd;
+ tFile = File.createTempFile("functionJunit", "request");
+ bw = new BufferedWriter(new FileWriter(tFile));
+ bw.append(reqString);
+ bw.flush();
+ bw.close();
+ try {
+ requestMalformedContent = DOMRequest.load(tFile);
+ tFile.delete();
+ } catch (org.apache.openaz.xacml.std.dom.DOMStructureException e) {
+ // this is what it should do, so just continue
+ } catch (Exception e) {
- fail("Unexpected exception for bad XML, e="+e);
++ fail("Unexpected exception for bad XML, e=" + e);
+ }
+
+ } catch (Exception e) {
- fail("Constructor initializing variables, e="+ e + " cause="+e.getCause());
++ fail("Constructor initializing variables, e=" + e + " cause=" + e.getCause());
+ }
+
+ }
+
-
-
-
-
-
-
+ @Ignore
+ @Test
+ public void testAccess_permitted() {
+
+ ExpressionResult res = null;
+ Boolean resValue = null;
+
- FunctionDefinitionAccessPermitted fd = (FunctionDefinitionAccessPermitted) StdFunctions.FD_ACCESS_PERMITTED;
++ FunctionDefinitionAccessPermitted fd = (FunctionDefinitionAccessPermitted)StdFunctions.FD_ACCESS_PERMITTED;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_ACCESS_PERMITTED, 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());
+
-
-
+ // successful invoke returns true
+ arguments.clear();
+ arguments.add(attrUriResources);
+ arguments.add(attrXEmpty);
+ res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertTrue(resValue);
+
-
-
+ // successful invoke returns false
+
-
+ // URI not in Request (ok - evaluate anyway)
+
+ // test for infinite loop
+
+ // second arg ok both with and without <Content> tag
+ arguments.clear();
+ arguments.add(attrUriResources);
+ arguments.add(attrXContentSpringer);
+ res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertTrue(resValue);
+
+ arguments.clear();
+ arguments.add(attrUriResources);
+ arguments.add(attrXSpringer);
+ res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments);
+ assertTrue(res.isOk());
+ resValue = (Boolean)res.getValue().getValue();
+ assertTrue(resValue);
+
+ // second arg not valid XML
+ arguments.clear();
+ arguments.add(attrUriResources);
+ arguments.add(attrXBadXML);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:access-permitted Parsing of XML string failed. Cause='The element type \"md:hospital_info\" must be terminated by the matching end-tag \"</md:hospital_info>\".'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:access-permitted Parsing of XML string failed. Cause='The element type \"md:hospital_info\" must be terminated by the matching end-tag \"</md:hospital_info>\".'",
++ res.getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // null Evaluation Context
+ arguments.clear();
+ arguments.add(attrUriNotCategory);
+ arguments.add(attrXContentSimpson);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:access-permitted First argument must be a urn for an attribute-category, not 'urn:oasis:names:tc:xacml:1.0:resource:resource-id", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:access-permitted First argument must be a urn for an attribute-category, not 'urn:oasis:names:tc:xacml:1.0:resource:resource-id",
++ res.getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // null Request
+ arguments.clear();
+ arguments.add(attrUriAction);
+ arguments.add(attrXContentSimpson);
+ res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:access-permitted Got null Request in EvaluationContext", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
-
++ assertEquals("function:access-permitted Got null Request in EvaluationContext", res.getStatus()
++ .getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // first arg not uri
+ arguments.clear();
+ arguments.add(attrUriNotCategory);
+ arguments.add(attrXContentSimpson);
+ res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:access-permitted First argument must be a urn for an attribute-category, not 'urn:oasis:names:tc:xacml:1.0:resource:resource-id", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:access-permitted First argument must be a urn for an attribute-category, not 'urn:oasis:names:tc:xacml:1.0:resource:resource-id",
++ res.getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // first arg not attribute-category urn
+ arguments.clear();
+ arguments.add(attrXContentSimpson);
+ arguments.add(attrXContentSimpson);
+ res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:access-permitted Expected data type 'anyURI' saw 'string'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:access-permitted Expected data type 'anyURI' saw 'string'", res.getStatus()
++ .getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // second arg not string
+ arguments.clear();
+ arguments.add(attrUriAction);
+ arguments.add(attrUriAction);
+ res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:access-permitted Expected data type 'string' saw 'anyURI'", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
-
++ assertEquals("function:access-permitted Expected data type 'string' saw 'anyURI'", res.getStatus()
++ .getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // too few args
+ arguments.clear();
+ res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:access-permitted Expected 2 arguments, got 0", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:access-permitted Expected 2 arguments, got 0", res.getStatus()
++ .getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ arguments.clear();
+ arguments.add(attrXContentSimpson);
+ res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:access-permitted Expected 2 arguments, got 1", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
-
++ assertEquals("function:access-permitted Expected 2 arguments, got 1", res.getStatus()
++ .getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // too many args
+ arguments.clear();
+ arguments.add(attrUriEmpty);
+ arguments.add(attrXContentSimpson);
+ arguments.add(attrXContentSimpson);
+ res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments);
+ assertFalse(res.getStatus().isOk());
- assertEquals( "function:access-permitted Expected 2 arguments, got 3", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
-
++ assertEquals("function:access-permitted Expected 2 arguments, got 3", 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/FunctionDefinitionArithmeticTest.java
----------------------------------------------------------------------
diff --cc openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionArithmeticTest.java
index 6127f36,0000000..a55cb01
mode 100644,000000..100644
--- a/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionArithmeticTest.java
+++ b/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionArithmeticTest.java
@@@ -1,726 -1,0 +1,693 @@@
+/*
+ * 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.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.FunctionDefinitionArithmetic;
+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 FunctionDefinitionArithmeticTest {
+
+ /*
+ * variables useful in the following tests
+ */
+ List<FunctionArgument> arguments = new ArrayList<FunctionArgument>();
+
+ @Test
+ public void testInteger_add() {
+
+ FunctionArgumentAttributeValue attr1 = null;
+ FunctionArgumentAttributeValue attr2 = null;
+ FunctionArgumentAttributeValue attrBadType = null;
+ try {
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
+ attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_INTEGER_ADD;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_INTEGER_ADD;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_INTEGER_ADD, fd.getId());
+ assertEquals(DataTypes.DT_INTEGER.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(2), fd.getNumArgs());
+
-
+ // test normal add
+ arguments.add(attr1);
+ arguments.add(attr2);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ BigInteger resValue = (BigInteger)res.getValue().getValue();
+ assertEquals(new BigInteger("2"), resValue);
+
+ arguments.clear();
+ arguments.add(attr1);
+ arguments.add(attrBadType);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
- assertEquals("function:integer-add Expected data type 'integer' saw 'double' at arg index 1", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:integer-add Expected data type 'integer' saw 'double' at arg index 1", res
++ .getStatus().getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ }
+
-
+ @Test
+ public void testDouble_add() {
+
+ FunctionArgumentAttributeValue attr1 = null;
- FunctionArgumentAttributeValue attr2 = null;
++ FunctionArgumentAttributeValue attr2 = null;
+
+ try {
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5));
+ } catch (Exception e) {
- fail("creating attributes e="+e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_DOUBLE_ADD;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_DOUBLE_ADD;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_DOUBLE_ADD, fd.getId());
+ assertEquals(DataTypes.DT_DOUBLE.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(2), fd.getNumArgs());
+
-
+ // test normal add
+ arguments.add(attr1);
+ arguments.add(attr2);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ Double resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(4.0), resValue);
+
+ }
+
-
+ @Test
+ public void testInteger_subtract() {
+
+ FunctionArgumentAttributeValue attr1 = null;
+ FunctionArgumentAttributeValue attr2 = null;
+ try {
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(6));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_INTEGER_SUBTRACT;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_INTEGER_SUBTRACT;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_INTEGER_SUBTRACT, fd.getId());
+ assertEquals(DataTypes.DT_INTEGER.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(2), fd.getNumArgs());
+
-
+ // test normal
+ arguments.add(attr1);
+ arguments.add(attr2);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ BigInteger resValue = (BigInteger)res.getValue().getValue();
+ assertEquals(new BigInteger("5"), resValue);
+
+ }
+
-
+ @Test
+ public void testDouble_subtract() {
+
+ FunctionArgumentAttributeValue attr1 = null;
- FunctionArgumentAttributeValue attr2 = null;
++ FunctionArgumentAttributeValue attr2 = null;
+
+ try {
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(8.5));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.3));
+ } catch (Exception e) {
- fail("creating attributes e="+e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_DOUBLE_SUBTRACT;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_DOUBLE_SUBTRACT;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_DOUBLE_SUBTRACT, fd.getId());
+ assertEquals(DataTypes.DT_DOUBLE.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(2), fd.getNumArgs());
+
-
+ // test normal
+ arguments.add(attr1);
+ arguments.add(attr2);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ Double resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(6.2), resValue);
+
+ }
+
-
+ @Test
+ public void testInteger_multiply() {
+
+ FunctionArgumentAttributeValue attr0 = null;
+ FunctionArgumentAttributeValue attr1 = null;
+ FunctionArgumentAttributeValue attr2 = null;
+ try {
+ attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0));
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_INTEGER_MULTIPLY;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_INTEGER_MULTIPLY;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_INTEGER_MULTIPLY, fd.getId());
+ assertEquals(DataTypes.DT_INTEGER.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(2), fd.getNumArgs());
+
-
+ // test normal
+ arguments.add(attr1);
+ arguments.add(attr2);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ BigInteger resValue = (BigInteger)res.getValue().getValue();
+ assertEquals(new BigInteger("10"), resValue);
+
-
+ // test 0
+ arguments.clear();
+ arguments.add(attr1);
+ arguments.add(attr0);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (BigInteger)res.getValue().getValue();
+ assertEquals(new BigInteger("0"), resValue);
+ }
+
-
+ @Test
+ public void testDouble_multiply() {
+
+ FunctionArgumentAttributeValue attr0 = null;
+ FunctionArgumentAttributeValue attr1 = null;
- FunctionArgumentAttributeValue attr2 = null;
++ FunctionArgumentAttributeValue attr2 = null;
+
+ try {
+ attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0));
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5));
+ } catch (Exception e) {
- fail("creating attributes e="+e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_DOUBLE_MULTIPLY;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_DOUBLE_MULTIPLY;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_DOUBLE_MULTIPLY, fd.getId());
+ assertEquals(DataTypes.DT_DOUBLE.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(2), fd.getNumArgs());
+
-
+ // test normal add
+ arguments.add(attr1);
+ arguments.add(attr2);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ Double resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(3.75), resValue);
+
+ // test multiply by 0
+ arguments.clear();
+ arguments.add(attr1);
+ arguments.add(attr0);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(0), resValue);
+ }
+
-
+ @Test
+ public void testInteger_divide() {
+
+ FunctionArgumentAttributeValue attr0 = null;
+ FunctionArgumentAttributeValue attr1 = null;
+ FunctionArgumentAttributeValue attr2 = null;
+ try {
+ attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0));
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_INTEGER_DIVIDE;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_INTEGER_DIVIDE;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_INTEGER_DIVIDE, fd.getId());
+ assertEquals(DataTypes.DT_INTEGER.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(2), fd.getNumArgs());
+
-
+ // test normal
+ arguments.add(attr1);
+ arguments.add(attr2);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ BigInteger resValue = (BigInteger)res.getValue().getValue();
+ assertEquals(new BigInteger("2"), resValue);
+
-
+ // test 0
+ arguments.clear();
+ arguments.add(attr1);
+ arguments.add(attr0);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
+ assertEquals("function:integer-divide Divide by 0 error: 5, 0", 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 testDouble_divide() {
+
+ FunctionArgumentAttributeValue attr0 = null;
+ FunctionArgumentAttributeValue attr1 = null;
- FunctionArgumentAttributeValue attr2 = null;
++ FunctionArgumentAttributeValue attr2 = null;
+
+ try {
+ attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0));
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5));
+
+ } catch (Exception e) {
- fail("creating attributes e="+e);
++ fail("creating attributes e=" + e);
+ }
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_DOUBLE_DIVIDE;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_DOUBLE_DIVIDE;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_DOUBLE_DIVIDE, fd.getId());
+ assertEquals(DataTypes.DT_DOUBLE.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(2), fd.getNumArgs());
+
-
+ // test normal
+ arguments.add(attr1);
+ arguments.add(attr2);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ Double resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(0.6), resValue);
+
+ // test multiply by 0
+ arguments.clear();
+ arguments.add(attr1);
+ arguments.add(attr0);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
+ assertEquals("function:double-divide Divide by 0 error: 1.5, 0.0", 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 testInteger_mod() {
+
+ FunctionArgumentAttributeValue attr0 = null;
+ FunctionArgumentAttributeValue attr1 = null;
+ FunctionArgumentAttributeValue attr2 = null;
+ try {
+ attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0));
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(28));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_INTEGER_MOD;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_INTEGER_MOD;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_INTEGER_MOD, fd.getId());
+ assertEquals(DataTypes.DT_INTEGER.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(2), fd.getNumArgs());
+
-
+ // test normal
+ arguments.add(attr1);
+ arguments.add(attr2);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ BigInteger resValue = (BigInteger)res.getValue().getValue();
+ assertEquals(new BigInteger("3"), resValue);
+
-
+ // test 0
+ arguments.clear();
+ arguments.add(attr1);
+ arguments.add(attr0);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
+ assertEquals("function:integer-mod Divide by 0 error: 28, 0", 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 testInteger_abs() {
+
+ FunctionArgumentAttributeValue attr0 = null;
+ FunctionArgumentAttributeValue attr1 = null;
+ FunctionArgumentAttributeValue attrM1 = null;
+ try {
+ attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0));
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5));
+ attrM1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-7));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_INTEGER_ABS;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_INTEGER_ABS;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_INTEGER_ABS, fd.getId());
+ assertEquals(DataTypes.DT_INTEGER.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
+ arguments.add(attr1);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ BigInteger resValue = (BigInteger)res.getValue().getValue();
+ assertEquals(new BigInteger("5"), resValue);
+
+ arguments.clear();
+ arguments.add(attrM1);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (BigInteger)res.getValue().getValue();
+ assertEquals(new BigInteger("7"), resValue);
+
+ arguments.clear();
+ arguments.add(attr0);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (BigInteger)res.getValue().getValue();
+ assertEquals(new BigInteger("0"), resValue);
+ }
+
-
+ @Test
+ public void testDouble_abs() {
+
+ FunctionArgumentAttributeValue attr0 = null;
+ FunctionArgumentAttributeValue attr1 = null;
- FunctionArgumentAttributeValue attr2 = null;
++ FunctionArgumentAttributeValue attr2 = null;
+
+ try {
+ attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0));
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5));
+
+ } catch (Exception e) {
- fail("creating attributes e="+e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_DOUBLE_ABS;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_DOUBLE_ABS;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_DOUBLE_ABS, fd.getId());
+ assertEquals(DataTypes.DT_DOUBLE.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
+ arguments.add(attr1);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ Double resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(1.5), resValue);
+
+ arguments.clear();
+ arguments.add(attr2);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(2.5), resValue);
+
+ arguments.clear();
+ arguments.add(attr0);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(0), resValue);
+
+ }
+
-
+ @Test
+ public void testDouble_round() {
+
+ FunctionArgumentAttributeValue attr0 = null;
+ FunctionArgumentAttributeValue attr1 = null;
- FunctionArgumentAttributeValue attr2 = null;
++ FunctionArgumentAttributeValue attr2 = null;
+ FunctionArgumentAttributeValue attr3 = null;
+ FunctionArgumentAttributeValue attr4 = null;
+ FunctionArgumentAttributeValue attr5 = null;
+ FunctionArgumentAttributeValue attr6 = null;
+ try {
+ attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0));
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.49));
+ attr3 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.51));
+ attr4 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5));
+ attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.49));
+ attr6 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.51));
+ } catch (Exception e) {
- fail("creating attributes e="+e);
++ fail("creating attributes e=" + e);
+ }
+
-
-
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_ROUND;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_ROUND;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_ROUND, fd.getId());
+ assertEquals(DataTypes.DT_DOUBLE.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
+ arguments.add(attr0);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ Double resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(0), resValue);
+
+ arguments.clear();
+ arguments.add(attr1);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(2), resValue);
+
+ arguments.clear();
+ arguments.add(attr2);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(1), resValue);
+
+ arguments.clear();
+ arguments.add(attr3);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(2), resValue);
+
+ arguments.clear();
+ arguments.add(attr4);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(-2), resValue);
+
+ arguments.clear();
+ arguments.add(attr5);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(-2), resValue);
+
+ arguments.clear();
+ arguments.add(attr6);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(-3), resValue);
+ }
+
-
+ @Test
+ public void testDouble_floor() {
+ FunctionArgumentAttributeValue attr0 = null;
+ FunctionArgumentAttributeValue attr1 = null;
- FunctionArgumentAttributeValue attr2 = null;
++ FunctionArgumentAttributeValue attr2 = null;
+ FunctionArgumentAttributeValue attr3 = null;
+ FunctionArgumentAttributeValue attr4 = null;
+ FunctionArgumentAttributeValue attr5 = null;
+ FunctionArgumentAttributeValue attr6 = null;
+ try {
+ attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0));
+ attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5));
+ attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.49));
+ attr3 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.51));
+ attr4 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5));
+ attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.49));
+ attr6 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.51));
+ } catch (Exception e) {
- fail("creating attributes e="+e);
++ fail("creating attributes e=" + e);
+ }
+
- FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_FLOOR;
++ FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>)StdFunctions.FD_FLOOR;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_FLOOR, fd.getId());
+ assertEquals(DataTypes.DT_DOUBLE.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
+ arguments.add(attr0);
+ ExpressionResult res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ Double resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(0), resValue);
+
+ arguments.clear();
+ arguments.add(attr1);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(1), resValue);
+
+ arguments.clear();
+ arguments.add(attr2);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(1), resValue);
+
+ arguments.clear();
+ arguments.add(attr3);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(1), resValue);
+
+ arguments.clear();
+ arguments.add(attr4);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(-3), resValue);
+
+ arguments.clear();
+ arguments.add(attr5);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(-3), resValue);
+
+ arguments.clear();
+ arguments.add(attr6);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ resValue = (Double)res.getValue().getValue();
+ assertEquals(new Double(-3), 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/FunctionDefinitionBagIsInTest.java
----------------------------------------------------------------------
diff --cc openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionBagIsInTest.java
index f56a366,0000000..225d2f9
mode 100644,000000..100644
--- a/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionBagIsInTest.java
+++ b/openaz-xacml-test/src/test/java/org/apache/openaz/xacml/pdp/std/functions/FunctionDefinitionBagIsInTest.java
@@@ -1,220 -1,0 +1,218 @@@
+/*
+ * 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.Bag;
+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.policy.FunctionArgumentBag;
+import org.apache.openaz.xacml.pdp.std.StdFunctions;
+import org.apache.openaz.xacml.pdp.std.functions.FunctionDefinitionBagIsIn;
+import org.apache.openaz.xacml.std.StdAttributeValue;
+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 FunctionDefinitionBagIsInTest {
+
-
+ /*
+ * 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");
+ String notInBag = new String("lmnop");
+ String sameValueV1 = new String("abc");
+ Integer vOtherType = new Integer(11);
+
-
+ FunctionArgumentAttributeValue attrV1 = null;
+ FunctionArgumentAttributeValue attrV2 = null;
+ FunctionArgumentAttributeValue attrNotInBag = null;
+ FunctionArgumentAttributeValue attrSameValueV1 = null;
+ FunctionArgumentAttributeValue attrOtherType = null;
+ try {
+ attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1));
+ attrV2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v2));
- attrNotInBag = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(notInBag));
- attrSameValueV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(sameValueV1));
- attrOtherType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(vOtherType));
++ attrNotInBag = new FunctionArgumentAttributeValue(
++ DataTypes.DT_STRING
++ .createAttributeValue(notInBag));
++ attrSameValueV1 = new FunctionArgumentAttributeValue(
++ DataTypes.DT_STRING
++ .createAttributeValue(sameValueV1));
++ attrOtherType = new FunctionArgumentAttributeValue(
++ DataTypes.DT_INTEGER
++ .createAttributeValue(vOtherType));
+ } catch (Exception e) {
- fail("creating attributes e="+ e);
++ fail("creating attributes e=" + e);
+ }
+
+ Bag bag0 = new Bag();
+ Bag bag1 = new Bag();
+ bag1.add(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), v1));
+ Bag bag2 = new Bag();
+ bag2.add(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), v1));
- bag2.add(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), v2));;
-
-
++ bag2.add(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), v2));
++ ;
+
+ FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0);
+ FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1);
+ FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2);
+
-
-
- FunctionDefinitionBagIsIn<?> fd = (FunctionDefinitionBagIsIn<?>) StdFunctions.FD_STRING_IS_IN;
++ FunctionDefinitionBagIsIn<?> fd = (FunctionDefinitionBagIsIn<?>)StdFunctions.FD_STRING_IS_IN;
+
+ // check identity and type of the thing created
+ assertEquals(XACML3.ID_FUNCTION_STRING_IS_IN, 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());
+
-
+ // element is in bag
+ arguments.clear();
+ arguments.add(attrV1);
+ arguments.add(attrBag2);
+ 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);
+
+ // element not in bag
+ arguments.clear();
+ arguments.add(attrNotInBag);
+ arguments.add(attrBag2);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(false, resValue);
+
+ // different element with the same value is in bag
+ arguments.clear();
+ arguments.add(attrSameValueV1);
+ arguments.add(attrBag2);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(true, resValue);
+
+ // empty bag
+ arguments.clear();
+ arguments.add(attrV1);
+ arguments.add(attrBag0);
+ res = fd.evaluate(null, arguments);
+ assertTrue(res.isOk());
+ assertEquals(Boolean.class, res.getValue().getValue().getClass());
+ resValue = (Boolean)res.getValue().getValue();
+ assertEquals(false, resValue);
+
+ // missing arg
+ arguments.clear();
+ arguments.add(attrSameValueV1);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
+ assertEquals("function:string-is-in Expected 2 arguments, got 1", 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());
+
+ // 1st arg is bag
+ arguments.clear();
+ arguments.add(attrBag1);
+ arguments.add(attrBag2);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
- assertEquals("function:string-is-in Expected a simple value, saw a bag", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:string-is-in Expected a simple value, saw a bag", res.getStatus()
++ .getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // 2nd arg not bag
+ arguments.clear();
+ arguments.add(attrV1);
+ arguments.add(attrV2);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
- assertEquals("function:string-is-in Expected a bag, saw a simple value", res.getStatus().getStatusMessage());
- assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
++ assertEquals("function:string-is-in Expected a bag, saw a simple value", res.getStatus()
++ .getStatusMessage());
++ assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode()
++ .getStatusCodeValue().stringValue());
+
+ // first arg null
+ arguments.clear();
+ arguments.add(null);
+ arguments.add(attrBag2);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
+ assertEquals("function:string-is-in 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());
+
+ // 2nd arg null
+ arguments.clear();
+ arguments.add(attrV1);
+ arguments.add(null);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
+ assertEquals("function:string-is-in 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());
+
+ // first arg type does not match bag elements
+ arguments.clear();
+ arguments.add(attrOtherType);
+ arguments.add(attrBag2);
+ res = fd.evaluate(null, arguments);
+ assertFalse(res.isOk());
- assertEquals("function:string-is-in 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-is-in 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());
+
+ // bag has mixed element types
- // behavior not specified for this case in spec. It ASSUMES that all elements in bag are same type.
++ // behavior not specified for this case in spec. It ASSUMES that all elements in bag are same type.
+
+ }
+
-
-
-
+ //
+ //
- // REST OF DATA TYPES OMITTED
- // because they "should" all work the same
++ // REST OF DATA TYPES OMITTED
++ // because they "should" all work the same
+ //
+ //
+
-
-
-
+}