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.assertTrue;
26 import static org.junit.Assert.fail;
28 import java.util.ArrayList;
29 import java.util.Calendar;
30 import java.util.Date;
31 import java.util.List;
33 import org.junit.Test;
35 import com.att.research.xacml.api.XACML3;
36 import com.att.research.xacml.std.datatypes.DataTypes;
37 import com.att.research.xacml.std.datatypes.ISO8601Date;
38 import com.att.research.xacml.std.datatypes.ISO8601DateTime;
39 import com.att.research.xacml.std.datatypes.ISO8601Time;
40 import com.att.research.xacmlatt.pdp.policy.ExpressionResult;
41 import com.att.research.xacmlatt.pdp.policy.FunctionArgument;
42 import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue;
43 import com.att.research.xacmlatt.pdp.std.StdFunctions;
44 import com.att.research.xacmlatt.pdp.std.functions.*;
47 * Test FunctionDefinitionComparison
50 * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
54 public class FunctionDefinitionComparisonTest {
57 * variables useful in the following tests
59 List<FunctionArgument> arguments = new ArrayList<>();
61 FunctionArgumentAttributeValue stringAttr1 = null;
62 FunctionArgumentAttributeValue stringAttr1a = null;
63 FunctionArgumentAttributeValue stringAttr2 = null;
64 FunctionArgumentAttributeValue stringAttrNeg1 = null;
67 FunctionArgumentAttributeValue intAttr1 = null;
68 FunctionArgumentAttributeValue intAttr1a = null;
69 FunctionArgumentAttributeValue intAttr2 = null;
70 FunctionArgumentAttributeValue intAttr0 = null;
71 FunctionArgumentAttributeValue intAttrNeg1 = null;
73 FunctionArgumentAttributeValue attr1 = null;
74 FunctionArgumentAttributeValue attr1a = null;
75 FunctionArgumentAttributeValue attr2 = null;
76 FunctionArgumentAttributeValue attrNeg1 = null;
78 FunctionArgumentAttributeValue attrDateToday = null;
79 FunctionArgumentAttributeValue attrDateSameDay = null;
80 FunctionArgumentAttributeValue attrDateTommorrow = null;
81 FunctionArgumentAttributeValue attrDateYesterday = null;
82 FunctionArgumentAttributeValue attrDateWithTimeZone = null;
83 FunctionArgumentAttributeValue attrDateNoTimeZone = null;
86 FunctionArgumentAttributeValue attrTimeToday = null;
87 FunctionArgumentAttributeValue attrTimeSameDay = null;
88 FunctionArgumentAttributeValue attrTimeTommorrow = null;
89 FunctionArgumentAttributeValue attrTimeYesterday = null;
90 FunctionArgumentAttributeValue attrTimeWithTimeZone = null;
91 FunctionArgumentAttributeValue attrTimeNoTimeZone = null;
93 FunctionArgumentAttributeValue attrDateTimeToday = null;
94 FunctionArgumentAttributeValue attrDateTimeSameDay = null;
95 FunctionArgumentAttributeValue attrDateTimeTommorrow = null;
96 FunctionArgumentAttributeValue attrDateTimeYesterday = null;
97 FunctionArgumentAttributeValue attrDateTimeWithTimeZone = null;
98 FunctionArgumentAttributeValue attrDateTimeNoTimeZone = null;
101 * Set up some common variables on startup
103 public FunctionDefinitionComparisonTest() {
105 stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc"));
106 stringAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc"));
107 stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def"));
108 stringAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("AAA"));
111 intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
112 intAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
113 intAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2));
114 intAttr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0));
115 intAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1));
117 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0));
118 attr1a = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0));
119 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.4));
120 attrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-1.0));
123 Calendar calendar = Calendar.getInstance();
124 Date today = calendar.getTime();
125 Date longAgo = new Date(1234);
126 // create a date that is different than "today" but within the same day (i.e. has a different hour)
127 if (calendar.get(Calendar.HOUR_OF_DAY) > 3) {
128 calendar.set(Calendar.HOUR_OF_DAY, 3);
130 calendar.set(Calendar.HOUR_OF_DAY, 5);
132 Date todayPlus = calendar.getTime();
133 calendar.add(Calendar.DATE, 1);
134 Date tommorrow = calendar.getTime();
135 attrDateToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today));
136 attrDateSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(todayPlus));
137 attrDateTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(tommorrow));
138 attrDateYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(longAgo));
139 ISO8601Date isoDate = new ISO8601Date(1920, 5, 8);
140 attrDateNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(isoDate));
141 isoDate = new ISO8601Date("GMT+00:02", 1920, 5, 8);
142 attrDateWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(isoDate));
145 ISO8601Time isoTime = new ISO8601Time(14, 43, 12, 145);
146 attrTimeToday = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime));
147 attrTimeSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime));
148 isoTime = new ISO8601Time(18, 53, 34, 423);
149 attrTimeTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime));
150 isoTime = new ISO8601Time(7, 34, 6,543);
151 attrTimeYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime));
152 isoTime = new ISO8601Time(12, 12, 12, 12);
153 attrTimeNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime));
154 isoTime = new ISO8601Time("GMT:+00:03", 12, 12, 12, 12);
155 attrTimeWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime));
158 isoDate = new ISO8601Date(1920, 5, 8);
159 isoTime = new ISO8601Time( 18, 53, 34, 423);
160 ISO8601DateTime isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 18, 53, 34, 423);
161 attrDateTimeToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime));
162 attrDateTimeSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime));
163 isoTime = new ISO8601Time(20, 53, 34, 423);
164 isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 20, 53, 34, 423);
165 attrDateTimeTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime));
166 isoTime = new ISO8601Time(7, 34, 6,543);
167 isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 7, 34, 6, 543);
168 attrDateTimeYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime));
169 isoTime = new ISO8601Time(12, 12, 12, 12);
170 isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 12, 12, 12, 12);
171 attrDateTimeNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime));
172 isoTime = new ISO8601Time("GMT:+00:03", 12, 12, 12, 12);
173 isoDate = new ISO8601Date("GMT:+00:03", 1920, 5, 8);
174 isoDateTime = new ISO8601DateTime("GMT:+00:03", 1920, 5, 8, 12, 12, 12, 12);
175 attrDateTimeWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime));
180 } catch (Exception e) {
181 fail("Error creating values e="+ e);
189 public void testString_GT() {
191 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_GREATER_THAN;
193 // check identity and type of the thing created
194 assertEquals(XACML3.ID_FUNCTION_STRING_GREATER_THAN, fd.getId());
195 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
197 // just to be safe... If tests take too long these can probably be eliminated
198 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
199 assertFalse(fd.returnsBag());
200 assertEquals(new Integer(2), fd.getNumArgs());
203 arguments.add(stringAttr1);
204 arguments.add(stringAttr1a);
205 ExpressionResult res = fd.evaluate(null, arguments);
206 assertTrue(res.isOk());
207 Boolean resValue = (Boolean)res.getValue().getValue();
208 assertFalse(resValue);
210 // check first < second
212 arguments.add(stringAttr1);
213 arguments.add(stringAttr2);
214 res = fd.evaluate(null, arguments);
215 assertTrue(res.isOk());
216 resValue = (Boolean)res.getValue().getValue();
217 assertFalse(resValue);
221 arguments.add(stringAttr1);
222 arguments.add(stringAttrNeg1);
223 res = fd.evaluate(null, arguments);
224 assertTrue(res.isOk());
225 resValue = (Boolean)res.getValue().getValue();
226 assertTrue(resValue);
228 // test bad args data types? Not needed?
230 arguments.add(intAttr1);
231 arguments.add(stringAttr1);
232 res = fd.evaluate(null, arguments);
233 assertFalse(res.isOk());
237 public void testString_GTE() {
239 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_GREATER_THAN_OR_EQUAL;
241 // check identity and type of the thing created
242 assertEquals(XACML3.ID_FUNCTION_STRING_GREATER_THAN_OR_EQUAL, fd.getId());
243 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
245 // just to be safe... If tests take too long these can probably be eliminated
246 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
247 assertFalse(fd.returnsBag());
248 assertEquals(new Integer(2), fd.getNumArgs());
251 arguments.add(stringAttr1);
252 arguments.add(stringAttr1a);
253 ExpressionResult res = fd.evaluate(null, arguments);
254 assertTrue(res.isOk());
255 Boolean resValue = (Boolean)res.getValue().getValue();
256 assertTrue(resValue);
258 // check first < second
260 arguments.add(stringAttr1);
261 arguments.add(stringAttr2);
262 res = fd.evaluate(null, arguments);
263 assertTrue(res.isOk());
264 resValue = (Boolean)res.getValue().getValue();
265 assertFalse(resValue);
269 arguments.add(stringAttr1);
270 arguments.add(stringAttrNeg1);
271 res = fd.evaluate(null, arguments);
272 assertTrue(res.isOk());
273 resValue = (Boolean)res.getValue().getValue();
274 assertTrue(resValue);
278 public void testString_LT() {
280 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_LESS_THAN;
282 // check identity and type of the thing created
283 assertEquals(XACML3.ID_FUNCTION_STRING_LESS_THAN, fd.getId());
284 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
286 // just to be safe... If tests take too long these can probably be eliminated
287 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
288 assertFalse(fd.returnsBag());
289 assertEquals(new Integer(2), fd.getNumArgs());
292 arguments.add(stringAttr1);
293 arguments.add(stringAttr1a);
294 ExpressionResult res = fd.evaluate(null, arguments);
295 assertTrue(res.isOk());
296 Boolean resValue = (Boolean)res.getValue().getValue();
297 assertFalse(resValue);
299 // check first < second
301 arguments.add(stringAttr1);
302 arguments.add(stringAttr2);
303 res = fd.evaluate(null, arguments);
304 assertTrue(res.isOk());
305 resValue = (Boolean)res.getValue().getValue();
306 assertTrue(resValue);
310 arguments.add(stringAttr1);
311 arguments.add(stringAttrNeg1);
312 res = fd.evaluate(null, arguments);
313 assertTrue(res.isOk());
314 resValue = (Boolean)res.getValue().getValue();
315 assertFalse(resValue);
319 public void testString_LTE() {
321 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_LESS_THAN_OR_EQUAL;
323 // check identity and type of the thing created
324 assertEquals(XACML3.ID_FUNCTION_STRING_LESS_THAN_OR_EQUAL, fd.getId());
325 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
327 // just to be safe... If tests take too long these can probably be eliminated
328 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
329 assertFalse(fd.returnsBag());
330 assertEquals(new Integer(2), fd.getNumArgs());
333 arguments.add(stringAttr1);
334 arguments.add(stringAttr1a);
335 ExpressionResult res = fd.evaluate(null, arguments);
336 assertTrue(res.isOk());
337 Boolean resValue = (Boolean)res.getValue().getValue();
338 assertTrue(resValue);
340 // check first < second
342 arguments.add(stringAttr1);
343 arguments.add(stringAttr2);
344 res = fd.evaluate(null, arguments);
345 assertTrue(res.isOk());
346 resValue = (Boolean)res.getValue().getValue();
347 assertTrue(resValue);
351 arguments.add(stringAttr1);
352 arguments.add(stringAttrNeg1);
353 res = fd.evaluate(null, arguments);
354 assertTrue(res.isOk());
355 resValue = (Boolean)res.getValue().getValue();
356 assertFalse(resValue);
365 public void testInteger_GT() {
367 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_GREATER_THAN;
369 // check identity and type of the thing created
370 assertEquals(XACML3.ID_FUNCTION_INTEGER_GREATER_THAN, fd.getId());
371 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
373 // just to be safe... If tests take too long these can probably be eliminated
374 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
375 assertFalse(fd.returnsBag());
376 assertEquals(new Integer(2), fd.getNumArgs());
379 arguments.add(intAttr1);
380 arguments.add(intAttr1a);
381 ExpressionResult res = fd.evaluate(null, arguments);
382 assertTrue(res.isOk());
383 Boolean resValue = (Boolean)res.getValue().getValue();
384 assertFalse(resValue);
386 // check first < second
388 arguments.add(intAttr1);
389 arguments.add(intAttr2);
390 res = fd.evaluate(null, arguments);
391 assertTrue(res.isOk());
392 resValue = (Boolean)res.getValue().getValue();
393 assertFalse(resValue);
397 arguments.add(intAttr1);
398 arguments.add(intAttrNeg1);
399 res = fd.evaluate(null, arguments);
400 assertTrue(res.isOk());
401 resValue = (Boolean)res.getValue().getValue();
402 assertTrue(resValue);
404 // test bad args data types? Not needed?
406 arguments.add(stringAttr1);
407 arguments.add(intAttr1);
408 res = fd.evaluate(null, arguments);
409 assertFalse(res.isOk());
413 public void testInteger_GTE() {
415 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_GREATER_THAN_OR_EQUAL;
417 // check identity and type of the thing created
418 assertEquals(XACML3.ID_FUNCTION_INTEGER_GREATER_THAN_OR_EQUAL, fd.getId());
419 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
421 // just to be safe... If tests take too long these can probably be eliminated
422 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
423 assertFalse(fd.returnsBag());
424 assertEquals(new Integer(2), fd.getNumArgs());
427 arguments.add(intAttr1);
428 arguments.add(intAttr1a);
429 ExpressionResult res = fd.evaluate(null, arguments);
430 assertTrue(res.isOk());
431 Boolean resValue = (Boolean)res.getValue().getValue();
432 assertTrue(resValue);
434 // check first < second
436 arguments.add(intAttr1);
437 arguments.add(intAttr2);
438 res = fd.evaluate(null, arguments);
439 assertTrue(res.isOk());
440 resValue = (Boolean)res.getValue().getValue();
441 assertFalse(resValue);
445 arguments.add(intAttr1);
446 arguments.add(intAttrNeg1);
447 res = fd.evaluate(null, arguments);
448 assertTrue(res.isOk());
449 resValue = (Boolean)res.getValue().getValue();
450 assertTrue(resValue);
454 public void testInteger_LT() {
456 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_LESS_THAN;
458 // check identity and type of the thing created
459 assertEquals(XACML3.ID_FUNCTION_INTEGER_LESS_THAN, fd.getId());
460 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
462 // just to be safe... If tests take too long these can probably be eliminated
463 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
464 assertFalse(fd.returnsBag());
465 assertEquals(new Integer(2), fd.getNumArgs());
468 arguments.add(intAttr1);
469 arguments.add(intAttr1a);
470 ExpressionResult res = fd.evaluate(null, arguments);
471 assertTrue(res.isOk());
472 Boolean resValue = (Boolean)res.getValue().getValue();
473 assertFalse(resValue);
475 // check first < second
477 arguments.add(intAttr1);
478 arguments.add(intAttr2);
479 res = fd.evaluate(null, arguments);
480 assertTrue(res.isOk());
481 resValue = (Boolean)res.getValue().getValue();
482 assertTrue(resValue);
486 arguments.add(intAttr1);
487 arguments.add(intAttrNeg1);
488 res = fd.evaluate(null, arguments);
489 assertTrue(res.isOk());
490 resValue = (Boolean)res.getValue().getValue();
491 assertFalse(resValue);
495 public void testInteger_LTE() {
497 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_LESS_THAN_OR_EQUAL;
499 // check identity and type of the thing created
500 assertEquals(XACML3.ID_FUNCTION_INTEGER_LESS_THAN_OR_EQUAL, fd.getId());
501 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
503 // just to be safe... If tests take too long these can probably be eliminated
504 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
505 assertFalse(fd.returnsBag());
506 assertEquals(new Integer(2), fd.getNumArgs());
509 arguments.add(intAttr1);
510 arguments.add(intAttr1a);
511 ExpressionResult res = fd.evaluate(null, arguments);
512 assertTrue(res.isOk());
513 Boolean resValue = (Boolean)res.getValue().getValue();
514 assertTrue(resValue);
516 // check first < second
518 arguments.add(intAttr1);
519 arguments.add(intAttr2);
520 res = fd.evaluate(null, arguments);
521 assertTrue(res.isOk());
522 resValue = (Boolean)res.getValue().getValue();
523 assertTrue(resValue);
527 arguments.add(intAttr1);
528 arguments.add(intAttrNeg1);
529 res = fd.evaluate(null, arguments);
530 assertTrue(res.isOk());
531 resValue = (Boolean)res.getValue().getValue();
532 assertFalse(resValue);
542 public void testDouble_GT() {
544 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_GREATER_THAN;
546 // check identity and type of the thing created
547 assertEquals(XACML3.ID_FUNCTION_DOUBLE_GREATER_THAN, fd.getId());
548 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
550 // just to be safe... If tests take too long these can probably be eliminated
551 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
552 assertFalse(fd.returnsBag());
553 assertEquals(new Integer(2), fd.getNumArgs());
556 arguments.add(attr1);
557 arguments.add(attr1a);
558 ExpressionResult res = fd.evaluate(null, arguments);
559 assertTrue(res.isOk());
560 Boolean resValue = (Boolean)res.getValue().getValue();
561 assertFalse(resValue);
565 arguments.add(attr1);
566 arguments.add(attr2);
567 res = fd.evaluate(null, arguments);
568 assertTrue(res.isOk());
569 resValue = (Boolean)res.getValue().getValue();
570 assertFalse(resValue);
574 arguments.add(attr1);
575 arguments.add(attrNeg1);
576 res = fd.evaluate(null, arguments);
577 assertTrue(res.isOk());
578 resValue = (Boolean)res.getValue().getValue();
579 assertTrue(resValue);
581 // test bad args data types? Not needed?
583 arguments.add(stringAttr1);
584 arguments.add(intAttr1);
585 res = fd.evaluate(null, arguments);
586 assertFalse(res.isOk());
591 public void testDouble_GTE() {
593 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_GREATER_THAN_OR_EQUAL;
595 // check identity and type of the thing created
596 assertEquals(XACML3.ID_FUNCTION_DOUBLE_GREATER_THAN_OR_EQUAL, fd.getId());
597 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
599 // just to be safe... If tests take too long these can probably be eliminated
600 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
601 assertFalse(fd.returnsBag());
602 assertEquals(new Integer(2), fd.getNumArgs());
605 arguments.add(attr1);
606 arguments.add(attr1a);
607 ExpressionResult res = fd.evaluate(null, arguments);
608 assertTrue(res.isOk());
609 Boolean resValue = (Boolean)res.getValue().getValue();
610 assertTrue(resValue);
614 arguments.add(attr1);
615 arguments.add(attr2);
616 res = fd.evaluate(null, arguments);
617 assertTrue(res.isOk());
618 resValue = (Boolean)res.getValue().getValue();
619 assertFalse(resValue);
623 arguments.add(attr1);
624 arguments.add(attrNeg1);
625 res = fd.evaluate(null, arguments);
626 assertTrue(res.isOk());
627 resValue = (Boolean)res.getValue().getValue();
628 assertTrue(resValue);
632 public void testDouble_LT() {
634 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_LESS_THAN;
636 // check identity and type of the thing created
637 assertEquals(XACML3.ID_FUNCTION_DOUBLE_LESS_THAN, fd.getId());
638 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
640 // just to be safe... If tests take too long these can probably be eliminated
641 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
642 assertFalse(fd.returnsBag());
643 assertEquals(new Integer(2), fd.getNumArgs());
646 arguments.add(attr1);
647 arguments.add(attr1a);
648 ExpressionResult res = fd.evaluate(null, arguments);
649 assertTrue(res.isOk());
650 Boolean resValue = (Boolean)res.getValue().getValue();
651 assertFalse(resValue);
655 arguments.add(attr1);
656 arguments.add(attr2);
657 res = fd.evaluate(null, arguments);
658 assertTrue(res.isOk());
659 resValue = (Boolean)res.getValue().getValue();
660 assertTrue(resValue);
664 arguments.add(attr1);
665 arguments.add(attrNeg1);
666 res = fd.evaluate(null, arguments);
667 assertTrue(res.isOk());
668 resValue = (Boolean)res.getValue().getValue();
669 assertFalse(resValue);
673 public void testDouble_LTE() {
675 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_LESS_THAN_OR_EQUAL;
677 // check identity and type of the thing created
678 assertEquals(XACML3.ID_FUNCTION_DOUBLE_LESS_THAN_OR_EQUAL, fd.getId());
679 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
681 // just to be safe... If tests take too long these can probably be eliminated
682 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
683 assertFalse(fd.returnsBag());
684 assertEquals(new Integer(2), fd.getNumArgs());
687 arguments.add(attr1);
688 arguments.add(attr1a);
689 ExpressionResult res = fd.evaluate(null, arguments);
690 assertTrue(res.isOk());
691 Boolean resValue = (Boolean)res.getValue().getValue();
692 assertTrue(resValue);
696 arguments.add(attr1);
697 arguments.add(attr2);
698 res = fd.evaluate(null, arguments);
699 assertTrue(res.isOk());
700 resValue = (Boolean)res.getValue().getValue();
701 assertTrue(resValue);
705 arguments.add(attr1);
706 arguments.add(attrNeg1);
707 res = fd.evaluate(null, arguments);
708 assertTrue(res.isOk());
709 resValue = (Boolean)res.getValue().getValue();
710 assertFalse(resValue);
720 public void testDate_GT() {
722 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_GREATER_THAN;
724 // check identity and type of the thing created
725 assertEquals(XACML3.ID_FUNCTION_DATE_GREATER_THAN, fd.getId());
726 assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId());
728 // just to be safe... If tests take too long these can probably be eliminated
729 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
730 assertFalse(fd.returnsBag());
731 assertEquals(new Integer(2), fd.getNumArgs());
734 arguments.add(attrDateToday);
735 arguments.add(attrDateSameDay);
736 ExpressionResult res = fd.evaluate(null, arguments);
737 assertTrue(res.isOk());
738 Boolean resValue = (Boolean)res.getValue().getValue();
739 assertFalse(resValue);
743 arguments.add(attrDateToday);
744 arguments.add(attrDateTommorrow);
745 res = fd.evaluate(null, arguments);
746 assertTrue(res.isOk());
747 resValue = (Boolean)res.getValue().getValue();
748 assertFalse(resValue);
752 arguments.add(attrDateToday);
753 arguments.add(attrDateYesterday);
754 res = fd.evaluate(null, arguments);
755 assertTrue(res.isOk());
756 resValue = (Boolean)res.getValue().getValue();
757 assertTrue(resValue);
759 // test bad args data types? One with TimeZone and one without
761 arguments.add(stringAttr1);
762 arguments.add(intAttr1);
763 res = fd.evaluate(null, arguments);
764 assertFalse(res.isOk());
766 // test with TimeZone vs without
768 arguments.add(attrDateWithTimeZone);
769 arguments.add(attrDateNoTimeZone);
770 res = fd.evaluate(null, arguments);
771 assertFalse(res.isOk());
772 assertEquals("function:date-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage());
773 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
779 public void testDate_GTE() {
781 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_GREATER_THAN_OR_EQUAL;
783 // check identity and type of the thing created
784 assertEquals(XACML3.ID_FUNCTION_DATE_GREATER_THAN_OR_EQUAL, fd.getId());
785 assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId());
787 // just to be safe... If tests take too long these can probably be eliminated
788 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
789 assertFalse(fd.returnsBag());
790 assertEquals(new Integer(2), fd.getNumArgs());
793 arguments.add(attrDateToday);
794 arguments.add(attrDateSameDay);
795 ExpressionResult res = fd.evaluate(null, arguments);
796 assertTrue(res.isOk());
797 Boolean resValue = (Boolean)res.getValue().getValue();
798 assertTrue(resValue);
802 arguments.add(attrDateToday);
803 arguments.add(attrDateTommorrow);
804 res = fd.evaluate(null, arguments);
805 assertTrue(res.isOk());
806 resValue = (Boolean)res.getValue().getValue();
807 assertFalse(resValue);
811 arguments.add(attrDateToday);
812 arguments.add(attrDateYesterday);
813 res = fd.evaluate(null, arguments);
814 assertTrue(res.isOk());
815 resValue = (Boolean)res.getValue().getValue();
816 assertTrue(resValue);
820 public void testDate_LT() {
822 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_LESS_THAN;
824 // check identity and type of the thing created
825 assertEquals(XACML3.ID_FUNCTION_DATE_LESS_THAN, fd.getId());
826 assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId());
828 // just to be safe... If tests take too long these can probably be eliminated
829 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
830 assertFalse(fd.returnsBag());
831 assertEquals(new Integer(2), fd.getNumArgs());
834 arguments.add(attrDateToday);
835 arguments.add(attrDateSameDay);
836 ExpressionResult res = fd.evaluate(null, arguments);
837 assertTrue(res.isOk());
838 Boolean resValue = (Boolean)res.getValue().getValue();
839 assertFalse(resValue);
843 arguments.add(attrDateToday);
844 arguments.add(attrDateTommorrow);
845 res = fd.evaluate(null, arguments);
846 assertTrue(res.isOk());
847 resValue = (Boolean)res.getValue().getValue();
848 assertTrue(resValue);
852 arguments.add(attrDateToday);
853 arguments.add(attrDateYesterday);
854 res = fd.evaluate(null, arguments);
855 assertTrue(res.isOk());
856 resValue = (Boolean)res.getValue().getValue();
857 assertFalse(resValue);
861 public void testDate_LTE() {
863 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_LESS_THAN_OR_EQUAL;
865 // check identity and type of the thing created
866 assertEquals(XACML3.ID_FUNCTION_DATE_LESS_THAN_OR_EQUAL, fd.getId());
867 assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId());
869 // just to be safe... If tests take too long these can probably be eliminated
870 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
871 assertFalse(fd.returnsBag());
872 assertEquals(new Integer(2), fd.getNumArgs());
875 arguments.add(attrDateToday);
876 arguments.add(attrDateSameDay);
877 ExpressionResult res = fd.evaluate(null, arguments);
878 assertTrue(res.isOk());
879 Boolean resValue = (Boolean)res.getValue().getValue();
880 assertTrue(resValue);
884 arguments.add(attrDateToday);
885 arguments.add(attrDateTommorrow);
886 res = fd.evaluate(null, arguments);
887 assertTrue(res.isOk());
888 resValue = (Boolean)res.getValue().getValue();
889 assertTrue(resValue);
893 arguments.add(attrDateToday);
894 arguments.add(attrDateYesterday);
895 res = fd.evaluate(null, arguments);
896 assertTrue(res.isOk());
897 resValue = (Boolean)res.getValue().getValue();
898 assertFalse(resValue);
912 public void testTime_GT() {
914 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_GREATER_THAN;
916 // check identity and type of the thing created
917 assertEquals(XACML3.ID_FUNCTION_TIME_GREATER_THAN, fd.getId());
918 assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId());
920 // just to be safe... If tests take too long these can probably be eliminated
921 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
922 assertFalse(fd.returnsBag());
923 assertEquals(new Integer(2), fd.getNumArgs());
926 arguments.add(attrTimeToday);
927 arguments.add(attrTimeSameDay);
928 ExpressionResult res = fd.evaluate(null, arguments);
929 assertTrue(res.isOk());
930 Boolean resValue = (Boolean)res.getValue().getValue();
931 assertFalse(resValue);
935 arguments.add(attrTimeToday);
936 arguments.add(attrTimeTommorrow);
937 res = fd.evaluate(null, arguments);
938 assertTrue(res.isOk());
939 resValue = (Boolean)res.getValue().getValue();
940 assertFalse(resValue);
944 arguments.add(attrTimeToday);
945 arguments.add(attrTimeYesterday);
946 res = fd.evaluate(null, arguments);
947 assertTrue(res.isOk());
948 resValue = (Boolean)res.getValue().getValue();
949 assertTrue(resValue);
951 // test bad args data types? One with TimeZone and one without
953 arguments.add(stringAttr1);
954 arguments.add(intAttr1);
955 res = fd.evaluate(null, arguments);
956 assertFalse(res.isOk());
958 // test with TimeZone vs without
960 arguments.add(attrTimeWithTimeZone);
961 arguments.add(attrTimeNoTimeZone);
962 res = fd.evaluate(null, arguments);
963 assertFalse(res.isOk());
964 assertEquals("function:time-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage());
965 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
971 public void testTime_GTE() {
973 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_GREATER_THAN_OR_EQUAL;
975 // check identity and type of the thing created
976 assertEquals(XACML3.ID_FUNCTION_TIME_GREATER_THAN_OR_EQUAL, fd.getId());
977 assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId());
979 // just to be safe... If tests take too long these can probably be eliminated
980 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
981 assertFalse(fd.returnsBag());
982 assertEquals(new Integer(2), fd.getNumArgs());
985 arguments.add(attrTimeToday);
986 arguments.add(attrTimeSameDay);
987 ExpressionResult res = fd.evaluate(null, arguments);
988 assertTrue(res.isOk());
989 Boolean resValue = (Boolean)res.getValue().getValue();
990 assertTrue(resValue);
994 arguments.add(attrTimeToday);
995 arguments.add(attrTimeTommorrow);
996 res = fd.evaluate(null, arguments);
997 assertTrue(res.isOk());
998 resValue = (Boolean)res.getValue().getValue();
999 assertFalse(resValue);
1003 arguments.add(attrTimeToday);
1004 arguments.add(attrTimeYesterday);
1005 res = fd.evaluate(null, arguments);
1006 assertTrue(res.isOk());
1007 resValue = (Boolean)res.getValue().getValue();
1008 assertTrue(resValue);
1012 public void testTime_LT() {
1014 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_LESS_THAN;
1016 // check identity and type of the thing created
1017 assertEquals(XACML3.ID_FUNCTION_TIME_LESS_THAN, fd.getId());
1018 assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId());
1020 // just to be safe... If tests take too long these can probably be eliminated
1021 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1022 assertFalse(fd.returnsBag());
1023 assertEquals(new Integer(2), fd.getNumArgs());
1026 arguments.add(attrTimeToday);
1027 arguments.add(attrTimeSameDay);
1028 ExpressionResult res = fd.evaluate(null, arguments);
1029 assertTrue(res.isOk());
1030 Boolean resValue = (Boolean)res.getValue().getValue();
1031 assertFalse(resValue);
1035 arguments.add(attrTimeToday);
1036 arguments.add(attrTimeTommorrow);
1037 res = fd.evaluate(null, arguments);
1038 assertTrue(res.isOk());
1039 resValue = (Boolean)res.getValue().getValue();
1040 assertTrue(resValue);
1044 arguments.add(attrTimeToday);
1045 arguments.add(attrTimeYesterday);
1046 res = fd.evaluate(null, arguments);
1047 assertTrue(res.isOk());
1048 resValue = (Boolean)res.getValue().getValue();
1049 assertFalse(resValue);
1053 public void testTime_LTE() {
1055 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_LESS_THAN_OR_EQUAL;
1057 // check identity and type of the thing created
1058 assertEquals(XACML3.ID_FUNCTION_TIME_LESS_THAN_OR_EQUAL, fd.getId());
1059 assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId());
1061 // just to be safe... If tests take too long these can probably be eliminated
1062 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1063 assertFalse(fd.returnsBag());
1064 assertEquals(new Integer(2), fd.getNumArgs());
1067 arguments.add(attrTimeToday);
1068 arguments.add(attrTimeSameDay);
1069 ExpressionResult res = fd.evaluate(null, arguments);
1070 assertTrue(res.isOk());
1071 Boolean resValue = (Boolean)res.getValue().getValue();
1072 assertTrue(resValue);
1076 arguments.add(attrTimeToday);
1077 arguments.add(attrTimeTommorrow);
1078 res = fd.evaluate(null, arguments);
1079 assertTrue(res.isOk());
1080 resValue = (Boolean)res.getValue().getValue();
1081 assertTrue(resValue);
1085 arguments.add(attrTimeToday);
1086 arguments.add(attrTimeYesterday);
1087 res = fd.evaluate(null, arguments);
1088 assertTrue(res.isOk());
1089 resValue = (Boolean)res.getValue().getValue();
1090 assertFalse(resValue);
1101 public void testTime_in_range() {
1103 FunctionDefinitionTimeInRange<?> fd = (FunctionDefinitionTimeInRange<?>) StdFunctions.FD_TIME_IN_RANGE;
1105 // check identity and type of the thing created
1106 assertEquals(XACML3.ID_FUNCTION_TIME_IN_RANGE, fd.getId());
1107 assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId());
1109 // just to be safe... If tests take too long these can probably be eliminated
1110 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1111 assertFalse(fd.returnsBag());
1112 assertEquals(new Integer(3), fd.getNumArgs());
1114 // arg 0 in range of others
1115 arguments.add(attrTimeToday);
1116 arguments.add(attrTimeYesterday);
1117 arguments.add(attrTimeTommorrow);
1118 ExpressionResult res = fd.evaluate(null, arguments);
1119 assertTrue(res.isOk());
1120 Boolean resValue = (Boolean)res.getValue().getValue();
1121 assertTrue(resValue);
1125 arguments.add(attrTimeYesterday);
1126 arguments.add(attrTimeToday);
1127 arguments.add(attrTimeTommorrow);
1128 res = fd.evaluate(null, arguments);
1129 assertTrue(res.isOk());
1130 resValue = (Boolean)res.getValue().getValue();
1131 assertFalse(resValue);
1135 arguments.add(attrTimeTommorrow);
1136 arguments.add(attrTimeYesterday);
1137 arguments.add(attrTimeToday);
1138 res = fd.evaluate(null, arguments);
1139 assertTrue(res.isOk());
1140 resValue = (Boolean)res.getValue().getValue();
1141 assertFalse(resValue);
1145 arguments.add(attrTimeToday);
1146 arguments.add(attrTimeTommorrow);
1147 arguments.add(attrTimeYesterday);
1148 res = fd.evaluate(null, arguments);
1149 assertTrue(res.isOk());
1150 resValue = (Boolean)res.getValue().getValue();
1151 assertFalse(resValue);
1155 arguments.add(attrDateTimeWithTimeZone);
1156 arguments.add(attrDateTimeNoTimeZone);
1157 res = fd.evaluate(null, arguments);
1158 assertFalse(res.isOk());
1159 assertEquals("function:time-in-range Expected 3 arguments, got 2", res.getStatus().getStatusMessage());
1160 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
1163 arguments.add(attrDateTimeWithTimeZone);
1164 arguments.add(attrDateTimeNoTimeZone);
1165 arguments.add(intAttr1);
1166 res = fd.evaluate(null, arguments);
1167 assertFalse(res.isOk());
1168 assertEquals("function:time-in-range Expected data type 'time' saw 'dateTime' at arg index 0", res.getStatus().getStatusMessage());
1169 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
1183 public void testDateTime_GT() {
1185 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_GREATER_THAN;
1187 // check identity and type of the thing created
1188 assertEquals(XACML3.ID_FUNCTION_DATETIME_GREATER_THAN, fd.getId());
1189 assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId());
1191 // just to be safe... If tests take too long these can probably be eliminated
1192 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1193 assertFalse(fd.returnsBag());
1194 assertEquals(new Integer(2), fd.getNumArgs());
1197 arguments.add(attrDateTimeToday);
1198 arguments.add(attrDateTimeSameDay);
1199 ExpressionResult res = fd.evaluate(null, arguments);
1200 assertTrue(res.isOk());
1201 Boolean resValue = (Boolean)res.getValue().getValue();
1202 assertFalse(resValue);
1206 arguments.add(attrDateTimeToday);
1207 arguments.add(attrDateTimeTommorrow);
1208 res = fd.evaluate(null, arguments);
1209 assertTrue(res.isOk());
1210 resValue = (Boolean)res.getValue().getValue();
1211 assertFalse(resValue);
1215 arguments.add(attrDateTimeToday);
1216 arguments.add(attrDateTimeYesterday);
1217 res = fd.evaluate(null, arguments);
1218 assertTrue(res.isOk());
1219 resValue = (Boolean)res.getValue().getValue();
1220 assertTrue(resValue);
1222 // test bad args data types? One with TimeZone and one without
1224 arguments.add(stringAttr1);
1225 arguments.add(intAttr1);
1226 res = fd.evaluate(null, arguments);
1227 assertFalse(res.isOk());
1229 // test with TimeZone vs without
1231 arguments.add(attrDateTimeWithTimeZone);
1232 arguments.add(attrDateTimeNoTimeZone);
1233 res = fd.evaluate(null, arguments);
1234 assertFalse(res.isOk());
1235 assertEquals("function:dateTime-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage());
1236 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
1242 public void testDateTime_GTE() {
1244 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_GREATER_THAN_OR_EQUAL;
1246 // check identity and type of the thing created
1247 assertEquals(XACML3.ID_FUNCTION_DATETIME_GREATER_THAN_OR_EQUAL, fd.getId());
1248 assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId());
1250 // just to be safe... If tests take too long these can probably be eliminated
1251 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1252 assertFalse(fd.returnsBag());
1253 assertEquals(new Integer(2), fd.getNumArgs());
1256 arguments.add(attrDateTimeToday);
1257 arguments.add(attrDateTimeSameDay);
1258 ExpressionResult res = fd.evaluate(null, arguments);
1259 assertTrue(res.isOk());
1260 Boolean resValue = (Boolean)res.getValue().getValue();
1261 assertTrue(resValue);
1265 arguments.add(attrDateTimeToday);
1266 arguments.add(attrDateTimeTommorrow);
1267 res = fd.evaluate(null, arguments);
1268 assertTrue(res.isOk());
1269 resValue = (Boolean)res.getValue().getValue();
1270 assertFalse(resValue);
1274 arguments.add(attrDateTimeToday);
1275 arguments.add(attrDateTimeYesterday);
1276 res = fd.evaluate(null, arguments);
1277 assertTrue(res.isOk());
1278 resValue = (Boolean)res.getValue().getValue();
1279 assertTrue(resValue);
1283 public void testDateTime_LT() {
1285 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_LESS_THAN;
1287 // check identity and type of the thing created
1288 assertEquals(XACML3.ID_FUNCTION_DATETIME_LESS_THAN, fd.getId());
1289 assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId());
1291 // just to be safe... If tests take too long these can probably be eliminated
1292 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1293 assertFalse(fd.returnsBag());
1294 assertEquals(new Integer(2), fd.getNumArgs());
1297 arguments.add(attrDateTimeToday);
1298 arguments.add(attrDateTimeSameDay);
1299 ExpressionResult res = fd.evaluate(null, arguments);
1300 assertTrue(res.isOk());
1301 Boolean resValue = (Boolean)res.getValue().getValue();
1302 assertFalse(resValue);
1306 arguments.add(attrDateTimeToday);
1307 arguments.add(attrDateTimeTommorrow);
1308 res = fd.evaluate(null, arguments);
1309 assertTrue(res.isOk());
1310 resValue = (Boolean)res.getValue().getValue();
1311 assertTrue(resValue);
1315 arguments.add(attrDateTimeToday);
1316 arguments.add(attrDateTimeYesterday);
1317 res = fd.evaluate(null, arguments);
1318 assertTrue(res.isOk());
1319 resValue = (Boolean)res.getValue().getValue();
1320 assertFalse(resValue);
1324 public void testDateTime_LTE() {
1326 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_LESS_THAN_OR_EQUAL;
1328 // check identity and type of the thing created
1329 assertEquals(XACML3.ID_FUNCTION_DATETIME_LESS_THAN_OR_EQUAL, fd.getId());
1330 assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId());
1332 // just to be safe... If tests take too long these can probably be eliminated
1333 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1334 assertFalse(fd.returnsBag());
1335 assertEquals(new Integer(2), fd.getNumArgs());
1338 arguments.add(attrDateTimeToday);
1339 arguments.add(attrDateTimeSameDay);
1340 ExpressionResult res = fd.evaluate(null, arguments);
1341 assertTrue(res.isOk());
1342 Boolean resValue = (Boolean)res.getValue().getValue();
1343 assertTrue(resValue);
1347 arguments.add(attrDateTimeToday);
1348 arguments.add(attrDateTimeTommorrow);
1349 res = fd.evaluate(null, arguments);
1350 assertTrue(res.isOk());
1351 resValue = (Boolean)res.getValue().getValue();
1352 assertTrue(resValue);
1356 arguments.add(attrDateTimeToday);
1357 arguments.add(attrDateTimeYesterday);
1358 res = fd.evaluate(null, arguments);
1359 assertTrue(res.isOk());
1360 resValue = (Boolean)res.getValue().getValue();
1361 assertFalse(resValue);