[POLICY-73] replace openecomp for policy-engine
[policy/engine.git] / ONAP-PDP / src / test / java / org / onap / policy / pdp / test / FunctionDefinitionBaseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PDP
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.pdp.test;
22
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
27
28 import org.junit.Test;
29
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.*;
35
36 /**
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.
39  * 
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.
42  * 
43  * TO RUN - use jUnit
44  * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
45  * 
46  *
47  */
48 public class FunctionDefinitionBaseTest {
49         /**
50          * getId() is pretty trivial, so verifying one should be enough to check that the mechanism is working ok
51          */
52         @Test
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()) );
57         }
58
59         /**
60          * check an instance of every result type that we can deal with
61          */     
62         @Test
63         public void testGetDataType() {
64                 
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());
68
69                 FunctionDefinition fdboolean = StdFunctions.FD_STRING_EQUAL;
70                 assertEquals(XACML3.ID_DATATYPE_BOOLEAN, fdboolean.getDataTypeId());
71                 
72                 FunctionDefinition fdinteger = StdFunctions.FD_INTEGER_ADD;
73                 assertEquals(XACML3.ID_DATATYPE_INTEGER, fdinteger.getDataTypeId());
74
75                 FunctionDefinition fddouble = StdFunctions.FD_DOUBLE_ADD;
76                 assertEquals(XACML3.ID_DATATYPE_DOUBLE, fddouble.getDataTypeId());
77
78                 FunctionDefinition fddate = StdFunctions.FD_DATE_BAG;
79                 assertEquals(XACML3.ID_DATATYPE_DATE, fddate.getDataTypeId());
80
81                 FunctionDefinition fdtime = StdFunctions.FD_TIME_BAG;
82                 assertEquals(XACML3.ID_DATATYPE_TIME, fdtime.getDataTypeId());
83
84                 FunctionDefinition fddateTime = StdFunctions.FD_DATETIME_BAG;
85                 assertEquals(XACML3.ID_DATATYPE_DATETIME, fddateTime.getDataTypeId());
86
87                 FunctionDefinition fddayTimeDuration = StdFunctions.FD_DAYTIMEDURATION_FROM_STRING;
88                 assertEquals(XACML3.ID_DATATYPE_DAYTIMEDURATION, fddayTimeDuration.getDataTypeId());
89
90                 FunctionDefinition fdyearMonthDuration = StdFunctions.FD_YEARMONTHDURATION_FROM_STRING;
91                 assertEquals(XACML3.ID_DATATYPE_YEARMONTHDURATION, fdyearMonthDuration.getDataTypeId());
92
93                 FunctionDefinition fdanyURI = StdFunctions.FD_ANYURI_FROM_STRING;
94                 assertEquals(XACML3.ID_DATATYPE_ANYURI, fdanyURI.getDataTypeId());
95
96                 FunctionDefinition fdhexBinary = StdFunctions.FD_HEXBINARY_UNION;
97                 assertEquals(XACML3.ID_DATATYPE_HEXBINARY, fdhexBinary.getDataTypeId());
98
99                 FunctionDefinition fdbase64Binary = StdFunctions.FD_BASE64BINARY_UNION;
100                 assertEquals(XACML3.ID_DATATYPE_BASE64BINARY, fdbase64Binary.getDataTypeId());
101
102                 FunctionDefinition fdrfc822Name = StdFunctions.FD_RFC822NAME_FROM_STRING;
103                 assertEquals(XACML3.ID_DATATYPE_RFC822NAME, fdrfc822Name.getDataTypeId());
104
105                 FunctionDefinition fdx500Name = StdFunctions.FD_X500NAME_FROM_STRING;
106                 assertEquals(XACML3.ID_DATATYPE_X500NAME, fdx500Name.getDataTypeId());
107
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());
111
112                 FunctionDefinition fdipAddress = StdFunctions.FD_IPADDRESS_FROM_STRING;
113                 assertEquals(XACML3.ID_DATATYPE_IPADDRESS, fdipAddress.getDataTypeId());
114
115                 FunctionDefinition fddnsName = StdFunctions.FD_DNSNAME_FROM_STRING;
116                 assertEquals(XACML3.ID_DATATYPE_DNSNAME, fddnsName.getDataTypeId());
117         }
118         
119         /**
120          * check the type of return, single vs multiple values
121          */
122         @Test
123         public void testReturnsBag() {
124                 FunctionDefinition fdNotBag = StdFunctions.FD_BOOLEAN_EQUAL;
125                 assertFalse(fdNotBag.returnsBag());
126                 
127                 FunctionDefinitionBag<?> fdBag = (FunctionDefinitionBag<?>) StdFunctions.FD_STRING_BAG;
128                 assertTrue(fdBag.returnsBag());
129         }
130         
131 }