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.std.functions;
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.FunctionDefinitionComparison;
45 import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionTimeInRange;
48 * Test FunctionDefinitionComparison
51 * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
55 public class FunctionDefinitionComparisonTest {
58 * variables useful in the following tests
60 List<FunctionArgument> arguments = new ArrayList<FunctionArgument>();
62 FunctionArgumentAttributeValue stringAttr1 = null;
63 FunctionArgumentAttributeValue stringAttr1a = null;
64 FunctionArgumentAttributeValue stringAttr2 = null;
65 FunctionArgumentAttributeValue stringAttrNeg1 = null;
68 FunctionArgumentAttributeValue intAttr1 = null;
69 FunctionArgumentAttributeValue intAttr1a = null;
70 FunctionArgumentAttributeValue intAttr2 = null;
71 FunctionArgumentAttributeValue intAttr0 = null;
72 FunctionArgumentAttributeValue intAttrNeg1 = null;
74 FunctionArgumentAttributeValue attr1 = null;
75 FunctionArgumentAttributeValue attr1a = null;
76 FunctionArgumentAttributeValue attr2 = null;
77 FunctionArgumentAttributeValue attrNeg1 = null;
79 FunctionArgumentAttributeValue attrDateToday = null;
80 FunctionArgumentAttributeValue attrDateSameDay = null;
81 FunctionArgumentAttributeValue attrDateTommorrow = null;
82 FunctionArgumentAttributeValue attrDateYesterday = null;
83 FunctionArgumentAttributeValue attrDateWithTimeZone = null;
84 FunctionArgumentAttributeValue attrDateNoTimeZone = null;
87 FunctionArgumentAttributeValue attrTimeToday = null;
88 FunctionArgumentAttributeValue attrTimeSameDay = null;
89 FunctionArgumentAttributeValue attrTimeTommorrow = null;
90 FunctionArgumentAttributeValue attrTimeYesterday = null;
91 FunctionArgumentAttributeValue attrTimeWithTimeZone = null;
92 FunctionArgumentAttributeValue attrTimeNoTimeZone = null;
94 FunctionArgumentAttributeValue attrDateTimeToday = null;
95 FunctionArgumentAttributeValue attrDateTimeSameDay = null;
96 FunctionArgumentAttributeValue attrDateTimeTommorrow = null;
97 FunctionArgumentAttributeValue attrDateTimeYesterday = null;
98 FunctionArgumentAttributeValue attrDateTimeWithTimeZone = null;
99 FunctionArgumentAttributeValue attrDateTimeNoTimeZone = null;
102 * Set up some common variables on startup
104 public FunctionDefinitionComparisonTest() {
106 stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc"));
107 stringAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc"));
108 stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def"));
109 stringAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("AAA"));
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));
118 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0));
119 attr1a = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.0));
120 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.4));
121 attrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-1.0));
124 Calendar calendar = Calendar.getInstance();
125 Date today = calendar.getTime();
126 Date longAgo = new Date(1234);
127 // create a date that is different than "today" but within the same day (i.e. has a different hour)
128 if (calendar.get(Calendar.HOUR_OF_DAY) > 3) {
129 calendar.set(Calendar.HOUR_OF_DAY, 3);
131 calendar.set(Calendar.HOUR_OF_DAY, 5);
133 Date todayPlus = calendar.getTime();
134 calendar.add(Calendar.DATE, 1);
135 Date tommorrow = calendar.getTime();
136 attrDateToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(today));
137 attrDateSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(todayPlus));
138 attrDateTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(tommorrow));
139 attrDateYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(longAgo));
140 ISO8601Date isoDate = new ISO8601Date(1920, 5, 8);
141 attrDateNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(isoDate));
142 isoDate = new ISO8601Date("GMT+00:02", 1920, 5, 8);
143 attrDateWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATE.createAttributeValue(isoDate));
146 ISO8601Time isoTime = new ISO8601Time(14, 43, 12, 145);
147 attrTimeToday = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime));
148 attrTimeSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime));
149 isoTime = new ISO8601Time(18, 53, 34, 423);
150 attrTimeTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime));
151 isoTime = new ISO8601Time(7, 34, 6,543);
152 attrTimeYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime));
153 isoTime = new ISO8601Time(12, 12, 12, 12);
154 attrTimeNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime));
155 isoTime = new ISO8601Time("GMT:+00:03", 12, 12, 12, 12);
156 attrTimeWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_TIME.createAttributeValue(isoTime));
159 isoDate = new ISO8601Date(1920, 5, 8);
160 isoTime = new ISO8601Time( 18, 53, 34, 423);
161 ISO8601DateTime isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 18, 53, 34, 423);
162 attrDateTimeToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime));
163 attrDateTimeSameDay = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime));
164 isoTime = new ISO8601Time(20, 53, 34, 423);
165 isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 20, 53, 34, 423);
166 attrDateTimeTommorrow = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime));
167 isoTime = new ISO8601Time(7, 34, 6,543);
168 isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 7, 34, 6, 543);
169 attrDateTimeYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime));
170 isoTime = new ISO8601Time(12, 12, 12, 12);
171 isoDateTime = new ISO8601DateTime((String)null, 1920, 5, 8, 12, 12, 12, 12);
172 attrDateTimeNoTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime));
173 isoTime = new ISO8601Time("GMT:+00:03", 12, 12, 12, 12);
174 isoDate = new ISO8601Date("GMT:+00:03", 1920, 5, 8);
175 isoDateTime = new ISO8601DateTime("GMT:+00:03", 1920, 5, 8, 12, 12, 12, 12);
176 attrDateTimeWithTimeZone = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(isoDateTime));
181 } catch (Exception e) {
182 fail("Error creating values e="+ e);
190 public void testString_GT() {
192 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_GREATER_THAN;
194 // check identity and type of the thing created
195 assertEquals(XACML3.ID_FUNCTION_STRING_GREATER_THAN, fd.getId());
196 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
198 // just to be safe... If tests take too long these can probably be eliminated
199 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
200 assertFalse(fd.returnsBag());
201 assertEquals(new Integer(2), fd.getNumArgs());
204 arguments.add(stringAttr1);
205 arguments.add(stringAttr1a);
206 ExpressionResult res = fd.evaluate(null, arguments);
207 assertTrue(res.isOk());
208 Boolean resValue = (Boolean)res.getValue().getValue();
209 assertFalse(resValue);
211 // check first < second
213 arguments.add(stringAttr1);
214 arguments.add(stringAttr2);
215 res = fd.evaluate(null, arguments);
216 assertTrue(res.isOk());
217 resValue = (Boolean)res.getValue().getValue();
218 assertFalse(resValue);
222 arguments.add(stringAttr1);
223 arguments.add(stringAttrNeg1);
224 res = fd.evaluate(null, arguments);
225 assertTrue(res.isOk());
226 resValue = (Boolean)res.getValue().getValue();
227 assertTrue(resValue);
229 // test bad args data types? Not needed?
231 arguments.add(intAttr1);
232 arguments.add(stringAttr1);
233 res = fd.evaluate(null, arguments);
234 assertFalse(res.isOk());
238 public void testString_GTE() {
240 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_GREATER_THAN_OR_EQUAL;
242 // check identity and type of the thing created
243 assertEquals(XACML3.ID_FUNCTION_STRING_GREATER_THAN_OR_EQUAL, fd.getId());
244 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
246 // just to be safe... If tests take too long these can probably be eliminated
247 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
248 assertFalse(fd.returnsBag());
249 assertEquals(new Integer(2), fd.getNumArgs());
252 arguments.add(stringAttr1);
253 arguments.add(stringAttr1a);
254 ExpressionResult res = fd.evaluate(null, arguments);
255 assertTrue(res.isOk());
256 Boolean resValue = (Boolean)res.getValue().getValue();
257 assertTrue(resValue);
259 // check first < second
261 arguments.add(stringAttr1);
262 arguments.add(stringAttr2);
263 res = fd.evaluate(null, arguments);
264 assertTrue(res.isOk());
265 resValue = (Boolean)res.getValue().getValue();
266 assertFalse(resValue);
270 arguments.add(stringAttr1);
271 arguments.add(stringAttrNeg1);
272 res = fd.evaluate(null, arguments);
273 assertTrue(res.isOk());
274 resValue = (Boolean)res.getValue().getValue();
275 assertTrue(resValue);
279 public void testString_LT() {
281 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_LESS_THAN;
283 // check identity and type of the thing created
284 assertEquals(XACML3.ID_FUNCTION_STRING_LESS_THAN, fd.getId());
285 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
287 // just to be safe... If tests take too long these can probably be eliminated
288 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
289 assertFalse(fd.returnsBag());
290 assertEquals(new Integer(2), fd.getNumArgs());
293 arguments.add(stringAttr1);
294 arguments.add(stringAttr1a);
295 ExpressionResult res = fd.evaluate(null, arguments);
296 assertTrue(res.isOk());
297 Boolean resValue = (Boolean)res.getValue().getValue();
298 assertFalse(resValue);
300 // check first < second
302 arguments.add(stringAttr1);
303 arguments.add(stringAttr2);
304 res = fd.evaluate(null, arguments);
305 assertTrue(res.isOk());
306 resValue = (Boolean)res.getValue().getValue();
307 assertTrue(resValue);
311 arguments.add(stringAttr1);
312 arguments.add(stringAttrNeg1);
313 res = fd.evaluate(null, arguments);
314 assertTrue(res.isOk());
315 resValue = (Boolean)res.getValue().getValue();
316 assertFalse(resValue);
320 public void testString_LTE() {
322 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_LESS_THAN_OR_EQUAL;
324 // check identity and type of the thing created
325 assertEquals(XACML3.ID_FUNCTION_STRING_LESS_THAN_OR_EQUAL, fd.getId());
326 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
328 // just to be safe... If tests take too long these can probably be eliminated
329 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
330 assertFalse(fd.returnsBag());
331 assertEquals(new Integer(2), fd.getNumArgs());
334 arguments.add(stringAttr1);
335 arguments.add(stringAttr1a);
336 ExpressionResult res = fd.evaluate(null, arguments);
337 assertTrue(res.isOk());
338 Boolean resValue = (Boolean)res.getValue().getValue();
339 assertTrue(resValue);
341 // check first < second
343 arguments.add(stringAttr1);
344 arguments.add(stringAttr2);
345 res = fd.evaluate(null, arguments);
346 assertTrue(res.isOk());
347 resValue = (Boolean)res.getValue().getValue();
348 assertTrue(resValue);
352 arguments.add(stringAttr1);
353 arguments.add(stringAttrNeg1);
354 res = fd.evaluate(null, arguments);
355 assertTrue(res.isOk());
356 resValue = (Boolean)res.getValue().getValue();
357 assertFalse(resValue);
366 public void testInteger_GT() {
368 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_GREATER_THAN;
370 // check identity and type of the thing created
371 assertEquals(XACML3.ID_FUNCTION_INTEGER_GREATER_THAN, fd.getId());
372 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
374 // just to be safe... If tests take too long these can probably be eliminated
375 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
376 assertFalse(fd.returnsBag());
377 assertEquals(new Integer(2), fd.getNumArgs());
380 arguments.add(intAttr1);
381 arguments.add(intAttr1a);
382 ExpressionResult res = fd.evaluate(null, arguments);
383 assertTrue(res.isOk());
384 Boolean resValue = (Boolean)res.getValue().getValue();
385 assertFalse(resValue);
387 // check first < second
389 arguments.add(intAttr1);
390 arguments.add(intAttr2);
391 res = fd.evaluate(null, arguments);
392 assertTrue(res.isOk());
393 resValue = (Boolean)res.getValue().getValue();
394 assertFalse(resValue);
398 arguments.add(intAttr1);
399 arguments.add(intAttrNeg1);
400 res = fd.evaluate(null, arguments);
401 assertTrue(res.isOk());
402 resValue = (Boolean)res.getValue().getValue();
403 assertTrue(resValue);
405 // test bad args data types? Not needed?
407 arguments.add(stringAttr1);
408 arguments.add(intAttr1);
409 res = fd.evaluate(null, arguments);
410 assertFalse(res.isOk());
414 public void testInteger_GTE() {
416 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_GREATER_THAN_OR_EQUAL;
418 // check identity and type of the thing created
419 assertEquals(XACML3.ID_FUNCTION_INTEGER_GREATER_THAN_OR_EQUAL, fd.getId());
420 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
422 // just to be safe... If tests take too long these can probably be eliminated
423 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
424 assertFalse(fd.returnsBag());
425 assertEquals(new Integer(2), fd.getNumArgs());
428 arguments.add(intAttr1);
429 arguments.add(intAttr1a);
430 ExpressionResult res = fd.evaluate(null, arguments);
431 assertTrue(res.isOk());
432 Boolean resValue = (Boolean)res.getValue().getValue();
433 assertTrue(resValue);
435 // check first < second
437 arguments.add(intAttr1);
438 arguments.add(intAttr2);
439 res = fd.evaluate(null, arguments);
440 assertTrue(res.isOk());
441 resValue = (Boolean)res.getValue().getValue();
442 assertFalse(resValue);
446 arguments.add(intAttr1);
447 arguments.add(intAttrNeg1);
448 res = fd.evaluate(null, arguments);
449 assertTrue(res.isOk());
450 resValue = (Boolean)res.getValue().getValue();
451 assertTrue(resValue);
455 public void testInteger_LT() {
457 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_LESS_THAN;
459 // check identity and type of the thing created
460 assertEquals(XACML3.ID_FUNCTION_INTEGER_LESS_THAN, fd.getId());
461 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
463 // just to be safe... If tests take too long these can probably be eliminated
464 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
465 assertFalse(fd.returnsBag());
466 assertEquals(new Integer(2), fd.getNumArgs());
469 arguments.add(intAttr1);
470 arguments.add(intAttr1a);
471 ExpressionResult res = fd.evaluate(null, arguments);
472 assertTrue(res.isOk());
473 Boolean resValue = (Boolean)res.getValue().getValue();
474 assertFalse(resValue);
476 // check first < second
478 arguments.add(intAttr1);
479 arguments.add(intAttr2);
480 res = fd.evaluate(null, arguments);
481 assertTrue(res.isOk());
482 resValue = (Boolean)res.getValue().getValue();
483 assertTrue(resValue);
487 arguments.add(intAttr1);
488 arguments.add(intAttrNeg1);
489 res = fd.evaluate(null, arguments);
490 assertTrue(res.isOk());
491 resValue = (Boolean)res.getValue().getValue();
492 assertFalse(resValue);
496 public void testInteger_LTE() {
498 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_LESS_THAN_OR_EQUAL;
500 // check identity and type of the thing created
501 assertEquals(XACML3.ID_FUNCTION_INTEGER_LESS_THAN_OR_EQUAL, fd.getId());
502 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
504 // just to be safe... If tests take too long these can probably be eliminated
505 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
506 assertFalse(fd.returnsBag());
507 assertEquals(new Integer(2), fd.getNumArgs());
510 arguments.add(intAttr1);
511 arguments.add(intAttr1a);
512 ExpressionResult res = fd.evaluate(null, arguments);
513 assertTrue(res.isOk());
514 Boolean resValue = (Boolean)res.getValue().getValue();
515 assertTrue(resValue);
517 // check first < second
519 arguments.add(intAttr1);
520 arguments.add(intAttr2);
521 res = fd.evaluate(null, arguments);
522 assertTrue(res.isOk());
523 resValue = (Boolean)res.getValue().getValue();
524 assertTrue(resValue);
528 arguments.add(intAttr1);
529 arguments.add(intAttrNeg1);
530 res = fd.evaluate(null, arguments);
531 assertTrue(res.isOk());
532 resValue = (Boolean)res.getValue().getValue();
533 assertFalse(resValue);
543 public void testDouble_GT() {
545 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_GREATER_THAN;
547 // check identity and type of the thing created
548 assertEquals(XACML3.ID_FUNCTION_DOUBLE_GREATER_THAN, fd.getId());
549 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
551 // just to be safe... If tests take too long these can probably be eliminated
552 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
553 assertFalse(fd.returnsBag());
554 assertEquals(new Integer(2), fd.getNumArgs());
557 arguments.add(attr1);
558 arguments.add(attr1a);
559 ExpressionResult res = fd.evaluate(null, arguments);
560 assertTrue(res.isOk());
561 Boolean resValue = (Boolean)res.getValue().getValue();
562 assertFalse(resValue);
566 arguments.add(attr1);
567 arguments.add(attr2);
568 res = fd.evaluate(null, arguments);
569 assertTrue(res.isOk());
570 resValue = (Boolean)res.getValue().getValue();
571 assertFalse(resValue);
575 arguments.add(attr1);
576 arguments.add(attrNeg1);
577 res = fd.evaluate(null, arguments);
578 assertTrue(res.isOk());
579 resValue = (Boolean)res.getValue().getValue();
580 assertTrue(resValue);
582 // test bad args data types? Not needed?
584 arguments.add(stringAttr1);
585 arguments.add(intAttr1);
586 res = fd.evaluate(null, arguments);
587 assertFalse(res.isOk());
592 public void testDouble_GTE() {
594 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_GREATER_THAN_OR_EQUAL;
596 // check identity and type of the thing created
597 assertEquals(XACML3.ID_FUNCTION_DOUBLE_GREATER_THAN_OR_EQUAL, fd.getId());
598 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
600 // just to be safe... If tests take too long these can probably be eliminated
601 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
602 assertFalse(fd.returnsBag());
603 assertEquals(new Integer(2), fd.getNumArgs());
606 arguments.add(attr1);
607 arguments.add(attr1a);
608 ExpressionResult res = fd.evaluate(null, arguments);
609 assertTrue(res.isOk());
610 Boolean resValue = (Boolean)res.getValue().getValue();
611 assertTrue(resValue);
615 arguments.add(attr1);
616 arguments.add(attr2);
617 res = fd.evaluate(null, arguments);
618 assertTrue(res.isOk());
619 resValue = (Boolean)res.getValue().getValue();
620 assertFalse(resValue);
624 arguments.add(attr1);
625 arguments.add(attrNeg1);
626 res = fd.evaluate(null, arguments);
627 assertTrue(res.isOk());
628 resValue = (Boolean)res.getValue().getValue();
629 assertTrue(resValue);
633 public void testDouble_LT() {
635 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_LESS_THAN;
637 // check identity and type of the thing created
638 assertEquals(XACML3.ID_FUNCTION_DOUBLE_LESS_THAN, fd.getId());
639 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
641 // just to be safe... If tests take too long these can probably be eliminated
642 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
643 assertFalse(fd.returnsBag());
644 assertEquals(new Integer(2), fd.getNumArgs());
647 arguments.add(attr1);
648 arguments.add(attr1a);
649 ExpressionResult res = fd.evaluate(null, arguments);
650 assertTrue(res.isOk());
651 Boolean resValue = (Boolean)res.getValue().getValue();
652 assertFalse(resValue);
656 arguments.add(attr1);
657 arguments.add(attr2);
658 res = fd.evaluate(null, arguments);
659 assertTrue(res.isOk());
660 resValue = (Boolean)res.getValue().getValue();
661 assertTrue(resValue);
665 arguments.add(attr1);
666 arguments.add(attrNeg1);
667 res = fd.evaluate(null, arguments);
668 assertTrue(res.isOk());
669 resValue = (Boolean)res.getValue().getValue();
670 assertFalse(resValue);
674 public void testDouble_LTE() {
676 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_LESS_THAN_OR_EQUAL;
678 // check identity and type of the thing created
679 assertEquals(XACML3.ID_FUNCTION_DOUBLE_LESS_THAN_OR_EQUAL, fd.getId());
680 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
682 // just to be safe... If tests take too long these can probably be eliminated
683 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
684 assertFalse(fd.returnsBag());
685 assertEquals(new Integer(2), fd.getNumArgs());
688 arguments.add(attr1);
689 arguments.add(attr1a);
690 ExpressionResult res = fd.evaluate(null, arguments);
691 assertTrue(res.isOk());
692 Boolean resValue = (Boolean)res.getValue().getValue();
693 assertTrue(resValue);
697 arguments.add(attr1);
698 arguments.add(attr2);
699 res = fd.evaluate(null, arguments);
700 assertTrue(res.isOk());
701 resValue = (Boolean)res.getValue().getValue();
702 assertTrue(resValue);
706 arguments.add(attr1);
707 arguments.add(attrNeg1);
708 res = fd.evaluate(null, arguments);
709 assertTrue(res.isOk());
710 resValue = (Boolean)res.getValue().getValue();
711 assertFalse(resValue);
721 public void testDate_GT() {
723 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_GREATER_THAN;
725 // check identity and type of the thing created
726 assertEquals(XACML3.ID_FUNCTION_DATE_GREATER_THAN, fd.getId());
727 assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId());
729 // just to be safe... If tests take too long these can probably be eliminated
730 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
731 assertFalse(fd.returnsBag());
732 assertEquals(new Integer(2), fd.getNumArgs());
735 arguments.add(attrDateToday);
736 arguments.add(attrDateSameDay);
737 ExpressionResult res = fd.evaluate(null, arguments);
738 assertTrue(res.isOk());
739 Boolean resValue = (Boolean)res.getValue().getValue();
740 assertFalse(resValue);
744 arguments.add(attrDateToday);
745 arguments.add(attrDateTommorrow);
746 res = fd.evaluate(null, arguments);
747 assertTrue(res.isOk());
748 resValue = (Boolean)res.getValue().getValue();
749 assertFalse(resValue);
753 arguments.add(attrDateToday);
754 arguments.add(attrDateYesterday);
755 res = fd.evaluate(null, arguments);
756 assertTrue(res.isOk());
757 resValue = (Boolean)res.getValue().getValue();
758 assertTrue(resValue);
760 // test bad args data types? One with TimeZone and one without
762 arguments.add(stringAttr1);
763 arguments.add(intAttr1);
764 res = fd.evaluate(null, arguments);
765 assertFalse(res.isOk());
767 // test with TimeZone vs without
769 arguments.add(attrDateWithTimeZone);
770 arguments.add(attrDateNoTimeZone);
771 res = fd.evaluate(null, arguments);
772 assertFalse(res.isOk());
773 assertEquals("function:date-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage());
774 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
780 public void testDate_GTE() {
782 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_GREATER_THAN_OR_EQUAL;
784 // check identity and type of the thing created
785 assertEquals(XACML3.ID_FUNCTION_DATE_GREATER_THAN_OR_EQUAL, fd.getId());
786 assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId());
788 // just to be safe... If tests take too long these can probably be eliminated
789 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
790 assertFalse(fd.returnsBag());
791 assertEquals(new Integer(2), fd.getNumArgs());
794 arguments.add(attrDateToday);
795 arguments.add(attrDateSameDay);
796 ExpressionResult res = fd.evaluate(null, arguments);
797 assertTrue(res.isOk());
798 Boolean resValue = (Boolean)res.getValue().getValue();
799 assertTrue(resValue);
803 arguments.add(attrDateToday);
804 arguments.add(attrDateTommorrow);
805 res = fd.evaluate(null, arguments);
806 assertTrue(res.isOk());
807 resValue = (Boolean)res.getValue().getValue();
808 assertFalse(resValue);
812 arguments.add(attrDateToday);
813 arguments.add(attrDateYesterday);
814 res = fd.evaluate(null, arguments);
815 assertTrue(res.isOk());
816 resValue = (Boolean)res.getValue().getValue();
817 assertTrue(resValue);
821 public void testDate_LT() {
823 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_LESS_THAN;
825 // check identity and type of the thing created
826 assertEquals(XACML3.ID_FUNCTION_DATE_LESS_THAN, fd.getId());
827 assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId());
829 // just to be safe... If tests take too long these can probably be eliminated
830 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
831 assertFalse(fd.returnsBag());
832 assertEquals(new Integer(2), fd.getNumArgs());
835 arguments.add(attrDateToday);
836 arguments.add(attrDateSameDay);
837 ExpressionResult res = fd.evaluate(null, arguments);
838 assertTrue(res.isOk());
839 Boolean resValue = (Boolean)res.getValue().getValue();
840 assertFalse(resValue);
844 arguments.add(attrDateToday);
845 arguments.add(attrDateTommorrow);
846 res = fd.evaluate(null, arguments);
847 assertTrue(res.isOk());
848 resValue = (Boolean)res.getValue().getValue();
849 assertTrue(resValue);
853 arguments.add(attrDateToday);
854 arguments.add(attrDateYesterday);
855 res = fd.evaluate(null, arguments);
856 assertTrue(res.isOk());
857 resValue = (Boolean)res.getValue().getValue();
858 assertFalse(resValue);
862 public void testDate_LTE() {
864 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_LESS_THAN_OR_EQUAL;
866 // check identity and type of the thing created
867 assertEquals(XACML3.ID_FUNCTION_DATE_LESS_THAN_OR_EQUAL, fd.getId());
868 assertEquals(DataTypes.DT_DATE.getId(), fd.getDataTypeArgs().getId());
870 // just to be safe... If tests take too long these can probably be eliminated
871 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
872 assertFalse(fd.returnsBag());
873 assertEquals(new Integer(2), fd.getNumArgs());
876 arguments.add(attrDateToday);
877 arguments.add(attrDateSameDay);
878 ExpressionResult res = fd.evaluate(null, arguments);
879 assertTrue(res.isOk());
880 Boolean resValue = (Boolean)res.getValue().getValue();
881 assertTrue(resValue);
885 arguments.add(attrDateToday);
886 arguments.add(attrDateTommorrow);
887 res = fd.evaluate(null, arguments);
888 assertTrue(res.isOk());
889 resValue = (Boolean)res.getValue().getValue();
890 assertTrue(resValue);
894 arguments.add(attrDateToday);
895 arguments.add(attrDateYesterday);
896 res = fd.evaluate(null, arguments);
897 assertTrue(res.isOk());
898 resValue = (Boolean)res.getValue().getValue();
899 assertFalse(resValue);
913 public void testTime_GT() {
915 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_GREATER_THAN;
917 // check identity and type of the thing created
918 assertEquals(XACML3.ID_FUNCTION_TIME_GREATER_THAN, fd.getId());
919 assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId());
921 // just to be safe... If tests take too long these can probably be eliminated
922 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
923 assertFalse(fd.returnsBag());
924 assertEquals(new Integer(2), fd.getNumArgs());
927 arguments.add(attrTimeToday);
928 arguments.add(attrTimeSameDay);
929 ExpressionResult res = fd.evaluate(null, arguments);
930 assertTrue(res.isOk());
931 Boolean resValue = (Boolean)res.getValue().getValue();
932 assertFalse(resValue);
936 arguments.add(attrTimeToday);
937 arguments.add(attrTimeTommorrow);
938 res = fd.evaluate(null, arguments);
939 assertTrue(res.isOk());
940 resValue = (Boolean)res.getValue().getValue();
941 assertFalse(resValue);
945 arguments.add(attrTimeToday);
946 arguments.add(attrTimeYesterday);
947 res = fd.evaluate(null, arguments);
948 assertTrue(res.isOk());
949 resValue = (Boolean)res.getValue().getValue();
950 assertTrue(resValue);
952 // test bad args data types? One with TimeZone and one without
954 arguments.add(stringAttr1);
955 arguments.add(intAttr1);
956 res = fd.evaluate(null, arguments);
957 assertFalse(res.isOk());
959 // test with TimeZone vs without
961 arguments.add(attrTimeWithTimeZone);
962 arguments.add(attrTimeNoTimeZone);
963 res = fd.evaluate(null, arguments);
964 assertFalse(res.isOk());
965 assertEquals("function:time-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage());
966 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
972 public void testTime_GTE() {
974 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_GREATER_THAN_OR_EQUAL;
976 // check identity and type of the thing created
977 assertEquals(XACML3.ID_FUNCTION_TIME_GREATER_THAN_OR_EQUAL, fd.getId());
978 assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId());
980 // just to be safe... If tests take too long these can probably be eliminated
981 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
982 assertFalse(fd.returnsBag());
983 assertEquals(new Integer(2), fd.getNumArgs());
986 arguments.add(attrTimeToday);
987 arguments.add(attrTimeSameDay);
988 ExpressionResult res = fd.evaluate(null, arguments);
989 assertTrue(res.isOk());
990 Boolean resValue = (Boolean)res.getValue().getValue();
991 assertTrue(resValue);
995 arguments.add(attrTimeToday);
996 arguments.add(attrTimeTommorrow);
997 res = fd.evaluate(null, arguments);
998 assertTrue(res.isOk());
999 resValue = (Boolean)res.getValue().getValue();
1000 assertFalse(resValue);
1004 arguments.add(attrTimeToday);
1005 arguments.add(attrTimeYesterday);
1006 res = fd.evaluate(null, arguments);
1007 assertTrue(res.isOk());
1008 resValue = (Boolean)res.getValue().getValue();
1009 assertTrue(resValue);
1013 public void testTime_LT() {
1015 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_LESS_THAN;
1017 // check identity and type of the thing created
1018 assertEquals(XACML3.ID_FUNCTION_TIME_LESS_THAN, fd.getId());
1019 assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId());
1021 // just to be safe... If tests take too long these can probably be eliminated
1022 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1023 assertFalse(fd.returnsBag());
1024 assertEquals(new Integer(2), fd.getNumArgs());
1027 arguments.add(attrTimeToday);
1028 arguments.add(attrTimeSameDay);
1029 ExpressionResult res = fd.evaluate(null, arguments);
1030 assertTrue(res.isOk());
1031 Boolean resValue = (Boolean)res.getValue().getValue();
1032 assertFalse(resValue);
1036 arguments.add(attrTimeToday);
1037 arguments.add(attrTimeTommorrow);
1038 res = fd.evaluate(null, arguments);
1039 assertTrue(res.isOk());
1040 resValue = (Boolean)res.getValue().getValue();
1041 assertTrue(resValue);
1045 arguments.add(attrTimeToday);
1046 arguments.add(attrTimeYesterday);
1047 res = fd.evaluate(null, arguments);
1048 assertTrue(res.isOk());
1049 resValue = (Boolean)res.getValue().getValue();
1050 assertFalse(resValue);
1054 public void testTime_LTE() {
1056 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_LESS_THAN_OR_EQUAL;
1058 // check identity and type of the thing created
1059 assertEquals(XACML3.ID_FUNCTION_TIME_LESS_THAN_OR_EQUAL, fd.getId());
1060 assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId());
1062 // just to be safe... If tests take too long these can probably be eliminated
1063 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1064 assertFalse(fd.returnsBag());
1065 assertEquals(new Integer(2), fd.getNumArgs());
1068 arguments.add(attrTimeToday);
1069 arguments.add(attrTimeSameDay);
1070 ExpressionResult res = fd.evaluate(null, arguments);
1071 assertTrue(res.isOk());
1072 Boolean resValue = (Boolean)res.getValue().getValue();
1073 assertTrue(resValue);
1077 arguments.add(attrTimeToday);
1078 arguments.add(attrTimeTommorrow);
1079 res = fd.evaluate(null, arguments);
1080 assertTrue(res.isOk());
1081 resValue = (Boolean)res.getValue().getValue();
1082 assertTrue(resValue);
1086 arguments.add(attrTimeToday);
1087 arguments.add(attrTimeYesterday);
1088 res = fd.evaluate(null, arguments);
1089 assertTrue(res.isOk());
1090 resValue = (Boolean)res.getValue().getValue();
1091 assertFalse(resValue);
1102 public void testTime_in_range() {
1104 FunctionDefinitionTimeInRange<?> fd = (FunctionDefinitionTimeInRange<?>) StdFunctions.FD_TIME_IN_RANGE;
1106 // check identity and type of the thing created
1107 assertEquals(XACML3.ID_FUNCTION_TIME_IN_RANGE, fd.getId());
1108 assertEquals(DataTypes.DT_TIME.getId(), fd.getDataTypeArgs().getId());
1110 // just to be safe... If tests take too long these can probably be eliminated
1111 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1112 assertFalse(fd.returnsBag());
1113 assertEquals(new Integer(3), fd.getNumArgs());
1115 // arg 0 in range of others
1116 arguments.add(attrTimeToday);
1117 arguments.add(attrTimeYesterday);
1118 arguments.add(attrTimeTommorrow);
1119 ExpressionResult res = fd.evaluate(null, arguments);
1120 assertTrue(res.isOk());
1121 Boolean resValue = (Boolean)res.getValue().getValue();
1122 assertTrue(resValue);
1126 arguments.add(attrTimeYesterday);
1127 arguments.add(attrTimeToday);
1128 arguments.add(attrTimeTommorrow);
1129 res = fd.evaluate(null, arguments);
1130 assertTrue(res.isOk());
1131 resValue = (Boolean)res.getValue().getValue();
1132 assertFalse(resValue);
1136 arguments.add(attrTimeTommorrow);
1137 arguments.add(attrTimeYesterday);
1138 arguments.add(attrTimeToday);
1139 res = fd.evaluate(null, arguments);
1140 assertTrue(res.isOk());
1141 resValue = (Boolean)res.getValue().getValue();
1142 assertFalse(resValue);
1146 arguments.add(attrTimeToday);
1147 arguments.add(attrTimeTommorrow);
1148 arguments.add(attrTimeYesterday);
1149 res = fd.evaluate(null, arguments);
1150 assertTrue(res.isOk());
1151 resValue = (Boolean)res.getValue().getValue();
1152 assertFalse(resValue);
1156 arguments.add(attrDateTimeWithTimeZone);
1157 arguments.add(attrDateTimeNoTimeZone);
1158 res = fd.evaluate(null, arguments);
1159 assertFalse(res.isOk());
1160 assertEquals("function:time-in-range Expected 3 arguments, got 2", res.getStatus().getStatusMessage());
1161 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
1164 arguments.add(attrDateTimeWithTimeZone);
1165 arguments.add(attrDateTimeNoTimeZone);
1166 arguments.add(intAttr1);
1167 res = fd.evaluate(null, arguments);
1168 assertFalse(res.isOk());
1169 assertEquals("function:time-in-range Expected data type 'time' saw 'dateTime' at arg index 0", res.getStatus().getStatusMessage());
1170 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
1184 public void testDateTime_GT() {
1186 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_GREATER_THAN;
1188 // check identity and type of the thing created
1189 assertEquals(XACML3.ID_FUNCTION_DATETIME_GREATER_THAN, fd.getId());
1190 assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId());
1192 // just to be safe... If tests take too long these can probably be eliminated
1193 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1194 assertFalse(fd.returnsBag());
1195 assertEquals(new Integer(2), fd.getNumArgs());
1198 arguments.add(attrDateTimeToday);
1199 arguments.add(attrDateTimeSameDay);
1200 ExpressionResult res = fd.evaluate(null, arguments);
1201 assertTrue(res.isOk());
1202 Boolean resValue = (Boolean)res.getValue().getValue();
1203 assertFalse(resValue);
1207 arguments.add(attrDateTimeToday);
1208 arguments.add(attrDateTimeTommorrow);
1209 res = fd.evaluate(null, arguments);
1210 assertTrue(res.isOk());
1211 resValue = (Boolean)res.getValue().getValue();
1212 assertFalse(resValue);
1216 arguments.add(attrDateTimeToday);
1217 arguments.add(attrDateTimeYesterday);
1218 res = fd.evaluate(null, arguments);
1219 assertTrue(res.isOk());
1220 resValue = (Boolean)res.getValue().getValue();
1221 assertTrue(resValue);
1223 // test bad args data types? One with TimeZone and one without
1225 arguments.add(stringAttr1);
1226 arguments.add(intAttr1);
1227 res = fd.evaluate(null, arguments);
1228 assertFalse(res.isOk());
1230 // test with TimeZone vs without
1232 arguments.add(attrDateTimeWithTimeZone);
1233 arguments.add(attrDateTimeNoTimeZone);
1234 res = fd.evaluate(null, arguments);
1235 assertFalse(res.isOk());
1236 assertEquals("function:dateTime-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage());
1237 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
1243 public void testDateTime_GTE() {
1245 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_GREATER_THAN_OR_EQUAL;
1247 // check identity and type of the thing created
1248 assertEquals(XACML3.ID_FUNCTION_DATETIME_GREATER_THAN_OR_EQUAL, fd.getId());
1249 assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId());
1251 // just to be safe... If tests take too long these can probably be eliminated
1252 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1253 assertFalse(fd.returnsBag());
1254 assertEquals(new Integer(2), fd.getNumArgs());
1257 arguments.add(attrDateTimeToday);
1258 arguments.add(attrDateTimeSameDay);
1259 ExpressionResult res = fd.evaluate(null, arguments);
1260 assertTrue(res.isOk());
1261 Boolean resValue = (Boolean)res.getValue().getValue();
1262 assertTrue(resValue);
1266 arguments.add(attrDateTimeToday);
1267 arguments.add(attrDateTimeTommorrow);
1268 res = fd.evaluate(null, arguments);
1269 assertTrue(res.isOk());
1270 resValue = (Boolean)res.getValue().getValue();
1271 assertFalse(resValue);
1275 arguments.add(attrDateTimeToday);
1276 arguments.add(attrDateTimeYesterday);
1277 res = fd.evaluate(null, arguments);
1278 assertTrue(res.isOk());
1279 resValue = (Boolean)res.getValue().getValue();
1280 assertTrue(resValue);
1284 public void testDateTime_LT() {
1286 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_LESS_THAN;
1288 // check identity and type of the thing created
1289 assertEquals(XACML3.ID_FUNCTION_DATETIME_LESS_THAN, fd.getId());
1290 assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId());
1292 // just to be safe... If tests take too long these can probably be eliminated
1293 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1294 assertFalse(fd.returnsBag());
1295 assertEquals(new Integer(2), fd.getNumArgs());
1298 arguments.add(attrDateTimeToday);
1299 arguments.add(attrDateTimeSameDay);
1300 ExpressionResult res = fd.evaluate(null, arguments);
1301 assertTrue(res.isOk());
1302 Boolean resValue = (Boolean)res.getValue().getValue();
1303 assertFalse(resValue);
1307 arguments.add(attrDateTimeToday);
1308 arguments.add(attrDateTimeTommorrow);
1309 res = fd.evaluate(null, arguments);
1310 assertTrue(res.isOk());
1311 resValue = (Boolean)res.getValue().getValue();
1312 assertTrue(resValue);
1316 arguments.add(attrDateTimeToday);
1317 arguments.add(attrDateTimeYesterday);
1318 res = fd.evaluate(null, arguments);
1319 assertTrue(res.isOk());
1320 resValue = (Boolean)res.getValue().getValue();
1321 assertFalse(resValue);
1325 public void testDateTime_LTE() {
1327 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_LESS_THAN_OR_EQUAL;
1329 // check identity and type of the thing created
1330 assertEquals(XACML3.ID_FUNCTION_DATETIME_LESS_THAN_OR_EQUAL, fd.getId());
1331 assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId());
1333 // just to be safe... If tests take too long these can probably be eliminated
1334 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
1335 assertFalse(fd.returnsBag());
1336 assertEquals(new Integer(2), fd.getNumArgs());
1339 arguments.add(attrDateTimeToday);
1340 arguments.add(attrDateTimeSameDay);
1341 ExpressionResult res = fd.evaluate(null, arguments);
1342 assertTrue(res.isOk());
1343 Boolean resValue = (Boolean)res.getValue().getValue();
1344 assertTrue(resValue);
1348 arguments.add(attrDateTimeToday);
1349 arguments.add(attrDateTimeTommorrow);
1350 res = fd.evaluate(null, arguments);
1351 assertTrue(res.isOk());
1352 resValue = (Boolean)res.getValue().getValue();
1353 assertTrue(resValue);
1357 arguments.add(attrDateTimeToday);
1358 arguments.add(attrDateTimeYesterday);
1359 res = fd.evaluate(null, arguments);
1360 assertTrue(res.isOk());
1361 resValue = (Boolean)res.getValue().getValue();
1362 assertFalse(resValue);