aboutsummaryrefslogtreecommitdiffstats
path: root/ECOMP-PDP/src/test/java/org/openecomp/policy/pdp/test/FunctionDefinitionBaseTest.java
blob: 10975f469fe5b41726672e21b38a3cbc313d1163 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*-
 * ============LICENSE_START=======================================================
 * ECOMP-PDP
 * ================================================================================
 * 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;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import com.att.research.xacml.api.Identifier;
import com.att.research.xacml.api.XACML3;
import com.att.research.xacmlatt.pdp.policy.FunctionDefinition;
import com.att.research.xacmlatt.pdp.std.StdFunctions;
import com.att.research.xacmlatt.pdp.std.functions.*;

/**
 * Test functions in the abstract FunctionDefinitionSimpleTest class.
 * Functions are tested by creating instances of other classes that should have appropriate properties to verify all variations of the responses expected.
 * 
 * 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
 * are tested enough in everything else that any errors in them will be found and fixed quickly.
 * 
 * TO RUN - use jUnit
 * In Eclipse select this file or the enclosing directory, right-click and select Run As/JUnit Test
 * 
 *
 */
public class FunctionDefinitionBaseTest {
	/**
	 * getId() is pretty trivial, so verifying one should be enough to check that the mechanism is working ok
	 */
	@Test
	public void testGetId() {
		FunctionDefinition fd = StdFunctions.FD_STRING_EQUAL;
		Identifier id = fd.getId();
		assertTrue(XACML3.ID_FUNCTION_STRING_EQUAL.stringValue().equals(id.stringValue()) );
	}

	/**
	 * check an instance of every result type that we can deal with
	 */	
	@Test
	public void testGetDataType() {
		
//?? Need functions that return each of these data types except for Boolean which is returned by any of the EQUAL functions
		FunctionDefinition fdstring = StdFunctions.FD_STRING_NORMALIZE_SPACE;
		assertEquals(XACML3.ID_DATATYPE_STRING, fdstring.getDataTypeId());

		FunctionDefinition fdboolean = StdFunctions.FD_STRING_EQUAL;
		assertEquals(XACML3.ID_DATATYPE_BOOLEAN, fdboolean.getDataTypeId());
		
		FunctionDefinition fdinteger = StdFunctions.FD_INTEGER_ADD;
		assertEquals(XACML3.ID_DATATYPE_INTEGER, fdinteger.getDataTypeId());

		FunctionDefinition fddouble = StdFunctions.FD_DOUBLE_ADD;
		assertEquals(XACML3.ID_DATATYPE_DOUBLE, fddouble.getDataTypeId());

		FunctionDefinition fddate = StdFunctions.FD_DATE_BAG;
		assertEquals(XACML3.ID_DATATYPE_DATE, fddate.getDataTypeId());

		FunctionDefinition fdtime = StdFunctions.FD_TIME_BAG;
		assertEquals(XACML3.ID_DATATYPE_TIME, fdtime.getDataTypeId());

		FunctionDefinition fddateTime = StdFunctions.FD_DATETIME_BAG;
		assertEquals(XACML3.ID_DATATYPE_DATETIME, fddateTime.getDataTypeId());

		FunctionDefinition fddayTimeDuration = StdFunctions.FD_DAYTIMEDURATION_FROM_STRING;
		assertEquals(XACML3.ID_DATATYPE_DAYTIMEDURATION, fddayTimeDuration.getDataTypeId());

		FunctionDefinition fdyearMonthDuration = StdFunctions.FD_YEARMONTHDURATION_FROM_STRING;
		assertEquals(XACML3.ID_DATATYPE_YEARMONTHDURATION, fdyearMonthDuration.getDataTypeId());

		FunctionDefinition fdanyURI = StdFunctions.FD_ANYURI_FROM_STRING;
		assertEquals(XACML3.ID_DATATYPE_ANYURI, fdanyURI.getDataTypeId());

		FunctionDefinition fdhexBinary = StdFunctions.FD_HEXBINARY_UNION;
		assertEquals(XACML3.ID_DATATYPE_HEXBINARY, fdhexBinary.getDataTypeId());

		FunctionDefinition fdbase64Binary = StdFunctions.FD_BASE64BINARY_UNION;
		assertEquals(XACML3.ID_DATATYPE_BASE64BINARY, fdbase64Binary.getDataTypeId());

		FunctionDefinition fdrfc822Name = StdFunctions.FD_RFC822NAME_FROM_STRING;
		assertEquals(XACML3.ID_DATATYPE_RFC822NAME, fdrfc822Name.getDataTypeId());

		FunctionDefinition fdx500Name = StdFunctions.FD_X500NAME_FROM_STRING;
		assertEquals(XACML3.ID_DATATYPE_X500NAME, fdx500Name.getDataTypeId());

//TODO - There are currently no functions that return XPathExpression objects
//		FunctionDefinition fdxpathExpression = StdFunctions.FD_XPATHEXPRESSION_FROM_STRING;
//		assertEquals(XACML3.ID_DATATYPE_XPATHEXPRESSION, fdxpathExpression.getDataTypeId());

		FunctionDefinition fdipAddress = StdFunctions.FD_IPADDRESS_FROM_STRING;
		assertEquals(XACML3.ID_DATATYPE_IPADDRESS, fdipAddress.getDataTypeId());

		FunctionDefinition fddnsName = StdFunctions.FD_DNSNAME_FROM_STRING;
		assertEquals(XACML3.ID_DATATYPE_DNSNAME, fddnsName.getDataTypeId());
	}
	
	/**
	 * check the type of return, single vs multiple values
	 */
	@Test
	public void testReturnsBag() {
		FunctionDefinition fdNotBag = StdFunctions.FD_BOOLEAN_EQUAL;
		assertFalse(fdNotBag.returnsBag());
		
		FunctionDefinitionBag<?> fdBag = (FunctionDefinitionBag<?>) StdFunctions.FD_STRING_BAG;
		assertTrue(fdBag.returnsBag());
	}
	
}