2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 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.xacml.pdp.std.functions;
23 import static org.junit.Assert.assertEquals;
25 import com.att.research.xacml.api.Identifier;
26 import com.att.research.xacml.api.XACML;
27 import com.att.research.xacml.std.IdentifierImpl;
28 import com.att.research.xacml.std.StdAttributeValue;
29 import com.att.research.xacml.std.StdStatusCode;
30 import com.att.research.xacml.std.datatypes.DataTypes;
31 import com.att.research.xacmlatt.pdp.policy.ExpressionResult;
32 import com.att.research.xacmlatt.pdp.policy.FunctionArgument;
33 import com.att.research.xacmlatt.pdp.policy.FunctionArgumentAttributeValue;
35 import java.util.ArrayList;
36 import java.util.List;
38 import org.junit.Test;
40 public class FunctionDefinitionCustomRegexpMatchTest {
42 public final void testRegexp() {
44 final String testVal = "testVal,testVal2";
45 final String testId = "function:testId";
46 final IdentifierImpl testFnId = new IdentifierImpl(testId);
47 final Identifier identifier = XACML.ID_DATATYPE_STRING;
48 final StdAttributeValue<String> attValue = new StdAttributeValue<String>(identifier, testVal);
49 final FunctionArgument fArg = new FunctionArgumentAttributeValue(attValue);
50 final List<FunctionArgument> listFa = new ArrayList<FunctionArgument>();
53 final FunctionDefinitionCustomRegexpMatch<String> regexpMatch =
54 new FunctionDefinitionCustomRegexpMatch<String>(testFnId, DataTypes.DT_STRING);
57 final ExpressionResult result = regexpMatch.evaluate(null, listFa);
58 assertEquals(true, result.getValue().getValue());
61 assertEquals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR,
62 regexpMatch.evaluate(null, null).getStatus().getStatusCode());
65 final Identifier identifier2 = XACML.ID_DATATYPE_BOOLEAN;
66 final StdAttributeValue<String> attValue2 = new StdAttributeValue<String>(identifier2, testVal);
67 final FunctionArgument fArg2 = new FunctionArgumentAttributeValue(attValue2);
68 final List<FunctionArgument> listFa2 = new ArrayList<FunctionArgument>();
71 assertEquals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR,
72 regexpMatch.evaluate(null, listFa2).getStatus().getStatusCode());
75 final List<FunctionArgument> listFa3 = new ArrayList<FunctionArgument>();
78 assertEquals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR,
79 regexpMatch.evaluate(null, listFa3).getStatus().getStatusCode());
82 final String testVal4 = "testVal3";
83 final StdAttributeValue<String> attValue4 = new StdAttributeValue<String>(identifier, testVal4);
84 final FunctionArgument fArg4 = new FunctionArgumentAttributeValue(attValue4);
85 final List<FunctionArgument> listFa4 = new ArrayList<FunctionArgument>();
88 assertEquals(false, regexpMatch.evaluate(null, listFa4).getValue().getValue());
91 final String testVal5 = "testVal2";
92 final StdAttributeValue<String> attValue5 = new StdAttributeValue<String>(identifier, testVal5);
93 final FunctionArgument fArg5 = new FunctionArgumentAttributeValue(attValue5);
94 final List<FunctionArgument> listFa5 = new ArrayList<FunctionArgument>();
97 assertEquals(true, regexpMatch.evaluate(null, listFa5).getValue().getValue());