Initial OpenECOMP policy/engine commit
[policy/engine.git] / ECOMP-TEST / src / test / java / org / openecomp / policy / pdp / test / std / functions / FunctionDefinitionComparisonTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-TEST
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.std.functions;
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.FunctionDefinitionComparison;
45 import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionTimeInRange;
46
47 /**
48  * Test FunctionDefinitionComparison
49  * 
50  * TO RUN - use jUnit
51  * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
52  * 
53  *
54  */
55 public class FunctionDefinitionComparisonTest {
56
57         /*
58          * variables useful in the following tests
59          */
60         List<FunctionArgument> arguments = new ArrayList<FunctionArgument>();
61         
62         FunctionArgumentAttributeValue stringAttr1 = null;
63         FunctionArgumentAttributeValue stringAttr1a = null;
64         FunctionArgumentAttributeValue stringAttr2 = null;
65         FunctionArgumentAttributeValue stringAttrNeg1 = null;
66
67
68         FunctionArgumentAttributeValue intAttr1 = null;
69         FunctionArgumentAttributeValue intAttr1a = null;
70         FunctionArgumentAttributeValue intAttr2 = null;
71         FunctionArgumentAttributeValue intAttr0 = null;
72         FunctionArgumentAttributeValue intAttrNeg1 = null;
73         
74         FunctionArgumentAttributeValue attr1 = null;
75         FunctionArgumentAttributeValue attr1a = null;
76         FunctionArgumentAttributeValue attr2 = null;
77         FunctionArgumentAttributeValue attrNeg1 = null;
78         
79         FunctionArgumentAttributeValue attrDateToday = null;
80         FunctionArgumentAttributeValue attrDateSameDay = null;
81         FunctionArgumentAttributeValue attrDateTommorrow = null;
82         FunctionArgumentAttributeValue attrDateYesterday = null;
83         FunctionArgumentAttributeValue attrDateWithTimeZone = null;
84         FunctionArgumentAttributeValue attrDateNoTimeZone = null;
85
86         
87         FunctionArgumentAttributeValue attrTimeToday = null;
88         FunctionArgumentAttributeValue attrTimeSameDay = null;
89         FunctionArgumentAttributeValue attrTimeTommorrow = null;
90         FunctionArgumentAttributeValue attrTimeYesterday = null;
91         FunctionArgumentAttributeValue attrTimeWithTimeZone = null;
92         FunctionArgumentAttributeValue attrTimeNoTimeZone = null;
93         
94         FunctionArgumentAttributeValue attrDateTimeToday = null;
95         FunctionArgumentAttributeValue attrDateTimeSameDay = null;
96         FunctionArgumentAttributeValue attrDateTimeTommorrow = null;
97         FunctionArgumentAttributeValue attrDateTimeYesterday = null;
98         FunctionArgumentAttributeValue attrDateTimeWithTimeZone = null;
99         FunctionArgumentAttributeValue attrDateTimeNoTimeZone = null;
100         
101         /**
102          * Set up some common variables on startup
103          */
104         public FunctionDefinitionComparisonTest() {
105         try {
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"));
110
111
112                 intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
113                 intAttr1a = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
114                 intAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2));
115                 intAttr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0));
116                 intAttrNeg1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-1));
117                 
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));
122                 
123                 // create dates
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);
130                 } else {
131                         calendar.set(Calendar.HOUR_OF_DAY, 5);
132                 }
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));
144                 
145                 // create Times
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));
157                 
158                 // create DateTimes
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));
177                 
178                 
179                 
180                 
181         } catch (Exception e) {
182                 fail("Error creating values e="+ e);
183         }
184         }
185         
186         /**
187          * String
188          */
189         @Test
190         public void testString_GT() {
191                 
192                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_GREATER_THAN;
193                 
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());
197                 
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());
202                 
203                 // first == second
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);
210
211                 // check first < second
212                 arguments.clear();
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);
219                 
220                 // first > second
221                 arguments.clear();
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);
228
229                 // test bad args data types?  Not needed?
230                 arguments.clear();
231                 arguments.add(intAttr1);
232                 arguments.add(stringAttr1);
233                 res = fd.evaluate(null, arguments);
234                 assertFalse(res.isOk());
235         }
236         
237         @Test
238         public void testString_GTE() {
239                 
240                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_GREATER_THAN_OR_EQUAL;
241                 
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());
245                 
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());
250                 
251                 // first == second
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);
258
259                 // check first < second
260                 arguments.clear();
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);
267                 
268                 // first > second
269                 arguments.clear();
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);
276         }
277         
278         @Test
279         public void testString_LT() {
280                 
281                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_LESS_THAN;
282                 
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());
286                 
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());
291                 
292                 // first == second
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);
299
300                 // check first < second
301                 arguments.clear();
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);
308                 
309                 // first > second
310                 arguments.clear();
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);
317         }
318         
319         @Test
320         public void testString_LTE() {
321                 
322                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_STRING_LESS_THAN_OR_EQUAL;
323                 
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());
327                 
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());
332                 
333                 // first == second
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);
340
341                 // check first < second
342                 arguments.clear();
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);
349                 
350                 // first > second
351                 arguments.clear();
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);
358         }
359
360         
361         
362         /**
363          * Integer
364          */
365         @Test
366         public void testInteger_GT() {
367                 
368                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_GREATER_THAN;
369                 
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());
373                 
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());
378                 
379                 // first == second
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);
386
387                 // check first < second
388                 arguments.clear();
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);
395                 
396                 // first > second
397                 arguments.clear();
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);
404
405                 // test bad args data types?  Not needed?
406                 arguments.clear();
407                 arguments.add(stringAttr1);
408                 arguments.add(intAttr1);
409                 res = fd.evaluate(null, arguments);
410                 assertFalse(res.isOk());
411         }
412         
413         @Test
414         public void testInteger_GTE() {
415                 
416                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_GREATER_THAN_OR_EQUAL;
417                 
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());
421                 
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());
426                 
427                 // first == second
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);
434
435                 // check first < second
436                 arguments.clear();
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);
443                 
444                 // first > second
445                 arguments.clear();
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);
452         }
453         
454         @Test
455         public void testInteger_LT() {
456                 
457                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_LESS_THAN;
458                 
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());
462                 
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());
467                 
468                 // first == second
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);
475
476                 // check first < second
477                 arguments.clear();
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);
484                 
485                 // first > second
486                 arguments.clear();
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);
493         }
494         
495         @Test
496         public void testInteger_LTE() {
497                 
498                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_INTEGER_LESS_THAN_OR_EQUAL;
499                 
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());
503                 
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());
508                 
509                 // first == second
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);
516
517                 // check first < second
518                 arguments.clear();
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);
525                 
526                 // first > second
527                 arguments.clear();
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);
534         }
535         
536         
537         
538         
539         /**
540          * Double
541          */
542         @Test
543         public void testDouble_GT() {
544
545                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_GREATER_THAN;
546                 
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());
550                 
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());
555                 
556                 // first == second
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);
563
564                 // first < second
565                 arguments.clear();
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);
572                 
573                 // first > second
574                 arguments.clear();
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);
581
582                 // test bad args data types?  Not needed?
583                 arguments.clear();
584                 arguments.add(stringAttr1);
585                 arguments.add(intAttr1);
586                 res = fd.evaluate(null, arguments);
587                 assertFalse(res.isOk());
588
589         }
590         
591         @Test
592         public void testDouble_GTE() {
593
594                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_GREATER_THAN_OR_EQUAL;
595                 
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());
599                 
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());
604                 
605                 // first == second
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);
612
613                 // first < second
614                 arguments.clear();
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);
621                 
622                 // first > second
623                 arguments.clear();
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);
630         }
631         
632         @Test
633         public void testDouble_LT() {
634
635                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_LESS_THAN;
636                 
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());
640                 
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());
645                 
646                 // first == second
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);
653
654                 // first < second
655                 arguments.clear();
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);
662                 
663                 // first > second
664                 arguments.clear();
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);
671         }
672         
673         @Test
674         public void testDouble_LTE() {
675
676                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DOUBLE_LESS_THAN_OR_EQUAL;
677                 
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());
681                 
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());
686                 
687                 // first == second
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);
694
695                 // first < second
696                 arguments.clear();
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);
703                 
704                 // first > second
705                 arguments.clear();
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);
712         }
713
714         
715         
716         /**
717          * Date
718          */
719         
720         @Test
721         public void testDate_GT() {
722
723                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_GREATER_THAN;
724                 
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());
728                 
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());
733                 
734                 // first == second
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);
741
742                 // first < second
743                 arguments.clear();
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);
750                 
751                 // first > second
752                 arguments.clear();
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);
759
760                 // test bad args data types?  One with TimeZone and one without
761                 arguments.clear();
762                 arguments.add(stringAttr1);
763                 arguments.add(intAttr1);
764                 res = fd.evaluate(null, arguments);
765                 assertFalse(res.isOk());
766
767                 // test with TimeZone vs without
768                 arguments.clear();
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());
775         
776
777         }
778
779         @Test
780         public void testDate_GTE() {
781
782                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_GREATER_THAN_OR_EQUAL;
783                 
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());
787                 
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());
792                 
793                 // first == second
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);
800
801                 // first < second
802                 arguments.clear();
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);
809                 
810                 // first > second
811                 arguments.clear();
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);
818         }
819         
820         @Test
821         public void testDate_LT() {
822
823                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_LESS_THAN;
824                 
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());
828                 
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());
833                 
834                 // first == second
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);
841
842                 // first < second
843                 arguments.clear();
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);
850                 
851                 // first > second
852                 arguments.clear();
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);
859         }
860         
861         @Test
862         public void testDate_LTE() {
863
864                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATE_LESS_THAN_OR_EQUAL;
865                 
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());
869                 
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());
874
875                 // first == second
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);
882
883                 // first < second
884                 arguments.clear();
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);
891                 
892                 // first > second
893                 arguments.clear();
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);
900         }
901         
902         
903         
904         
905         
906         
907         
908         /**
909          * Time
910          */
911         
912         @Test
913         public void testTime_GT() {
914
915                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_GREATER_THAN;
916                 
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());
920                 
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());
925                 
926                 // first == second
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);
933
934                 // first < second
935                 arguments.clear();
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);
942                 
943                 // first > second
944                 arguments.clear();
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);
951
952                 // test bad args data types?  One with TimeZone and one without
953                 arguments.clear();
954                 arguments.add(stringAttr1);
955                 arguments.add(intAttr1);
956                 res = fd.evaluate(null, arguments);
957                 assertFalse(res.isOk());
958
959                 // test with TimeZone vs without
960                 arguments.clear();
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());
967         
968
969         }
970         
971         @Test
972         public void testTime_GTE() {
973
974                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_GREATER_THAN_OR_EQUAL;
975                 
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());
979                 
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());
984                 
985                 // first == second
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);
992
993                 // first < second
994                 arguments.clear();
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);
1001                 
1002                 // first > second
1003                 arguments.clear();
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);
1010         }
1011         
1012         @Test
1013         public void testTime_LT() {
1014
1015                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_LESS_THAN;
1016                 
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());
1020                 
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());
1025                 
1026                 // first == second
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);
1033
1034                 // first < second
1035                 arguments.clear();
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);
1042                 
1043                 // first > second
1044                 arguments.clear();
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);
1051         }
1052         
1053         @Test
1054         public void testTime_LTE() {
1055
1056                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_TIME_LESS_THAN_OR_EQUAL;
1057                 
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());
1061                 
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());
1066                 
1067                 // first == second
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);
1074
1075                 // first < second
1076                 arguments.clear();
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);
1083                 
1084                 // first > second
1085                 arguments.clear();
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);
1092         }
1093         
1094         
1095         
1096         
1097         
1098         /**
1099          * Time-in-range
1100          */
1101         @Test
1102         public void testTime_in_range() {
1103
1104                 FunctionDefinitionTimeInRange<?> fd = (FunctionDefinitionTimeInRange<?>) StdFunctions.FD_TIME_IN_RANGE;
1105                 
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());
1109                 
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());
1114                 
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);
1123                 
1124                 // below range
1125                 arguments.clear();
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);
1133                 
1134                 // above range
1135                 arguments.clear();
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);
1143                 
1144                 // range bad
1145                 arguments.clear();
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);
1153                 
1154                 // bad types
1155                 arguments.clear();
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());
1162         
1163                 arguments.clear();
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());
1171         
1172         }
1173
1174         
1175         
1176         
1177         
1178         
1179         /**
1180          * DateTime
1181          */
1182         
1183         @Test
1184         public void testDateTime_GT() {
1185
1186                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_GREATER_THAN;
1187                 
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());
1191                 
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());
1196                 
1197                 // first == second
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);
1204
1205                 // first < second
1206                 arguments.clear();
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);
1213                 
1214                 // first > second
1215                 arguments.clear();
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);
1222
1223                 // test bad args data types?  One with TimeZone and one without
1224                 arguments.clear();
1225                 arguments.add(stringAttr1);
1226                 arguments.add(intAttr1);
1227                 res = fd.evaluate(null, arguments);
1228                 assertFalse(res.isOk());
1229
1230                 // test with TimeZone vs without
1231                 arguments.clear();
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());
1238         
1239
1240         }
1241         
1242         @Test
1243         public void testDateTime_GTE() {
1244
1245                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_GREATER_THAN_OR_EQUAL;
1246                 
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());
1250                 
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());
1255                 
1256                 // first == second
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);
1263
1264                 // first < second
1265                 arguments.clear();
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);
1272                 
1273                 // first > second
1274                 arguments.clear();
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);
1281         }
1282         
1283         @Test
1284         public void testDateTime_LT() {
1285
1286                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_LESS_THAN;
1287                 
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());
1291                 
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());
1296                 
1297                 // first == second
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);
1304
1305                 // first < second
1306                 arguments.clear();
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);
1313                 
1314                 // first > second
1315                 arguments.clear();
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);
1322         }
1323         
1324         @Test
1325         public void testDateTime_LTE() {
1326
1327                 FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_LESS_THAN_OR_EQUAL;
1328                 
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());
1332                 
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());
1337                 
1338                 // first == second
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);
1345
1346                 // first < second
1347                 arguments.clear();
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);
1354                 
1355                 // first > second
1356                 arguments.clear();
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);
1363         }
1364
1365
1366
1367 }