aboutsummaryrefslogtreecommitdiffstats
path: root/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json
diff options
context:
space:
mode:
Diffstat (limited to 'ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json')
-rw-r--r--ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestCategoryTest.java4174
-rw-r--r--ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestConformanceTest.java255
-rw-r--r--ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestDefaultCategoryTest.java1427
-rw-r--r--ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestMainTest.java1076
-rw-r--r--ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseConformanceTest.java370
-rw-r--r--ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseTest.java2297
6 files changed, 9599 insertions, 0 deletions
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
new file mode 100644
index 000000000..0afde1729
--- /dev/null
+++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestCategoryTest.java
@@ -0,0 +1,4174 @@
+/*-
+ * ============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
new file mode 100644
index 000000000..54f5b26f8
--- /dev/null
+++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestConformanceTest.java
@@ -0,0 +1,255 @@
+/*-
+ * ============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
new file mode 100644
index 000000000..2465b3768
--- /dev/null
+++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestDefaultCategoryTest.java
@@ -0,0 +1,1427 @@
+/*-
+ * ============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
new file mode 100644
index 000000000..eb19e35a2
--- /dev/null
+++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/RequestMainTest.java
@@ -0,0 +1,1076 @@
+/*-
+ * ============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
new file mode 100644
index 000000000..adf903022
--- /dev/null
+++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseConformanceTest.java
@@ -0,0 +1,370 @@
+/*-
+ * ============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
new file mode 100644
index 000000000..b2c2fd0f6
--- /dev/null
+++ b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/json/ResponseTest.java
@@ -0,0 +1,2297 @@
+/*-
+ * ============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??
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+