aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolverTest.java27
-rwxr-xr-xsli/provider/src/test/resources/expression.tests32
2 files changed, 35 insertions, 24 deletions
diff --git a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolverTest.java b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolverTest.java
index d35d93c..6181548 100644
--- a/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolverTest.java
+++ b/sli/provider/src/test/java/org/openecomp/sdnc/sli/provider/SvcLogicExpressionResolverTest.java
@@ -35,6 +35,7 @@ import org.openecomp.sdnc.sli.provider.SvcLogicExpressionResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import junit.framework.Assert;
import junit.framework.TestCase;
public class SvcLogicExpressionResolverTest extends TestCase {
@@ -50,21 +51,22 @@ public class SvcLogicExpressionResolverTest extends TestCase {
try
{
- String testExpr = null;
SvcLogicContext ctx = new SvcLogicContext();
SvcLogicGraph graph = new SvcLogicGraph();
SvcLogicNode node = new SvcLogicNode(1, "return", graph);
graph.setRootNode(node);
-
- while ((testExpr = testsReader.readLine()) != null) {
- testExpr = testExpr.trim();
- if (testExpr.startsWith("#"))
+
+ String line = null;
+ int lineNo = 0;
+ while ((line = testsReader.readLine()) != null) {
+ ++lineNo;
+ if (line.startsWith("#"))
{
- testExpr = testExpr.substring(1).trim();
+ String testExpr = line.trim().substring(1).trim();
String[] nameValue = testExpr.split("=");
String name = nameValue[0].trim();
String value = nameValue[1].trim();
-
+
if (name.startsWith("$"))
{
LOG.info("Setting context attribute "+name+" = "+value);
@@ -80,6 +82,12 @@ public class SvcLogicExpressionResolverTest extends TestCase {
}
else
{
+ // if the line contains #, what comes before is the expression to evaluate, and what comes after
+ // is the expected value
+ String[] substrings = line.split("#");
+ String expectedValue = substrings.length > 1 ? substrings[1].trim() : null;
+ String testExpr = substrings[0].trim();
+
LOG.info("Parsing expression "+testExpr);
SvcLogicExpression expr = SvcLogicExpressionFactory.parse(testExpr);
if (expr == null)
@@ -96,7 +104,10 @@ public class SvcLogicExpressionResolverTest extends TestCase {
}
else
{
- LOG.info("Expression "+testExpr+" evaluates to "+exprValue);
+ LOG.info("Expression " + testExpr + " evaluates to " + exprValue);
+ if (expectedValue != null) {
+ Assert.assertEquals("Line " + lineNo + ": " + testExpr, expectedValue, exprValue);
+ }
}
}
}
diff --git a/sli/provider/src/test/resources/expression.tests b/sli/provider/src/test/resources/expression.tests
index c5661c3..848a0e7 100755
--- a/sli/provider/src/test/resources/expression.tests
+++ b/sli/provider/src/test/resources/expression.tests
@@ -6,19 +6,19 @@
# $network.segment[0].provider-segmentation-id = 1212
# $network.segment[1].provider-segmentation-id = 1213
# $availability-zone = mtsnj-esx-az01
-length($uni-circuit-id) > 0
-$uni-cir-units * 1000 * 100 / 100
-$uni-cir-units / 1000
-$uni-cir-units - 100
-$uni-cir-units + 100
-(value * 3 - $arg1 > 0) and (length($uni-circuit-id) == 0)
-'pg-'+$network.name
-$network.segment[0].provider-segmentation-id
-toUpperCase($network.name)
-toLowerCase($network.name)
-toUpperCase(substr($availability-zone, 0, 5))
-convertBase(1234, 10)
-convertBase(10, 16, 10)
-convertBase(ZZ, 36, 10)
-convertBase(10, 10, 36)
-(0 - 1) * $arg1
+length($uni-circuit-id) > 0 # true
+$uni-cir-units * 1000 * 100 / 100 # 10000
+$uni-cir-units / 1000 # 0
+$uni-cir-units - 100 # -90
+$uni-cir-units + 100 # 110
+(value * 3 - $arg1 > 0) and (length($uni-circuit-id) == 0) # true
+'pg-'+$network.name # pg-vCE0001.in
+$network.segment[0].provider-segmentation-id # 1212
+toUpperCase($network.name) # VCE0001.IN
+toLowerCase($network.name) # vce0001.in
+toUpperCase(substr($availability-zone, 0, 5)) # MTSNJ
+convertBase(1234, 10) # 1234
+convertBase(10, 16, 10) # 16
+convertBase(ZZ, 36, 10) # 1295
+convertBase(10, 10, 36) # a
+(0 - 1) * $arg1 # -1