diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2018-04-03 12:32:48 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-04-03 12:32:48 +0000 |
commit | def1c29d8a8c4372e006b1388a456bca92d57500 (patch) | |
tree | ae973c41a0fe48a2afc90dcae431598b34583a62 /ONAP-PDP | |
parent | 145ef110e6ee7108846c91a509e33e65b5b64306 (diff) | |
parent | b0b4b6397de13ac296ab82ed40df75fdf5846d83 (diff) |
Merge "JUnit additions for PDP,PDP-REST,SDK,XACML"
Diffstat (limited to 'ONAP-PDP')
-rw-r--r-- | ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatchTest.java | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatchTest.java b/ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatchTest.java index da1759a22..08a01c879 100644 --- a/ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatchTest.java +++ b/ONAP-PDP/src/test/java/org/onap/policy/xacml/pdp/std/functions/FunctionDefinitionCustomRegexpMatchTest.java @@ -26,6 +26,7 @@ import com.att.research.xacml.api.Identifier; import com.att.research.xacml.api.XACML; import com.att.research.xacml.std.IdentifierImpl; import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.std.StdStatusCode; import com.att.research.xacml.std.datatypes.DataTypes; import com.att.research.xacmlatt.pdp.policy.ExpressionResult; import com.att.research.xacmlatt.pdp.policy.FunctionArgument; @@ -40,7 +41,7 @@ public class FunctionDefinitionCustomRegexpMatchTest { @Test public final void testRegexp() { // Setup - final String testVal = "testVal"; + final String testVal = "testVal,testVal2"; final String testId = "function:testId"; final IdentifierImpl testFnId = new IdentifierImpl(testId); final Identifier identifier = XACML.ID_DATATYPE_STRING; @@ -49,11 +50,50 @@ public class FunctionDefinitionCustomRegexpMatchTest { final List<FunctionArgument> listFa = new ArrayList<FunctionArgument>(); listFa.add(fArg); listFa.add(fArg); - - // Try a match final FunctionDefinitionCustomRegexpMatch<String> regexpMatch = new FunctionDefinitionCustomRegexpMatch<String>(testFnId, DataTypes.DT_STRING); + + // Try a match final ExpressionResult result = regexpMatch.evaluate(null, listFa); - assertEquals(result.getStatus().isOk(), true); + assertEquals(true, result.getValue().getValue()); + + // Try error case 1 + assertEquals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, + regexpMatch.evaluate(null, null).getStatus().getStatusCode()); + + // Try error case 2 + final Identifier identifier2 = XACML.ID_DATATYPE_BOOLEAN; + final StdAttributeValue<String> attValue2 = new StdAttributeValue<String>(identifier2, testVal); + final FunctionArgument fArg2 = new FunctionArgumentAttributeValue(attValue2); + final List<FunctionArgument> listFa2 = new ArrayList<FunctionArgument>(); + listFa2.add(fArg2); + listFa2.add(fArg2); + assertEquals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, + regexpMatch.evaluate(null, listFa2).getStatus().getStatusCode()); + + // Try error case 3 + final List<FunctionArgument> listFa3 = new ArrayList<FunctionArgument>(); + listFa3.add(fArg); + listFa3.add(fArg2); + assertEquals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, + regexpMatch.evaluate(null, listFa3).getStatus().getStatusCode()); + + // Try a mismatch + final String testVal4 = "testVal3"; + final StdAttributeValue<String> attValue4 = new StdAttributeValue<String>(identifier, testVal4); + final FunctionArgument fArg4 = new FunctionArgumentAttributeValue(attValue4); + final List<FunctionArgument> listFa4 = new ArrayList<FunctionArgument>(); + listFa4.add(fArg); + listFa4.add(fArg4); + assertEquals(false, regexpMatch.evaluate(null, listFa4).getValue().getValue()); + + // Try a comma match + final String testVal5 = "testVal2"; + final StdAttributeValue<String> attValue5 = new StdAttributeValue<String>(identifier, testVal5); + final FunctionArgument fArg5 = new FunctionArgumentAttributeValue(attValue5); + final List<FunctionArgument> listFa5 = new ArrayList<FunctionArgument>(); + listFa5.add(fArg); + listFa5.add(fArg5); + assertEquals(true, regexpMatch.evaluate(null, listFa5).getValue().getValue()); } } |