Initial OpenECOMP policy/engine commit
[policy/engine.git] / ECOMP-XACML / src / test / java / org / openecomp / policy / xacml / test / DOMResponseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-XACML
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.policy.xacml.test;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.fail;
25
26 import java.text.ParseException;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.Collection;
30 import java.util.List;
31
32 import org.junit.Test;
33
34 import com.att.research.xacml.api.Attribute;
35 import com.att.research.xacml.api.AttributeValue;
36 import com.att.research.xacml.api.Decision;
37 import com.att.research.xacml.api.Identifier;
38 import com.att.research.xacml.api.XACML3;
39 import com.att.research.xacml.std.IdentifierImpl;
40 import com.att.research.xacml.std.StdAttribute;
41 import com.att.research.xacml.std.StdAttributeCategory;
42 import com.att.research.xacml.std.StdAttributeValue;
43 import com.att.research.xacml.std.StdIdReference;
44 import com.att.research.xacml.std.StdMutableAdvice;
45 import com.att.research.xacml.std.StdMutableAttribute;
46 import com.att.research.xacml.std.StdMutableAttributeAssignment;
47 import com.att.research.xacml.std.StdMutableMissingAttributeDetail;
48 import com.att.research.xacml.std.StdMutableObligation;
49 import com.att.research.xacml.std.StdMutableResponse;
50 import com.att.research.xacml.std.StdMutableResult;
51 import com.att.research.xacml.std.StdMutableStatus;
52 import com.att.research.xacml.std.StdMutableStatusDetail;
53 import com.att.research.xacml.std.StdStatusCode;
54 import com.att.research.xacml.std.StdVersion;
55 import com.att.research.xacml.std.datatypes.DataTypes;
56 import com.att.research.xacml.std.datatypes.StringNamespaceContext;
57 import com.att.research.xacml.std.datatypes.XPathExpressionWrapper;
58 import com.att.research.xacml.std.dom.DOMResponse;
59 import com.att.research.xacml.std.dom.DOMStructureException;
60
61 /**
62  * Test DOM XML Responses
63  * 
64  * TO RUN - use jUnit
65  * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
66  * 
67  * This class was copied from the JSON tests.  At this time only the first two methods have been revised to work with XML.
68  * The second method includes multiple instances of all possible fields and has been manually verified.
69  * The remaining methods have not been converted because:
70  *      - "conversion" consists of replacing the JSON strings with XML
71  *      - the replacement would consist of copying the XML from the JUnit output and doing a String replace
72  *      - there would be little examination of the (long) XML strings, so their validity would be questionable
73  * so the benefit for the cost of doing that work is not clear.
74  * 
75  *
76  */
77 public class DOMResponseTest {
78
79         String xmlResponse;
80         
81         StdMutableResponse response;
82         
83         StdMutableResult result;
84         
85         StdMutableStatus status;
86         
87         
88         // Note: Initially test responses without Obligations, Associated Advice, Attributes, or PolicyIdentifier
89         
90         
91         @Test
92         public void testEmptyAndDecisions() {
93                 // null response
94                 try {
95                         xmlResponse = DOMResponse.toString(null, false);
96                         fail("Operation should throw exception");
97                 } catch (DOMStructureException e) {
98                         // correct response
99                 } catch (Exception e) {
100                         fail ("Failed convert from object to XML: " + e);
101                 }
102                 
103                 // empty response (no Result object)
104                 response = new StdMutableResponse();
105                 try {
106                         xmlResponse = DOMResponse.toString(response, false);
107                         fail("Operation should throw exception");
108                 } catch (DOMStructureException e) {
109                         // correct response
110                 } catch (Exception e) {
111                         fail ("Failed convert from object to XML: " + e);
112                 }
113                 
114                 
115                 // just decision, no status
116                 response = new StdMutableResponse();
117                 result = new StdMutableResult();
118                 result.setDecision(Decision.PERMIT);
119                 response.add(result);
120                 try {
121                         xmlResponse = DOMResponse.toString(response, false);
122                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision></Result></Response>", xmlResponse);
123                 } catch (Exception e) {
124                         fail("operation failed, e="+e);
125                 }
126                 
127                 // just status (empty), no decision
128                 response = new StdMutableResponse();
129                 result = new StdMutableResult();
130                 status = new StdMutableStatus();                
131                 result.setStatus(status);
132                 response.add(result);
133                 try {
134                         xmlResponse = DOMResponse.toString(response, false);
135                         fail("Operation should throw exception");
136                 } catch (DOMStructureException e) {
137                         // correct response
138                 } catch (Exception e) {
139                         fail ("Failed convert from object to XML: " + e);
140                 }
141                 
142                 // just status (non-empty), no decision
143                 response = new StdMutableResponse();
144                 result = new StdMutableResult();
145                 status = new StdMutableStatus();
146                 status.setStatusCode(StdStatusCode.STATUS_CODE_OK);
147                 result.setStatus(status);
148                 response.add(result);
149                 try {
150                         xmlResponse = DOMResponse.toString(response, false);
151                         fail("Operation should throw exception");
152                 } catch (DOMStructureException e) {
153                         // correct response
154                 } catch (Exception e) {
155                         fail ("Failed convert from object to XML: " + e);
156                 }
157                 
158                 
159                 // test other decisions without Status
160                 
161                 response = new StdMutableResponse();
162                 result = new StdMutableResult();
163                 result.setDecision(Decision.DENY);
164                 response.add(result);
165                 try {
166                         xmlResponse = DOMResponse.toString(response, false);
167                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Deny</Decision></Result></Response>", xmlResponse);
168                 } catch (Exception e) {
169                         fail("operation failed, e="+e);
170                 }
171                 
172                 response = new StdMutableResponse();
173                 result = new StdMutableResult();
174                 result.setDecision(Decision.NOTAPPLICABLE);
175                 response.add(result);
176                 try {
177                         xmlResponse = DOMResponse.toString(response, false);
178                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>NotApplicable</Decision></Result></Response>", xmlResponse);
179                 } catch (Exception e) {
180                         fail("operation failed, e="+e);
181                 }
182                 
183                 response = new StdMutableResponse();
184                 result = new StdMutableResult();
185                 result.setDecision(Decision.INDETERMINATE);
186                 response.add(result);
187                 try {
188                         xmlResponse = DOMResponse.toString(response, false);
189                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision></Result></Response>", xmlResponse);
190                 } catch (Exception e) {
191                         fail("operation failed, e="+e);
192                 }
193                 
194                 response = new StdMutableResponse();
195                 result = new StdMutableResult();
196                 result.setDecision(Decision.INDETERMINATE_DENY);
197                 response.add(result);
198                 try {
199                         xmlResponse = DOMResponse.toString(response, false);
200                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{D}</Decision></Result></Response>", xmlResponse);
201                 } catch (Exception e) {
202                         fail("operation failed, e="+e);
203                 }
204                 
205                 response = new StdMutableResponse();
206                 result = new StdMutableResult();
207                 result.setDecision(Decision.INDETERMINATE_DENYPERMIT);
208                 response.add(result);
209                 try {
210                         xmlResponse = DOMResponse.toString(response, false);
211                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{DP}</Decision></Result></Response>", xmlResponse);
212                 } catch (Exception e) {
213                         fail("operation failed, e="+e);
214                 }
215                 
216                 response = new StdMutableResponse();
217                 result = new StdMutableResult();
218                 result.setDecision(Decision.INDETERMINATE_PERMIT);
219                 response.add(result);
220                 try {
221                         xmlResponse = DOMResponse.toString(response, false);
222                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{P}</Decision></Result></Response>", xmlResponse);
223                 } catch (Exception e) {
224                         fail("operation failed, e="+e);
225                 }
226
227                 
228                 // test Multiple Decisions - success
229                 response = new StdMutableResponse();
230                 result = new StdMutableResult();
231                 result.setDecision(Decision.PERMIT);
232                 response.add(result);
233                 StdMutableResult result2 = new StdMutableResult();
234                 result2.setDecision(Decision.DENY);
235                 response.add(result2);
236                 try {
237                         xmlResponse = DOMResponse.toString(response, false);
238                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision></Result><Result><Decision>Deny</Decision></Result></Response>", xmlResponse);
239                 } catch (Exception e) {
240                         fail("operation failed, e="+e);
241                 }
242                 
243                 
244                 // test Multiple Decisions - one success and one error
245                 response = new StdMutableResponse();
246                 result = new StdMutableResult();
247                 result.setDecision(Decision.PERMIT);
248                 response.add(result);
249                 result2 = new StdMutableResult();
250                 result2.setDecision(Decision.INDETERMINATE);
251                 response.add(result2);
252                 try {
253                         xmlResponse = DOMResponse.toString(response, false);
254                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision></Result><Result><Decision>Indeterminate</Decision></Result></Response>", xmlResponse);
255                 } catch (Exception e) {
256                         fail("operation failed, e="+e);
257                 }
258         }
259                 
260
261         
262         
263         // Test with every field filled in with multiple values where appropriate
264         @Test
265         public void testAllFieldsResponse() {   
266                 
267                 // fully-loaded multiple response
268                 
269                 StdMutableResponse response = new StdMutableResponse();
270                 // create a Status object
271                 StdMutableStatus status = new StdMutableStatus(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
272                 status.setStatusMessage("some status message");
273                 StdMutableStatusDetail statusDetailIn = new StdMutableStatusDetail();
274                 StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail();
275                 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "doh"));
276                 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_INTEGER.getId(), "5432"));
277                 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh"));
278                 mad.setAttributeId(XACML3.ID_ACTION_PURPOSE);
279                 mad.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION);
280                 mad.setDataTypeId(XACML3.ID_DATATYPE_STRING);
281                 mad.setIssuer("an Issuer");
282                 statusDetailIn.addMissingAttributeDetail(mad);
283                 status.setStatusDetail(statusDetailIn);
284                 // create a single result object
285                 StdMutableResult result = new StdMutableResult(status);
286                 // set the decision
287                 result.setDecision(Decision.INDETERMINATE);
288                 // put the Result into the Response
289                 response.add(result);
290
291                 
292                 // create a new Result with a different Decision
293                 status = new StdMutableStatus(StdStatusCode.STATUS_CODE_OK);
294                 result = new StdMutableResult(status);
295                 result.setDecision(Decision.DENY);
296                 
297                 StdMutableObligation obligation = new StdMutableObligation();
298                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
299                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
300                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
301                                 XACML3.ID_SUBJECT, 
302                                 "obligation-issuer1", 
303                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
304                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
305                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
306                                 XACML3.ID_SUBJECT, 
307                                 "obligation-issuer2", 
308                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Ned")));
309                 result.addObligation(obligation);
310                 obligation = new StdMutableObligation();
311                 obligation.setId(XACML3.ID_SUBJECT_CATEGORY_INTERMEDIARY_SUBJECT);
312                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
313                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
314                                 XACML3.ID_SUBJECT, 
315                                 "obligation-issuer3", 
316                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Maggie")));
317                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
318                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
319                                 XACML3.ID_SUBJECT, 
320                                 "obligation-issuer4", 
321                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Homer")));
322                 result.addObligation(obligation);
323                 
324                 
325                 StdMutableAdvice advice = new StdMutableAdvice();
326                 advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
327                 advice.addAttributeAssignment(new StdMutableAttributeAssignment(
328                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
329                                 XACML3.ID_SUBJECT, 
330                                 "advice-issuer1", 
331                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu")));
332                 advice.addAttributeAssignment(new StdMutableAttributeAssignment(
333                                 null, 
334                                 XACML3.ID_SUBJECT, 
335                                 "advice-issuerNoCategory", 
336                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Crusty")));
337                 result.addAdvice(advice);
338                 
339                 
340                 response.add(result);
341                 
342                 
343                 // create a new Result with a different Decision
344                 // add Child/minor status codes within the main status
345                 StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode"));
346                 StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode);
347                 StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode);
348                 StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode);
349                 
350                 status = new StdMutableStatus(statusCode);
351                 
352                 
353                 result = new StdMutableResult(status);
354                 result.setDecision(Decision.PERMIT);
355                 
356                 
357                 
358                 
359                 // add attribute list in result
360                 Identifier categoryIdentifier = new IdentifierImpl("firstCategory");
361                 Attribute[] attrList = {
362                                 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true),
363                                 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false),
364                                 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true),
365                                 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true),
366                                 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true),
367                                 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), null, true) };
368                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(attrList)));
369                 categoryIdentifier = new IdentifierImpl("secondCategory");
370                 Attribute[] secondAttrList = {
371                                 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true),
372                                 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false),
373                                 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) };
374                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList)));
375                 
376                 
377                 // add PolicyIdentifierList to result
378                 StdIdReference policyIdentifier1 = null;
379                 StdIdReference policyIdentifier2 = null;
380                 StdIdReference policySetIdentifier1 = null;
381                 StdIdReference policySetIdentifier2 = null;
382                 try {
383                         policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3"));
384                         policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion"));
385                         policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0"));
386                         policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion"));
387                 } catch (ParseException e1) {
388                         fail("creating policyIds, e="+e1);
389                 }
390                 
391                 result.addPolicyIdentifier(policyIdentifier1);
392                 result.addPolicyIdentifier(policyIdentifier2);
393         
394                 result.addPolicySetIdentifier(policySetIdentifier1);
395                 result.addPolicySetIdentifier(policySetIdentifier2);
396                 
397                 response.add(result);
398         
399                 // convert Response to XML
400                 try {
401                         xmlResponse = DOMResponse.toString(response, false);
402 //System.out.println(xmlResponse);
403 //System.out.println(DOMResponse.toString(response, true));
404                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusMessage>some status message</StatusMessage><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:3.0:attribute-category:action\" AttributeId=\"urn:oasis:names:tc:xacml:2.0:action:purpose\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\" Issuer=\"an Issuer\"><AttributeValue>doh</AttributeValue><AttributeValue>5432</AttributeValue><AttributeValue>meh</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result><Result><Decision>Deny</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Ned</AttributeAssignment></Obligation><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:subject-category:intermediary-subject\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Maggie</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Homer</AttributeAssignment></Obligation></Obligations><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Crusty</AttributeAssignment></Advice></AssociatedAdvice></Result><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"><StatusCode Value=\"child1StatusCode\"><StatusCode Value=\"childChildStatusCode\"><StatusCode Value=\"childChildChildStatusCode\"/></StatusCode></StatusCode></StatusCode></Status><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent3\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent4\" Issuer=\"DIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent5\" Issuer=\"EIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrNoIssuer\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes><Attributes Category=\"secondCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent12\" Issuer=\"AIssue2\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu2</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent32\" Issuer=\"CIssue2\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Der2</AttributeValue></Attribute></Attributes><PolicyIdentifierList><PolicyIdReference Version=\"1.2.3\">idRef1</PolicyIdReference><PolicyIdReference>idRef2_NoVersion</PolicyIdReference><PolicySetIdReference Version=\"4.5.6.7.8.9.0\">idSetRef1</PolicySetIdReference><PolicySetIdReference>idSetRef2_NoVersion</PolicySetIdReference></PolicyIdentifierList></Result></Response>", xmlResponse);
405                 } catch (Exception e) {
406                         fail("operation failed, e="+e);
407                 }
408         }
409         
410         
411         
412         
413         // combinations of Status values with Decision values
414         @Test
415         public void testDecisionStatusMatch() {
416                 // the tests in this method use different values and do not change structures, so we can re-use the objects
417                 response = new StdMutableResponse();
418                 result = new StdMutableResult();
419                 status = new StdMutableStatus();
420                 result.setStatus(status);
421                 response.add(result);
422                 
423                 // StatusCode = OK
424                 status.setStatusCode(StdStatusCode.STATUS_CODE_OK);
425                 result.setDecision(Decision.PERMIT);
426                 try {
427                         xmlResponse = DOMResponse.toString(response, false);
428                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status></Result></Response>", xmlResponse);
429                 } catch (Exception e) {
430                         fail("operation failed, e="+e);
431                 }
432                 result.setDecision(Decision.DENY);
433                 try {
434                         xmlResponse = DOMResponse.toString(response, false);
435                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Deny</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status></Result></Response>", xmlResponse);
436                 } catch (Exception e) {
437                         fail("operation failed, e="+e);
438                 }
439                 result.setDecision(Decision.NOTAPPLICABLE);
440                 try {
441                         xmlResponse = DOMResponse.toString(response, false);
442                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>NotApplicable</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/></Status></Result></Response>", xmlResponse);
443                 } catch (Exception e) {
444                         fail("operation failed, e="+e);
445                 }
446                 result.setDecision(Decision.INDETERMINATE);
447                 try {
448                         xmlResponse = DOMResponse.toString(response, false);
449                         fail("Operation should throw exception");
450                 } catch (DOMStructureException e) {
451                         // correct response
452                 } catch (Exception e) {
453                         fail ("Failed convert from object to XML: " + e);
454                 }
455                 result.setDecision(Decision.INDETERMINATE_DENY);
456                 try {
457                         xmlResponse = DOMResponse.toString(response, false);
458                         fail("Operation should throw exception");
459                 } catch (DOMStructureException e) {
460                         // correct response
461                 } catch (Exception e) {
462                         fail ("Failed convert from object to XML: " + e);
463                 }
464                 result.setDecision(Decision.INDETERMINATE_DENYPERMIT);
465                 try {
466                         xmlResponse = DOMResponse.toString(response, false);
467                         fail("Operation should throw exception");
468                 } catch (DOMStructureException e) {
469                         // correct response
470                 } catch (Exception e) {
471                         fail ("Failed convert from object to XML: " + e);
472                 }
473                 result.setDecision(Decision.INDETERMINATE_PERMIT);
474                 try {
475                         xmlResponse = DOMResponse.toString(response, false);
476                         fail("Operation should throw exception");
477                 } catch (DOMStructureException e) {
478                         // correct response
479                 } catch (Exception e) {
480                         fail ("Failed convert from object to XML: " + e);
481                 }
482                 
483                 
484                 
485                 
486                 
487                 
488                 // StatusCode = SyntaxError
489                 status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR);
490                 result.setDecision(Decision.PERMIT);
491                 try {
492                         xmlResponse = DOMResponse.toString(response, false);
493                         fail("Operation should throw exception");
494                 } catch (DOMStructureException e) {
495                         // correct response
496                 } catch (Exception e) {
497                         fail ("Failed convert from object to XML: " + e);
498                 }
499                 result.setDecision(Decision.DENY);
500                 try {
501                         xmlResponse = DOMResponse.toString(response, false);
502                         fail("Operation should throw exception");
503                 } catch (DOMStructureException e) {
504                         // correct response
505                 } catch (Exception e) {
506                         fail ("Failed convert from object to XML: " + e);
507                 }
508                 result.setDecision(Decision.NOTAPPLICABLE);
509                 try {
510                         xmlResponse = DOMResponse.toString(response, false);
511                         fail("Operation should throw exception");
512                 } catch (DOMStructureException e) {
513                         // correct response
514                 } catch (Exception e) {
515                         fail ("Failed convert from object to XML: " + e);
516                 }
517                 result.setDecision(Decision.INDETERMINATE);
518                 try {
519                         xmlResponse = DOMResponse.toString(response, false);
520                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/></Status></Result></Response>", xmlResponse);
521                 } catch (Exception e) {
522                         fail("operation failed, e="+e);
523                 }
524                 result.setDecision(Decision.INDETERMINATE_DENY);
525                 try {
526                         xmlResponse = DOMResponse.toString(response, false);
527                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{D}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/></Status></Result></Response>", xmlResponse);
528                 } catch (Exception e) {
529                         fail("operation failed, e="+e);
530                 }
531                 result.setDecision(Decision.INDETERMINATE_DENYPERMIT);
532                 try {
533                         xmlResponse = DOMResponse.toString(response, false);
534                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{DP}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/></Status></Result></Response>", xmlResponse);
535                 } catch (Exception e) {
536                         fail("operation failed, e="+e);
537                 }
538                 result.setDecision(Decision.INDETERMINATE_PERMIT);
539                 try {
540                         xmlResponse = DOMResponse.toString(response, false);
541                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{P}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/></Status></Result></Response>", xmlResponse);
542                 } catch (Exception e) {
543                         fail("operation failed, e="+e);
544                 }
545                 
546                 
547                 // StatusCode = ProcessingError
548                 status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR);
549                 result.setDecision(Decision.PERMIT);
550                 try {
551                         xmlResponse = DOMResponse.toString(response, false);
552                         fail("Operation should throw exception");
553                 } catch (DOMStructureException e) {
554                         // correct response
555                 } catch (Exception e) {
556                         fail ("Failed convert from object to XML: " + e);
557                 }
558                 result.setDecision(Decision.DENY);
559                 try {
560                         xmlResponse = DOMResponse.toString(response, false);
561                         fail("Operation should throw exception");
562                 } catch (DOMStructureException e) {
563                         // correct response
564                 } catch (Exception e) {
565                         fail ("Failed convert from object to XML: " + e);
566                 }
567                 result.setDecision(Decision.NOTAPPLICABLE);
568                 try {
569                         xmlResponse = DOMResponse.toString(response, false);
570                         fail("Operation should throw exception");
571                 } catch (DOMStructureException e) {
572                         // correct response
573                 } catch (Exception e) {
574                         fail ("Failed convert from object to XML: " + e);
575                 }
576                 result.setDecision(Decision.INDETERMINATE);
577                 try {
578                         xmlResponse = DOMResponse.toString(response, false);
579                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/></Status></Result></Response>", xmlResponse);
580                 } catch (Exception e) {
581                         fail("operation failed, e="+e);
582                 }
583                 result.setDecision(Decision.INDETERMINATE_DENY);
584                 try {
585                         xmlResponse = DOMResponse.toString(response, false);
586                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{D}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/></Status></Result></Response>", xmlResponse);
587                 } catch (Exception e) {
588                         fail("operation failed, e="+e);
589                 }
590                 result.setDecision(Decision.INDETERMINATE_DENYPERMIT);
591                 try {
592                         xmlResponse = DOMResponse.toString(response, false);
593                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{DP}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/></Status></Result></Response>", xmlResponse);
594                 } catch (Exception e) {
595                         fail("operation failed, e="+e);
596                 }
597                 result.setDecision(Decision.INDETERMINATE_PERMIT);
598                 try {
599                         xmlResponse = DOMResponse.toString(response, false);
600                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{P}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/></Status></Result></Response>", xmlResponse);
601                 } catch (Exception e) {
602                         fail("operation failed, e="+e);
603                 }
604                 
605                 
606                 
607                 // StatusCode = MissingAttribute
608                 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
609                 result.setDecision(Decision.PERMIT);
610                 try {
611                         xmlResponse = DOMResponse.toString(response, false);
612                         fail("Operation should throw exception");
613                 } catch (DOMStructureException e) {
614                         // correct response
615                 } catch (Exception e) {
616                         fail ("Failed convert from object to XML: " + e);
617                 }
618                 result.setDecision(Decision.DENY);
619                 try {
620                         xmlResponse = DOMResponse.toString(response, false);
621                         fail("Operation should throw exception");
622                 } catch (DOMStructureException e) {
623                         // correct response
624                 } catch (Exception e) {
625                         fail ("Failed convert from object to XML: " + e);
626                 }
627                 result.setDecision(Decision.NOTAPPLICABLE);
628                 try {
629                         xmlResponse = DOMResponse.toString(response, false);
630                         fail("Operation should throw exception");
631                 } catch (DOMStructureException e) {
632                         // correct response
633                 } catch (Exception e) {
634                         fail ("Failed convert from object to XML: " + e);
635                 }
636                 result.setDecision(Decision.INDETERMINATE);
637                 try {
638                         xmlResponse = DOMResponse.toString(response, false);
639                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/></Status></Result></Response>", xmlResponse);
640                 } catch (Exception e) {
641                         fail("operation failed, e="+e);
642                 }
643                 result.setDecision(Decision.INDETERMINATE_DENY);
644                 try {
645                         xmlResponse = DOMResponse.toString(response, false);
646                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{D}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/></Status></Result></Response>", xmlResponse);
647                 } catch (Exception e) {
648                         fail("operation failed, e="+e);
649                 }
650                 result.setDecision(Decision.INDETERMINATE_DENYPERMIT);
651                 try {
652                         xmlResponse = DOMResponse.toString(response, false);
653                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{DP}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/></Status></Result></Response>", xmlResponse);
654                 } catch (Exception e) {
655                         fail("operation failed, e="+e);
656                 }
657                 result.setDecision(Decision.INDETERMINATE_PERMIT);
658                 try {
659                         xmlResponse = DOMResponse.toString(response, false);
660                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate{P}</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/></Status></Result></Response>", xmlResponse);
661                 } catch (Exception e) {
662                         fail("operation failed, e="+e);
663                 }
664         }
665
666         
667         
668
669         // tests related to Status and its components
670         @Test
671         public void testStatus() {
672                 // Status with no StatusCode - error
673                 response = new StdMutableResponse();
674                 result = new StdMutableResult();
675                 status = new StdMutableStatus();
676                 result.setStatus(status);
677                 result.setDecision(Decision.PERMIT);
678                 response.add(result);
679                 try {
680                         xmlResponse = DOMResponse.toString(response, false);
681                         fail("Operation should throw exception");
682                 } catch (DOMStructureException e) {
683                         // correct response
684                 } catch (Exception e) {
685                         fail ("Failed convert from object to XML: " + e);
686                 }
687                 
688                 // Status with StatusMessage when OK
689                 response = new StdMutableResponse();
690                 result = new StdMutableResult();
691                 status = new StdMutableStatus();
692                 status.setStatusCode(StdStatusCode.STATUS_CODE_OK);
693                 status.setStatusMessage("I'm ok, you're ok");
694                 result.setStatus(status);
695                 result.setDecision(Decision.PERMIT);
696                 response.add(result);
697                 try {
698                         xmlResponse = DOMResponse.toString(response, false);
699                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"/><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse);
700                 } catch (Exception e) {
701                         fail("operation failed, e="+e);
702                 }
703                 
704                 // Status with StatusDetail when OK
705                 response = new StdMutableResponse();
706                 result = new StdMutableResult();
707                 status = new StdMutableStatus();
708                 status.setStatusCode(StdStatusCode.STATUS_CODE_OK);
709                 StdMutableStatusDetail statusDetail = new StdMutableStatusDetail();
710                 status.setStatusDetail(statusDetail);
711                 result.setStatus(status);
712                 result.setDecision(Decision.PERMIT);
713                 response.add(result);
714                 try {
715                         xmlResponse = DOMResponse.toString(response, false);
716                         fail("Operation should throw exception");
717                 } catch (DOMStructureException e) {
718                         // correct response
719                 } catch (Exception e) {
720                         fail ("Failed convert from object to XML: " + e);
721                 }
722                 
723                 // Status with StatusMessage when SyntaxError
724                 response = new StdMutableResponse();
725                 result = new StdMutableResult();
726                 status = new StdMutableStatus();
727                 status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR);
728                 status.setStatusMessage("I'm ok, you're ok");
729                 result.setStatus(status);
730                 result.setDecision(Decision.INDETERMINATE);
731                 response.add(result);
732                 try {
733                         xmlResponse = DOMResponse.toString(response, false);
734                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:syntax-error\"/><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse);
735                 } catch (Exception e) {
736                         fail("operation failed, e="+e);
737                 }
738                 
739                 // Status with empty StatusDetail when SyntaxError
740                 response = new StdMutableResponse();
741                 result = new StdMutableResult();
742                 status = new StdMutableStatus();
743                 status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR);
744                 statusDetail = new StdMutableStatusDetail();
745                 status.setStatusDetail(statusDetail);
746                 result.setStatus(status);
747                 result.setDecision(Decision.INDETERMINATE);
748                 response.add(result);
749                 try {
750                         xmlResponse = DOMResponse.toString(response, false);
751                         fail("Operation should throw exception");
752                 } catch (DOMStructureException e) {
753                         // correct response
754                 } catch (Exception e) {
755                         fail ("Failed convert from object to XML: " + e);
756                 }
757                 
758                 
759                 // Status with StatusMessage when ProcessingError
760                 response = new StdMutableResponse();
761                 result = new StdMutableResult();
762                 status = new StdMutableStatus();
763                 status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR);
764                 status.setStatusMessage("I'm ok, you're ok");
765                 result.setStatus(status);
766                 result.setDecision(Decision.INDETERMINATE);
767                 response.add(result);
768                 try {
769                         xmlResponse = DOMResponse.toString(response, false);
770                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:processing-error\"/><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse);
771                 } catch (Exception e) {
772                         fail("operation failed, e="+e);
773                 }
774                 
775                 // Status with empty StatusDetail when ProcessingError
776                 response = new StdMutableResponse();
777                 result = new StdMutableResult();
778                 status = new StdMutableStatus();
779                 status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR);
780                 statusDetail = new StdMutableStatusDetail();
781                 status.setStatusDetail(statusDetail);
782                 result.setStatus(status);
783                 result.setDecision(Decision.INDETERMINATE);
784                 response.add(result);
785                 try {
786                         xmlResponse = DOMResponse.toString(response, false);
787                         fail("Operation should throw exception");
788                 } catch (DOMStructureException e) {
789                         // correct response
790                 } catch (Exception e) {
791                         fail ("Failed convert from object to XML: " + e);
792                 }
793
794                 
795                 // Status with StatusMessage when MissingAttribute
796                 response = new StdMutableResponse();
797                 result = new StdMutableResult();
798                 status = new StdMutableStatus();
799                 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
800                 status.setStatusMessage("I'm ok, you're ok");
801                 result.setStatus(status);
802                 result.setDecision(Decision.INDETERMINATE);
803                 response.add(result);
804                 try {
805                         xmlResponse = DOMResponse.toString(response, false);
806                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse);
807                 } catch (Exception e) {
808                         fail("operation failed, e="+e);
809                 }
810                 
811                 // Status with empty StatusDetail when MissingAttribute
812                 response = new StdMutableResponse();
813                 result = new StdMutableResult();
814                 status = new StdMutableStatus();
815                 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
816                 statusDetail = new StdMutableStatusDetail();
817                 status.setStatusDetail(statusDetail);
818                 result.setStatus(status);
819                 result.setDecision(Decision.INDETERMINATE);
820                 response.add(result);
821                 try {
822                         xmlResponse = DOMResponse.toString(response, false);
823                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail></StatusDetail></Status></Result></Response>", xmlResponse);
824                 } catch (Exception e) {
825                         fail("operation failed, e="+e);
826                 }
827                 
828                 
829                 
830                 // Status with StatusDetail with empty detail when MissingAttribute
831                 response = new StdMutableResponse();
832                 result = new StdMutableResult();
833                 status = new StdMutableStatus();
834                 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
835                 statusDetail = new StdMutableStatusDetail();
836                 StdMutableMissingAttributeDetail mad = new StdMutableMissingAttributeDetail();
837                 statusDetail.addMissingAttributeDetail(mad);
838                 status.setStatusDetail(statusDetail);
839                 result.setStatus(status);
840                 result.setDecision(Decision.INDETERMINATE);
841                 response.add(result);
842                 try {
843                         xmlResponse = DOMResponse.toString(response, false);
844                         fail("Operation should throw exception");
845                 } catch (DOMStructureException e) {
846                         // correct response
847                 } catch (Exception e) {
848                         fail ("Failed convert from object to XML: " + e);
849                 }
850                 
851                 // Status with StatusDetail with valid detail with no value when MissingAttribute
852                 response = new StdMutableResponse();
853                 result = new StdMutableResult();
854                 status = new StdMutableStatus();
855                 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
856                 statusDetail = new StdMutableStatusDetail();
857                 mad = new StdMutableMissingAttributeDetail();
858                 mad.setAttributeId(new IdentifierImpl("mad"));
859                 mad.setCategory(XACML3.ID_ACTION);
860                 mad.setDataTypeId(DataTypes.DT_STRING.getId());
861                 statusDetail.addMissingAttributeDetail(mad);
862                 status.setStatusDetail(statusDetail);
863                 result.setStatus(status);
864                 result.setDecision(Decision.INDETERMINATE);
865                 response.add(result);
866                 try {
867                         xmlResponse = DOMResponse.toString(response, false);
868                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse);
869                 } catch (Exception e) {
870                         fail("operation failed, e="+e);
871                 }
872                 
873                 // Status with StatusDetail with valid detail with value when MissingAttribute
874                 response = new StdMutableResponse();
875                 result = new StdMutableResult();
876                 status = new StdMutableStatus();
877                 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
878                 statusDetail = new StdMutableStatusDetail();
879                 mad = new StdMutableMissingAttributeDetail();
880                 mad.setAttributeId(new IdentifierImpl("mad"));
881                 mad.setCategory(XACML3.ID_ACTION);
882                 mad.setDataTypeId(DataTypes.DT_STRING.getId()); 
883                 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh"));
884                 statusDetail.addMissingAttributeDetail(mad);
885                 status.setStatusDetail(statusDetail);
886                 result.setStatus(status);
887                 result.setDecision(Decision.INDETERMINATE);
888                 response.add(result);
889                 try {
890                         xmlResponse = DOMResponse.toString(response, false);
891                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"><AttributeValue>meh</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse);
892                 } catch (Exception e) {
893                         fail("operation failed, e="+e);
894                 }
895                 
896                 // Status with StatusDetail with array valid detail with value when MissingAttribute
897                 response = new StdMutableResponse();
898                 result = new StdMutableResult();
899                 status = new StdMutableStatus();
900                 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
901                 statusDetail = new StdMutableStatusDetail();
902                 mad = new StdMutableMissingAttributeDetail();
903                 mad.setAttributeId(new IdentifierImpl("mad"));
904                 mad.setCategory(XACML3.ID_ACTION);
905                 mad.setDataTypeId(DataTypes.DT_STRING.getId()); 
906                 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh"));
907                 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "nu?"));
908                 statusDetail.addMissingAttributeDetail(mad);
909                 status.setStatusDetail(statusDetail);
910                 result.setStatus(status);
911                 result.setDecision(Decision.INDETERMINATE);
912                 response.add(result);
913                 try {
914                         xmlResponse = DOMResponse.toString(response, false);
915                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"><AttributeValue>meh</AttributeValue><AttributeValue>nu?</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse);
916                 } catch (Exception e) {
917                         fail("operation failed, e="+e);
918                 }
919                 
920                 
921                 // Status with StatusDetail with valid detail with Integer value when MissingAttribute
922                 response = new StdMutableResponse();
923                 result = new StdMutableResult();
924                 status = new StdMutableStatus();
925                 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
926                 statusDetail = new StdMutableStatusDetail();
927                 mad = new StdMutableMissingAttributeDetail();
928                 mad.setAttributeId(new IdentifierImpl("mad"));
929                 mad.setCategory(XACML3.ID_ACTION);
930                 mad.setDataTypeId(DataTypes.DT_STRING.getId()); 
931                 mad.addAttributeValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111));
932                 statusDetail.addMissingAttributeDetail(mad);
933                 status.setStatusDetail(statusDetail);
934                 result.setStatus(status);
935                 result.setDecision(Decision.INDETERMINATE);
936                 response.add(result);
937                 try {
938                         xmlResponse = DOMResponse.toString(response, false);
939                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"><AttributeValue>1111</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse);
940                 } catch (Exception e) {
941                         fail("operation failed, e="+e);
942                 }
943                 
944                 // Status with StatusDetail with array valid detail with Integer value when MissingAttribute
945                 response = new StdMutableResponse();
946                 result = new StdMutableResult();
947                 status = new StdMutableStatus();
948                 status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
949                 statusDetail = new StdMutableStatusDetail();
950                 mad = new StdMutableMissingAttributeDetail();
951                 mad.setAttributeId(new IdentifierImpl("mad"));
952                 mad.setCategory(XACML3.ID_ACTION);
953                 mad.setDataTypeId(DataTypes.DT_STRING.getId()); 
954                 mad.addAttributeValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111));
955                 mad.addAttributeValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 2222));
956                 statusDetail.addMissingAttributeDetail(mad);
957                 status.setStatusDetail(statusDetail);
958                 result.setStatus(status);
959                 result.setDecision(Decision.INDETERMINATE);
960                 response.add(result);
961                 try {
962                         xmlResponse = DOMResponse.toString(response, false);
963                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Indeterminate</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"/><StatusDetail><MissingAttributeDetail Category=\"urn:oasis:names:tc:xacml:1.0:action\" AttributeId=\"mad\" DataTypeId=\"http://www.w3.org/2001/XMLSchema#string\"><AttributeValue>1111</AttributeValue><AttributeValue>2222</AttributeValue></MissingAttributeDetail></StatusDetail></Status></Result></Response>", xmlResponse);
964                 } catch (Exception e) {
965                         fail("operation failed, e="+e);
966                 }
967                 
968 //              StringNamespaceContext snc = new StringNamespaceContext();
969 //              try {
970 //                      snc.add("defaultURI");
971 //                      snc.add("md", "referenceForMD");
972 //              } catch (Exception e) {
973 //                      fail("unable to create NamespaceContext e="+e);
974 //              }
975 //              XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record");
976 //
977 //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
978 //              // Status with StatusDetail with valid detail with XPathExpression value when MissingAttribute
979 //              response = new StdMutableResponse();
980 //              result = new StdMutableResult();
981 //              status = new StdMutableStatus();
982 //              status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
983 //              statusDetail = new StdMutableStatusDetail();
984 //              mad = new StdMutableMissingAttributeDetail();
985 //              mad.setAttributeId(new IdentifierImpl("mad"));
986 //              mad.setCategory(XACML3.ID_ACTION);
987 //              mad.setDataTypeId(DataTypes.DT_STRING.getId()); 
988 //              mad.addAttributeValue(new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId")));
989 //              statusDetail.addMissingAttributeDetail(mad);
990 //              status.setStatusDetail(statusDetail);
991 //              result.setStatus(status);
992 //              result.setDecision(Decision.INDETERMINATE);
993 //              response.add(result);
994 //              try {
995 //                      xmlResponse = DOMResponse.toString(response, false);
996 //                      assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<MissingAttributeDetail><AttributeValue>1111</AttributeValue><Category>urn:oasis:names:tc:xacml:1.0:action</Category><AttributeId>mad</AttributeId><DataType>http://www.w3.org/2001/XMLSchema#string</DataType></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", xmlResponse);
997 //              } catch (Exception e) {
998 //                      fail("operation failed, e="+e);
999 //              }
1000 //              
1001 //              // Status with StatusDetail with array valid detail with XPathExpression value when MissingAttribute
1002 //              response = new StdMutableResponse();
1003 //              result = new StdMutableResult();
1004 //              status = new StdMutableStatus();
1005 //              status.setStatusCode(StdStatusCode.STATUS_CODE_MISSING_ATTRIBUTE);
1006 //              statusDetail = new StdMutableStatusDetail();
1007 //              mad = new StdMutableMissingAttributeDetail();
1008 //              mad.setAttributeId(new IdentifierImpl("mad"));
1009 //              mad.setCategory(XACML3.ID_ACTION);
1010 //              mad.setDataTypeId(DataTypes.DT_STRING.getId()); 
1011 //              mad.addAttributeValue(new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId1")));
1012 //              mad.addAttributeValue(new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategoryId2")));
1013 //              statusDetail.addMissingAttributeDetail(mad);
1014 //              status.setStatusDetail(statusDetail);
1015 //              result.setStatus(status);
1016 //              result.setDecision(Decision.INDETERMINATE);
1017 //              response.add(result);
1018 //              try {
1019 //                      xmlResponse = DOMResponse.toString(response, false);
1020 //                      assertEquals("{\"Response\":[{\"Status\":{\"StatusCode\":{\"Value\":\"urn:oasis:names:tc:xacml:1.0:status:missing-attribute\"},\"StatusDetail\":\"<MissingAttributeDetail><AttributeValue>1111</AttributeValue><AttributeValue>2222</AttributeValue><Category>urn:oasis:names:tc:xacml:1.0:action</Category><AttributeId>mad</AttributeId><DataType>http://www.w3.org/2001/XMLSchema#string</DataType></MissingAttributeDetail>\"},\"Decision\":\"Indeterminate\"}]}", xmlResponse);
1021 //              } catch (Exception e) {
1022 //                      fail("operation failed, e="+e);
1023 //              }
1024                 
1025 //TODO - try with other data types, esp XPathExpression         
1026                 
1027                 // Status with StatusDetail with array valid detail with value when SyntaxError
1028                 response = new StdMutableResponse();
1029                 result = new StdMutableResult();
1030                 status = new StdMutableStatus();
1031                 status.setStatusCode(StdStatusCode.STATUS_CODE_SYNTAX_ERROR);
1032                 statusDetail = new StdMutableStatusDetail();
1033                 mad = new StdMutableMissingAttributeDetail();
1034                 mad.setAttributeId(new IdentifierImpl("mad"));
1035                 mad.setCategory(XACML3.ID_ACTION);
1036                 mad.setDataTypeId(DataTypes.DT_STRING.getId()); 
1037                 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh"));
1038                 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "nu?"));
1039                 statusDetail.addMissingAttributeDetail(mad);
1040                 status.setStatusDetail(statusDetail);
1041                 result.setStatus(status);
1042                 result.setDecision(Decision.INDETERMINATE);
1043                 response.add(result);
1044                 try {
1045                         xmlResponse = DOMResponse.toString(response, false);
1046                         fail("Operation should throw exception");
1047                 } catch (DOMStructureException e) {
1048                         // correct response
1049                 } catch (Exception e) {
1050                         fail ("Failed convert from object to XML: " + e);
1051                 }
1052                 
1053                 // Status with StatusDetail with array valid detail with value when ProcessingError
1054                 response = new StdMutableResponse();
1055                 result = new StdMutableResult();
1056                 status = new StdMutableStatus();
1057                 status.setStatusCode(StdStatusCode.STATUS_CODE_PROCESSING_ERROR);
1058                 statusDetail = new StdMutableStatusDetail();
1059                 mad = new StdMutableMissingAttributeDetail();
1060                 mad.setAttributeId(new IdentifierImpl("mad"));
1061                 mad.setCategory(XACML3.ID_ACTION);
1062                 mad.setDataTypeId(DataTypes.DT_STRING.getId()); 
1063                 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "meh"));
1064                 mad.addAttributeValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "nu?"));
1065                 statusDetail.addMissingAttributeDetail(mad);
1066                 status.setStatusDetail(statusDetail);
1067                 result.setStatus(status);
1068                 result.setDecision(Decision.INDETERMINATE);
1069                 response.add(result);
1070                 try {
1071                         xmlResponse = DOMResponse.toString(response, false);
1072                         fail("Operation should throw exception");
1073                 } catch (DOMStructureException e) {
1074                         // correct response
1075                 } catch (Exception e) {
1076                         fail ("Failed convert from object to XML: " + e);
1077                 }
1078                 
1079                 
1080                 
1081                 // Status with nested child StatusCodes (child status containing child status containing...)
1082                 response = new StdMutableResponse();
1083                 result = new StdMutableResult();
1084                 status = new StdMutableStatus();
1085                 StdStatusCode child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"));
1086                 StdStatusCode statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode);
1087                 status = new StdMutableStatus(statusCode);
1088                 status.setStatusMessage("I'm ok, you're ok");
1089                 result.setStatus(status);
1090                 result.setDecision(Decision.PERMIT);
1091                 response.add(result);
1092                 try {
1093                         xmlResponse = DOMResponse.toString(response, false);
1094                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"><StatusCode Value=\"child1StatusCode\"/></StatusCode><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse);
1095                 } catch (Exception e) {
1096                         fail("operation failed, e="+e);
1097                 }
1098                 response = new StdMutableResponse();
1099                 result = new StdMutableResult();
1100                 status = new StdMutableStatus();
1101                 StdStatusCode childChildChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildChildStatusCode"));
1102                 StdStatusCode childChildStatusCode = new StdStatusCode(new IdentifierImpl("childChildStatusCode"), childChildChildStatusCode);
1103                 child1StatusCode = new StdStatusCode(new IdentifierImpl("child1StatusCode"), childChildStatusCode);
1104                 statusCode = new StdStatusCode(XACML3.ID_STATUS_OK, child1StatusCode);
1105                 status = new StdMutableStatus(statusCode);
1106                 status.setStatusMessage("I'm ok, you're ok");
1107                 result.setStatus(status);
1108                 result.setDecision(Decision.PERMIT);
1109                 response.add(result);
1110                 try {
1111                         xmlResponse = DOMResponse.toString(response, false);
1112                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Status><StatusCode Value=\"urn:oasis:names:tc:xacml:1.0:status:ok\"><StatusCode Value=\"child1StatusCode\"><StatusCode Value=\"childChildStatusCode\"><StatusCode Value=\"childChildChildStatusCode\"/></StatusCode></StatusCode></StatusCode><StatusMessage>I'm ok, you're ok</StatusMessage></Status></Result></Response>", xmlResponse);
1113                 } catch (Exception e) {
1114                         fail("operation failed, e="+e);
1115                 }
1116
1117         }
1118
1119
1120         
1121         @Test
1122         public void testObligations() {
1123                 
1124                 // create an XPathExpression for use later
1125                 StringNamespaceContext snc = new StringNamespaceContext();
1126                 try {
1127                         snc.add("defaultURI");
1128                         snc.add("md", "referenceForMD");
1129                 } catch (Exception e) {
1130                         fail("unable to create NamespaceContext e="+e);
1131                 }
1132                 XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record");
1133                 XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital");
1134                 
1135                 StdMutableObligation obligation;
1136
1137                 // test Obligation single decision no attributes
1138                 response = new StdMutableResponse();
1139                 result = new StdMutableResult();
1140                 result.setDecision(Decision.PERMIT);
1141                 obligation = new StdMutableObligation();
1142                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1143                 result.addObligation(obligation);
1144                 response.add(result);
1145                 try {
1146                         xmlResponse = DOMResponse.toString(response, false);
1147                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"></Obligation></Obligations></Result></Response>", xmlResponse);
1148                 } catch (Exception e) {
1149                         fail("operation failed, e="+e);
1150                 }
1151                 
1152                 // obligation missing Id
1153                 response = new StdMutableResponse();
1154                 result = new StdMutableResult();
1155                 result.setDecision(Decision.PERMIT);
1156                 obligation = new StdMutableObligation();
1157                 result.addObligation(obligation);
1158                 response.add(result);
1159                 try {
1160                         xmlResponse = DOMResponse.toString(response, false);
1161                         fail("Operation should throw exception");
1162                 } catch (DOMStructureException e) {
1163                         // correct response
1164                 } catch (Exception e) {
1165                         fail ("Failed convert from object to XML: " + e);
1166                 }
1167                 
1168                 
1169                 
1170                 //      AttributeAssignment     - with AttributeId, Value,  Category, DataType, Issuer
1171                 response = new StdMutableResponse();
1172                 result = new StdMutableResult();
1173                 result.setDecision(Decision.PERMIT);
1174                 obligation = new StdMutableObligation();
1175                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1176                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1177                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1178                                 XACML3.ID_SUBJECT, 
1179                                 "obligation-issuer1", 
1180                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1181                 result.addObligation(obligation);
1182                 response.add(result);
1183                 try {
1184                         xmlResponse = DOMResponse.toString(response, false);
1185                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1186                 } catch (Exception e) {
1187                         fail("operation failed, e="+e);
1188                 }
1189                 
1190                 
1191                 //      AttributeAssignment     - with AttributeId, Value, no Category, DataType, Issuer
1192                 response = new StdMutableResponse();
1193                 result = new StdMutableResult();
1194                 result.setDecision(Decision.PERMIT);
1195                 obligation = new StdMutableObligation();
1196                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1197                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1198                                 null, 
1199                                 XACML3.ID_SUBJECT, 
1200                                 "obligation-issuer1", 
1201                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1202                 result.addObligation(obligation);
1203                 response.add(result);
1204                 try {
1205                         xmlResponse = DOMResponse.toString(response, false);
1206                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1207                 } catch (Exception e) {
1208                         fail("operation failed, e="+e);
1209                 }
1210                 
1211                 //      AttributeAssignment     - Missing AttributeId
1212                 response = new StdMutableResponse();
1213                 result = new StdMutableResult();
1214                 result.setDecision(Decision.PERMIT);
1215                 obligation = new StdMutableObligation();
1216                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1217                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1218                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1219                                 null, 
1220                                 "obligation-issuer1", 
1221                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1222                 result.addObligation(obligation);
1223                 response.add(result);
1224                 try {
1225                         xmlResponse = DOMResponse.toString(response, false);
1226                         fail("Operation should throw exception");
1227                 } catch (DOMStructureException e) {
1228                         // correct response
1229                 } catch (Exception e) {
1230                         fail ("Failed convert from object to XML: " + e);
1231                 }
1232                 
1233                 //      AttributeAssignment     - Missing Value
1234                 response = new StdMutableResponse();
1235                 result = new StdMutableResult();
1236                 result.setDecision(Decision.PERMIT);
1237                 obligation = new StdMutableObligation();
1238                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1239                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1240                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1241                                 XACML3.ID_SUBJECT, 
1242                                 "obligation-issuer1", 
1243                                 null));
1244                 result.addObligation(obligation);
1245                 response.add(result);
1246                 try {
1247                         xmlResponse = DOMResponse.toString(response, false);
1248                         fail("Operation should throw exception");
1249                 } catch (DOMStructureException e) {
1250                         // correct response
1251                 } catch (Exception e) {
1252                         fail ("Failed convert from object to XML: " + e);
1253                 }
1254                 
1255                 // AttributeAssignment - missing required DataType (Different than JSON where DataType is optional with default String)
1256                 response = new StdMutableResponse();
1257                 result = new StdMutableResult();
1258                 result.setDecision(Decision.PERMIT);
1259                 obligation = new StdMutableObligation();
1260                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1261                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1262                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1263                                 XACML3.ID_SUBJECT, 
1264                                 "obligation-issuer1", 
1265                                 new StdAttributeValue<String>(null, "Bart")));
1266                 result.addObligation(obligation);
1267                 response.add(result);
1268                 try {
1269                         xmlResponse = DOMResponse.toString(response, false);
1270                         fail("Operation should throw exception");
1271                 } catch (DOMStructureException e) {
1272                         // correct response
1273                 } catch (Exception e) {
1274                         fail ("Failed convert from object to XML: " + e);
1275                 }
1276                 
1277                 // AttributeAssignment - missing issuer
1278                 response = new StdMutableResponse();
1279                 result = new StdMutableResult();
1280                 result.setDecision(Decision.PERMIT);
1281                 obligation = new StdMutableObligation();
1282                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1283                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1284                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1285                                 XACML3.ID_SUBJECT, 
1286                                 null, 
1287                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1288                 result.addObligation(obligation);
1289                 response.add(result);
1290                 try {
1291                         xmlResponse = DOMResponse.toString(response, false);
1292                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1293                 } catch (Exception e) {
1294                         fail("operation failed, e="+e);
1295                 }
1296                 
1297                 // AttributeAssignment - Integer type
1298                 response = new StdMutableResponse();
1299                 result = new StdMutableResult();
1300                 result.setDecision(Decision.PERMIT);
1301                 obligation = new StdMutableObligation();
1302                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1303                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1304                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1305                                 XACML3.ID_SUBJECT, 
1306                                 null, 
1307                                 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111)));
1308                 result.addObligation(obligation);
1309                 response.add(result);
1310                 try {
1311                         xmlResponse = DOMResponse.toString(response, false);
1312                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">1111</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1313                 } catch (Exception e) {
1314                         fail("operation failed, e="+e);
1315                 }
1316                 
1317                 
1318                 // AttributeAssignment - XPathExpression type
1319                 response = new StdMutableResponse();
1320                 result = new StdMutableResult();
1321                 result.setDecision(Decision.PERMIT);
1322                 obligation = new StdMutableObligation();
1323                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1324                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1325                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1326                                 XACML3.ID_SUBJECT, 
1327                                 null, 
1328                                 new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory"))));
1329                 result.addObligation(obligation);
1330                 response.add(result);
1331                 try {
1332                         xmlResponse = DOMResponse.toString(response, false);
1333                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:record</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1334                 } catch (Exception e) {
1335                         fail("operation failed, e="+e);
1336                 }
1337                 
1338                 
1339                 
1340
1341                 //
1342                 // Technically arrays cannot occur in Obligations and Advice elements.  The XML spec boils down to the following definition:
1343                 //              <Obligation (attributes of the obligation) >
1344                 //                      <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment>
1345                 //                      <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment>
1346                 //                      :
1347                 //              </Obligation
1348                 //      which means that there may be multiple AttributeAssignments but each one has only one value.
1349                 //      This differs from the Attributes section in which each <Attribute> may have multiple <AttributeValue> elements.
1350                 // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer.
1351                 //
1352
1353                 
1354                 //      AttributeAssignment     - Multiple values with same Category and Id (one way of doing array)
1355                 response = new StdMutableResponse();
1356                 result = new StdMutableResult();
1357                 result.setDecision(Decision.PERMIT);
1358                 obligation = new StdMutableObligation();
1359                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1360                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1361                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1362                                 XACML3.ID_SUBJECT, 
1363                                 "obligation-issuer1", 
1364                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1365                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1366                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1367                                 XACML3.ID_SUBJECT, 
1368                                 "obligation-issuer1", 
1369                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Lisa")));
1370                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1371                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1372                                 XACML3.ID_SUBJECT, 
1373                                 "obligation-issuer1", 
1374                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Maggie")));
1375                 result.addObligation(obligation);
1376                 response.add(result);
1377                 try {
1378                         xmlResponse = DOMResponse.toString(response, false);
1379                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Lisa</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Maggie</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1380                 } catch (Exception e) {
1381                         fail("operation failed, e="+e);
1382                 }
1383                 
1384                 
1385                 //      AttributeAssignment     - Multiple Integer values with same Category and Id (one way of doing array)
1386                 response = new StdMutableResponse();
1387                 result = new StdMutableResult();
1388                 result.setDecision(Decision.PERMIT);
1389                 obligation = new StdMutableObligation();
1390                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1391                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1392                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1393                                 XACML3.ID_SUBJECT, 
1394                                 "obligation-issuer1", 
1395                                 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111)));
1396                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1397                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1398                                 XACML3.ID_SUBJECT, 
1399                                 "obligation-issuer1", 
1400                                 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 2222)));
1401                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1402                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1403                                 XACML3.ID_SUBJECT, 
1404                                 "obligation-issuer1", 
1405                                 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 3333)));
1406                 result.addObligation(obligation);
1407                 response.add(result);
1408                 try {
1409                         xmlResponse = DOMResponse.toString(response, false);
1410                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">1111</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">2222</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">3333</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1411                 } catch (Exception e) {
1412                         fail("operation failed, e="+e);
1413                 }
1414                 
1415                 
1416                 // Multiple XPathExpression values with same Category and Id (one way of doing array)
1417                 response = new StdMutableResponse();
1418                 result = new StdMutableResult();
1419                 result.setDecision(Decision.PERMIT);
1420                 obligation = new StdMutableObligation();
1421                 obligation.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1422                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1423                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1424                                 XACML3.ID_SUBJECT, 
1425                                 null, 
1426                                 new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory"))));
1427                 obligation.addAttributeAssignment(new StdMutableAttributeAssignment(
1428                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1429                                 XACML3.ID_SUBJECT, 
1430                                 null, 
1431                                 new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory"))));
1432                 result.addObligation(obligation);
1433                 response.add(result);
1434                 try {
1435                         xmlResponse = DOMResponse.toString(response, false);
1436                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Obligations><Obligation ObligationId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:record</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:hospital</AttributeAssignment></Obligation></Obligations></Result></Response>", xmlResponse);
1437                 } catch (Exception e) {
1438                         fail("operation failed, e="+e);
1439                 }       
1440                 
1441         }
1442         
1443         
1444         
1445         
1446         @Test
1447         public void testAdvice() {
1448                 
1449                 // create an XPathExpression for use later
1450                 StringNamespaceContext snc = new StringNamespaceContext();
1451                 try {
1452                         snc.add("defaultURI");
1453                         snc.add("md", "referenceForMD");
1454                 } catch (Exception e) {
1455                         fail("unable to create NamespaceContext e="+e);
1456                 }
1457                 XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record");
1458                 XPathExpressionWrapper xpathExpressionWrapper2 = new XPathExpressionWrapper(snc, "//md:hospital");
1459                 
1460                 StdMutableAdvice Advice;
1461
1462                 // test Advice single decision no attributes
1463                 response = new StdMutableResponse();
1464                 result = new StdMutableResult();
1465                 result.setDecision(Decision.PERMIT);
1466                 Advice = new StdMutableAdvice();
1467                 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1468                 result.addAdvice(Advice);
1469                 response.add(result);
1470                 try {
1471                         xmlResponse = DOMResponse.toString(response, false);
1472                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1473                 } catch (Exception e) {
1474                         fail("operation failed, e="+e);
1475                 }
1476                 
1477                 // Advice missing Id
1478                 response = new StdMutableResponse();
1479                 result = new StdMutableResult();
1480                 result.setDecision(Decision.PERMIT);
1481                 Advice = new StdMutableAdvice();
1482                 result.addAdvice(Advice);
1483                 response.add(result);
1484                 try {
1485                         xmlResponse = DOMResponse.toString(response, false);
1486                         fail("Operation should throw exception");
1487                 } catch (DOMStructureException e) {
1488                         // correct response
1489                 } catch (Exception e) {
1490                         fail ("Failed convert from object to XML: " + e);
1491                 }
1492                 
1493                 
1494                 
1495                 //      AttributeAssignment     - with AttributeId, Value,  Category, DataType, Issuer
1496                 response = new StdMutableResponse();
1497                 result = new StdMutableResult();
1498                 result.setDecision(Decision.PERMIT);
1499                 Advice = new StdMutableAdvice();
1500                 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1501                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1502                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1503                                 XACML3.ID_SUBJECT, 
1504                                 "Advice-issuer1", 
1505                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1506                 result.addAdvice(Advice);
1507                 response.add(result);
1508                 try {
1509                         xmlResponse = DOMResponse.toString(response, false);
1510                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1511                 } catch (Exception e) {
1512                         fail("operation failed, e="+e);
1513                 }
1514                 
1515                 
1516                 //      AttributeAssignment     - with AttributeId, Value, no Category, DataType, Issuer
1517                 response = new StdMutableResponse();
1518                 result = new StdMutableResult();
1519                 result.setDecision(Decision.PERMIT);
1520                 Advice = new StdMutableAdvice();
1521                 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1522                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1523                                 null, 
1524                                 XACML3.ID_SUBJECT, 
1525                                 "Advice-issuer1", 
1526                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1527                 result.addAdvice(Advice);
1528                 response.add(result);
1529                 try {
1530                         xmlResponse = DOMResponse.toString(response, false);
1531                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1532                 } catch (Exception e) {
1533                         fail("operation failed, e="+e);
1534                 }
1535                 
1536                 //      AttributeAssignment     - Missing AttributeId
1537                 response = new StdMutableResponse();
1538                 result = new StdMutableResult();
1539                 result.setDecision(Decision.PERMIT);
1540                 Advice = new StdMutableAdvice();
1541                 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1542                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1543                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1544                                 null, 
1545                                 "Advice-issuer1", 
1546                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1547                 result.addAdvice(Advice);
1548                 response.add(result);
1549                 try {
1550                         xmlResponse = DOMResponse.toString(response, false);
1551                         fail("Operation should throw exception");
1552                 } catch (DOMStructureException e) {
1553                         // correct response
1554                 } catch (Exception e) {
1555                         fail ("Failed convert from object to XML: " + e);
1556                 }
1557                 
1558                 //      AttributeAssignment     - Missing Value
1559                 response = new StdMutableResponse();
1560                 result = new StdMutableResult();
1561                 result.setDecision(Decision.PERMIT);
1562                 Advice = new StdMutableAdvice();
1563                 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1564                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1565                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1566                                 XACML3.ID_SUBJECT, 
1567                                 "Advice-issuer1", 
1568                                 null));
1569                 result.addAdvice(Advice);
1570                 response.add(result);
1571                 try {
1572                         xmlResponse = DOMResponse.toString(response, false);
1573                         fail("Operation should throw exception");
1574                 } catch (DOMStructureException e) {
1575                         // correct response
1576                 } catch (Exception e) {
1577                         fail ("Failed convert from object to XML: " + e);
1578                 }
1579                 
1580                 // AttributeAssignment - missing Required DataType (Different than JSON where DataType is optional with default String)
1581                 response = new StdMutableResponse();
1582                 result = new StdMutableResult();
1583                 result.setDecision(Decision.PERMIT);
1584                 Advice = new StdMutableAdvice();
1585                 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1586                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1587                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1588                                 XACML3.ID_SUBJECT, 
1589                                 "Advice-issuer1", 
1590                                 new StdAttributeValue<String>(null, "Bart")));
1591                 result.addAdvice(Advice);
1592                 response.add(result);
1593                 try {
1594                         xmlResponse = DOMResponse.toString(response, false);
1595                         fail("Operation should throw exception");
1596                 } catch (DOMStructureException e) {
1597                         // correct response
1598                 } catch (Exception e) {
1599                         fail ("Failed convert from object to XML: " + e);
1600                 }
1601                 
1602                 // AttributeAssignment - missing issuer
1603                 response = new StdMutableResponse();
1604                 result = new StdMutableResult();
1605                 result.setDecision(Decision.PERMIT);
1606                 Advice = new StdMutableAdvice();
1607                 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1608                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1609                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1610                                 XACML3.ID_SUBJECT, 
1611                                 null, 
1612                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1613                 result.addAdvice(Advice);
1614                 response.add(result);
1615                 try {
1616                         xmlResponse = DOMResponse.toString(response, false);
1617                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1618                 } catch (Exception e) {
1619                         fail("operation failed, e="+e);
1620                 }
1621                 
1622                 // AttributeAssignment - Integer type
1623                 response = new StdMutableResponse();
1624                 result = new StdMutableResult();
1625                 result.setDecision(Decision.PERMIT);
1626                 Advice = new StdMutableAdvice();
1627                 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1628                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1629                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1630                                 XACML3.ID_SUBJECT, 
1631                                 null, 
1632                                 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111)));
1633                 result.addAdvice(Advice);
1634                 response.add(result);
1635                 try {
1636                         xmlResponse = DOMResponse.toString(response, false);
1637                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">1111</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1638                 } catch (Exception e) {
1639                         fail("operation failed, e="+e);
1640                 }
1641                 
1642                 
1643                 // AttributeAssignment - XPathExpression type
1644                 response = new StdMutableResponse();
1645                 result = new StdMutableResult();
1646                 result.setDecision(Decision.PERMIT);
1647                 Advice = new StdMutableAdvice();
1648                 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1649                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1650                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1651                                 XACML3.ID_SUBJECT, 
1652                                 null, 
1653                                 new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory"))));
1654                 result.addAdvice(Advice);
1655                 response.add(result);
1656                 try {
1657                         xmlResponse = DOMResponse.toString(response, false);
1658                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:record</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1659                 } catch (Exception e) {
1660                         fail("operation failed, e="+e);
1661                 }
1662                 
1663                 
1664                 
1665
1666                 //
1667                 // Technically arrays cannot occur in Obligations and Advice elements.  The XML spec boils down to the following definition:
1668                 //              <Obligation (attributes of the obligation) >
1669                 //                      <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment>
1670                 //                      <AttributeAssignment (attributes of this assignment) >value</AttributeAssignment>
1671                 //                      :
1672                 //              </Obligation
1673                 //      which means that there may be multiple AttributeAssignments but each one has only one value.
1674                 //      This differs from the Attributes section in which each <Attribute> may have multiple <AttributeValue> elements.
1675                 // For Obligations and Advice we can simulate an array by having multiple AttributeAssignment elements with the same Category, Id and Issuer.
1676                 //
1677                 
1678                 //      AttributeAssignment     - Multiple values with same Category and Id (one way of doing array)
1679                 response = new StdMutableResponse();
1680                 result = new StdMutableResult();
1681                 result.setDecision(Decision.PERMIT);
1682                 Advice = new StdMutableAdvice();
1683                 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1684                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1685                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1686                                 XACML3.ID_SUBJECT, 
1687                                 "Advice-issuer1", 
1688                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart")));
1689                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1690                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1691                                 XACML3.ID_SUBJECT, 
1692                                 "Advice-issuer1", 
1693                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Lisa")));
1694                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1695                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1696                                 XACML3.ID_SUBJECT, 
1697                                 "Advice-issuer1", 
1698                                 new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Maggie")));
1699                 result.addAdvice(Advice);
1700                 response.add(result);
1701                 try {
1702                         xmlResponse = DOMResponse.toString(response, false);
1703                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Lisa</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#string\">Maggie</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1704                 } catch (Exception e) {
1705                         fail("operation failed, e="+e);
1706                 }
1707                 
1708                 
1709                 //      AttributeAssignment     - Multiple Integer values with same Category and Id (one way of doing array)
1710                 response = new StdMutableResponse();
1711                 result = new StdMutableResult();
1712                 result.setDecision(Decision.PERMIT);
1713                 Advice = new StdMutableAdvice();
1714                 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1715                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1716                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1717                                 XACML3.ID_SUBJECT, 
1718                                 "Advice-issuer1", 
1719                                 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 1111)));
1720                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1721                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1722                                 XACML3.ID_SUBJECT, 
1723                                 "Advice-issuer1", 
1724                                 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 2222)));
1725                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1726                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1727                                 XACML3.ID_SUBJECT, 
1728                                 "Advice-issuer1", 
1729                                 new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 3333)));
1730                 result.addAdvice(Advice);
1731                 response.add(result);
1732                 try {
1733                         xmlResponse = DOMResponse.toString(response, false);
1734                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">1111</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">2222</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"http://www.w3.org/2001/XMLSchema#integer\">3333</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1735                 } catch (Exception e) {
1736                         fail("operation failed, e="+e);
1737                 }
1738                 
1739                 
1740                 // Multiple XPathExpression values with same Category and Id (one way of doing array)
1741                 response = new StdMutableResponse();
1742                 result = new StdMutableResult();
1743                 result.setDecision(Decision.PERMIT);
1744                 Advice = new StdMutableAdvice();
1745                 Advice.setId(XACML3.ID_ACTION_IMPLIED_ACTION);
1746                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1747                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1748                                 XACML3.ID_SUBJECT, 
1749                                 null, 
1750                                 new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("SimpleXPathCategory"))));
1751                 Advice.addAttributeAssignment(new StdMutableAttributeAssignment(
1752                                 XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, 
1753                                 XACML3.ID_SUBJECT, 
1754                                 null, 
1755                                 new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper2, new IdentifierImpl("SimpleXPathCategory"))));
1756                 result.addAdvice(Advice);
1757                 response.add(result);
1758                 try {
1759                         xmlResponse = DOMResponse.toString(response, false);
1760                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><AssociatedAdvice><Advice AdviceId=\"urn:oasis:names:tc:xacml:1.0:action:implied-action\"><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:record</AttributeAssignment><AttributeAssignment AttributeId=\"urn:oasis:names:tc:xacml:1.0:subject\" DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" xmlns:md=\"referenceForMD\" xmlns=\"defaultURI\">//md:hospital</AttributeAssignment></Advice></AssociatedAdvice></Result></Response>", xmlResponse);
1761                 } catch (Exception e) {
1762                         fail("operation failed, e="+e);
1763                 }
1764         }
1765         
1766         
1767         
1768         
1769         
1770
1771         
1772         
1773
1774         
1775         // Attributes tests
1776         @Test
1777         public void testAttributes() {
1778                 
1779                 // create an XPathExpression for use later
1780                 StringNamespaceContext snc = new StringNamespaceContext();
1781                 try {
1782                         snc.add("defaultURI");
1783                         snc.add("md", "referenceForMD");
1784                 } catch (Exception e) {
1785                         fail("unable to create NamespaceContext e="+e);
1786                 }
1787                 XPathExpressionWrapper xpathExpressionWrapper = new XPathExpressionWrapper(snc, "//md:record");
1788                 
1789                 
1790                 Identifier categoryIdentifier;
1791                 List<Attribute> attrList = new ArrayList<Attribute>();
1792                 StdMutableAttribute mutableAttribute;
1793                 
1794                 // Attr list with no entries
1795                 response = new StdMutableResponse();
1796                 result = new StdMutableResult();
1797                 result.setDecision(Decision.PERMIT);
1798                 categoryIdentifier = new IdentifierImpl("firstCategory");
1799                 attrList.clear();
1800                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1801                 response.add(result);
1802                 try {
1803                         xmlResponse = DOMResponse.toString(response, false);
1804                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"></Attributes></Result></Response>", xmlResponse);
1805                 } catch (Exception e) {
1806                         fail("operation failed, e="+e);
1807                 }
1808                 
1809                 
1810                 // one Attribute
1811                 response = new StdMutableResponse();
1812                 result = new StdMutableResult();
1813                 result.setDecision(Decision.PERMIT);
1814                 categoryIdentifier = new IdentifierImpl("firstCategory");
1815                 attrList.clear();
1816                                 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1817                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1818                 response.add(result);
1819                 try {
1820                         xmlResponse = DOMResponse.toString(response, false);
1821                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
1822                 } catch (Exception e) {
1823                         fail("operation failed, e="+e);
1824                 }
1825                 
1826                 // multiple attributes
1827                 response = new StdMutableResponse();
1828                 result = new StdMutableResult();
1829                 result.setDecision(Decision.PERMIT);
1830                 categoryIdentifier = new IdentifierImpl("firstCategory");
1831                 attrList.clear();
1832                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1833                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true));
1834                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true));
1835                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true));
1836                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true));
1837                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1838                 response.add(result);
1839                 try {
1840                         xmlResponse = DOMResponse.toString(response, false);
1841                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent2\" Issuer=\"BIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">P10Y4M</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent3\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent4\" Issuer=\"DIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent5\" Issuer=\"EIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
1842                 } catch (Exception e) {
1843                         fail("operation failed, e="+e);
1844                 }
1845                 
1846                 // IncludeInResult=false/true
1847                 response = new StdMutableResponse();
1848                 result = new StdMutableResult();
1849                 result.setDecision(Decision.PERMIT);
1850                 categoryIdentifier = new IdentifierImpl("firstCategory");
1851                 attrList.clear();
1852                                 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", false));
1853                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1854                 response.add(result);
1855                 try {
1856                         xmlResponse = DOMResponse.toString(response, false);
1857                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"></Attributes></Result></Response>", xmlResponse);
1858                 } catch (Exception e) {
1859                         fail("operation failed, e="+e);
1860                 }
1861                 
1862                 // Missing AttributeId (mandatory)
1863                 response = new StdMutableResponse();
1864                 result = new StdMutableResult();
1865                 result.setDecision(Decision.PERMIT);
1866                 categoryIdentifier = new IdentifierImpl("firstCategory");
1867                 attrList.clear();
1868                                 attrList.add(new StdAttribute(categoryIdentifier, null, new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1869                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1870                 response.add(result);
1871                 try {
1872                         xmlResponse = DOMResponse.toString(response, false);
1873                         fail("Operation should throw exception");
1874                 } catch (DOMStructureException e) {
1875                         // correct response
1876                 } catch (Exception e) {
1877                         fail ("Failed convert from object to XML: " + e);
1878                 }
1879                 
1880                 // Missing mandatory Value
1881                 response = new StdMutableResponse();
1882                 result = new StdMutableResult();
1883                 result.setDecision(Decision.PERMIT);
1884                 categoryIdentifier = new IdentifierImpl("firstCategory");
1885                 attrList.clear();
1886                                 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), null), "AIssue", true));
1887                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1888                 response.add(result);
1889                 try {
1890                         xmlResponse = DOMResponse.toString(response, false);
1891                         fail("Operation should throw exception");
1892                 } catch (DOMStructureException e) {
1893                         // correct response
1894                 } catch (Exception e) {
1895                         fail ("Failed convert from object to XML: " + e);
1896                 }
1897                 
1898                 // Missing optional Issuer
1899                 response = new StdMutableResponse();
1900                 result = new StdMutableResult();
1901                 result.setDecision(Decision.PERMIT);
1902                 categoryIdentifier = new IdentifierImpl("firstCategory");
1903                 attrList.clear();
1904                                 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), null, true));
1905                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1906                 response.add(result);
1907                 try {
1908                         xmlResponse = DOMResponse.toString(response, false);
1909                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
1910                 } catch (Exception e) {
1911                         fail("operation failed, e="+e);
1912                 }
1913                 
1914                 // missing required DataType (different from JSON where DataType is optional and assumed to be String)
1915                 response = new StdMutableResponse();
1916                 result = new StdMutableResult();
1917                 result.setDecision(Decision.PERMIT);
1918                 categoryIdentifier = new IdentifierImpl("firstCategory");
1919                 attrList.clear();
1920                                 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(null, "Apu"), "AIssue", true));
1921                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1922                 response.add(result);
1923                 try {
1924                         xmlResponse = DOMResponse.toString(response, false);
1925                         fail("Operation should throw exception");
1926                 } catch (DOMStructureException e) {
1927                         // correct response
1928                 } catch (Exception e) {
1929                         fail ("Failed convert from object to XML: " + e);
1930                 }
1931                 
1932                 // same id, same type different issuer
1933                 // (This is not an array of values because Issuer is different)
1934                 response = new StdMutableResponse();
1935                 result = new StdMutableResult();
1936                 result.setDecision(Decision.PERMIT);
1937                 categoryIdentifier = new IdentifierImpl("firstCategory");
1938                 attrList.clear();
1939                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1940                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"), "BIssue", true));
1941                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Simpson"), "CIssue", true));
1942                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1943                 response.add(result);
1944                 try {
1945                         xmlResponse = DOMResponse.toString(response, false);
1946                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"BIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Simpson</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
1947                 } catch (Exception e) {
1948                         fail("operation failed, e="+e);
1949                 }
1950                 
1951                 // same id, same type same issuer
1952                 // (This is an array of values)
1953                 response = new StdMutableResponse();
1954                 result = new StdMutableResult();
1955                 result.setDecision(Decision.PERMIT);
1956                 categoryIdentifier = new IdentifierImpl("firstCategory");
1957                 attrList.clear();
1958                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1959                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"), "AIssue", true));
1960                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Simpson"), "AIssue", true));
1961                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1962                 response.add(result);
1963                 try {
1964                         xmlResponse = DOMResponse.toString(response, false);
1965                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Simpson</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
1966                 } catch (Exception e) {
1967                         fail("operation failed, e="+e);
1968                 }
1969                 
1970                 // same Id, different types, same issuer
1971                 response = new StdMutableResponse();
1972                 result = new StdMutableResult();
1973                 result.setDecision(Decision.PERMIT);
1974                 categoryIdentifier = new IdentifierImpl("firstCategory");
1975                 attrList.clear();
1976                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1977                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "AIssue", true));
1978                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true));
1979                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true));
1980                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true));
1981                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true));
1982                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
1983                 response.add(result);
1984                 try {
1985                         xmlResponse = DOMResponse.toString(response, false);
1986                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">P10Y4M</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
1987                 } catch (Exception e) {
1988                         fail("operation failed, e="+e);
1989                 }
1990                 
1991                 // same Id, different types, different issuer
1992                 response = new StdMutableResponse();
1993                 result = new StdMutableResult();
1994                 result.setDecision(Decision.PERMIT);
1995                 categoryIdentifier = new IdentifierImpl("firstCategory");
1996                 attrList.clear();
1997                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
1998                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", true));
1999                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true));
2000                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true));
2001                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true));
2002                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), null, true));
2003                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2004                 response.add(result);
2005                 try {
2006                         xmlResponse = DOMResponse.toString(response, false);
2007                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"BIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">P10Y4M</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"DIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"EIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2008                 } catch (Exception e) {
2009                         fail("operation failed, e="+e);
2010                 }
2011
2012                 // different Id, different types, same issuer
2013                 response = new StdMutableResponse();
2014                 result = new StdMutableResult();
2015                 result.setDecision(Decision.PERMIT);
2016                 categoryIdentifier = new IdentifierImpl("firstCategory");
2017                 attrList.clear();
2018                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
2019                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "AIssue"), "BIssue", true));
2020                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "AIssue", true));
2021                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "AIssue", true));
2022                         attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "AIssue", true));
2023                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2024                 response.add(result);
2025                 try {
2026                         xmlResponse = DOMResponse.toString(response, false);
2027                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent2\" Issuer=\"BIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">AIssue</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent3\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent4\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent5\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2028                 } catch (Exception e) {
2029                         fail("operation failed, e="+e);
2030                 }
2031                 
2032                 
2033                 // one Attribute of type XPathExpression (the only complex data type)
2034                 response = new StdMutableResponse();
2035                 result = new StdMutableResult();
2036                 result.setDecision(Decision.PERMIT);
2037                 categoryIdentifier = new IdentifierImpl("firstCategory");
2038                 attrList.clear();
2039                                 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<XPathExpressionWrapper>(DataTypes.DT_XPATHEXPRESSION.getId(), xpathExpressionWrapper, new IdentifierImpl("xpathCategory")), "AIssue", true));
2040                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2041                 response.add(result);
2042                 try {
2043                         xmlResponse = DOMResponse.toString(response, false);
2044                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"urn:oasis:names:tc:xacml:3.0:data-type:xpathExpression\" XPathCategory=\"xpathCategory\">//md:record</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2045                 } catch (Exception e) {
2046                         fail("operation failed, e="+e);
2047                 }
2048                 
2049                 
2050                 // multiple sets of values
2051                 response = new StdMutableResponse();
2052                 result = new StdMutableResult();
2053                 result.setDecision(Decision.PERMIT);
2054                 categoryIdentifier = new IdentifierImpl("firstCategory");
2055                 attrList.clear();
2056                 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"), "AIssue", true));
2057                 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent2"), new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"), "BIssue", false));
2058                 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent3"), new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432), "CIssue", true));
2059                 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent4"), new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true), "DIssue", true));
2060                 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent5"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), "EIssue", true));
2061                 attrList.add(new StdAttribute(categoryIdentifier, new IdentifierImpl("attrNoIssuer"), new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567), null, true));
2062                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2063                 categoryIdentifier = new IdentifierImpl("secondCategory");
2064                 Attribute[] secondAttrList = {
2065                                 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent12"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu2"), "AIssue2", true),
2066                                 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent22"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Abc2"), "BIssue2", false),
2067                                 new StdAttribute(categoryIdentifier, new IdentifierImpl("attrIdent32"), new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Der2"), "CIssue2", true) };
2068                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, Arrays.asList(secondAttrList)));
2069                 response.add(result);
2070                 try {
2071                         xmlResponse = DOMResponse.toString(response, false);
2072                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent3\" Issuer=\"CIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent4\" Issuer=\"DIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent5\" Issuer=\"EIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrNoIssuer\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes><Attributes Category=\"secondCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent12\" Issuer=\"AIssue2\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu2</AttributeValue></Attribute><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent32\" Issuer=\"CIssue2\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Der2</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2073                 } catch (Exception e) {
2074                         fail("operation failed, e="+e);
2075                 }
2076                 
2077                 
2078                 // array of values - same type
2079                 response = new StdMutableResponse();
2080                 result = new StdMutableResult();
2081                 result.setDecision(Decision.PERMIT);
2082                 attrList.clear();
2083                 categoryIdentifier = new IdentifierImpl("firstCategory");
2084                 mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection<AttributeValue<?>>)null, "AIssue", true);
2085
2086                         mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"));
2087                         mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Bart"));
2088                         mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Homer"));
2089                         mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Ned"));
2090                         
2091                 attrList.add(mutableAttribute);
2092                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2093                 response.add(result);
2094                 try {
2095                         xmlResponse = DOMResponse.toString(response, false);
2096                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Bart</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Homer</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Ned</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2097                 } catch (Exception e) {
2098                         fail("operation failed, e="+e);
2099                 }
2100                 
2101                 
2102                 // array of values - compatible different types
2103                 response = new StdMutableResponse();
2104                 result = new StdMutableResult();
2105                 result.setDecision(Decision.PERMIT);
2106                 attrList.clear();
2107                 categoryIdentifier = new IdentifierImpl("firstCategory");
2108                 mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection<AttributeValue<?>>)null, "AIssue", true);
2109
2110                         mutableAttribute.addValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567));
2111                         mutableAttribute.addValue(new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432));
2112                         mutableAttribute.addValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567));
2113                 attrList.add(mutableAttribute);
2114                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2115                 response.add(result);
2116                 try {
2117                         xmlResponse = DOMResponse.toString(response, false);
2118                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2119                 } catch (Exception e) {
2120                         fail("operation failed, e="+e);
2121                 }
2122                 
2123                 
2124                 // array of values - incompatible different types (Different from JSON because these are not part of an array in XML, just separate values)
2125                 response = new StdMutableResponse();
2126                 result = new StdMutableResult();
2127                 result.setDecision(Decision.PERMIT);
2128                 attrList.clear();
2129                 categoryIdentifier = new IdentifierImpl("firstCategory");
2130                 mutableAttribute = new StdMutableAttribute(categoryIdentifier, new IdentifierImpl("attrIdent1"), (Collection<AttributeValue<?>>)null, "AIssue", true);
2131
2132                         mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_STRING.getId(), "Apu"));
2133                         mutableAttribute.addValue(new StdAttributeValue<String>(DataTypes.DT_YEARMONTHDURATION.getId(), "P10Y4M"));
2134                         mutableAttribute.addValue(new StdAttributeValue<Double>(DataTypes.DT_DOUBLE.getId(), 765.432));
2135                         mutableAttribute.addValue(new StdAttributeValue<Boolean>(DataTypes.DT_BOOLEAN.getId(), true));
2136                         mutableAttribute.addValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567));
2137                         mutableAttribute.addValue(new StdAttributeValue<Integer>(DataTypes.DT_INTEGER.getId(), 4567));
2138                 attrList.add(mutableAttribute);
2139                 result.addAttributeCategory(new StdAttributeCategory(categoryIdentifier, attrList));
2140                 response.add(result);
2141                 try {
2142                         xmlResponse = DOMResponse.toString(response, false);
2143                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><Attributes Category=\"firstCategory\"><Attribute IncludeInResult=\"true\" AttributeId=\"attrIdent1\" Issuer=\"AIssue\"><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">Apu</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#yearMonthDuration\">P10Y4M</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#double\">765.432</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#boolean\">true</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue><AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#integer\">4567</AttributeValue></Attribute></Attributes></Result></Response>", xmlResponse);
2144                 } catch (Exception e) {
2145                         fail("operation failed, e="+e);
2146                 }
2147                 
2148         }
2149         
2150         
2151         
2152         
2153         
2154         // PolicyIdentifier tests
2155         @Test
2156         public void testPolicyIdentifier() {
2157                 
2158                 StdIdReference policyIdentifier1 = null;
2159                 StdIdReference policyIdentifier2 = null;
2160                 StdIdReference policySetIdentifier1 = null;
2161                 StdIdReference policySetIdentifier2 = null;
2162                 
2163                 // multiple PolicyIdentifiers of both types
2164                 response = new StdMutableResponse();
2165                 result = new StdMutableResult();
2166                 result.setDecision(Decision.PERMIT);
2167                 try {
2168                         policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3"));
2169                         policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion"));
2170                         policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0"));
2171                         policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion"));
2172                 } catch (ParseException e1) {
2173                         fail("creating policyIds, e="+e1);
2174                 }
2175                 result.addPolicyIdentifier(policyIdentifier1);
2176                 result.addPolicyIdentifier(policyIdentifier2);
2177                 result.addPolicySetIdentifier(policySetIdentifier1);
2178                 result.addPolicySetIdentifier(policySetIdentifier2);
2179                 response.add(result);
2180                 try {
2181                         xmlResponse = DOMResponse.toString(response, false);
2182                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><PolicyIdentifierList><PolicyIdReference Version=\"1.2.3\">idRef1</PolicyIdReference><PolicyIdReference>idRef2_NoVersion</PolicyIdReference><PolicySetIdReference Version=\"4.5.6.7.8.9.0\">idSetRef1</PolicySetIdReference><PolicySetIdReference>idSetRef2_NoVersion</PolicySetIdReference></PolicyIdentifierList></Result></Response>", xmlResponse);
2183                 } catch (Exception e) {
2184                         fail("operation failed, e="+e);
2185                 }
2186                 
2187                 
2188                 // PolicyIdentifier exists but has no IdReferences
2189                 response = new StdMutableResponse();
2190                 result = new StdMutableResult();
2191                 result.setDecision(Decision.PERMIT);
2192                 policyIdentifier1 = null;
2193                 result.addPolicyIdentifier(policyIdentifier1);
2194                 response.add(result);
2195                 try {
2196                         xmlResponse = DOMResponse.toString(response, false);
2197                         fail("Operation should throw exception");
2198                 } catch (DOMStructureException e) {
2199                         // correct response
2200                 } catch (Exception e) {
2201                         fail ("Failed convert from object to XML: " + e);
2202                 }
2203                 
2204                 // PolicySetIdentifier exists but has not IdReferences
2205                 response = new StdMutableResponse();
2206                 result = new StdMutableResult();
2207                 result.setDecision(Decision.PERMIT);
2208                 policySetIdentifier1 = null;
2209                 result.addPolicyIdentifier(policySetIdentifier1);
2210                 response.add(result);
2211                 try {
2212                         xmlResponse = DOMResponse.toString(response, false);
2213                         fail("Operation should throw exception");
2214                 } catch (DOMStructureException e) {
2215                         // correct response
2216                 } catch (Exception e) {
2217                         fail ("Failed convert from object to XML: " + e);
2218                 }
2219                 
2220                 // PolicyIdentifier with PolicyIdReference and no PolicySetIdReference
2221                 response = new StdMutableResponse();
2222                 result = new StdMutableResult();
2223                 result.setDecision(Decision.PERMIT);
2224                 try {
2225                         policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), StdVersion.newInstance("1.2.3"));
2226                 } catch (ParseException e1) {
2227                         fail("creating policyIds, e="+e1);
2228                 }
2229                 result.addPolicyIdentifier(policyIdentifier1);
2230                 response.add(result);
2231                 try {
2232                         xmlResponse = DOMResponse.toString(response, false);
2233                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><PolicyIdentifierList><PolicyIdReference Version=\"1.2.3\">idRef1</PolicyIdReference></PolicyIdentifierList></Result></Response>", xmlResponse);
2234                 } catch (Exception e) {
2235                         fail("operation failed, e="+e);
2236                 }
2237                 
2238                 
2239                 
2240                 // PolicyIdentifier with no PolicyIdReference and with PolicySetIdReference
2241                 response = new StdMutableResponse();
2242                 result = new StdMutableResult();
2243                 result.setDecision(Decision.PERMIT);
2244                 try {
2245                         policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"), StdVersion.newInstance("4.5.6.7.8.9.0"));
2246                 } catch (ParseException e1) {
2247                         fail("creating policyIds, e="+e1);
2248                 }
2249                 result.addPolicySetIdentifier(policySetIdentifier1);
2250                 response.add(result);
2251                 try {
2252                         xmlResponse = DOMResponse.toString(response, false);
2253                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><PolicyIdentifierList><PolicySetIdReference Version=\"4.5.6.7.8.9.0\">idSetRef1</PolicySetIdReference></PolicyIdentifierList></Result></Response>", xmlResponse);
2254                 } catch (Exception e) {
2255                         fail("operation failed, e="+e);
2256                 }
2257                 
2258                 
2259                 // IdReferences without version
2260                 response = new StdMutableResponse();
2261                 result = new StdMutableResult();
2262                 result.setDecision(Decision.PERMIT);
2263
2264                         policyIdentifier1 = new StdIdReference(new IdentifierImpl("idRef1"), null);
2265                         policyIdentifier2 = new StdIdReference(new IdentifierImpl("idRef2_NoVersion"));
2266                         policySetIdentifier1 = new StdIdReference(new IdentifierImpl("idSetRef1"));
2267                         policySetIdentifier2 = new StdIdReference(new IdentifierImpl("idSetRef2_NoVersion"));
2268
2269                 result.addPolicyIdentifier(policyIdentifier1);
2270                 result.addPolicyIdentifier(policyIdentifier2);
2271                 result.addPolicySetIdentifier(policySetIdentifier1);
2272                 result.addPolicySetIdentifier(policySetIdentifier2);
2273                 response.add(result);
2274                 try {
2275                         xmlResponse = DOMResponse.toString(response, false);
2276                         assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response xmlns=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd\"><Result><Decision>Permit</Decision><PolicyIdentifierList><PolicyIdReference>idRef1</PolicyIdReference><PolicyIdReference>idRef2_NoVersion</PolicyIdReference><PolicySetIdReference>idSetRef1</PolicySetIdReference><PolicySetIdReference>idSetRef2_NoVersion</PolicySetIdReference></PolicyIdentifierList></Result></Response>", xmlResponse);
2277                 } catch (Exception e) {
2278                         fail("operation failed, e="+e);
2279                 }
2280         }
2281
2282
2283 //TODO - the XML spec implies that the Result Attributes may include the Content (It is part of the UML)
2284         
2285         
2286         // test indentation???
2287         
2288         
2289 }
2290
2291
2292 /*
2293 Place to edit long strings ouput from tests
2294
2295
2296 Expected
2297 <?xml version="1.0" encoding="UTF-8"?><Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd"><Result><Decision>Permit</Decision></Result></Response>
2298 <?xml version="1.0" encoding="UTF-8"?><Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17 http://docs.oasis-open.org/xacml/3.0/xacml-core-v3-schema-wd-17.xsd"><Result><Decision>Permit</Decision></Result></Response>
2299 Actual
2300
2301
2302
2303  */
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316