From e0addf5b588a1244f9679becd90999dfcb4c3a94 Mon Sep 17 00:00:00 2001 From: "ITSERVICES\\rb7147" Date: Tue, 25 Apr 2017 11:46:00 -0400 Subject: Policy 1707 commit to LF Change-Id: Ibe6f01d92f9a434c040abb05d5386e89d675ae65 Signed-off-by: ITSERVICES\rb7147 --- .../FunctionDefinitionArithmeticTest.java | 717 --------------------- 1 file changed, 717 deletions(-) delete mode 100644 ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionArithmeticTest.java (limited to 'ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionArithmeticTest.java') diff --git a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionArithmeticTest.java b/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionArithmeticTest.java deleted file mode 100644 index 95fcdb2d2..000000000 --- a/ECOMP-TEST/src/test/java/org/openecomp/policy/pdp/test/std/functions/FunctionDefinitionArithmeticTest.java +++ /dev/null @@ -1,717 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ECOMP-TEST - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.policy.pdp.test.std.functions; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import com.att.research.xacml.api.XACML3; -import com.att.research.xacml.std.datatypes.DataTypes; -import com.att.research.xacmlatt.pdp.policy.ExpressionResult; -import com.att.research.xacmlatt.pdp.policy.FunctionArgument; -import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue; -import com.att.research.xacmlatt.pdp.std.StdFunctions; -import com.att.research.xacmlatt.pdp.std.functions.FunctionDefinitionArithmetic; - -/** - * Test of PDP Functions (See XACML core spec section A.3) - * - * TO RUN - use jUnit - * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test - * - * - */ -public class FunctionDefinitionArithmeticTest { - - /* - * variables useful in the following tests - */ - List arguments = new ArrayList(); - - @Test - public void testInteger_add() { - - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - FunctionArgumentAttributeValue attrBadType = null; - try { - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); - attrBadType = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.1)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_ADD; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_ADD, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - // test normal add - arguments.add(attr1); - arguments.add(attr2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - BigInteger resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("2"), resValue); - - arguments.clear(); - arguments.add(attr1); - arguments.add(attrBadType); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-add Expected data type 'integer' saw 'double' at arg index 1", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - @Test - public void testDouble_add() { - - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - - try { - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5)); - } catch (Exception e) { - fail("creating attributes e="+e); - } - - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_ADD; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DOUBLE_ADD, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - // test normal add - arguments.add(attr1); - arguments.add(attr2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Double resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(4.0), resValue); - - } - - - @Test - public void testInteger_subtract() { - - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - try { - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(6)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_SUBTRACT; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_SUBTRACT, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - // test normal - arguments.add(attr1); - arguments.add(attr2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - BigInteger resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("5"), resValue); - - } - - - @Test - public void testDouble_subtract() { - - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - - try { - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(8.5)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.3)); - } catch (Exception e) { - fail("creating attributes e="+e); - } - - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_SUBTRACT; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DOUBLE_SUBTRACT, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - // test normal - arguments.add(attr1); - arguments.add(attr2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Double resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(6.2), resValue); - - } - - - @Test - public void testInteger_multiply() { - - FunctionArgumentAttributeValue attr0 = null; - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - try { - attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_MULTIPLY; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_MULTIPLY, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - // test normal - arguments.add(attr1); - arguments.add(attr2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - BigInteger resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("10"), resValue); - - - // test 0 - arguments.clear(); - arguments.add(attr1); - arguments.add(attr0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("0"), resValue); - } - - - @Test - public void testDouble_multiply() { - - FunctionArgumentAttributeValue attr0 = null; - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - - try { - attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5)); - } catch (Exception e) { - fail("creating attributes e="+e); - } - - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_MULTIPLY; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DOUBLE_MULTIPLY, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - // test normal add - arguments.add(attr1); - arguments.add(attr2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Double resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(3.75), resValue); - - // test multiply by 0 - arguments.clear(); - arguments.add(attr1); - arguments.add(attr0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(0), resValue); - } - - - @Test - public void testInteger_divide() { - - FunctionArgumentAttributeValue attr0 = null; - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - try { - attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(2)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_DIVIDE; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_DIVIDE, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - // test normal - arguments.add(attr1); - arguments.add(attr2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - BigInteger resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("2"), resValue); - - - // test 0 - arguments.clear(); - arguments.add(attr1); - arguments.add(attr0); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-divide Divide by 0 error: 5, 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - @Test - public void testDouble_divide() { - - FunctionArgumentAttributeValue attr0 = null; - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - - try { - attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(2.5)); - - } catch (Exception e) { - fail("creating attributes e="+e); - } - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_DIVIDE; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DOUBLE_DIVIDE, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - // test normal - arguments.add(attr1); - arguments.add(attr2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Double resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(0.6), resValue); - - // test multiply by 0 - arguments.clear(); - arguments.add(attr1); - arguments.add(attr0); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:double-divide Divide by 0 error: 1.5, 0.0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - - - - - @Test - public void testInteger_mod() { - - FunctionArgumentAttributeValue attr0 = null; - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - try { - attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(28)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_MOD; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_MOD, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(2), fd.getNumArgs()); - - - // test normal - arguments.add(attr1); - arguments.add(attr2); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - BigInteger resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("3"), resValue); - - - // test 0 - arguments.clear(); - arguments.add(attr1); - arguments.add(attr0); - res = fd.evaluate(null, arguments); - assertFalse(res.isOk()); - assertEquals("function:integer-mod Divide by 0 error: 28, 0", res.getStatus().getStatusMessage()); - assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); - - } - - - @Test - public void testInteger_abs() { - - FunctionArgumentAttributeValue attr0 = null; - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attrM1 = null; - try { - attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(0)); - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(5)); - attrM1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(-7)); - } catch (Exception e) { - fail("creating attributes e="+ e); - } - - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_INTEGER_ABS; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_INTEGER_ABS, fd.getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(1), fd.getNumArgs()); - - - // test normal - arguments.add(attr1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - BigInteger resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("5"), resValue); - - arguments.clear(); - arguments.add(attrM1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("7"), resValue); - - arguments.clear(); - arguments.add(attr0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (BigInteger)res.getValue().getValue(); - assertEquals(new BigInteger("0"), resValue); - } - - - @Test - public void testDouble_abs() { - - FunctionArgumentAttributeValue attr0 = null; - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - - try { - attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5)); - - } catch (Exception e) { - fail("creating attributes e="+e); - } - - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_DOUBLE_ABS; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_DOUBLE_ABS, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(1), fd.getNumArgs()); - - - // test normal - arguments.add(attr1); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Double resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(1.5), resValue); - - arguments.clear(); - arguments.add(attr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(2.5), resValue); - - arguments.clear(); - arguments.add(attr0); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(0), resValue); - - } - - - @Test - public void testDouble_round() { - - FunctionArgumentAttributeValue attr0 = null; - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - FunctionArgumentAttributeValue attr3 = null; - FunctionArgumentAttributeValue attr4 = null; - FunctionArgumentAttributeValue attr5 = null; - FunctionArgumentAttributeValue attr6 = null; - try { - attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.49)); - attr3 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.51)); - attr4 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5)); - attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.49)); - attr6 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.51)); - } catch (Exception e) { - fail("creating attributes e="+e); - } - - - - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_ROUND; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_ROUND, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(1), fd.getNumArgs()); - - - // test normal - arguments.add(attr0); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Double resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(0), resValue); - - arguments.clear(); - arguments.add(attr1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(2), resValue); - - arguments.clear(); - arguments.add(attr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(1), resValue); - - arguments.clear(); - arguments.add(attr3); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(2), resValue); - - arguments.clear(); - arguments.add(attr4); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(-2), resValue); - - arguments.clear(); - arguments.add(attr5); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(-2), resValue); - - arguments.clear(); - arguments.add(attr6); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(-3), resValue); - } - - - @Test - public void testDouble_floor() { - FunctionArgumentAttributeValue attr0 = null; - FunctionArgumentAttributeValue attr1 = null; - FunctionArgumentAttributeValue attr2 = null; - FunctionArgumentAttributeValue attr3 = null; - FunctionArgumentAttributeValue attr4 = null; - FunctionArgumentAttributeValue attr5 = null; - FunctionArgumentAttributeValue attr6 = null; - try { - attr0 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(0)); - attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.5)); - attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.49)); - attr3 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(1.51)); - attr4 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.5)); - attr5 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.49)); - attr6 = new FunctionArgumentAttributeValue(DataTypes.DT_DOUBLE.createAttributeValue(-2.51)); - } catch (Exception e) { - fail("creating attributes e="+e); - } - - FunctionDefinitionArithmetic fd = (FunctionDefinitionArithmetic) StdFunctions.FD_FLOOR; - - // check identity and type of the thing created - assertEquals(XACML3.ID_FUNCTION_FLOOR, fd.getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeArgs().getId()); - assertEquals(DataTypes.DT_DOUBLE.getId(), fd.getDataTypeId()); - - // just to be safe... If tests take too long these can probably be eliminated - assertFalse(fd.returnsBag()); - assertEquals(new Integer(1), fd.getNumArgs()); - - - // test normal - arguments.add(attr0); - ExpressionResult res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - Double resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(0), resValue); - - arguments.clear(); - arguments.add(attr1); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(1), resValue); - - arguments.clear(); - arguments.add(attr2); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(1), resValue); - - arguments.clear(); - arguments.add(attr3); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(1), resValue); - - arguments.clear(); - arguments.add(attr4); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(-3), resValue); - - arguments.clear(); - arguments.add(attr5); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(-3), resValue); - - arguments.clear(); - arguments.add(attr6); - res = fd.evaluate(null, arguments); - assertTrue(res.isOk()); - resValue = (Double)res.getValue().getValue(); - assertEquals(new Double(-3), resValue); - } - -} -- cgit 1.2.3-korg