From 82e7550ed8f20025dba7f2a7afb1cd8ae2c7b017 Mon Sep 17 00:00:00 2001 From: "Smokowski, Kevin (ks6305)" Date: Thu, 23 May 2019 15:50:35 +0000 Subject: Add additional SvcLogicParser junit Add additional SvcLogicParser junit Change-Id: I3186d2ce0981ac20c5655e5f88d8cb2e4ed55b9f Issue-ID: CCSDK-1361 Signed-off-by: Smokowski, Kevin (ks6305) --- .../base/SvcLogicExpressionResolverTest.java | 157 +++++++++++++++++++++ .../src/test/resources/expressions.xml | 55 ++++++++ 2 files changed, 212 insertions(+) create mode 100755 sli/provider-base/src/test/resources/expressions.xml diff --git a/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolverTest.java b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolverTest.java index bf4a2622..054b38d0 100644 --- a/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolverTest.java +++ b/sli/provider-base/src/test/java/org/onap/ccsdk/sli/core/sli/provider/base/SvcLogicExpressionResolverTest.java @@ -24,6 +24,7 @@ package org.onap.ccsdk.sli.core.sli.provider.base; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; +import java.util.LinkedList; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicExprListener; @@ -32,6 +33,7 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicExpressionFactory; import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; import org.onap.ccsdk.sli.core.sli.SvcLogicNode; import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicExpressionResolver; +import org.onap.ccsdk.sli.core.sli.SvcLogicParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -120,4 +122,159 @@ public class SvcLogicExpressionResolverTest extends TestCase { } } + public void testSvcLogicExpressions() throws Exception { + SwitchNodeExecutor switchNodeExecutor = new SwitchNodeExecutor(); + SetNodeExecutor setNodeExecutor = new SetNodeExecutor(); + SvcLogicContext ctx = new SvcLogicContext(); + SvcLogicParser slp = new SvcLogicParser(); + LinkedList graph = slp.parse("src/test/resources/expressions.xml"); + SvcLogicNode root = graph.getFirst().getRootNode(); +//Test a set node that makes use of arithmetic operations +/* + + + + + + + + + + +*/ +//the node matching outcome value 1 comes from parsing the block of xml above + ctx.setAttribute("a", "5"); + ctx.setAttribute("b", "3"); + setNodeExecutor.execute(root.getOutcomeValue("1"), ctx); + assertEquals("2", ctx.getAttribute("add")); + assertEquals("1", ctx.getAttribute("sub")); + assertEquals("3", ctx.getAttribute("div")); + assertEquals("4", ctx.getAttribute("multi")); + assertEquals("2", ctx.getAttribute("addDoubleQuotes")); + assertEquals("1", ctx.getAttribute("subDoubleQuotes")); + assertEquals("3", ctx.getAttribute("divDoubleQuotes")); + assertEquals("4", ctx.getAttribute("multiDoubleQuotes")); + +//Test a set node that makes use of string concatenation +/* + + + + + + + + + + +*/ +//the node matching outcome value 2 comes from parsing the block of xml above + ctx.setAttribute("a", "cat"); + ctx.setAttribute("b", "dog"); + setNodeExecutor.execute(root.getOutcomeValue("2"), ctx); + assertEquals("catdog", ctx.getAttribute("varA")); + assertEquals("catliteral", ctx.getAttribute("varB")); + assertEquals("literaldog", ctx.getAttribute("varC")); + assertEquals("tooliteral", ctx.getAttribute("varD")); + assertEquals("catdog", ctx.getAttribute("varADoubleQuotes")); + assertEquals("catliteral", ctx.getAttribute("varBDoubleQuotes")); + assertEquals("literaldog", ctx.getAttribute("varCDoubleQuotes")); + assertEquals("tooliteral", ctx.getAttribute("varDDoubleQuotes")); + +//Shows how backticks interact with + operator +/* + + + + + + + + +*/ +//the node matching outcome value 3 comes from parsing the block of xml above + ctx.setAttribute("portNumber", "2"); + ctx.setAttribute("slot", "3"); + ctx.setAttribute("shelf", "1"); + + setNodeExecutor.execute(root.getOutcomeValue("3"), ctx); + assertEquals("2", ctx.getAttribute("testOne")); + assertEquals("\"1\" +\"1\"", ctx.getAttribute("testThree")); + assertEquals("6", ctx.getAttribute("testFour")); + assertEquals("2", ctx.getAttribute("testOneDoubleQuotes")); + assertEquals("'1' +'1'", ctx.getAttribute("testThreeDoubleQuotes")); + assertEquals("6", ctx.getAttribute("testFourDoubleQuotes")); + + ctx.setAttribute("a", "5"); + ctx.setAttribute("b", "3"); + + // series of switch statements showing and or != > < >= == <= + // the XML for the node is commented above the line that evaluates that node, the switch statements are single line + + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("4"), ctx)); + + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("5"), ctx)); + + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("6"), ctx)); + + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("7"), ctx)); + + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("8"), ctx)); + + // + assertEquals("false",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("9"), ctx)); + + // + assertEquals("false",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("10"), ctx)); + + // + assertEquals("false",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("11"), ctx)); + + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("12"), ctx)); + + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("13"), ctx)); + + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("14"), ctx)); + + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("15"), ctx)); + + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("16"), ctx)); + + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("17"), ctx)); + + // Series of switch statements that show the effect of using backticks + + ctx.setAttribute("literalStartingWithDollarSign", "DONT READ ME!"); + // + assertEquals("$literalStartingWithDollarSign",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("18"), ctx)); + + ctx.setAttribute("dollarSignFollowedByVariableSurroundedinBackticks", "README"); + // + assertEquals("README",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("19"), ctx)); + + ctx.setAttribute("a", "2"); + ctx.setAttribute("b", "2"); + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("20"), ctx)); + + // + assertEquals("true",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("21"), ctx)); + + // + assertEquals("$a == $b",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("22"), ctx)); + + // + assertEquals("$a == $b",switchNodeExecutor.evaluateNodeTest(root.getOutcomeValue("23"), ctx)); + } } diff --git a/sli/provider-base/src/test/resources/expressions.xml b/sli/provider-base/src/test/resources/expressions.xml new file mode 100755 index 00000000..79118570 --- /dev/null +++ b/sli/provider-base/src/test/resources/expressions.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit 1.2.3-korg