From b0b4b6397de13ac296ab82ed40df75fdf5846d83 Mon Sep 17 00:00:00 2001 From: bobbymander Date: Mon, 2 Apr 2018 14:35:37 -0400 Subject: JUnit additions for PDP,PDP-REST,SDK,XACML Issue-ID: POLICY-600 Change-Id: I8052451c3f66116f361f2963fcc2727c022dd4d9 Signed-off-by: bobbymander --- .../FunctionDefinitionCustomRegexpMatchTest.java | 48 ++++++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'ONAP-PDP') 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 listFa = new ArrayList(); listFa.add(fArg); listFa.add(fArg); - - // Try a match final FunctionDefinitionCustomRegexpMatch regexpMatch = new FunctionDefinitionCustomRegexpMatch(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 attValue2 = new StdAttributeValue(identifier2, testVal); + final FunctionArgument fArg2 = new FunctionArgumentAttributeValue(attValue2); + final List listFa2 = new ArrayList(); + listFa2.add(fArg2); + listFa2.add(fArg2); + assertEquals(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, + regexpMatch.evaluate(null, listFa2).getStatus().getStatusCode()); + + // Try error case 3 + final List listFa3 = new ArrayList(); + 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 attValue4 = new StdAttributeValue(identifier, testVal4); + final FunctionArgument fArg4 = new FunctionArgumentAttributeValue(attValue4); + final List listFa4 = new ArrayList(); + listFa4.add(fArg); + listFa4.add(fArg4); + assertEquals(false, regexpMatch.evaluate(null, listFa4).getValue().getValue()); + + // Try a comma match + final String testVal5 = "testVal2"; + final StdAttributeValue attValue5 = new StdAttributeValue(identifier, testVal5); + final FunctionArgument fArg5 = new FunctionArgumentAttributeValue(attValue5); + final List listFa5 = new ArrayList(); + listFa5.add(fArg); + listFa5.add(fArg5); + assertEquals(true, regexpMatch.evaluate(null, listFa5).getValue().getValue()); } } -- cgit 1.2.3-korg