2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.pdp.test;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
28 import java.math.BigInteger;
29 import java.util.ArrayList;
30 import java.util.List;
32 import org.junit.Test;
34 import com.att.research.xacml.api.XACML3;
35 import com.att.research.xacml.std.datatypes.DataTypes;
36 import com.att.research.xacmlatt.pdp.policy.ExpressionResult;
37 import com.att.research.xacmlatt.pdp.policy.FunctionArgument;
38 import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue;
39 import com.att.research.xacmlatt.pdp.std.StdFunctions;
40 import com.att.research.xacmlatt.pdp.std.functions.*;
43 * Test of PDP Functions (See XACML core spec section A.3)
46 * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
50 public class FunctionDefinitionArithmeticTest {
53 * variables useful in the following tests
55 List<FunctionArgument> arguments = new ArrayList<FunctionArgument>();
58 public void testInteger_add() {
60 FunctionArgumentAttributeValue attr1 = null;
61 FunctionArgumentAttributeValue attr2 = null;
62 FunctionArgumentAttributeValue attrBadType = null;
64 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
65 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
66 attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1));
67 } catch (Exception e) {
68 fail("creating attributes e="+ e);
71 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_INTEGER_ADD;
73 // check identity and type of the thing created
74 assertEquals(XACML3.ID_FUNCTION_INTEGER_ADD, fd.getId());
75 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
76 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId());
78 // just to be safe... If tests take too long these can probably be eliminated
79 assertFalse(fd.returnsBag());
80 assertEquals(new Integer(2), fd.getNumArgs());
86 ExpressionResult res = fd.evaluate(null, arguments);
87 assertTrue(res.isOk());
88 BigInteger resValue = (BigInteger)res.getValue().getValue();
89 assertEquals(new BigInteger("2"), resValue);
93 arguments.add(attrBadType);
94 res = fd.evaluate(null, arguments);
95 assertFalse(res.isOk());
96 assertEquals("function:integer-add Expected data type 'integer' saw 'double' at arg index 1", res.getStatus().getStatusMessage());
97 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
103 public void testDouble_add() {
105 FunctionArgumentAttributeValue attr1 = null;
106 FunctionArgumentAttributeValue attr2 = null;
109 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5));
110 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5));
111 } catch (Exception e) {
112 fail("creating attributes e="+e);
115 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_DOUBLE_ADD;
117 // check identity and type of the thing created
118 assertEquals(XACML3.ID_FUNCTION_DOUBLE_ADD, fd.getId());
119 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
120 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId());
122 // just to be safe... If tests take too long these can probably be eliminated
123 assertFalse(fd.returnsBag());
124 assertEquals(new Integer(2), fd.getNumArgs());
128 arguments.add(attr1);
129 arguments.add(attr2);
130 ExpressionResult res = fd.evaluate(null, arguments);
131 assertTrue(res.isOk());
132 Double resValue = (Double)res.getValue().getValue();
133 assertEquals(new Double(4.0), resValue);
139 public void testInteger_subtract() {
141 FunctionArgumentAttributeValue attr1 = null;
142 FunctionArgumentAttributeValue attr2 = null;
144 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(6));
145 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
146 } catch (Exception e) {
147 fail("creating attributes e="+ e);
150 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_INTEGER_SUBTRACT;
152 // check identity and type of the thing created
153 assertEquals(XACML3.ID_FUNCTION_INTEGER_SUBTRACT, fd.getId());
154 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
155 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId());
157 // just to be safe... If tests take too long these can probably be eliminated
158 assertFalse(fd.returnsBag());
159 assertEquals(new Integer(2), fd.getNumArgs());
163 arguments.add(attr1);
164 arguments.add(attr2);
165 ExpressionResult res = fd.evaluate(null, arguments);
166 assertTrue(res.isOk());
167 BigInteger resValue = (BigInteger)res.getValue().getValue();
168 assertEquals(new BigInteger("5"), resValue);
174 public void testDouble_subtract() {
176 FunctionArgumentAttributeValue attr1 = null;
177 FunctionArgumentAttributeValue attr2 = null;
180 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(8.5));
181 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.3));
182 } catch (Exception e) {
183 fail("creating attributes e="+e);
186 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_DOUBLE_SUBTRACT;
188 // check identity and type of the thing created
189 assertEquals(XACML3.ID_FUNCTION_DOUBLE_SUBTRACT, fd.getId());
190 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
191 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId());
193 // just to be safe... If tests take too long these can probably be eliminated
194 assertFalse(fd.returnsBag());
195 assertEquals(new Integer(2), fd.getNumArgs());
199 arguments.add(attr1);
200 arguments.add(attr2);
201 ExpressionResult res = fd.evaluate(null, arguments);
202 assertTrue(res.isOk());
203 Double resValue = (Double)res.getValue().getValue();
204 assertEquals(new Double(6.2), resValue);
210 public void testInteger_multiply() {
212 FunctionArgumentAttributeValue attr0 = null;
213 FunctionArgumentAttributeValue attr1 = null;
214 FunctionArgumentAttributeValue attr2 = null;
216 attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0));
217 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5));
218 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2));
219 } catch (Exception e) {
220 fail("creating attributes e="+ e);
223 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_INTEGER_MULTIPLY;
225 // check identity and type of the thing created
226 assertEquals(XACML3.ID_FUNCTION_INTEGER_MULTIPLY, fd.getId());
227 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
228 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId());
230 // just to be safe... If tests take too long these can probably be eliminated
231 assertFalse(fd.returnsBag());
232 assertEquals(new Integer(2), fd.getNumArgs());
236 arguments.add(attr1);
237 arguments.add(attr2);
238 ExpressionResult res = fd.evaluate(null, arguments);
239 assertTrue(res.isOk());
240 BigInteger resValue = (BigInteger)res.getValue().getValue();
241 assertEquals(new BigInteger("10"), resValue);
246 arguments.add(attr1);
247 arguments.add(attr0);
248 res = fd.evaluate(null, arguments);
249 assertTrue(res.isOk());
250 resValue = (BigInteger)res.getValue().getValue();
251 assertEquals(new BigInteger("0"), resValue);
256 public void testDouble_multiply() {
258 FunctionArgumentAttributeValue attr0 = null;
259 FunctionArgumentAttributeValue attr1 = null;
260 FunctionArgumentAttributeValue attr2 = null;
263 attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0));
264 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5));
265 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5));
266 } catch (Exception e) {
267 fail("creating attributes e="+e);
270 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_DOUBLE_MULTIPLY;
272 // check identity and type of the thing created
273 assertEquals(XACML3.ID_FUNCTION_DOUBLE_MULTIPLY, fd.getId());
274 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
275 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId());
277 // just to be safe... If tests take too long these can probably be eliminated
278 assertFalse(fd.returnsBag());
279 assertEquals(new Integer(2), fd.getNumArgs());
283 arguments.add(attr1);
284 arguments.add(attr2);
285 ExpressionResult res = fd.evaluate(null, arguments);
286 assertTrue(res.isOk());
287 Double resValue = (Double)res.getValue().getValue();
288 assertEquals(new Double(3.75), resValue);
290 // test multiply by 0
292 arguments.add(attr1);
293 arguments.add(attr0);
294 res = fd.evaluate(null, arguments);
295 assertTrue(res.isOk());
296 resValue = (Double)res.getValue().getValue();
297 assertEquals(new Double(0), resValue);
302 public void testInteger_divide() {
304 FunctionArgumentAttributeValue attr0 = null;
305 FunctionArgumentAttributeValue attr1 = null;
306 FunctionArgumentAttributeValue attr2 = null;
308 attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0));
309 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5));
310 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2));
311 } catch (Exception e) {
312 fail("creating attributes e="+ e);
315 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_INTEGER_DIVIDE;
317 // check identity and type of the thing created
318 assertEquals(XACML3.ID_FUNCTION_INTEGER_DIVIDE, fd.getId());
319 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
320 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId());
322 // just to be safe... If tests take too long these can probably be eliminated
323 assertFalse(fd.returnsBag());
324 assertEquals(new Integer(2), fd.getNumArgs());
328 arguments.add(attr1);
329 arguments.add(attr2);
330 ExpressionResult res = fd.evaluate(null, arguments);
331 assertTrue(res.isOk());
332 BigInteger resValue = (BigInteger)res.getValue().getValue();
333 assertEquals(new BigInteger("2"), resValue);
338 arguments.add(attr1);
339 arguments.add(attr0);
340 res = fd.evaluate(null, arguments);
341 assertFalse(res.isOk());
342 assertEquals("function:integer-divide Divide by 0 error: 5, 0", res.getStatus().getStatusMessage());
343 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
349 public void testDouble_divide() {
351 FunctionArgumentAttributeValue attr0 = null;
352 FunctionArgumentAttributeValue attr1 = null;
353 FunctionArgumentAttributeValue attr2 = null;
356 attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0));
357 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5));
358 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5));
360 } catch (Exception e) {
361 fail("creating attributes e="+e);
363 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_DOUBLE_DIVIDE;
365 // check identity and type of the thing created
366 assertEquals(XACML3.ID_FUNCTION_DOUBLE_DIVIDE, fd.getId());
367 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
368 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId());
370 // just to be safe... If tests take too long these can probably be eliminated
371 assertFalse(fd.returnsBag());
372 assertEquals(new Integer(2), fd.getNumArgs());
376 arguments.add(attr1);
377 arguments.add(attr2);
378 ExpressionResult res = fd.evaluate(null, arguments);
379 assertTrue(res.isOk());
380 Double resValue = (Double)res.getValue().getValue();
381 assertEquals(new Double(0.6), resValue);
383 // test multiply by 0
385 arguments.add(attr1);
386 arguments.add(attr0);
387 res = fd.evaluate(null, arguments);
388 assertFalse(res.isOk());
389 assertEquals("function:double-divide Divide by 0 error: 1.5, 0.0", res.getStatus().getStatusMessage());
390 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
400 public void testInteger_mod() {
402 FunctionArgumentAttributeValue attr0 = null;
403 FunctionArgumentAttributeValue attr1 = null;
404 FunctionArgumentAttributeValue attr2 = null;
406 attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0));
407 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(28));
408 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5));
409 } catch (Exception e) {
410 fail("creating attributes e="+ e);
413 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_INTEGER_MOD;
415 // check identity and type of the thing created
416 assertEquals(XACML3.ID_FUNCTION_INTEGER_MOD, fd.getId());
417 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
418 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId());
420 // just to be safe... If tests take too long these can probably be eliminated
421 assertFalse(fd.returnsBag());
422 assertEquals(new Integer(2), fd.getNumArgs());
426 arguments.add(attr1);
427 arguments.add(attr2);
428 ExpressionResult res = fd.evaluate(null, arguments);
429 assertTrue(res.isOk());
430 BigInteger resValue = (BigInteger)res.getValue().getValue();
431 assertEquals(new BigInteger("3"), resValue);
436 arguments.add(attr1);
437 arguments.add(attr0);
438 res = fd.evaluate(null, arguments);
439 assertFalse(res.isOk());
440 assertEquals("function:integer-mod Divide by 0 error: 28, 0", res.getStatus().getStatusMessage());
441 assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue());
447 public void testInteger_abs() {
449 FunctionArgumentAttributeValue attr0 = null;
450 FunctionArgumentAttributeValue attr1 = null;
451 FunctionArgumentAttributeValue attrM1 = null;
453 attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0));
454 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5));
455 attrM1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-7));
456 } catch (Exception e) {
457 fail("creating attributes e="+ e);
460 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_INTEGER_ABS;
462 // check identity and type of the thing created
463 assertEquals(XACML3.ID_FUNCTION_INTEGER_ABS, fd.getId());
464 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId());
465 assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId());
467 // just to be safe... If tests take too long these can probably be eliminated
468 assertFalse(fd.returnsBag());
469 assertEquals(new Integer(1), fd.getNumArgs());
473 arguments.add(attr1);
474 ExpressionResult res = fd.evaluate(null, arguments);
475 assertTrue(res.isOk());
476 BigInteger resValue = (BigInteger)res.getValue().getValue();
477 assertEquals(new BigInteger("5"), resValue);
480 arguments.add(attrM1);
481 res = fd.evaluate(null, arguments);
482 assertTrue(res.isOk());
483 resValue = (BigInteger)res.getValue().getValue();
484 assertEquals(new BigInteger("7"), resValue);
487 arguments.add(attr0);
488 res = fd.evaluate(null, arguments);
489 assertTrue(res.isOk());
490 resValue = (BigInteger)res.getValue().getValue();
491 assertEquals(new BigInteger("0"), resValue);
496 public void testDouble_abs() {
498 FunctionArgumentAttributeValue attr0 = null;
499 FunctionArgumentAttributeValue attr1 = null;
500 FunctionArgumentAttributeValue attr2 = null;
503 attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0));
504 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5));
505 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5));
507 } catch (Exception e) {
508 fail("creating attributes e="+e);
511 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_DOUBLE_ABS;
513 // check identity and type of the thing created
514 assertEquals(XACML3.ID_FUNCTION_DOUBLE_ABS, fd.getId());
515 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
516 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId());
518 // just to be safe... If tests take too long these can probably be eliminated
519 assertFalse(fd.returnsBag());
520 assertEquals(new Integer(1), fd.getNumArgs());
524 arguments.add(attr1);
525 ExpressionResult res = fd.evaluate(null, arguments);
526 assertTrue(res.isOk());
527 Double resValue = (Double)res.getValue().getValue();
528 assertEquals(new Double(1.5), resValue);
531 arguments.add(attr2);
532 res = fd.evaluate(null, arguments);
533 assertTrue(res.isOk());
534 resValue = (Double)res.getValue().getValue();
535 assertEquals(new Double(2.5), resValue);
538 arguments.add(attr0);
539 res = fd.evaluate(null, arguments);
540 assertTrue(res.isOk());
541 resValue = (Double)res.getValue().getValue();
542 assertEquals(new Double(0), resValue);
548 public void testDouble_round() {
550 FunctionArgumentAttributeValue attr0 = null;
551 FunctionArgumentAttributeValue attr1 = null;
552 FunctionArgumentAttributeValue attr2 = null;
553 FunctionArgumentAttributeValue attr3 = null;
554 FunctionArgumentAttributeValue attr4 = null;
555 FunctionArgumentAttributeValue attr5 = null;
556 FunctionArgumentAttributeValue attr6 = null;
558 attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0));
559 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5));
560 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.49));
561 attr3 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.51));
562 attr4 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5));
563 attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.49));
564 attr6 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.51));
565 } catch (Exception e) {
566 fail("creating attributes e="+e);
571 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_ROUND;
573 // check identity and type of the thing created
574 assertEquals(XACML3.ID_FUNCTION_ROUND, fd.getId());
575 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
576 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId());
578 // just to be safe... If tests take too long these can probably be eliminated
579 assertFalse(fd.returnsBag());
580 assertEquals(new Integer(1), fd.getNumArgs());
584 arguments.add(attr0);
585 ExpressionResult res = fd.evaluate(null, arguments);
586 assertTrue(res.isOk());
587 Double resValue = (Double)res.getValue().getValue();
588 assertEquals(new Double(0), resValue);
591 arguments.add(attr1);
592 res = fd.evaluate(null, arguments);
593 assertTrue(res.isOk());
594 resValue = (Double)res.getValue().getValue();
595 assertEquals(new Double(2), resValue);
598 arguments.add(attr2);
599 res = fd.evaluate(null, arguments);
600 assertTrue(res.isOk());
601 resValue = (Double)res.getValue().getValue();
602 assertEquals(new Double(1), resValue);
605 arguments.add(attr3);
606 res = fd.evaluate(null, arguments);
607 assertTrue(res.isOk());
608 resValue = (Double)res.getValue().getValue();
609 assertEquals(new Double(2), resValue);
612 arguments.add(attr4);
613 res = fd.evaluate(null, arguments);
614 assertTrue(res.isOk());
615 resValue = (Double)res.getValue().getValue();
616 assertEquals(new Double(-2), resValue);
619 arguments.add(attr5);
620 res = fd.evaluate(null, arguments);
621 assertTrue(res.isOk());
622 resValue = (Double)res.getValue().getValue();
623 assertEquals(new Double(-2), resValue);
626 arguments.add(attr6);
627 res = fd.evaluate(null, arguments);
628 assertTrue(res.isOk());
629 resValue = (Double)res.getValue().getValue();
630 assertEquals(new Double(-3), resValue);
635 public void testDouble_floor() {
636 FunctionArgumentAttributeValue attr0 = null;
637 FunctionArgumentAttributeValue attr1 = null;
638 FunctionArgumentAttributeValue attr2 = null;
639 FunctionArgumentAttributeValue attr3 = null;
640 FunctionArgumentAttributeValue attr4 = null;
641 FunctionArgumentAttributeValue attr5 = null;
642 FunctionArgumentAttributeValue attr6 = null;
644 attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0));
645 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5));
646 attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.49));
647 attr3 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.51));
648 attr4 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5));
649 attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.49));
650 attr6 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.51));
651 } catch (Exception e) {
652 fail("creating attributes e="+e);
655 FunctionDefinitionArithmetic<?> fd = (FunctionDefinitionArithmetic<?>) StdFunctions.FD_FLOOR;
657 // check identity and type of the thing created
658 assertEquals(XACML3.ID_FUNCTION_FLOOR, fd.getId());
659 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId());
660 assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId());
662 // just to be safe... If tests take too long these can probably be eliminated
663 assertFalse(fd.returnsBag());
664 assertEquals(new Integer(1), fd.getNumArgs());
668 arguments.add(attr0);
669 ExpressionResult res = fd.evaluate(null, arguments);
670 assertTrue(res.isOk());
671 Double resValue = (Double)res.getValue().getValue();
672 assertEquals(new Double(0), resValue);
675 arguments.add(attr1);
676 res = fd.evaluate(null, arguments);
677 assertTrue(res.isOk());
678 resValue = (Double)res.getValue().getValue();
679 assertEquals(new Double(1), resValue);
682 arguments.add(attr2);
683 res = fd.evaluate(null, arguments);
684 assertTrue(res.isOk());
685 resValue = (Double)res.getValue().getValue();
686 assertEquals(new Double(1), resValue);
689 arguments.add(attr3);
690 res = fd.evaluate(null, arguments);
691 assertTrue(res.isOk());
692 resValue = (Double)res.getValue().getValue();
693 assertEquals(new Double(1), resValue);
696 arguments.add(attr4);
697 res = fd.evaluate(null, arguments);
698 assertTrue(res.isOk());
699 resValue = (Double)res.getValue().getValue();
700 assertEquals(new Double(-3), resValue);
703 arguments.add(attr5);
704 res = fd.evaluate(null, arguments);
705 assertTrue(res.isOk());
706 resValue = (Double)res.getValue().getValue();
707 assertEquals(new Double(-3), resValue);
710 arguments.add(attr6);
711 res = fd.evaluate(null, arguments);
712 assertTrue(res.isOk());
713 resValue = (Double)res.getValue().getValue();
714 assertEquals(new Double(-3), resValue);