2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.policy.pdp.test;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
30 import java.util.ArrayList;
31 import java.util.Calendar;
32 import java.util.Date;
33 import java.util.List;
35 import javax.security.auth.x500.X500Principal;
37 import org.junit.Test;
39 import com.att.research.xacml.api.XACML1;
40 import com.att.research.xacml.api.XACML3;
41 import com.att.research.xacml.std.datatypes.Base64Binary;
42 import com.att.research.xacml.std.datatypes.DataTypeRFC822Name;
43 import com.att.research.xacml.std.datatypes.DataTypes;
44 import com.att.research.xacml.std.datatypes.HexBinary;
45 import com.att.research.xacml.std.datatypes.RFC822Name;
46 import com.att.research.xacml.std.datatypes.XPathDayTimeDuration;
47 import com.att.research.xacml.std.datatypes.XPathYearMonthDuration;
48 import com.att.research.xacmlatt.pdp.policy.ExpressionResult;
49 import com.att.research.xacmlatt.pdp.policy.FunctionArgument;
50 import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue;
51 import com.att.research.xacmlatt.pdp.std.StdFunctions;
52 import com.att.research.xacmlatt.pdp.std.functions.*;
55 * Test FunctionDefinitionEquality, all of its super-classes, and all XACML functions supported by that class.
58 * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
60 * In the first implementation of XACML we had separate files for each XACML Function.
61 * This release combines multiple Functions in fewer files to minimize code duplication.
62 * This file supports the following XACML codes:
70 * dayTimeDuration-equal
71 * yearMonthDuration-equal
73 * Each of these is put into a separate test method just to keep things organized.
77 public class FunctionDefinitionEqualityTest {
80 * variables useful in the following tests
82 List<FunctionArgument> arguments = new ArrayList<>();
84 FunctionArgumentAttributeValue stringAttr1 = null;
85 FunctionArgumentAttributeValue stringAttr2 = null;
86 FunctionArgumentAttributeValue stringAttr3 = null;
87 FunctionArgumentAttributeValue stringAttr4 = null;
89 FunctionArgumentAttributeValue booleanAttrT1 = null;
90 FunctionArgumentAttributeValue booleanAttrT2 = null;
91 FunctionArgumentAttributeValue booleanAttrF1 = null;
92 FunctionArgumentAttributeValue booleanAttrF2 = null;
94 FunctionArgumentAttributeValue intAttr1 = null;
95 FunctionArgumentAttributeValue intAttr1a = null;
96 FunctionArgumentAttributeValue intAttr2 = null;
97 FunctionArgumentAttributeValue intAttr0 = null;
98 FunctionArgumentAttributeValue intAttrNeg1 = null;
100 public FunctionDefinitionEqualityTest() {
102 stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc"));
103 stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc"));
104 stringAttr3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ABC"));
105 stringAttr4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def"));
107 booleanAttrT1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(true));
108 booleanAttrT2 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(true));
109 booleanAttrF1 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(false));
110 booleanAttrF2 = new FunctionArgumentAttributeValue(DataTypes.DT_BOOLEAN.createAttributeValue(false));
112 intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
113 intAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
114 intAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2));
115 intAttr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0));
116 intAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1));
117 } catch (Exception e) {
118 fail("creating attribute e="+ e);
126 * String (matching case)
129 public void testString_Equal() {
131 // String exact match
132 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_STRING_EQUAL;
134 // check identity and type of the thing created
135 assertEquals(XACML3.ID_FUNCTION_STRING_EQUAL, fd.getId());
136 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
138 // just to be safe... If tests take too long these can probably be eliminated
139 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
140 assertFalse(fd.returnsBag());
141 assertEquals(new Integer(2), fd.getNumArgs());
143 // test normal equals and non-equals
144 // check "abc" with "abc" - separate string objects with same value
145 arguments.add(stringAttr1);
146 arguments.add(stringAttr2);
147 ExpressionResult res = fd.evaluate(null, arguments);
148 assertTrue(res.isOk());
149 Boolean resValue = (Boolean)res.getValue().getValue();
150 assertTrue(resValue);
152 // check "abc" with "ABC" (not same)
154 arguments.add(stringAttr1);
155 arguments.add(stringAttr3);
156 res = fd.evaluate(null, arguments);
157 assertTrue(res.isOk());
158 resValue = (Boolean)res.getValue().getValue();
159 assertFalse(resValue);
161 // test bad args data types? Not needed?
163 arguments.add(stringAttr1);
164 arguments.add(intAttr1);
165 res = fd.evaluate(null, arguments);
166 assertFalse(res.isOk());
176 public void testBoolean_Equal() {
178 // String exact match
179 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_BOOLEAN_EQUAL;
181 // check identity and type of the thing created
182 assertEquals(XACML3.ID_FUNCTION_BOOLEAN_EQUAL, fd.getId());
183 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeArgs().getId());
185 // just to be safe... If tests take too long these can probably be eliminated
186 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
187 assertFalse(fd.returnsBag());
188 assertEquals(new Integer(2), fd.getNumArgs());
190 // test normal equals and non-equals
191 // check separate objects with same value
192 arguments.add(booleanAttrT1);
193 arguments.add(booleanAttrT2);
194 ExpressionResult res = fd.evaluate(null, arguments);
195 assertTrue(res.isOk());
196 Boolean resValue = (Boolean)res.getValue().getValue();
197 assertTrue(resValue);
199 // check different values
201 arguments.add(booleanAttrT1);
202 arguments.add(booleanAttrF1);
203 res = fd.evaluate(null, arguments);
204 assertTrue(res.isOk());
205 resValue = (Boolean)res.getValue().getValue();
206 assertFalse(resValue);
208 // test bad args data types? Not needed?
210 arguments.add(stringAttr1);
211 arguments.add(intAttr1);
212 res = fd.evaluate(null, arguments);
213 assertFalse(res.isOk());
222 public void testInteger_Equal() {
224 // String exact match
225 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_INTEGER_EQUAL;
227 // check identity and type of the thing created
228 assertEquals(XACML3.ID_FUNCTION_INTEGER_EQUAL, fd.getId());
229 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
231 // just to be safe... If tests take too long these can probably be eliminated
232 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
233 assertFalse(fd.returnsBag());
234 assertEquals(new Integer(2), fd.getNumArgs());
236 // test normal equals and non-equals
237 // check separate objects with same value
238 arguments.add(intAttr1);
239 arguments.add(intAttr1a);
240 ExpressionResult res = fd.evaluate(null, arguments);
241 assertTrue(res.isOk());
242 Boolean resValue = (Boolean)res.getValue().getValue();
243 assertTrue(resValue);
247 arguments.add(intAttr1);
248 arguments.add(intAttr2);
249 res = fd.evaluate(null, arguments);
250 assertTrue(res.isOk());
251 resValue = (Boolean)res.getValue().getValue();
252 assertFalse(resValue);
255 arguments.add(intAttr1);
256 arguments.add(intAttrNeg1);
257 res = fd.evaluate(null, arguments);
258 assertTrue(res.isOk());
259 resValue = (Boolean)res.getValue().getValue();
260 assertFalse(resValue);
263 // test bad args data types? Not needed?
265 arguments.add(stringAttr1);
266 arguments.add(intAttr1);
267 res = fd.evaluate(null, arguments);
268 assertFalse(res.isOk());
278 public void testDouble_Equal() {
279 FunctionArgumentAttributeValue attr1 = null;
280 FunctionArgumentAttributeValue attr1a = null;
281 FunctionArgumentAttributeValue attr2 = null;
282 FunctionArgumentAttributeValue attrNeg1 = null;
284 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0));
285 attr1a = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0));
286 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.4));
287 attrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-1.0));
288 } catch (Exception e) {
289 fail("creating attribute e="+ e);
292 // String exact match
293 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_DOUBLE_EQUAL;
295 // check identity and type of the thing created
296 assertEquals(XACML3.ID_FUNCTION_DOUBLE_EQUAL, fd.getId());
297 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
299 // just to be safe... If tests take too long these can probably be eliminated
300 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
301 assertFalse(fd.returnsBag());
302 assertEquals(new Integer(2), fd.getNumArgs());
304 // test normal equals and non-equals
305 // check separate objects with the same value
306 arguments.add(attr1);
307 arguments.add(attr1a);
308 ExpressionResult res = fd.evaluate(null, arguments);
309 assertTrue(res.isOk());
310 Boolean resValue = (Boolean)res.getValue().getValue();
311 assertTrue(resValue);
315 arguments.add(attr1);
316 arguments.add(attr2);
317 res = fd.evaluate(null, arguments);
318 assertTrue(res.isOk());
319 resValue = (Boolean)res.getValue().getValue();
320 assertFalse(resValue);
323 arguments.add(attr1);
324 arguments.add(attrNeg1);
325 res = fd.evaluate(null, arguments);
326 assertTrue(res.isOk());
327 resValue = (Boolean)res.getValue().getValue();
328 assertFalse(resValue);
331 // test bad args data types? Not needed?
333 arguments.add(stringAttr1);
334 arguments.add(intAttr1);
335 res = fd.evaluate(null, arguments);
336 assertFalse(res.isOk());
348 public void testDate_Equal() {
349 Calendar calendar = Calendar.getInstance();
350 Date today = calendar.getTime();
351 Date longAgo = new Date(1234);
352 // create a date that is different than "today" but within the same day (i.e. has a different hour)
353 if (calendar.get(Calendar.HOUR_OF_DAY) > 3) {
354 calendar.set(Calendar.HOUR_OF_DAY, 3);
356 calendar.set(Calendar.HOUR_OF_DAY, 5);
358 Date todayPlus = calendar.getTime();
361 FunctionArgumentAttributeValue attrToday = null;
362 FunctionArgumentAttributeValue attrToday2 = null;
363 FunctionArgumentAttributeValue attrLaterToday = null;
364 FunctionArgumentAttributeValue attrYesterday = null;
366 attrToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today));
367 attrToday2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today));
368 attrLaterToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(todayPlus));
369 attrYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(longAgo));
370 } catch (Exception e) {
371 fail("creating attribute e="+ e);
374 // String exact match
375 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_DATE_EQUAL;
377 // check identity and type of the thing created
378 assertEquals(XACML3.ID_FUNCTION_DATE_EQUAL, fd.getId());
379 assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId());
381 // just to be safe... If tests take too long these can probably be eliminated
382 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
383 assertFalse(fd.returnsBag());
384 assertEquals(new Integer(2), fd.getNumArgs());
386 // test normal equals and non-equals
387 // check separate objects with the same value
388 arguments.add(attrToday);
389 arguments.add(attrToday2);
390 ExpressionResult res = fd.evaluate(null, arguments);
391 assertTrue(res.isOk());
392 Boolean resValue = (Boolean)res.getValue().getValue();
393 assertTrue(resValue);
397 arguments.add(attrToday);
398 arguments.add(attrYesterday);
399 res = fd.evaluate(null, arguments);
400 assertTrue(res.isOk());
401 resValue = (Boolean)res.getValue().getValue();
402 assertFalse(resValue);
404 // Date objects with different times but within the same day should match
406 arguments.add(attrToday);
407 arguments.add(attrLaterToday);
408 res = fd.evaluate(null, arguments);
409 assertTrue(res.isOk());
410 resValue = (Boolean)res.getValue().getValue();
411 assertTrue(resValue);
413 // test bad args data types? Not needed?
415 arguments.add(stringAttr1);
416 arguments.add(intAttr1);
417 res = fd.evaluate(null, arguments);
418 assertFalse(res.isOk());
429 public void testTime_Equal() {
431 Date now = new Date();
432 Date now2 = new Date(now.getTime());
433 Date notNow = new Date(now.getTime() - 100000);
435 FunctionArgumentAttributeValue attrNow = null;
436 FunctionArgumentAttributeValue attrNow2 = null;
437 FunctionArgumentAttributeValue attrNotNow = null;
439 attrNow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(now));
440 attrNow2 = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(now2));
441 attrNotNow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(notNow));
442 } catch (Exception e) {
443 fail("creating attribute e="+ e);
446 // String exact match
447 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_TIME_EQUAL;
449 // check identity and type of the thing created
450 assertEquals(XACML3.ID_FUNCTION_TIME_EQUAL, fd.getId());
451 assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId());
453 // just to be safe... If tests take too long these can probably be eliminated
454 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
455 assertFalse(fd.returnsBag());
456 assertEquals(new Integer(2), fd.getNumArgs());
458 // test normal equals and non-equals
459 // check separate objects with the same value
460 arguments.add(attrNow);
461 arguments.add(attrNow2);
462 ExpressionResult res = fd.evaluate(null, arguments);
463 assertTrue(res.isOk());
464 Boolean resValue = (Boolean)res.getValue().getValue();
465 assertTrue(resValue);
469 arguments.add(attrNow);
470 arguments.add(attrNotNow);
471 res = fd.evaluate(null, arguments);
472 assertTrue(res.isOk());
473 resValue = (Boolean)res.getValue().getValue();
474 assertFalse(resValue);
476 // test bad args data types? Not needed?
478 arguments.add(stringAttr1);
479 arguments.add(intAttr1);
480 res = fd.evaluate(null, arguments);
481 assertFalse(res.isOk());
492 public void testDateTime_Equal() {
493 Calendar calendar = Calendar.getInstance();
494 Date today = calendar.getTime();
495 Date longAgo = new Date(1234);
496 // create a dateTime that is different than "today" changing only the Timezone
497 if (calendar.get(Calendar.ZONE_OFFSET) > 3) {
498 calendar.set(Calendar.ZONE_OFFSET, 3);
500 calendar.set(Calendar.ZONE_OFFSET, 5);
502 Date todayPlus = calendar.getTime();
505 FunctionArgumentAttributeValue attrToday = null;
506 FunctionArgumentAttributeValue attrToday2 = null;
507 FunctionArgumentAttributeValue attrLaterToday = null;
508 FunctionArgumentAttributeValue attrYesterday = null;
510 attrToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(today));
511 attrToday2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(today));
512 attrLaterToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(todayPlus));
513 attrYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(longAgo));
514 } catch (Exception e) {
515 fail("creating attribute e="+ e);
518 // String exact match
519 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_DATETIME_EQUAL;
521 // check identity and type of the thing created
522 assertEquals(XACML3.ID_FUNCTION_DATETIME_EQUAL, fd.getId());
523 assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId());
525 // just to be safe... If tests take too long these can probably be eliminated
526 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
527 assertFalse(fd.returnsBag());
528 assertEquals(new Integer(2), fd.getNumArgs());
530 // test normal equals and non-equals
531 // check separate objects with the same value
532 arguments.add(attrToday);
533 arguments.add(attrToday2);
534 ExpressionResult res = fd.evaluate(null, arguments);
535 assertTrue(res.isOk());
536 Boolean resValue = (Boolean)res.getValue().getValue();
537 assertTrue(resValue);
541 arguments.add(attrToday);
542 arguments.add(attrYesterday);
543 res = fd.evaluate(null, arguments);
544 assertTrue(res.isOk());
545 resValue = (Boolean)res.getValue().getValue();
546 assertFalse(resValue);
548 // DateTime with different Zones should not match
550 arguments.add(attrToday);
551 arguments.add(attrLaterToday);
552 res = fd.evaluate(null, arguments);
553 assertTrue(res.isOk());
554 resValue = (Boolean)res.getValue().getValue();
555 assertFalse(resValue);
557 // test bad args data types? Not needed?
559 arguments.add(stringAttr1);
560 arguments.add(intAttr1);
561 res = fd.evaluate(null, arguments);
562 assertFalse(res.isOk());
568 * dayTimeDuration - Version1
571 public void testDayTimeDuration_Equal_V1() {
573 XPathDayTimeDuration dur1 = new XPathDayTimeDuration(1, 3, 5, 12, 38);
574 XPathDayTimeDuration dur2 = new XPathDayTimeDuration(1, 3, 5, 12, 38);
575 XPathDayTimeDuration differentDur = new XPathDayTimeDuration(-1, 4, 7, 5, 33);
577 FunctionArgumentAttributeValue attrDur1 = null;
578 FunctionArgumentAttributeValue attrDur2 = null;
579 FunctionArgumentAttributeValue attrDifferentDur = null;
581 attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur1));
582 attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur2));
583 attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(differentDur));
584 } catch (Exception e) {
585 fail("creating attribute e="+ e);
588 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_DAYTIMEDURATION_EQUAL_VERSION1;
590 // check identity and type of the thing created
591 assertEquals(XACML1.ID_FUNCTION_DAYTIMEDURATION_EQUAL, fd.getId());
592 assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeArgs().getId());
594 // just to be safe... If tests take too long these can probably be eliminated
595 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
596 assertFalse(fd.returnsBag());
597 assertEquals(new Integer(2), fd.getNumArgs());
599 // test normal equals and non-equals
600 // check separate objects with the same value
601 arguments.add(attrDur1);
602 arguments.add(attrDur2);
603 ExpressionResult res = fd.evaluate(null, arguments);
604 assertTrue(res.isOk());
605 Boolean resValue = (Boolean)res.getValue().getValue();
606 assertTrue(resValue);
610 arguments.add(attrDur1);
611 arguments.add(attrDifferentDur);
612 res = fd.evaluate(null, arguments);
613 assertTrue(res.isOk());
614 resValue = (Boolean)res.getValue().getValue();
615 assertFalse(resValue);
617 // test bad args data types? Not needed?
619 arguments.add(stringAttr1);
620 arguments.add(intAttr1);
621 res = fd.evaluate(null, arguments);
622 assertFalse(res.isOk());
628 * dayTimeDuration - Current version
631 public void testDayTimeDuration_Equal() {
633 XPathDayTimeDuration dur1 = new XPathDayTimeDuration(1, 3, 5, 12, 38);
634 XPathDayTimeDuration dur2 = new XPathDayTimeDuration(1, 3, 5, 12, 38);
635 XPathDayTimeDuration differentDur = new XPathDayTimeDuration(-1, 4, 7, 5, 33);
637 FunctionArgumentAttributeValue attrDur1 = null;
638 FunctionArgumentAttributeValue attrDur2 = null;
639 FunctionArgumentAttributeValue attrDifferentDur = null;
641 attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur1));
642 attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(dur2));
643 attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_DAYTIMEDURATION.createAttributeValue(differentDur));
644 } catch (Exception e) {
645 fail("creating attribute e="+ e);
648 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_DAYTIMEDURATION_EQUAL;
650 // check identity and type of the thing created
651 assertEquals(XACML3.ID_FUNCTION_DAYTIMEDURATION_EQUAL, fd.getId());
652 assertEquals(DataTypes.DT_DAYTIMEDURATION.getId(), fd.getDataTypeArgs().getId());
654 // just to be safe... If tests take too long these can probably be eliminated
655 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
656 assertFalse(fd.returnsBag());
657 assertEquals(new Integer(2), fd.getNumArgs());
659 // test normal equals and non-equals
660 // check separate objects with the same value
661 arguments.add(attrDur1);
662 arguments.add(attrDur2);
663 ExpressionResult res = fd.evaluate(null, arguments);
664 assertTrue(res.isOk());
665 Boolean resValue = (Boolean)res.getValue().getValue();
666 assertTrue(resValue);
670 arguments.add(attrDur1);
671 arguments.add(attrDifferentDur);
672 res = fd.evaluate(null, arguments);
673 assertTrue(res.isOk());
674 resValue = (Boolean)res.getValue().getValue();
675 assertFalse(resValue);
677 // test bad args data types? Not needed?
679 arguments.add(stringAttr1);
680 arguments.add(intAttr1);
681 res = fd.evaluate(null, arguments);
682 assertFalse(res.isOk());
689 * dayTimeDuration - Version1
692 public void testYearMonthDuration_Equal_V1() {
694 XPathYearMonthDuration dur1 = new XPathYearMonthDuration(1, 3, 5);
695 XPathYearMonthDuration dur2 = new XPathYearMonthDuration(1, 3, 5);
696 XPathYearMonthDuration differentDur = new XPathYearMonthDuration(-1, 4, 7);
698 FunctionArgumentAttributeValue attrDur1 = null;
699 FunctionArgumentAttributeValue attrDur2 = null;
700 FunctionArgumentAttributeValue attrDifferentDur = null;
702 attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur1));
703 attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur2));
704 attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(differentDur));
705 } catch (Exception e) {
706 fail("creating attribute e="+ e);
709 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_YEARMONTHDURATION_EQUAL_VERSION1;
711 // check identity and type of the thing created
712 assertEquals(XACML1.ID_FUNCTION_YEARMONTHDURATION_EQUAL, fd.getId());
713 assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeArgs().getId());
715 // just to be safe... If tests take too long these can probably be eliminated
716 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
717 assertFalse(fd.returnsBag());
718 assertEquals(new Integer(2), fd.getNumArgs());
720 // test normal equals and non-equals
721 // check separate objects with the same value
722 arguments.add(attrDur1);
723 arguments.add(attrDur2);
724 ExpressionResult res = fd.evaluate(null, arguments);
725 assertTrue(res.isOk());
726 Boolean resValue = (Boolean)res.getValue().getValue();
727 assertTrue(resValue);
731 arguments.add(attrDur1);
732 arguments.add(attrDifferentDur);
733 res = fd.evaluate(null, arguments);
734 assertTrue(res.isOk());
735 resValue = (Boolean)res.getValue().getValue();
736 assertFalse(resValue);
738 // test bad args data types? Not needed?
740 arguments.add(stringAttr1);
741 arguments.add(intAttr1);
742 res = fd.evaluate(null, arguments);
743 assertFalse(res.isOk());
751 * dayTimeDuration - Current version
754 public void testYearMonthDuration_Equal() {
756 XPathYearMonthDuration dur1 = new XPathYearMonthDuration(1, 3, 5);
757 XPathYearMonthDuration dur2 = new XPathYearMonthDuration(1, 3, 5);
758 XPathYearMonthDuration differentDur = new XPathYearMonthDuration(-1, 4, 7);
760 FunctionArgumentAttributeValue attrDur1 = null;
761 FunctionArgumentAttributeValue attrDur2 = null;
762 FunctionArgumentAttributeValue attrDifferentDur = null;
764 attrDur1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur1));
765 attrDur2 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(dur2));
766 attrDifferentDur = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(differentDur));
767 } catch (Exception e) {
768 fail("creating attribute e="+ e);
771 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_YEARMONTHDURATION_EQUAL;
773 // check identity and type of the thing created
774 assertEquals(XACML3.ID_FUNCTION_YEARMONTHDURATION_EQUAL, fd.getId());
775 assertEquals(DataTypes.DT_YEARMONTHDURATION.getId(), fd.getDataTypeArgs().getId());
777 // just to be safe... If tests take too long these can probably be eliminated
778 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
779 assertFalse(fd.returnsBag());
780 assertEquals(new Integer(2), fd.getNumArgs());
782 // test normal equals and non-equals
783 // check separate objects with the same value
784 arguments.add(attrDur1);
785 arguments.add(attrDur2);
786 ExpressionResult res = fd.evaluate(null, arguments);
787 assertTrue(res.isOk());
788 Boolean resValue = (Boolean)res.getValue().getValue();
789 assertTrue(resValue);
793 arguments.add(attrDur1);
794 arguments.add(attrDifferentDur);
795 res = fd.evaluate(null, arguments);
796 assertTrue(res.isOk());
797 resValue = (Boolean)res.getValue().getValue();
798 assertFalse(resValue);
800 // test bad args data types? Not needed?
802 arguments.add(stringAttr1);
803 arguments.add(intAttr1);
804 res = fd.evaluate(null, arguments);
805 assertFalse(res.isOk());
814 public void testAnyURI_Equal() {
818 URI uriNotThere = null;
820 uri1 = new URI("http://someplace.com/gothere");
821 uri2 = new URI("http://someplace.com/gothere");
822 uriNotThere = new URI("http://someplace.com/notGoingThere");
823 } catch (Exception e) {
827 FunctionArgumentAttributeValue attrUri1 = null;
828 FunctionArgumentAttributeValue attrUri2 = null;
829 FunctionArgumentAttributeValue attrUriNotThere = null;
831 attrUri1 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri1));
832 attrUri2 = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uri2));
833 attrUriNotThere = new FunctionArgumentAttributeValue(DataTypes.DT_ANYURI.createAttributeValue(uriNotThere));
834 } catch (Exception e) {
835 fail("creating attribute e="+ e);
838 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_ANYURI_EQUAL;
840 // check identity and type of the thing created
841 assertEquals(XACML3.ID_FUNCTION_ANYURI_EQUAL, fd.getId());
842 assertEquals(DataTypes.DT_ANYURI.getId(), fd.getDataTypeArgs().getId());
844 // just to be safe... If tests take too long these can probably be eliminated
845 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
846 assertFalse(fd.returnsBag());
847 assertEquals(new Integer(2), fd.getNumArgs());
849 // test normal equals and non-equals
850 // check separate objects with the same value
851 arguments.add(attrUri1);
852 arguments.add(attrUri2);
853 ExpressionResult res = fd.evaluate(null, arguments);
854 assertTrue(res.isOk());
855 Boolean resValue = (Boolean)res.getValue().getValue();
856 assertTrue(resValue);
860 arguments.add(attrUri1);
861 arguments.add(attrUriNotThere);
862 res = fd.evaluate(null, arguments);
863 assertTrue(res.isOk());
864 resValue = (Boolean)res.getValue().getValue();
865 assertFalse(resValue);
867 // test bad args data types? Not needed?
869 arguments.add(stringAttr1);
870 arguments.add(intAttr1);
871 res = fd.evaluate(null, arguments);
872 assertFalse(res.isOk());
881 public void testX500Name_Equal() {
883 X500Principal name1 = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US");
884 X500Principal name2 = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US");
885 X500Principal name3 = new X500Principal("CN=NotDuke, OU=NotThere, O=Oracle, C=US");
888 FunctionArgumentAttributeValue attrName1 = null;
889 FunctionArgumentAttributeValue attrName1a = null;
890 FunctionArgumentAttributeValue attrNotSameName = null;
892 attrName1 = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(name1));
893 attrName1a = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(name2));
894 attrNotSameName = new FunctionArgumentAttributeValue(DataTypes.DT_X500NAME.createAttributeValue(name3));
895 } catch (Exception e) {
896 fail("creating attribute e="+ e);
899 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_X500NAME_EQUAL;
901 // check identity and type of the thing created
902 assertEquals(XACML3.ID_FUNCTION_X500NAME_EQUAL, fd.getId());
903 assertEquals(DataTypes.DT_X500NAME.getId(), fd.getDataTypeArgs().getId());
905 // just to be safe... If tests take too long these can probably be eliminated
906 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
907 assertFalse(fd.returnsBag());
908 assertEquals(new Integer(2), fd.getNumArgs());
910 // test normal equals and non-equals
911 // check separate objects with the same value
912 arguments.add(attrName1);
913 arguments.add(attrName1a);
914 ExpressionResult res = fd.evaluate(null, arguments);
915 assertTrue(res.isOk());
916 Boolean resValue = (Boolean)res.getValue().getValue();
917 assertTrue(resValue);
921 arguments.add(attrName1);
922 arguments.add(attrNotSameName);
923 res = fd.evaluate(null, arguments);
924 assertTrue(res.isOk());
925 resValue = (Boolean)res.getValue().getValue();
926 assertFalse(resValue);
928 // test bad args data types? Not needed?
930 arguments.add(stringAttr1);
931 arguments.add(intAttr1);
932 res = fd.evaluate(null, arguments);
933 assertFalse(res.isOk());
943 public void testRfc822Name_Equal() {
945 RFC822Name name1 = null;
946 RFC822Name name1a = null;
947 RFC822Name differentLocalName = null;
948 RFC822Name differentDomainName = null;
949 RFC822Name localCaseName = null;
950 RFC822Name domainCaseName = null;
951 @SuppressWarnings("unused")
952 RFC822Name noAtName = null;
955 name1 = RFC822Name.newInstance("localPart@DomainPart");
956 name1a = RFC822Name.newInstance("localPart@DomainPart");
957 differentLocalName = RFC822Name.newInstance("differentlocalPart@DomainPart");
958 differentDomainName = RFC822Name.newInstance("localPart@differentDomainPart");
959 localCaseName = RFC822Name.newInstance("LOCALPart@DomainPart");
960 domainCaseName = RFC822Name.newInstance("localPart@DOMAINPart");
963 } catch (Exception e) {
967 // should not be able to create a name without an @. If you try, newInstance returns null
968 Exception exSeen = null;
970 noAtName = RFC822Name.newInstance("nameWithoutAnAtSign");
971 } catch (Exception e) {
974 assertNotNull(exSeen);
977 FunctionArgumentAttributeValue attrName1 = null;
978 FunctionArgumentAttributeValue attrName1a = null;
979 FunctionArgumentAttributeValue attrDifferentLocalName = null;
980 FunctionArgumentAttributeValue attrDifferentDomainName = null;
981 FunctionArgumentAttributeValue attrLocalCaseName = null;
982 FunctionArgumentAttributeValue attrDomainCaseName = null;
984 attrName1 = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(name1));
985 attrName1a = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(name1a));
986 attrDifferentLocalName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(differentLocalName));
987 attrDifferentDomainName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(differentDomainName));
988 attrLocalCaseName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(localCaseName));
989 attrDomainCaseName = new FunctionArgumentAttributeValue(DataTypes.DT_RFC822NAME.createAttributeValue(domainCaseName));
990 } catch (Exception e) {
991 fail("creating attribute e="+ e);
994 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_RFC822NAME_EQUAL;
996 // check identity and type of the thing created
997 assertEquals(XACML3.ID_FUNCTION_RFC822NAME_EQUAL, fd.getId());
998 assertEquals(DataTypeRFC822Name.newInstance().getId(), fd.getDataTypeArgs().getId());
1000 // just to be safe... If tests take too long these can probably be eliminated
1001 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1002 assertFalse(fd.returnsBag());
1003 assertEquals(new Integer(2), fd.getNumArgs());
1005 // test normal equals and non-equals
1006 // check separate objects with the same value
1007 arguments.add(attrName1);
1008 arguments.add(attrName1a);
1009 ExpressionResult res = fd.evaluate(null, arguments);
1010 assertTrue(res.isOk());
1011 Boolean resValue = (Boolean)res.getValue().getValue();
1012 assertTrue(resValue);
1014 // check not same Local
1016 arguments.add(attrName1);
1017 arguments.add(attrDifferentLocalName);
1018 res = fd.evaluate(null, arguments);
1019 assertTrue(res.isOk());
1020 resValue = (Boolean)res.getValue().getValue();
1021 assertFalse(resValue);
1023 // check not same Domain
1025 arguments.add(attrName1);
1026 arguments.add(attrDifferentDomainName);
1027 res = fd.evaluate(null, arguments);
1028 assertTrue(res.isOk());
1029 resValue = (Boolean)res.getValue().getValue();
1030 assertFalse(resValue);
1032 // test case-sensitivity in local part
1034 arguments.add(attrName1);
1035 arguments.add(attrLocalCaseName);
1036 res = fd.evaluate(null, arguments);
1037 assertTrue(res.isOk());
1038 resValue = (Boolean)res.getValue().getValue();
1039 assertFalse(resValue);
1041 // test non-case-sensitivity in Domain part
1043 arguments.add(attrName1);
1044 arguments.add(attrDomainCaseName);
1045 res = fd.evaluate(null, arguments);
1046 assertTrue(res.isOk());
1047 resValue = (Boolean)res.getValue().getValue();
1048 assertTrue(resValue);
1050 // test bad args data types? Not needed?
1052 arguments.add(stringAttr1);
1053 arguments.add(intAttr1);
1054 res = fd.evaluate(null, arguments);
1055 assertFalse(res.isOk());
1064 public void testHexBinary_Equal() {
1065 HexBinary binary = null;
1066 HexBinary sameBinary = null;
1067 HexBinary differentBinary = null;
1069 binary = HexBinary.newInstance("e04fd020ea3a6910a2d808002b30309d");
1070 sameBinary = HexBinary.newInstance("e04fd020ea3a6910a2d808002b30309d");
1071 differentBinary = HexBinary.newInstance("f123a890ee3d");
1072 } catch (Exception e) {
1076 FunctionArgumentAttributeValue attrBinary = null;
1077 FunctionArgumentAttributeValue attrSameBinary = null;
1078 FunctionArgumentAttributeValue attrDifferentBinary = null;;
1080 attrBinary = new FunctionArgumentAttributeValue(DataTypes.DT_HEXBINARY.createAttributeValue(binary));
1081 attrSameBinary = new FunctionArgumentAttributeValue(DataTypes.DT_HEXBINARY.createAttributeValue(sameBinary));
1082 attrDifferentBinary = new FunctionArgumentAttributeValue(DataTypes.DT_HEXBINARY.createAttributeValue(differentBinary));
1084 } catch (Exception e) {
1085 fail("creating attribute e="+ e);
1088 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_HEXBINARY_EQUAL;
1090 // check identity and type of the thing created
1091 assertEquals(XACML3.ID_FUNCTION_HEXBINARY_EQUAL, fd.getId());
1092 assertEquals(DataTypes.DT_HEXBINARY.getId(), fd.getDataTypeArgs().getId());
1094 // just to be safe... If tests take too long these can probably be eliminated
1095 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1096 assertFalse(fd.returnsBag());
1097 assertEquals(new Integer(2), fd.getNumArgs());
1099 // test normal equals and non-equals
1100 // check separate objects with the same value
1101 arguments.add(attrBinary);
1102 arguments.add(attrSameBinary);
1103 ExpressionResult res = fd.evaluate(null, arguments);
1104 assertTrue(res.isOk());
1105 Boolean resValue = (Boolean)res.getValue().getValue();
1106 assertTrue(resValue);
1110 arguments.add(attrBinary);
1111 arguments.add(attrDifferentBinary);
1112 res = fd.evaluate(null, arguments);
1113 assertTrue(res.isOk());
1114 resValue = (Boolean)res.getValue().getValue();
1115 assertFalse(resValue);
1117 // test bad args data types? Not needed?
1119 arguments.add(stringAttr1);
1120 arguments.add(intAttr1);
1121 res = fd.evaluate(null, arguments);
1122 assertFalse(res.isOk());
1131 public void testBase64Binary_Equal() {
1132 Base64Binary binary = null;
1133 Base64Binary sameBinary = null;
1134 Base64Binary differentBinary = null;
1136 binary = Base64Binary.newInstance("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz");
1137 sameBinary = Base64Binary.newInstance("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz");
1138 differentBinary = Base64Binary.newInstance("f123a890ee3d");
1139 } catch (Exception e) {
1143 FunctionArgumentAttributeValue attrBinary = null;
1144 FunctionArgumentAttributeValue attrSameBinary = null;
1145 FunctionArgumentAttributeValue attrDifferentBinary = null;
1147 attrBinary = new FunctionArgumentAttributeValue(DataTypes.DT_BASE64BINARY.createAttributeValue(binary));
1148 attrSameBinary = new FunctionArgumentAttributeValue(DataTypes.DT_BASE64BINARY.createAttributeValue(sameBinary));
1149 attrDifferentBinary = new FunctionArgumentAttributeValue(DataTypes.DT_BASE64BINARY.createAttributeValue(differentBinary));
1151 } catch (Exception e) {
1152 fail("creating attribute e="+ e);
1155 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_BASE64BINARY_EQUAL;
1157 // check identity and type of the thing created
1158 assertEquals(XACML3.ID_FUNCTION_BASE64BINARY_EQUAL, fd.getId());
1159 assertEquals(DataTypes.DT_BASE64BINARY.getId(), fd.getDataTypeArgs().getId());
1161 // just to be safe... If tests take too long these can probably be eliminated
1162 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1163 assertFalse(fd.returnsBag());
1164 assertEquals(new Integer(2), fd.getNumArgs());
1166 // test normal equals and non-equals
1167 // check separate objects with the same value
1168 arguments.add(attrBinary);
1169 arguments.add(attrSameBinary);
1170 ExpressionResult res = fd.evaluate(null, arguments);
1171 assertTrue(res.isOk());
1172 Boolean resValue = (Boolean)res.getValue().getValue();
1173 assertTrue(resValue);
1177 arguments.add(attrBinary);
1178 arguments.add(attrDifferentBinary);
1179 res = fd.evaluate(null, arguments);
1180 assertTrue(res.isOk());
1181 resValue = (Boolean)res.getValue().getValue();
1182 assertFalse(resValue);
1184 // test bad args data types? Not needed?
1186 arguments.add(stringAttr1);
1187 arguments.add(intAttr1);
1188 res = fd.evaluate(null, arguments);
1189 assertFalse(res.isOk());