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 * Test of PDP Functions (See XACML core spec section A.3)
45 * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
49 public class FunctionDefinitionStringNormalizeTest {
52 * variables useful in the following tests
54 List<FunctionArgument> arguments = new ArrayList<>();
57 public void testString_normalize_space() {
58 String initialString = " First and last are whitespace ";
59 FunctionArgumentAttributeValue attr1 = null;
61 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(initialString));
62 } catch (Exception e) {
63 fail("creating attribute e="+ e);
66 FunctionDefinitionStringNormalize fd = (FunctionDefinitionStringNormalize) StdFunctions.FD_STRING_NORMALIZE_SPACE;
68 // check identity and type of the thing created
69 assertEquals(XACML3.ID_FUNCTION_STRING_NORMALIZE_SPACE, fd.getId());
70 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
71 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId());
73 // just to be safe... If tests take too long these can probably be eliminated
74 assertFalse(fd.returnsBag());
75 assertEquals(new Integer(1), fd.getNumArgs());
80 ExpressionResult res = fd.evaluate(null, arguments);
81 assertTrue(res.isOk());
82 String resValue = (String)res.getValue().getValue();
83 assertEquals(initialString.length() - 4, resValue.length());
84 assertTrue(initialString.trim().equals(resValue));
89 public void testString_normalize_to_lower_case() {
90 String initialString = " First and last are whitespace ";
91 FunctionArgumentAttributeValue attr1 = null;
93 attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(initialString));
94 } catch (Exception e) {
95 fail("creating attribute e="+ e);
98 FunctionDefinitionStringNormalize fd = (FunctionDefinitionStringNormalize) StdFunctions.FD_STRING_NORMALIZE_TO_LOWER_CASE;
100 // check identity and type of the thing created
101 assertEquals(XACML3.ID_FUNCTION_STRING_NORMALIZE_TO_LOWER_CASE, fd.getId());
102 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId());
103 assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId());
105 // just to be safe... If tests take too long these can probably be eliminated
106 assertFalse(fd.returnsBag());
107 assertEquals(new Integer(1), fd.getNumArgs());
111 arguments.add(attr1);
112 ExpressionResult res = fd.evaluate(null, arguments);
113 assertTrue(res.isOk());
114 String resValue = (String)res.getValue().getValue();
115 assertTrue(initialString.toLowerCase().equals(resValue));