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.util.ArrayList;
29 import java.util.List;
31 import org.junit.Test;
33 import com.att.research.xacml.api.XACML3;
34 import com.att.research.xacml.std.datatypes.DataTypes;
35 import com.att.research.xacmlatt.pdp.policy.ExpressionResult;
36 import com.att.research.xacmlatt.pdp.policy.FunctionArgument;
37 import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue;
38 import com.att.research.xacmlatt.pdp.std.StdFunctions;
39 import com.att.research.xacmlatt.pdp.std.functions.*;
42 * Only one function to test here. Code copy/pasted from FunctionDefinitionEqualityTest
45 * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
47 * In the first implementation of XACML we had separate files for each XACML Function.
48 * This release combines multiple Functions in fewer files to minimize code duplication.
49 * This file supports the following XACML codes:
50 * string-equal-ignore-case
54 public class FunctionDefinitionStringEqualIgnoreCaseTest {
57 * variables useful in the following tests
59 List<FunctionArgument> arguments = new ArrayList<FunctionArgument>();
61 FunctionArgumentAttributeValue stringAttr1 = null;
62 FunctionArgumentAttributeValue stringAttr2 = null;
63 FunctionArgumentAttributeValue stringAttr3 = null;
64 FunctionArgumentAttributeValue stringAttr4 = null;
66 FunctionArgumentAttributeValue intAttr1 = null;
68 public FunctionDefinitionStringEqualIgnoreCaseTest() {
70 stringAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc"));
71 stringAttr2 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("abc"));
72 stringAttr3 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("ABC"));
73 stringAttr4 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue("def"));
74 intAttr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1));
75 } catch (Exception e) {
76 fail("creating attribute e="+ e);
82 * String match even when Case is different
85 public void testFunctionDefinitionStringEqualIgnoreCase() {
87 FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_STRING_EQUAL_IGNORE_CASE;
89 // check identity and type of the thing created
90 assertEquals(XACML3.ID_FUNCTION_STRING_EQUAL_IGNORE_CASE, fd.getId());
91 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
93 // just to be safe... If tests take too long these can probably be eliminated
94 assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId());
95 assertFalse(fd.returnsBag());
96 assertEquals(new Integer(2), fd.getNumArgs());
100 // test normal equals and non-equals
101 // check "abc" with "abc"
102 arguments.add(stringAttr1);
103 arguments.add(stringAttr2);
104 ExpressionResult res = fd.evaluate(null, arguments);
105 assertTrue(res.isOk());
106 Boolean resValue = (Boolean)res.getValue().getValue();
107 assertTrue(resValue);
109 // check "abc" with "ABC" (should be same)
111 arguments.add(stringAttr1);
112 arguments.add(stringAttr3);
113 res = fd.evaluate(null, arguments);
114 assertTrue(res.isOk());
115 resValue = (Boolean)res.getValue().getValue();
116 assertTrue(resValue);
118 // test bad args data types? Not needed?
120 arguments.add(stringAttr1);
121 arguments.add(intAttr1);
122 res = fd.evaluate(null, arguments);
123 assertFalse(res.isOk());
126 //TODO - null in either first or 2nd arg => NullPointerException