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.onap.policy.pdp.test;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
28 import org.junit.Test;
30 import com.att.research.xacml.api.Identifier;
31 import com.att.research.xacml.api.XACML3;
32 import com.att.research.xacmlatt.pdp.policy.FunctionDefinition;
33 import com.att.research.xacmlatt.pdp.std.StdFunctions;
34 import com.att.research.xacmlatt.pdp.std.functions.*;
37 * Test functions in the abstract FunctionDefinitionSimpleTest class.
38 * Functions are tested by creating instances of other classes that should have appropriate properties to verify all variations of the responses expected.
40 * Note: we do not test getDataTypeId() because all it does is get the String out of the Identity object and we assume that the Data Type Identity objects
41 * are tested enough in everything else that any errors in them will be found and fixed quickly.
44 * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
48 public class FunctionDefinitionBaseTest {
50 * getId() is pretty trivial, so verifying one should be enough to check that the mechanism is working ok
53 public void testGetId() {
54 FunctionDefinition fd = StdFunctions.FD_STRING_EQUAL;
55 Identifier id = fd.getId();
56 assertTrue(XACML3.ID_FUNCTION_STRING_EQUAL.stringValue().equals(id.stringValue()) );
60 * check an instance of every result type that we can deal with
63 public void testGetDataType() {
65 //?? Need functions that return each of these data types except for Boolean which is returned by any of the EQUAL functions
66 FunctionDefinition fdstring = StdFunctions.FD_STRING_NORMALIZE_SPACE;
67 assertEquals(XACML3.ID_DATATYPE_STRING, fdstring.getDataTypeId());
69 FunctionDefinition fdboolean = StdFunctions.FD_STRING_EQUAL;
70 assertEquals(XACML3.ID_DATATYPE_BOOLEAN, fdboolean.getDataTypeId());
72 FunctionDefinition fdinteger = StdFunctions.FD_INTEGER_ADD;
73 assertEquals(XACML3.ID_DATATYPE_INTEGER, fdinteger.getDataTypeId());
75 FunctionDefinition fddouble = StdFunctions.FD_DOUBLE_ADD;
76 assertEquals(XACML3.ID_DATATYPE_DOUBLE, fddouble.getDataTypeId());
78 FunctionDefinition fddate = StdFunctions.FD_DATE_BAG;
79 assertEquals(XACML3.ID_DATATYPE_DATE, fddate.getDataTypeId());
81 FunctionDefinition fdtime = StdFunctions.FD_TIME_BAG;
82 assertEquals(XACML3.ID_DATATYPE_TIME, fdtime.getDataTypeId());
84 FunctionDefinition fddateTime = StdFunctions.FD_DATETIME_BAG;
85 assertEquals(XACML3.ID_DATATYPE_DATETIME, fddateTime.getDataTypeId());
87 FunctionDefinition fddayTimeDuration = StdFunctions.FD_DAYTIMEDURATION_FROM_STRING;
88 assertEquals(XACML3.ID_DATATYPE_DAYTIMEDURATION, fddayTimeDuration.getDataTypeId());
90 FunctionDefinition fdyearMonthDuration = StdFunctions.FD_YEARMONTHDURATION_FROM_STRING;
91 assertEquals(XACML3.ID_DATATYPE_YEARMONTHDURATION, fdyearMonthDuration.getDataTypeId());
93 FunctionDefinition fdanyURI = StdFunctions.FD_ANYURI_FROM_STRING;
94 assertEquals(XACML3.ID_DATATYPE_ANYURI, fdanyURI.getDataTypeId());
96 FunctionDefinition fdhexBinary = StdFunctions.FD_HEXBINARY_UNION;
97 assertEquals(XACML3.ID_DATATYPE_HEXBINARY, fdhexBinary.getDataTypeId());
99 FunctionDefinition fdbase64Binary = StdFunctions.FD_BASE64BINARY_UNION;
100 assertEquals(XACML3.ID_DATATYPE_BASE64BINARY, fdbase64Binary.getDataTypeId());
102 FunctionDefinition fdrfc822Name = StdFunctions.FD_RFC822NAME_FROM_STRING;
103 assertEquals(XACML3.ID_DATATYPE_RFC822NAME, fdrfc822Name.getDataTypeId());
105 FunctionDefinition fdx500Name = StdFunctions.FD_X500NAME_FROM_STRING;
106 assertEquals(XACML3.ID_DATATYPE_X500NAME, fdx500Name.getDataTypeId());
108 //TODO - There are currently no functions that return XPathExpression objects
109 // FunctionDefinition fdxpathExpression = StdFunctions.FD_XPATHEXPRESSION_FROM_STRING;
110 // assertEquals(XACML3.ID_DATATYPE_XPATHEXPRESSION, fdxpathExpression.getDataTypeId());
112 FunctionDefinition fdipAddress = StdFunctions.FD_IPADDRESS_FROM_STRING;
113 assertEquals(XACML3.ID_DATATYPE_IPADDRESS, fdipAddress.getDataTypeId());
115 FunctionDefinition fddnsName = StdFunctions.FD_DNSNAME_FROM_STRING;
116 assertEquals(XACML3.ID_DATATYPE_DNSNAME, fddnsName.getDataTypeId());
120 * check the type of return, single vs multiple values
123 public void testReturnsBag() {
124 FunctionDefinition fdNotBag = StdFunctions.FD_BOOLEAN_EQUAL;
125 assertFalse(fdNotBag.returnsBag());
127 FunctionDefinitionBag<?> fdBag = (FunctionDefinitionBag<?>) StdFunctions.FD_STRING_BAG;
128 assertTrue(fdBag.returnsBag());