Commit includes ControlLoopPolicy API and bugfixes
[policy/engine.git] / ECOMP-PDP / src / test / java / org / openecomp / policy / pdp / test / FunctionDefinitionComparisonTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-PDP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.policy.pdp.test;
22
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;
27
28 import java.util.ArrayList;
29 import java.util.Calendar;
30 import java.util.Date;
31 import java.util.List;
32
33 import org.junit.Test;
34
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.*;
45
46 /**
47  * Test FunctionDefinitionComparison
48  * 
49  * TO RUN - use jUnit
50  * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
51  * 
52  *
53  */
54 public class FunctionDefinitionComparisonTest {
55
56         /*
57          * variables useful in the following tests
58          */
59         List<FunctionArgument> arguments = new ArrayList<>();
60         
61         FunctionArgumentAttributeValue stringAttr1 = null;
62         FunctionArgumentAttributeValue stringAttr1a = null;
63         FunctionArgumentAttributeValue stringAttr2 = null;
64         FunctionArgumentAttributeValue stringAttrNeg1 = null;
65
66
67         FunctionArgumentAttributeValue intAttr1 = null;
68         FunctionArgumentAttributeValue intAttr1a = null;
69         FunctionArgumentAttributeValue intAttr2 = null;
70         FunctionArgumentAttributeValue intAttr0 = null;
71         FunctionArgumentAttributeValue intAttrNeg1 = null;
72         
73         FunctionArgumentAttributeValue attr1 = null;
74         FunctionArgumentAttributeValue attr1a = null;
75         FunctionArgumentAttributeValue attr2 = null;
76         FunctionArgumentAttributeValue attrNeg1 = null;
77         
78         FunctionArgumentAttributeValue attrDateToday = null;
79         FunctionArgumentAttributeValue attrDateSameDay = null;
80         FunctionArgumentAttributeValue attrDateTommorrow = null;
81         FunctionArgumentAttributeValue attrDateYesterday = null;
82         FunctionArgumentAttributeValue attrDateWithTimeZone = null;
83         FunctionArgumentAttributeValue attrDateNoTimeZone = null;
84
85         
86         FunctionArgumentAttributeValue attrTimeToday = null;
87         FunctionArgumentAttributeValue attrTimeSameDay = null;
88         FunctionArgumentAttributeValue attrTimeTommorrow = null;
89         FunctionArgumentAttributeValue attrTimeYesterday = null;
90         FunctionArgumentAttributeValue attrTimeWithTimeZone = null;
91         FunctionArgumentAttributeValue attrTimeNoTimeZone = null;
92         
93         FunctionArgumentAttributeValue attrDateTimeToday = null;
94         FunctionArgumentAttributeValue attrDateTimeSameDay = null;
95         FunctionArgumentAttributeValue attrDateTimeTommorrow = null;
96         FunctionArgumentAttributeValue attrDateTimeYesterday = null;
97         FunctionArgumentAttributeValue attrDateTimeWithTimeZone = null;
98         FunctionArgumentAttributeValue attrDateTimeNoTimeZone = null;
99         
100         /**
101          * Set up some common variables on startup
102          */
103         public FunctionDefinitionComparisonTest() {
104         try {
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"));
109
110
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));
116                 
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));
121                 
122                 // create dates
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);
129                 } else {
130                         calendar.set(Calendar.HOUR_OF_DAY, 5);
131                 }
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));
143                 
144                 // create Times
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));
156                 
157                 // create DateTimes
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));
176                 
177                 
178                 
179                 
180         } catch (Exception e) {
181                 fail("Error creating values e="+ e);
182         }
183         }
184         
185         /**
186          * String
187          */
188         @Test
189         public void testString_GT() {
190                 
191                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_GREATER_THAN;
192                 
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());
196                 
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());
201                 
202                 // first == second
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);
209
210                 // check first < second
211                 arguments.clear();
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);
218                 
219                 // first > second
220                 arguments.clear();
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);
227
228                 // test bad args data types?  Not needed?
229                 arguments.clear();
230                 arguments.add(intAttr1);
231                 arguments.add(stringAttr1);
232                 res = fd.evaluate(null, arguments);
233                 assertFalse(res.isOk());
234         }
235         
236         @Test
237         public void testString_GTE() {
238                 
239                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_GREATER_THAN_OR_EQUAL;
240                 
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());
244                 
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());
249                 
250                 // first == second
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);
257
258                 // check first < second
259                 arguments.clear();
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);
266                 
267                 // first > second
268                 arguments.clear();
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);
275         }
276         
277         @Test
278         public void testString_LT() {
279                 
280                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_LESS_THAN;
281                 
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());
285                 
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());
290                 
291                 // first == second
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);
298
299                 // check first < second
300                 arguments.clear();
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);
307                 
308                 // first > second
309                 arguments.clear();
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);
316         }
317         
318         @Test
319         public void testString_LTE() {
320                 
321                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_LESS_THAN_OR_EQUAL;
322                 
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());
326                 
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());
331                 
332                 // first == second
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);
339
340                 // check first < second
341                 arguments.clear();
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);
348                 
349                 // first > second
350                 arguments.clear();
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);
357         }
358
359         
360         
361         /**
362          * Integer
363          */
364         @Test
365         public void testInteger_GT() {
366                 
367                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_GREATER_THAN;
368                 
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());
372                 
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());
377                 
378                 // first == second
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);
385
386                 // check first < second
387                 arguments.clear();
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);
394                 
395                 // first > second
396                 arguments.clear();
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);
403
404                 // test bad args data types?  Not needed?
405                 arguments.clear();
406                 arguments.add(stringAttr1);
407                 arguments.add(intAttr1);
408                 res = fd.evaluate(null, arguments);
409                 assertFalse(res.isOk());
410         }
411         
412         @Test
413         public void testInteger_GTE() {
414                 
415                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_GREATER_THAN_OR_EQUAL;
416                 
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());
420                 
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());
425                 
426                 // first == second
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);
433
434                 // check first < second
435                 arguments.clear();
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);
442                 
443                 // first > second
444                 arguments.clear();
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);
451         }
452         
453         @Test
454         public void testInteger_LT() {
455                 
456                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_LESS_THAN;
457                 
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());
461                 
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());
466                 
467                 // first == second
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);
474
475                 // check first < second
476                 arguments.clear();
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);
483                 
484                 // first > second
485                 arguments.clear();
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);
492         }
493         
494         @Test
495         public void testInteger_LTE() {
496                 
497                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_LESS_THAN_OR_EQUAL;
498                 
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());
502                 
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());
507                 
508                 // first == second
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);
515
516                 // check first < second
517                 arguments.clear();
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);
524                 
525                 // first > second
526                 arguments.clear();
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);
533         }
534         
535         
536         
537         
538         /**
539          * Double
540          */
541         @Test
542         public void testDouble_GT() {
543
544                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_GREATER_THAN;
545                 
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());
549                 
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());
554                 
555                 // first == second
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);
562
563                 // first < second
564                 arguments.clear();
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);
571                 
572                 // first > second
573                 arguments.clear();
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);
580
581                 // test bad args data types?  Not needed?
582                 arguments.clear();
583                 arguments.add(stringAttr1);
584                 arguments.add(intAttr1);
585                 res = fd.evaluate(null, arguments);
586                 assertFalse(res.isOk());
587
588         }
589         
590         @Test
591         public void testDouble_GTE() {
592
593                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_GREATER_THAN_OR_EQUAL;
594                 
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());
598                 
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());
603                 
604                 // first == second
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);
611
612                 // first < second
613                 arguments.clear();
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);
620                 
621                 // first > second
622                 arguments.clear();
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);
629         }
630         
631         @Test
632         public void testDouble_LT() {
633
634                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_LESS_THAN;
635                 
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());
639                 
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());
644                 
645                 // first == second
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);
652
653                 // first < second
654                 arguments.clear();
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);
661                 
662                 // first > second
663                 arguments.clear();
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);
670         }
671         
672         @Test
673         public void testDouble_LTE() {
674
675                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_LESS_THAN_OR_EQUAL;
676                 
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());
680                 
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());
685                 
686                 // first == second
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);
693
694                 // first < second
695                 arguments.clear();
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);
702                 
703                 // first > second
704                 arguments.clear();
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);
711         }
712
713         
714         
715         /**
716          * Date
717          */
718         
719         @Test
720         public void testDate_GT() {
721
722                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_GREATER_THAN;
723                 
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());
727                 
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());
732                 
733                 // first == second
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);
740
741                 // first < second
742                 arguments.clear();
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);
749                 
750                 // first > second
751                 arguments.clear();
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);
758
759                 // test bad args data types?  One with TimeZone and one without
760                 arguments.clear();
761                 arguments.add(stringAttr1);
762                 arguments.add(intAttr1);
763                 res = fd.evaluate(null, arguments);
764                 assertFalse(res.isOk());
765
766                 // test with TimeZone vs without
767                 arguments.clear();
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());
774         
775
776         }
777
778         @Test
779         public void testDate_GTE() {
780
781                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_GREATER_THAN_OR_EQUAL;
782                 
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());
786                 
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());
791                 
792                 // first == second
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);
799
800                 // first < second
801                 arguments.clear();
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);
808                 
809                 // first > second
810                 arguments.clear();
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);
817         }
818         
819         @Test
820         public void testDate_LT() {
821
822                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_LESS_THAN;
823                 
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());
827                 
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());
832                 
833                 // first == second
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);
840
841                 // first < second
842                 arguments.clear();
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);
849                 
850                 // first > second
851                 arguments.clear();
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);
858         }
859         
860         @Test
861         public void testDate_LTE() {
862
863                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_LESS_THAN_OR_EQUAL;
864                 
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());
868                 
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());
873
874                 // first == second
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);
881
882                 // first < second
883                 arguments.clear();
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);
890                 
891                 // first > second
892                 arguments.clear();
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);
899         }
900         
901         
902         
903         
904         
905         
906         
907         /**
908          * Time
909          */
910         
911         @Test
912         public void testTime_GT() {
913
914                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_GREATER_THAN;
915                 
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());
919                 
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());
924                 
925                 // first == second
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);
932
933                 // first < second
934                 arguments.clear();
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);
941                 
942                 // first > second
943                 arguments.clear();
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);
950
951                 // test bad args data types?  One with TimeZone and one without
952                 arguments.clear();
953                 arguments.add(stringAttr1);
954                 arguments.add(intAttr1);
955                 res = fd.evaluate(null, arguments);
956                 assertFalse(res.isOk());
957
958                 // test with TimeZone vs without
959                 arguments.clear();
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());
966         
967
968         }
969         
970         @Test
971         public void testTime_GTE() {
972
973                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_GREATER_THAN_OR_EQUAL;
974                 
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());
978                 
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());
983                 
984                 // first == second
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);
991
992                 // first < second
993                 arguments.clear();
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);
1000                 
1001                 // first > second
1002                 arguments.clear();
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);
1009         }
1010         
1011         @Test
1012         public void testTime_LT() {
1013
1014                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_LESS_THAN;
1015                 
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());
1019                 
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());
1024                 
1025                 // first == second
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);
1032
1033                 // first < second
1034                 arguments.clear();
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);
1041                 
1042                 // first > second
1043                 arguments.clear();
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);
1050         }
1051         
1052         @Test
1053         public void testTime_LTE() {
1054
1055                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_LESS_THAN_OR_EQUAL;
1056                 
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());
1060                 
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());
1065                 
1066                 // first == second
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);
1073
1074                 // first < second
1075                 arguments.clear();
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);
1082                 
1083                 // first > second
1084                 arguments.clear();
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);
1091         }
1092         
1093         
1094         
1095         
1096         
1097         /**
1098          * Time-in-range
1099          */
1100         @Test
1101         public void testTime_in_range() {
1102
1103                 FunctionDefinitionTimeInRange<?> fd = (FunctionDefinitionTimeInRange<?>) StdFunctions.FD_TIME_IN_RANGE;
1104                 
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());
1108                 
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());
1113                 
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);
1122                 
1123                 // below range
1124                 arguments.clear();
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);
1132                 
1133                 // above range
1134                 arguments.clear();
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);
1142                 
1143                 // range bad
1144                 arguments.clear();
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);
1152                 
1153                 // bad types
1154                 arguments.clear();
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());
1161         
1162                 arguments.clear();
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());
1170         
1171         }
1172
1173         
1174         
1175         
1176         
1177         
1178         /**
1179          * DateTime
1180          */
1181         
1182         @Test
1183         public void testDateTime_GT() {
1184
1185                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_GREATER_THAN;
1186                 
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());
1190                 
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());
1195                 
1196                 // first == second
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);
1203
1204                 // first < second
1205                 arguments.clear();
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);
1212                 
1213                 // first > second
1214                 arguments.clear();
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);
1221
1222                 // test bad args data types?  One with TimeZone and one without
1223                 arguments.clear();
1224                 arguments.add(stringAttr1);
1225                 arguments.add(intAttr1);
1226                 res = fd.evaluate(null, arguments);
1227                 assertFalse(res.isOk());
1228
1229                 // test with TimeZone vs without
1230                 arguments.clear();
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());
1237         
1238
1239         }
1240         
1241         @Test
1242         public void testDateTime_GTE() {
1243
1244                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_GREATER_THAN_OR_EQUAL;
1245                 
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());
1249                 
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());
1254                 
1255                 // first == second
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);
1262
1263                 // first < second
1264                 arguments.clear();
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);
1271                 
1272                 // first > second
1273                 arguments.clear();
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);
1280         }
1281         
1282         @Test
1283         public void testDateTime_LT() {
1284
1285                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_LESS_THAN;
1286                 
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());
1290                 
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());
1295                 
1296                 // first == second
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);
1303
1304                 // first < second
1305                 arguments.clear();
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);
1312                 
1313                 // first > second
1314                 arguments.clear();
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);
1321         }
1322         
1323         @Test
1324         public void testDateTime_LTE() {
1325
1326                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_LESS_THAN_OR_EQUAL;
1327                 
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());
1331                 
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());
1336                 
1337                 // first == second
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);
1344
1345                 // first < second
1346                 arguments.clear();
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);
1353                 
1354                 // first > second
1355                 arguments.clear();
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);
1362         }
1363
1364
1365
1366 }