diff options
Diffstat (limited to 'ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std')
31 files changed, 0 insertions, 30138 deletions
diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseConformanceTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseConformanceTest.java deleted file mode 100644 index e314e1c2b..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseConformanceTest.java +++ /dev/null @@ -1,196 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.dom; - -import static org.junit.Assert.fail; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import com.att.research.xacml.api.Response; -import com.att.research.xacml.std.dom.DOMResponse; - -/** - * Tests for handling the XML version of the XACML Response object. - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * Normally the Response is generated by the PDP and returned through the RESTful interface as JSON. - * Testing of the XML interface is minimal and not complete. - * - * - * - * - */ -public class DOMResponseConformanceTest { - - // where to find the conformance test XML files - private final String CONFORMANCE_DIRECTORY_PATH = "testsets/conformance/xacml3.0-ct-v.0.4"; - - // The request object output from each test conversion from JSON string - Response response; - - - - // Load the Conformance test responses into Response objects, generate the output XML for that Response and compare with the original files. - @Test - public void testDOMResponse() { - List<File> filesInDirectory = null; - - File conformanceDirectory = null; - - File currentFile = null; - - try { - conformanceDirectory = new File(CONFORMANCE_DIRECTORY_PATH); - filesInDirectory = getRequestsInDirectory(conformanceDirectory); - } catch (Exception e) { - fail("Unable to set up Conformance tests for dir '" + conformanceDirectory.getAbsolutePath()+"' e="+ e); - } - - // run through each XML file - // - load the file from XML into an internal Response object - // - generate the XML representation from that Response object - // - reload the file into a String - // - compare the 2 XML strings - Response xmlResponse = null; - try { - for (File f : filesInDirectory) { - currentFile = f; - -//// This is a simple way to select just one file for debugging - comment out when not being used -//if ( ! f.getName().equals("IID302Response.xml")) { continue; } - -// during debugging it is helpful to know what file it is starting to work on -// System.out.println("starting file="+currentFile.getName()); - - - BufferedReader br = new BufferedReader(new FileReader(f)); - StringBuffer sb = new StringBuffer(); - String line; - while ((line = br.readLine()) != null) { - sb.append(line + "\n"); - } - br.close(); - - String xmlFromFile = sb.toString(); - - try { - // load XML into a Response object - xmlResponse = DOMResponse.load(xmlFromFile); - } catch (Exception e) { - // if XML does not load, just note it and continue with next file - System.out.println("XML file did not load: '" + f.getName() + " e=" + e); - continue; - } -//System.out.println(xmlFromFile); - - // create String version from the Response object - String xmlResponseString = DOMResponse.toString(xmlResponse, false); - - // Comparing the string directly to the String from the file is difficult. - // We can minimize the problems with newlines and whitespace, but we have other issues with how various object values are represented. - // For instance, and input double of "23.50" is output as "23.5" which is the same value but not identical strings. - // Therefore we take the XML output and use it to create a new Response object, then compare the two objects. - -//System.out.println(xmlResponseString); - Response reGeneratedResponse = DOMResponse.load(xmlResponseString); - - if ( ! xmlResponse.equals(reGeneratedResponse)) { - String normalizedFromFile = xmlFromFile.replaceAll("\\r|\\n", ""); - normalizedFromFile = normalizedFromFile.replaceAll("\\s+", " "); - normalizedFromFile = normalizedFromFile.replaceAll(">\\s*<", "><"); - System.out.println("File="+normalizedFromFile); - System.out.println("Gend="+ xmlResponseString); - - System.out.println(DOMResponse.toString(xmlResponse, true)); - - fail("Output string did not re-generate eqivilent object."); - } - -// // Normally whitespace is significant in XML. -// // However in this case we are generating an XML string for output and comparing it to a hand-made file. -// // The file may contain extra newlines or fewer spaces then our prettyPrinted output version. -// // Therefore we do the comparison on the un-prettyPrinted generated string. -// // To do this we have to remove the extra whitespace from the version read from the file. -// String normalizedFromFile = xmlFromFile.replaceAll("\\r|\\n", ""); -// normalizedFromFile = normalizedFromFile.replaceAll("\\s+", " "); -// normalizedFromFile = normalizedFromFile.replaceAll(">\\s*<", "><"); -// -// if ( ! xmlResponseString.equals(normalizedFromFile)) { -// System.out.println("file="+normalizedFromFile+"\ngend="+xmlResponseString); -// fail("file not same as generated string: " + f.getName()+ "\nFile="+xmlFromFile + "\nString="+xmlResponseString); -// } - - - } - - } catch (Exception e) { - fail ("Failed test with '" + currentFile.getName() + "', e=" + e); - } - - - } - - - - // - // HELPER to get list of all Request files in the given directory - // - - private List<File> getRequestsInDirectory(File directory) { - List<File> fileList = new ArrayList<File>(); - - File[] fileArray = directory.listFiles(); - for (File f : fileArray) { - if (f.isDirectory()) { - List<File> subDirList = getRequestsInDirectory(f); - fileList.addAll(subDirList); - } - if (f.getName().endsWith("Response.xml")) { - fileList.add(f); - } - } - return fileList; - - } - - -} - - -/* -Place to edit long strings output during tests - - - - - - - - -*/ diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseTest.java deleted file mode 100644 index e4e1e1662..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/dom/DOMResponseTest.java +++ /dev/null @@ -1,2316 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.dom; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import org.junit.Test; - -import com.att.research.xacml.api.Attribute; -import com.att.research.xacml.api.AttributeValue; -import com.att.research.xacml.api.Decision; -import com.att.research.xacml.api.Identifier; -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.IdentifierImpl; -import com.att.research.xacml.std.StdAttribute; -import com.att.research.xacml.std.StdAttributeCategory; -import com.att.research.xacml.std.StdAttributeValue; -import com.att.research.xacml.std.StdIdReference; -import com.att.research.xacml.std.StdMutableAdvice; -import com.att.research.xacml.std.StdMutableAttribute; -import com.att.research.xacml.std.StdMutableAttributeAssignment; -import com.att.research.xacml.std.StdMutableMissingAttributeDetail; -import com.att.research.xacml.std.StdMutableObligation; -import com.att.research.xacml.std.StdMutableResponse; -import com.att.research.xacml.std.StdMutableResult; -import com.att.research.xacml.std.StdMutableStatus; -import com.att.research.xacml.std.StdMutableStatusDetail; -import com.att.research.xacml.std.StdStatusCode; -import com.att.research.xacml.std.StdVersion; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacml.std.datatypes.StringNamespaceContext; -import com.att.research.xacml.std.datatypes.XPathExpressionWrapper; -import com.att.research.xacml.std.dom.DOMResponse; -import com.att.research.xacml.std.dom.DOMStructureException; - -/** - * Test DOM XML Responses - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * This class was copied from the JSON tests. At this time only the first two methods have been revised to work with XML. - * The second method includes multiple instances of all possible fields and has been manually verified. - * The remaining methods have not been converted because: - * - "conversion" consists of replacing the JSON strings with XML - * - the replacement would consist of copying the XML from the JUnit output and doing a String replace - * - there would be little examination of the (long) XML strings, so their validity would be questionable - * so the benefit for the cost of doing that work is not clear. - * - * - */ -public class DOMResponseTest { - - String xmlResponse; - - StdMutableResponse response; - - StdMutableResult result; - - StdMutableStatus status; - - - // Note: Initially test responses without Obligations, Associated Advice, Attributes, or PolicyIdentifier - - - @Test - public void testEmptyAndDecisions() { - // null response - try { - xmlResponse = DOMResponse.toString(null, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // empty response (no Result object) - response = new StdMutableResponse(); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - - // just decision, no status - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // just status (empty), no decision - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - result.setStatus(status); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // just status (non-empty), no decision - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_OK); - result.setStatus(status); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - - // test other decisions without Status - - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.DENY); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Deny</Decision></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.NOTAPPLICABLE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>NotApplicable</Decision></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.INDETERMINATE_DENY); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate{D}</Decision></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.INDETERMINATE_DENYPERMIT); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate{DP}</Decision></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.INDETERMINATE_PERMIT); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate{P}</Decision></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // test Multiple Decisions - success - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - response.add(result); - StdMutableResult result2 = new StdMutableResult(); - result2.setDecision(Decision.DENY); - response.add(result2); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision></Result><Result><Decision>Deny</Decision></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // test Multiple Decisions - one success and one error - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - response.add(result); - result2 = new StdMutableResult(); - result2.setDecision(Decision.INDETERMINATE); - response.add(result2); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision></Result><Result><Decision>Indeterminate</Decision></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - } - - - - - // Test with every field filled in with multiple values where appropriate - @Test - public void testAllFieldsResponse() { - - // fully-loaded multiple response - - StdMutableResponse response = new StdMutableResponse(); - // create a Status object - StdMutableStatus status = new StdMutableStatus(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - status.setStatusMessage("some status message"); - StdMutableStatusDetail statusDetailIn = new StdMutableStatusDetail(); - StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "doh")); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_INTEGER.getId(), "5432")); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh")); - mad.setAttributeId(XACML3.ID_ACTION_PURPOSE); - mad.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION); - mad.setDataTypeId(XACML3.ID_DATATYPE_STRING); - mad.setIssuer("an Issuer"); - statusDetailIn.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetailIn); - // create a single result object - StdMutableResult result = new StdMutableResult(status); - // set the decision - result.setDecision(Decision.INDETERMINATE); - // put the Result into the Response - response.add(result); - - - // create a new Result with a different Decision - status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK); - result = new StdMutableResult(status); - result.setDecision(Decision.DENY); - - StdMutableObligation obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer2", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Ned"))); - result.addObligation(obligation); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_SUBJECT_CATEGORY_INTERMEDIARY_SUBJECT); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer3", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Maggie"))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer4", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Homer"))); - result.addObligation(obligation); - - - StdMutableAdvice advice = new StdMutableAdvice(); - advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"))); - advice.addAttributeAssignment(new StdMutableAttributeAssignment( - null, - XACML3.ID_SUBJECT, - "advice-issuerNoCategory", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Crusty"))); - result.addAdvice(advice); - - - response.add(result); - - - // create a new Result with a different Decision - // add Child/minor status codes within the main status - StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode")); - StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode); - StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode); - StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); - - status = new StdMutableStatus(statusCode); - - - result = new StdMutableResult(status); - result.setDecision(Decision.PERMIT); - - - - - // add attribute list in result - Identifier categoryIdentifier = new IdentifierImpl("firstCategory"); - Attribute[] attrList = { - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), null, true) }; - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(attrList))); - categoryIdentifier = new IdentifierImpl("secondCategory"); - Attribute[] secondAttrList = { - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) }; - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList))); - - - // add PolicyIdentifierList to result - StdIdReference policyIdentifier1 = null; - StdIdReference policyIdentifier2 = null; - StdIdReference policySetIdentifier1 = null; - StdIdReference policySetIdentifier2 = null; - try { - policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); - policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); - policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); - policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); - } catch (ParseException e1) { - fail("creating policyIds, e="+e1); - } - - result.addPolicyIdentifier(policyIdentifier1); - result.addPolicyIdentifier(policyIdentifier2); - - result.addPolicySetIdentifier(policySetIdentifier1); - result.addPolicySetIdentifier(policySetIdentifier2); - - response.add(result); - - // convert Response to XML - try { - xmlResponse = DOMResponse.toString(response, false); -//System.out.println(xmlResponse); -//System.out.println(DOMResponse.toString(response, true)); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusMessage>some status message</StatusMessage><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:action\" AttributeId=\"urn:oasis:names:tc:xacml:2.0:action:purpose\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\" Issuer=\"an Issuer\"><AttributeValue>doh</AttributeValue><AttributeValue>5432</AttributeValue><AttributeValue>meh</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result><Result><Decision>Deny</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Ned</AttributeAssignment></Obligation><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Maggie</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Homer</AttributeAssignment></Obligation></Obligations><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Crusty</AttributeAssignment></Advice></AssociatedAdvice></Result><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"><StatusCode Value=\"child1StatusCode\"><StatusCode Value=\"childChildStatusCode\"><StatusCode Value=\"childChildChildStatusCode\"/></StatusCode></StatusCode></StatusCode></Status><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent3\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent4\" Issuer=\"DIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent5\" Issuer=\"EIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrNoIssuer\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes><Attributes Category=\"secondCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent12\" Issuer=\"AIssue2\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu2</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent32\" Issuer=\"CIssue2\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Der2</AttributeValue></Attribute></Attributes><PolicyIdentifierList><PolicyIdReference Version=\"1.2.3\">idRef1</PolicyIdReference><PolicyIdReference>idRef2_NoVersion</PolicyIdReference><PolicySetIdReference Version=\"4.5.6.7.8.9.0\">idSetRef1</PolicySetIdReference><PolicySetIdReference>idSetRef2_NoVersion</PolicySetIdReference></PolicyIdentifierList></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - } - - - - - // combinations of Status values with Decision values - @Test - public void testDecisionStatusMatch() { - // the tests in this method use different values and do not change structures, so we can re-use the objects - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - result.setStatus(status); - response.add(result); - - // StatusCode = OK - status.setStatusCode(StdStatusCode.STATUS_CODE_OK); - result.setDecision(Decision.PERMIT); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.DENY); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Deny</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.NOTAPPLICABLE); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>NotApplicable</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - result.setDecision(Decision.INDETERMINATE_DENY); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - result.setDecision(Decision.INDETERMINATE_DENYPERMIT); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - result.setDecision(Decision.INDETERMINATE_PERMIT); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - - - - - - // StatusCode = SyntaxError - status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); - result.setDecision(Decision.PERMIT); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - result.setDecision(Decision.DENY); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - result.setDecision(Decision.NOTAPPLICABLE); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - result.setDecision(Decision.INDETERMINATE); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_DENY); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate{D}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_DENYPERMIT); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate{DP}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_PERMIT); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate{P}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // StatusCode = ProcessingError - status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); - result.setDecision(Decision.PERMIT); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - result.setDecision(Decision.DENY); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - result.setDecision(Decision.NOTAPPLICABLE); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - result.setDecision(Decision.INDETERMINATE); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_DENY); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate{D}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_DENYPERMIT); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate{DP}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_PERMIT); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate{P}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - - // StatusCode = MissingAttribute - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - result.setDecision(Decision.PERMIT); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - result.setDecision(Decision.DENY); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - result.setDecision(Decision.NOTAPPLICABLE); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - result.setDecision(Decision.INDETERMINATE); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_DENY); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate{D}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_DENYPERMIT); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate{DP}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_PERMIT); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate{P}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - } - - - - - // tests related to Status and its components - @Test - public void testStatus() { - // Status with no StatusCode - error - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - result.setStatus(status); - result.setDecision(Decision.PERMIT); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // Status with StatusMessage when OK - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_OK); - status.setStatusMessage("I'm ok, you're ok"); - result.setStatus(status); - result.setDecision(Decision.PERMIT); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with StatusDetail when OK - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_OK); - StdMutableStatusDetail statusDetail = new StdMutableStatusDetail(); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.PERMIT); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // Status with StatusMessage when SyntaxError - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); - status.setStatusMessage("I'm ok, you're ok"); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with empty StatusDetail when SyntaxError - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); - statusDetail = new StdMutableStatusDetail(); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - - // Status with StatusMessage when ProcessingError - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); - status.setStatusMessage("I'm ok, you're ok"); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with empty StatusDetail when ProcessingError - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); - statusDetail = new StdMutableStatusDetail(); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - - // Status with StatusMessage when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - status.setStatusMessage("I'm ok, you're ok"); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with empty StatusDetail when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail></StatusDetail></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - - // Status with StatusDetail with empty detail when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // Status with StatusDetail with valid detail with no value when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with StatusDetail with valid detail with value when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh")); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"><AttributeValue>meh</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with StatusDetail with array valid detail with value when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh")); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "nu?")); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"><AttributeValue>meh</AttributeValue><AttributeValue>nu?</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // Status with StatusDetail with valid detail with Integer value when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - mad.addAttributeValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111)); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"><AttributeValue>1111</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with StatusDetail with array valid detail with Integer value when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - mad.addAttributeValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111)); - mad.addAttributeValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 2222)); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"><AttributeValue>1111</AttributeValue><AttributeValue>2222</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - -// StringNamespaceContext snc = new StringNamespaceContext(); -// try { -// snc.add("defaultURI"); -// snc.add("md", "referenceForMD"); -// } catch (Exception e) { -// fail("unable to create NamespaceContext e="+e); -// } -// XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); -// -//TODO - assume that we will never try to pass back an XPathExpression in a MissingAttributeDetail - it doesn't make sense and is unclear how to put into XML -// // Status with StatusDetail with valid detail with XPathExpression value when MissingAttribute -// response = new StdMutableResponse(); -// result = new StdMutableResult(); -// status = new StdMutableStatus(); -// status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); -// statusDetail = new StdMutableStatusDetail(); -// mad = new StdMutableMissingAttributeDetail(); -// mad.setAttributeId(new IdentifierImpl("mad")); -// mad.setCategory(XACML3.ID_ACTION); -// mad.setDataTypeId(DataTypes.DT_STRING.getId()); -// mad.addAttributeValue(new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId"))); -// statusDetail.addMissingAttributeDetail(mad); -// status.setStatusDetail(statusDetail); -// result.setStatus(status); -// result.setDecision(Decision.INDETERMINATE); -// response.add(result); -// try { -// xmlResponse = DOMResponse.toString(response, false); -// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<MissingAttributeDetail><AttributeValue>1111</AttributeValue><Category>urn:oasis:names:tc:xacml:1.0:action</Category><AttributeId>mad</AttributeId><DataType>http://www.w3.org/2001/XMLSchema#string</DataType></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", xmlResponse); -// } catch (Exception e) { -// fail("operation failed, e="+e); -// } -// -// // Status with StatusDetail with array valid detail with XPathExpression value when MissingAttribute -// response = new StdMutableResponse(); -// result = new StdMutableResult(); -// status = new StdMutableStatus(); -// status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); -// statusDetail = new StdMutableStatusDetail(); -// mad = new StdMutableMissingAttributeDetail(); -// mad.setAttributeId(new IdentifierImpl("mad")); -// mad.setCategory(XACML3.ID_ACTION); -// mad.setDataTypeId(DataTypes.DT_STRING.getId()); -// mad.addAttributeValue(new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId1"))); -// mad.addAttributeValue(new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId2"))); -// statusDetail.addMissingAttributeDetail(mad); -// status.setStatusDetail(statusDetail); -// result.setStatus(status); -// result.setDecision(Decision.INDETERMINATE); -// response.add(result); -// try { -// xmlResponse = DOMResponse.toString(response, false); -// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<MissingAttributeDetail><AttributeValue>1111</AttributeValue><AttributeValue>2222</AttributeValue><Category>urn:oasis:names:tc:xacml:1.0:action</Category><AttributeId>mad</AttributeId><DataType>http://www.w3.org/2001/XMLSchema#string</DataType></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", xmlResponse); -// } catch (Exception e) { -// fail("operation failed, e="+e); -// } - -//TODO - try with other data types, esp XPathExpression - - // Status with StatusDetail with array valid detail with value when SyntaxError - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh")); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "nu?")); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // Status with StatusDetail with array valid detail with value when ProcessingError - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh")); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "nu?")); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - - - // Status with nested child StatusCodes (child status containing child status containing...) - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode")); - StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); - status = new StdMutableStatus(statusCode); - status.setStatusMessage("I'm ok, you're ok"); - result.setStatus(status); - result.setDecision(Decision.PERMIT); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"><StatusCode Value=\"child1StatusCode\"/></StatusCode><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode")); - StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode); - child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode); - statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); - status = new StdMutableStatus(statusCode); - status.setStatusMessage("I'm ok, you're ok"); - result.setStatus(status); - result.setDecision(Decision.PERMIT); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"><StatusCode Value=\"child1StatusCode\"><StatusCode Value=\"childChildStatusCode\"><StatusCode Value=\"childChildChildStatusCode\"/></StatusCode></StatusCode></StatusCode><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - } - - - - @Test - public void testObligations() { - - // create an XPathExpression for use later - StringNamespaceContext snc = new StringNamespaceContext(); - try { - snc.add("defaultURI"); - snc.add("md", "referenceForMD"); - } catch (Exception e) { - fail("unable to create NamespaceContext e="+e); - } - XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); - XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital"); - - StdMutableObligation obligation; - - // test Obligation single decision no attributes - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"></Obligation></Obligations></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // obligation missing Id - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - - - // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - null, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // AttributeAssignment - Missing AttributeId - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - null, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // AttributeAssignment - Missing Value - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - null)); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // AttributeAssignment - missing required DataType (Different than JSON where DataType is optional with default String) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(null, "Bart"))); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // AttributeAssignment - missing issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // AttributeAssignment - Integer type - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111))); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">1111</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // AttributeAssignment - XPathExpression type - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:record</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - - - // - // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition: - // <Obligation (attributes of the obligation) > - // <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment> - // <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment> - // : - // </Obligation - // which means that there may be multiple AttributeAssignments but each one has only one value. - // This differs from the Attributes section in which each <Attribute> may have multiple <AttributeValue> elements. - // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer. - // - - - // AttributeAssignment - Multiple values with same Category and Id (one way of doing array) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Lisa"))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Maggie"))); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Lisa</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Maggie</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 2222))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 3333))); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">1111</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">2222</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">3333</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // Multiple XPathExpression values with same Category and Id (one way of doing array) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory")))); - result.addObligation(obligation); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:record</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:hospital</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - } - - - - - @Test - public void testAdvice() { - - // create an XPathExpression for use later - StringNamespaceContext snc = new StringNamespaceContext(); - try { - snc.add("defaultURI"); - snc.add("md", "referenceForMD"); - } catch (Exception e) { - fail("unable to create NamespaceContext e="+e); - } - XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); - XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital"); - - StdMutableAdvice Advice; - - // test Advice single decision no attributes - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"></Advice></AssociatedAdvice></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Advice missing Id - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - - - // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - null, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // AttributeAssignment - Missing AttributeId - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - null, - "Advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // AttributeAssignment - Missing Value - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - null)); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // AttributeAssignment - missing Required DataType (Different than JSON where DataType is optional with default String) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<String>(null, "Bart"))); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // AttributeAssignment - missing issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // AttributeAssignment - Integer type - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111))); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">1111</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // AttributeAssignment - XPathExpression type - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:record</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - - - // - // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition: - // <Obligation (attributes of the obligation) > - // <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment> - // <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment> - // : - // </Obligation - // which means that there may be multiple AttributeAssignments but each one has only one value. - // This differs from the Attributes section in which each <Attribute> may have multiple <AttributeValue> elements. - // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer. - // - - // AttributeAssignment - Multiple values with same Category and Id (one way of doing array) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Lisa"))); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Maggie"))); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Lisa</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Maggie</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111))); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 2222))); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 3333))); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">1111</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">2222</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">3333</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // Multiple XPathExpression values with same Category and Id (one way of doing array) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory")))); - result.addAdvice(Advice); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:record</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:hospital</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - } - - - - - - - - - - - // Attributes tests - @Test - public void testAttributes() { - - // create an XPathExpression for use later - StringNamespaceContext snc = new StringNamespaceContext(); - try { - snc.add("defaultURI"); - snc.add("md", "referenceForMD"); - } catch (Exception e) { - fail("unable to create NamespaceContext e="+e); - } - XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); - - - Identifier categoryIdentifier; - List<Attribute> attrList = new ArrayList<Attribute>(); - StdMutableAttribute mutableAttribute; - - // Attr list with no entries - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // one Attribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // multiple attributes - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent2\" Issuer=\"BIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">P10Y4M</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent3\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent4\" Issuer=\"DIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent5\" Issuer=\"EIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // IncludeInResult=false/true - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", false)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Missing AttributeId (mandatory) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, null, new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // Missing mandatory Value - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), null), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // Missing optional Issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), null, true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // missing required DataType (different from JSON where DataType is optional and assumed to be String) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(null, "Apu"), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // same id, same type different issuer - // (This is not an array of values because Issuer is different) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"), "BIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Simpson"), "CIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"BIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Simpson</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // same id, same type same issuer - // (This is an array of values) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Simpson"), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Simpson</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // same Id, different types, same issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">P10Y4M</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // same Id, different types, different issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), null, true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"BIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">P10Y4M</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"DIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"EIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // different Id, different types, same issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "AIssue"), "BIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent2\" Issuer=\"BIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">AIssue</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent3\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent4\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent5\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // one Attribute of type XPathExpression (the only complex data type) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategory")), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" XPathCategory=\"xpathCategory\">//md:record</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // multiple sets of values - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), null, true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - categoryIdentifier = new IdentifierImpl("secondCategory"); - Attribute[] secondAttrList = { - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) }; - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList))); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent3\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent4\" Issuer=\"DIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent5\" Issuer=\"EIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrNoIssuer\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes><Attributes Category=\"secondCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent12\" Issuer=\"AIssue2\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu2</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent32\" Issuer=\"CIssue2\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Der2</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // array of values - same type - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - attrList.clear(); - categoryIdentifier = new IdentifierImpl("firstCategory"); - mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection<AttributeValue<?>>)null, "AIssue", true); - - mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu")); - mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")); - mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Homer")); - mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Ned")); - - attrList.add(mutableAttribute); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Homer</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Ned</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // array of values - compatible different types - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - attrList.clear(); - categoryIdentifier = new IdentifierImpl("firstCategory"); - mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection<AttributeValue<?>>)null, "AIssue", true); - - mutableAttribute.addValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567)); - mutableAttribute.addValue(new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432)); - mutableAttribute.addValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567)); - attrList.add(mutableAttribute); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // array of values - incompatible different types (Different from JSON because these are not part of an array in XML, just separate values) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - attrList.clear(); - categoryIdentifier = new IdentifierImpl("firstCategory"); - mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection<AttributeValue<?>>)null, "AIssue", true); - - mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu")); - mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M")); - mutableAttribute.addValue(new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432)); - mutableAttribute.addValue(new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true)); - mutableAttribute.addValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567)); - mutableAttribute.addValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567)); - attrList.add(mutableAttribute); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">P10Y4M</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - } - - - - - - // PolicyIdentifier tests - @Test - public void testPolicyIdentifier() { - - StdIdReference policyIdentifier1 = null; - StdIdReference policyIdentifier2 = null; - StdIdReference policySetIdentifier1 = null; - StdIdReference policySetIdentifier2 = null; - - // multiple PolicyIdentifiers of both types - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - try { - policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); - policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); - policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); - policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); - } catch (ParseException e1) { - fail("creating policyIds, e="+e1); - } - result.addPolicyIdentifier(policyIdentifier1); - result.addPolicyIdentifier(policyIdentifier2); - result.addPolicySetIdentifier(policySetIdentifier1); - result.addPolicySetIdentifier(policySetIdentifier2); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><PolicyIdentifierList><PolicyIdReference Version=\"1.2.3\">idRef1</PolicyIdReference><PolicyIdReference>idRef2_NoVersion</PolicyIdReference><PolicySetIdReference Version=\"4.5.6.7.8.9.0\">idSetRef1</PolicySetIdReference><PolicySetIdReference>idSetRef2_NoVersion</PolicySetIdReference></PolicyIdentifierList></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // PolicyIdentifier exists but has no IdReferences - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - policyIdentifier1 = null; - result.addPolicyIdentifier(policyIdentifier1); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // PolicySetIdentifier exists but has not IdReferences - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - policySetIdentifier1 = null; - result.addPolicyIdentifier(policySetIdentifier1); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (DOMStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from object to XML: " + e); - } - - // PolicyIdentifier with PolicyIdReference and no PolicySetIdReference - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - try { - policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); - } catch (ParseException e1) { - fail("creating policyIds, e="+e1); - } - result.addPolicyIdentifier(policyIdentifier1); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><PolicyIdentifierList><PolicyIdReference Version=\"1.2.3\">idRef1</PolicyIdReference></PolicyIdentifierList></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - - // PolicyIdentifier with no PolicyIdReference and with PolicySetIdReference - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - try { - policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); - } catch (ParseException e1) { - fail("creating policyIds, e="+e1); - } - result.addPolicySetIdentifier(policySetIdentifier1); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><PolicyIdentifierList><PolicySetIdReference Version=\"4.5.6.7.8.9.0\">idSetRef1</PolicySetIdReference></PolicyIdentifierList></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // IdReferences without version - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - - policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), null); - policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); - policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1")); - policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); - - result.addPolicyIdentifier(policyIdentifier1); - result.addPolicyIdentifier(policyIdentifier2); - result.addPolicySetIdentifier(policySetIdentifier1); - result.addPolicySetIdentifier(policySetIdentifier2); - response.add(result); - try { - xmlResponse = DOMResponse.toString(response, false); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" 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\"><Result><Decision>Permit</Decision><PolicyIdentifierList><PolicyIdReference>idRef1</PolicyIdReference><PolicyIdReference>idRef2_NoVersion</PolicyIdReference><PolicySetIdReference>idSetRef1</PolicySetIdReference><PolicySetIdReference>idSetRef2_NoVersion</PolicySetIdReference></PolicyIdentifierList></Result></Response>", xmlResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - } - - -//TODO - the XML spec implies that the Result Attributes may include the Content (It is part of the UML) - - - // test indentation??? - - -} - - -/* -Place to edit long strings ouput from tests - - -Expected -<?xml version="1.0" encoding="UTF-8"?><Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"><Result><Decision>Permit</Decision></Result></Response> -<?xml version="1.0" encoding="UTF-8"?><Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"><Result><Decision>Permit</Decision></Result></Response> -Actual - - - - */ - - - - - - - - - - - - - diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionAccessPermittedTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionAccessPermittedTest.java deleted file mode 100644 index 3e23ebca0..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionAccessPermittedTest.java +++ /dev/null @@ -1,522 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.xml.namespace.NamespaceContext; - -import org.junit.Ignore; -import org.junit.Test; - -import com.att.research.xacml.api.Request; -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.StdMutableRequest; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacml.std.dom.DOMRequest; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdEvaluationContext; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionAccessPermitted; - -/** - * 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>"; - 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 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\">"; - - 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> "; - 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; - - - /* - * 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)) { - 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")); - - // 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)); - - - - // 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. - - // 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; - 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; - 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 (com.att.research.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); - } - - // content included in both Resource and Action - ok - 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; - 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; - 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 (com.att.research.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); - } - - // 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 (com.att.research.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); - } - - } catch (Exception e) { - 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; - - // 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 - 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()); - - // 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()); - - // 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()); - - - // 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()); - - // 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()); - - // 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()); - - - // 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()); - - 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()); - - - // 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()); - - - } - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionArithmeticTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionArithmeticTest.java deleted file mode 100644 index 95fcdb2d2..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionArithmeticTest.java +++ /dev/null @@ -1,717 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionArithmetic; - -/** - * 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); - } - - 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 - 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()); - - } - - - @Test - public void testDouble_add() { - - FunctionArgumentAttributeValue attr1 = 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); - } - - 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 - 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); - } - - 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 - 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; - - 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); - } - - 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 - 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); - } - - 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 - 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; - - 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); - } - - 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 - 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); - } - - 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 - 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()); - - } - - - @Test - public void testDouble_divide() { - - FunctionArgumentAttributeValue attr0 = null; - FunctionArgumentAttributeValue attr1 = 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); - } - 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 - 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()); - - } - - - - - - - @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); - } - - 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 - 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()); - - } - - - @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); - } - - 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 - 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; - - 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); - } - - 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 - 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 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); - } - - - - 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 - 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 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); - } - - 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 - 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); - } - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagIsInTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagIsInTest.java deleted file mode 100644 index f783254a9..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagIsInTest.java +++ /dev/null @@ -1,221 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.StdAttributeValue; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.Bag; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBagIsIn; - -/** - * 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)); - } catch (Exception 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));; - - - - FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0); - FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1); - FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2); - - - - 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 - 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(java.lang.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(java.lang.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(java.lang.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(java.lang.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()); - - // 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()); - - // 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()); - - // 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()); - - // 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()); - - // 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()); - - // bag has mixed element types -// 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 - // - // - - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagOneAndOnlyTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagOneAndOnlyTest.java deleted file mode 100644 index 42a0aed75..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagOneAndOnlyTest.java +++ /dev/null @@ -1,224 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.functions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; -import java.math.BigInteger; - -import org.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.StdAttributeValue; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.Bag; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBagOneAndOnly; - -/** - * 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 FunctionDefinitionBagOneAndOnlyTest { - - - /* - * 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"); - BigInteger vOtherType = BigInteger.valueOf(11); - - 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)); - Bag bagOtherType = new Bag(); - bagOtherType.add(new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), vOtherType)); - - FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0); - FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1); - FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2); - FunctionArgumentBag attrBagOtherType = new FunctionArgumentBag(bagOtherType); - - - FunctionDefinitionBagOneAndOnly<?> fd = (FunctionDefinitionBagOneAndOnly<?>) StdFunctions.FD_STRING_ONE_AND_ONLY; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_ONE_AND_ONLY, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - - - - // bag with only one - arguments.clear(); - arguments.add(attrBag1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - String resValue = (String)res.getValue().getValue(); - assertEquals(v1, resValue); - - // null bag - arguments.clear(); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-one-and-only Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bag with exactly one but of other type in it - arguments.clear(); - arguments.add(attrBagOtherType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-one-and-only Element in bag of wrong type. Expected string got integer", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bag with none - arguments.clear(); - arguments.add(attrBag0); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-one-and-only Expected 1 but Bag has 0 elements", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bag with multiple - arguments.clear(); - arguments.add(attrBag2); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-one-and-only Expected 1 but Bag has 2 elements", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - @Test - public void testBoolean() { - Boolean v1 = new Boolean(true); - Boolean v2 = new Boolean(false); - BigInteger vOtherType = BigInteger.valueOf(11); - - Bag bag0 = new Bag(); - Bag bag1 = new Bag(); - bag1.add(new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), v1)); - Bag bag2 = new Bag(); - bag2.add(new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), v1)); - bag2.add(new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), v2)); - Bag bagOtherType = new Bag(); - bagOtherType.add(new StdAttributeValue<BigInteger>(DataTypes.DT_STRING.getId(), vOtherType)); - - - FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0); - FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1); - FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2); - FunctionArgumentBag attrBagOtherType = new FunctionArgumentBag(bagOtherType); - - - FunctionDefinitionBagOneAndOnly<?> fd = (FunctionDefinitionBagOneAndOnly<?>) StdFunctions.FD_BOOLEAN_ONE_AND_ONLY; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_BOOLEAN_ONE_AND_ONLY, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - - - - // bag with only one - arguments.clear(); - arguments.add(attrBag1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertEquals(new Boolean(true), resValue); - - // null bag - arguments.clear(); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:boolean-one-and-only Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bag with exactly one but of other type in it - arguments.clear(); - arguments.add(attrBagOtherType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:boolean-one-and-only Element in bag of wrong type. Expected boolean got string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bag with none - arguments.clear(); - arguments.add(attrBag0); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:boolean-one-and-only Expected 1 but Bag has 0 elements", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bag with multiple - arguments.clear(); - arguments.add(attrBag2); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:boolean-one-and-only Expected 1 but Bag has 2 elements", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - // - // - // REST OF DATA TYPES OMITTED - // because they "should" all work the same - // - // - - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagSizeTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagSizeTest.java deleted file mode 100644 index cd08234f5..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagSizeTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.functions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.StdAttributeValue; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.Bag; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBagSize; - -/** - * 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 FunctionDefinitionBagSizeTest { - - - /* - * 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"); - Integer vOtherType = new Integer(11); - - - - 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)); - Bag bagOtherType = new Bag(); - bagOtherType.add(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), vOtherType)); - - - FunctionArgumentBag attrBag0 = new FunctionArgumentBag(bag0); - FunctionArgumentBag attrBag1 = new FunctionArgumentBag(bag1); - FunctionArgumentBag attrBag2 = new FunctionArgumentBag(bag2); - FunctionArgumentBag attrBagOtherType = new FunctionArgumentBag(bagOtherType); - - - FunctionDefinitionBagSize<?> fd = (FunctionDefinitionBagSize<?>) StdFunctions.FD_STRING_BAG_SIZE; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_BAG_SIZE, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - - - - // bag with only one - arguments.clear(); - arguments.add(attrBag1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.math.BigInteger.class, res.getValue().getValue().getClass()); - BigInteger resValue = (BigInteger)res.getValue().getValue(); - assertEquals(BigInteger.valueOf(1), resValue); - - // null bag - arguments.clear(); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-bag-size Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bag with exactly one but of other type in it - arguments.clear(); - arguments.add(attrBagOtherType); - res = fd.evaluate(null, arguments); - // NOTE: Size does not care about content type! - assertTrue(res.isOk()); - assertEquals(java.math.BigInteger.class, res.getValue().getValue().getClass()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(BigInteger.valueOf(1), resValue); - - // bag with none - arguments.clear(); - arguments.add(attrBag0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.math.BigInteger.class, res.getValue().getValue().getClass()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(BigInteger.valueOf(0), resValue); - - // bag with multiple - arguments.clear(); - arguments.add(attrBag2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.math.BigInteger.class, res.getValue().getValue().getClass()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(BigInteger.valueOf(2), resValue); - } - - - - - - - - // - // - // REST OF DATA TYPES OMITTED - // because they "should" all work the same - // - // - - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagTest.java deleted file mode 100644 index 925a09851..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBagTest.java +++ /dev/null @@ -1,547 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.functions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.junit.Test; - -import com.att.research.xacml.api.AttributeValue; -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.Bag; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBag; - -/** - * 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 FunctionDefinitionBagTest { - - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - - FunctionArgumentAttributeValue attrInteger = null; - FunctionArgumentAttributeValue attrString = null; - - public FunctionDefinitionBagTest() { - try { - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1111111111)); - attrString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("a string value")); - } catch (Exception e) { - fail("creating attributes e="+e); - } - } - - @Test - public void testString() { - - String s1 = "abc"; - String s2 = "def"; - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - try { - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(s1)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(s2)); - } catch (Exception e) { - fail("creating attributes e="+e); - } - - FunctionDefinitionBag<?> fd = (FunctionDefinitionBag<?>) StdFunctions.FD_STRING_BAG; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_BAG, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertTrue(fd.returnsBag()); - - // bag with only one - arguments.clear(); - arguments.add(attr1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Bag bag = res.getBag(); - assertNotNull(bag); - Iterator<AttributeValue<?>> it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - AttributeValue<?> attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - - // zero args => empty bag - arguments.clear(); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - assertEquals(0, bag.size()); - - - // null argument - arguments.clear(); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-bag Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // argument of other type - arguments.clear(); - arguments.add(attrInteger); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-bag 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()); - - // 2 args (check response is correct) - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(2, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(s2, attrValueObject.getValue()); - - // duplicate args (verify return) - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - arguments.add(attr1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(3, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(s2, attrValueObject.getValue()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - - // lots of args - arguments.clear(); - for (int i = 0; i < 1000; i++) { - arguments.add(attr1); - } - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1000, bag.size()); - - } - - - @Test - public void testBoolean() { - - Boolean s1 = true; - Boolean s2 = false; - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - try { - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(s1)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(s2)); - } catch (Exception e) { - fail("creating attributes e="+e); - } - - FunctionDefinitionBag<?> fd = (FunctionDefinitionBag<?>) StdFunctions.FD_BOOLEAN_BAG; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_BOOLEAN_BAG, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertTrue(fd.returnsBag()); - - // bag with only one - arguments.clear(); - arguments.add(attr1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Bag bag = res.getBag(); - assertNotNull(bag); - Iterator<AttributeValue<?>> it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - AttributeValue<?> attrValueObject = it.next(); - assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - - // zero args => empty bag - arguments.clear(); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - assertEquals(0, bag.size()); - - - // null argument - arguments.clear(); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:boolean-bag Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // argument of other type - arguments.clear(); - arguments.add(attrInteger); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:boolean-bag 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()); - - // 2 args (check response is correct) - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(2, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); - assertEquals(s2, attrValueObject.getValue()); - - // duplicate args (verify return) - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - arguments.add(attr1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(3, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); - assertEquals(s2, attrValueObject.getValue()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_BOOLEAN.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - - // lots of args - arguments.clear(); - for (int i = 0; i < 1000; i++) { - arguments.add(attr1); - } - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1000, bag.size()); - - } - - - - @Test - public void testInteger() { - - BigInteger s1 = new BigInteger("123"); - BigInteger s2 = new BigInteger("456"); - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - try { - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(s1)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(s2)); - } catch (Exception e) { - fail("creating attributes e="+e); - } - - FunctionDefinitionBag<?> fd = (FunctionDefinitionBag<?>) StdFunctions.FD_INTEGER_BAG; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_BAG, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertTrue(fd.returnsBag()); - - // bag with only one - arguments.clear(); - arguments.add(attr1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Bag bag = res.getBag(); - assertNotNull(bag); - Iterator<AttributeValue<?>> it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - AttributeValue<?> attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - - // zero args => empty bag - arguments.clear(); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - assertEquals(0, bag.size()); - - - // null argument - arguments.clear(); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-bag Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // argument of other type - arguments.clear(); - arguments.add(attrString); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-bag Expected data type 'integer' saw 'string'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // 2 args (check response is correct) - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(2, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(s2, attrValueObject.getValue()); - - // duplicate args (verify return) - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - arguments.add(attr1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(3, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(s2, attrValueObject.getValue()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - - // lots of args - arguments.clear(); - for (int i = 0; i < 1000; i++) { - arguments.add(attr1); - } - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1000, bag.size()); - - } - - - - - @Test - public void testDouble() { - - Double s1 = 123.45; - Double s2 = 678.901; - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - try { - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(s1)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(s2)); - } catch (Exception e) { - fail("creating attributes e="+e); - } - - FunctionDefinitionBag<?> fd = (FunctionDefinitionBag<?>) StdFunctions.FD_DOUBLE_BAG; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DOUBLE_BAG, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertTrue(fd.returnsBag()); - - // bag with only one - arguments.clear(); - arguments.add(attr1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Bag bag = res.getBag(); - assertNotNull(bag); - Iterator<AttributeValue<?>> it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - AttributeValue<?> attrValueObject = it.next(); - assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - - // zero args => empty bag - arguments.clear(); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - assertEquals(0, bag.size()); - - - // null argument - arguments.clear(); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:double-bag Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // argument of other type - arguments.clear(); - arguments.add(attrInteger); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:double-bag Expected data type 'double' saw 'integer'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // 2 args (check response is correct) - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(2, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); - assertEquals(s2, attrValueObject.getValue()); - - // duplicate args (verify return) - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - arguments.add(attr1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(3, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); - assertEquals(s2, attrValueObject.getValue()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_DOUBLE.getId(), attrValueObject.getDataTypeId()); - assertEquals(s1, attrValueObject.getValue()); - - // lots of args - arguments.clear(); - for (int i = 0; i < 1000; i++) { - arguments.add(attr1); - } - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1000, bag.size()); - - } - - - - - - // - // - // REST OF DATA TYPES OMITTED - // because they "should" all work the same - // - // - - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBaseTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBaseTest.java deleted file mode 100644 index 64881758e..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionBaseTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.functions; - - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.att.research.xacml.api.Identifier; -import com.att.research.xacml.api.XACML3; -import com.att.research.xacmlatt.pdp.policy.FunctionDefinition; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionBag; - -/** - * Test functions in the abstract FunctionDefinitionSimpleTest class. - * Functions are tested by creating instances of other classes that should have appropriate properties to verify all variations of the responses expected. - * - * Note: we do not test getDataTypeId() because all it does is get the String out of the Identity object and we assume that the Data Type Identity objects - * are tested enough in everything else that any errors in them will be found and fixed quickly. - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * - */ -public class FunctionDefinitionBaseTest { - /** - * getId() is pretty trivial, so verifying one should be enough to check that the mechanism is working ok - */ - @Test - public void testGetId() { - FunctionDefinition fd = StdFunctions.FD_STRING_EQUAL; - Identifier id = fd.getId(); - assertTrue(XACML3.ID_FUNCTION_STRING_EQUAL.stringValue().equals(id.stringValue()) ); - } - - /** - * check an instance of every result type that we can deal with - */ - @Test - public void testGetDataType() { - -//?? Need functions that return each of these data types except for Boolean which is returned by any of the EQUAL functions - FunctionDefinition fdstring = StdFunctions.FD_STRING_NORMALIZE_SPACE; - assertEquals(XACML3.ID_DATATYPE_STRING, fdstring.getDataTypeId()); - - FunctionDefinition fdboolean = StdFunctions.FD_STRING_EQUAL; - assertEquals(XACML3.ID_DATATYPE_BOOLEAN, fdboolean.getDataTypeId()); - - FunctionDefinition fdinteger = StdFunctions.FD_INTEGER_ADD; - assertEquals(XACML3.ID_DATATYPE_INTEGER, fdinteger.getDataTypeId()); - - FunctionDefinition fddouble = StdFunctions.FD_DOUBLE_ADD; - assertEquals(XACML3.ID_DATATYPE_DOUBLE, fddouble.getDataTypeId()); - - FunctionDefinition fddate = StdFunctions.FD_DATE_BAG; - assertEquals(XACML3.ID_DATATYPE_DATE, fddate.getDataTypeId()); - - FunctionDefinition fdtime = StdFunctions.FD_TIME_BAG; - assertEquals(XACML3.ID_DATATYPE_TIME, fdtime.getDataTypeId()); - - FunctionDefinition fddateTime = StdFunctions.FD_DATETIME_BAG; - assertEquals(XACML3.ID_DATATYPE_DATETIME, fddateTime.getDataTypeId()); - - FunctionDefinition fddayTimeDuration = StdFunctions.FD_DAYTIMEDURATION_FROM_STRING; - assertEquals(XACML3.ID_DATATYPE_DAYTIMEDURATION, fddayTimeDuration.getDataTypeId()); - - FunctionDefinition fdyearMonthDuration = StdFunctions.FD_YEARMONTHDURATION_FROM_STRING; - assertEquals(XACML3.ID_DATATYPE_YEARMONTHDURATION, fdyearMonthDuration.getDataTypeId()); - - FunctionDefinition fdanyURI = StdFunctions.FD_ANYURI_FROM_STRING; - assertEquals(XACML3.ID_DATATYPE_ANYURI, fdanyURI.getDataTypeId()); - - FunctionDefinition fdhexBinary = StdFunctions.FD_HEXBINARY_UNION; - assertEquals(XACML3.ID_DATATYPE_HEXBINARY, fdhexBinary.getDataTypeId()); - - FunctionDefinition fdbase64Binary = StdFunctions.FD_BASE64BINARY_UNION; - assertEquals(XACML3.ID_DATATYPE_BASE64BINARY, fdbase64Binary.getDataTypeId()); - - FunctionDefinition fdrfc822Name = StdFunctions.FD_RFC822NAME_FROM_STRING; - assertEquals(XACML3.ID_DATATYPE_RFC822NAME, fdrfc822Name.getDataTypeId()); - - FunctionDefinition fdx500Name = StdFunctions.FD_X500NAME_FROM_STRING; - assertEquals(XACML3.ID_DATATYPE_X500NAME, fdx500Name.getDataTypeId()); - -//TODO - There are currently no functions that return XPathExpression objects -// FunctionDefinition fdxpathExpression = StdFunctions.FD_XPATHEXPRESSION_FROM_STRING; -// assertEquals(XACML3.ID_DATATYPE_XPATHEXPRESSION, fdxpathExpression.getDataTypeId()); - - FunctionDefinition fdipAddress = StdFunctions.FD_IPADDRESS_FROM_STRING; - assertEquals(XACML3.ID_DATATYPE_IPADDRESS, fdipAddress.getDataTypeId()); - - FunctionDefinition fddnsName = StdFunctions.FD_DNSNAME_FROM_STRING; - assertEquals(XACML3.ID_DATATYPE_DNSNAME, fddnsName.getDataTypeId()); - } - - /** - * check the type of return, single vs multiple values - */ - @Test - public void testReturnsBag() { - FunctionDefinition fdNotBag = StdFunctions.FD_BOOLEAN_EQUAL; - assertFalse(fdNotBag.returnsBag()); - - FunctionDefinitionBag<?> fdBag = (FunctionDefinitionBag<?>) StdFunctions.FD_STRING_BAG; - assertTrue(fdBag.returnsBag()); - } - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionComparisonTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionComparisonTest.java deleted file mode 100644 index b5b9c1453..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionComparisonTest.java +++ /dev/null @@ -1,1367 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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.Calendar; -import java.util.Date; -import java.util.List; - -import org.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacml.std.datatypes.ISO8601Date; -import com.att.research.xacml.std.datatypes.ISO8601DateTime; -import com.att.research.xacml.std.datatypes.ISO8601Time; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionComparison; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionTimeInRange; - -/** - * Test FunctionDefinitionComparison - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * - */ -public class FunctionDefinitionComparisonTest { - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - FunctionArgumentAttributeValue stringAttr1 = null; - FunctionArgumentAttributeValue stringAttr1a = null; - FunctionArgumentAttributeValue stringAttr2 = null; - FunctionArgumentAttributeValue stringAttrNeg1 = null; - - - FunctionArgumentAttributeValue intAttr1 = null; - FunctionArgumentAttributeValue intAttr1a = null; - FunctionArgumentAttributeValue intAttr2 = null; - FunctionArgumentAttributeValue intAttr0 = null; - FunctionArgumentAttributeValue intAttrNeg1 = null; - - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr1a = null; - FunctionArgumentAttributeValue attr2 = null; - FunctionArgumentAttributeValue attrNeg1 = null; - - FunctionArgumentAttributeValue attrDateToday = null; - FunctionArgumentAttributeValue attrDateSameDay = null; - FunctionArgumentAttributeValue attrDateTommorrow = null; - FunctionArgumentAttributeValue attrDateYesterday = null; - FunctionArgumentAttributeValue attrDateWithTimeZone = null; - FunctionArgumentAttributeValue attrDateNoTimeZone = null; - - - FunctionArgumentAttributeValue attrTimeToday = null; - FunctionArgumentAttributeValue attrTimeSameDay = null; - FunctionArgumentAttributeValue attrTimeTommorrow = null; - FunctionArgumentAttributeValue attrTimeYesterday = null; - FunctionArgumentAttributeValue attrTimeWithTimeZone = null; - FunctionArgumentAttributeValue attrTimeNoTimeZone = null; - - FunctionArgumentAttributeValue attrDateTimeToday = null; - FunctionArgumentAttributeValue attrDateTimeSameDay = null; - FunctionArgumentAttributeValue attrDateTimeTommorrow = null; - FunctionArgumentAttributeValue attrDateTimeYesterday = null; - FunctionArgumentAttributeValue attrDateTimeWithTimeZone = null; - FunctionArgumentAttributeValue attrDateTimeNoTimeZone = null; - - /** - * Set up some common variables on startup - */ - public FunctionDefinitionComparisonTest() { - try { - stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); - stringAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); - stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def")); - stringAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("AAA")); - - - intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); - intAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); - intAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); - intAttr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); - intAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1)); - - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0)); - attr1a = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.4)); - attrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-1.0)); - - // create dates - Calendar calendar = Calendar.getInstance(); - Date today = calendar.getTime(); - Date longAgo = new Date(1234); - // create a date that is different than "today" but within the same day (i.e. has a different hour) - if (calendar.get(Calendar.HOUR_OF_DAY) > 3) { - calendar.set(Calendar.HOUR_OF_DAY, 3); - } else { - calendar.set(Calendar.HOUR_OF_DAY, 5); - } - Date todayPlus = calendar.getTime(); - calendar.add(Calendar.DATE, 1); - Date tommorrow = calendar.getTime(); - attrDateToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today)); - attrDateSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(todayPlus)); - attrDateTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(tommorrow)); - attrDateYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(longAgo)); - ISO8601Date isoDate = new ISO8601Date(1920, 5, 8); - attrDateNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(isoDate)); - isoDate = new ISO8601Date("GMT+00:02", 1920, 5, 8); - attrDateWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(isoDate)); - - // create Times - ISO8601Time isoTime = new ISO8601Time(14, 43, 12, 145); - attrTimeToday = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); - attrTimeSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); - isoTime = new ISO8601Time(18, 53, 34, 423); - attrTimeTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); - isoTime = new ISO8601Time(7, 34, 6,543); - attrTimeYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); - isoTime = new ISO8601Time(12, 12, 12, 12); - attrTimeNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); - isoTime = new ISO8601Time("GMT:+00:03", 12, 12, 12, 12); - attrTimeWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime)); - - // create DateTimes - isoDate = new ISO8601Date(1920, 5, 8); - isoTime = new ISO8601Time( 18, 53, 34, 423); - ISO8601DateTime isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 18, 53, 34, 423); - attrDateTimeToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); - attrDateTimeSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); - isoTime = new ISO8601Time(20, 53, 34, 423); - isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 20, 53, 34, 423); - attrDateTimeTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); - isoTime = new ISO8601Time(7, 34, 6,543); - isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 7, 34, 6, 543); - attrDateTimeYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); - isoTime = new ISO8601Time(12, 12, 12, 12); - isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 12, 12, 12, 12); - attrDateTimeNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); - isoTime = new ISO8601Time("GMT:+00:03", 12, 12, 12, 12); - isoDate = new ISO8601Date("GMT:+00:03", 1920, 5, 8); - isoDateTime = new ISO8601DateTime("GMT:+00:03", 1920, 5, 8, 12, 12, 12, 12); - attrDateTimeWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime)); - - - - - } catch (Exception e) { - fail("Error creating values e="+ e); - } - } - - /** - * String - */ - @Test - public void testString_GT() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_GREATER_THAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_GREATER_THAN, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(stringAttr1); - arguments.add(stringAttr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // check first < second - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(stringAttr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first > second - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(stringAttrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(intAttr1); - arguments.add(stringAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - } - - @Test - public void testString_GTE() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_GREATER_THAN_OR_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_GREATER_THAN_OR_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(stringAttr1); - arguments.add(stringAttr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check first < second - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(stringAttr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first > second - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(stringAttrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - } - - @Test - public void testString_LT() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_LESS_THAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_LESS_THAN, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(stringAttr1); - arguments.add(stringAttr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // check first < second - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(stringAttr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first > second - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(stringAttrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - } - - @Test - public void testString_LTE() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_LESS_THAN_OR_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_LESS_THAN_OR_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(stringAttr1); - arguments.add(stringAttr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check first < second - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(stringAttr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first > second - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(stringAttrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - } - - - - /** - * Integer - */ - @Test - public void testInteger_GT() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_GREATER_THAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_GREATER_THAN, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(intAttr1); - arguments.add(intAttr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // check first < second - arguments.clear(); - arguments.add(intAttr1); - arguments.add(intAttr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first > second - arguments.clear(); - arguments.add(intAttr1); - arguments.add(intAttrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - } - - @Test - public void testInteger_GTE() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_GREATER_THAN_OR_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_GREATER_THAN_OR_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(intAttr1); - arguments.add(intAttr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check first < second - arguments.clear(); - arguments.add(intAttr1); - arguments.add(intAttr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first > second - arguments.clear(); - arguments.add(intAttr1); - arguments.add(intAttrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - } - - @Test - public void testInteger_LT() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_LESS_THAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_LESS_THAN, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(intAttr1); - arguments.add(intAttr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // check first < second - arguments.clear(); - arguments.add(intAttr1); - arguments.add(intAttr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first > second - arguments.clear(); - arguments.add(intAttr1); - arguments.add(intAttrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - } - - @Test - public void testInteger_LTE() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_LESS_THAN_OR_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_LESS_THAN_OR_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(intAttr1); - arguments.add(intAttr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check first < second - arguments.clear(); - arguments.add(intAttr1); - arguments.add(intAttr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first > second - arguments.clear(); - arguments.add(intAttr1); - arguments.add(intAttrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - } - - - - - /** - * Double - */ - @Test - public void testDouble_GT() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_GREATER_THAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DOUBLE_GREATER_THAN, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attr1); - arguments.add(attr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first < second - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first > second - arguments.clear(); - arguments.add(attr1); - arguments.add(attrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - @Test - public void testDouble_GTE() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_GREATER_THAN_OR_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DOUBLE_GREATER_THAN_OR_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attr1); - arguments.add(attr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first < second - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first > second - arguments.clear(); - arguments.add(attr1); - arguments.add(attrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - } - - @Test - public void testDouble_LT() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_LESS_THAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DOUBLE_LESS_THAN, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attr1); - arguments.add(attr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first < second - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first > second - arguments.clear(); - arguments.add(attr1); - arguments.add(attrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - } - - @Test - public void testDouble_LTE() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_LESS_THAN_OR_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DOUBLE_LESS_THAN_OR_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attr1); - arguments.add(attr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first < second - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first > second - arguments.clear(); - arguments.add(attr1); - arguments.add(attrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - } - - - - /** - * Date - */ - - @Test - public void testDate_GT() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_GREATER_THAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATE_GREATER_THAN, fd.getId()); - assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attrDateToday); - arguments.add(attrDateSameDay); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first < second - arguments.clear(); - arguments.add(attrDateToday); - arguments.add(attrDateTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first > second - arguments.clear(); - arguments.add(attrDateToday); - arguments.add(attrDateYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // test bad args data types? One with TimeZone and one without - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - // test with TimeZone vs without - arguments.clear(); - arguments.add(attrDateWithTimeZone); - arguments.add(attrDateNoTimeZone); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - } - - @Test - public void testDate_GTE() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_GREATER_THAN_OR_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATE_GREATER_THAN_OR_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attrDateToday); - arguments.add(attrDateSameDay); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first < second - arguments.clear(); - arguments.add(attrDateToday); - arguments.add(attrDateTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first > second - arguments.clear(); - arguments.add(attrDateToday); - arguments.add(attrDateYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - } - - @Test - public void testDate_LT() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_LESS_THAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATE_LESS_THAN, fd.getId()); - assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attrDateToday); - arguments.add(attrDateSameDay); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first < second - arguments.clear(); - arguments.add(attrDateToday); - arguments.add(attrDateTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first > second - arguments.clear(); - arguments.add(attrDateToday); - arguments.add(attrDateYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - } - - @Test - public void testDate_LTE() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_LESS_THAN_OR_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATE_LESS_THAN_OR_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attrDateToday); - arguments.add(attrDateSameDay); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first < second - arguments.clear(); - arguments.add(attrDateToday); - arguments.add(attrDateTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first > second - arguments.clear(); - arguments.add(attrDateToday); - arguments.add(attrDateYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - } - - - - - - - - /** - * Time - */ - - @Test - public void testTime_GT() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_GREATER_THAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_TIME_GREATER_THAN, fd.getId()); - assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attrTimeToday); - arguments.add(attrTimeSameDay); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first < second - arguments.clear(); - arguments.add(attrTimeToday); - arguments.add(attrTimeTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first > second - arguments.clear(); - arguments.add(attrTimeToday); - arguments.add(attrTimeYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // test bad args data types? One with TimeZone and one without - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - // test with TimeZone vs without - arguments.clear(); - arguments.add(attrTimeWithTimeZone); - arguments.add(attrTimeNoTimeZone); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:time-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - } - - @Test - public void testTime_GTE() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_GREATER_THAN_OR_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_TIME_GREATER_THAN_OR_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attrTimeToday); - arguments.add(attrTimeSameDay); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first < second - arguments.clear(); - arguments.add(attrTimeToday); - arguments.add(attrTimeTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first > second - arguments.clear(); - arguments.add(attrTimeToday); - arguments.add(attrTimeYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - } - - @Test - public void testTime_LT() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_LESS_THAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_TIME_LESS_THAN, fd.getId()); - assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attrTimeToday); - arguments.add(attrTimeSameDay); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first < second - arguments.clear(); - arguments.add(attrTimeToday); - arguments.add(attrTimeTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first > second - arguments.clear(); - arguments.add(attrTimeToday); - arguments.add(attrTimeYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - } - - @Test - public void testTime_LTE() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_LESS_THAN_OR_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_TIME_LESS_THAN_OR_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attrTimeToday); - arguments.add(attrTimeSameDay); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first < second - arguments.clear(); - arguments.add(attrTimeToday); - arguments.add(attrTimeTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first > second - arguments.clear(); - arguments.add(attrTimeToday); - arguments.add(attrTimeYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - } - - - - - - /** - * Time-in-range - */ - @Test - public void testTime_in_range() { - - FunctionDefinitionTimeInRange<?> fd = (FunctionDefinitionTimeInRange<?>) StdFunctions.FD_TIME_IN_RANGE; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_TIME_IN_RANGE, fd.getId()); - assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(3), fd.getNumArgs()); - - // arg 0 in range of others - arguments.add(attrTimeToday); - arguments.add(attrTimeYesterday); - arguments.add(attrTimeTommorrow); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // below range - arguments.clear(); - arguments.add(attrTimeYesterday); - arguments.add(attrTimeToday); - arguments.add(attrTimeTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // above range - arguments.clear(); - arguments.add(attrTimeTommorrow); - arguments.add(attrTimeYesterday); - arguments.add(attrTimeToday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // range bad - arguments.clear(); - arguments.add(attrTimeToday); - arguments.add(attrTimeTommorrow); - arguments.add(attrTimeYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bad types - arguments.clear(); - arguments.add(attrDateTimeWithTimeZone); - arguments.add(attrDateTimeNoTimeZone); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:time-in-range Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrDateTimeWithTimeZone); - arguments.add(attrDateTimeNoTimeZone); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:time-in-range Expected data type 'time' saw 'dateTime' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - /** - * DateTime - */ - - @Test - public void testDateTime_GT() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_GREATER_THAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATETIME_GREATER_THAN, fd.getId()); - assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attrDateTimeToday); - arguments.add(attrDateTimeSameDay); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first < second - arguments.clear(); - arguments.add(attrDateTimeToday); - arguments.add(attrDateTimeTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first > second - arguments.clear(); - arguments.add(attrDateTimeToday); - arguments.add(attrDateTimeYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // test bad args data types? One with TimeZone and one without - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - // test with TimeZone vs without - arguments.clear(); - arguments.add(attrDateTimeWithTimeZone); - arguments.add(attrDateTimeNoTimeZone); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - } - - @Test - public void testDateTime_GTE() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_GREATER_THAN_OR_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATETIME_GREATER_THAN_OR_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attrDateTimeToday); - arguments.add(attrDateTimeSameDay); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first < second - arguments.clear(); - arguments.add(attrDateTimeToday); - arguments.add(attrDateTimeTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first > second - arguments.clear(); - arguments.add(attrDateTimeToday); - arguments.add(attrDateTimeYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - } - - @Test - public void testDateTime_LT() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_LESS_THAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATETIME_LESS_THAN, fd.getId()); - assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attrDateTimeToday); - arguments.add(attrDateTimeSameDay); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first < second - arguments.clear(); - arguments.add(attrDateTimeToday); - arguments.add(attrDateTimeTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first > second - arguments.clear(); - arguments.add(attrDateTimeToday); - arguments.add(attrDateTimeYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - } - - @Test - public void testDateTime_LTE() { - - FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_LESS_THAN_OR_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATETIME_LESS_THAN_OR_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // first == second - arguments.add(attrDateTimeToday); - arguments.add(attrDateTimeSameDay); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first < second - arguments.clear(); - arguments.add(attrDateTimeToday); - arguments.add(attrDateTimeTommorrow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first > second - arguments.clear(); - arguments.add(attrDateTimeToday); - arguments.add(attrDateTimeYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - } - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionDateTimeArithmeticTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionDateTimeArithmeticTest.java deleted file mode 100644 index e11929e93..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionDateTimeArithmeticTest.java +++ /dev/null @@ -1,1602 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacml.std.datatypes.ISO8601Date; -import com.att.research.xacml.std.datatypes.ISO8601DateTime; -import com.att.research.xacml.std.datatypes.ISO8601Time; -import com.att.research.xacml.std.datatypes.ISO8601TimeZone; -import com.att.research.xacml.std.datatypes.XPathDayTimeDuration; -import com.att.research.xacml.std.datatypes.XPathYearMonthDuration; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionDateTimeArithmetic; - -/** - * 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 FunctionDefinitionDateTimeArithmeticTest { - - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - ExpressionResult res; - - - @Test - public void testDateTime_add_dayTimeDuration() { - // Date objects to be adjusted - ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, - new ISO8601Date(2000, 1, 12), - new ISO8601Time(12, 13, 14, 0)); - ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, - new ISO8601Date(2000, 1, 12), - new ISO8601Time(12, 13, 14, 777)); - ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, - new ISO8601Date(2000, 12, 31), - new ISO8601Time(23, 59, 30, 1)); - ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, - new ISO8601Date(-2000, 1, 12), - new ISO8601Time(12, 13, 14, 0)); - ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); - ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); - ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, - new ISO8601Date(timeZone0, 2000, 1, 12), - new ISO8601Time(timeZone0, 12, 13, 14, 0)); - ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, - new ISO8601Date(timeZone5, 2000, 1, 12), - new ISO8601Time(timeZone5, 12, 13, 14, 0)); - ISO8601DateTime dateTimeIIC102Result = null; - - // Durations - XPathDayTimeDuration duration0 = new XPathDayTimeDuration(1, 0, 0, 0, 0); - XPathDayTimeDuration durationStdExample1 = new XPathDayTimeDuration(1, 5, 7, 10, 3.3); - XPathDayTimeDuration durationNStdExample1 = new XPathDayTimeDuration(-1, 5, 7, 10, 3.3); - XPathDayTimeDuration durationMsecs = new XPathDayTimeDuration(1, 5, 7, 10, 3.223); - XPathDayTimeDuration durationCrossover = new XPathDayTimeDuration(1, 0, 0, 0, 29.999); - - // ARGS declarations - // Dates - FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; - FunctionArgumentAttributeValue attrDateTimeMsecs = null; - FunctionArgumentAttributeValue attrDateTimeCrossover = null; - FunctionArgumentAttributeValue attrDateTimeBC = null; - FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; - FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; - FunctionArgumentAttributeValue attrDateTimeIIC102 = null; - - // Durations - FunctionArgumentAttributeValue attrDuration0 = null; - FunctionArgumentAttributeValue attrDurationStdExample1 = null; - FunctionArgumentAttributeValue attrDurationNStdExample1 = null; - FunctionArgumentAttributeValue attrDurationMsecs = null; - FunctionArgumentAttributeValue attrDurationCrossover = null; - FunctionArgumentAttributeValue attrDurationIIC102 = null; - - // misc bad - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlank = null; - FunctionArgumentAttributeValue attrInteger = null; - // set values - try { - // Date attrs - attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); - attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); - attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); - attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); - attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); - attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); - attrDateTimeIIC102 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(DataTypes.DT_DATETIME.convert("2002-03-22T08:23:47-05:00"))); - - dateTimeIIC102Result = DataTypes.DT_DATETIME.convert("2002-03-27T10:23:47-05:00"); - - // Duration attrs - attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(duration0)); - attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationStdExample1)); - attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationNStdExample1)); - attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationMsecs)); - attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationCrossover)); - attrDurationIIC102 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue("P5DT2H0M0S")); - - // misc bad - attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionDateTimeArithmetic<?,?> fd = (FunctionDefinitionDateTimeArithmetic<?,?>) StdFunctions.FD_DATETIME_ADD_DAYTIMEDURATION; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATETIME_ADD_DAYTIMEDURATION, fd.getId()); - assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // Duration = 0 => same as original - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDuration0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); - assertEquals(dateTimeStdExample1, resValue); - - - // simple positive operation - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - ISO8601DateTime testResponse = new ISO8601DateTime( - null, - new ISO8601Date(2000, 1, 17), - new ISO8601Time(19, 23, 17, 300) ); - assertEquals(testResponse, resValue); - - // negative operation - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDurationNStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(2000, 1, 7), - new ISO8601Time(5, 3, 10, 700) ); - assertEquals(testResponse, resValue); - - // millisecs work correctly - arguments.clear(); - arguments.add(attrDateTimeMsecs); - arguments.add(attrDurationMsecs); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(2000, 1, 17), - new ISO8601Time(19, 23, 18, 0) ); - assertEquals(testResponse, resValue); - - // cross minute => cross day => cross month => cross year - arguments.clear(); - arguments.add(attrDateTimeCrossover); - arguments.add(attrDurationCrossover); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(2001, 1, 1), - new ISO8601Time(0, 0, 0, 0) ); - assertEquals(testResponse, resValue); - - // negative (BC) original date add goes the right direction - arguments.clear(); - arguments.add(attrDateTimeBC); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(-2000, 1, 17), - new ISO8601Time(19, 23, 17, 300) ); - assertEquals(testResponse, resValue); - - // non-null timezone not changed - // original has timezone offset = 0 - arguments.clear(); - arguments.add(attrDateTimeTimeZone0); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - timeZone0, - new ISO8601Date(timeZone0, 2000, 1, 17), - new ISO8601Time(timeZone0, 19, 23, 17, 300) ); - assertEquals(testResponse, resValue); - - // original has timezone offset not 0 - arguments.clear(); - arguments.add(attrDateTimeTimeZone5); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - timeZone5, - new ISO8601Date(timeZone5, 2000, 1, 17), - new ISO8601Time(timeZone5, 19, 23, 17, 300) ); - assertEquals(testResponse, resValue); - - // conformance test IIC102 - arguments.clear(); - arguments.add(attrDateTimeIIC102); - arguments.add(attrDurationIIC102); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - assertEquals(dateTimeIIC102Result, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // two blanks - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-dayTimeDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - @Test - public void testDateTime_subtract_dayTimeDuration() { - // Date objects to be adjusted - ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, - new ISO8601Date(2000, 1, 12), - new ISO8601Time(12, 13, 14, 0)); - ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, - new ISO8601Date(2000, 1, 12), - new ISO8601Time(12, 13, 14, 777)); - ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, - new ISO8601Date(2001, 1, 1), - new ISO8601Time(0, 0, 0, 0) ); - ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, - new ISO8601Date(-2000, 1, 12), - new ISO8601Time(12, 13, 14, 0)); - ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); - ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); - ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, - new ISO8601Date(timeZone0, 2000, 1, 12), - new ISO8601Time(timeZone0, 12, 13, 14, 0)); - ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, - new ISO8601Date(timeZone5, 2000, 1, 12), - new ISO8601Time(timeZone5, 12, 13, 14, 0)); - - // Durations - XPathDayTimeDuration duration0 = new XPathDayTimeDuration(1, 0, 0, 0, 0); - XPathDayTimeDuration durationStdExample1 = new XPathDayTimeDuration(1, 5, 7, 10, 3.3); - XPathDayTimeDuration durationNStdExample1 = new XPathDayTimeDuration(-1, 5, 7, 10, 3.3); - XPathDayTimeDuration durationMsecs = new XPathDayTimeDuration(1, 5, 7, 10, 14.778); - XPathDayTimeDuration durationCrossover = new XPathDayTimeDuration(1, 0, 0, 0, 29.999); - - // ARGS declarations - // Dates - FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; - FunctionArgumentAttributeValue attrDateTimeMsecs = null; - FunctionArgumentAttributeValue attrDateTimeCrossover = null; - FunctionArgumentAttributeValue attrDateTimeBC = null; - FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; - FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; - - // Durations - FunctionArgumentAttributeValue attrDuration0 = null; - FunctionArgumentAttributeValue attrDurationStdExample1 = null; - FunctionArgumentAttributeValue attrDurationNStdExample1 = null; - FunctionArgumentAttributeValue attrDurationMsecs = null; - FunctionArgumentAttributeValue attrDurationCrossover = null; - - // misc bad - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlank = null; - FunctionArgumentAttributeValue attrInteger = null; - // set values - try { - // Date attrs - attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); - attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); - attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); - attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); - attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); - attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); - - // Duration attrs - attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(duration0)); - attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationStdExample1)); - attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationNStdExample1)); - attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationMsecs)); - attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(durationCrossover)); - - // misc bad - attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionDateTimeArithmetic<?,?> fd = (FunctionDefinitionDateTimeArithmetic<?,?>) StdFunctions.FD_DATETIME_SUBTRACT_DAYTIMEDURATION; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATETIME_SUBTRACT_DAYTIMEDURATION, fd.getId()); - assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // Duration = 0 => same as original - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDuration0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); - assertEquals(dateTimeStdExample1, resValue); - - - // simple positive operation - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - ISO8601DateTime testResponse = new ISO8601DateTime( - null, - new ISO8601Date(2000, 1, 7), - new ISO8601Time(5, 3, 10, 700) ); - assertEquals(testResponse, resValue); - - - // negative operation - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDurationNStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(2000, 1, 17), - new ISO8601Time(19, 23, 17, 300) ); - assertEquals(testResponse, resValue); - - // millisecs work correctly - arguments.clear(); - arguments.add(attrDateTimeMsecs); - arguments.add(attrDurationMsecs); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(2000, 1, 7), - new ISO8601Time(5, 2, 59, 999) ); - assertEquals(testResponse, resValue); - - // cross minute => cross day => cross month => cross year - arguments.clear(); - arguments.add(attrDateTimeCrossover); - arguments.add(attrDurationCrossover); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(2000, 12, 31), - new ISO8601Time(23, 59, 30, 1)); - assertEquals(testResponse, resValue); - - // negative (BC) original date add goes the right direction - arguments.clear(); - arguments.add(attrDateTimeBC); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(-2000, 1, 7), - new ISO8601Time(5, 3, 10, 700) ); - assertEquals(testResponse, resValue); - - // non-null timezone not changed - // original has timezone offset = 0 - arguments.clear(); - arguments.add(attrDateTimeTimeZone0); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - timeZone0, - new ISO8601Date(timeZone0, 2000, 1, 7), - new ISO8601Time(timeZone0, 5, 3, 10, 700) ); - assertEquals(testResponse, resValue); - - // original has timezone offset not 0 - arguments.clear(); - arguments.add(attrDateTimeTimeZone5); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - timeZone5, - new ISO8601Date(timeZone5, 2000, 1, 7), - new ISO8601Time(timeZone5, 5, 3, 10, 700) ); - assertEquals(testResponse, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // two blanks - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-dayTimeDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-dayTimeDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - - - - - - @Test - public void testDateTime_add_yearMonthDuration() { - // Date objects to be adjusted - ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, - new ISO8601Date(2000, 1, 12), - new ISO8601Time(12, 13, 14, 0)); - ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, - new ISO8601Date(2000, 1, 12), - new ISO8601Time(12, 13, 14, 777)); - ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, - new ISO8601Date(2000, 12, 31), - new ISO8601Time(23, 59, 30, 1)); - ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, - new ISO8601Date(-2000, 1, 12), - new ISO8601Time(12, 13, 14, 0)); - ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); - ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); - ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, - new ISO8601Date(timeZone0, 2000, 1, 12), - new ISO8601Time(timeZone0, 12, 13, 14, 0)); - ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, - new ISO8601Date(timeZone5, 2000, 1, 12), - new ISO8601Time(timeZone5, 12, 13, 14, 0)); - - // Durations - XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); - XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); - XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); - XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); - XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); - - // ARGS declarations - // Dates - FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; - FunctionArgumentAttributeValue attrDateTimeMsecs = null; - FunctionArgumentAttributeValue attrDateTimeCrossover = null; - FunctionArgumentAttributeValue attrDateTimeBC = null; - FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; - FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; - - // Durations - FunctionArgumentAttributeValue attrDuration0 = null; - FunctionArgumentAttributeValue attrDurationStdExample1 = null; - FunctionArgumentAttributeValue attrDurationNStdExample1 = null; - FunctionArgumentAttributeValue attrDurationMsecs = null; - FunctionArgumentAttributeValue attrDurationCrossover = null; - - // misc bad - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlank = null; - FunctionArgumentAttributeValue attrInteger = null; - // set values - try { - // Date attrs - attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); - attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); - attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); - attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); - attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); - attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); - - // Duration attrs - attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); - attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); - attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); - attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); - attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); - - // misc bad - attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionDateTimeArithmetic<?,?> fd = (FunctionDefinitionDateTimeArithmetic<?,?>) StdFunctions.FD_DATETIME_ADD_YEARMONTHDURATION; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATETIME_ADD_YEARMONTHDURATION, fd.getId()); - assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // Duration = 0 => same as original - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDuration0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); - assertEquals(dateTimeStdExample1, resValue); - - - // simple positive operation - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - ISO8601DateTime testResponse = new ISO8601DateTime( - null, - new ISO8601Date(2005, 8, 12), - new ISO8601Time(12, 13, 14, 0) ); - assertEquals(testResponse, resValue); - - // negative operation - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDurationNStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(1994, 6, 12), - new ISO8601Time(12, 13, 14, 0) ); - assertEquals(testResponse, resValue); - - // millisecs work correctly (not relevant to YearMonth, but should not break - arguments.clear(); - arguments.add(attrDateTimeMsecs); - arguments.add(attrDurationMsecs); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(2005, 8, 12), - new ISO8601Time(12, 13, 14, 777) ); - assertEquals(testResponse, resValue); - - // cross minute => cross day => cross month => cross year - arguments.clear(); - arguments.add(attrDateTimeCrossover); - arguments.add(attrDurationCrossover); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(2001, 1, 31), - new ISO8601Time(23, 59, 30, 1) ); - assertEquals(testResponse, resValue); - - // negative (BC) original date add goes the right direction - arguments.clear(); - arguments.add(attrDateTimeBC); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(-1995, 8, 12), - new ISO8601Time(12, 13, 14, 0) ); - assertEquals(testResponse, resValue); - - // non-null timezone not changed - // original has timezone offset = 0 - arguments.clear(); - arguments.add(attrDateTimeTimeZone0); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - timeZone0, - new ISO8601Date(timeZone0, 2005, 8, 12), - new ISO8601Time(timeZone0, 12, 13, 14, 0) ); - assertEquals(testResponse, resValue); - - // original has timezone offset not 0 - arguments.clear(); - arguments.add(attrDateTimeTimeZone5); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - timeZone5, - new ISO8601Date(timeZone5, 2005, 8, 12), - new ISO8601Time(timeZone5, 12, 13, 14, 0) ); - assertEquals(testResponse, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // two blanks - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-yearMonthDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - @Test - public void testDateTime_subtract_yearMonthDuration() { - // Date objects to be adjusted - ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, - new ISO8601Date(2000, 1, 12), - new ISO8601Time(12, 13, 14, 0)); - ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, - new ISO8601Date(2000, 1, 12), - new ISO8601Time(12, 13, 14, 777)); - ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, - new ISO8601Date(2000, 1, 1), - new ISO8601Time(23, 59, 30, 1)); - ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, - new ISO8601Date(-2000, 1, 12), - new ISO8601Time(12, 13, 14, 0)); - ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); - ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); - ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, - new ISO8601Date(timeZone0, 2000, 1, 12), - new ISO8601Time(timeZone0, 12, 13, 14, 0)); - ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, - new ISO8601Date(timeZone5, 2000, 1, 12), - new ISO8601Time(timeZone5, 12, 13, 14, 0)); - - // Durations - XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); - XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); - XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); - XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); - XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); - - // ARGS declarations - // Dates - FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; - FunctionArgumentAttributeValue attrDateTimeMsecs = null; - FunctionArgumentAttributeValue attrDateTimeCrossover = null; - FunctionArgumentAttributeValue attrDateTimeBC = null; - FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; - FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; - - // Durations - FunctionArgumentAttributeValue attrDuration0 = null; - FunctionArgumentAttributeValue attrDurationStdExample1 = null; - FunctionArgumentAttributeValue attrDurationNStdExample1 = null; - FunctionArgumentAttributeValue attrDurationMsecs = null; - FunctionArgumentAttributeValue attrDurationCrossover = null; - - // misc bad - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlank = null; - FunctionArgumentAttributeValue attrInteger = null; - // set values - try { - // Date attrs - attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); - attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); - attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); - attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); - attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); - attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); - - // Duration attrs - attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); - attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); - attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); - attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); - attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); - - // misc bad - attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionDateTimeArithmetic<?,?> fd = (FunctionDefinitionDateTimeArithmetic<?,?>) StdFunctions.FD_DATETIME_SUBTRACT_YEARMONTHDURATION; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATETIME_SUBTRACT_YEARMONTHDURATION, fd.getId()); - assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // Duration = 0 => same as original - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDuration0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); - assertEquals(dateTimeStdExample1, resValue); - - - // simple positive operation - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - ISO8601DateTime testResponse = new ISO8601DateTime( - null, - new ISO8601Date(1994, 6, 12), - new ISO8601Time(12, 13, 14, 0) ); - assertEquals(testResponse, resValue); - - // negative operation - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDurationNStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(2005, 8, 12), - new ISO8601Time(12, 13, 14, 0) ); - assertEquals(testResponse, resValue); - - // millisecs work correctly (not relevant to YearMonth, but should not break - arguments.clear(); - arguments.add(attrDateTimeMsecs); - arguments.add(attrDurationMsecs); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(1994, 6, 12), - new ISO8601Time(12, 13, 14, 777) ); - assertEquals(testResponse, resValue); - - // cross minute => cross day => cross month => cross year - arguments.clear(); - arguments.add(attrDateTimeCrossover); - arguments.add(attrDurationCrossover); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(1999, 12, 1), - new ISO8601Time(23, 59, 30, 1) ); - assertEquals(testResponse, resValue); - - // negative (BC) original date add goes the right direction - arguments.clear(); - arguments.add(attrDateTimeBC); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - null, - new ISO8601Date(-2006, 6, 12), - new ISO8601Time(12, 13, 14, 0) ); - assertEquals(testResponse, resValue); - - // non-null timezone not changed - // original has timezone offset = 0 - arguments.clear(); - arguments.add(attrDateTimeTimeZone0); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - timeZone0, - new ISO8601Date(timeZone0, 1994, 6, 12), - new ISO8601Time(timeZone0, 12, 13, 14, 0) ); - assertEquals(testResponse, resValue); - - // original has timezone offset not 0 - arguments.clear(); - arguments.add(attrDateTimeTimeZone5); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - testResponse = new ISO8601DateTime( - timeZone5, - new ISO8601Date(timeZone5, 1994, 6, 12), - new ISO8601Time(timeZone5, 12, 13, 14, 0) ); - assertEquals(testResponse, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // two blanks - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-yearMonthDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - - - - - - - - @Test - public void testDate_add_yearMonthDuration() { - // Date objects to be adjusted - ISO8601Date dateTimeStdExample1 = new ISO8601Date(2000, 1, 12); - ISO8601Date dateTimeMsecs =new ISO8601Date(2000, 1, 12); - ISO8601Date dateTimeCrossover = new ISO8601Date(2000, 12, 31); - ISO8601Date dateTimeBC = new ISO8601Date(-2000, 1, 12); - ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); - ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); - ISO8601Date dateTimeTimeZone0 = new ISO8601Date(timeZone0, 2000, 1, 12); - ISO8601Date dateTimeTimeZone5 = new ISO8601Date(timeZone5, 2000, 1, 12); - - // Durations - XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); - XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); - XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); - XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); - XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); - - // ARGS declarations - // Dates - FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; - FunctionArgumentAttributeValue attrDateTimeMsecs = null; - FunctionArgumentAttributeValue attrDateTimeCrossover = null; - FunctionArgumentAttributeValue attrDateTimeBC = null; - FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; - FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; - - // Durations - FunctionArgumentAttributeValue attrDuration0 = null; - FunctionArgumentAttributeValue attrDurationStdExample1 = null; - FunctionArgumentAttributeValue attrDurationNStdExample1 = null; - FunctionArgumentAttributeValue attrDurationMsecs = null; - FunctionArgumentAttributeValue attrDurationCrossover = null; - - // misc bad - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlank = null; - FunctionArgumentAttributeValue attrInteger = null; - // set values - try { - // Date attrs - attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeStdExample1)); - attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeMsecs)); - attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeCrossover)); - attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeBC)); - attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeTimeZone0)); - attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeTimeZone5)); - - // Duration attrs - attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); - attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); - attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); - attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); - attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); - - // misc bad - attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionDateTimeArithmetic<?,?> fd = (FunctionDefinitionDateTimeArithmetic<?,?>) StdFunctions.FD_DATE_ADD_YEARMONTHDURATION; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATE_ADD_YEARMONTHDURATION, fd.getId()); - assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // Duration = 0 => same as original - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDuration0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - ISO8601Date resValue = (ISO8601Date)res.getValue().getValue(); - assertEquals(dateTimeStdExample1, resValue); - - - // simple positive operation - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - ISO8601Date testResponse = new ISO8601Date(2005, 8, 12); - assertEquals(testResponse, resValue); - - // negative operation - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDurationNStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - testResponse = new ISO8601Date(1994, 6, 12); - assertEquals(testResponse, resValue); - - // millisecs work correctly (not relevant to YearMonth, but should not break - arguments.clear(); - arguments.add(attrDateTimeMsecs); - arguments.add(attrDurationMsecs); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - testResponse = new ISO8601Date(2005, 8, 12); - assertEquals(testResponse, resValue); - - // cross minute => cross day => cross month => cross year - arguments.clear(); - arguments.add(attrDateTimeCrossover); - arguments.add(attrDurationCrossover); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - testResponse = new ISO8601Date(2001, 1, 31); - assertEquals(testResponse, resValue); - - // negative (BC) original date add goes the right direction - arguments.clear(); - arguments.add(attrDateTimeBC); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - testResponse = new ISO8601Date(-1995, 8, 12); - assertEquals(testResponse, resValue); - - // non-null timezone not changed - // original has timezone offset = 0 - arguments.clear(); - arguments.add(attrDateTimeTimeZone0); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - testResponse = new ISO8601Date(timeZone0, 2005, 8, 12); - assertEquals(testResponse, resValue); - - // original has timezone offset not 0 - arguments.clear(); - arguments.add(attrDateTimeTimeZone5); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - testResponse = new ISO8601Date(timeZone5, 2005, 8, 12); - assertEquals(testResponse, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // two blanks - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-add-yearMonthDuration Expected data type 'date' saw 'integer'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-add-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - - - @Test - public void testDate_subtract_yearMonthDuration() { - // Date objects to be adjusted - ISO8601Date dateTimeStdExample1 =new ISO8601Date(2000, 1, 12); - ISO8601Date dateTimeMsecs = new ISO8601Date(2000, 1, 12); - ISO8601Date dateTimeCrossover = new ISO8601Date(2000, 1, 1); - ISO8601Date dateTimeBC = new ISO8601Date(-2000, 1, 12); - ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); - ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); - ISO8601Date dateTimeTimeZone0 = new ISO8601Date(timeZone0, 2000, 1, 12); - ISO8601Date dateTimeTimeZone5 = new ISO8601Date(timeZone5, 2000, 1, 12); - - // Durations - XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); - XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); - XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); - XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); - XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); - - // ARGS declarations - // Dates - FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; - FunctionArgumentAttributeValue attrDateTimeMsecs = null; - FunctionArgumentAttributeValue attrDateTimeCrossover = null; - FunctionArgumentAttributeValue attrDateTimeBC = null; - FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; - FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; - - // Durations - FunctionArgumentAttributeValue attrDuration0 = null; - FunctionArgumentAttributeValue attrDurationStdExample1 = null; - FunctionArgumentAttributeValue attrDurationNStdExample1 = null; - FunctionArgumentAttributeValue attrDurationMsecs = null; - FunctionArgumentAttributeValue attrDurationCrossover = null; - - // misc bad - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlank = null; - FunctionArgumentAttributeValue attrInteger = null; - // set values - try { - // Date attrs - attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeStdExample1)); - attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeMsecs)); - attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeCrossover)); - attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeBC)); - attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeTimeZone0)); - attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(dateTimeTimeZone5)); - - // Duration attrs - attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); - attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); - attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); - attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); - attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); - - // misc bad - attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionDateTimeArithmetic<?,?> fd = (FunctionDefinitionDateTimeArithmetic<?,?>) StdFunctions.FD_DATE_SUBTRACT_YEARMONTHDURATION; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATE_SUBTRACT_YEARMONTHDURATION, fd.getId()); - assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // Duration = 0 => same as original - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDuration0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - ISO8601Date resValue = (ISO8601Date)res.getValue().getValue(); - assertEquals(dateTimeStdExample1, resValue); - - - // simple positive operation - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - ISO8601Date testResponse = new ISO8601Date(1994, 6, 12); - assertEquals(testResponse, resValue); - - // negative operation - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrDurationNStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - testResponse = new ISO8601Date(2005, 8, 12); - assertEquals(testResponse, resValue); - - // millisecs work correctly (not relevant to YearMonth, but should not break - arguments.clear(); - arguments.add(attrDateTimeMsecs); - arguments.add(attrDurationMsecs); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - testResponse = new ISO8601Date(1994, 6, 12); - assertEquals(testResponse, resValue); - - // cross minute => cross day => cross month => cross year - arguments.clear(); - arguments.add(attrDateTimeCrossover); - arguments.add(attrDurationCrossover); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - testResponse = new ISO8601Date(1999, 12, 1); - assertEquals(testResponse, resValue); - - // negative (BC) original date add goes the right direction - arguments.clear(); - arguments.add(attrDateTimeBC); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - testResponse = new ISO8601Date(-2006, 6, 12); - assertEquals(testResponse, resValue); - - // non-null timezone not changed - // original has timezone offset = 0 - arguments.clear(); - arguments.add(attrDateTimeTimeZone0); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - testResponse = new ISO8601Date(timeZone0, 1994, 6, 12); - assertEquals(testResponse, resValue); - - // original has timezone offset not 0 - arguments.clear(); - arguments.add(attrDateTimeTimeZone5); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(com.att.research.xacml.std.datatypes.ISO8601Date.class, res.getValue().getValue().getClass()); - resValue = (ISO8601Date)res.getValue().getValue(); - testResponse = new ISO8601Date(timeZone5, 1994, 6, 12); - assertEquals(testResponse, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // two blanks - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrDurationStdExample1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-subtract-yearMonthDuration Expected data type 'date' saw 'integer'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrDateTimeStdExample1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionEqualityTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionEqualityTest.java deleted file mode 100644 index 52f065ff8..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionEqualityTest.java +++ /dev/null @@ -1,1192 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.functions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -import javax.security.auth.x500.X500Principal; - -import org.junit.Test; - -import com.att.research.xacml.api.XACML1; -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.Base64Binary; -import com.att.research.xacml.std.datatypes.DataTypeRFC822Name; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacml.std.datatypes.HexBinary; -import com.att.research.xacml.std.datatypes.RFC822Name; -import com.att.research.xacml.std.datatypes.XPathDayTimeDuration; -import com.att.research.xacml.std.datatypes.XPathYearMonthDuration; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionEquality; - -/** - * Test FunctionDefinitionEquality, all of its super-classes, and all XACML functions supported by that class. - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * In the first implementation of XACML we had separate files for each XACML Function. - * This release combines multiple Functions in fewer files to minimize code duplication. - * This file supports the following XACML codes: - * string-equal - * boolean-equal - * integer-equal - * double-equal - * date-equal - * time-equal - * dateTime-equal - * dayTimeDuration-equal - * yearMonthDuration-equal - * - * Each of these is put into a separate test method just to keep things organized. - * - * - */ -public class FunctionDefinitionEqualityTest { - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - FunctionArgumentAttributeValue stringAttr1 = null; - FunctionArgumentAttributeValue stringAttr2 = null; - FunctionArgumentAttributeValue stringAttr3 = null; - FunctionArgumentAttributeValue stringAttr4 = null; - - FunctionArgumentAttributeValue booleanAttrT1 = null; - FunctionArgumentAttributeValue booleanAttrT2 = null; - FunctionArgumentAttributeValue booleanAttrF1 = null; - FunctionArgumentAttributeValue booleanAttrF2 = null; - - FunctionArgumentAttributeValue intAttr1 = null; - FunctionArgumentAttributeValue intAttr1a = null; - FunctionArgumentAttributeValue intAttr2 = null; - FunctionArgumentAttributeValue intAttr0 = null; - FunctionArgumentAttributeValue intAttrNeg1 = null; - - public FunctionDefinitionEqualityTest() { - try { - stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); - stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); - stringAttr3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ABC")); - stringAttr4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def")); - - booleanAttrT1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(true)); - booleanAttrT2 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(true)); - booleanAttrF1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - booleanAttrF2 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - - intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); - intAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); - intAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); - intAttr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); - intAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - } - - - - - /** - * String (matching case) - */ - @Test - public void testString_Equal() { - - // String exact match - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_STRING_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check "abc" with "abc" - separate string objects with same value - arguments.add(stringAttr1); - arguments.add(stringAttr2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check "abc" with "ABC" (not same) - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(stringAttr3); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - - /** - * Boolean - */ - @Test - public void testBoolean_Equal() { - - // String exact match - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_BOOLEAN_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_BOOLEAN_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with same value - arguments.add(booleanAttrT1); - arguments.add(booleanAttrT2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check different values - arguments.clear(); - arguments.add(booleanAttrT1); - arguments.add(booleanAttrF1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - /** - * Integer - */ - @Test - public void testInteger_Equal() { - - // String exact match - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_INTEGER_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with same value - arguments.add(intAttr1); - arguments.add(intAttr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(intAttr1); - arguments.add(intAttr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - arguments.clear(); - arguments.add(intAttr1); - arguments.add(intAttrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - - /** - * Double - */ - @Test - public void testDouble_Equal() { - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr1a = null; - FunctionArgumentAttributeValue attr2 = null; - FunctionArgumentAttributeValue attrNeg1 = null; - try { - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0)); - attr1a = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.4)); - attrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-1.0)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - // String exact match - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_DOUBLE_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DOUBLE_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attr1); - arguments.add(attr1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(attr1); - arguments.add(attr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - arguments.clear(); - arguments.add(attr1); - arguments.add(attrNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - - - - /** - * Date - */ - @Test - public void testDate_Equal() { - Calendar calendar = Calendar.getInstance(); - Date today = calendar.getTime(); - Date longAgo = new Date(1234); - // create a date that is different than "today" but within the same day (i.e. has a different hour) - if (calendar.get(Calendar.HOUR_OF_DAY) > 3) { - calendar.set(Calendar.HOUR_OF_DAY, 3); - } else { - calendar.set(Calendar.HOUR_OF_DAY, 5); - } - Date todayPlus = calendar.getTime(); - - - FunctionArgumentAttributeValue attrToday = null; - FunctionArgumentAttributeValue attrToday2 = null; - FunctionArgumentAttributeValue attrLaterToday = null; - FunctionArgumentAttributeValue attrYesterday = null; - try { - attrToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today)); - attrToday2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today)); - attrLaterToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(todayPlus)); - attrYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(longAgo)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - // String exact match - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_DATE_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATE_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attrToday); - arguments.add(attrToday2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(attrToday); - arguments.add(attrYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // Date objects with different times but within the same day should match - arguments.clear(); - arguments.add(attrToday); - arguments.add(attrLaterToday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - - - /** - * Time - */ - @Test - public void testTime_Equal() { - - Date now = new Date(); - Date now2 = new Date(now.getTime()); - Date notNow = new Date(now.getTime() - 100000); - - FunctionArgumentAttributeValue attrNow = null; - FunctionArgumentAttributeValue attrNow2 = null; - FunctionArgumentAttributeValue attrNotNow = null; - try { - attrNow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(now)); - attrNow2 = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(now2)); - attrNotNow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(notNow)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - // String exact match - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_TIME_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_TIME_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attrNow); - arguments.add(attrNow2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(attrNow); - arguments.add(attrNotNow); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - - - /** - * DateTime - */ - @Test - public void testDateTime_Equal() { - Calendar calendar = Calendar.getInstance(); - Date today = calendar.getTime(); - Date longAgo = new Date(1234); - // create a dateTime that is different than "today" changing only the Timezone - if (calendar.get(Calendar.ZONE_OFFSET) > 3) { - calendar.set(Calendar.ZONE_OFFSET, 3); - } else { - calendar.set(Calendar.ZONE_OFFSET, 5); - } - Date todayPlus = calendar.getTime(); - - - FunctionArgumentAttributeValue attrToday = null; - FunctionArgumentAttributeValue attrToday2 = null; - FunctionArgumentAttributeValue attrLaterToday = null; - FunctionArgumentAttributeValue attrYesterday = null; - try { - attrToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(today)); - attrToday2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(today)); - attrLaterToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(todayPlus)); - attrYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(longAgo)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - // String exact match - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_DATETIME_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATETIME_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attrToday); - arguments.add(attrToday2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(attrToday); - arguments.add(attrYesterday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // DateTime with different Zones should not match - arguments.clear(); - arguments.add(attrToday); - arguments.add(attrLaterToday); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - /** - * dayTimeDuration - Version1 - */ - @Test - public void testDayTimeDuration_Equal_V1() { - - XPathDayTimeDuration dur1 = new XPathDayTimeDuration(1, 3, 5, 12, 38); - XPathDayTimeDuration dur2 = new XPathDayTimeDuration(1, 3, 5, 12, 38); - XPathDayTimeDuration differentDur = new XPathDayTimeDuration(-1, 4, 7, 5, 33); - - FunctionArgumentAttributeValue attrDur1 = null; - FunctionArgumentAttributeValue attrDur2 = null; - FunctionArgumentAttributeValue attrDifferentDur = null; - try { - attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur1)); - attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur2)); - attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(differentDur)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_DAYTIMEDURATION_EQUAL_VERSION1; - - // check identity and type of the thing created - assertEquals(XACML1.ID_FUNCTION_DAYTIMEDURATION_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attrDur1); - arguments.add(attrDur2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(attrDur1); - arguments.add(attrDifferentDur); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - /** - * dayTimeDuration - Current version - */ - @Test - public void testDayTimeDuration_Equal() { - - XPathDayTimeDuration dur1 = new XPathDayTimeDuration(1, 3, 5, 12, 38); - XPathDayTimeDuration dur2 = new XPathDayTimeDuration(1, 3, 5, 12, 38); - XPathDayTimeDuration differentDur = new XPathDayTimeDuration(-1, 4, 7, 5, 33); - - FunctionArgumentAttributeValue attrDur1 = null; - FunctionArgumentAttributeValue attrDur2 = null; - FunctionArgumentAttributeValue attrDifferentDur = null; - try { - attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur1)); - attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur2)); - attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(differentDur)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_DAYTIMEDURATION_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DAYTIMEDURATION_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attrDur1); - arguments.add(attrDur2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(attrDur1); - arguments.add(attrDifferentDur); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - - /** - * dayTimeDuration - Version1 - */ - @Test - public void testYearMonthDuration_Equal_V1() { - - XPathYearMonthDuration dur1 = new XPathYearMonthDuration(1, 3, 5); - XPathYearMonthDuration dur2 = new XPathYearMonthDuration(1, 3, 5); - XPathYearMonthDuration differentDur = new XPathYearMonthDuration(-1, 4, 7); - - FunctionArgumentAttributeValue attrDur1 = null; - FunctionArgumentAttributeValue attrDur2 = null; - FunctionArgumentAttributeValue attrDifferentDur = null; - try { - attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur1)); - attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur2)); - attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(differentDur)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_YEARMONTHDURATION_EQUAL_VERSION1; - - // check identity and type of the thing created - assertEquals(XACML1.ID_FUNCTION_YEARMONTHDURATION_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attrDur1); - arguments.add(attrDur2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(attrDur1); - arguments.add(attrDifferentDur); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - - - /** - * dayTimeDuration - Current version - */ - @Test - public void testYearMonthDuration_Equal() { - - XPathYearMonthDuration dur1 = new XPathYearMonthDuration(1, 3, 5); - XPathYearMonthDuration dur2 = new XPathYearMonthDuration(1, 3, 5); - XPathYearMonthDuration differentDur = new XPathYearMonthDuration(-1, 4, 7); - - FunctionArgumentAttributeValue attrDur1 = null; - FunctionArgumentAttributeValue attrDur2 = null; - FunctionArgumentAttributeValue attrDifferentDur = null; - try { - attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur1)); - attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur2)); - attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(differentDur)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_YEARMONTHDURATION_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_YEARMONTHDURATION_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attrDur1); - arguments.add(attrDur2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(attrDur1); - arguments.add(attrDifferentDur); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - /** - * URI - */ - @Test - public void testAnyURI_Equal() { - - URI uri1 = null; - URI uri2 = null; - URI uriNotThere = null; - try { - uri1 = new URI("http://someplace.com/gothere"); - uri2 = new URI("http://someplace.com/gothere"); - uriNotThere = new URI("http://someplace.com/notGoingThere"); - } catch (Exception e) { - fail(e.toString()); - } - - FunctionArgumentAttributeValue attrUri1 = null; - FunctionArgumentAttributeValue attrUri2 = null; - FunctionArgumentAttributeValue attrUriNotThere = null; - try { - attrUri1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri1)); - attrUri2 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri2)); - attrUriNotThere = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uriNotThere)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_ANYURI_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ANYURI_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attrUri1); - arguments.add(attrUri2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(attrUri1); - arguments.add(attrUriNotThere); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - /** - * X500Name - */ - @Test - public void testX500Name_Equal() { - - X500Principal name1 = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"); - X500Principal name2 = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"); - X500Principal name3 = new X500Principal("CN=NotDuke, OU=NotThere, O=Oracle, C=US"); - - - FunctionArgumentAttributeValue attrName1 = null; - FunctionArgumentAttributeValue attrName1a = null; - FunctionArgumentAttributeValue attrNotSameName = null; - try { - attrName1 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(name1)); - attrName1a = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(name2)); - attrNotSameName = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(name3)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_X500NAME_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_X500NAME_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_X500NAME.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attrName1); - arguments.add(attrName1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(attrName1); - arguments.add(attrNotSameName); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - - /** - * RFC822Name - */ - @Test - public void testRfc822Name_Equal() { - - RFC822Name name1 = null; - RFC822Name name1a = null; - RFC822Name differentLocalName = null; - RFC822Name differentDomainName = null; - RFC822Name localCaseName = null; - RFC822Name domainCaseName = null; - @SuppressWarnings("unused") - RFC822Name noAtName = null; - - try { - name1 = RFC822Name.newInstance("localPart@DomainPart"); - name1a = RFC822Name.newInstance("localPart@DomainPart"); - differentLocalName = RFC822Name.newInstance("differentlocalPart@DomainPart"); - differentDomainName = RFC822Name.newInstance("localPart@differentDomainPart"); - localCaseName = RFC822Name.newInstance("LOCALPart@DomainPart"); - domainCaseName = RFC822Name.newInstance("localPart@DOMAINPart"); - - - } catch (Exception e) { - fail(e.toString()); - } - - // should not be able to create a name without an @. If you try, newInstance returns null - Exception exSeen = null; - try { - noAtName = RFC822Name.newInstance("nameWithoutAnAtSign"); - } catch (Exception e) { - exSeen = e; - } - assertNotNull(exSeen); - - - FunctionArgumentAttributeValue attrName1 = null; - FunctionArgumentAttributeValue attrName1a = null; - FunctionArgumentAttributeValue attrDifferentLocalName = null; - FunctionArgumentAttributeValue attrDifferentDomainName = null; - FunctionArgumentAttributeValue attrLocalCaseName = null; - FunctionArgumentAttributeValue attrDomainCaseName = null; - try { - attrName1 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(name1)); - attrName1a = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(name1a)); - attrDifferentLocalName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(differentLocalName)); - attrDifferentDomainName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(differentDomainName)); - attrLocalCaseName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(localCaseName)); - attrDomainCaseName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(domainCaseName)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_RFC822NAME_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_RFC822NAME_EQUAL, fd.getId()); - assertEquals(DataTypeRFC822Name.newInstance().getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attrName1); - arguments.add(attrName1a); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same Local - arguments.clear(); - arguments.add(attrName1); - arguments.add(attrDifferentLocalName); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // check not same Domain - arguments.clear(); - arguments.add(attrName1); - arguments.add(attrDifferentDomainName); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test case-sensitivity in local part - arguments.clear(); - arguments.add(attrName1); - arguments.add(attrLocalCaseName); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test non-case-sensitivity in Domain part - arguments.clear(); - arguments.add(attrName1); - arguments.add(attrDomainCaseName); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - /** - * Hex Binary - */ - @Test - public void testHexBinary_Equal() { - HexBinary binary = null; - HexBinary sameBinary = null; - HexBinary differentBinary = null; - try { - binary = HexBinary.newInstance("e04fd020ea3a6910a2d808002b30309d"); - sameBinary = HexBinary.newInstance("e04fd020ea3a6910a2d808002b30309d"); - differentBinary = HexBinary.newInstance("f123a890ee3d"); - } catch (Exception e) { - fail(e.toString()); - } - - FunctionArgumentAttributeValue attrBinary = null; - FunctionArgumentAttributeValue attrSameBinary = null; - FunctionArgumentAttributeValue attrDifferentBinary = null;; - try { - attrBinary = new FunctionArgumentAttributeValue(DataTypes.DT_HEXBINARY.createAttributeValue(binary)); - attrSameBinary = new FunctionArgumentAttributeValue(DataTypes.DT_HEXBINARY.createAttributeValue(sameBinary)); - attrDifferentBinary = new FunctionArgumentAttributeValue(DataTypes.DT_HEXBINARY.createAttributeValue(differentBinary)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_HEXBINARY_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_HEXBINARY_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_HEXBINARY.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attrBinary); - arguments.add(attrSameBinary); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(attrBinary); - arguments.add(attrDifferentBinary); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } - - - /** - * Base64 Binary - */ - @Test - public void testBase64Binary_Equal() { - Base64Binary binary = null; - Base64Binary sameBinary = null; - Base64Binary differentBinary = null; - try { - binary = Base64Binary.newInstance("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"); - sameBinary = Base64Binary.newInstance("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz"); - differentBinary = Base64Binary.newInstance("f123a890ee3d"); - } catch (Exception e) { - fail(e.toString()); - } - - FunctionArgumentAttributeValue attrBinary = null; - FunctionArgumentAttributeValue attrSameBinary = null; - FunctionArgumentAttributeValue attrDifferentBinary = null; - try { - attrBinary = new FunctionArgumentAttributeValue(DataTypes.DT_BASE64BINARY.createAttributeValue(binary)); - attrSameBinary = new FunctionArgumentAttributeValue(DataTypes.DT_BASE64BINARY.createAttributeValue(sameBinary)); - attrDifferentBinary = new FunctionArgumentAttributeValue(DataTypes.DT_BASE64BINARY.createAttributeValue(differentBinary)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_BASE64BINARY_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_BASE64BINARY_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_BASE64BINARY.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - // test normal equals and non-equals - // check separate objects with the same value - arguments.add(attrBinary); - arguments.add(attrSameBinary); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check not same - arguments.clear(); - arguments.add(attrBinary); - arguments.add(attrDifferentBinary); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - } -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHigherOrderBagTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHigherOrderBagTest.java deleted file mode 100644 index 64364e4b8..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHigherOrderBagTest.java +++ /dev/null @@ -1,2193 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.functions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import com.att.research.xacml.api.AttributeValue; -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.Bag; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionHigherOrderBag; - -/** - * 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 FunctionDefinitionHigherOrderBagTest { - - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - - - // - // ANY-OF tests - // - - - @Test - public void testAny_of() { - String a = "a"; - String b = "b"; - String c = "c"; - String d = "d"; - String e = "e"; - String f = "f"; - String g = "g"; - String h = "h"; - String j = "j"; - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagb = null; - Bag bagaaacccef = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - Bag bagStringBooleansTrue = null; - Bag bagStringBooleansFalse = null; - - - // primitive attrs - FunctionArgumentAttributeValue attra = null; - FunctionArgumentAttributeValue attrb = null; - FunctionArgumentAttributeValue attrh = null; - - - // predicates passed as arguments - FunctionArgumentAttributeValue attrPredicateStringEqual = null; - FunctionArgumentAttributeValue attrPredicateStringIntersection = null; - FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; - - try { - - // Create Bag contents - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagb = new Bag(); - bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagaaacccef = new Bag(); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagEmpty = new Bag(); - bagStringBooleansTrue = new Bag(); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansFalse = new Bag(); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - - - // create primitive attrs - attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); - attrb = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(b)); - attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); - - - // predicates passed as function arguments - attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); - attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); - attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); - - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); - FunctionArgumentBag attrBagStringBooleansFalse = new FunctionArgumentBag(bagStringBooleansFalse); - - FunctionDefinitionHigherOrderBag<?,?> fd = (FunctionDefinitionHigherOrderBag<?,?>) StdFunctions.FD_ANY_OF; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ANY_OF, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // normal match - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attra); - arguments.add(attrBagabcdefg); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // bag in first position - match - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrBagabcdefg); - arguments.add(attra); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // normal no-match - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attra); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // multiple primitives - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrh); - arguments.add(attrb); - arguments.add(attrBagace); - arguments.add(attra); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of Predicate error: function:string-equal Expected 2 arguments, got 4", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // no primitives - predicate function expects 2 - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of Predicate error: function:string-equal Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no primitives - predicate expects only 1 arg - arguments.clear(); - arguments.add(attrPredicateBooleanFromString); - arguments.add(attrBagStringBooleansTrue); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - arguments.clear(); - arguments.add(attrPredicateBooleanFromString); - arguments.add(attrBagStringBooleansFalse); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bag is empty - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrh); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // no bag - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrh); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of Did not get any Bag argument; must have at least 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // extra bag - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrh); - arguments.add(attrBagStringBooleansTrue); - arguments.add(attrh); - arguments.add(attrBagStringBooleansTrue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of must have only 1 bag; found one at index 2 and another at 4", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // bad predicate - arguments.clear(); - arguments.add(attrh); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // non-boolean predicate - arguments.clear(); - arguments.add(attrPredicateStringIntersection); - arguments.add(attrh); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // predicate after first arg - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrPredicateStringIntersection); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of Predicate error: function:string-equal Expected data type 'string' saw 'anyURI' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bags of different types - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrh); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - // first null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of Predicate Function (first argument) was null", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of Got null argument at index 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - @Test - public void testAll_of() { - String a = "a"; - String b = "b"; - String c = "c"; - String d = "d"; - String e = "e"; - String f = "f"; - String g = "g"; - String h = "h"; - String j = "j"; - - String w = "w"; - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagb = null; - Bag bagaaacccef = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - Bag bagStringBooleansFalse = null; - Bag bagStringBooleansTrue = null; - - - // primitive attrs - FunctionArgumentAttributeValue attra = null; - FunctionArgumentAttributeValue attrh = null; - FunctionArgumentAttributeValue attrw = null; - - - - // predicates passed as arguments - FunctionArgumentAttributeValue attrPredicateStringEqual = null; - FunctionArgumentAttributeValue attrPredicateStringIntersection = null; - FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; - FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; - - try { - - // Create Bag contents - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagb = new Bag(); - bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagaaacccef = new Bag(); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagEmpty = new Bag(); - bagStringBooleansTrue = new Bag(); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansFalse = new Bag(); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - - - - // create primitive attrs - attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); - attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); - attrw = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(w)); - - - // predicates passed as function arguments - attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); - attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); - attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); - attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); - - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); - FunctionArgumentBag attrBagStringBooleansFalse = new FunctionArgumentBag(bagStringBooleansFalse); - - FunctionDefinitionHigherOrderBag<?,?> fd = (FunctionDefinitionHigherOrderBag<?,?>) StdFunctions.FD_ALL_OF; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ALL_OF, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // normal match - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrw); - arguments.add(attrBagace); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // normal no-match - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attra); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // no primitives - predicate function expects 2 - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of Predicate error: function:string-equal Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no primitives - predicate expects only 1 arg - arguments.clear(); - arguments.add(attrPredicateBooleanFromString); - arguments.add(attrBagStringBooleansTrue); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - arguments.clear(); - arguments.add(attrPredicateBooleanFromString); - arguments.add(attrBagStringBooleansFalse); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bag is empty - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrh); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // no bag - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrh); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of Did not get any Bag argument; must have at least 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // extra bag - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrh); - arguments.add(attrBagStringBooleansTrue); - arguments.add(attrh); - arguments.add(attrBagStringBooleansTrue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of must have only 1 bag; found one at index 2 and another at 4", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // bad predicate - arguments.clear(); - arguments.add(attrh); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // non-boolean predicate - arguments.clear(); - arguments.add(attrPredicateStringIntersection); - arguments.add(attrh); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // predicate after first arg - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrPredicateStringIntersection); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of Predicate error: function:string-greater-than Expected data type 'string' saw 'anyURI' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bags of different types - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrh); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - // first null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of Predicate Function (first argument) was null", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of Got null argument at index 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - - - - - - - - @Test - public void testAny_of_any() { - String a = "a"; - String b = "b"; - String c = "c"; - String d = "d"; - String e = "e"; - String f = "f"; - String g = "g"; - String h = "h"; - String j = "j"; - - String w = "w"; - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagb = null; - Bag bagaaacccef = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - Bag bagStringBooleansFalse = null; - Bag bagStringBooleansTrue = null; - Bag bagBooleansFalse = null; - Bag bagBooleansTrue = null; - - - // primitive attrs - FunctionArgumentAttributeValue attra = null; - FunctionArgumentAttributeValue attrh = null; - FunctionArgumentAttributeValue attrw = null; - - - FunctionArgumentAttributeValue attrInt4 = null; - - - // predicates passed as arguments - FunctionArgumentAttributeValue attrPredicateStringEqual = null; - FunctionArgumentAttributeValue attrPredicateStringIntersection = null; - FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; - FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; - FunctionArgumentAttributeValue attrPredicateNof = null; - - try { - - // Create Bag contents - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagb = new Bag(); - bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagaaacccef = new Bag(); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagEmpty = new Bag(); - bagStringBooleansTrue = new Bag(); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansFalse = new Bag(); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagBooleansTrue = new Bag(); - bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(true)); - bagBooleansFalse = new Bag(); - bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - - - // create primitive attrs - attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); - attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); - attrw = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(w)); - - attrInt4 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(4)); - - - // predicates passed as function arguments - attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); - attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); - attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); - attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); - attrPredicateNof = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_N_OF)); - - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); - FunctionArgumentBag attrBagStringBooleansFalse = new FunctionArgumentBag(bagStringBooleansFalse); - FunctionArgumentBag attrBagBooleansTrue = new FunctionArgumentBag(bagBooleansTrue); - FunctionArgumentBag attrBagBooleansFalse = new FunctionArgumentBag(bagBooleansFalse); - - FunctionDefinitionHigherOrderBag<?,?> fd = (FunctionDefinitionHigherOrderBag<?,?>) StdFunctions.FD_ANY_OF_ANY; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ANY_OF_ANY, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // normal match - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrw); - arguments.add(attrBagace); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // normal no-match - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attra); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // no primitives - predicate function expects 2 - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-any Predicate error: function:string-equal Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrBagace); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // no primitives - predicate expects only 1 arg - arguments.clear(); - arguments.add(attrPredicateBooleanFromString); - arguments.add(attrBagStringBooleansTrue); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - arguments.clear(); - arguments.add(attrPredicateBooleanFromString); - arguments.add(attrBagStringBooleansFalse); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // n-of with lots of bags - success - arguments.clear(); - arguments.add(attrPredicateNof); - arguments.add(attrInt4); - arguments.add(attrBagBooleansTrue); - arguments.add(attrBagBooleansTrue); - arguments.add(attrBagBooleansTrue); - arguments.add(attrBagBooleansTrue); - arguments.add(attrBagBooleansTrue); - arguments.add(attrBagBooleansTrue); - arguments.add(attrBagBooleansTrue); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // n-of with lots of bags - fail - arguments.clear(); - arguments.add(attrPredicateNof); - arguments.add(attrInt4); - arguments.add(attrBagBooleansFalse); - arguments.add(attrBagBooleansFalse); - arguments.add(attrBagBooleansTrue); - arguments.add(attrBagBooleansTrue); - arguments.add(attrBagBooleansFalse); - arguments.add(attrBagBooleansFalse); - arguments.add(attrBagBooleansFalse); - arguments.add(attrBagBooleansFalse); - arguments.add(attrBagBooleansFalse); - arguments.add(attrBagBooleansFalse); - arguments.add(attrBagBooleansFalse); - arguments.add(attrBagBooleansFalse); - arguments.add(attrBagBooleansFalse); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - - // bag is empty - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrh); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-any Bag is empty at index 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // no bag - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrh); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-any Predicate error: function:string-greater-than Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrh); - arguments.add(attrh); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bad predicate - arguments.clear(); - arguments.add(attrh); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-any First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // non-boolean predicate - arguments.clear(); - arguments.add(attrPredicateStringIntersection); - arguments.add(attrh); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-any Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // predicate after first arg - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrPredicateStringIntersection); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-any Predicate error: function:string-greater-than Expected data type 'string' saw 'anyURI' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bags of different types - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrh); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-any Predicate Function (first argument) was null", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-any Got null argument at index 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - - - - - - - - - - @Test - public void testAll_of_any() { - String a = "a"; - String b = "b"; - String c = "c"; - String d = "d"; - String e = "e"; - String f = "f"; - String g = "g"; - String h = "h"; - String j = "j"; - - String w = "w"; - String x = "x"; - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagb = null; - Bag bagaaacccef = null; - Bag bagawx = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - Bag bagStringBooleansFalse = null; - Bag bagStringBooleansTrue = null; - Bag bagBooleansFalse = null; - Bag bagBooleansTrue = null; - - - // primitive attrs - FunctionArgumentAttributeValue attra = null; - FunctionArgumentAttributeValue attrh = null; - - - - - // predicates passed as arguments - FunctionArgumentAttributeValue attrPredicateStringEqual = null; - FunctionArgumentAttributeValue attrPredicateStringIntersection = null; - FunctionArgumentAttributeValue attrPredicateStringLessThan = null; - FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; - FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; - - try { - - // Create Bag contents - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagb = new Bag(); - bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagaaacccef = new Bag(); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagawx = new Bag(); - bagawx.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagawx.add(DataTypes.DT_STRING.createAttributeValue(w)); - bagawx.add(DataTypes.DT_STRING.createAttributeValue(x)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagEmpty = new Bag(); - bagStringBooleansTrue = new Bag(); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansFalse = new Bag(); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagBooleansTrue = new Bag(); - bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(true)); - bagBooleansFalse = new Bag(); - bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - - - // create primitive attrs - attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); - attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); - - - - // predicates passed as function arguments - attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); - attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); - attrPredicateStringLessThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_LESS_THAN)); - attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); - attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); - - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagawx = new FunctionArgumentBag(bagawx); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); - - FunctionDefinitionHigherOrderBag<?,?> fd = (FunctionDefinitionHigherOrderBag<?,?>) StdFunctions.FD_ALL_OF_ANY; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ALL_OF_ANY, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // normal match - arguments.clear(); - arguments.add(attrPredicateStringLessThan); - arguments.add(attrBagabcdefg); - arguments.add(attrBagawx); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // normal no-match - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagace); - arguments.add(attrBagawx); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // primitive instead of bag - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attra); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any 2nd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrBagace); - arguments.add(attra); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any 3rd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no primitives - predicate expects only 1 arg - arguments.clear(); - arguments.add(attrPredicateBooleanFromString); - arguments.add(attrBagStringBooleansTrue); - arguments.add(attrBagStringBooleansTrue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any Predicate error: function:boolean-from-string Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - - // bag is empty - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagace); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagEmpty); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // no bag - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrh); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // bad predicate - arguments.clear(); - arguments.add(attrh); - arguments.add(attrBagStringInt); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // non-boolean predicate - arguments.clear(); - arguments.add(attrPredicateStringIntersection); - arguments.add(attrBagStringInt); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // predicate after first arg - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrPredicateStringIntersection); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any 2nd argument must be bag, got 'anyURI'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bags of different types - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagace); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any Predicate error: function:string-greater-than Expected data type 'string' saw 'integer' at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no args - arguments.clear(); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any Expected at least 2 arguments, got 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // one arg - arguments.clear(); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any Expected at least 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(attrBagabcdefg); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // first null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-any 3rd argument must be bag, got 'null'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - - - - - - - @Test - public void testAny_of_all() { - String a = "a"; - String b = "b"; - String c = "c"; - String d = "d"; - String e = "e"; - String f = "f"; - String g = "g"; - String h = "h"; - String j = "j"; - - String w = "w"; - String x = "x"; - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagb = null; - Bag bagaaacccef = null; - Bag bagewx = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - Bag bagStringBooleansFalse = null; - Bag bagStringBooleansTrue = null; - Bag bagBooleansFalse = null; - Bag bagBooleansTrue = null; - - - // primitive attrs - FunctionArgumentAttributeValue attra = null; - FunctionArgumentAttributeValue attrh = null; - - - - - // predicates passed as arguments - FunctionArgumentAttributeValue attrPredicateStringEqual = null; - FunctionArgumentAttributeValue attrPredicateStringIntersection = null; - FunctionArgumentAttributeValue attrPredicateStringGreaterThanOrEqual = null; - FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; - FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; - - try { - - // Create Bag contents - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagb = new Bag(); - bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagaaacccef = new Bag(); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagewx = new Bag(); - bagewx.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagewx.add(DataTypes.DT_STRING.createAttributeValue(w)); - bagewx.add(DataTypes.DT_STRING.createAttributeValue(x)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagEmpty = new Bag(); - bagStringBooleansTrue = new Bag(); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansFalse = new Bag(); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagBooleansTrue = new Bag(); - bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(true)); - bagBooleansFalse = new Bag(); - bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - - - // create primitive attrs - attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); - attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); - - - - // predicates passed as function arguments - attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); - attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); - attrPredicateStringGreaterThanOrEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN_OR_EQUAL)); - attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); - attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); - - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagewx = new FunctionArgumentBag(bagewx); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); - - FunctionDefinitionHigherOrderBag<?,?> fd = (FunctionDefinitionHigherOrderBag<?,?>) StdFunctions.FD_ANY_OF_ALL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ANY_OF_ALL, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // normal match - arguments.clear(); - arguments.add(attrPredicateStringGreaterThanOrEqual); - arguments.add(attrBagewx); - arguments.add(attrBagace); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // normal no-match - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagace); - arguments.add(attrBagewx); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // primitive instead of bag - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attra); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all 2nd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrBagace); - arguments.add(attra); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all 3rd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no primitives - predicate expects only 1 arg - arguments.clear(); - arguments.add(attrPredicateBooleanFromString); - arguments.add(attrBagStringBooleansTrue); - arguments.add(attrBagStringBooleansTrue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all Predicate error: function:boolean-from-string Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bag is empty - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagace); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagEmpty); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // no bag - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrh); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // bad predicate - arguments.clear(); - arguments.add(attrh); - arguments.add(attrBagStringInt); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // non-boolean predicate - arguments.clear(); - arguments.add(attrPredicateStringIntersection); - arguments.add(attrBagStringInt); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // predicate after first arg - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrPredicateStringIntersection); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all 2nd argument must be bag, got 'anyURI'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bags of different types - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagace); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all Predicate error: function:string-greater-than Expected data type 'string' saw 'integer' at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no args - arguments.clear(); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all Expected at least 2 arguments, got 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // one arg - arguments.clear(); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all Expected at least 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(attrBagabcdefg); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // first null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:any-of-all 3rd argument must be bag, got 'null'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - @Test - public void testAll_of_all() { - String a = "a"; - String b = "b"; - String c = "c"; - String d = "d"; - String e = "e"; - String f = "f"; - String g = "g"; - String h = "h"; - String j = "j"; - - String w = "w"; - String x = "x"; - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagb = null; - Bag bagaaacccef = null; - Bag bagawx = null; - Bag bagwx = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - Bag bagStringBooleansFalse = null; - Bag bagStringBooleansTrue = null; - Bag bagBooleansFalse = null; - Bag bagBooleansTrue = null; - - - // primitive attrs - FunctionArgumentAttributeValue attra = null; - FunctionArgumentAttributeValue attrh = null; - - - - - // predicates passed as arguments - FunctionArgumentAttributeValue attrPredicateStringEqual = null; - FunctionArgumentAttributeValue attrPredicateStringIntersection = null; - FunctionArgumentAttributeValue attrPredicateStringGreaterThan = null; - FunctionArgumentAttributeValue attrPredicateBooleanFromString = null; - - try { - - // Create Bag contents - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagb = new Bag(); - bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagaaacccef = new Bag(); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagawx = new Bag(); - bagawx.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagawx.add(DataTypes.DT_STRING.createAttributeValue(w)); - bagawx.add(DataTypes.DT_STRING.createAttributeValue(x)); - bagwx = new Bag(); - bagwx.add(DataTypes.DT_STRING.createAttributeValue(w)); - bagwx.add(DataTypes.DT_STRING.createAttributeValue(x)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagEmpty = new Bag(); - bagStringBooleansTrue = new Bag(); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansFalse = new Bag(); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagBooleansTrue = new Bag(); - bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - bagBooleansTrue.add(DataTypes.DT_BOOLEAN.createAttributeValue(true)); - bagBooleansFalse = new Bag(); - bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - bagBooleansFalse.add(DataTypes.DT_BOOLEAN.createAttributeValue(false)); - - - // create primitive attrs - attra = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(a)); - attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); - - - - // predicates passed as function arguments - attrPredicateStringEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_EQUAL)); - attrPredicateStringIntersection = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_INTERSECTION)); - attrPredicateStringGreaterThan = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_GREATER_THAN)); - attrPredicateBooleanFromString = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING)); - - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagawx = new FunctionArgumentBag(bagawx); - FunctionArgumentBag attrBagwx = new FunctionArgumentBag(bagwx); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); - - FunctionDefinitionHigherOrderBag<?,?> fd = (FunctionDefinitionHigherOrderBag<?,?>) StdFunctions.FD_ALL_OF_ALL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ALL_OF_ALL, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // normal match - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagwx); - arguments.add(attrBagace); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // normal no-match - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagawx); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagace); - arguments.add(attrBagwx); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // primitive instead of bag - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attra); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all 2nd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrPredicateStringEqual); - arguments.add(attrBagace); - arguments.add(attra); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all 3rd argument must be bag, got 'string'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no primitives - predicate expects only 1 arg - arguments.clear(); - arguments.add(attrPredicateBooleanFromString); - arguments.add(attrBagStringBooleansTrue); - arguments.add(attrBagStringBooleansTrue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all Predicate error: function:boolean-from-string Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bag is empty - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagace); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagEmpty); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // no bag - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrh); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // bad predicate - arguments.clear(); - arguments.add(attrh); - arguments.add(attrBagStringInt); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // non-boolean predicate - arguments.clear(); - arguments.add(attrPredicateStringIntersection); - arguments.add(attrBagStringInt); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all Predicate Function must return boolean, but 'urn:oasis:names:tc:xacml:1.0:function:string-intersection' returns 'string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // predicate after first arg - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrPredicateStringIntersection); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all 2nd argument must be bag, got 'anyURI'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bags of different types - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagwx); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all Predicate error: function:string-greater-than Expected data type 'string' saw 'integer' at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no args - arguments.clear(); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all Expected at least 2 arguments, got 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // one arg - arguments.clear(); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all Expected at least 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(attrBagabcdefg); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // first null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrPredicateStringGreaterThan); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:all-of-all 3rd argument must be bag, got 'null'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - - - - - @Test - public void testMap() { - String a = "a"; - String b = "b"; - String c = "c"; - String d = "d"; - String e = "e"; - String f = "f"; - String g = "g"; - String h = "h"; - String j = "j"; - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagb = null; - Bag bagaaacccef = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - Bag bagStringBooleansFalse = null; - Bag bagStringBooleansTrue = null; - Bag bagInt123 = null; - Bag bagInt789 = null; - - - // primitive attrs - FunctionArgumentAttributeValue attrh = null; - FunctionArgumentAttributeValue attrInt7 = null; - - - - // predicates passed as arguments - FunctionArgumentAttributeValue attrPredicateStringNormalizeToLowerCase = null; - FunctionArgumentAttributeValue attrPredicateIntegerEqual = null; - FunctionArgumentAttributeValue attrPredicateIntegerAdd = null; - - try { - - // Create Bag contents - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_STRING.createAttributeValue("A")); - bagace.add(DataTypes.DT_STRING.createAttributeValue("C")); - bagace.add(DataTypes.DT_STRING.createAttributeValue("E")); - bagb = new Bag(); - bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagaaacccef = new Bag(); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); - - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagEmpty = new Bag(); - bagStringBooleansTrue = new Bag(); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansTrue.add(DataTypes.DT_STRING.createAttributeValue("true")); - bagStringBooleansFalse = new Bag(); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagStringBooleansFalse.add(DataTypes.DT_STRING.createAttributeValue("false")); - bagInt123 = new Bag(); - bagInt123.add(DataTypes.DT_INTEGER.createAttributeValue(1)); - bagInt123.add(DataTypes.DT_INTEGER.createAttributeValue(2)); - bagInt123.add(DataTypes.DT_INTEGER.createAttributeValue(3)); - bagInt789 = new Bag(); - bagInt789.add(DataTypes.DT_INTEGER.createAttributeValue(7)); - bagInt789.add(DataTypes.DT_INTEGER.createAttributeValue(8)); - bagInt789.add(DataTypes.DT_INTEGER.createAttributeValue(9)); - - - - // create primitive attrs - attrh = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(h)); - attrInt7 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(7)); - - - // predicates passed as function arguments - attrPredicateStringNormalizeToLowerCase = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_STRING_NORMALIZE_TO_LOWER_CASE)); - attrPredicateIntegerEqual = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_INTEGER_EQUAL)); - attrPredicateIntegerAdd = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(XACML3.ID_FUNCTION_INTEGER_ADD)); - - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - FunctionArgumentBag attrBagStringBooleansTrue = new FunctionArgumentBag(bagStringBooleansTrue); - FunctionArgumentBag attrBagInt789 = new FunctionArgumentBag(bagInt789); - - FunctionDefinitionHigherOrderBag<?,?> fd = (FunctionDefinitionHigherOrderBag<?,?>) StdFunctions.FD_MAP; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_MAP, fd.getId()); - assertNull( fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertTrue(fd.returnsBag()); - - // normal match - arguments.clear(); - arguments.add(attrPredicateStringNormalizeToLowerCase); - arguments.add(attrBagace); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertTrue(res.isBag()); - Bag bag = res.getBag(); - assertEquals(3, bag.size()); - List<AttributeValue<?>> bagAttributes = bag.getAttributeValueList(); - try { - assertTrue(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("a"))); - assertFalse(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("A"))); - assertTrue(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("c"))); - assertFalse(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("C"))); - assertTrue(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("e"))); - assertFalse(bagAttributes.contains(DataTypes.DT_STRING.createAttributeValue("E"))); - } catch (Exception ex) { - fail("checking result e="+ex); - } - - // 2-input predicate - arguments.clear(); - arguments.add(attrPredicateIntegerAdd); - arguments.add(attrInt7); - arguments.add(attrBagInt789); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertTrue(res.isBag()); - bag = res.getBag(); - assertEquals(3, bag.size()); - bagAttributes = bag.getAttributeValueList(); - try { - assertTrue(bagAttributes.contains(DataTypes.DT_INTEGER.createAttributeValue("14"))); - assertTrue(bagAttributes.contains(DataTypes.DT_INTEGER.createAttributeValue("15"))); - assertTrue(bagAttributes.contains(DataTypes.DT_INTEGER.createAttributeValue("16"))); - } catch (Exception ex) { - fail("checking result e="+ex); - } - - - // predicate returns booleans - arguments.clear(); - arguments.add(attrPredicateIntegerEqual); - arguments.add(attrInt7); - arguments.add(attrBagInt789); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertTrue(res.isBag()); - bag = res.getBag(); - assertEquals(3, bag.size()); - bagAttributes = bag.getAttributeValueList(); - try { - assertEquals(bagAttributes.get(0), (DataTypes.DT_BOOLEAN.createAttributeValue(true))); - assertEquals(bagAttributes.get(1), (DataTypes.DT_BOOLEAN.createAttributeValue(false))); - assertEquals(bagAttributes.get(2), (DataTypes.DT_BOOLEAN.createAttributeValue(false))); - } catch (Exception ex) { - fail("checking result e="+ex); - } - - // predicate returns bag - - - - // no primitives - predicate function expects 2 - arguments.clear(); - arguments.add(attrPredicateIntegerAdd); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:map Predicate error: function:integer-add Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bag is empty - arguments.clear(); - arguments.add(attrPredicateStringNormalizeToLowerCase); - arguments.add(attrh); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertTrue(res.isBag()); - bag = res.getBag(); - assertEquals(0, bag.size());; - - // no bag - arguments.clear(); - arguments.add(attrPredicateStringNormalizeToLowerCase); - arguments.add(attrh); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:map Did not get any Bag argument; must have at least 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // extra bag - arguments.clear(); - arguments.add(attrPredicateStringNormalizeToLowerCase); - arguments.add(attrh); - arguments.add(attrBagStringBooleansTrue); - arguments.add(attrh); - arguments.add(attrBagStringBooleansTrue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:map must have only 1 bag; found one at index 2 and another at 4", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // bad predicate - arguments.clear(); - arguments.add(attrh); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:map First argument expected URI, got http://www.w3.org/2001/XMLSchema#string", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // predicate gets unexpected number of args - arguments.clear(); - arguments.add(attrPredicateStringNormalizeToLowerCase); - arguments.add(attrh); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:map Predicate error: function:string-normalize-to-lower-case Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // predicate gets bad primitive type - arguments.clear(); - arguments.add(attrPredicateStringNormalizeToLowerCase); - arguments.add(attrPredicateStringNormalizeToLowerCase); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:map Predicate error: function:string-normalize-to-lower-case Expected 1 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bags of different types - arguments.clear(); - arguments.add(attrPredicateStringNormalizeToLowerCase); - arguments.add(attrh); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - // first null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:map Predicate Function (first argument) was null", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrPredicateStringNormalizeToLowerCase); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:map Got null argument at index 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHomogeneousSimpleTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHomogeneousSimpleTest.java deleted file mode 100644 index 8e98793b9..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionHomogeneousSimpleTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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.junit.Test; - -import com.att.research.xacml.api.Status; -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.Bag; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionEquality; - -/** - * 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 - * - * - */ -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); - 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); - 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); - } - - 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); - - // 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()); - - // 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()); - - // 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()); - - // 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"); - - - // 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()); - - // 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()); - } - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionLogicalTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionLogicalTest.java deleted file mode 100644 index b70ed138c..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionLogicalTest.java +++ /dev/null @@ -1,422 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionLogical; - -/** - * 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 () { - 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); - } - } - - - @Test - public void testOR() { - FunctionArgumentAttributeValue attr5 = null; - try { - attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - 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 - 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 - 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()); - - // 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()); - - // 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()); - - } - - - @Test - public void testAND() { - FunctionArgumentAttributeValue attr5 = null; - try { - attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - - 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 - 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 - 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()); - - // 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()); - - // 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()); - - } - - - - - @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); - } - - - 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 - 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()); - - // 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()); - - // 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()); - - - // 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()); - - } - - - @Test - public void testNot() { - - 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 - 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()); - - // 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()); - } -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionNumberTypeConversionTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionNumberTypeConversionTest.java deleted file mode 100644 index 17843292c..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionNumberTypeConversionTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionNumberTypeConversion; - -/** - * 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); - } - - 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 - 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); - } - - 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 - 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); - } - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionRegexpMatchTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionRegexpMatchTest.java deleted file mode 100644 index 04fe8255e..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionRegexpMatchTest.java +++ /dev/null @@ -1,511 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacml.std.datatypes.IPAddress; -import com.att.research.xacml.std.datatypes.RFC2396DomainName; -import com.att.research.xacml.std.datatypes.RFC822Name; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionRegexpMatch; - -/** - * 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); - } - - 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 - assertFalse(fd.returnsBag()); - - - // match - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrV1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.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(java.lang.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()); - - - 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()); - - // 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()); - - 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()); - - - // 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()); - - // 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()); - - } - - @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); - } - - - 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); - } - - 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 - assertFalse(fd.returnsBag()); - - - // match - arguments.clear(); - arguments.add(attrRegexp); - arguments.add(attrUri1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.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(java.lang.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()); - - } - - - @Test - public void testIpAddress() { - String regexp = new String(".*123.*"); - IPAddress addr1 = null; - IPAddress addr2 = null; - try { - addr1 = IPAddress.newInstance("10.123.13.14"); - addr2 = IPAddress.newInstance("10.11.12.13"); - } catch (Exception 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); - } - - 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 - assertFalse(fd.returnsBag()); - - - // match - arguments.clear(); - arguments.add(attrRegexp); - arguments.add(attrAddr1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.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(java.lang.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()); - - } - - - @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); - } - - - 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); - } - - 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 - assertFalse(fd.returnsBag()); - - - // match - arguments.clear(); - arguments.add(attrRegexp); - arguments.add(attrAddr1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.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(java.lang.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()); - - } - - - @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); - } - - - 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)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - 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 - assertFalse(fd.returnsBag()); - - - // match - arguments.clear(); - arguments.add(attrRegexp); - arguments.add(attrAddr1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.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(java.lang.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()); - - } - - - @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); - } - - - 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); - } - - 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 - assertFalse(fd.returnsBag()); - - - // match - arguments.clear(); - arguments.add(attrRegexp); - arguments.add(attrAddr1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.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(java.lang.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()); - - } - - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSetTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSetTest.java deleted file mode 100644 index 99e27910a..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSetTest.java +++ /dev/null @@ -1,1903 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.functions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.junit.Test; - -import com.att.research.xacml.api.AttributeValue; -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.Bag; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionSet; - -/** - * 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 FunctionDefinitionSetTest { - - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - - - // - // INTERSECTION tests - // - - - @Test - public void testString_intersection() { - String a = "a"; - String b = "b"; - String c = "c"; - String d = "d"; - String e = "e"; - String f = "f"; - String g = "g"; - String h = "h"; - String j = "j"; - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagb = null; - Bag bagaaacccef = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - - FunctionArgumentAttributeValue attrBadType = null; - - try { - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagb = new Bag(); - bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagaaacccef = new Bag(); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagEmpty = new Bag(); - - attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); - FunctionArgumentBag attrBagaaacccef = new FunctionArgumentBag(bagaaacccef); - FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - - FunctionDefinitionSet<?,?> fd = (FunctionDefinitionSet<?,?>) StdFunctions.FD_STRING_INTERSECTION; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_INTERSECTION, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertTrue(fd.returnsBag()); - - // normal intersection (everything in both bags, no duplicates) - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Bag bag = res.getBag(); - assertNotNull(bag); - Iterator<AttributeValue<?>> it = bag.getAttributeValues(); - assertEquals(7, bag.size()); - AttributeValue<?> attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - - // several but not all intersection - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(3, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(b, attrValueObject.getValue() ); - - // no intersection - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(0, bag.size()); - - // one intersection - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagb); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(b, attrValueObject.getValue() ); - - // bag one has duplicates that do not intersect - arguments.clear(); - arguments.add(attrBagaaacccef); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(f, attrValueObject.getValue() ); - - // bag one has duplicates that do intersect - arguments.clear(); - arguments.add(attrBagaaacccef); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(3, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - attrValueObject = it.next(); - assertEquals(c, attrValueObject.getValue() ); - attrValueObject = it.next(); - assertEquals(e, attrValueObject.getValue() ); - - // bag 2 has duplicates that do not intersect - arguments.clear(); - arguments.add(attrBagbdfhj); - arguments.add(attrBagaaacccef); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(f, attrValueObject.getValue() ); - - // bag 2 has duplicates that intersect - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagaaacccef); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(3, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - attrValueObject = it.next(); - assertEquals(c, attrValueObject.getValue() ); - attrValueObject = it.next(); - assertEquals(e, attrValueObject.getValue() ); - - // first bag is empty - arguments.clear(); - arguments.add(attrBagEmpty); - arguments.add(attrBagaaacccef); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(0, bag.size()); - - // second bag is empty - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(0, bag.size()); - - // bags of different types - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(0, bag.size()); - - // first not a bag - arguments.clear(); - arguments.add(attrBadType); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-intersection 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()); - - // second not a bag - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-intersection 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 null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-intersection Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-intersection Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // too few args - arguments.clear(); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-intersection Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-intersection Expected 2 arguments, got 0", 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(attrBagabcdefg); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-intersection Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - @Test - public void testInteger_intersection() { - BigInteger a = new BigInteger("1"); - BigInteger b = new BigInteger("2"); - BigInteger c = new BigInteger("3"); - BigInteger d = new BigInteger("4"); - BigInteger e = new BigInteger("5"); - BigInteger f = new BigInteger("6"); - BigInteger g = new BigInteger("7"); - BigInteger h = new BigInteger("8"); - BigInteger j = new BigInteger("9"); - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagb = null; - Bag bagaaacccef = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - - FunctionArgumentAttributeValue attrBadType = null; - - try { - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_INTEGER.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_INTEGER.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_INTEGER.createAttributeValue(a)); - bagace.add(DataTypes.DT_INTEGER.createAttributeValue(c)); - bagace.add(DataTypes.DT_INTEGER.createAttributeValue(e)); - bagb = new Bag(); - bagb.add(DataTypes.DT_INTEGER.createAttributeValue(b)); - bagaaacccef = new Bag(); - bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(e)); - bagaaacccef.add(DataTypes.DT_INTEGER.createAttributeValue(f)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue("abc")); - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(1)); - bagEmpty = new Bag(); - - attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); - FunctionArgumentBag attrBagaaacccef = new FunctionArgumentBag(bagaaacccef); - FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - - FunctionDefinitionSet<?,?> fd = (FunctionDefinitionSet<?,?>) StdFunctions.FD_INTEGER_INTERSECTION; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_INTERSECTION, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertTrue(fd.returnsBag()); - - // normal intersection (everything in both bags, no duplicates) - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Bag bag = res.getBag(); - assertNotNull(bag); - Iterator<AttributeValue<?>> it = bag.getAttributeValues(); - assertEquals(7, bag.size()); - AttributeValue<?> attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - - // several but not all intersection - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(3, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(b, attrValueObject.getValue() ); - - // no intersection - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(0, bag.size()); - - // one intersection - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagb); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(b, attrValueObject.getValue() ); - - // bag one has duplicates that do not intersect - arguments.clear(); - arguments.add(attrBagaaacccef); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(f, attrValueObject.getValue() ); - - // bag one has duplicates that do intersect - arguments.clear(); - arguments.add(attrBagaaacccef); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(3, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - attrValueObject = it.next(); - assertEquals(c, attrValueObject.getValue() ); - attrValueObject = it.next(); - assertEquals(e, attrValueObject.getValue() ); - - // bag 2 has duplicates that do not intersect - arguments.clear(); - arguments.add(attrBagbdfhj); - arguments.add(attrBagaaacccef); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(f, attrValueObject.getValue() ); - - // bag 2 has duplicates that intersect - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagaaacccef); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(3, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - attrValueObject = it.next(); - assertEquals(c, attrValueObject.getValue() ); - attrValueObject = it.next(); - assertEquals(e, attrValueObject.getValue() ); - - // first bag is empty - arguments.clear(); - arguments.add(attrBagEmpty); - arguments.add(attrBagaaacccef); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(0, bag.size()); - - // second bag is empty - arguments.clear(); - arguments.add(attrBagbdfhj); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(0, bag.size()); - - // bags of different types - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagInt); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(1, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - - - // first not a bag - arguments.clear(); - arguments.add(attrBadType); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-intersection 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()); - - // second not a bag - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-intersection 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 null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-intersection Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-intersection Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // too few args - arguments.clear(); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-intersection Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-intersection Expected 2 arguments, got 0", 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(attrBagabcdefg); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-intersection Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - - - - - - - - // - // AT_LEAST_ONE_MEMBER_OF tests - // - - @Test - public void testString_at_least_one_member_of() { - String a = "a"; - String b = "b"; - String c = "c"; - String d = "d"; - String e = "e"; - String f = "f"; - String g = "g"; - String h = "h"; - String j = "j"; - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagb = null; - Bag bagaaaccce = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - - FunctionArgumentAttributeValue attrBadType = null; - - try { - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagb = new Bag(); - bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagaaaccce = new Bag(); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagEmpty = new Bag(); - - attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); - FunctionArgumentBag attrBagaaaccce = new FunctionArgumentBag(bagaaaccce); - FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - - FunctionDefinitionSet<?,?> fd = (FunctionDefinitionSet<?,?>) StdFunctions.FD_STRING_AT_LEAST_ONE_MEMBER_OF; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_AT_LEAST_ONE_MEMBER_OF, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // normal intersection (everything in both bags, no duplicates) - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - - // several but not all intersection - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // no intersection - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // one intersection - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagb); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // bag one has duplicates that do not intersect - arguments.clear(); - arguments.add(attrBagaaaccce); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bag one has duplicates that do intersect - arguments.clear(); - arguments.add(attrBagaaaccce); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // bag 2 has duplicates that do not intersect - arguments.clear(); - arguments.add(attrBagbdfhj); - arguments.add(attrBagaaaccce); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bag 2 has duplicates that intersect - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagaaaccce); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // 2 empty bags - arguments.clear(); - arguments.add(attrBagEmpty); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first non-empty, 2nd empty - arguments.clear(); - arguments.add(attrBagaaaccce); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first empty, 2nd not empty - arguments.clear(); - arguments.add(attrBagEmpty); - arguments.add(attrBagaaaccce); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bags of different types - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first not a bag - arguments.clear(); - arguments.add(attrBadType); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-at-least-one-member-of 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()); - - // second not a bag - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-at-least-one-member-of 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 null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-at-least-one-member-of Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-at-least-one-member-of Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // too few args - arguments.clear(); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-at-least-one-member-of Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-at-least-one-member-of Expected 2 arguments, got 0", 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(attrBagabcdefg); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-at-least-one-member-of Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - - - - - - - - // - // UNION tests - // - - - - - - @Test - public void testString_union() { - String a = "a"; - String b = "b"; - String c = "c"; - String d = "d"; - String e = "e"; - String f = "f"; - String g = "g"; - String h = "h"; - String j = "j"; - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagaaacccef = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - - FunctionArgumentAttributeValue attrBadType = null; - - try { - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagaaacccef = new Bag(); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagaaacccef.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagEmpty = new Bag(); - - attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagaaacccef = new FunctionArgumentBag(bagaaacccef); - FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - - FunctionDefinitionSet<?,?> fd = (FunctionDefinitionSet<?,?>) StdFunctions.FD_STRING_UNION; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_UNION, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertTrue(fd.returnsBag()); - - // normal intersection (everything in both bags, no duplicates) - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Bag bag = res.getBag(); - assertNotNull(bag); - Iterator<AttributeValue<?>> it = bag.getAttributeValues(); - assertEquals(7, bag.size()); - AttributeValue<?> attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - - // several but not all union - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(8, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - - // bag one has duplicates that do not match first bag - arguments.clear(); - arguments.add(attrBagaaacccef); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(8, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - - // bag one has duplicates that do match first bag - arguments.clear(); - arguments.add(attrBagaaacccef); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(4, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - attrValueObject = it.next(); - assertEquals(c, attrValueObject.getValue() ); - attrValueObject = it.next(); - assertEquals(e, attrValueObject.getValue() ); - - // bag 2 has duplicates that do not match first bag - arguments.clear(); - arguments.add(attrBagbdfhj); - arguments.add(attrBagaaacccef); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(8, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(b, attrValueObject.getValue() ); - - // bag 2 has duplicates that do match first bag - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagaaacccef); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(4, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - attrValueObject = it.next(); - assertEquals(c, attrValueObject.getValue() ); - attrValueObject = it.next(); - assertEquals(e, attrValueObject.getValue() ); - - // two empty bags - arguments.clear(); - arguments.add(attrBagEmpty); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(0, bag.size()); - - // first bag empty, 2nd not empty - arguments.clear(); - arguments.add(attrBagEmpty); - arguments.add(attrBagaaacccef); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(4, bag.size()); - - // first bag not empty, 2nd empty - arguments.clear(); - arguments.add(attrBagaaacccef); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(4, bag.size()); - - // bags of different types - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(4, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - bag = res.getBag(); - assertNotNull(bag); - it = bag.getAttributeValues(); - assertEquals(4, bag.size()); - attrValueObject = it.next(); - assertEquals(DataTypes.DT_STRING.getId(), attrValueObject.getDataTypeId()); - assertEquals(a, attrValueObject.getValue() ); - - // first not a bag - arguments.clear(); - arguments.add(attrBadType); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-union 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()); - - // second not a bag - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-union 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 null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-union Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-union Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // too few args - arguments.clear(); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-union Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-union Expected 2 arguments, got 0", 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(attrBagabcdefg); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-union Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - - - - - // - // SUBSET tests - // - - @Test - public void testString_subset() { - String a = "a"; - String b = "b"; - String c = "c"; - String d = "d"; - String e = "e"; - String f = "f"; - String g = "g"; - String h = "h"; - String j = "j"; - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagb = null; - Bag bagaaaccce = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - - FunctionArgumentAttributeValue attrBadType = null; - - try { - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagb = new Bag(); - bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagaaaccce = new Bag(); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagEmpty = new Bag(); - - attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); - FunctionArgumentBag attrBagaaaccce = new FunctionArgumentBag(bagaaaccce); - FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - - FunctionDefinitionSet<?,?> fd = (FunctionDefinitionSet<?,?>) StdFunctions.FD_STRING_SUBSET; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_SUBSET, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // normal intersection (everything in both bags, no duplicates) - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - - // not subset - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // subset - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - - // no intersection - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // Not - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagb); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // Subset - arguments.clear(); - arguments.add(attrBagb); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // bag one has duplicates that do not intersect - arguments.clear(); - arguments.add(attrBagaaaccce); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bag one has duplicates that do intersect - arguments.clear(); - arguments.add(attrBagaaaccce); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // bag 2 has duplicates that do not intersect - arguments.clear(); - arguments.add(attrBagbdfhj); - arguments.add(attrBagaaaccce); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bag 2 has duplicates that intersect - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagaaaccce); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // 2 empty bags - arguments.clear(); - arguments.add(attrBagEmpty); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first non-empty, 2nd empty - arguments.clear(); - arguments.add(attrBagaaaccce); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first empty, 2nd not empty - arguments.clear(); - arguments.add(attrBagEmpty); - arguments.add(attrBagaaaccce); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // bags of different types - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - arguments.clear(); - arguments.add(attrBagb); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first not a bag - arguments.clear(); - arguments.add(attrBadType); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-subset 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()); - - // second not a bag - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-subset 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 null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-subset Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-subset Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // too few args - arguments.clear(); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-subset Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-subset Expected 2 arguments, got 0", 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(attrBagabcdefg); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-subset Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - - - - - - // - // SET_EQUALS tests - // - - @Test - public void testString_set_equals() { - String a = "a"; - String b = "b"; - String c = "c"; - String d = "d"; - String e = "e"; - String f = "f"; - String g = "g"; - String h = "h"; - String j = "j"; - - - Bag bagabcdefg = null; - Bag bagbdfhj = null; - Bag bagace = null; - Bag bagb = null; - Bag bagaaaccce = null; - Bag bagInt = null; - Bag bagStringInt = null; - Bag bagEmpty = null; - - FunctionArgumentAttributeValue attrBadType = null; - - try { - bagabcdefg = new Bag(); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagabcdefg.add(DataTypes.DT_STRING.createAttributeValue(g)); - bagbdfhj = new Bag(); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(d)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(f)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(h)); - bagbdfhj.add(DataTypes.DT_STRING.createAttributeValue(j)); - bagace = new Bag(); - bagace.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagace.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagb = new Bag(); - bagb.add(DataTypes.DT_STRING.createAttributeValue(b)); - bagaaaccce = new Bag(); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(c)); - bagaaaccce.add(DataTypes.DT_STRING.createAttributeValue(e)); - bagInt = new Bag(); - bagInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagStringInt = new Bag(); - bagStringInt.add(DataTypes.DT_STRING.createAttributeValue(a)); - bagStringInt.add(DataTypes.DT_INTEGER.createAttributeValue(123)); - bagEmpty = new Bag(); - - attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); - } catch (Exception ex) { - fail("creating attribute e="+ ex); - } - - // make into attributes - FunctionArgumentBag attrBagabcdefg = new FunctionArgumentBag(bagabcdefg); - FunctionArgumentBag attrBagbdfhj = new FunctionArgumentBag(bagbdfhj); - FunctionArgumentBag attrBagace = new FunctionArgumentBag(bagace); - FunctionArgumentBag attrBagb = new FunctionArgumentBag(bagb); - FunctionArgumentBag attrBagaaaccce = new FunctionArgumentBag(bagaaaccce); - FunctionArgumentBag attrBagInt = new FunctionArgumentBag(bagInt); - FunctionArgumentBag attrBagStringInt = new FunctionArgumentBag(bagStringInt); - FunctionArgumentBag attrBagEmpty = new FunctionArgumentBag(bagEmpty); - - FunctionDefinitionSet<?,?> fd = (FunctionDefinitionSet<?,?>) StdFunctions.FD_STRING_SET_EQUALS; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_SET_EQUALS, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - // normal intersection (everything in both bags, no duplicates) - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - - // several but not all intersection - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // no intersection - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // one intersection - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBagb); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bag one has duplicates that do not intersect - arguments.clear(); - arguments.add(attrBagaaaccce); - arguments.add(attrBagbdfhj); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bag one has duplicates that do intersect - arguments.clear(); - arguments.add(attrBagaaaccce); - arguments.add(attrBagace); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // bag 2 has duplicates that do not intersect - arguments.clear(); - arguments.add(attrBagbdfhj); - arguments.add(attrBagaaaccce); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bag 2 has duplicates that intersect - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagaaaccce); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // 2 empty bags - arguments.clear(); - arguments.add(attrBagEmpty); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first non-empty, 2nd empty - arguments.clear(); - arguments.add(attrBagaaaccce); - arguments.add(attrBagEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first empty, 2nd not empty - arguments.clear(); - arguments.add(attrBagEmpty); - arguments.add(attrBagaaaccce); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bags of different types - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagStringInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - arguments.clear(); - arguments.add(attrBagace); - arguments.add(attrBagInt); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first not a bag - arguments.clear(); - arguments.add(attrBadType); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-set-equals 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()); - - // second not a bag - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(attrBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-set-equals 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 null - arguments.clear(); - arguments.add(null); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-set-equals Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // second null - arguments.clear(); - arguments.add(attrBagabcdefg); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-set-equals Got null argument", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // too few args - arguments.clear(); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-set-equals Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-set-equals Expected 2 arguments, got 0", 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(attrBagabcdefg); - arguments.add(attrBagabcdefg); - arguments.add(attrBagabcdefg); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-set-equals Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - - - - - // - // - // REST OF DATA TYPES OMITTED - // because they "should" all work the same - // - // - - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSpecialMatchTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSpecialMatchTest.java deleted file mode 100644 index 3bce2f6cc..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionSpecialMatchTest.java +++ /dev/null @@ -1,488 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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 javax.security.auth.x500.X500Principal; - -import org.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.Bag; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentBag; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionRFC822NameMatch; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionX500NameMatch; - -/** - * 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 FunctionDefinitionSpecialMatchTest { - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - @Test - public void testX500NameMatch() { - // assume that the contents of the name components are not significant and we can treat them as simple blocks of "<name>=<value>" - String A = "cn=Some person"; - String B = "O=Medico Corp"; - String C = "C=US"; - String D = "DNQUALIFIER=d string"; - String E = "SURNAME=some name"; - String F = "INITIALS=inits"; - - - X500Principal abc = new X500Principal(A + "," + B + "," + C); - X500Principal dabc = new X500Principal(D + "," + A + "," + B + "," + C); - X500Principal abcd = new X500Principal(A + "," + B + "," + C + "," + D); - X500Principal adbc = new X500Principal(A + "," + D + "," + B + "," + C); - X500Principal dcab = new X500Principal(D + "," + C + "," + A + "," + B) ; - X500Principal def = new X500Principal(D + "," + E + "," + F) ; - - - FunctionArgumentAttributeValue attrABC = null; - FunctionArgumentAttributeValue attrDABC = null; - FunctionArgumentAttributeValue attrABCD = null; - FunctionArgumentAttributeValue attrADBC = null; - FunctionArgumentAttributeValue attrDCAB = null; - FunctionArgumentAttributeValue attrDEF = null; - - FunctionArgumentAttributeValue attrBad = null; - FunctionArgumentBag attrBag = new FunctionArgumentBag(new Bag()); - - - try { - attrABC = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(abc)); - attrDABC = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(dabc)); - attrABCD = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(abcd)); - attrADBC = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(adbc)); - attrDCAB = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(dcab)); - attrDEF = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(def)); - - attrBad = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionX500NameMatch fd = (FunctionDefinitionX500NameMatch) StdFunctions.FD_X500NAME_MATCH; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_X500NAME_MATCH, fd.getId()); - assertEquals(DataTypes.DT_X500NAME.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 - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - // test normal, first exact match for second - arguments.clear(); - arguments.add(attrABC); - arguments.add(attrABC); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // test first is end of second - arguments.clear(); - arguments.add(attrABC); - arguments.add(attrDABC); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // first exact match for sub-section but not end of second - arguments.clear(); - arguments.add(attrABC); - arguments.add(attrABCD); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // components of first match components in second but not contiguous - arguments.clear(); - arguments.add(attrABC); - arguments.add(attrADBC); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // components of first match components in second but not in order - arguments.clear(); - arguments.add(attrABC); - arguments.add(attrDCAB); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first does not match second at all - arguments.clear(); - arguments.add(attrABC); - arguments.add(attrDEF); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first arg larger than 2nd arg - arguments.clear(); - arguments.add(attrABCD); - arguments.add(attrABC); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // bad arg types - arguments.clear(); - arguments.add(attrABC); - arguments.add(attrBad); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:x500Name-match Expected data type 'x500Name' saw 'integer' at arg index 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(attrABC); - arguments.add(attrABC); - arguments.add(attrABC); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:x500Name-match Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // too few args - arguments.clear(); - arguments.add(attrABC); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:x500Name-match Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:x500Name-match Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // one arg is bag - arguments.clear(); - arguments.add(attrABC); - arguments.add(attrBag); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:x500Name-match Expected a simple value, saw a bag at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null arg - arguments.clear(); - arguments.add(null); - arguments.add(attrBag); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:x500Name-match Got null argument at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - @Test - public void testRfc822NameMatch() { - - - - - FunctionArgumentAttributeValue attrStringabcxyz = null; - FunctionArgumentAttributeValue attrStringABCxyz = null; - FunctionArgumentAttributeValue attrStringabcXYZ = null; - FunctionArgumentAttributeValue attrStringcx = null; - FunctionArgumentAttributeValue attrStringwholedomainpart = null; - FunctionArgumentAttributeValue attrStringWholeDomainPart = null; - FunctionArgumentAttributeValue attrStringWholeDomain = null; - FunctionArgumentAttributeValue attrStringdomainpart = null; - FunctionArgumentAttributeValue attrStringDomainPart = null; - FunctionArgumentAttributeValue attrStringdotWholeDomain = null; - FunctionArgumentAttributeValue attrStringdomain = null; - - FunctionArgumentAttributeValue attrStringNoMatch = null; - FunctionArgumentAttributeValue attrStringMultipleAt = null; - FunctionArgumentAttributeValue attrStringMissingLocal = null; - FunctionArgumentAttributeValue attrStringMissingDomain = null; - - - FunctionArgumentAttributeValue attrRfcabcxyz = null; - FunctionArgumentAttributeValue attrRfcwholedomainpart = null; - FunctionArgumentAttributeValue attrRfcWholeDomainPart = null; - - FunctionArgumentBag attrBag = new FunctionArgumentBag(new Bag()); - - try { - attrStringabcxyz = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc@xyz")); - attrStringABCxyz = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ABC@xyz")); - attrStringabcXYZ = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc@XYZ")); - attrStringcx = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("c@x")); - attrStringwholedomainpart = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("whole.domain.part")); - attrStringWholeDomainPart = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("Whole.Domain.Part")); - attrStringWholeDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("Whole.Domain")); - attrStringdomainpart = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(".domain.part")); - attrStringDomainPart = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(".Domain.Part")); - attrStringdotWholeDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(".Whole.Domain")); - attrStringdomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(".domain.")); - - attrStringNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("no match to any legal name")); - attrStringMultipleAt = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("name@with@multipleAts")); - attrStringMissingLocal = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("@multipleAts")); - attrStringMissingDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("localpart@")); - - attrRfcabcxyz = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue("abc@xyz")); - attrRfcwholedomainpart = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue("abc@whole.domain.part")); - attrRfcWholeDomainPart = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue("abc@Whole.Domain.Part")); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionRFC822NameMatch fd = (FunctionDefinitionRFC822NameMatch) StdFunctions.FD_RFC822NAME_MATCH; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_RFC822NAME_MATCH, fd.getId()); - assertEquals(DataTypes.DT_RFC822NAME.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 - assertFalse(fd.returnsBag()); - - - // string identical to name - exact match on whole search term - arguments.clear(); - arguments.add(attrStringabcxyz); - arguments.add(attrRfcabcxyz); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.getStatus().isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // no match local case different - arguments.clear(); - arguments.add(attrStringABCxyz); - arguments.add(attrRfcabcxyz); - res = fd.evaluate(null, arguments); - assertTrue(res.getStatus().isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // match domain case different - arguments.clear(); - arguments.add(attrStringabcXYZ); - arguments.add(attrRfcabcxyz); - res = fd.evaluate(null, arguments); - assertTrue(res.getStatus().isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - - // partial local + partial domain - arguments.clear(); - arguments.add(attrStringcx); - arguments.add(attrRfcabcxyz); - res = fd.evaluate(null, arguments); - assertTrue(res.getStatus().isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // whole domain - arguments.clear(); - arguments.add(attrStringwholedomainpart); - arguments.add(attrRfcwholedomainpart); - res = fd.evaluate(null, arguments); - assertTrue(res.getStatus().isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // whole domain different case - arguments.clear(); - arguments.add(attrStringWholeDomainPart); - arguments.add(attrRfcwholedomainpart); - res = fd.evaluate(null, arguments); - assertTrue(res.getStatus().isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - arguments.clear(); - arguments.add(attrStringwholedomainpart); - arguments.add(attrRfcWholeDomainPart); - res = fd.evaluate(null, arguments); - assertTrue(res.getStatus().isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // whole domain fail - arguments.clear(); - arguments.add(attrStringWholeDomain); - arguments.add(attrRfcWholeDomainPart); - res = fd.evaluate(null, arguments); - assertTrue(res.getStatus().isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // partial domain match - arguments.clear(); - arguments.add(attrStringDomainPart); - arguments.add(attrRfcWholeDomainPart); - res = fd.evaluate(null, arguments); - assertTrue(res.getStatus().isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // partial domain different case - arguments.clear(); - arguments.add(attrStringdomainpart); - arguments.add(attrRfcWholeDomainPart); - res = fd.evaluate(null, arguments); - assertTrue(res.getStatus().isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // partial domain fail - arguments.clear(); - arguments.add(attrStringdotWholeDomain); - arguments.add(attrRfcWholeDomainPart); - res = fd.evaluate(null, arguments); - assertTrue(res.getStatus().isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - arguments.clear(); - arguments.add(attrStringdomain); - arguments.add(attrRfcWholeDomainPart); - res = fd.evaluate(null, arguments); - assertTrue(res.getStatus().isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // search term contains more than 1 @ - arguments.clear(); - arguments.add(attrStringMultipleAt); - arguments.add(attrRfcabcxyz); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:rfc822Name-match String contained more than 1 '@' in 'name@with@multipleAts'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // search term missing local part - arguments.clear(); - arguments.add(attrStringMissingLocal); - arguments.add(attrRfcabcxyz); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:rfc822Name-match String missing local part in '@multipleAts'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // search term missing domain part - arguments.clear(); - arguments.add(attrStringMissingDomain); - arguments.add(attrRfcabcxyz); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:rfc822Name-match String missing domain part in 'localpart@'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg types - arguments.clear(); - arguments.add(attrRfcabcxyz); - arguments.add(attrStringNoMatch); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:rfc822Name-match Expected data type 'string' saw 'rfc822Name' at arg index 0", 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(attrStringNoMatch); - arguments.add(attrStringNoMatch); - arguments.add(attrStringNoMatch); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:rfc822Name-match Expected 2 arguments, got 3", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // too few args - arguments.clear(); - arguments.add(attrStringNoMatch); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:rfc822Name-match Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:rfc822Name-match Expected 2 arguments, got 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // one arg is bag - arguments.clear(); - arguments.add(attrStringNoMatch); - arguments.add(attrBag); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:rfc822Name-match Expected a simple value, saw a bag at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null arg - arguments.clear(); - arguments.add(null); - arguments.add(attrStringNoMatch); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:rfc822Name-match Got null argument at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - - } - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringConversionTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringConversionTest.java deleted file mode 100644 index 341da61d0..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringConversionTest.java +++ /dev/null @@ -1,2504 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.functions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.math.BigInteger; -import java.net.URI; -import java.net.URISyntaxException; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.List; - -import javax.security.auth.x500.X500Principal; - -import org.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacml.std.datatypes.IPAddress; -import com.att.research.xacml.std.datatypes.IPv4Address; -import com.att.research.xacml.std.datatypes.IPv6Address; -import com.att.research.xacml.std.datatypes.ISO8601Date; -import com.att.research.xacml.std.datatypes.ISO8601DateTime; -import com.att.research.xacml.std.datatypes.ISO8601Time; -import com.att.research.xacml.std.datatypes.ISO8601TimeZone; -import com.att.research.xacml.std.datatypes.PortRange; -import com.att.research.xacml.std.datatypes.RFC2396DomainName; -import com.att.research.xacml.std.datatypes.RFC822Name; -import com.att.research.xacml.std.datatypes.XPathDayTimeDuration; -import com.att.research.xacml.std.datatypes.XPathYearMonthDuration; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionStringConversion; - -/** - * Tests for converting objects to/from Strings. - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * - */ -public class FunctionDefinitionStringConversionTest { - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - - /** - * Boolean - */ - @Test - public void testBoolean_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("true")); - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_BOOLEAN_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_BOOLEAN_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.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 - assertFalse(fd.returnsBag()); - assertEquals(new Integer(1), fd.getNumArgs()); - - // test normal - arguments.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertEquals(new Boolean(true), resValue); - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:boolean-from-string Cannot convert from \"java.lang.String\" with value \"not valid obj value\" to boolean", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:boolean-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - @Test - public void testString_from_boolean() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrStringBadType = null; - String objValueString = "false"; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(objValueString)); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_BOOLEAN; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_BOOLEAN, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(objValueString, res.getValue().getValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-boolean Expected data type 'boolean' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - /** - * Integer - */ - @Test - public void testInteger_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("123456")); - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_INTEGER_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.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 - assertFalse(fd.returnsBag()); - assertEquals(new Integer(1), fd.getNumArgs()); - - // test normal - arguments.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - BigInteger resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("123456"), resValue); - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-from-string For input string: \"n\"", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - @Test - public void testString_from_integer() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrStringBadType = null; - String objValueString = "1234"; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(objValueString)); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_INTEGER; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_INTEGER, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(objValueString, res.getValue().getValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-integer Expected data type 'integer' saw 'double' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - /** - * Double - */ - @Test - public void testDouble_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("5.432")); - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_DOUBLE_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DOUBLE_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.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 - assertFalse(fd.returnsBag()); - assertEquals(new Integer(1), fd.getNumArgs()); - - // test normal - arguments.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Double resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(5.432), resValue); - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:double-from-string For input string: \"not valid obj value\"", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:double-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - @Test - public void testString_from_double() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrObjBig = null; - FunctionArgumentAttributeValue attrStringBadType = null; - String objValueString = "5.432"; - String objValueStringBig = "55555555555555555555.123455"; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(objValueString)); - attrObjBig = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(objValueStringBig)); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_DOUBLE; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DOUBLE, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(objValueString, res.getValue().getValue()); - - arguments.clear(); - arguments.add(attrObjBig); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals("5.555555555555556E19", res.getValue().getValue()); - - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-double Expected data type 'double' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - - /** - * Time - */ - @Test - public void testTime_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrString2 = null; - FunctionArgumentAttributeValue attrString3 = null; - FunctionArgumentAttributeValue attrString4 = null; - FunctionArgumentAttributeValue attrStringTimeZone = null; - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("05:12:34.323")); - attrString2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("5:12:34.323")); - attrString3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("05:12")); - attrString4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("05:12:34")); - attrStringTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("05:12:34.323+03:00")); - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_TIME_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_TIME_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - ISO8601Time resValue = (ISO8601Time)res.getValue().getValue(); - assertEquals(new ISO8601Time(5, 12, 34, 323), resValue); - - // check missing 0 in front - arguments.clear(); - arguments.add(attrString2); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:time-from-string Invalid hour of day", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // check missing seconds/msecs - arguments.clear(); - arguments.add(attrString3); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:time-from-string Time string too short", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // check missing just msecs - arguments.clear(); - arguments.add(attrString4); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (ISO8601Time)res.getValue().getValue(); - assertEquals(new ISO8601Time(5, 12, 34, 0), resValue); - - // check TimeZone - arguments.clear(); - arguments.add(attrStringTimeZone); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (ISO8601Time)res.getValue().getValue(); - assertEquals(new ISO8601Time(new ISO8601TimeZone(180), 5, 12, 34, 323), resValue); - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:time-from-string Invalid hour of day", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:time-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - @Test - public void testString_from_time() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrObj2 = null; - FunctionArgumentAttributeValue attrObjTimeZone = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue("05:12:34.323")); - attrObj2 = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue("05:01:02.323")); - attrObjTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue("05:12:34.323+03:00")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_TIME; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_TIME, fd.getId()); - assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals("05:12:34.323", res.getValue().getValue()); - - // missing digits in string value? - arguments.clear(); - arguments.add(attrObj2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals("05:01:02.323", res.getValue().getValue()); - - // include TimeZone - arguments.clear(); - arguments.add(attrObjTimeZone); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals("05:12:34.323+03:00", res.getValue().getValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-time Expected data type 'time' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - - /** - * Date - */ - @Test - public void testDate_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrString2 = null; - FunctionArgumentAttributeValue attrString3 = null; - FunctionArgumentAttributeValue attrString4 = null; - FunctionArgumentAttributeValue attrString5 = null; - FunctionArgumentAttributeValue attrString6 = null; - FunctionArgumentAttributeValue attrString7 = null; - FunctionArgumentAttributeValue attrString8 = null; - FunctionArgumentAttributeValue attrString9 = null; - FunctionArgumentAttributeValue attrStringDateZone = null; - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-12")); - attrString2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-2013-05-12")); - attrString3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("1232013-05-12")); - attrString4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-1232013-05-12")); - attrString5 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("213-05-12")); - attrString6 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-5-12")); - attrString7 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-2")); - attrString8 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-32-12")); - attrString9 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-45")); - attrStringDateZone = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-12+03:00")); - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_DATE_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATE_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - ISO8601Date resValue = (ISO8601Date)res.getValue().getValue(); - assertEquals(new ISO8601Date(2013, 5, 12), resValue); - - // check negative - arguments.clear(); - arguments.add(attrString2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (ISO8601Date)res.getValue().getValue(); - assertEquals(new ISO8601Date(-2013, 5, 12), resValue); - - // check big - arguments.clear(); - arguments.add(attrString3); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (ISO8601Date)res.getValue().getValue(); - assertEquals(new ISO8601Date(1232013, 5, 12), resValue); - - // check big negative - arguments.clear(); - arguments.add(attrString4); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (ISO8601Date)res.getValue().getValue(); - assertEquals(new ISO8601Date(-1232013, 5, 12), resValue); - - // bad year - arguments.clear(); - arguments.add(attrString5); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-from-string Invalid year (must be at least 4 digits)", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad month - arguments.clear(); - arguments.add(attrString6); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-from-string Invalid month", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad day format - arguments.clear(); - arguments.add(attrString7); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-from-string Invalid day", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // month out of range - arguments.clear(); - arguments.add(attrString8); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-from-string Invalid month", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // day out of range - arguments.clear(); - arguments.add(attrString9); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-from-string Invalid day", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // check TimeZone - arguments.clear(); - arguments.add(attrStringDateZone); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (ISO8601Date)res.getValue().getValue(); - assertEquals(new ISO8601Date(new ISO8601TimeZone(180), 2013, 5, 12), resValue); - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-from-string Invalid year", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:date-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - @Test - public void testString_from_date() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrObj2 = null; - FunctionArgumentAttributeValue attrObjDateZone = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue("2013-05-12")); - attrObj2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue("0001-01-01")); - attrObjDateZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue("2013-05-12+03:00")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_DATE; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DATE, fd.getId()); - assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals("2013-05-12", res.getValue().getValue()); - - // missing digits in string value? - arguments.clear(); - arguments.add(attrObj2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals("1-01-01", res.getValue().getValue()); - - // include DateZone - arguments.clear(); - arguments.add(attrObjDateZone); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals("2013-05-12+03:00", res.getValue().getValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-date Expected data type 'date' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - - - /** - * DateTime - */ - @Test - public void testDateTime_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrString2 = null; - FunctionArgumentAttributeValue attrString3 = null; - FunctionArgumentAttributeValue attrString4 = null; - FunctionArgumentAttributeValue attrString5 = null; - FunctionArgumentAttributeValue attrString6 = null; - FunctionArgumentAttributeValue attrString7 = null; - FunctionArgumentAttributeValue attrString8 = null; - FunctionArgumentAttributeValue attrString9 = null; - FunctionArgumentAttributeValue attrStringDateTimeZone = null; - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-12T12:14:15.323")); - attrString2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-2013-05-12T12:14:15.323")); - attrString3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("1232013-05-12T12:14:15.323")); - attrString4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-1232013-05-12T12:14:15.323")); - attrString5 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("213-05-12T12:14:15.323")); - attrString6 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-5-12T12:14:15.323")); - attrString7 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-2T12:14:15.323")); - attrString8 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-32-12T12:14:15.323")); - attrString9 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-45T12:14:15.323")); - attrStringDateTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2013-05-12T12:14:15.323+03:00")); - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_DATETIME_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DATETIME_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); - assertEquals(new ISO8601DateTime(null, new ISO8601Date(2013, 5, 12), new ISO8601Time(12, 14, 15, 323)), resValue); - - // check negative - arguments.clear(); - arguments.add(attrString2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - assertEquals(new ISO8601DateTime(null, new ISO8601Date(-2013, 5, 12), new ISO8601Time(12, 14, 15, 323)), resValue); - - - // check big - arguments.clear(); - arguments.add(attrString3); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - assertEquals(new ISO8601DateTime(null, new ISO8601Date(1232013, 5, 12), new ISO8601Time(12, 14, 15, 323)), resValue); - - // check big negative - arguments.clear(); - arguments.add(attrString4); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - assertEquals(new ISO8601DateTime(null, new ISO8601Date(-1232013, 5, 12), new ISO8601Time(12, 14, 15, 323)), resValue); - - // bad year - arguments.clear(); - arguments.add(attrString5); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-from-string Invalid year (must be at least 4 digits)", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad month - arguments.clear(); - arguments.add(attrString6); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-from-string Invalid month", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad day format - arguments.clear(); - arguments.add(attrString7); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-from-string Invalid day", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // month out of range - arguments.clear(); - arguments.add(attrString8); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-from-string Invalid month", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // day out of range - arguments.clear(); - arguments.add(attrString9); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-from-string Invalid day", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // check TimeZone - arguments.clear(); - arguments.add(attrStringDateTimeZone); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (ISO8601DateTime)res.getValue().getValue(); - assertEquals(new ISO8601DateTime(new ISO8601TimeZone(180), new ISO8601Date(new ISO8601TimeZone(180), 2013, 5, 12), new ISO8601Time(new ISO8601TimeZone(180),12, 14, 15, 323)), resValue); - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-from-string Invalid year", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dateTime-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - @Test - public void testString_from_dateTime() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrObj2 = null; - FunctionArgumentAttributeValue attrObjDateTimeZone = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue("2013-05-12T12:14:15.323")); - attrObj2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue("0001-01-01T12:14:15.323")); - attrObjDateTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue("2013-05-12T12:14:15.323+03:00")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_DATETIME; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DATETIME, fd.getId()); - assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals("2013-05-12T12:14:15.323", res.getValue().getValue()); - - // missing digits in string value? - arguments.clear(); - arguments.add(attrObj2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals("1-01-01T12:14:15.323", res.getValue().getValue()); - - // include DateTimeZone - arguments.clear(); - arguments.add(attrObjDateTimeZone); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals("2013-05-12T12:14:15.323+03:00", res.getValue().getValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-dateTime Expected data type 'dateTime' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - - /** - * URI - */ - @Test - public void testURI_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("http://someMachine.com/subdir")); - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_ANYURI_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ANYURI_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - URI resValue = (URI)res.getValue().getValue(); - try { - assertEquals(new URI("http://someMachine.com/subdir"), resValue); - } catch (URISyntaxException e) { - fail("uri generation e="+e); - } - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-from-string Illegal character in path at index 3: not valid obj value", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - @Test - public void testString_from_anyURI() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrStringBadType = null; - String objValueString = "http://aMachine.com:8080/aRef"; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(objValueString)); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_ANYURI; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_ANYURI, fd.getId()); - assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(objValueString, res.getValue().getValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-anyURI Expected data type 'anyURI' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - /** - * XPathDayTimeDuration - */ - @Test - public void testXPathDayTimeDuration_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrStringNeg1 = null; - FunctionArgumentAttributeValue attrStringNeg2 = null; - FunctionArgumentAttributeValue attrStringNoDay = null; - FunctionArgumentAttributeValue attrStringNoHour = null; - FunctionArgumentAttributeValue attrStringNoMin = null; - FunctionArgumentAttributeValue attrStringNoSec = null; - FunctionArgumentAttributeValue attrStringNoP = null; - FunctionArgumentAttributeValue attrStringSecondsDot = null; - FunctionArgumentAttributeValue attrStringMissingTOk = null; - FunctionArgumentAttributeValue attrStringMissingTBad = null; - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT10H30M23S")); - attrStringNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-P3DT10H30M23S")); - attrStringNeg2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P-3DT10H30M23S")); - attrStringNoDay = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("PT10H30M23S")); - attrStringNoHour = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT30M23S")); - attrStringNoMin = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT10H23S")); - attrStringNoSec = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT10H30M")); - attrStringNoP = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("3DT10H30M")); - attrStringSecondsDot = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3DT10H30M23.456S")); - attrStringMissingTOk = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3D")); - attrStringMissingTBad = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3D10H30M23S")); - - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_DAYTIMEDURATION_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DAYTIMEDURATION_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - XPathDayTimeDuration resValue = (XPathDayTimeDuration)res.getValue().getValue(); - assertEquals(new XPathDayTimeDuration(1, 3, 10, 30, 23), resValue); - - - // negative values in front is allowed - arguments.clear(); - arguments.add(attrStringNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (XPathDayTimeDuration)res.getValue().getValue(); - assertEquals(new XPathDayTimeDuration(-1, 3, 10, 30, 23), resValue); - - // negative in middle of string not ok - arguments.clear(); - arguments.add(attrStringNeg2); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dayTimeDuration-from-string Invalid chunk \"P-3DT10H30M23S\" at position 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // omit parts that are 0 - arguments.clear(); - arguments.add(attrStringNoDay); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (XPathDayTimeDuration)res.getValue().getValue(); - assertEquals(new XPathDayTimeDuration(1, 0, 10, 30, 23), resValue); - - arguments.clear(); - arguments.add(attrStringNoHour); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (XPathDayTimeDuration)res.getValue().getValue(); - assertEquals(new XPathDayTimeDuration(1, 3, 0, 30, 23), resValue); - - arguments.clear(); - arguments.add(attrStringNoMin); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (XPathDayTimeDuration)res.getValue().getValue(); - assertEquals(new XPathDayTimeDuration(1, 3, 10, 0, 23), resValue); - - arguments.clear(); - arguments.add(attrStringNoSec); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (XPathDayTimeDuration)res.getValue().getValue(); - assertEquals(new XPathDayTimeDuration(1, 3, 10, 30, 0), resValue); - - // P must always be present - arguments.clear(); - arguments.add(attrStringNoP); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dayTimeDuration-from-string Invalid ISO8601 duration string \"3DT10H30M\" at position 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // seconds may contain decimal - arguments.clear(); - arguments.add(attrStringSecondsDot); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (XPathDayTimeDuration)res.getValue().getValue(); - assertEquals(new XPathDayTimeDuration(1, 3, 10, 30, 23.456), resValue); - - // T must be absent iff all time items are absent - arguments.clear(); - arguments.add(attrStringMissingTOk); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (XPathDayTimeDuration)res.getValue().getValue(); - assertEquals(new XPathDayTimeDuration(1, 3, 0, 0, 0), resValue); - - // negative in middle of string not ok - arguments.clear(); - arguments.add(attrStringMissingTBad); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dayTimeDuration-from-string Invalid ISO8601 duration string \"P3D10H30M23S\" at position 6: out of order component", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dayTimeDuration-from-string Invalid ISO8601 duration string \"not valid obj value\" at position 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dayTimeDuration-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - @Test - public void testString_from_dayTimeDuration() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrStringBadType = null; - String objValueString = "P3DT10H30M23S"; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(objValueString)); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_DAYTIMEDURATION; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DAYTIMEDURATION, fd.getId()); - assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(objValueString, res.getValue().getValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-dayTimeDuration Expected data type 'dayTimeDuration' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - - - - - - /** - * XPathYearMonthDuration - */ - @Test - public void testXPathYearMonthDuration_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrStringNeg1 = null; - FunctionArgumentAttributeValue attrStringNeg2 = null; - FunctionArgumentAttributeValue attrStringNoYear1 = null; - FunctionArgumentAttributeValue attrStringNoYear2 = null; - FunctionArgumentAttributeValue attrStringNoMonth1 = null; - FunctionArgumentAttributeValue attrStringNoMonth2 = null; - FunctionArgumentAttributeValue attrStringNoValue = null; - FunctionArgumentAttributeValue attrStringNoP = null; - FunctionArgumentAttributeValue attrStringBigMonths = null; - FunctionArgumentAttributeValue attrStringMissingTOk = null; - FunctionArgumentAttributeValue attrStringMissingTBad = null; - FunctionArgumentAttributeValue attrStringZeroMonths = null; - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P1Y2M")); - attrStringNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("-P1Y2M")); - attrStringNeg2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P-1Y2M")); - attrStringNoYear1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P2M")); - attrStringNoYear2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("PY2M")); - attrStringNoMonth1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P1Y")); - attrStringNoMonth2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P1YM")); - attrStringNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P")); - attrStringNoP = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("1Y2M")); - attrStringBigMonths = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P1Y12M")); - attrStringMissingTOk = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3D")); - attrStringMissingTBad = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P3D10H30M23S")); - attrStringZeroMonths = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("P0M")); - - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_YEARMONTHDURATION_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_YEARMONTHDURATION_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - XPathYearMonthDuration resValue = (XPathYearMonthDuration)res.getValue().getValue(); - assertEquals(new XPathYearMonthDuration(1,1, 2), resValue); - - - // negative values in front is allowed - arguments.clear(); - arguments.add(attrStringNeg1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (XPathYearMonthDuration)res.getValue().getValue(); - assertEquals(new XPathYearMonthDuration(-1, 1, 2), resValue); - - // negative in middle of string not ok - arguments.clear(); - arguments.add(attrStringNeg2); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:yearMonthDuration-from-string Invalid chunk \"P-1Y2M\" at position 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // omit parts that are 0 - arguments.clear(); - arguments.add(attrStringNoYear1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (XPathYearMonthDuration)res.getValue().getValue(); - assertEquals(new XPathYearMonthDuration(1, 0, 2), resValue); - - arguments.clear(); - arguments.add(attrStringNoYear2); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:yearMonthDuration-from-string Invalid chunk \"PY2M\" at position 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - arguments.clear(); - arguments.add(attrStringNoMonth1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (XPathYearMonthDuration)res.getValue().getValue(); - assertEquals(new XPathYearMonthDuration(1, 1, 0), resValue); - - arguments.clear(); - arguments.add(attrStringNoMonth2); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:yearMonthDuration-from-string Invalid chunk \"P1YM\" at position 3", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // No field with a value - arguments.clear(); - arguments.add(attrStringNoValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:yearMonthDuration-from-string Invalid ISO8601 duration string \"P\": No duration components following P", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // P must always be present - arguments.clear(); - arguments.add(attrStringNoP); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:yearMonthDuration-from-string Invalid ISO8601 duration string \"1Y2M\" at position 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // Canonical Form of output may not have more than 12 months, but input as string is ok? - arguments.clear(); - arguments.add(attrStringBigMonths); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (XPathYearMonthDuration)res.getValue().getValue(); - assertEquals(new XPathYearMonthDuration(1, 1, 12), resValue); - - // Canonical representation of 0 Months - arguments.clear(); - arguments.add(attrStringZeroMonths); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (XPathYearMonthDuration)res.getValue().getValue(); - assertEquals(new XPathYearMonthDuration(1, 0, 0), resValue); - - // T must be absent iff all time items are absent - arguments.clear(); - arguments.add(attrStringMissingTOk); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:yearMonthDuration-from-string Invalid XPath yearMonthDuraiton \"{durationSign=1years=0months=0days=3hours=0minutes=0seconds=0millis=0}\": includes days, hours, minutes, or seconds", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // negative in middle of string not ok - arguments.clear(); - arguments.add(attrStringMissingTBad); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:yearMonthDuration-from-string Invalid ISO8601 duration string \"P3D10H30M23S\" at position 6: out of order component", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:yearMonthDuration-from-string Invalid ISO8601 duration string \"not valid obj value\" at position 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:yearMonthDuration-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - @Test - public void testString_from_yearMonthDuration() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrStringBadType = null; - String objValueString = "P1Y2M"; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(objValueString)); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_YEARMONTHDURATION; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_YEARMONTHDURATION, fd.getId()); - assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(objValueString, res.getValue().getValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-yearMonthDuration Expected data type 'yearMonthDuration' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - - - /** - * X500Principal - * - * See http://www.ietf.org/rfc/rfc2253.txt and http://www.ietf.org/rfc/rfc2251.txt - */ - @Test - public void testX500Principal_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrStringNoComma = null; - FunctionArgumentAttributeValue attrStringEmpty = null; - FunctionArgumentAttributeValue attrStringNoValue = null; - FunctionArgumentAttributeValue attrStringOrder = null; - FunctionArgumentAttributeValue attrStringDottedDecimalOID = null; - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("CN=Name, L=local, ST=NJ, O=ATT, C=USA")); - attrStringNoComma = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("CN=Name, L=local ST=NJ, O=ATT, C=USA")); - attrStringEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); - attrStringNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("CN=Name, L=, ST=NJ, O=ATT, C=USA")); - attrStringOrder = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("L=local, ST=NJ, O=ATT, CN=Name, C=USA")); - attrStringDottedDecimalOID = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2.5.4.3=A. N. Other")); - - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_X500NAME_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_X500NAME_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_X500NAME.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - X500Principal resValue = (X500Principal)res.getValue().getValue(); - assertEquals(new X500Principal("CN=Name, L=local, ST=NJ, O=ATT, C=USA"), resValue); - - // no comma between components => next attribute/value is included as part of first value - arguments.clear(); - arguments.add(attrStringNoComma); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (X500Principal)res.getValue().getValue(); - assertEquals(new X500Principal("CN=Name, L=local ST=NJ, O=ATT, C=USA"), resValue); - - // nothing in name (fail) - arguments.clear(); - arguments.add(attrStringEmpty); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (X500Principal)res.getValue().getValue(); - assertEquals(new X500Principal(""), resValue); - - // type value with no = - arguments.clear(); - arguments.add(attrStringNoValue); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (X500Principal)res.getValue().getValue(); - assertEquals(new X500Principal("CN=Name, L=, ST=NJ, O=ATT, C=USA"), resValue); - - // different order - arguments.clear(); - arguments.add(attrStringOrder); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (X500Principal)res.getValue().getValue(); - assertNotEquals(new X500Principal("CN=Name, L=local, ST=NJ, O=ATT, C=USA"), resValue); - - // dotted-decimal name with numbers - arguments.clear(); - arguments.add(attrStringDottedDecimalOID); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (X500Principal)res.getValue().getValue(); - assertEquals(new X500Principal("2.5.4.3=A. N. Other"), resValue); - - - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:x500Name-from-string improperly specified input name: not valid obj value", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:x500Name-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - @Test - public void testString_from_x500Name() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrStringBadType = null; - String objValueString = "CN=Name, L=local, ST=NJ, O=ATT, C=USA"; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(objValueString)); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_X500NAME; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_X500NAME, fd.getId()); - assertEquals(DataTypes.DT_X500NAME.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(objValueString, res.getValue().getValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-x500Name Expected data type 'x500Name' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - /** - * RFC822Name - */ - @Test - public void testRFC822Name_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrStringCapsDomain = null; - FunctionArgumentAttributeValue attrStringCapsLocal = null; - FunctionArgumentAttributeValue attrStringMissingAt = null; - FunctionArgumentAttributeValue attrStringMissingLocal = null; - FunctionArgumentAttributeValue attrStringMissingDomain = null; - FunctionArgumentAttributeValue attrStringEmpty = null; - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("local@Domain")); - attrStringCapsDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("local@DOMAIN")); - attrStringCapsLocal = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("LOCAL@Domain")); - attrStringMissingAt = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("localDomain")); - attrStringMissingLocal = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("@Domain")); - attrStringMissingDomain = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("local@")); - attrStringEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); - - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_RFC822NAME_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_RFC822NAME_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_RFC822NAME.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - RFC822Name resValue = (RFC822Name)res.getValue().getValue(); - assertEquals(new RFC822Name("local", "domain"), resValue); - - // caps domain - arguments.clear(); - arguments.add(attrStringCapsDomain); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (RFC822Name)res.getValue().getValue(); - assertEquals(new RFC822Name("local", "domain"), resValue); - - // caps local - arguments.clear(); - arguments.add(attrStringCapsLocal); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (RFC822Name)res.getValue().getValue(); - assertNotEquals(new RFC822Name("local", "domain"), resValue); - - // missing at - arguments.clear(); - arguments.add(attrStringMissingAt); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"localDomain\": missing local part", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // missing local - arguments.clear(); - arguments.add(attrStringMissingLocal); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"@Domain\": empty parts", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // missing domain - arguments.clear(); - arguments.add(attrStringMissingDomain); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"local@\": empty parts", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // empty - arguments.clear(); - arguments.add(attrStringEmpty); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"\": missing local part", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:rfc822Name-from-string Invalid RFC822Name \"not valid obj value\": missing local part", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:rfc822Name-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - @Test - public void testString_from_rfc822Name() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrStringBadType = null; - String objValueString = "local@DOMAIN"; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(objValueString)); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_RFC822NAME; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_RFC822NAME, fd.getId()); - assertEquals(DataTypes.DT_RFC822NAME.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals("local@domain", res.getValue().getValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-rfc822Name Expected data type 'rfc822Name' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - /** - * IPAddress - */ - @Test - public void testIPAddress_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrStringFull = null; - FunctionArgumentAttributeValue attrStringMissingElement = null; - FunctionArgumentAttributeValue attrStringTooManyElement = null; - FunctionArgumentAttributeValue attrStringIllegalElement = null; - FunctionArgumentAttributeValue attrStringOutOfOrder = null; - - FunctionArgumentAttributeValue attrStringMask = null; - FunctionArgumentAttributeValue attrStringMissingMaskElement = null; - FunctionArgumentAttributeValue attrStringTooManyMaskElement = null; - FunctionArgumentAttributeValue attrStringIllegalMaskElement = null; - FunctionArgumentAttributeValue attrStringMaskNoValue = null; - - FunctionArgumentAttributeValue attrStringMinusPort = null; - FunctionArgumentAttributeValue attrStringPortMinus = null; - FunctionArgumentAttributeValue attrStringPortPort = null; - FunctionArgumentAttributeValue attrStringNoPort = null; - FunctionArgumentAttributeValue attrStringBadPort = null; - FunctionArgumentAttributeValue attrStringTooManyPorts = null; - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - - // set up for v4 address tests - this setup and the tests are repeated for V6 - short[] addrShorts= {123, 134, 156, 255 }; - short[] addrMaskShorts= {255, 255, 255, 255 }; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123")); - attrStringFull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/10.11.123.255:123-456")); - attrStringMissingElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.255")); - attrStringTooManyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123.222")); - attrStringIllegalElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.123.255")); - attrStringOutOfOrder = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:123-456/10.11.12.255")); - - attrStringMask = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/10.11.12.255")); - attrStringMissingMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/10.11.123")); - attrStringTooManyMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.255/10.11.12.123.222")); - attrStringIllegalMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/10.11.12.255")); - attrStringMaskNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123/")); - // optional mask - // "/" with no mask (fail) - - attrStringMinusPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:-123")); - attrStringPortMinus = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:123-")); - attrStringPortPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:1234567-432")); - attrStringNoPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:")); - attrStringBadPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:12.34")); - attrStringTooManyPorts = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("10.11.12.123:-123-456")); - - - - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_IPADDRESS_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_IPADDRESS_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_IPADDRESS.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - IPAddress resValue = (IPAddress)res.getValue().getValue(); - assertEquals(new IPv4Address(addrShorts, null, null), resValue); - - // fully-loaded address - arguments.clear(); - arguments.add(attrStringFull); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - try { - assertEquals(new IPv4Address(addrShorts, addrMaskShorts, PortRange.newInstance("123-456")), resValue); - } catch (Exception e) { - fail("port error e="+e); - } - - // missing element - arguments.clear(); - arguments.add(attrStringMissingElement); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.123\": invalid address", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // too many elements - arguments.clear(); - arguments.add(attrStringTooManyElement); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123.222\": invalid address", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // illegal element - arguments.clear(); - arguments.add(attrStringIllegalElement); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123\": invalid octet: \"256", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // Out of order - arguments.clear(); - arguments.add(attrStringOutOfOrder); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123:123-456/10.11.12.255\": out of order components", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // simple mask - arguments.clear(); - arguments.add(attrStringMask); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - try { - assertEquals(new IPv4Address(addrShorts, addrMaskShorts, null), resValue); - } catch (Exception e) { - fail("port error e="+e); - } - - // missing mask element - arguments.clear(); - arguments.add(attrStringMissingMaskElement); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123\": invalid address", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // too many mask elements - arguments.clear(); - arguments.add(attrStringTooManyMaskElement); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123.222\": invalid address", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // illegal Mask element - arguments.clear(); - arguments.add(attrStringIllegalMaskElement); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123\": invalid octet: \"256", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - //mask indicator without value - arguments.clear(); - arguments.add(attrStringMaskNoValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"\": invalid address", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // portrange (-port, port-, port-port) - arguments.clear(); - arguments.add(attrStringMinusPort); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - try { - assertEquals(new IPv4Address(addrShorts, null, PortRange.newInstance("-123")), resValue); - } catch (ParseException e) { - fail("port error e="+e); - } - - arguments.clear(); - arguments.add(attrStringPortMinus); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - try { - assertEquals(new IPv4Address(addrShorts, null, PortRange.newInstance("123-")), resValue); - } catch (ParseException e) { - fail("port error e="+e); - } - - arguments.clear(); - arguments.add(attrStringPortPort); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - try { - assertEquals(new IPv4Address(addrShorts, null, PortRange.newInstance("1234567-432")), resValue); - } catch (ParseException e) { - fail("port error e="+e); - } - - // ":" without port - arguments.clear(); - arguments.add(attrStringNoPort); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv4 address string \"10.11.12.123:\": no portrange given after ':'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // bad port number - arguments.clear(); - arguments.add(attrStringBadPort); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid PortRange \"12.34\": invalid port number", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad port range - arguments.clear(); - arguments.add(attrStringTooManyPorts); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid PortRange \"-123-456\": too many ranges", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Unknown IPAddress type for \"not valid obj value\"", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // - // V6 IP Addresses - // - - // reset the variable for IPv6 tests - FunctionArgumentAttributeValue attrStringAlternateFull = null; - FunctionArgumentAttributeValue attrStringEmptyElement = null; - FunctionArgumentAttributeValue attrString2xEmptyElement = null; - FunctionArgumentAttributeValue attrStringNoStartBracket = null; - FunctionArgumentAttributeValue attrStringNoEndBracket = null; - short[] addrv6Shorts = {(short)0x2001, (short)0xdb8, (short)0x85a3, (short)0x0, (short)0x0, (short)0x8a2e, (short)0x370, (short)0x1}; - Short prefix = new Short((short) 121); - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]")); - attrStringFull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/121]:123-456")); - attrStringAlternateFull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]/121:123-456")); - attrStringEmptyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3::8a2e:370:1]")); - attrString2xEmptyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3::8a2e::1]")); - attrStringNoStartBracket = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("2002:db8:85a3::8a2e::1]")); - attrStringNoEndBracket = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3::8a2e::1")); - - attrStringMissingElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:1]")); - attrStringTooManyElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1:123]")); - attrStringIllegalElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:mnop:85a3:0:0:8a2e:370:1]")); - attrStringOutOfOrder = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:mnop:85a3:0:0:8a2e:370:1:123-456/121]")); - - attrStringMask = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/21]")); - attrStringIllegalMaskElement = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/130]")); - attrStringMaskNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1/]")); - - attrStringMinusPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:-123")); - attrStringPortMinus = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:123-")); - attrStringPortPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:1234567-432")); - attrStringNoPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:")); - attrStringBadPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:12.34")); - attrStringTooManyPorts = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("[2001:db8:85a3:0:0:8a2e:370:1]:-123-456")); - - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - - // test normal - arguments.clear(); - arguments.add(attrString1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - assertEquals(new IPv6Address(addrv6Shorts, null, null), resValue); - - // fully-loaded address - "prefix" is inside the brackets (not clear if this is correct) - arguments.clear(); - arguments.add(attrStringFull); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - try { - assertEquals(new IPv6Address(addrv6Shorts, new Short(prefix), PortRange.newInstance("123-456")), resValue); - } catch (Exception e) { - fail("port error e="+e); - } - - // Alternate way of identifying "prefix" - outside the brackets - arguments.clear(); - arguments.add(attrStringAlternateFull); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - try { - assertEquals(new IPv6Address(addrv6Shorts, prefix, PortRange.newInstance("123-456")), resValue); - } catch (Exception e) { - fail("port error e="+e); - } - - - // consecutive zero elements removed - arguments.clear(); - arguments.add(attrStringEmptyElement); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - try { - assertEquals(new IPv6Address(addrv6Shorts, prefix, null), resValue); - } catch (Exception e) { - fail("port error e="+e); - } - - // consecutive zero elements removed in two locations (no-no) - arguments.clear(); - arguments.add(attrString2xEmptyElement); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:db8:85a3::8a2e::1\": multiple zero runs", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // address must have [] on it - arguments.clear(); - arguments.add(attrStringNoStartBracket); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2002:db8:85a3::8a2e::1]\": missing opening bracket", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrStringNoEndBracket); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"[2001:db8:85a3::8a2e::1\": missing closing bracket", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // missing element - arguments.clear(); - arguments.add(attrStringMissingElement); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:db8:85a3:0:0:8a2e:1\": not enough address fields", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // too many elements - arguments.clear(); - arguments.add(attrStringTooManyElement); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:db8:85a3:0:0:8a2e:370:1:123\"", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // illegal element - arguments.clear(); - arguments.add(attrStringIllegalElement); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv6Address component \"mnop\": invalid hex", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // Out of order - arguments.clear(); - arguments.add(attrStringOutOfOrder); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv6Address string \"2001:mnop:85a3:0:0:8a2e:370:1:123-456\"", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // simple mask - arguments.clear(); - arguments.add(attrStringMask); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - try { - assertEquals(new IPv6Address(addrv6Shorts, prefix, null), resValue); - } catch (Exception e) { - fail("port error e="+e); - } - - // illegal Mask element - arguments.clear(); - arguments.add(attrStringIllegalMaskElement); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid Ipv6Address string \"[2001:db8:85a3:0:0:8a2e:370:1/130]\": prefix is larger than 128", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - //mask indicator without value - arguments.clear(); - arguments.add(attrStringMaskNoValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid Ipv6Address string \"[2001:db8:85a3:0:0:8a2e:370:1/]\": prefix designation without value", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // portrange (-port, port-, port-port) - arguments.clear(); - arguments.add(attrStringMinusPort); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - try { - assertEquals(new IPv6Address(addrv6Shorts, null, PortRange.newInstance("-123")), resValue); - } catch (ParseException e) { - fail("port error e="+e); - } - - arguments.clear(); - arguments.add(attrStringPortMinus); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - try { - assertEquals(new IPv6Address(addrv6Shorts, null, PortRange.newInstance("123-")), resValue); - } catch (ParseException e) { - fail("port error e="+e); - } - - arguments.clear(); - arguments.add(attrStringPortPort); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (IPAddress)res.getValue().getValue(); - try { - assertEquals(new IPv6Address(addrv6Shorts, null, PortRange.newInstance("1234567-432")), resValue); - } catch (ParseException e) { - fail("port error e="+e); - } - - // ":" without port - arguments.clear(); - arguments.add(attrStringNoPort); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid IPv6 address string \"[2001:db8:85a3:0:0:8a2e:370:1]:\": no portrange given after ':'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // bad port number - arguments.clear(); - arguments.add(attrStringBadPort); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid PortRange \"12.34\": invalid port number", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad port range - arguments.clear(); - arguments.add(attrStringTooManyPorts); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:ipAddress-from-string Invalid PortRange \"-123-456\": too many ranges", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - - - - } - - @Test - public void testString_from_ipAddress() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrObjV6 = null; - FunctionArgumentAttributeValue attrStringBadType = null; - String objValueString = "10.11.12.123"; - String objValueStringV6 = "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]"; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_IPADDRESS.createAttributeValue(objValueString)); - attrObjV6 = new FunctionArgumentAttributeValue(DataTypes.DT_IPADDRESS.createAttributeValue(objValueStringV6)); - - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_IPADDRESS; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_IPADDRESS, fd.getId()); - assertEquals(DataTypes.DT_IPADDRESS.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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 V4 - arguments.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(objValueString, res.getValue().getValue()); - - // test normal V6 - arguments.clear(); - arguments.add(attrObjV6); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(objValueStringV6.toLowerCase(), res.getValue().getValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-ipAddress Expected data type 'ipAddress' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - - - - - - - /** - * RFC2396DomainName - */ - @Test - public void testRFC2396DomainName_from_string() { - FunctionArgumentAttributeValue attrString1 = null; - FunctionArgumentAttributeValue attrString2 = null; - FunctionArgumentAttributeValue attrStringMinusPort = null; - FunctionArgumentAttributeValue attrStringPortMinus = null; - FunctionArgumentAttributeValue attrStringPortPort = null; - FunctionArgumentAttributeValue attrStringNoPort = null; - FunctionArgumentAttributeValue attrStringBadPort = null; - FunctionArgumentAttributeValue attrStringTooManyPorts = null; - - FunctionArgumentAttributeValue attrStringBadValue = null; - FunctionArgumentAttributeValue attrStringBadType = null; - try { - attrString1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host")); - attrString2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host")); - - attrStringMinusPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:-123")); - attrStringPortMinus = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:123-")); - attrStringPortPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:1234567-432")); - attrStringNoPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:")); - attrStringBadPort = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:12.34")); - attrStringTooManyPorts = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("host.host:-123-456")); - - attrStringBadValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("not valid obj value")); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_DNSNAME_FROM_STRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DNSNAME_FROM_STRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_DNSNAME.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrString1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - RFC2396DomainName resValue = (RFC2396DomainName)res.getValue().getValue(); - assertEquals(new RFC2396DomainName("host", null), resValue); - - arguments.clear(); - arguments.add(attrString2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (RFC2396DomainName)res.getValue().getValue(); - assertEquals(new RFC2396DomainName("host.host", null), resValue); - - - // portrange (-port, port-, port-port) - arguments.clear(); - arguments.add(attrStringMinusPort); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (RFC2396DomainName)res.getValue().getValue(); - try { - assertEquals(new RFC2396DomainName("host.host", PortRange.newInstance("-123")), resValue); - } catch (ParseException e) { - fail("port error e="+e); - } - - arguments.clear(); - arguments.add(attrStringPortMinus); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (RFC2396DomainName)res.getValue().getValue(); - try { - assertEquals(new RFC2396DomainName("host.host", PortRange.newInstance("123-")), resValue); - } catch (ParseException e) { - fail("port error e="+e); - } - - arguments.clear(); - arguments.add(attrStringPortPort); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (RFC2396DomainName)res.getValue().getValue(); - try { - assertEquals(new RFC2396DomainName("host.host", PortRange.newInstance("1234567-432")), resValue); - } catch (ParseException e) { - fail("port error e="+e); - } - - // ":" without port - arguments.clear(); - arguments.add(attrStringNoPort); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dnsName-from-string Invalid RFC 2396 port range \"host.host:\": no port numbers", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad port number - arguments.clear(); - arguments.add(attrStringBadPort); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dnsName-from-string Invalid RFC 2396 port range \"12.34\"", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad port range - arguments.clear(); - arguments.add(attrStringTooManyPorts); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dnsName-from-string Invalid RFC 2396 port range \"-123-456\"", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad value - arguments.clear(); - arguments.add(attrStringBadValue); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dnsName-from-string Invalid RFC 2396 host name \"not valid obj value\"", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:dnsName-from-string Expected data type 'string' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - @Test - public void testString_from_dnsName() { - FunctionArgumentAttributeValue attrObj1 = null; - FunctionArgumentAttributeValue attrStringBadType = null; - String objValueString = "someName.com"; - try { - attrObj1 = new FunctionArgumentAttributeValue(DataTypes.DT_DNSNAME.createAttributeValue(objValueString)); - attrStringBadType = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(123)); - - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringConversion<?, ?> fd = (FunctionDefinitionStringConversion<?, ?>) StdFunctions.FD_STRING_FROM_DNSNAME; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_FROM_DNSNAME, fd.getId()); - assertEquals(DataTypes.DT_DNSNAME.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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.clear(); - arguments.add(attrObj1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(objValueString, res.getValue().getValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrStringBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-from-dnsName Expected data type 'dnsName' saw 'integer' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - } - - - - - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringEqualIgnoreCaseTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringEqualIgnoreCaseTest.java deleted file mode 100644 index b01c49cc6..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringEqualIgnoreCaseTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionEquality; - -/** - * Only one function to test here. Code copy/pasted from FunctionDefinitionEqualityTest - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * In the first implementation of XACML we had separate files for each XACML Function. - * This release combines multiple Functions in fewer files to minimize code duplication. - * This file supports the following XACML codes: - * string-equal-ignore-case - * - * - */ -public class FunctionDefinitionStringEqualIgnoreCaseTest { - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - FunctionArgumentAttributeValue stringAttr1 = null; - FunctionArgumentAttributeValue stringAttr2 = null; - FunctionArgumentAttributeValue stringAttr3 = null; - FunctionArgumentAttributeValue stringAttr4 = null; - - FunctionArgumentAttributeValue intAttr1 = null; - - public FunctionDefinitionStringEqualIgnoreCaseTest() { - try { - stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); - stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc")); - stringAttr3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ABC")); - stringAttr4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def")); - intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - } - - - /** - * String match even when Case is different - */ - @Test - public void testFunctionDefinitionStringEqualIgnoreCase() { - - FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_STRING_EQUAL_IGNORE_CASE; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_EQUAL_IGNORE_CASE, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - - // test normal equals and non-equals - // check "abc" with "abc" - arguments.add(stringAttr1); - arguments.add(stringAttr2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // check "abc" with "ABC" (should be same) - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(stringAttr3); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // test bad args data types? Not needed? - arguments.clear(); - arguments.add(stringAttr1); - arguments.add(intAttr1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - - -//TODO - null in either first or 2nd arg => NullPointerException - } - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringFunctionsTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringFunctionsTest.java deleted file mode 100644 index 736293580..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringFunctionsTest.java +++ /dev/null @@ -1,1497 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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 org.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionStringFunctions; - -/** - * 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 FunctionDefinitionStringFunctionsTest { - - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - ExpressionResult res; - - - @Test - public void testConcatenate() { - String v1 = new String("abc"); - String v2 = new String("def"); - - FunctionArgumentAttributeValue attrV1 = null; - FunctionArgumentAttributeValue attrV2 = null; - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlank = null; - FunctionArgumentAttributeValue attrInteger = null; - try { - attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); - attrV2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v2)); - attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionStringFunctions<?,?> fd = (FunctionDefinitionStringFunctions<?,?>) StdFunctions.FD_STRING_CONCATENATE; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_CONCATENATE, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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(attrV2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - String resValue = (String)res.getValue().getValue(); - assertEquals(v1 + v2, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrV2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals(v2, resValue); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals(v1, resValue); - - // two blanks - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals("", resValue); - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-concatenate Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-concatenate Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrV2); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-concatenate 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()); - - // null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-concatenate Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - @Test - public void testStringStartsWith() { - String v1 = new String("abc"); - String bigger = new String("abc some string"); - String biggerNoMatch = new String(" abc some string"); - String caps = new String("AbC"); - - FunctionArgumentAttributeValue attrV1 = null; - FunctionArgumentAttributeValue attrBigger = null; - FunctionArgumentAttributeValue attrBiggerNoMatch = null; - FunctionArgumentAttributeValue attrCaps = null; - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlank = null; - FunctionArgumentAttributeValue attrInteger = null; - try { - attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); - attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigger)); - attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(biggerNoMatch)); - attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); - attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionStringFunctions<?,?> fd = (FunctionDefinitionStringFunctions<?,?>) StdFunctions.FD_STRING_STARTS_WITH; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_STARTS_WITH, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // 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(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // no match - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrBiggerNoMatch); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // caps no match - arguments.clear(); - arguments.add(attrCaps); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // bigger on the inside - arguments.clear(); - arguments.add(attrBigger); - arguments.add(attrV1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // two blanks - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-starts-with Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-starts-with Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // illegal arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-starts-with 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 testAnyuriStartsWith() { - - - FunctionArgumentAttributeValue attrV1 = null; - FunctionArgumentAttributeValue attrBigger = null; - FunctionArgumentAttributeValue attrBiggerNoMatch = null; - FunctionArgumentAttributeValue attrCaps = null; - FunctionArgumentAttributeValue attrBigString = null; - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlankString = null; - FunctionArgumentAttributeValue attrBlankURI = null; - FunctionArgumentAttributeValue attrInteger = null; - try { - String v1 = new String("abc"); - URI bigger = new URI("abc.some.string"); - URI biggerNoMatch = new URI("Zabc.some.string"); - String caps = new String("AbC"); - String bigString = "thisIsSomeReallyBigStringToMatch"; - - attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); - attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(bigger)); - attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(biggerNoMatch)); - attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); - attrBigString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigString)); - attrBlankString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); - attrBlankURI = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionStringFunctions<?,?> fd = (FunctionDefinitionStringFunctions<?,?>) StdFunctions.FD_ANYURI_STARTS_WITH; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ANYURI_STARTS_WITH, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // 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(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // no match - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrBiggerNoMatch); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // caps no match - arguments.clear(); - arguments.add(attrCaps); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // bigger on the inside - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlankString); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrBlankURI); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - - // two blanks - arguments.clear(); - arguments.add(attrBlankString); - arguments.add(attrBlankURI); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // arguments reversed - arguments.clear(); - arguments.add(attrBigger); - arguments.add(attrV1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-starts-with 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()); - - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlankURI); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-starts-with Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-starts-with Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // illegal arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-starts-with 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 testStringEndsWith() { - String v1 = new String("abc"); - String bigger = new String("abc some string abc"); - String biggerNoMatch = new String(" abc some string abc "); - String caps = new String("AbC"); - - FunctionArgumentAttributeValue attrV1 = null; - FunctionArgumentAttributeValue attrBigger = null; - FunctionArgumentAttributeValue attrBiggerNoMatch = null; - FunctionArgumentAttributeValue attrCaps = null; - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlank = null; - FunctionArgumentAttributeValue attrInteger = null; - try { - attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); - attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigger)); - attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(biggerNoMatch)); - attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); - attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionStringFunctions<?,?> fd = (FunctionDefinitionStringFunctions<?,?>) StdFunctions.FD_STRING_ENDS_WITH; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_ENDS_WITH, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // 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(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // no match - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrBiggerNoMatch); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // caps no match - arguments.clear(); - arguments.add(attrCaps); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // bigger on the inside - arguments.clear(); - arguments.add(attrBigger); - arguments.add(attrV1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // two blanks - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-ends-with Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-ends-with Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // illegal arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-ends-with 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 testAnyuriEndsWith() { - - - FunctionArgumentAttributeValue attrV1 = null; - FunctionArgumentAttributeValue attrBigger = null; - FunctionArgumentAttributeValue attrBiggerNoMatch = null; - FunctionArgumentAttributeValue attrCaps = null; - FunctionArgumentAttributeValue attrBigString = null; - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlankString = null; - FunctionArgumentAttributeValue attrBlankURI = null; - FunctionArgumentAttributeValue attrInteger = null; - try { - String v1 = new String("abc"); - URI bigger = new URI("abc.some.stringabc"); - URI biggerNoMatch = new URI("Zabc.some.stringabcZ"); - String caps = new String("AbC"); - String bigString = "thisIsSomeReallyBigStringToMatch"; - - attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); - attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(bigger)); - attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(biggerNoMatch)); - attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); - attrBigString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigString)); - attrBlankString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); - attrBlankURI = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionStringFunctions<?,?> fd = (FunctionDefinitionStringFunctions<?,?>) StdFunctions.FD_ANYURI_ENDS_WITH; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ANYURI_ENDS_WITH, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // 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(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // no match - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrBiggerNoMatch); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // caps no match - arguments.clear(); - arguments.add(attrCaps); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // bigger on the inside - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlankString); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrBlankURI); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - - // two blanks - arguments.clear(); - arguments.add(attrBlankString); - arguments.add(attrBlankURI); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // arguments reversed - arguments.clear(); - arguments.add(attrBigger); - arguments.add(attrV1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-ends-with 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()); - - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlankURI); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-ends-with Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-ends-with Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // illegal arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-ends-with 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 testStringSubstring() { - String bigString = new String("abc some string abc"); - - FunctionArgumentAttributeValue attrBigString = null; - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlank = null; - FunctionArgumentAttributeValue attrDouble = null; - - FunctionArgumentAttributeValue attrInteger0 = null; - FunctionArgumentAttributeValue attrInteger1 = null; - FunctionArgumentAttributeValue attrIntegerM1 = null; - FunctionArgumentAttributeValue attrInteger8 = null; - FunctionArgumentAttributeValue attrInteger19 = null; - FunctionArgumentAttributeValue attrInteger20 = null; - - - - try { - attrBigString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigString)); - attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); - attrInteger0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); - attrInteger1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); - attrIntegerM1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1)); - attrInteger8 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(8)); - attrInteger19 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(19)); - attrInteger20 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(20)); - attrDouble = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(123.4)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionStringFunctions<?,?> fd = (FunctionDefinitionStringFunctions<?,?>) StdFunctions.FD_STRING_SUBSTRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_SUBSTRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - - // match - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrInteger1); - arguments.add(attrInteger8); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - String resValue = (String)res.getValue().getValue(); - assertEquals("bc some", resValue); - - // edge: start - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrInteger0); - arguments.add(attrInteger8); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals("abc some", resValue); - - // edge: end - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrInteger8); - arguments.add(attrInteger19); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals(" string abc", resValue); - - // from index to end of string - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrInteger8); - arguments.add(attrIntegerM1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals(" string abc", resValue); - - // first index too low - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrIntegerM1); - arguments.add(attrInteger8); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-substring Start point '-1' out of range 0-19 for string='abc some string abc'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // second index too big - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrInteger8); - arguments.add(attrInteger20); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-substring End point '20' out of range 0-19 for string='abc some string abc'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // indexes reversed - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrInteger8); - arguments.add(attrInteger1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-substring End point '1' less than start point 'null' for string='abc some string abc'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // indexes the same - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrInteger8); - arguments.add(attrInteger8); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals("", resValue); - - // blank string with indexes both 0 - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrInteger0); - arguments.add(attrInteger0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals("", resValue); - - // non-string first attribute - arguments.clear(); - arguments.add(attrDouble); - arguments.add(attrInteger8); - arguments.add(attrInteger1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-substring Expected data type 'string' saw 'double'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // non-integer 2nd attr - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrDouble); - arguments.add(attrInteger1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-substring Expected data type 'integer' saw 'double'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // non-integer 3rd attr - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrInteger8); - arguments.add(attrDouble); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-substring Expected data type 'integer' saw 'double'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // 4 args - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrInteger8); - arguments.add(attrInteger1); - arguments.add(attrInteger1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-substring Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // 2 args - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrInteger8); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-substring Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null 1st arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrInteger8); - arguments.add(attrInteger1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-substring Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // null 2nd arg - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrNull); - arguments.add(attrInteger1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-substring Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - } - - - - - @Test - public void testAnyURISubstring() { - String bigString = new String("http://company.com:8080/this/is/some/long/uri"); - - FunctionArgumentAttributeValue attrURI = null; - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlank = null; - FunctionArgumentAttributeValue attrDouble = null; - - FunctionArgumentAttributeValue attrInteger0 = null; - FunctionArgumentAttributeValue attrInteger1 = null; - FunctionArgumentAttributeValue attrIntegerM1 = null; - FunctionArgumentAttributeValue attrInteger8 = null; - FunctionArgumentAttributeValue attrInteger45 = null; - FunctionArgumentAttributeValue attrInteger46 = null; - - - - try { - attrURI = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(bigString)); - attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(null)); - attrInteger0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); - attrInteger1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); - attrIntegerM1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1)); - attrInteger8 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(8)); - attrInteger45 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(45)); - attrInteger46 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(46)); - attrDouble = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(123.4)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionStringFunctions<?,?> fd = (FunctionDefinitionStringFunctions<?,?>) StdFunctions.FD_ANYURI_SUBSTRING; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ANYURI_SUBSTRING, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - - // match - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrInteger1); - arguments.add(attrInteger8); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - String resValue = (String)res.getValue().getValue(); - assertEquals("ttp://c", resValue); - - // edge: start - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrInteger0); - arguments.add(attrInteger8); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals("http://c", resValue); - - // edge: end - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrInteger8); - arguments.add(attrInteger45); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals("ompany.com:8080/this/is/some/long/uri", resValue); - - // from index to end of string - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrInteger8); - arguments.add(attrIntegerM1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals("ompany.com:8080/this/is/some/long/uri", resValue); - - // first index too low - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrIntegerM1); - arguments.add(attrInteger8); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-substring Start point '-1' out of range 0-45 for string='http://company.com:8080/this/is/some/long/uri'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // second index too big - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrInteger8); - arguments.add(attrInteger46); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-substring End point '46' out of range 0-45 for string='http://company.com:8080/this/is/some/long/uri'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // indexes reversed - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrInteger8); - arguments.add(attrInteger1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-substring End point '1' less than start point 'null' for string='http://company.com:8080/this/is/some/long/uri'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // indexes the same - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrInteger8); - arguments.add(attrInteger8); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals("", resValue); - - // blank string with indexes both 0 - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrInteger0); - arguments.add(attrInteger0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.String.class, res.getValue().getValue().getClass()); - resValue = (String)res.getValue().getValue(); - assertEquals("", resValue); - - // non-string first attribute - arguments.clear(); - arguments.add(attrDouble); - arguments.add(attrInteger8); - arguments.add(attrInteger1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-substring Expected data type 'anyURI' saw 'double'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // non-integer 2nd attr - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrDouble); - arguments.add(attrInteger1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-substring Expected data type 'integer' saw 'double'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // non-integer 3rd attr - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrInteger8); - arguments.add(attrDouble); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-substring Expected data type 'integer' saw 'double'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // 4 args - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrInteger8); - arguments.add(attrInteger1); - arguments.add(attrInteger1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-substring Expected 3 arguments, got 4", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // 2 args - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrInteger8); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-substring Expected 3 arguments, got 2", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null 1st arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrInteger8); - arguments.add(attrInteger1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-substring Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // null 2nd arg - arguments.clear(); - arguments.add(attrURI); - arguments.add(attrNull); - arguments.add(attrInteger1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-substring Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - - - - - - - - - - - - - - - - @Test - public void testStringContains() { - String v1 = new String("abc"); - String bigger = new String("abc some string abc"); - String biggerNoMatch = new String(" abc some string abc "); - String caps = new String("AbC"); - - FunctionArgumentAttributeValue attrV1 = null; - FunctionArgumentAttributeValue attrBigger = null; - FunctionArgumentAttributeValue attrBiggerNoMatch = null; - FunctionArgumentAttributeValue attrCaps = null; - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlank = null; - FunctionArgumentAttributeValue attrInteger = null; - try { - attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); - attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigger)); - attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(biggerNoMatch)); - attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); - attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionStringFunctions<?,?> fd = (FunctionDefinitionStringFunctions<?,?>) StdFunctions.FD_STRING_CONTAINS; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_CONTAINS, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // 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(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // no match - arguments.clear(); - arguments.add(attrBiggerNoMatch); - arguments.add(attrV1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // caps no match - arguments.clear(); - arguments.add(attrCaps); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // bigger on the inside - arguments.clear(); - arguments.add(attrBigger); - arguments.add(attrV1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // two blanks - arguments.clear(); - arguments.add(attrBlank); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlank); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-contains Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-contains Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // illegal arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:string-contains 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 testAnyuriContains() { - - - FunctionArgumentAttributeValue attrV1 = null; - FunctionArgumentAttributeValue attrBigger = null; - FunctionArgumentAttributeValue attrBiggerNoMatch = null; - FunctionArgumentAttributeValue attrCaps = null; - FunctionArgumentAttributeValue attrBigString = null; - FunctionArgumentAttributeValue attrNull = null; - FunctionArgumentAttributeValue attrBlankString = null; - FunctionArgumentAttributeValue attrBlankURI = null; - FunctionArgumentAttributeValue attrInteger = null; - try { - String v1 = new String("abc"); - URI bigger = new URI("abc.some.stringabc"); - URI biggerNoMatch = new URI("Zabc.some.stringabcZ"); - String caps = new String("AbC"); - String bigString = "thisIsSomeReallyBigStringToMatch"; - - attrV1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(v1)); - attrBigger = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(bigger)); - attrBiggerNoMatch = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(biggerNoMatch)); - attrCaps = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(caps)); - attrBigString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(bigString)); - attrBlankString = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); - attrBlankURI = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("")); - attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(null)); - attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionStringFunctions<?,?> fd = (FunctionDefinitionStringFunctions<?,?>) StdFunctions.FD_ANYURI_CONTAINS; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ANYURI_CONTAINS, fd.getId()); - assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); - - // 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(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // no match - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrBiggerNoMatch); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // caps no match - arguments.clear(); - arguments.add(attrCaps); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // bigger on the inside - arguments.clear(); - arguments.add(attrBigString); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - // empty non-null first arg - arguments.clear(); - arguments.add(attrBlankString); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // empty non-null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrBlankURI); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(false, resValue); - - - // two blanks - arguments.clear(); - arguments.add(attrBlankString); - arguments.add(attrBlankURI); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.lang.Boolean.class, res.getValue().getValue().getClass()); - resValue = (Boolean)res.getValue().getValue(); - assertEquals(true, resValue); - - // arguments reversed - arguments.clear(); - arguments.add(attrBigger); - arguments.add(attrV1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-contains 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()); - - - // null firat arg - arguments.clear(); - arguments.add(attrNull); - arguments.add(attrBlankURI); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-contains Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null second arg - arguments.clear(); - arguments.add(attrV1); - arguments.add(attrNull); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-contains Got null attribute", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // illegal arg type - arguments.clear(); - arguments.add(attrInteger); - arguments.add(attrBigger); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:anyURI-contains 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()); - - } - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringNormalizeTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringNormalizeTest.java deleted file mode 100644 index 0071a7020..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionStringNormalizeTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionStringNormalize; - -/** - * 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 FunctionDefinitionStringNormalizeTest { - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - @Test - public void testString_normalize_space() { - String initialString = " First and last are whitespace "; - FunctionArgumentAttributeValue attr1 = null; - try { - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(initialString)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringNormalize fd = (FunctionDefinitionStringNormalize) StdFunctions.FD_STRING_NORMALIZE_SPACE; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_NORMALIZE_SPACE, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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()); - String resValue = (String)res.getValue().getValue(); - assertEquals(initialString.length() - 4, resValue.length()); - assertTrue(initialString.trim().equals(resValue)); - } - - - @Test - public void testString_normalize_to_lower_case() { - String initialString = " First and last are whitespace "; - FunctionArgumentAttributeValue attr1 = null; - try { - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(initialString)); - } catch (Exception e) { - fail("creating attribute e="+ e); - } - - FunctionDefinitionStringNormalize fd = (FunctionDefinitionStringNormalize) StdFunctions.FD_STRING_NORMALIZE_TO_LOWER_CASE; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_STRING_NORMALIZE_TO_LOWER_CASE, fd.getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); - - // 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()); - String resValue = (String)res.getValue().getValue(); - assertTrue(initialString.toLowerCase().equals(resValue)); - } - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionURIStringConcatenateTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionURIStringConcatenateTest.java deleted file mode 100644 index e1e91a79e..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionURIStringConcatenateTest.java +++ /dev/null @@ -1,185 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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 org.junit.Test; - -import com.att.research.xacml.api.XACML2; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionURIStringConcatenate; - -/** - * 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 FunctionDefinitionURIStringConcatenateTest { - - /* - * THE FUNCTION BEING TESTED BY THIS CLASS IS DEPRECATED - * uri-string-concatenate has been deprecated in XACML 3.0 - */ - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - - @SuppressWarnings("deprecation") - @Test - public void testURI_string_concatenate() { - - // URI args - FunctionArgumentAttributeValue attrURI1 = null; - - - FunctionArgumentAttributeValue attrStrAbc = null; - FunctionArgumentAttributeValue attrStrSlashMno = null; - FunctionArgumentAttributeValue attrStrSlashInMiddle = null; - FunctionArgumentAttributeValue attrStrWithSpace = null; - - - try { - attrURI1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue("http://someplace")); - - - attrStrAbc = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("Abc")); - attrStrSlashMno = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("/Mno")); - attrStrSlashInMiddle = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("hij/pqr")); - attrStrWithSpace = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("x y z")); - - - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - // deprecation marking in the following line is correct - this function IS deprecated but still valid for XACML 3.0 - FunctionDefinitionURIStringConcatenate fd = (FunctionDefinitionURIStringConcatenate) StdFunctions.FD_URI_STRING_CONCATENATE; - - // check identity and type of the thing created - assertEquals(XACML2.ID_FUNCTION_URI_STRING_CONCATENATE, fd.getId()); - assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - - - // add one string to uri - arguments.clear(); - arguments.add(attrURI1); - arguments.add(attrStrAbc); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.net.URI.class, res.getValue().getValue().getClass()); - URI resValue = (URI)res.getValue().getValue(); - assertEquals("http://someplaceAbc", resValue.toString()); - - - // add 2 strings to uri - arguments.clear(); - arguments.add(attrURI1); - arguments.add(attrStrAbc); - arguments.add(attrStrSlashMno); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.net.URI.class, res.getValue().getValue().getClass()); - resValue = (URI)res.getValue().getValue(); - assertEquals("http://someplaceAbc/Mno", resValue.toString()); - - // slash in middle of string - arguments.clear(); - arguments.add(attrURI1); - arguments.add(attrStrSlashInMiddle); - arguments.add(attrStrSlashMno); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - assertEquals(java.net.URI.class, res.getValue().getValue().getClass()); - resValue = (URI)res.getValue().getValue(); - assertEquals("http://someplacehij/pqr/Mno", resValue.toString()); - - // create bad uri - arguments.clear(); - arguments.add(attrURI1); - arguments.add(attrStrWithSpace); - arguments.add(attrStrSlashMno); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:uri-string-concatenate Final string 'http://someplacex y z/Mno' not URI, Illegal character in authority at index 7: http://someplacex y z/Mno", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no args - arguments.clear(); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:uri-string-concatenate Expected 2 or more arguments, got 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // one arg - arguments.clear(); - arguments.add(attrURI1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:uri-string-concatenate Expected 2 or more arguments, got 1", 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(attrStrAbc); - arguments.add(attrURI1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:uri-string-concatenate Expected data type 'anyURI' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // 2nd arg not string - arguments.clear(); - arguments.add(attrURI1); - arguments.add(attrURI1); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:uri-string-concatenate Expected data type 'string' saw 'anyURI' at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionXPathTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionXPathTest.java deleted file mode 100644 index 5b6c97de1..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionXPathTest.java +++ /dev/null @@ -1,1127 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.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.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.xml.namespace.NamespaceContext; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathFactory; - -import org.junit.Test; - -import com.att.research.xacml.api.Request; -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.IdentifierImpl; -import com.att.research.xacml.std.StdRequest; -import com.att.research.xacml.std.StdStatus; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacml.std.datatypes.XPathExpressionWrapper; -import com.att.research.xacml.std.dom.DOMRequest; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdEvaluationContext; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionXPath; - -/** - * 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 FunctionDefinitionXPathTest { - - // - // 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 reqStrContentMdRecord = - " <Content>" + - "<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>" + - "</Content>"; - String reqStrMalformedContent = - " <Content>" + - "<md:record>" + - "<md:hospital_info>" + - "<md:name>ABC Hospital</md:name>" + - "<md:malignancy type=\"yes\"/>" + - "</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\">"; - - 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> "; - 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; - - - /* - * variables useful in the following tests - */ - List<FunctionArgument> arguments = new ArrayList<FunctionArgument>(); - - - - // Name Spaces used in the XML as part of these examples (copied from the Conformance tests) - 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)) { - 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; - } - }; - - - - // - // XPath Function Attributes available for use in tests (representing appropriate fragment of Policy) - // - - FunctionArgumentAttributeValue attrXnull = null; - FunctionArgumentAttributeValue attrXEmpty = null; - FunctionArgumentAttributeValue attrXNoCategory = null; - FunctionArgumentAttributeValue attrXNoValue = null; - FunctionArgumentAttributeValue attrXSlashSlashMdRecord = null; - FunctionArgumentAttributeValue attrXSlashSlashStar = null; - FunctionArgumentAttributeValue attrXSlashSlashMdName = null; - FunctionArgumentAttributeValue attrXSlashSlashMdMalignancy = null; - FunctionArgumentAttributeValue attrXNotInRequest = null; - FunctionArgumentAttributeValue attrXSlashSlashMdRecordSlashStar = null; - FunctionArgumentAttributeValue attrXMdPatientInfo = null; - - FunctionArgumentAttributeValue attrBadType = null; - - // String version of attrs for use in Deprecated functions - FunctionArgumentAttributeValue attrStrnull = null; - FunctionArgumentAttributeValue attrStrEmpty = null; - FunctionArgumentAttributeValue attrStrNoCategory = null; - FunctionArgumentAttributeValue attrStrNoValue = null; - FunctionArgumentAttributeValue attrStrSlashSlashMdRecord = null; - FunctionArgumentAttributeValue attrStrSlashSlashStar = null; - FunctionArgumentAttributeValue attrStrSlashSlashMdName = null; - FunctionArgumentAttributeValue attrStrSlashSlashMdMalignancy = null; - FunctionArgumentAttributeValue attrStrNotInRequest = null; - FunctionArgumentAttributeValue attrStrSlashSlashMdRecordSlashStar = null; - FunctionArgumentAttributeValue attrStrMdPatientInfo = null; - - - // - // REQUEST objects available for use in tests - // - Request requestEmpty = new StdRequest(StdStatus.STATUS_OK); - Request requestMdRecord = null; - Request requestDoubleResources = 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 FunctionDefinitionXPathTest() { - try { - XPathFactory xPathFactory = XPathFactory.newInstance(); - XPath xpath = xPathFactory.newXPath(); - xpath.setNamespaceContext(nameSpaceContext); - - // Create XPaths to use in expressions - XPathExpressionWrapper xEmpty = new XPathExpressionWrapper(""); - XPathExpressionWrapper xSlashSlashMdRecord = new XPathExpressionWrapper(xpath.compile("//md:record")); - XPathExpressionWrapper xSlashSlashStar = new XPathExpressionWrapper(xpath.compile("//*")); - XPathExpressionWrapper xSlashSlashMdName = new XPathExpressionWrapper(xpath.compile("//md:name")); - XPathExpressionWrapper xSlashSlashMdMalignancy = new XPathExpressionWrapper(xpath.compile("//md:malignancy")); - XPathExpressionWrapper xNotInRequest = new XPathExpressionWrapper(xpath.compile("value_Not_in_request")); - XPathExpressionWrapper xSlashSlashMdRecordSlashStar = new XPathExpressionWrapper(xpath.compile("//md:record/*")); - XPathExpressionWrapper xMdPatientInfo = new XPathExpressionWrapper(xpath.compile("md:patient_info")); - - - - // create Function Attributes out of the XPathExpressions - attrXnull = new FunctionArgumentAttributeValue(null); - attrXEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xEmpty)); - attrXNoCategory = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdRecord)); - attrXNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xEmpty, - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - attrXSlashSlashMdRecord = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdRecord, - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - attrXSlashSlashStar = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashStar, - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - attrXSlashSlashMdName = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdName, - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - attrXSlashSlashMdMalignancy = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdMalignancy, - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - attrXNotInRequest = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xNotInRequest, - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - - attrXSlashSlashMdRecordSlashStar = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xSlashSlashMdRecordSlashStar, - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - attrXMdPatientInfo = new FunctionArgumentAttributeValue(DataTypes.DT_XPATHEXPRESSION.createAttributeValue(xMdPatientInfo, - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - - - // Deprecated versions of args - attrStrnull = new FunctionArgumentAttributeValue(null); - attrStrEmpty = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("")); - attrStrNoCategory = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:record")); - attrStrNoValue = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("", - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - attrStrSlashSlashMdRecord = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:record", - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - attrStrSlashSlashStar = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//*", - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - attrStrSlashSlashMdName = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:name", - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - attrStrSlashSlashMdMalignancy = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:malignancy", - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - attrStrNotInRequest = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("value_Not_in_request", - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - - attrStrSlashSlashMdRecordSlashStar = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("//md:record/*", - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - attrStrMdPatientInfo = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("md:patient_info", - new IdentifierImpl("urn:oasis:names:tc:xacml:3.0:attribute-category:resource" ))); - - - - - attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("some string")); - - - - // 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. - - // single Content in the Resources section (normal valid request) - String reqString = reqStrMainResourceStart + reqStrContentMdRecord + 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 + reqStrContentMdRecord + reqStrResourceEnd + reqStrResourceStart + reqStrContentMdRecord +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 in both Resource and Action - ok - reqString = reqStrMainResourceStart + reqStrContentMdRecord + reqStrResourceEnd + reqStrActionStart + reqStrContentMdRecord + 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 + reqStrContentMdRecord + 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; - @SuppressWarnings("unused") - Request requestDoubleContent = null; - - - // Content included twice - error - reqString = reqStrMainResourceStart + reqStrContentMdRecord + reqStrContentMdRecord +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 (com.att.research.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); - } - - // Bad XML - Content not under a Category - reqString = reqStrMainStart + reqStrContentMdRecord + 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 (com.att.research.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); - } - - // 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 (com.att.research.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); - } - - } catch (Exception e) { - fail("Constructor initializing variables, e="+ e + " cause="+e.getCause()); - } - - } - - - - - - - - - @Test - public void testXpath_node_count() { - - - - FunctionDefinitionXPath<?> fd = (FunctionDefinitionXPath<?>) StdFunctions.FD_XPATH_NODE_COUNT; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_XPATH_NODE_COUNT, fd.getId()); - assertEquals(DataTypes.DT_XPATHEXPRESSION.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 - assertFalse(fd.returnsBag()); - assertEquals(new Integer(1), fd.getNumArgs()); - - - // match all elements within context - arguments.clear(); - arguments.add(attrXSlashSlashStar); - ExpressionResult res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - BigInteger resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("18"), resValue); - - // match exactly 1 element - arguments.clear(); - arguments.add(attrXSlashSlashMdMalignancy); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("1"), resValue); - - // match a few but not all - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("2"), resValue); - - - // verify variables using in other tests: count nodes immediately under md:record - arguments.clear(); - arguments.add(attrXSlashSlashMdRecordSlashStar); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("3"), resValue); - - // verify variables using in other tests: count number of records containing patient_info - arguments.clear(); - arguments.add(attrXMdPatientInfo); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("1"), resValue); - - // verify variables using in other tests: count number of records containing md:name - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("2"), resValue); - - // verify variables using in other tests: count number of records containing md:malignancy - arguments.clear(); - arguments.add(attrXSlashSlashMdMalignancy); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("1"), resValue); - - - - - // match no element - arguments.clear(); - arguments.add(attrXNotInRequest); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("0"), resValue); - - // Resources included twice - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestDoubleResources, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-count More than one Content section for id 'urn:oasis:names:tc:xacml:3.0:attribute-category:resource'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // Content in both Resource and Action categories (ok) - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestResourceActionContent, null, null), arguments); - assertTrue(res.isOk()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("2"), resValue); - - // Content only in Action category (missing in Resources -> 0 according to spec) - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestContentInAction, null, null), arguments); - assertTrue(res.isOk()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("0"), resValue); - - - - -//TODO - any other tests???? - - // null Evaluation Context - arguments.clear(); - arguments.add(attrXEmpty); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-count Got null EvaluationContext", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null Request - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-count Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null attribute - arguments.clear(); - arguments.add(attrXnull); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-count Got null attribute at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no value - arguments.clear(); - arguments.add(attrXNoValue); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-count XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no category - arguments.clear(); - arguments.add(attrXNoCategory); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-count Got null Category at index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // too many args - arguments.clear(); - arguments.add(attrXEmpty); - arguments.add(attrXEmpty); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-count Expected 1 arguments, got 2", 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(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-count Expected 1 arguments, got 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-count Expected data type 'xpathExpression' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null args - arguments.clear(); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-count Got null argument at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - @Test - public void testXpath_node_equal() { - - - FunctionDefinitionXPath<?> fd = (FunctionDefinitionXPath<?>) StdFunctions.FD_XPATH_NODE_EQUAL; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_XPATH_NODE_EQUAL, fd.getId()); - assertEquals(DataTypes.DT_XPATHEXPRESSION.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 - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - // test normal success - exactly the same set - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - arguments.add(attrXSlashSlashMdName); - ExpressionResult res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // success - second list is subset of first list - arguments.clear(); - arguments.add(attrXSlashSlashMdRecordSlashStar); - arguments.add(attrXMdPatientInfo); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // success - first list is subset of second list - arguments.clear(); - arguments.add(attrXMdPatientInfo); - arguments.add(attrXSlashSlashMdRecordSlashStar); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // success - second list contains children of first list - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // success - first list contains children of second list - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - - - // two non-overlapping sets - arguments.clear(); - arguments.add(attrXSlashSlashMdMalignancy); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first list contains nothing - arguments.clear(); - arguments.add(attrXNotInRequest); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // second list contains nothing - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - arguments.add(attrXNotInRequest); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - - -//TODO - //????? - ///??????? add real tests - ////// - - - // Resources included twice - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestDoubleResources, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal More than one Content section for id 'urn:oasis:names:tc:xacml:3.0:attribute-category:resource'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - - // Content in both Resource and Action categories (ok) - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestResourceActionContent, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // Content only in Action category (missing in Resources -> 0 according to spec) - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestContentInAction, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - - // null Evaluation Context - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal Got null EvaluationContext", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null Request - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null attribute - arguments.clear(); - arguments.add(attrXnull); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal Got null attribute at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - arguments.add(attrXnull); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal Got null attribute at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no value - arguments.clear(); - arguments.add(attrXNoValue); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - arguments.add(attrXNoValue); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no category - arguments.clear(); - arguments.add(attrXNoCategory); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal Got null Category at index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - arguments.add(attrXNoCategory); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal XPathExpression returned null at index 0", 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(attrXEmpty); - arguments.add(attrXEmpty); - arguments.add(attrXEmpty); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal Expected 2 arguments, got 3", 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(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal 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(attrXEmpty); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrBadType); - arguments.add(attrXEmpty); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal Expected data type 'xpathExpression' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrXEmpty); - arguments.add(attrBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal Expected data type 'xpathExpression' saw 'string' at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null args - arguments.clear(); - arguments.add(attrXEmpty); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal Got null argument at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(null); - arguments.add(attrXEmpty); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-equal Got null argument at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - @Test - public void testXpath_node_match() { - - - FunctionDefinitionXPath<?> fd = (FunctionDefinitionXPath<?>) StdFunctions.FD_XPATH_NODE_MATCH; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_XPATH_NODE_MATCH, fd.getId()); - assertEquals(DataTypes.DT_XPATHEXPRESSION.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 - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - // test normal success - exactly the same set - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - arguments.add(attrXSlashSlashMdName); - ExpressionResult res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - Boolean resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // success - second list is subset of first list - arguments.clear(); - arguments.add(attrXSlashSlashMdRecordSlashStar); - arguments.add(attrXMdPatientInfo); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // success - first list is subset of second list - arguments.clear(); - arguments.add(attrXMdPatientInfo); - arguments.add(attrXSlashSlashMdRecordSlashStar); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // success - second list contains children of first list - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // success - first list contains children of second list - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - - - // two non-overlapping sets - arguments.clear(); - arguments.add(attrXSlashSlashMdMalignancy); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // first list contains nothing - arguments.clear(); - arguments.add(attrXNotInRequest); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - // second list contains nothing - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - arguments.add(attrXNotInRequest); - res = fd.evaluate(new StdEvaluationContext(requestMdRecord, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - -//TODO - //????? - ///??????? add real tests - ////// - - - // Resources included twice - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestDoubleResources, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match More than one Content section for id 'urn:oasis:names:tc:xacml:3.0:attribute-category:resource'", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - // Content in both Resource and Action categories (ok) - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestResourceActionContent, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertTrue(resValue); - - // Content only in Action category (missing in Resources -> 0 according to spec) - arguments.clear(); - arguments.add(attrXSlashSlashMdName); - arguments.add(attrXSlashSlashMdName); - res = fd.evaluate(new StdEvaluationContext(requestContentInAction, null, null), arguments); - assertTrue(res.isOk()); - resValue = (Boolean)res.getValue().getValue(); - assertFalse(resValue); - - - // null Evaluation Context - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match Got null EvaluationContext", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null Request - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(new StdEvaluationContext(null, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match Got null Request in EvaluationContext", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null attribute - arguments.clear(); - arguments.add(attrXnull); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match Got null attribute at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - arguments.add(attrXnull); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match Got null attribute at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no value - arguments.clear(); - arguments.add(attrXNoValue); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - arguments.add(attrXNoValue); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match XPathExpression returned null at index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // no category - arguments.clear(); - arguments.add(attrXNoCategory); - arguments.add(attrXSlashSlashMdRecord); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match Got null Category at index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:syntax-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrXSlashSlashMdRecord); - arguments.add(attrXNoCategory); - res = fd.evaluate(new StdEvaluationContext(requestEmpty, null, null), arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match XPathExpression returned null at index 0", 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(attrXEmpty); - arguments.add(attrXEmpty); - arguments.add(attrXEmpty); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match Expected 2 arguments, got 3", 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(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match 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(attrXEmpty); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match Expected 2 arguments, got 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // bad arg type - arguments.clear(); - arguments.add(attrBadType); - arguments.add(attrXEmpty); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match Expected data type 'xpathExpression' saw 'string' at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(attrXEmpty); - arguments.add(attrBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match Expected data type 'xpathExpression' saw 'string' at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - // null args - arguments.clear(); - arguments.add(attrXEmpty); - arguments.add(null); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match Got null argument at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - arguments.clear(); - arguments.add(null); - arguments.add(attrXEmpty); - res = fd.evaluate(null, arguments); - assertFalse(res.getStatus().isOk()); - assertEquals( "function:xpath-node-match Got null argument at arg index 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - - - } - - - - // - // DEPRECATED versions that use String arguments rather than XPATHEXPRESSIONs - // are NOT supported due to ambiguity in the semantics between 2.0 (<Request> is root and has only one <Content> in resources) - // and 3.0 (<Content> is root and there are multiple <Content> sections in any category) - // - - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestCategoryTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestCategoryTest.java deleted file mode 100644 index 0afde1729..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestCategoryTest.java +++ /dev/null @@ -1,4174 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.json; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import org.junit.Test; - -import com.att.research.xacml.api.Request; -import com.att.research.xacml.std.json.JSONRequest; -import com.att.research.xacml.std.json.JSONStructureException; - -/** - * Test JSON Request convert to object - Category sub-component. Does not include "Default" Categories (Subject, Action, Resource, Environment). - * Basic existance/absence of Category is tested in RequestMainTest. - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * NOTE: - * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects - * and verify that they are correct. This would involve a lot of coding to get child of child of child and individually verify each property of each element. - * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object - * and we compare the resulting String to our expected String. - * This has two possible sources of error: - * - toString might not include some sub-component, and - * - the initial verification of the resulting string is done by hand and may have been incorrect. - * - * - */ -public class RequestCategoryTest { - - // The request object output from each test conversion from JSON string - Request request; - - - /* - * Request that uses all fields with both single and multiple entries - */ - String allFieldsRequest = - "{\"Request\": {" + - "\"ReturnPolicyIdList\" : true ," + - "\"CombinedDecision\" : true ," + - "\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"," + - "\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{ " + - "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + - "}," + - "{" + - "\"ReferenceId\" : [\"foo2\",\"bar1\"]" + - "}]" + - "}," + - - "\"Category\": [" + - "{ " + - "\"CategoryId\": \"custom-category\", " + - "\"Id\" : \"customId\", " + - "\"Attribute\" : [" + - "{" + - "\"AttributeId\" : \"document-id\", " + - "\"DataType\" : \"integer\", " + - "\"Value\" : 123 " + - "}, " + - "{" + - "\"AttributeId\" : \"document-url\", " + - "\"DataType\" : \"anyURI\", " + - "\"Value\" : \"http://somewhere.over.the.com/rainbow\" " + - "}, " + - "{" + - "\"AttributeId\" : \"page-list\", " + - "\"Value\" : [1, 2, 3, 4.5, 3, 2, 1] " + - "} " + - "]" + - "}, " + - "{ " + - "\"CategoryId\": \"another-custom-cat\", " + - "\"Id\" : \"anotherXmlId\", " + - "\"Attribute\" : []" + - "} " + - "], " + - - "\"AccessSubject\":{ " + - "\"Content\" : \"<?xml version=\\\"1.0\\\"?><catalog>" + - "<book id=\\\"bk101\\\"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre>" + - "<price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description>"+ - "</book></catalog>\"," + - "\"Attribute\" : []" + - "}, " + - - "\"Resource\" : {" + - "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" + - "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+ - "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" + - - - "} " + - - - "}}"; - - /* - * The following example comes directly from the JSON Profile Spec - */ - String exampleFromSpec = "{ " + - "\"Request\" : { " + - "\"AccessSubject\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "}, " + - "\"Action\" : { " + - "\"Attribute\": " + - "{ " + - "\"Id\" : \"action-id\", " + - "\"Value\" : \"http://www.xacml.eu/buy\", " + - "\"DataType\" : \"anyURI\" " + - "} " + - "}, " + - "\"Resource\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"book-title\", " + - "\"Value\" : \"Learn German in 90 days\" " + - "}, " + - "{ " + - "\"Id\" : \"currency\", " + - "\"Value\" : \"SEK\" " + - "}, " + - "{ " + - "\"Id\" : \"price\", " + - "\"Value\" : 123.34 " + - "} " + - "] " + - "} " + - "} " + - "} "; - - - /* - * The following example comes directly from the JSON Profile Spec (modified to include a "</Catalog>" missing from both examples). - * It shows the two ways of handling XPath content, as escaped XML and as Base64 encoding. - */ - String xPathExampleFromSpec = "{ " + - "\"Request\" : { " + - "\"Resource\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"urn:oasis:names:tc:xacml:3.0:content-selector\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : { " + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", " + - "\"Namespaces\" : [{ " + - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}, " + - "{ " + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "} " + - "], " + - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" " + - "} " + - "} " + - "] " + - "} " + - "} " + - "} "; - - - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - // Top-level of Category - @Test - public void testCategoryTopLevel() { - - // empty Category - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Missing value - try { - request = JSONRequest.load("{\"Request\" : {\"Category\" }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\" : }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category without CategoryId - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{}] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category with CategoryId value missing or ="" - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\"] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"\" ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // CategoryId wrong type - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : true } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : 123 } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category with Id - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Id\" : \"customId\" } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category},xmlId=customId}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category with Id - wrong type - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Id\" : true } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Id\" : 123 } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Category without Id - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\" } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Category with standard CategoryId - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\" } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category with extra unknown field - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", unknown } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"unknown\" : 123 } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category with multiple sub-Category objects using same CategoryId - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"category1\" }, {\"CategoryId\" : \"category1\" } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=category1}}{super={category=category1}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - } - - - - // Tests related to Attributes - @Test - public void testCategoryAttributes() { - - // Category with Attribute but none given ("Attribute" : [] ) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with empty attribute (missing both AttributeId and Id) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with AttributeId and no Value - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"AttributeId\" : \"document-id\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute missing AttributeId but with Id - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"AttributeId\" : \"document-id\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute missing AttributeId but with Id - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute including both AttributeId and Id with same value - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"AttributeId\" : \"document-id\", " + - "\"Id\" : \"document-id\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute missing both AttributeId and Id - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Value\" : 123 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute AttributeId not string - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"AttributeId\" : true, " + - "\"Value\" : 123 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"AttributeId\" : 123, " + - "\"Value\" : 123 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute Id not string - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : true, " + - "\"Value\" : 123 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : 123, " + - "\"Value\" : 123 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Category Attribute with DataType - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"integer\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with DataType not string (e.g. "DataType" : 55.5 ) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : true, " + - "\"Value\" : 123 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with unknown DataType - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"no such data type\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : 321, " + - "\"Value\" : 123 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with multiple value array - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"dayTimeDuration\", " + - "\"Value\" : [\"P3D\", \"P2DT12H34M\", \"PT15M\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=3hours=0minutes=0seconds=0millis=0},factionalSeconds=0.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=2hours=12minutes=34seconds=0millis=0},factionalSeconds=0.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=0hours=0minutes=15seconds=0millis=0},factionalSeconds=0.0}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute multiple value with null in array - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"dayTimeDuration\", " + - "\"Value\" : [\"P3D\", , \"P15M\"] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with array value with no values ("Attribute": [ {"AttributeId" :"a", Value:[] } ] } ) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"dayTimeDuration\", " + - "\"Value\" : [ ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with no DataType and array with no values - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with Issuer - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Issuer\" : \"University Press\", " + - "\"DataType\" : \"integer\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],issuer=University Press,includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with Issuer not string - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Issuer\" : true, " + - "\"DataType\" : \"integer\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Issuer\" : 4.56, " + - "\"DataType\" : \"integer\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with includeInResult=true - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : 123, " + - "\"IncludeInResult\" : true " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=true}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with includeInResult = false - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : 123, " + - "\"IncludeInResult\" : false " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with includeInResult not boolean - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : 123, " + - "\"IncludeInResult\" : \"abc\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : 123, " + - "\"IncludeInResult\" : 123.45 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - } - - - - // Tests related to DataTypes within Attributes - @Test - public void testCategoryAttributesDataTypesSimple() { - - // Category Attribute using full Identifier for each data type - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : \"abc\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + - "\"Value\" : true " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + - "\"Value\" : 123.34 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + - "\"Value\" : \"12:00:00Z\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + - "\"Value\" : \"2002-10-10\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + - "\"Value\" : \"2002-10-10T12:00:00Z\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + - "\"Value\" : \"P23DT7H12M54S\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + - "\"Value\" : \"P165Y8M\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + - "\"Value\" : \"aValue\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + - "\"Value\" : \"FA027B7D12CC34DDD20012AEEF\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + - "\"Value\" : \"lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9y\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,-46,35,18,-29,2,35,-13,-29,-58,54,23,70,22,-58,-10,115,-29,-58,38,-10,-10,-78,6,-106,67,-46,38,38,-77,19,3,18,35,-29,-58,23,87,70,-122,-9]}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + - "\"Value\" : \"someone.else@A.COMPANY.com\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=someone.else,domainName=A.COMPANY.com}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + - "\"Value\" : \"cn=Julius Hibbert, o=Medi Corporation, c=US\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + - "\"Value\" : \"10.221.43.58:12345\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + - "\"Value\" : \"aValue\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); - - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Category Attribute shorthand notation for each data type - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"string\", " + - "\"Value\" : \"abc\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"boolean\", " + - "\"Value\" : true " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"integer\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"double\", " + - "\"Value\" : 123.34 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"time\", " + - "\"Value\" : \"12:00:00Z\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"date\", " + - "\"Value\" : \"2002-10-10\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"dateTime\", " + - "\"Value\" : \"2002-10-10T12:00:00Z\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"dayTimeDuration\", " + - "\"Value\" : \"P23DT7H12M54S\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"yearMonthDuration\", " + - "\"Value\" : \"P165Y8M\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"anyURI\", " + - "\"Value\" : \"aValue\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"hexBinary\", " + - "\"Value\" : \"FA027B7D12CC34DDD20012AEEF\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"base64Binary\", " + - "\"Value\" : \"lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9y\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,-46,35,18,-29,2,35,-13,-29,-58,54,23,70,22,-58,-10,115,-29,-58,38,-10,-10,-78,6,-106,67,-46,38,38,-77,19,3,18,35,-29,-58,23,87,70,-122,-9]}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"rfc822Name\", " + - "\"Value\" : \"someone.else@A.COMPANY.com\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=someone.else,domainName=A.COMPANY.com}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"x500Name\", " + - "\"Value\" : \"cn=Julius Hibbert, o=Medi Corporation, c=US\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"ipAddress\", " + - "\"Value\" : \"10.221.43.58:12345\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"dnsName\", " + - "\"Value\" : \"aValue\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); - - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - - // infer data type - only integer, boolean and double are distinguishable from strings; everything else is treated as a string - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"abc\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : true " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : 123.34 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"12:00:00Z\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"2002-10-10\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"2002-10-10T12:00:00Z\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"P23DT7H12M54S\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"P165Y8M\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"FA027B7D12CC34DDD20012AEEF\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9y\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"someone.else@A.COMPANY.com\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.COMPANY.com}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + - "\"Value\" : \"cn=Julius Hibbert, o=Medi Corporation, c=US\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"10.221.43.58:12345\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - // gets inferred to a String containing the whole structure under Value as a String - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value={XPathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource, Namespaces=[{Namespace=urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}, {Prefix=md, Namespace=urn:example:med:schemas:record}], XPath=md:record/md:patient/md:patientDoB}}],includeInResults=false}]}}]}", request.toString()); - - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - } - - - - @Test - public void testCategoryAttributesDataTypesNotMatchValue() { - - // Category Attribute with DataType not matching value type (JSON type derived from syntax) - // AUTO-CONVERSION from Boolean to String! - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : true " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // SUCCESSFUL AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // SUCCESSFUL AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : 123.34 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123.34}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + - "\"Value\" : \"abc\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + - "\"Value\" : 123.45 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // SUCCESSFUL AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : \"123\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : true " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : 123.45 " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // SUCCESSFUL AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + - "\"Value\" : \"123.34\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + - "\"Value\" : true " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // allow integer to auto-convert to double when DataType is given - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + - "\"Value\" : 123 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.0}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // special JavaScript values not allowed except for -0 (inappropriate requirement in spec - check it anyway) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : \"NaN\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : \"INF\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : \"-INF\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // JavaScript 0 and -0 are ok - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : 0 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=0}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : -0 " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=0}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // All other data types are checked when we convert internally, so value must be syntactically correct - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + - "\"Value\" : \"syntactically incorrect value\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + - "\"Value\" : \"syntactically incorrect value\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + - "\"Value\" : \"syntactically incorrect value\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + - "\"Value\" : \"syntactically incorrect value\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + - "\"Value\" : \"syntactically incorrect value\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + - "\"Value\" : \"syntactically incorrect value\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + - "\"Value\" : \"syntactically incorrect value\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Base64 convert does not throw an exception if the contents are not Base64, so cannot test for this. - // Any problem with the data will have to be discovered later when the data is used. - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + - "\"Value\" : \"syntactically incorrect value\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + - "\"Value\" : \"syntactically incorrect value\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + - "\"Value\" : \"syntactically incorrect value\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + - "\"Value\" : \"syntactically incorrect value\" " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Cannot test XPathExpressions here. The XPathExpression gets converted into a simple String value within the XPathExpression object, - // but it is not evaluated or compiled at that time. Therefore we do not know whether or not the value is valid until it is used in a computation. - - } - - - @Test - public void testArrayDataTypes() { - - // array of size 0 - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : [] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Category Attribute value array DataType given (repeat for all data types) - // Category Attribute using full Identifier for each data type - // Category Attribute shorthand notation for each data type - // Also tests for mixes of different JSON types (trying incorrect strings for XACML data types whenever possible) - // string - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : [\"abc\", \"def\", \"hig\", \"lmn\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=def}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"string\", " + - "\"Value\" : [\"abc\", \"def\", \"hig\", \"lmn\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=def}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // SUCCESSFUL AUTO-CONVERT to DataType - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : [\"abc\", true, \"hig\", \"lmn\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // SUCCESSFUL AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : [\"abc\",123, \"hig\", \"lmn\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // SUCCESSFUL AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : [\"abc\", 34.34, \"hig\", \"lmn\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=34.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // boolean - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + - "\"Value\" : [true, true, false, true, false ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"boolean\", " + - "\"Value\" : [true, true, false, true, false ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + - "\"Value\" : [true, \"abc\", false, true, false ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + - "\"Value\" : [true, 123, false, true, false ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#boolean\", " + - "\"Value\" : [true, 12.34, false, true, false ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - - // integer - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : [123, 456, 765, 234] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=456}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=765}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=234}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"integer\", " + - "\"Value\" : [123, 456, 765, 234] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=456}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=765}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=234}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : [123, \"abc\", 765, 234] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : [123, true, 765, 234] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#integer\", " + - "\"Value\" : [123, 34.56, 765, 234] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // double - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + - "\"Value\" : [ 123.34, 543.54, 3445.455, 4543,543 ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.54}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"double\", " + - "\"Value\" : [ 123.34, 543.54, 3445.455, 4543,543 ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.54}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // special case - auto-convert integer to boolean - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + - "\"Value\" : [ 123.34, 111122, 3445.455, 4543,543 ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=111122.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + - "\"Value\" : [ 123.34, true, 3445.455, 4543,543 ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#double\", " + - "\"Value\" : [ 123.34, \"abb\", 3445.455, 4543,543 ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // time - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + - "\"Value\" : [ \"12:00:00Z\", \"12:00:00Z\", \"12:00:00Z\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"time\", " + - "\"Value\" : [ \"12:00:00Z\", \"12:00:00Z\", \"12:00:00Z\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#time,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + - "\"Value\" : [ \"12:00:00Z\", \"not a time\", \"12:00:00Z\"] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + - "\"Value\" : [ \"12:00:00Z\", true, \"12:00:00Z\"] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + - "\"Value\" : [ \"12:00:00Z\", 123, \"12:00:00Z\"] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#time\", " + - "\"Value\" : [ \"12:00:00Z\", 12.34, \"12:00:00Z\"] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // date - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + - "\"Value\" : [\"2002-10-10\",\"2002-10-10\",\"2002-10-10\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"date\", " + - "\"Value\" : [\"2002-10-10\",\"2002-10-10\",\"2002-10-10\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#date,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + - "\"Value\" : [\"2002-10-10\",\"not a date\",\"2002-10-10\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + - "\"Value\" : [\"2002-10-10\",true,\"2002-10-10\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + - "\"Value\" : [\"2002-10-10\",123,\"2002-10-10\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#date\", " + - "\"Value\" : [\"2002-10-10\",123.45,\"2002-10-10\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // dateTime - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + - "\"Value\" : [ \"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"dateTime\", " + - "\"Value\" : [ \"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#dateTime,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + - "\"Value\" : [ \"2002-10-10T12:00:00Z\",\"not a dateTime\",\"2002-10-10T12:00:00Z\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + - "\"Value\" : [ \"2002-10-10T12:00:00Z\",true,\"2002-10-10T12:00:00Z\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + - "\"Value\" : [ \"2002-10-10T12:00:00Z\",123,\"2002-10-10T12:00:00Z\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dateTime\", " + - "\"Value\" : [ \"2002-10-10T12:00:00Z\",12.34,\"2002-10-10T12:00:00Z\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // dayTimeDuration - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + - "\"Value\" : [ \"P23DT7H12M54S\",\"P23DT7H12M54S\",\"P23DT7H12M54S\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"dayTimeDuration\", " + - "\"Value\" : [ \"P23DT7H12M54S\",\"P23DT7H12M54S\",\"P23DT7H12M54S\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}{dataTypeId=http://www.w3.org/2001/XMLSchema#dayTimeDuration,value={super={durationSign=1years=0months=0days=23hours=7minutes=12seconds=54millis=0},factionalSeconds=54.0}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + - "\"Value\" : [ \"P23DT7H12M54S\",\"not a duration\",\"P23DT7H12M54S\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + - "\"Value\" : [ \"P23DT7H12M54S\",true,\"P23DT7H12M54S\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + - "\"Value\" : [ \"P23DT7H12M54S\",123,\"P23DT7H12M54S\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#dayTimeDuration\", " + - "\"Value\" : [ \"P23DT7H12M54S\",11.22,\"P23DT7H12M54S\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // yearMonth duration - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + - "\"Value\" : [ \"P165Y8M\",\"P165Y8M\",\"P165Y8M\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"yearMonthDuration\", " + - "\"Value\" : [ \"P165Y8M\",\"P165Y8M\",\"P165Y8M\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}{dataTypeId=http://www.w3.org/2001/XMLSchema#yearMonthDuration,value={super={durationSign=1years=165months=8days=0hours=0minutes=0seconds=0millis=0},monthsDuration=1988}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + - "\"Value\" : [ \"P165Y8M\",\"not a duration\",\"P165Y8M\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + - "\"Value\" : [ \"P165Y8M\",true,\"P165Y8M\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + - "\"Value\" : [ \"P165Y8M\",123,\"P165Y8M\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#yearMonthDuration\", " + - "\"Value\" : [ \"P165Y8M\",11.22,\"P165Y8M\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // anyURI - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + - "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"anyURI\", " + - "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // SUCCESSFUL AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + - "\"Value\" : [ \"aValue\",true,\"aValue\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // SUCCESSFUL AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + - "\"Value\" : [ \"aValue\",123,\"aValue\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#anyURI\", " + - "\"Value\" : [ \"aValue\",11.111,\"aValue\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=11.111}{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // hexBinary - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + - "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"hexBinary\", " + - "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#hexBinary,value={data=[-6,2,123,125,18,-52,52,-35,-46,0,18,-82,-17]}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + - "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",true,\"012AEEF\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + - "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",123,\"012AEEF\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#hexBinary\", " + - "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",11.44,\"012AEEF\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // base64Binary - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + - "\"Value\" : [ \"aG9y\",\"lvbj0iMS4xIj48YXV0aG9y\",\"lvbjIj48YXV0aG9y\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,-46,35,18,-29,18,35,-29,-58,23,87,70,-122,-9]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"base64Binary\", " + - "\"Value\" : [ \"aG9y\",\"lvbj0iMS4xIj48YXV0aG9y\",\"lvbjIj48YXV0aG9y\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,-46,35,18,-29,18,35,-29,-58,23,87,70,-122,-9]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + - "\"Value\" : [ \"aG9y\",true,\"lvbjIj48YXV0aG9y\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-74,-69,-98]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + - "\"Value\" : [ \"aG9y\",1123,\"lvbjIj48YXV0aG9y\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-41,93,-73]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#base64Binary\", " + - "\"Value\" : [ \"aG9y\",11.22,\"lvbjIj48YXV0aG9y\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[104,111,114]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-41,93,-74]}}{dataTypeId=http://www.w3.org/2001/XMLSchema#base64Binary,value={data=[-106,-10,-29,34,62,60,97,117,116,104,111,114]}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // RFC822 name - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + - "\"Value\" : [ \"sne.else@A.COMPANY.com\",\"one.else@A.COMPANY.com\",\"someone.else@A.CONY.com\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=sne.else,domainName=A.COMPANY.com}}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=one.else,domainName=A.COMPANY.com}}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=someone.else,domainName=A.CONY.com}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"rfc822Name\", " + - "\"Value\" : [ \"sne.else@A.COMPANY.com\",\"one.else@A.COMPANY.com\",\"someone.else@A.CONY.com\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=sne.else,domainName=A.COMPANY.com}}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=one.else,domainName=A.COMPANY.com}}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name,value={localName=someone.else,domainName=A.CONY.com}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + - "\"Value\" : [ \"sne.else@A.COMPANY.com\",\"not a dns\",\"someone.else@A.CONY.com\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + - "\"Value\" : [ \"sne.else@A.COMPANY.com\",true,\"someone.else@A.CONY.com\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + - "\"Value\" : [ \"sne.else@A.COMPANY.com\",111,\"someone.else@A.CONY.com\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name\", " + - "\"Value\" : [ \"sne.else@A.COMPANY.com\",11.22,\"someone.else@A.CONY.com\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // x500 - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + - "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"x500Name\", " + - "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}{dataTypeId=urn:oasis:names:tc:xacml:1.0:data-type:x500Name,value=CN=Julius Hibbert, O=Medi Corporation, C=US}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + - "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"non-x500 string\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + - "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", true, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + - "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", 1111, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:1.0:data-type:x500Name\", " + - "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", 11.22, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // ipAddress - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + - "\"Value\" : [ \"10.221.43.58:12345\",\"10.221.43.58:12345\",\"10.221.43.58:12345\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"ipAddress\", " + - "\"Value\" : [ \"10.221.43.58:12345\",\"10.221.43.58:12345\",\"10.221.43.58:12345\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:ipAddress,value=10.221.43.58:12345-12345}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + - "\"Value\" : [ \"10.221.43.58:12345\",\"not an ip address\",\"10.221.43.58:12345\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + - "\"Value\" : [ \"10.221.43.58:12345\",true,\"10.221.43.58:12345\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + - "\"Value\" : [ \"10.221.43.58:12345\",1111,\"10.221.43.58:12345\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:ipAddress\", " + - "\"Value\" : [ \"10.221.43.58:12345\",11.22,\"10.221.43.58:12345\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // dnsName - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"dnsName\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + - "\"Value\" : [ \"aValue\", true, \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=true}}{dataTypeId=urn:oasis:names:tc:xacml:2.0:data-type:dnsName,value={domainName=aValue}}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + - "\"Value\" : [ \"aValue\", 1111, \"aValue\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:2.0:data-type:dnsName\", " + - "\"Value\" : [ \"aValue\", 11.22, \"aValue\" ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // xPathExpression - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + - "\"Value\" : [ " - + "{" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}," + - "{" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}," + - "{" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" - + "] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + - "\"Value\" : [ " - + "{" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}," + - "\"simpleString\"," + - "{" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" - + "] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + - "\"Value\" : [ " - + "{" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}," + - "true," + - "{" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" - + "] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + - "\"Value\" : [ " - + "{" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}," + - "123," + - "{" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" - + "] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\", " + - "\"Value\" : [ " - + "{" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}," + - "12.34," + - "{" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" - + "] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - } - - - - - - - - @Test - public void testArrayNoDataTypes() { - - // array of size 0 - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Category Attribute value array DataType Not given (repeat for all data types) - // Also tests for mixes of different JSON types (trying incorrect strings for XACML data types whenever possible) - // string - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [\"abc\", \"def\", \"hig\", \"lmn\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=def}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // SUCCESSFUL AUTO-CONVERT to DataType - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [\"abc\", true, \"hig\", \"lmn\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // SUCCESSFUL AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [\"abc\",123, \"hig\", \"lmn\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // SUCCESSFUL AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [\"abc\", 34.34, \"hig\", \"lmn\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=34.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=hig}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lmn}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // boolean - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [true, true, false, true, false ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#boolean,value=false}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [true, \"abc\", false, true, false ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [true, 123, false, true, false ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [true, 12.34, false, true, false ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - - // integer - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [123, 456, 765, 234] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=456}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=765}{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=234}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [123, \"abc\", 765, 234] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [123, true, 765, 234] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - - // double - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ 123.34, 543.54, 3445.455, 4543,543 ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.54}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // special case - auto-convert integer to boolean - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ 123.34, 111122, 3445.455, 4543,543 ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=111122.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3445.455}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4543.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=543.0}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ 123.34, true, 3445.455, 4543,543 ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ 123.34, \"abb\", 3445.455, 4543,543 ] " + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // time - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"12:00:00Z\", \"12:00:00Z\", \"12:00:00Z\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // SUCCESSFUL AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"12:00:00Z\", true, \"12:00:00Z\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // SUCCESSFUL AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"12:00:00Z\", 123, \"12:00:00Z\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"12:00:00Z\", 12.34, \"12:00:00Z\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // date - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [\"2002-10-10\",\"2002-10-10\",\"2002-10-10\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [\"2002-10-10\",true,\"2002-10-10\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [\"2002-10-10\",123,\"2002-10-10\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [\"2002-10-10\",123.45,\"2002-10-10\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123.45}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // dateTime - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\",\"2002-10-10T12:00:00Z\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"2002-10-10T12:00:00Z\",true,\"2002-10-10T12:00:00Z\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"2002-10-10T12:00:00Z\",123,\"2002-10-10T12:00:00Z\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"2002-10-10T12:00:00Z\",12.34,\"2002-10-10T12:00:00Z\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=12.34}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=2002-10-10T12:00:00Z}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // dayTimeDuration - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"P23DT7H12M54S\",\"P23DT7H12M54S\",\"P23DT7H12M54S\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - //AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"P23DT7H12M54S\",true,\"P23DT7H12M54S\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"P23DT7H12M54S\",123,\"P23DT7H12M54S\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"P23DT7H12M54S\",11.22,\"P23DT7H12M54S\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P23DT7H12M54S}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // yearMonth duration - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"P165Y8M\",\"P165Y8M\",\"P165Y8M\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"P165Y8M\",true,\"P165Y8M\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"P165Y8M\",123,\"P165Y8M\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"P165Y8M\",11.22,\"P165Y8M\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=P165Y8M}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // anyURI - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\",true,\"aValue\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\",123,\"aValue\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\",11.111,\"aValue\"] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // hexBinary - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\",\"FA027B7D12CC34DDD20012AEEF\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",true,\"012AEEF\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=012AEEF}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",123,\"012AEEF\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=012AEEF}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"FA027B7D12CC34DDD20012AEEF\",11.44,\"012AEEF\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=FA027B7D12CC34DDD20012AEEF}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.44}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=012AEEF}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // base64Binary - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aG9y\",\"lvbj0iMS4xIj48YXV0aG9y\",\"lvbjIj48YXV0aG9y\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbj0iMS4xIj48YXV0aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbjIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aG9y\",true,\"lvbjIj48YXV0aG9y\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbjIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aG9y\",1123,\"lvbjIj48YXV0aG9y\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1123}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbjIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aG9y\",11.22,\"lvbjIj48YXV0aG9y\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aG9y}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=lvbjIj48YXV0aG9y}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // RFC822 name - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"sne.else@A.COMPANY.com\",\"one.else@A.COMPANY.com\",\"someone.else@A.CONY.com\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=sne.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=one.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.CONY.com}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"sne.else@A.COMPANY.com\",true,\"someone.else@A.CONY.com\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=sne.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.CONY.com}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"sne.else@A.COMPANY.com\",111,\"someone.else@A.CONY.com\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=sne.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.CONY.com}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"sne.else@A.COMPANY.com\",11.22,\"someone.else@A.CONY.com\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=sne.else@A.COMPANY.com}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=someone.else@A.CONY.com}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // x500 - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\", \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", true, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", 1111, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"cn=Julius Hibbert, o=Medi Corporation, c=US\", 11.22, \"cn=Julius Hibbert, o=Medi Corporation, c=US\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=cn=Julius Hibbert, o=Medi Corporation, c=US}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // ipAddress - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"10.221.43.58:12345\",\"10.221.43.58:12345\",\"10.221.43.58:12345\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"10.221.43.58:12345\",true,\"10.221.43.58:12345\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"10.221.43.58:12345\",1111,\"10.221.43.58:12345\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"10.221.43.58:12345\",11.22,\"10.221.43.58:12345\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=10.221.43.58:12345}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // dnsName - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", true, \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", 1111, \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", 11.22, \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // xPathExpression - defaults to String - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", true, \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=true}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", 1111, \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=1111}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - // AUTO-CONVERT - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", 11.22, \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=11.22}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - } - - - - - @Test - public void testXPathExpression() { - // Category Attribute with XPathExpression including XPathCategory and XPath - // Category Attribute with XPathExpression with Namespaces with/without Prefix - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [" - + "{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{ "+ - "\"Prefix\" : \"lab\", " + - "\"Namespace\" : \"http://somewhere/uri.html\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{lab,http://somewhere/uri.html}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with XPathExpression missing XPathCategory - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"Namespaces\" : [{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with XPathExpression missing XPath - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}] "+ - "}" + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with XPathExpression without Namespaces - // (path does not contain namespace references) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"XPath\" : \"record/patient/patientDoB\" "+ - "}" + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=record/patient/patientDoB,Namespace=null,status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with XPathExpression with 0 Namespaces - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace=null,status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Category Attribute with XPathExpression with Namespaces without mandatory Namespace - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [{ "+ - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [{ "+ - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with XPathExpression with Namespaces with 2 namespaces using same prefix - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [{ "+ - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with XPathExpression without Namespaces which are used within the XPathExpression (NOTE: Error is not syntactic and is not found by converter) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace=null,status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with XPathExpression containing simple value (must be object) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : \"simple Value\"" + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with Namespaces containing simple value (must be object) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [ \"simpleValue\"," + - "{" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Category Attribute with Namespaces non-string Namespace - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [ {" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : 123 " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with Namespaces non-string prefix - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [ {" + - "\"Prefix\" : 123, " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with Namespaces non-string XPathCategory - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : 123," + - "\"Namespaces\" : [ {" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" "+ - "}" + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category Attribute with Namespaces non-string XPath - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : {" + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\"," + - "\"Namespaces\" : [ {" + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "}], "+ - "\"XPath\" : 123 "+ - "}" + - "}] } ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - } - - - - @Test - public void testContent() { - - // Category with Content in XML, escaped properly - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + - "}]," + - "\"Content\" : \"<?xml version=\\\"1.0\\\"?><catalog>" + - "<book id=\\\"bk101\\\"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre>" + - "<price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description>"+ - "</book></catalog>\"" + - "} ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]},contentRoot=[catalog: null]}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category with Content in XML, double quotes and back-slashes NOT escaped properly? - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + - "}]," + - "\"Content\" : \"<?xml version=\\\"1.0\\\"?><catalog>" + - "<book id=\"bk101\\\"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre>" + - "<price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description>"+ - "</book></catalog>\"" + - "} ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category with Content in Base64 - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + - "}]," + - "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" + - "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+ - "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" + - "} ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]},contentRoot=[catalog: null]}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Category with Bad Content in Base64 - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + - "}]," + - "\"Content\" : \"PD94bWwgdmV\"" + - "} ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - } - - - - - @Test - public void testDuplicates() { - // duplicate of same element within Category array is ok - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : \"abc\" " + - "}] }, " + - "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : \"abc\" " + - "}] } " - + "] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=abc}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // duplicate Attribute - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [" + - "{\"CategoryId\" : \"custom-category\"," - + " \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : \"abc\" " + - "}], " - + " \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : \"abc\" " + - "}] " - + "} " - + " }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // dup id - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : \"abc\" " + - "}] } " - + "] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // dup DataType - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : \"abc\" " + - "}] } " - + "] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // dup Value - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"DataType\" : \"http://www.w3.org/2001/XMLSchema#string\", " + - "\"Value\" : \"abc\" " + - "\"Value\" : \"abc\" " + - "}] } " - + "] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // duplicate Content - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{" - + "\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\",\"aValue\",\"aValue\"] " + - "}]," + - "\"Content\" : \"<?xml version=\\\"1.0\\\"?><catalog>" + - "<book id=\\\"bk101\\\"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre>" + - "<price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description>"+ - "</book></catalog>\" , " + - "\"Content\" : \"<?xml version=\\\"1.0\\\"?><catalog>" + - "<book id=\\\"bk101\\\"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre>" + - "<price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description>"+ - "</book></catalog>\"" + - "} ] }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - } - - - -//TODO - Shorthand for CategoryId ???? - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestConformanceTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestConformanceTest.java deleted file mode 100644 index 54f5b26f8..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestConformanceTest.java +++ /dev/null @@ -1,255 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.json; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.junit.Test; - -import com.att.research.xacml.api.Request; -import com.att.research.xacml.api.RequestAttributes; -import com.att.research.xacml.api.RequestReference; -import com.att.research.xacml.std.dom.DOMRequest; -import com.att.research.xacml.std.json.JSONRequest; -import com.att.research.xacml.std.json.JSONStructureException; -/** - * Test JSON Request convert to object - Conformance tests - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * NOTE: - * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects - * and verify that they are correct. This would involve a lot of coding to get child of child of child and individually verify each property of each element. - * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object - * and we compare the resulting String to our expected String. - * This has two possible sources of error: - * - toString might not include some sub-component, and - * - the initial verification of the resulting string is done by hand and may have been incorrect. - * - * - */ -public class RequestConformanceTest { - - // where to find the conformance test XML files - private final String CONFORMANCE_DIRECTORY_PATH = "testsets/conformance/xacml3.0-ct-v.0.4"; - - // The request object output from each test conversion from JSON string - Request request; - - - - - - // test just one of each top-level element. - // For simple elements also test for incorrect type - @Test - public void testConformanceRequests() { - - List<File> filesInDirectory = null; - - File conformanceDirectory = null; - - File currentFile = null; - - try { - conformanceDirectory = new File(CONFORMANCE_DIRECTORY_PATH); - filesInDirectory = getRequestsInDirectory(conformanceDirectory); - } catch (Exception e) { - fail("Unable to set up Conformance tests for dir '" + conformanceDirectory.getAbsolutePath()+"' e="+ e); - } - - // run through each XML file - // - load the file from XML into an internal Request object - // - generate the JSON representation of that Request object - // - load that JSON representation into a new Request object - // - compare the 2 Request objects - Request xmlRequest = null; - Request jsonRequest = null; - try { - for (File f : filesInDirectory) { - currentFile = f; - -//// This is a simple way to select just one file for debugging - comment out when not being used -//if ( ! f.getName().equals("IIA023Request.xml")) { continue; } - -// during debugging it is helpful to know what file it is starting to work on -// System.out.println("starting file="+currentFile.getName()); - - try { - // load XML into a Request object - xmlRequest = DOMRequest.load(f); - xmlRequest.getStatus(); - } catch (Exception e) { - // if XML does not load, just note it and continue with next file - System.out.println("XML file did not load: '" + f.getName() + " e=" + e); - continue; - } - - - - // generate JSON from the Request - String jsonString = JSONRequest.toString(xmlRequest, false); - - - - // load JSON into a Request - jsonRequest = JSONRequest.load(jsonString); - - // compare the two Request objects - - // check simple things first - assertEquals("File '" + currentFile.getName() + "' CombinedDecision", xmlRequest.getCombinedDecision(), jsonRequest.getCombinedDecision()); - assertEquals("File '" + currentFile.getName() + "' getReturnPolicyIdList", xmlRequest.getReturnPolicyIdList(), jsonRequest.getReturnPolicyIdList()); - assertEquals("File '" + currentFile.getName() + "' requestDefaults", xmlRequest.getRequestDefaults(), jsonRequest.getRequestDefaults()); - - // multiRequests (guaranteed to not be null) - // We do NOT care about ordering, so compare the two collections inefficiently - Collection<RequestReference> xmlCollection = xmlRequest.getMultiRequests(); - Collection<RequestReference> jsonCollection = jsonRequest.getMultiRequests(); - String errorMessage = null; - if (jsonCollection.size() != xmlCollection.size()) { - errorMessage = "File '" + currentFile.getName() + "' MultiRequests not same size. "; - } else if (! jsonCollection.containsAll(xmlCollection)) { - errorMessage = "File '" + currentFile.getName() + "' MultiRequests have different contents. "; - } - if (errorMessage != null) { - String xmlContents = ""; - String jsonContents = ""; - Iterator<RequestReference> rrIt = xmlCollection.iterator(); - while (rrIt.hasNext()) { - xmlContents += "\n " + rrIt.next().toString(); - } - rrIt = jsonCollection.iterator(); - while (rrIt.hasNext()) { - jsonContents += "\n " + rrIt.next().toString(); - } - fail(errorMessage + "\nXML(" + xmlCollection.size() + ")='" + xmlContents + - "' \nJSON(" + jsonCollection.size() + ")='" + jsonContents + - "'" + - "\njson='" + jsonString + "'"); - } - - // attributes (guaranteed to not be null) - // We do NOT care about ordering, so compare the two collections inefficiently - Collection<RequestAttributes> xmlAttrCollection = xmlRequest.getRequestAttributes(); - Collection<RequestAttributes> jsonAttrCollection = jsonRequest.getRequestAttributes(); - errorMessage = null; - if (jsonAttrCollection.size() != xmlAttrCollection.size()) { - errorMessage = "File '" + currentFile.getName() + "' RequestAttributes not same size. "; - } else if (! jsonAttrCollection.containsAll(xmlAttrCollection)) { - String attrName = ""; - Iterator<RequestAttributes> rait = xmlAttrCollection.iterator(); - while (rait.hasNext()) { - RequestAttributes ra = rait.next(); - if (jsonAttrCollection.contains(ra) == false) { - attrName = ra.toString(); - } - } - errorMessage = "File '" + currentFile.getName() + "' RequestAttributes have different contents. JSON is missing attr=" + attrName; - } - if (errorMessage != null) { - String xmlContents = ""; - String jsonContents = ""; - Iterator<RequestAttributes> rrIt = xmlAttrCollection.iterator(); - while (rrIt.hasNext()) { - RequestAttributes ras = rrIt.next(); - xmlContents += "\n " + ras.toString(); - if (ras.getContentRoot() != null) { - StringWriter writer = new StringWriter(); - Transformer transformer = null; - try { - transformer = TransformerFactory.newInstance().newTransformer(); - transformer.transform(new DOMSource(ras.getContentRoot()), new StreamResult(writer)); - } catch (Exception e) { - throw new JSONStructureException("Unable to Content node to string; e="+e); - } - - xmlContents += "\n Content: " + writer.toString(); - } - } - rrIt = jsonAttrCollection.iterator(); - while (rrIt.hasNext()) { - RequestAttributes ras = rrIt.next(); - jsonContents += "\n " + ras.toString(); - if (ras.getContentRoot() != null) { - StringWriter writer = new StringWriter(); - Transformer transformer = null; - try { - transformer = TransformerFactory.newInstance().newTransformer(); - transformer.transform(new DOMSource(ras.getContentRoot()), new StreamResult(writer)); - } catch (Exception e) { - throw new JSONStructureException("Unable to Content node to string; e="+e); - } - - jsonContents += "\n Content: " + writer.toString(); - } - } - fail(errorMessage + "\nXML(" + xmlAttrCollection.size() + ")='" + xmlContents + - "' \nJSON(" + jsonAttrCollection.size() + ")='" + jsonContents + - "\njson='" + jsonString + "'"); - } - - - } - - } catch (Exception e) { - fail ("Failed test with '" + currentFile.getName() + "', e=" + e); - } - - - } - - // - // HELPER to get list of all Request files in the given directory - // - - private List<File> getRequestsInDirectory(File directory) { - List<File> fileList = new ArrayList<File>(); - - File[] fileArray = directory.listFiles(); - for (File f : fileArray) { - if (f.isDirectory()) { - List<File> subDirList = getRequestsInDirectory(f); - fileList.addAll(subDirList); - } - if (f.getName().endsWith("Request.xml")) { - fileList.add(f); - } - } - return fileList; - - } - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestDefaultCategoryTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestDefaultCategoryTest.java deleted file mode 100644 index 2465b3768..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestDefaultCategoryTest.java +++ /dev/null @@ -1,1427 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.json; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import org.junit.Test; - -import com.att.research.xacml.api.Request; -import com.att.research.xacml.std.json.JSONRequest; -import com.att.research.xacml.std.json.JSONStructureException; -/** - * Test JSON Request convert to object - Default Category object tests - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * NOTE: - * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects - * and verify that they are correct. This would involve a lot of coding to get child of child of child and individually verify each property of each element. - * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object - * and we compare the resulting String to our expected String. - * This has two possible sources of error: - * - toString might not include some sub-component, and - * - the initial verification of the resulting string is done by hand and may have been incorrect. - * - * - */ -public class RequestDefaultCategoryTest { - - // The request object output from each test conversion from JSON string - Request request; - - - /* - * Request that uses all fields with both single and multiple entries - */ - String allFieldsRequest = - "{\"Request\": {" + - "\"ReturnPolicyIdList\" : true ," + - "\"CombinedDecision\" : true ," + - "\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"," + - "\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{ " + - "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + - "}," + - "{" + - "\"ReferenceId\" : [\"foo2\",\"bar1\"]" + - "}]" + - "}," + - - "\"Category\": [" + - "{ " + - "\"CategoryId\": \"custom-category\", " + - "\"Id\" : \"customId\", " + - "\"Attribute\" : [" + - "{" + - "\"AttributeId\" : \"document-id\", " + - "\"DataType\" : \"integer\", " + - "\"Value\" : 123 " + - "}, " + - "{" + - "\"AttributeId\" : \"document-url\", " + - "\"DataType\" : \"anyURI\", " + - "\"Value\" : \"http://somewhere.over.the.com/rainbow\" " + - "}, " + - "{" + - "\"AttributeId\" : \"page-list\", " + - "\"Value\" : [1, 2, 3, 4.5, 3, 2, 1] " + - "} " + - "]" + - "}, " + - "{ " + - "\"CategoryId\": \"another-custom-cat\", " + - "\"Id\" : \"anotherXmlId\", " + - "\"Attribute\" : []" + - "} " + - "], " + - - "\"AccessSubject\":{ " + - "\"Content\" : \"<?xml version=\\\"1.0\\\"?><catalog>" + - "<book id=\\\"bk101\\\"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre>" + - "<price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description>"+ - "</book></catalog>\"," + - "\"Attribute\" : []" + - "}, " + - - "\"Resource\" : {" + - "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" + - "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+ - "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" + - - - "} " + - - - "}}"; - - /* - * The following example comes directly from the JSON Profile Spec - */ - String exampleFromSpec = "{ " + - "\"Request\" : { " + - "\"AccessSubject\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "}, " + - "\"Action\" : { " + - "\"Attribute\": " + - "{ " + - "\"Id\" : \"action-id\", " + - "\"Value\" : \"http://www.xacml.eu/buy\", " + - "\"DataType\" : \"anyURI\" " + - "} " + - "}, " + - "\"Resource\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"book-title\", " + - "\"Value\" : \"Learn German in 90 days\" " + - "}, " + - "{ " + - "\"Id\" : \"currency\", " + - "\"Value\" : \"SEK\" " + - "}, " + - "{ " + - "\"Id\" : \"price\", " + - "\"Value\" : 123.34 " + - "} " + - "] " + - "} " + - "} " + - "} "; - - - /* - * The following example comes directly from the JSON Profile Spec (modified to include a "</Catalog>" missing from both examples). - * It shows the two ways of handling XPath content, as escaped XML and as Base64 encoding. - */ - String xPathExampleFromSpec = "{ " + - "\"Request\" : { " + - "\"Resource\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"urn:oasis:names:tc:xacml:3.0:content-selector\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : { " + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", " + - "\"Namespaces\" : [{ " + - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}, " + - "{ " + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "} " + - "], " + - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" " + - "} " + - "} " + - "] " + - "} " + - "} " + - "} "; - - - // test Shorthand Category notation for elements not tested in their own section below. - // Categories that are more commonly used are fully tested. - // Given that the functions within the categories are the same irrespective of the name of the category, - // we assume that the contents of the category will work ok once the Shorthand notation is recognized, so all we need to test is the shorthand - // The ones that are tested in their own sections are: - // AccessSubject - // Action - // Resource - // Environment - // test Subject - @Test - public void testCategoryShorthand() { - - // RecipientSubject present both as element within Category and as separate RecipientSubject element at same level as Category - try { - request = JSONRequest.load("{\"Request\" : {" - + "\"Category\": [" - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] }, " - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "]," + - "\"RecipientSubject\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:recipient-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // IntermediarySubject present both as element within Category and as separate IntermediarySubject element at same level as Category - try { - request = JSONRequest.load("{\"Request\" : {" - + "\"Category\": [" - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] }, " - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "]," + - "\"IntermediarySubject\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Codebase present both as element within Category and as separate Codebase element at same level as Category - try { - request = JSONRequest.load("{\"Request\" : {" - + "\"Category\": [" - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:codebase\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] }, " - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:codebase\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "]," + - "\"Codebase\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:codebase,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - - // RequestingMachine present both as element within Category and as separate RequestingMachine element at same level as Category - try { - request = JSONRequest.load("{\"Request\" : {" - + "\"Category\": [" - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] }, " - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "]," + - "\"RequestingMachine\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:requesting-machine,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - } - - - - - - - - - - - - - - - - - // test AccessSubject - // Include test for backward compatibility with "Subject" - @Test - public void testAccessSubjectRequest() { - - // AccessSubject absent - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // AccessSubject as normal element under Category (with CategoryId==subject category id) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // multiple AccessSubjects under Category - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [" - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] }, " - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // AccessSubject present both as element within Category and as separate AccessSubject element at same level as Category - try { - request = JSONRequest.load("{\"Request\" : {" - + "\"Category\": [" - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] }, " - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "]," + - "\"AccessSubject\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // AccessSubject present, no other Category element - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"AccessSubject\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Subject present, no other Category element (Backward Compatibility - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Subject\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // AccessSubject present, 1/multiple other Category element also present - try { - request = JSONRequest.load("{\"Request\" : {" - + "\"Category\": [" - + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "]," + - "\"AccessSubject\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // 2 AccessSubjects - duplicates fail - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"AccessSubject\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + - "\"AccessSubject\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // AccessSubject with correct Category value - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"AccessSubject\" : { " + - "\"CategoryId\" : \"urn:oasis:names:tc:xacml:1.0:subject-category:access-subject\" ," + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // AccessSubject with wrong Category value - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"AccessSubject\" : { " + - "\"CategoryId\" : \"notthesubject\" ," + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // AccessSubject with array of sub-object AccessSubjects (Multi Decision) - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"AccessSubject\" : [" - + "{ " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "}, " - + "{ " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Arless\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Somewhere\" " + - "} " + - "] " + - "}, " - + "{ " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Barry\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Elsewhere\" " + - "} " + - "] " + - "} " - + "]" - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - } - - - - - - - - - - // Action ... duplicate all AccessSubject tests... - // test Action - @Test - public void testActionRequest() { - - // Action absent - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Action as normal element under Category (with CategoryId==subject category id) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // multiple Actions under Category - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [" - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] }, " - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Action present both as element within Category and as separate Action element at same level as Category - try { - request = JSONRequest.load("{\"Request\" : {" - + "\"Category\": [" - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] }, " - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "]," + - "\"Action\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Action present, no other Category element - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Action\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Action present, 1/multiple other Category element also present - try { - request = JSONRequest.load("{\"Request\" : {" - + "\"Category\": [" - + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "]," + - "\"Action\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // 2 Actions - duplicates fail - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Action\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + - "\"Action\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Action with correct Category value - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Action\" : { " + - "\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:action\" ," + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Action with wrong Category value - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Action\" : { " + - "\"CategoryId\" : \"notthesubject\" ," + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Action with array of sub-object Actions (Multi Decision) - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Action\" : [" - + "{ " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "}, " - + "{ " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Arless\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Somewhere\" " + - "} " + - "] " + - "}, " - + "{ " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Barry\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Elsewhere\" " + - "} " + - "] " + - "} " - + "]" - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - } - - - - - // Resource ... duplicate all AccessSubject tests... - // test Resource - @Test - public void testResourceRequest() { - - // Resource absent - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Resource as normal element under Category (with CategoryId==subject category id) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // multiple Resources under Category - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [" - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] }, " - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Resource present both as element within Category and as separate Resource element at same level as Category - try { - request = JSONRequest.load("{\"Request\" : {" - + "\"Category\": [" - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] }, " - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "]," + - "\"Resource\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Resource present, no other Category element - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Resource\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Resource present, 1/multiple other Category element also present - try { - request = JSONRequest.load("{\"Request\" : {" - + "\"Category\": [" - + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "]," + - "\"Resource\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // 2 Resources - duplicates fail - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Resource\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + - "\"Resource\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Resource with correct Category value - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Resource\" : { " + - "\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\" ," + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Resource with wrong Category value - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Resource\" : { " + - "\"CategoryId\" : \"notthesubject\" ," + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Resource with array of sub-object Resources (Multi Decision) - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Resource\" : [" - + "{ " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "}, " - + "{ " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Arless\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Somewhere\" " + - "} " + - "] " + - "}, " - + "{ " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Barry\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Elsewhere\" " + - "} " + - "] " + - "} " - + "]" - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - } - - - - - - - // Environment ... duplicate all AccessSubject tests ... - // test Environment - @Test - public void testEnvironmentRequest() { - - // Environment absent - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Environment as normal element under Category (with CategoryId==subject category id) - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\" " + - "}] } ] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // multiple Environments under Category - try { - request = JSONRequest.load("{\"Request\" : {\"Category\": [" - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] }, " - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Environment present both as element within Category and as separate Environment element at same level as Category - try { - request = JSONRequest.load("{\"Request\" : {" - + "\"Category\": [" - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : [ \"aValue\", \"aValue\", \"aValue\" ] " + - "}] }, " - + "{\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "]," + - "\"Environment\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=document-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Environment present, no other Category element - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Environment\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Environment present, 1/multiple other Category element also present - try { - request = JSONRequest.load("{\"Request\" : {" - + "\"Category\": [" - + "{\"CategoryId\" : \"custom-category\", \"Attribute\" : [{" + - "\"Id\" : \"document-id\", " + - "\"Value\" : \"aValue\"" + - "}] } " - + "]," + - "\"Environment\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=aValue}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // 2 Environments - duplicates fail - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Environment\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + - "\"Environment\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Environment with correct Category value - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Environment\" : { " + - "\"CategoryId\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:environment\" ," + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Environment with wrong Category value - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Environment\" : { " + - "\"CategoryId\" : \"notthesubject\" ," + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "} " - + " }}"); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Environment with array of sub-object Environments (Multi Decision) - try { - request = JSONRequest.load("{\"Request\" : {" - + - "\"Environment\" : [" - + "{ " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "}, " - + "{ " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Arless\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Somewhere\" " + - "} " + - "] " + - "}, " - + "{ " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Barry\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Elsewhere\" " + - "} " + - "] " + - "} " - + "]" - + " }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Arless}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Somewhere}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Barry}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Elsewhere}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - } - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestMainTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestMainTest.java deleted file mode 100644 index eb19e35a2..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestMainTest.java +++ /dev/null @@ -1,1076 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.json; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import org.junit.Test; - -import com.att.research.xacml.api.Request; -import com.att.research.xacml.std.json.JSONRequest; -import com.att.research.xacml.std.json.JSONStructureException; -/** - * Test JSON Request convert to object - High-level Request-as-a-whole tests including test that fills in all fields with multiple values (where appropriate) - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * NOTE: - * The "correct" way to verify that each JSON string gets translated into our internal Objects correctly is to look explicitly at each of the child objects - * and verify that they are correct. This would involve a lot of coding to get child of child of child and individually verify each property of each element. - * To simplify testing we assume that request.toString() correctly includes a complete text representation of every sub-component of the Request object - * and we compare the resulting String to our expected String. - * This has two possible sources of error: - * - toString might not include some sub-component, and - * - the initial verification of the resulting string is done by hand and may have been incorrect. - * - * - */ -public class RequestMainTest { - - // The request object output from each test conversion from JSON string - Request request; - - - /* - * Request that uses all fields with both single and multiple entries - */ - String allFieldsRequest = - "{\"Request\": {" + - "\"ReturnPolicyIdList\" : true ," + - "\"CombinedDecision\" : true ," + - "\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"," + - "\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{ " + - "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + - "}," + - "{" + - "\"ReferenceId\" : [\"foo2\",\"bar1\"]" + - "}]" + - "}," + - - "\"Category\": [" + - "{ " + - "\"CategoryId\": \"custom-category\", " + - "\"Id\" : \"customId\", " + - "\"Attribute\" : [" + - "{" + - "\"AttributeId\" : \"document-id\", " + - "\"DataType\" : \"integer\", " + - "\"Value\" : 123 " + - "}, " + - "{" + - "\"AttributeId\" : \"document-url\", " + - "\"DataType\" : \"anyURI\", " + - "\"Value\" : \"http://somewhere.over.the.com/rainbow\" " + - "}, " + - "{" + - "\"AttributeId\" : \"page-list\", " + - "\"Value\" : [1, 2, 3, 4.5, 3, 2, 1] " + - "} " + - "]" + - "}, " + - "{ " + - "\"CategoryId\": \"another-custom-cat\", " + - "\"Id\" : \"anotherXmlId\", " + - "\"Attribute\" : []" + - "} " + - "], " + - - "\"AccessSubject\":{ " + - "\"Content\" : \"<?xml version=\\\"1.0\\\"?><catalog>" + - "<book id=\\\"bk101\\\"><author>Gambardella, Matthew</author><title>XML Developer's Guide</title><genre>Computer</genre>" + - "<price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description>"+ - "</book></catalog>\"," + - "\"Attribute\" : []" + - "}, " + - - "\"Resource\" : {" + - "\"Content\" : \"PD94bWwgdmVyc2lvbj0iMS4wIj8+PGNhdGFsb2c+PGJvb2sgaWQ9ImJrMTAxIj48YXV0aG9yPkdhbWJhcmRlbGxhLCBNYXR0aGV3PC9hdXRob3I+PHRpdGxlPlhNT" + - "CBEZXZlbG9wZXIncyBHdWlkZTwvdGl0bGU+PGdlbnJlPkNvbXB1dGVyPC9nZW5yZT48cHJpY2U+NDQuOTU8L3ByaWNlPjxwdWJsaXNoX2RhdGU+MjAwMC0xMC0wMTwvcHVibGlzaF"+ - "9kYXRlPjxkZXNjcmlwdGlvbj5BbiBpbi1kZXB0aCBsb29rIGF0IGNyZWF0aW5nIGFwcGxpY2F0aW9ucyB3aXRoIFhNTC48L2Rlc2NyaXB0aW9uPjwvYm9vaz48L2NhdGFsb2c+\"" + - - - "} " + - - - "}}"; - - /* - * The following example comes directly from the JSON Profile Spec - */ - String exampleFromSpec = "{ " + - "\"Request\" : { " + - "\"AccessSubject\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"subject-id\", " + - "\"Value\" : \"Andreas\" " + - "}, " + - "{ " + - "\"Id\" : \"location\", " + - "\"Value\" : \"Gamla Stan\" " + - "} " + - "] " + - "}, " + - "\"Action\" : { " + - "\"Attribute\": " + - "{ " + - "\"Id\" : \"action-id\", " + - "\"Value\" : \"http://www.xacml.eu/buy\", " + - "\"DataType\" : \"anyURI\" " + - "} " + - "}, " + - "\"Resource\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"book-title\", " + - "\"Value\" : \"Learn German in 90 days\" " + - "}, " + - "{ " + - "\"Id\" : \"currency\", " + - "\"Value\" : \"SEK\" " + - "}, " + - "{ " + - "\"Id\" : \"price\", " + - "\"Value\" : 123.34 " + - "} " + - "] " + - "} " + - "} " + - "} "; - - - /* - * The following example comes directly from the JSON Profile Spec (modified to include a "</Catalog>" missing from both examples). - * It shows the two ways of handling XPath content, as escaped XML and as Base64 encoding. - */ - String xPathExampleFromSpec = "{ " + - "\"Request\" : { " + - "\"Resource\" : { " + - "\"Attribute\": [ " + - "{ " + - "\"Id\" : \"urn:oasis:names:tc:xacml:3.0:content-selector\", " + - "\"DataType\" : \"xpathExpression\", " + - "\"Value\" : { " + - "\"XPathCategory\" : \"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\", " + - "\"Namespaces\" : [{ " + - "\"Namespace\" : \"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" " + - "}, " + - "{ " + - "\"Prefix\" : \"md\", " + - "\"Namespace\" : \"urn:example:med:schemas:record\" " + - "} " + - "], " + - "\"XPath\" : \"md:record/md:patient/md:patientDoB\" " + - "} " + - "} " + - "] " + - "} " + - "} " + - "} "; - - - - // test various ways that request might be empty - @Test - public void testEmptyRequest() { - // null request - try { - request = JSONRequest.load((String)null); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // empty request - try { - request = JSONRequest.load((String)""); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)" "); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // empty JSON request - try { - request = JSONRequest.load((String)"{}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{{}}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // garbage input - try { - request = JSONRequest.load((String)"Some non-JSON string"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{something non-JSON}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // bad syntax (Request with no content) - try { - request = JSONRequest.load((String)"{\"Request\"}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // bad syntax (no :field after Request) - try { - request = JSONRequest.load((String)"{\"Request\" : }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // bad syntax (no " around Request) - try { - request = JSONRequest.load((String)"{Request}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // empty content in Request - try { - request = JSONRequest.load((String)"{\"Request\" : \"\"}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // content is not an object - try { - request = JSONRequest.load((String)"{\"Request\" : \"CombinedDecision\" : true }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // too many } at end - // Jackson parser does not treat this as an error - try { - request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\"}}}}}"); - assertEquals("{requestDefaults={xpatherVersion=http://www.w3.org/TR/1999/REC-xpath-19991116},returnPolicyIdList=false,combinedDecision=false}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // too few } at end - try { - request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\" }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // misplaced } in middle - try { - request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : } \"http://www.w3.org/TR/1999/REC-xpath-19991116\"}}}}}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - } - - - - // Test double braces around request - @Test - public void testDoubleBraces() { - - try { - request = JSONRequest.load((String)"{{\"Request\" }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{{\"Request\" : }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{{\"Request\" : {\"CombinedDecision\" : true }}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - } - - - - // test elements missing from top-level Request and arrays where single elements should be - @Test - public void testMissingFields() { - - // Request containing empty array - try { - request = JSONRequest.load((String)"{\"Request\" : []}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // array of one element - try { - request = JSONRequest.load((String)"{\"Request\" : [{\"CombinedDecision\" : true }]}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // correctly formatted empty request gives request with defaults set - try { - request = JSONRequest.load((String)"{\"Request\" : { }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // space in front of name (inside quotes) - try { - request = JSONRequest.load((String)"{\" Request\" : {\"XPathVersion\" : \"http://some/other/default/uri\" }}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // space at end of name (inside quotes) - try { - request = JSONRequest.load((String)"{\"Request \" : {\"XPathVersion\" : \"http://some/other/default/uri\" }}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // space in front of value (inside quotes) - valid String but not valid URI - try { - request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \" http://some/other/default/uri\" }}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // space at end of value (inside quotes) - valid String but not valid URI - try { - request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://some/other/default/uri \" }}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - } - - - - // test just one of each top-level element. - // For simple elements also test for incorrect type - @Test - public void testTopLevelElements() { - - // empty request - try { - request = JSONRequest.load((String)"{\"Request\" : {}}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - - // ReturnPolicyIdList - try { - request = JSONRequest.load((String)"{\"Request\" : {\"ReturnPolicyIdList\" : true }}"); - assertEquals("{returnPolicyIdList=true,combinedDecision=false}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"ReturnPolicyIdList\" : \"abc\" }}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load((String)"{\"Request\" : {\"ReturnPolicyIdList\" : 123 }}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // CombinedDecision - try { - request = JSONRequest.load((String)"{\"Request\" : { \"CombinedDecision\" : true }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=true}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"CombinedDecision\" : \"abc\" }}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load((String)"{\"Request\" : {\"CombinedDecision\" : 123 }}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // XPathVersion - try { - request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://some/other/default/uri\" }}"); - assertEquals("{requestDefaults={xpatherVersion=http://some/other/default/uri},returnPolicyIdList=false,combinedDecision=false}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : true }}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : 123 }}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"not a uri\" }}"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Category - try { - request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + - "\"CategoryId\": \"another-custom-cat\", " + - "\"Id\" : \"anotherXmlId\", " + - "\"Attribute\" : []" + - "} " + - "] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=another-custom-cat},xmlId=anotherXmlId}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // AccessSubject - try { - request = JSONRequest.load((String)"{\"Request\" : { \"AccessSubject\":{ }}}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Action - try { - request = JSONRequest.load((String)"{\"Request\" : { \"Action\":{ }}}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Resource - try { - request = JSONRequest.load((String)"{\"Request\" : {\"Resource\":{ }}}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Environment - try { - request = JSONRequest.load((String)"{\"Request\" : {\"Environment\":{ } }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:environment}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // MultiRequests - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{ " + - "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + - "}," + - "{" + - "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + - "}]" + - "} } }"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,multiRequests=[{requestAttributesReferences=[{referenceId=foo1}{referenceId=bar1}]}{requestAttributesReferences=[{referenceId=foo2}{referenceId=bar2}]}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // MultiRequest with 1 - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{" + - "\"ReferenceId\" : [\"bar2\"]" + - "}]" + - "} } }"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,multiRequests=[{requestAttributesReferences=[{referenceId=bar2}]}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // MultiRequest with RequestReferences with no ReferenceId - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{" + - "\"ReferenceId\" : []" + - "}]" + - "} } }"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // MultiRequests with no RequestReference - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": []" + - "} } }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // MultiRequests with something other than RequestReference - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"SomeOtherAttribute\": 123" + - "} } }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // MultiRequests with single RequestReference rather than array - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": " + - "{" + - "\"ReferenceId\" : []" + - "}" + - "} } }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // MultiRequests with RequestReference containing single element instead of array - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{" + - "\"ReferenceId\" : \"foo1\"" + - "}]" + - "} } }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{" + - "\"ReferenceId\" : {\"foo1\"}" + - "}]" + - "} } }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // MultiRequests with component that is not a RequestReference - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{ " + - "\"SomeOtherAttribute\" : [\"foo1\",\"bar1\"]" + - "}," + - "{" + - "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + - "}]" + - "} } }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // MultiRequests with component that is not a RequestReference - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{ " + - "\"ReferenceId\" : [\"foo2\",\"bar2\"]," + - "\"SomeOtherAttribute\" : [\"foo1\",\"bar1\"]" + - "}," + - "{" + - "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + - "}]" + - "} } }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // MultiRequest with unknown elements (in addition to RequestReference) - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"SomeOtherAttribute\": 123," + - "\"RequestReference\": [" + - "{ " + - "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + - "}," + - "{" + - "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + - "}]" + - "} } }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // MultiRequest with RequestReferences with ReferenceId NOT a string - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{" + - "\"ReferenceId\" : [ true ]" + - "}]" + - "} } }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{" + - "\"ReferenceId\" : [ 123 ]" + - "}]" + - "} } }"); - fail("Request should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Cannot test with ReferenceId that is NOT referring to a Category object Id property because we may not have read the Category objects yet. - // Need to leave this up to the PDP. - - - // extra elements in top-level - try { - request = JSONRequest.load((String)"{\"Request\" : {}, \"unknownElement\" : false, \"unk2\" : \"abc\", \"unk3\" : 123 }}"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // extra elements in Request - try { - request = JSONRequest.load((String)"{\"Request\" : {\"XPathVersion\" : \"http://www.w3.org/TR/1999/REC-xpath-19991116\", \"unknownElement\" : false }}"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - } - - - // Test with every field filled in with multiple values where appropriate - @Test - public void testAllFieldsRequest() { - - // convert Response to JSON - try { - request = JSONRequest.load(allFieldsRequest); - assertEquals("{requestDefaults={xpatherVersion=http://www.w3.org/TR/1999/REC-xpath-19991116},returnPolicyIdList=true,combinedDecision=true,requestAttributes=[{super={category=custom-category,attributes=[{attributeId=document-id,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#integer,value=123}],includeInResults=false}{attributeId=document-url,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=http://somewhere.over.the.com/rainbow}],includeInResults=false}{attributeId=page-list,category=custom-category,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=1.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=2.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=4.5}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=3.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=2.0}{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=1.0}],includeInResults=false}]},xmlId=customId}{super={category=another-custom-cat},xmlId=anotherXmlId}{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject},contentRoot=[catalog: null]}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource},contentRoot=[catalog: null]}],multiRequests=[{requestAttributesReferences=[{referenceId=foo1}{referenceId=bar1}]}{requestAttributesReferences=[{referenceId=foo2}{referenceId=bar1}]}]}" - , request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // convert example request from spec - try { - request = JSONRequest.load(exampleFromSpec); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,attributes=[{attributeId=subject-id,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Andreas}],includeInResults=false}{attributeId=location,category=urn:oasis:names:tc:xacml:1.0:subject-category:access-subject,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Gamla Stan}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,attributes=[{attributeId=action-id,category=urn:oasis:names:tc:xacml:3.0:attribute-category:action,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#anyURI,value=http://www.xacml.eu/buy}],includeInResults=false}]}}{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=book-title,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=Learn German in 90 days}],includeInResults=false}{attributeId=currency,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#string,value=SEK}],includeInResults=false}{attributeId=price,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=http://www.w3.org/2001/XMLSchema#double,value=123.34}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // convert example request from spec containing XPAthExpression - try { - request = JSONRequest.load(xPathExampleFromSpec); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,attributes=[{attributeId=urn:oasis:names:tc:xacml:3.0:content-selector,category=urn:oasis:names:tc:xacml:3.0:attribute-category:resource,values=[{dataTypeId=urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression,value={path=md:record/md:patient/md:patientDoB,Namespace={[{md,urn:example:med:schemas:record}{urn:oasis:names:tc:xacml:3.0:core:schema:wd-17}]},status=null,xpathExpressionWrapped=null},xpathCategory=urn:oasis:names:tc:xacml:3.0:attribute-category:resource}],includeInResults=false}]}}]}", request.toString()); - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - } - - - - // Duplicates - Each element duplicated - @Test - public void testDuplicates() { - // duplicate Request - try { - request = JSONRequest.load((String)"{\"Request\" : {}, \"Request\" : {}}"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"ReturnPolicyIdList\" : true, \"ReturnPolicyIdList\" : true }}"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{\"Request\" : { \"CombinedDecision\" : true, \"CombinedDecision\" : true }}"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + - "\"CategoryId\": \"another-custom-cat\", " + - "\"Id\" : \"anotherXmlId\", " + - "\"Attribute\" : []" + - "} " + - "]," - + "\"Category\": [{ " + - "\"CategoryId\": \"another-custom-cat\", " + - "\"Id\" : \"anotherXmlId\", " + - "\"Attribute\" : []" + - "} " + - "] }}"); - assertEquals("{returnPolicyIdList=false,combinedDecision=false,requestAttributes=[{super={category=another-custom-cat},xmlId=anotherXmlId}]}", request.toString()); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + - "\"CategoryId\": \"another-custom-cat\", " + - "\"CategoryId\": \"another-custom-cat\", " + - "\"Id\" : \"anotherXmlId\", " + - "\"Attribute\" : []" + - "} " + - "] }}"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + - "\"CategoryId\": \"another-custom-cat\", " + - "\"Id\" : \"anotherXmlId\", " + - "\"Id\" : \"anotherXmlId\", " + - "\"Attribute\" : []" + - "} " + - "] }}"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"Category\": [{ " + - "\"CategoryId\": \"another-custom-cat\", " + - "\"Id\" : \"anotherXmlId\", " + - "\"Attribute\" : []" + - "\"Attribute\" : []" + - "} " + - "] }}"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // AccessSubject - try { - request = JSONRequest.load((String)"{\"Request\" : { \"AccessSubject\":{ }, \"AccessSubject\":{ }}}"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Action - try { - request = JSONRequest.load((String)"{\"Request\" : { \"Action\":{ }, \"Action\":{ }}}"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Resource - try { - request = JSONRequest.load((String)"{\"Request\" : {\"Resource\":{ }, \"Resource\":{ }}}"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Environment - try { - request = JSONRequest.load((String)"{\"Request\" : {\"Environment\":{ }, \"Environment\":{ } }}"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // MultiRequests - - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{ " + - "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + - "}," + - "{" + - "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + - "}]" + - "}," - + "\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{ " + - "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + - "}," + - "{" + - "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + - "}]" + - "} } }"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{ " + - "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + - "}," + - "{" + - "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + - "}]," + - "\"RequestReference\": [" + - "{ " + - "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + - "}," + - "{" + - "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + - "}]" + - "} } }"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - try { - request = JSONRequest.load((String)"{\"Request\" : {\"MultiRequests\" : {" + - "\"RequestReference\": [" + - "{ " + - "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + - "\"ReferenceId\" : [\"foo1\",\"bar1\"]" + - "}," + - "{" + - "\"ReferenceId\" : [\"foo2\",\"bar2\"]" + - "}]" + - "} } }"); - fail("Unknown element should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - } - - -} diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseConformanceTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseConformanceTest.java deleted file mode 100644 index adf903022..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseConformanceTest.java +++ /dev/null @@ -1,370 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.json; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.junit.Test; - -import com.att.research.xacml.api.Advice; -import com.att.research.xacml.api.Attribute; -import com.att.research.xacml.api.AttributeCategory; -import com.att.research.xacml.api.IdReference; -import com.att.research.xacml.api.Obligation; -import com.att.research.xacml.api.Response; -import com.att.research.xacml.api.Result; -import com.att.research.xacml.std.dom.DOMResponse; -import com.att.research.xacml.std.json.JSONResponse; -import com.att.research.xacml.util.ListUtil; -/** - * Test JSON Response convert to object - Conformance tests - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * Note: some of the validation tests comparing the XML-derived Results to the JSON-derived Results are high-level comparisons of Collections. - * When this class was first created that was sufficient to pass all Conformance tests. - * However if this sees a failure in a Conformance test, those validations may need to be upgraded to look at the individual data elements to see what is wrong. - * - * - */ -public class ResponseConformanceTest { - - // where to find the conformance test XML files - private final String CONFORMANCE_DIRECTORY_PATH = "testsets/conformance/xacml3.0-ct-v.0.4"; - - // The request object output from each test conversion from JSON string - Response response; - - - - - - // test just one of each top-level element. - // For simple elements also test for incorrect type - @Test - public void testConformanceResponses() { - - List<File> filesInDirectory = null; - - File conformanceDirectory = null; - - File currentFile = null; - - try { - conformanceDirectory = new File(CONFORMANCE_DIRECTORY_PATH); - filesInDirectory = getRequestsInDirectory(conformanceDirectory); - } catch (Exception e) { - fail("Unable to set up Conformance tests for dir '" + conformanceDirectory.getAbsolutePath()+"' e="+ e); - } - - // run through each XML file - // - load the file from XML into an internal Response object - // - generate the JSON representation of that Response object - // - load that JSON representation into a new Response object - // - compare the 2 Request objects - Response xmlResponse = null; - Response jsonResponse = null; - try { - for (File f : filesInDirectory) { - currentFile = f; - -//// This is a simple way to select just one file for debugging - comment out when not being used -//if ( ! f.getName().equals("IIIA030Response.xml") && ! f.getName().equals("IIIA330Response.xml")) { continue; } - -// during debugging it is helpful to know what file it is starting to work on -// System.out.println("starting file="+currentFile.getName()); - - try { - // load XML into a Response object - xmlResponse = DOMResponse.load(f); - } catch (Exception e) { - // if XML does not load, just note it and continue with next file - System.out.println("XML file did not load: '" + f.getName() + " e=" + e); - continue; - } - - // some tests have JSON response files to load, most do not - String jsonFileName = f.getName().replace(".xml", ".json"); - File jsonFile = new File(conformanceDirectory, jsonFileName); - - if (jsonFile.exists()) { -//System.out.println("found file "+jsonFile.getName()); - // json version exists in file, so load it - jsonResponse = JSONResponse.load(jsonFile); - } else { - // json does not exist in file, so create it from the XML response using a String intermediate version - String jsonResponseString = JSONResponse.toString(xmlResponse, false); -//System.out.println(jsonResponseString); -//System.out.println(JSONResponse.toString(xmlResponse, true)); - - jsonResponse = JSONResponse.load(jsonResponseString); - } - - -//System.out.println(JSONResponse.toString(xmlResponse, true)); - - - - - // compare the two Response objects - - // compare results - assertEquals(xmlResponse.getResults().size(), jsonResponse.getResults().size()); - - if (xmlResponse.getResults().size() == 0) { - fail("neither XML nor JSON response have any Results"); - } - - - // Results are an un-ordered Collection. - // There is no identifying information that is unique to a specific Result. - // If there are more than one we cannot be sure which one corresponds with which. - // The best we can do is say that one or more in the first list do not match any in the second list - if (xmlResponse.getResults().size() > 1) { - for (Result xmlResult : xmlResponse.getResults()) { - boolean found = false; - for (Result jsonResult : jsonResponse.getResults()) { - if (xmlResult.equals(jsonResult)) { - found = true; - break; - } - } - if (found) { - continue; - } - // no match found - System.out.println("No match for XML in " + f.getName()); - System.out.println("XML =" + xmlResult.toString()); - for (Result jsonResult : jsonResponse.getResults()) { - System.out.println("JSON="+ jsonResult.toString()); - } - fail("JSON Response has no match for XML Result: " + xmlResult.toString()); - } - // we've done the best we can for multiple decisions, so go to next file - continue; - } - - // single Result in each - Result xmlResult = xmlResponse.getResults().iterator().next(); - Result jsonResult = jsonResponse.getResults().iterator().next(); - - // The following sections have not given us trouble, so checking is very high-level. - // If we see a problem in one of these elements, the single line will need to be replaced with detailed examination of the objects. - assertEquals(f.getName() + " Decision", xmlResult.getDecision(), jsonResult.getDecision()); - assertEquals(f.getName() + " Status", xmlResult.getStatus(), jsonResult.getStatus()); - - // Obligations - if (xmlResult.getObligations() != jsonResult.getObligations()) { - Collection<Obligation> xmlObligations = xmlResult.getObligations(); - Collection<Obligation> jsonObligations = jsonResult.getObligations(); - // if both are null we do not get here - if (xmlObligations == null || jsonObligations == null) { - fail(f.getName() + " Obligations has null \nXML="+xmlObligations + "\nJSON="+jsonObligations); - } - if (ListUtil.equalsAllowNulls(xmlObligations, jsonObligations) == false) { - // collections are not equal, so need to examine further -fail(f.getName() + " Obligation collections not equal\nXML="+xmlObligations + "\nJSON="+jsonObligations); - } - } - - // AssociatedAdvice - if (xmlResult.getAssociatedAdvice() != jsonResult.getAssociatedAdvice()) { - Collection<Advice> xmlAdvice = xmlResult.getAssociatedAdvice(); - Collection<Advice> jsonAdvice = jsonResult.getAssociatedAdvice(); - // if both are null we do not get here - if (xmlAdvice == null || jsonAdvice == null) { - fail(f.getName() + " Advice has null \nXML="+xmlAdvice + "\nJSON="+jsonAdvice); - } - if (ListUtil.equalsAllowNulls(xmlAdvice, jsonAdvice) == false) { - // collections are not equal, so need to examine further -fail(f.getName() + " Advice collections not equal\nXML="+xmlAdvice + "\nJSON="+jsonAdvice); - } - } - - - - // check Attributes in more detail - Collection<AttributeCategory> xmlAttributes = xmlResult.getAttributes(); - Collection<AttributeCategory> jsonAttributes = jsonResult.getAttributes(); - if (xmlAttributes == null && jsonAttributes != null || - xmlAttributes != null && jsonAttributes == null) { - fail(f.getName() + " XML Attributes="+xmlAttributes + " but JSON Attributes=" + jsonAttributes); - } - if (xmlAttributes != null) { - // both are non-null - if (xmlAttributes.size() != jsonAttributes.size()) { - String xmlAttributesString = "XML categorys="; - for (AttributeCategory ac : xmlAttributes) { - xmlAttributesString += " " + ac.getCategory().stringValue(); - } - String jsonAttributesString = "JSON categorys="; - for (AttributeCategory ac : jsonAttributes) { - jsonAttributesString += " " + ac.getCategory().stringValue(); - } - fail(f.getName() + " XML and JSON have different number of Category elements: " + xmlAttributesString + ", " + jsonAttributesString); - } - - // Attribute collections are the same size but may be in different orders. - // for each XML category try to find the corresponding JSON category. - // ASSUME that each category only shows up once!!!! - for (AttributeCategory xmlAttributeCategory : xmlAttributes) { - boolean attributeCategoryFound = false; - for (AttributeCategory jsonAttributeCategory : jsonAttributes) { - if (xmlAttributeCategory.equals(jsonAttributeCategory)) { - attributeCategoryFound = true; - break; - } - // not an exact match, but if same CategoryId then need to check individual Attribute objects - if (xmlAttributeCategory.getCategory().equals(jsonAttributeCategory.getCategory())) { - // same category - if (xmlAttributeCategory.getAttributes().size() != jsonAttributeCategory.getAttributes().size()) { - System.out.println("XML =" + xmlAttributeCategory.getAttributes()); - System.out.println("JSON=" + jsonAttributeCategory.getAttributes()); - fail(f.getName() + " Attributes Category '" + xmlAttributeCategory.getCategory().stringValue() + "' size mismatch; XML="+ - xmlAttributeCategory.getAttributes().size() +", JSON=" + jsonAttributeCategory.getAttributes().size()); - } - for (Attribute xmlAttr : xmlAttributeCategory.getAttributes()) { - boolean attributeFound = false; - for (Attribute jsonAttr : jsonAttributeCategory.getAttributes()) { - if (xmlAttr.equals(jsonAttr)) { - attributeFound = true; - break; - } - } - - if (attributeFound) { - // check next XML attribute - continue; - } - System.out.println("Attribute not found in JSON, Category="+xmlAttributeCategory.getCategory()); - System.out.println("XML Attribute ="+ xmlAttr); - System.out.println("JSON Attributes=" + jsonAttributeCategory.toString()); - fail(f.getName() + " Attribute not found in JSON, Category=" + xmlAttributeCategory.getCategory() + - "/nXML Attribute="+xmlAttr+ - "\nJSON Category Attributes="+jsonAttributeCategory.toString()); - } - - - - } - } - if (attributeCategoryFound) { - continue; - } - fail("XML Category not found in JSON; xml="+xmlAttributeCategory.toString()); - } - - } - - // PolicyIdentifiers - if (xmlResult.getPolicyIdentifiers() != jsonResult.getPolicyIdentifiers()) { - Collection<IdReference> xmlIdReferences = xmlResult.getPolicyIdentifiers(); - Collection<IdReference> jsonIdReferences = jsonResult.getPolicyIdentifiers(); - // if both are null we do not get here - if (xmlIdReferences == null || jsonIdReferences == null) { - fail(f.getName() + " PolicyIdentifiers has null \nXML="+xmlIdReferences + "\nJSON="+jsonIdReferences); - } - if (ListUtil.equalsAllowNulls(xmlIdReferences, jsonIdReferences) == false) { - // collections are not equal, so need to examine further -fail(f.getName() + " PolicyIdentifiers collections not equal\nXML="+xmlIdReferences+ "\nJSON="+jsonIdReferences); - } - } - - // PolicySetIdentifiers - if (xmlResult.getPolicySetIdentifiers() != jsonResult.getPolicySetIdentifiers()) { - Collection<IdReference> xmlIdReferences = xmlResult.getPolicySetIdentifiers(); - Collection<IdReference> jsonIdReferences = jsonResult.getPolicySetIdentifiers(); - // if both are null we do not get here - if (xmlIdReferences == null || jsonIdReferences == null) { - fail(f.getName() + " PolicySetIdentifiers has null \nXML="+xmlIdReferences + "\nJSON="+jsonIdReferences); - } - if (ListUtil.equalsAllowNulls(xmlIdReferences, jsonIdReferences) == false) { - // collections are not equal, so need to examine further -fail(f.getName() + " PolicySetIdentifiers collections not equal\nXML="+xmlIdReferences + "\nJSON="+jsonIdReferences); - } - } - - - } - - } catch (Exception e) { - fail ("Failed test with '" + currentFile.getName() + "', e=" + e); - } - - - } - - // - // HELPER to get list of all Request files in the given directory - // - - private List<File> getRequestsInDirectory(File directory) { - List<File> fileList = new ArrayList<File>(); - - File[] fileArray = directory.listFiles(); - for (File f : fileArray) { - if (f.isDirectory()) { - List<File> subDirList = getRequestsInDirectory(f); - fileList.addAll(subDirList); - } - if (f.getName().endsWith("Response.xml")) { - fileList.add(f); - } - } - return fileList; - - } - -} - - - - - -/* - * -This is a place to copy the really long output from test rigs that need to be manually edited for readability.... - - - -{"Response":[{"Status":{"StatusCode":{"Value":"urn:oasis:names:tc:xacml:1.0:status:ok"}},"Obligations":[{"Id":"urn:oasis:names:tc:xacml:2.0:conformance-test:IIIA030:obligation-1","AttributeAssignment":[ -{"Value":"assignment1","DataType":"string","AttributeId":"urn:oasis:names:tc:xacml:2.0:conformance-test:IIIA030:assignment1"}, -{"Value":{"Namespaces":[{"Namespace":"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"},{"Namespace":"http://www.w3.org/2001/XMLSchema-instance","Prefix":"xsi"}], - "XPathCategory":"urn:oasis:names:tc:xacml:3.0:attribute-category:resource", - "XPath":"//md:records/md:record"}, - "DataType":"xpathExpression", - "AttributeId":"urn:oasis:names:tc:xacml:2.0:conformance-test:IIIA030:assignment2"}]}],"Decision":"Permit"}]} - - - -*/ - - - - - diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseTest.java deleted file mode 100644 index b2c2fd0f6..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseTest.java +++ /dev/null @@ -1,2297 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.json; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.math.BigInteger; - -import org.junit.Ignore; -import org.junit.Test; - -import com.att.research.xacml.api.Attribute; -import com.att.research.xacml.api.AttributeValue; -import com.att.research.xacml.api.Decision; -import com.att.research.xacml.api.Identifier; -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.IdentifierImpl; -import com.att.research.xacml.std.StdAttribute; -import com.att.research.xacml.std.StdAttributeCategory; -import com.att.research.xacml.std.StdAttributeValue; -import com.att.research.xacml.std.StdIdReference; -import com.att.research.xacml.std.StdMutableAdvice; -import com.att.research.xacml.std.StdMutableAttribute; -import com.att.research.xacml.std.StdMutableAttributeAssignment; -import com.att.research.xacml.std.StdMutableMissingAttributeDetail; -import com.att.research.xacml.std.StdMutableObligation; -import com.att.research.xacml.std.StdMutableResponse; -import com.att.research.xacml.std.StdMutableResult; -import com.att.research.xacml.std.StdMutableStatus; -import com.att.research.xacml.std.StdMutableStatusDetail; -import com.att.research.xacml.std.StdStatusCode; -import com.att.research.xacml.std.StdVersion; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacml.std.datatypes.StringNamespaceContext; -import com.att.research.xacml.std.datatypes.XPathExpressionWrapper; -import com.att.research.xacml.std.json.JSONResponse; -import com.att.research.xacml.std.json.JSONStructureException; - -/** - * Test JSON Responses - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * - */ -public class ResponseTest { - - String jsonResponse; - - StdMutableResponse response; - - StdMutableResult result; - - StdMutableStatus status; - - - // Note: Initially test responses without Obligations, Associated Advice, Attributes, or PolicyIdentifier - - - @Test - public void testEmptyAndDecisions() { - // null response - try { - jsonResponse = JSONResponse.toString(null, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // empty response (no Result object) - response = new StdMutableResponse(); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // just decision, no status - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // just status (empty), no decision - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - result.setStatus(status); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // just status (non-empty), no decision - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_OK); - result.setStatus(status); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // test other decisions without Status - - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.DENY); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Deny\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.NOTAPPLICABLE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"NotApplicable\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.INDETERMINATE_DENY); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Indeterminate{D}\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.INDETERMINATE_DENYPERMIT); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Indeterminate{DP}\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.INDETERMINATE_PERMIT); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Indeterminate{P}\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // test Multiple Decisions - success - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - response.add(result); - StdMutableResult result2 = new StdMutableResult(); - result2.setDecision(Decision.DENY); - response.add(result2); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\"},{\"Decision\":\"Deny\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // test Multiple Decisions - one success and one error - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - response.add(result); - result2 = new StdMutableResult(); - result2.setDecision(Decision.INDETERMINATE); - response.add(result2); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\"},{\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - } - - - - - // Test with every field filled in with multiple values where appropriate - @Ignore //@Test - public void testAllFieldsResponse() { - - // fully-loaded multiple response - - StdMutableResponse response = new StdMutableResponse(); - // create a Status object - StdMutableStatus status = new StdMutableStatus(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - status.setStatusMessage("some status message"); - StdMutableStatusDetail statusDetailIn = new StdMutableStatusDetail(); - StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "doh")); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_INTEGER.getId(), "5432")); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh")); - mad.setAttributeId(XACML3.ID_ACTION_PURPOSE); - mad.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION); - mad.setDataTypeId(XACML3.ID_DATATYPE_STRING); - mad.setIssuer("an Issuer"); - statusDetailIn.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetailIn); - // create a single result object - StdMutableResult result = new StdMutableResult(status); - // set the decision - result.setDecision(Decision.INDETERMINATE); - // put the Result into the Response - response.add(result); - - - // create a new Result with a different Decision - status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK); - result = new StdMutableResult(status); - result.setDecision(Decision.DENY); - - StdMutableObligation obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer2", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Ned"))); - result.addObligation(obligation); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_SUBJECT_CATEGORY_INTERMEDIARY_SUBJECT); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer3", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Maggie"))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer4", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Homer"))); - result.addObligation(obligation); - - - StdMutableAdvice advice = new StdMutableAdvice(); - advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"))); - advice.addAttributeAssignment(new StdMutableAttributeAssignment( - null, - XACML3.ID_SUBJECT, - "advice-issuerNoCategory", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Crusty"))); - result.addAdvice(advice); - - - response.add(result); - - - // create a new Result with a different Decision - // add Child/minor status codes within the main status - StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode")); - StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode); - StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode); - StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); - - status = new StdMutableStatus(statusCode); - - - result = new StdMutableResult(status); - result.setDecision(Decision.PERMIT); - - - - - // add attribute list in result - Identifier categoryIdentifier = new IdentifierImpl("firstCategory"); - Attribute[] attrList = { - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "EIssue", true), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), null, true) }; - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(attrList))); - categoryIdentifier = new IdentifierImpl("secondCategory"); - Attribute[] secondAttrList = { - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) }; - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList))); - - - // add PolicyIdentifierList to result - StdIdReference policyIdentifier1 = null; - StdIdReference policyIdentifier2 = null; - StdIdReference policySetIdentifier1 = null; - StdIdReference policySetIdentifier2 = null; - try { - policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); - policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); - policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); - policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); - } catch (ParseException e1) { - fail("creating policyIds, e="+e1); - } - - result.addPolicyIdentifier(policyIdentifier1); - result.addPolicyIdentifier(policyIdentifier2); - - result.addPolicySetIdentifier(policySetIdentifier1); - result.addPolicySetIdentifier(policySetIdentifier2); - - response.add(result); - - // convert Response to JSON - try { - jsonResponse = JSONResponse.toString(response, false); -System.out.println(jsonResponse); -//System.out.println(JSONResponse.toString(response, true)); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusMessage\":\"some status message\",\"StatusDetail\":\"<MissingAttributeDetail Category=\\\\\\\"urn:oasis:names:tc:xacml:3.0:attribute-category:action\\\\\\\" AttributeId=\\\\\\\"urn:oasis:names:tc:xacml:2.0:action:purpose\\\\\\\" DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#string\\\\\\\" Issuer=\\\\\\\"an Issuer\\\\\\\"><AttributeValue DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#string\\\\\\\">doh</AttributeValue><AttributeValue DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#integer\\\\\\\">5432</AttributeValue><AttributeValue DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#string\\\\\\\">meh</AttributeValue></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"},{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer2\",\"Value\":\"Ned\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]},{\"Id\":\"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer3\",\"Value\":\"Maggie\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer4\",\"Value\":\"Homer\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Deny\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"advice-issuer1\",\"Value\":\"Apu\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"advice-issuerNoCategory\",\"Value\":\"Crusty\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]},{\"Status\":{\"StatusCode\":{\"StatusCode\":{\"StatusCode\":{\"StatusCode\":{\"Value\":\"childChildChildStatusCode\"},\"Value\":\"childChildStatusCode\"},\"Value\":\"child1StatusCode\"},\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"CIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent3\"},{\"Issuer\":\"DIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent4\"},{\"Issuer\":\"EIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent5\"},{\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrNoIssuer\"}]},{\"CategoryId\":\"secondCategory\",\"Attribute\":[{\"Issuer\":\"AIssue2\",\"Value\":\"Apu2\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent12\"},{\"Issuer\":\"CIssue2\",\"Value\":\"Der2\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent32\"}]}],\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicyIdReference\":[{\"Id\":\"idRef1\",\"Version\":\"1.2.3\"},{\"Id\":\"idRef2_NoVersion\"}],\"PolicySetIdReference\":[{\"Id\":\"idSetRef1\",\"Version\":\"4.5.6.7.8.9.0\"},{\"Id\":\"idSetRef2_NoVersion\"}]}}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - } - - - - - // combinations of Status values with Decision values - @Test - public void testDecisionStatusMatch() { - // the tests in this method use different values and do not change structures, so we can re-use the objects - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - result.setStatus(status); - response.add(result); - - // StatusCode = OK - status.setStatusCode(StdStatusCode.STATUS_CODE_OK); - result.setDecision(Decision.PERMIT); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.DENY); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Decision\":\"Deny\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.NOTAPPLICABLE); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"}},\"Decision\":\"NotApplicable\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - result.setDecision(Decision.INDETERMINATE_DENY); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - result.setDecision(Decision.INDETERMINATE_DENYPERMIT); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - result.setDecision(Decision.INDETERMINATE_PERMIT); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - - - - - // StatusCode = SyntaxError - status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); - result.setDecision(Decision.PERMIT); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - result.setDecision(Decision.DENY); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - result.setDecision(Decision.NOTAPPLICABLE); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - result.setDecision(Decision.INDETERMINATE); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"}},\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_DENY); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"}},\"Decision\":\"Indeterminate{D}\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_DENYPERMIT); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"}},\"Decision\":\"Indeterminate{DP}\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_PERMIT); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"}},\"Decision\":\"Indeterminate{P}\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // StatusCode = ProcessingError - status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); - result.setDecision(Decision.PERMIT); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - result.setDecision(Decision.DENY); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - result.setDecision(Decision.NOTAPPLICABLE); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - result.setDecision(Decision.INDETERMINATE); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"}},\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_DENY); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"}},\"Decision\":\"Indeterminate{D}\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_DENYPERMIT); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"}},\"Decision\":\"Indeterminate{DP}\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_PERMIT); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"}},\"Decision\":\"Indeterminate{P}\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - - // StatusCode = MissingAttribute - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - result.setDecision(Decision.PERMIT); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - result.setDecision(Decision.DENY); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - result.setDecision(Decision.NOTAPPLICABLE); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - result.setDecision(Decision.INDETERMINATE); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_DENY); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate{D}\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_DENYPERMIT); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate{DP}\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - result.setDecision(Decision.INDETERMINATE_PERMIT); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate{P}\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - } - - - - - // tests related to Status and its components - @Ignore //@Test - public void testStatus() { - // Status with no StatusCode - error - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - result.setStatus(status); - result.setDecision(Decision.PERMIT); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Status with StatusMessage when OK - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_OK); - status.setStatusMessage("I'm ok, you're ok"); - result.setStatus(status); - result.setDecision(Decision.PERMIT); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with StatusDetail when OK - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_OK); - StdMutableStatusDetail statusDetail = new StdMutableStatusDetail(); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.PERMIT); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Status with StatusMessage when SyntaxError - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); - status.setStatusMessage("I'm ok, you're ok"); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with empty StatusDetail when SyntaxError - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); - statusDetail = new StdMutableStatusDetail(); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Status with StatusMessage when ProcessingError - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); - status.setStatusMessage("I'm ok, you're ok"); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with empty StatusDetail when ProcessingError - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); - statusDetail = new StdMutableStatusDetail(); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - // Status with StatusMessage when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - status.setStatusMessage("I'm ok, you're ok"); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with empty StatusDetail when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"}},\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - - // Status with StatusDetail with empty detail when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail(); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Status with StatusDetail with valid detail with no value when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<MissingAttributeDetail Category=\\\\\\\"urn:oasis:names:tc:xacml:1.0:action\\\\\\\" AttributeId=\\\\\\\"mad\\\\\\\" DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#string\\\\\\\"></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with StatusDetail with valid detail with value when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh")); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<MissingAttributeDetail Category=\\\\\\\"urn:oasis:names:tc:xacml:1.0:action\\\\\\\" AttributeId=\\\\\\\"mad\\\\\\\" DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#string\\\\\\\"><AttributeValue DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#string\\\\\\\">meh</AttributeValue></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Status with StatusDetail with array valid detail with value when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh")); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "nu?")); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<MissingAttributeDetail Category=\\\\\\\"urn:oasis:names:tc:xacml:1.0:action\\\\\\\" AttributeId=\\\\\\\"mad\\\\\\\" DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#string\\\\\\\"><AttributeValue DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#string\\\\\\\">meh</AttributeValue><AttributeValue DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#string\\\\\\\">nu?</AttributeValue></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // Status with StatusDetail with valid detail with Integer value when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_INTEGER.getId()); - mad.addAttributeValue(new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111))); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); -// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<MissingAttributeDetail Category=\\\\\\\"urn:oasis:names:tc:xacml:1.0:action\\\\\\\" AttributeId=\\\\\\\"mad\\\\\\\" DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#string\\\\\\\"><AttributeValue DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#integer\\\\\\\">1111</AttributeValue></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - e.printStackTrace(pw); - - - fail("operation failed, e="+e + sw.toString()); - } - - // Status with StatusDetail with array valid detail with Integer value when MissingAttribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - mad.addAttributeValue(new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111))); - mad.addAttributeValue(new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(2222))); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<MissingAttributeDetail Category=\\\\\\\"urn:oasis:names:tc:xacml:1.0:action\\\\\\\" AttributeId=\\\\\\\"mad\\\\\\\" DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#string\\\\\\\"><AttributeValue DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#integer\\\\\\\">1111</AttributeValue><AttributeValue DataType=\\\\\\\"http://www.w3.org/2001/XMLSchema#integer\\\\\\\">2222</AttributeValue></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - -// StringNamespaceContext snc = new StringNamespaceContext(); -// try { -// snc.add("defaultURI"); -// snc.add("md", "referenceForMD"); -// } catch (Exception e) { -// fail("unable to create NamespaceContext e="+e); -// } -// XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); -// -//TODO - assume that we will never try to pass back an XPathExpression in a MissingAttributeDetail - it doesn't make sense and is unclear how to put into XML -// // Status with StatusDetail with valid detail with XPathExpression value when MissingAttribute -// response = new StdMutableResponse(); -// result = new StdMutableResult(); -// status = new StdMutableStatus(); -// status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); -// statusDetail = new StdMutableStatusDetail(); -// mad = new StdMutableMissingAttributeDetail(); -// mad.setAttributeId(new IdentifierImpl("mad")); -// mad.setCategory(XACML3.ID_ACTION); -// mad.setDataTypeId(DataTypes.DT_STRING.getId()); -// mad.addAttributeValue(new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId"))); -// statusDetail.addMissingAttributeDetail(mad); -// status.setStatusDetail(statusDetail); -// result.setStatus(status); -// result.setDecision(Decision.INDETERMINATE); -// response.add(result); -// try { -// jsonResponse = JSONResponse.toString(response, false); -// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<AttributeValue>1111</AttributeValue><Category>urn:oasis:names:tc:xacml:1.0:action</Category><AttributeId>mad</AttributeId><DataType>http://www.w3.org/2001/XMLSchema#string</DataType></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); -// } catch (Exception e) { -// fail("operation failed, e="+e); -// } -// -// // Status with StatusDetail with array valid detail with XPathExpression value when MissingAttribute -// response = new StdMutableResponse(); -// result = new StdMutableResult(); -// status = new StdMutableStatus(); -// status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE); -// statusDetail = new StdMutableStatusDetail(); -// mad = new StdMutableMissingAttributeDetail(); -// mad.setAttributeId(new IdentifierImpl("mad")); -// mad.setCategory(XACML3.ID_ACTION); -// mad.setDataTypeId(DataTypes.DT_STRING.getId()); -// mad.addAttributeValue(new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId1"))); -// mad.addAttributeValue(new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId2"))); -// statusDetail.addMissingAttributeDetail(mad); -// status.setStatusDetail(statusDetail); -// result.setStatus(status); -// result.setDecision(Decision.INDETERMINATE); -// response.add(result); -// try { -// jsonResponse = JSONResponse.toString(response, false); -// assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<AttributeValue>1111</AttributeValue><AttributeValue>2222</AttributeValue><Category>urn:oasis:names:tc:xacml:1.0:action</Category><AttributeId>mad</AttributeId><DataType>http://www.w3.org/2001/XMLSchema#string</DataType></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", jsonResponse); -// } catch (Exception e) { -// fail("operation failed, e="+e); -// } - -//TODO - try with other data types, esp XPathExpression - - // Status with StatusDetail with array valid detail with value when SyntaxError - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh")); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "nu?")); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Status with StatusDetail with array valid detail with value when ProcessingError - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR); - statusDetail = new StdMutableStatusDetail(); - mad = new StdMutableMissingAttributeDetail(); - mad.setAttributeId(new IdentifierImpl("mad")); - mad.setCategory(XACML3.ID_ACTION); - mad.setDataTypeId(DataTypes.DT_STRING.getId()); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh")); - mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "nu?")); - statusDetail.addMissingAttributeDetail(mad); - status.setStatusDetail(statusDetail); - result.setStatus(status); - result.setDecision(Decision.INDETERMINATE); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - - // Status with nested child StatusCodes (child status containing child status containing...) - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode")); - StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); - status = new StdMutableStatus(statusCode); - status.setStatusMessage("I'm ok, you're ok"); - result.setStatus(status); - result.setDecision(Decision.PERMIT); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"StatusCode\":{\"Value\":\"child1StatusCode\"},\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - response = new StdMutableResponse(); - result = new StdMutableResult(); - status = new StdMutableStatus(); - StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode")); - StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode); - child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode); - statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode); - status = new StdMutableStatus(statusCode); - status.setStatusMessage("I'm ok, you're ok"); - result.setStatus(status); - result.setDecision(Decision.PERMIT); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"StatusCode\":{\"StatusCode\":{\"StatusCode\":{\"Value\":\"childChildChildStatusCode\"},\"Value\":\"childChildStatusCode\"},\"Value\":\"child1StatusCode\"},\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:ok\"},\"StatusMessage\":\"I'm ok, you're ok\"},\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - } - - - - @Ignore //@Test - public void testObligations() { - - // create an XPathExpression for use later - StringNamespaceContext snc = new StringNamespaceContext(); - try { - snc.add("defaultURI"); - snc.add("md", "referenceForMD"); - } catch (Exception e) { - fail("unable to create NamespaceContext e="+e); - } - XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); - XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital"); - - StdMutableObligation obligation; - - // test Obligation single decision no attributes - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // obligation missing Id - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - - // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - null, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // AttributeAssignment - Missing AttributeId - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - null, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // AttributeAssignment - Missing Value - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - null)); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // AttributeAssignment - missing DataType - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(null, "Bart"))); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // AttributeAssignment - missing issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // AttributeAssignment - Integer type - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111)))); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":1111,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // AttributeAssignment - XPathExpression type - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:record\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - - - // - // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition: - // <Obligation (attributes of the obligation) > - // <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment> - // <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment> - // : - // </Obligation - // which means that there may be multiple AttributeAssignments but each one has only one value. - // This differs from the Attributes section in which each <Attribute> may have multiple <AttributeValue> elements. - // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer. - // - - - // AttributeAssignment - Multiple values with same Category and Id (one way of doing array) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Lisa"))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Maggie"))); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Lisa\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer1\",\"Value\":\"Maggie\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111)))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(2222)))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "obligation-issuer1", - new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(3333)))); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"obligation-issuer1\",\"Value\":1111,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer1\",\"Value\":2222,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"obligation-issuer1\",\"Value\":3333,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // Multiple XPathExpression values with same Category and Id (one way of doing array) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - obligation = new StdMutableObligation(); - obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); - obligation.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory")))); - result.addObligation(obligation); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Obligations\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:record\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:hospital\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - } - - - - - @Ignore //@Test - public void testAdvice() { - - // create an XPathExpression for use later - StringNamespaceContext snc = new StringNamespaceContext(); - try { - snc.add("defaultURI"); - snc.add("md", "referenceForMD"); - } catch (Exception e) { - fail("unable to create NamespaceContext e="+e); - } - XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); - XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital"); - - StdMutableAdvice Advice; - - // test Advice single decision no attributes - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"}]}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Advice missing Id - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - - - // AttributeAssignment - with AttributeId, Value, Category, DataType, Issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // AttributeAssignment - with AttributeId, Value, no Category, DataType, Issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - null, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Bart\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // AttributeAssignment - Missing AttributeId - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - null, - "Advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // AttributeAssignment - Missing Value - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - null)); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // AttributeAssignment - missing DataType - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<String>(null, "Bart"))); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // AttributeAssignment - missing issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // AttributeAssignment - Integer type - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111)))); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":1111,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // AttributeAssignment - XPathExpression type - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:record\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - - - // - // Technically arrays cannot occur in Obligations and Advice elements. The XML spec boils down to the following definition: - // <Obligation (attributes of the obligation) > - // <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment> - // <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment> - // : - // </Obligation - // which means that there may be multiple AttributeAssignments but each one has only one value. - // This differs from the Attributes section in which each <Attribute> may have multiple <AttributeValue> elements. - // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer. - // - - // AttributeAssignment - Multiple values with same Category and Id (one way of doing array) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"))); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Lisa"))); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Maggie"))); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Bart\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Lisa\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"Advice-issuer1\",\"Value\":\"Maggie\",\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // AttributeAssignment - Multiple Integer values with same Category and Id (one way of doing array) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(1111)))); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(2222)))); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - "Advice-issuer1", - new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(3333)))); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Issuer\":\"Advice-issuer1\",\"Value\":1111,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"Advice-issuer1\",\"Value\":2222,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Issuer\":\"Advice-issuer1\",\"Value\":3333,\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // Multiple XPathExpression values with same Category and Id (one way of doing array) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - Advice = new StdMutableAdvice(); - Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory")))); - Advice.addAttributeAssignment(new StdMutableAttributeAssignment( - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - XACML3.ID_SUBJECT, - null, - new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory")))); - result.addAdvice(Advice); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"AssociatedAdvice\":[{\"Id\":\"urn:oasis:names:tc:xacml:1.0:action:implied-action\",\"AttributeAssignment\":[{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:record\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"},{\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"SimpleXPathCategory\",\"XPath\":\"//md:hospital\"},\"Category\":\"urn:oasis:names:tc:xacml:3.0:attribute-category:resource\",\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:subject\"}]}]}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - } - - - - - - - - - - - // Attributes tests - @Ignore //@Test - public void testAttributes() { - - // create an XPathExpression for use later - StringNamespaceContext snc = new StringNamespaceContext(); - try { - snc.add("defaultURI"); - snc.add("md", "referenceForMD"); - } catch (Exception e) { - fail("unable to create NamespaceContext e="+e); - } - XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record"); - - - Identifier categoryIdentifier; - List<Attribute> attrList = new ArrayList<Attribute>(); - StdMutableAttribute mutableAttribute; - - // Attr list with no entries - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // one Attribute - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // multiple attributes - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "EIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"BIssue\",\"Value\":\"P10Y4M\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\",\"AttributeId\":\"attrIdent2\"},{\"Issuer\":\"CIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent3\"},{\"Issuer\":\"DIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent4\"},{\"Issuer\":\"EIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent5\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // IncludeInResult=false/true - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", false)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // Missing AttributeId (mandatory) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, null, new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Missing mandatory Value - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), null), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // Missing optional Issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), null, true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // missing optional DataType - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(null, "Apu"), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // same id, same type different issuer - // (This is not an array of values because issuer is different) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"), "BIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Simpson"), "CIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"BIssue\",\"Value\":\"Bart\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"CIssue\",\"Value\":\"Simpson\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // same id, same type different issuer - // (This is effectively an array of values, but we return them as separate values to the client) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Simpson"), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":\"Bart\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":\"Simpson\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // same Id, different types, same issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":\"P10Y4M\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"AIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // same Id, different types, different issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "EIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), null, true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"BIssue\",\"Value\":\"P10Y4M\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"CIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"DIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"EIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent1\"},{\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - // different Id, different types, same issuer - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "AIssue"), "BIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"BIssue\",\"Value\":\"AIssue\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\",\"AttributeId\":\"attrIdent2\"},{\"Issuer\":\"AIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent3\"},{\"Issuer\":\"AIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent4\"},{\"Issuer\":\"AIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent5\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // one Attribute of type XPathExpression (the only complex data type) - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategory")), "AIssue", true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":{\"Namespaces\":[{\"Namespace\":\"referenceForMD\",\"Prefix\":\"md\"},{\"Namespace\":\"defaultURI\"}],\"XPathCategory\":\"xpathCategory\",\"XPath\":\"//md:record\"},\"DataType\":\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // multiple sets of values - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - categoryIdentifier = new IdentifierImpl("firstCategory"); - attrList.clear(); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), "EIssue", true)); - attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567)), null, true)); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - categoryIdentifier = new IdentifierImpl("secondCategory"); - Attribute[] secondAttrList = { - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false), - new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) }; - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList))); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":\"Apu\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"},{\"Issuer\":\"CIssue\",\"Value\":765.432,\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent3\"},{\"Issuer\":\"DIssue\",\"Value\":true,\"DataType\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"AttributeId\":\"attrIdent4\"},{\"Issuer\":\"EIssue\",\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrIdent5\"},{\"Value\":4567,\"DataType\":\"http://www.w3.org/2001/XMLSchema#integer\",\"AttributeId\":\"attrNoIssuer\"}]},{\"CategoryId\":\"secondCategory\",\"Attribute\":[{\"Issuer\":\"AIssue2\",\"Value\":\"Apu2\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent12\"},{\"Issuer\":\"CIssue2\",\"Value\":\"Der2\",\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent32\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // array of values - same type - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - attrList.clear(); - categoryIdentifier = new IdentifierImpl("firstCategory"); - mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection<AttributeValue<?>>)null, "AIssue", true); - - mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu")); - mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")); - mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Homer")); - mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Ned")); - - attrList.add(mutableAttribute); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":[\"Apu\",\"Bart\",\"Homer\",\"Ned\"],\"DataType\":\"http://www.w3.org/2001/XMLSchema#string\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // array of values - compatible different types - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - attrList.clear(); - categoryIdentifier = new IdentifierImpl("firstCategory"); - mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection<AttributeValue<?>>)null, "AIssue", true); - - mutableAttribute.addValue(new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567))); - mutableAttribute.addValue(new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432)); - mutableAttribute.addValue(new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567))); - attrList.add(mutableAttribute); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Category\":[{\"CategoryId\":\"firstCategory\",\"Attribute\":[{\"Issuer\":\"AIssue\",\"Value\":[4567,765.432,4567],\"DataType\":\"http://www.w3.org/2001/XMLSchema#double\",\"AttributeId\":\"attrIdent1\"}]}],\"Decision\":\"Permit\"}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // array of values - incompatible different types - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - attrList.clear(); - categoryIdentifier = new IdentifierImpl("firstCategory"); - mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection<AttributeValue<?>>)null, "AIssue", true); - - mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu")); - mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M")); - mutableAttribute.addValue(new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432)); - mutableAttribute.addValue(new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true)); - mutableAttribute.addValue(new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567))); - mutableAttribute.addValue(new StdAttributeValue<BigInteger>(DataTypes.DT_INTEGER.getId(), BigInteger.valueOf(4567))); - attrList.add(mutableAttribute); - result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList)); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - } - - - - - - // PolicyIdentifier tests - @Ignore //@Test - public void testPolicyIdentifier() { - - StdIdReference policyIdentifier1 = null; - StdIdReference policyIdentifier2 = null; - StdIdReference policySetIdentifier1 = null; - StdIdReference policySetIdentifier2 = null; - - // multiple PolicyIdentifiers of both types - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - try { - policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); - policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); - policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); - policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); - } catch (ParseException e1) { - fail("creating policyIds, e="+e1); - } - result.addPolicyIdentifier(policyIdentifier1); - result.addPolicyIdentifier(policyIdentifier2); - result.addPolicySetIdentifier(policySetIdentifier1); - result.addPolicySetIdentifier(policySetIdentifier2); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicyIdReference\":[{\"Id\":\"idRef1\",\"Version\":\"1.2.3\"},{\"Id\":\"idRef2_NoVersion\"}],\"PolicySetIdReference\":[{\"Id\":\"idSetRef1\",\"Version\":\"4.5.6.7.8.9.0\"},{\"Id\":\"idSetRef2_NoVersion\"}]}}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // PolicyIdentifier exists but has no IdReferences - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - policyIdentifier1 = null; - result.addPolicyIdentifier(policyIdentifier1); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // PolicySetIdentifier exists but has not IdReferences - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - policySetIdentifier1 = null; - result.addPolicyIdentifier(policySetIdentifier1); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - fail("Operation should throw exception"); - } catch (JSONStructureException e) { - // correct response - } catch (Exception e) { - fail ("Failed convert from JSON to object: " + e); - } - - // PolicyIdentifier with PolicyIdReference and no PolicySetIdReference - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - try { - policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3")); - } catch (ParseException e1) { - fail("creating policyIds, e="+e1); - } - result.addPolicyIdentifier(policyIdentifier1); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicyIdReference\":[{\"Id\":\"idRef1\",\"Version\":\"1.2.3\"}]}}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - - // PolicyIdentifier with no PolicyIdReference and with PolicySetIdReference - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - try { - policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0")); - } catch (ParseException e1) { - fail("creating policyIds, e="+e1); - } - result.addPolicySetIdentifier(policySetIdentifier1); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicySetIdReference\":[{\"Id\":\"idSetRef1\",\"Version\":\"4.5.6.7.8.9.0\"}]}}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - - - // IdReferences without version - response = new StdMutableResponse(); - result = new StdMutableResult(); - result.setDecision(Decision.PERMIT); - - policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), null); - policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion")); - policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1")); - policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion")); - - result.addPolicyIdentifier(policyIdentifier1); - result.addPolicyIdentifier(policyIdentifier2); - result.addPolicySetIdentifier(policySetIdentifier1); - result.addPolicySetIdentifier(policySetIdentifier2); - response.add(result); - try { - jsonResponse = JSONResponse.toString(response, false); - assertEquals("{\"Response\":[{\"Decision\":\"Permit\",\"PolicyIdentifier\":{\"PolicyIdReference\":[{\"Id\":\"idRef1\"},{\"Id\":\"idRef2_NoVersion\"}],\"PolicySetIdReference\":[{\"Id\":\"idSetRef1\"},{\"Id\":\"idSetRef2_NoVersion\"}]}}]}", jsonResponse); - } catch (Exception e) { - fail("operation failed, e="+e); - } - } - - -//TODO - the JSON and XML spec imply that the Result Attributes may include the Content (It is part of the UML) - - - // test indentation??? - - // order does not matter?? - -} - - - - - - - - - - - - - - - - |