5100dc7c55b5d7440f31e1678dd7eb48611e849b
[policy/engine.git] / ONAP-PDP / src / test / java / org / onap / policy / xacml / pdp / std / functions / FunctionDefinitionCustomRegexpMatchTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PDP
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
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 package org.onap.policy.xacml.pdp.std.functions;
21
22 import static org.junit.Assert.assertEquals;
23 import java.util.ArrayList;
24 import java.util.List;
25 import org.junit.Test;
26 import com.att.research.xacml.api.Identifier;
27 import com.att.research.xacml.api.XACML;
28 import com.att.research.xacml.std.IdentifierImpl;
29 import com.att.research.xacml.std.StdAttributeValue;
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;
34
35 public class FunctionDefinitionCustomRegexpMatchTest {
36         @Test
37         public final void testRegexp() {
38                 // Setup
39                 String testVal = "testVal";
40                 String testId = "function:testId";
41                 IdentifierImpl testFnId = new IdentifierImpl(testId);
42                 Identifier identifier = XACML.ID_DATATYPE_STRING;
43                 StdAttributeValue<String> attValue = new StdAttributeValue<String>(identifier, testVal);
44                 FunctionArgument fArg = new FunctionArgumentAttributeValue(attValue);
45                 List<FunctionArgument> listFA = new ArrayList<FunctionArgument>();
46                 listFA.add(fArg);
47                 listFA.add(fArg);
48                 
49                 // Try a match
50                 FunctionDefinitionCustomRegexpMatch<String> regexpMatch = new FunctionDefinitionCustomRegexpMatch<String>(testFnId, DataTypes.DT_STRING);
51                 ExpressionResult result = regexpMatch.evaluate(null, listFA);
52                 assertEquals(result.getStatus().isOk(), true);
53         }
54 }