add more unit testing, use constants for success/failure and improve some logging calls
Issue-ID: CCSDK-2064
Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Change-Id: I2c7039c706de1172bd506a20e96eb987cc86f211
--- /dev/null
+package org.onap.ccsdk.sli.core.sli;
+
+public class SvcLogicConstants {
+ public final static String SUCCESS = "success";
+ public final static String FAILURE = "failure";
+
+}
private HashMap<String, String> attributes;
- private String status = "success";
+ private String status = SvcLogicConstants.SUCCESS;
public SvcLogicContext()
{
{
return attributes.keySet();
}
+ public Boolean isSuccess() {
+ return status.equals(SvcLogicConstants.SUCCESS);
+ }
+ @Deprecated
public String getStatus() {
return status;
}
+ @Deprecated
public void setStatus(String status) {
this.status = status;
}
+ public void markFailed() {
+ this.status = SvcLogicConstants.FAILURE;
+ }
+
+ public void markSuccess() {
+ this.status = SvcLogicConstants.SUCCESS;
+ }
+
public Properties toProperties()
{
Properties props = new Properties();
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;
-
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
-
import junit.framework.TestCase;
public class SvcLogicContextTest extends TestCase {
private static final Logger LOG = LoggerFactory
.getLogger(SvcLogicContext.class);
-
+
public void testMerge() {
try {
}
+ public void testIsSuccess() {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setStatus(SvcLogicConstants.SUCCESS);
+ assertTrue(ctx.isSuccess());
+ ctx.setStatus(SvcLogicConstants.FAILURE);
+ assertFalse(ctx.isSuccess());
+ }
+
+ public void testMarkSuccess() {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.markSuccess();
+ assertTrue(ctx.isSuccess());
+ assertEquals(SvcLogicConstants.SUCCESS, ctx.getStatus());
+ }
+
+ public void testMarkFailed() {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.markFailed();
+ assertFalse(ctx.isSuccess());
+ assertEquals(SvcLogicConstants.FAILURE, ctx.getStatus());
+ }
+
}
package org.onap.ccsdk.sli.core.sli.provider.base;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
boolean isAtomic = "true".equalsIgnoreCase(atomicStr);
// Initialize status to success so that at least one outcome will execute
- ctx.setStatus("success");
+ ctx.markSuccess();
int numOutcomes = node.getNumOutcomes();
for (int i = 0; i < numOutcomes; i++) {
- if ("failure".equals(ctx.getStatus()) && isAtomic) {
+ if (SvcLogicConstants.FAILURE.equals(ctx.getStatus()) && isAtomic) {
LOG.info("Block - stopped executing nodes due to failure status");
return(null);
}
import java.util.Set;
import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
String adaptorName = SvcLogicExpressionResolver.evaluate(
node.getAttribute("adaptor"), node, ctx);
- String outValue = "failure";
+ String outValue = SvcLogicConstants.FAILURE;
if (LOG.isDebugEnabled()) {
LOG.debug("configure node encountered - looking for adaptor "
switch (confStatus) {
case SUCCESS:
- outValue = "success";
+ outValue = SvcLogicConstants.SUCCESS;
if ((activate != null) && (activate.length() > 0)) {
if ("true".equalsIgnoreCase(activate)) {
SvcLogicAdaptor.ConfigStatus activateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
break;
case FAILURE:
default:
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} else if ("false".equalsIgnoreCase(activate)) {
SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
break;
case FAILURE:
default:
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
}
}
break;
case FAILURE:
default:
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} else {
if ((activate != null) && (activate.length() > 0)) {
}
switch (activateStatus) {
case SUCCESS:
- outValue = "success";
+ outValue = SvcLogicConstants.SUCCESS;
break;
case ALREADY_ACTIVE:
outValue = ALREADY_ACTIVE;
break;
case FAILURE:
default:
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} else if ("false".equalsIgnoreCase(activate)) {
SvcLogicAdaptor.ConfigStatus deactivateStatus = SvcLogicAdaptor.ConfigStatus.FAILURE;
}
switch (deactivateStatus) {
case SUCCESS:
- outValue = "success";
+ outValue = SvcLogicConstants.SUCCESS;
break;
case ALREADY_ACTIVE:
outValue = ALREADY_ACTIVE;
break;
case FAILURE:
default:
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
}
} else {
LOG.warn("Nothing to configure - no parameters passed, and activate attribute is not set");
- outValue = "success";
+ outValue = SvcLogicConstants.SUCCESS;
}
}
} else {
package org.onap.ccsdk.sli.core.sli.provider.base;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
public class DeleteNodeExecutor extends AbstractSvcLogicNodeExecutor {
private static final Logger LOG = LoggerFactory.getLogger(DeleteNodeExecutor.class);
- private static final String FAILURE="failure";
+ private static final String FAILURE=SvcLogicConstants.FAILURE;
@Override
public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx)
try {
switch (resourcePlugin.delete(resourceType, key, ctx)) {
case SUCCESS:
- outValue = "success";
+ outValue = SvcLogicConstants.SUCCESS;
break;
case NOT_FOUND:
outValue = "not-found";
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
-import java.util.Set;
-
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
public class ExecuteNodeExecutor extends AbstractSvcLogicNodeExecutor {
private static final Logger LOG = LoggerFactory
.getLogger(ExecuteNodeExecutor.class);
- private static final String FAILURE="failure";
+ private static final String FAILURE=SvcLogicConstants.FAILURE;
private static final String pluginErrorMessage = "Could not execute plugin. SvcLogic status will be set to failure.";
public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node,
LOG.error(pluginErrorMessage, e);
}
outValue = FAILURE;
- ctx.setStatus(FAILURE);
+ ctx.markFailed();
} catch (IllegalAccessException e) {
LOG.error(pluginErrorMessage, e);
outValue = FAILURE;
- ctx.setStatus(FAILURE);
+ ctx.markFailed();
} catch (IllegalArgumentException e) {
LOG.error(pluginErrorMessage, e);
outValue = FAILURE;
- ctx.setStatus(FAILURE);
+ ctx.markFailed();
}
}
if (nodeEmitsOutcome) {
return (String) o;
} else {
- return "success";
+ return SvcLogicConstants.SUCCESS;
}
} else {
- return "success";
+ return SvcLogicConstants.SUCCESS;
}
}
package org.onap.ccsdk.sli.core.sli.provider.base;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
String key = SvcLogicExpressionResolver.evaluateAsKey(node.getAttribute("key"), node, ctx);
String pfx = SvcLogicExpressionResolver.evaluate(node.getAttribute("pfx"), node, ctx);
- String outValue = "failure";
+ String outValue = SvcLogicConstants.FAILURE;
if (LOG.isDebugEnabled()) {
LOG.debug("exists node encountered - looking for resource class " + plugin);
}
} catch (SvcLogicException e) {
LOG.error("Caught exception from resource plugin", e);
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} else {
LOG.warn("Could not find SvcLogicResource object for plugin " + plugin);
package org.onap.ccsdk.sli.core.sli.provider.base;
import org.onap.ccsdk.sli.core.sli.BreakNodeException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
for (int i = 0; i < numOutcomes; i++) {
- if ("failure".equals(ctx.getStatus()) && isAtomic) {
+ if (SvcLogicConstants.FAILURE.equals(ctx.getStatus()) && isAtomic) {
LOG.info("For - stopped executing nodes due to failure status");
return(null);
}
}
}
} catch (BreakNodeException br) {
- LOG.error("ForNodeExecutor caught break",br);
+ LOG.trace("ForNodeExecutor caught break" + br.getMessage());
}
return (null);
}
package org.onap.ccsdk.sli.core.sli.provider.base;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
orderBy = SvcLogicExpressionResolver.evaluateAsKey(orderByExpr, node, ctx);
}
- String outValue = "failure";
+ String outValue = SvcLogicConstants.FAILURE;
if (LOG.isDebugEnabled()) {
LOG.debug(node.getNodeType() + " node encountered - looking for resource class " + plugin);
try {
switch (resourcePlugin.query(resourceType, localOnly, select, key, pfx, orderBy, ctx)) {
case SUCCESS:
- outValue = "success";
+ outValue = SvcLogicConstants.SUCCESS;
break;
case NOT_FOUND:
outValue = "not-found";
break;
case FAILURE:
default:
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} catch (SvcLogicException e) {
LOG.error("Caught exception from resource plugin", e);
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} else {
LOG.warn("Could not find SvcLogicResource object for plugin " + plugin);
package org.onap.ccsdk.sli.core.sli.provider.base;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
String key = SvcLogicExpressionResolver.evaluateAsKey(node.getAttribute("key"), node, ctx);
String pfx = SvcLogicExpressionResolver.evaluate(node.getAttribute("pfx"), node, ctx);
- String outValue = "failure";
+ String outValue = SvcLogicConstants.FAILURE;
SvcLogicResource resourcePlugin = getSvcLogicResource(plugin);
}
} catch (SvcLogicException e) {
LOG.error("Caught exception from resource plugin", e);
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} else {
LOG.warn("Could not find SvcLogicResource object for plugin " + plugin);
package org.onap.ccsdk.sli.core.sli.provider.base;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
String action = SvcLogicExpressionResolver.evaluateAsKey(node.getAttribute("action"), node, ctx);
String key = SvcLogicExpressionResolver.evaluateAsKey(node.getAttribute("key"), node, ctx);
- String outValue = "failure";
+ String outValue = SvcLogicConstants.FAILURE;
if (LOG.isDebugEnabled()) {
LOG.debug("release node encountered - looking for resource class " + plugin);
try {
switch (resourcePlugin.notify(resourceType, action, key, ctx)) {
case SUCCESS:
- outValue = "success";
+ outValue = SvcLogicConstants.SUCCESS;
break;
case NOT_FOUND:
outValue = "not-found";
break;
case FAILURE:
default:
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} catch (SvcLogicException e) {
LOG.error("Caught exception from resource plugin", e);
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} else {
LOG.warn("Could not find SvcLogicResource object for plugin " + plugin);
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
throws SvcLogicException {
String plugin = SvcLogicExpressionResolver.evaluate(node.getAttribute("plugin"), node, ctx);
- String outValue = "failure";
+ String outValue = SvcLogicConstants.FAILURE;
Map<String, String> parmMap = getResolvedParameters(node,ctx);
recorder.record(parmMap);
} catch (SvcLogicException e) {
LOG.error("Caught exception from recorder plugin", e);
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} else {
LOG.warn("Could not find SvcLogicRecorder object for plugin " + plugin);
package org.onap.ccsdk.sli.core.sli.provider.base;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
String resourceType = SvcLogicExpressionResolver.evaluate(node.getAttribute("resource"), node, ctx);
String key = SvcLogicExpressionResolver.evaluateAsKey(node.getAttribute("key"), node, ctx);
- String outValue = "failure";
+ String outValue = SvcLogicConstants.FAILURE;
if (LOG.isDebugEnabled()) {
LOG.debug("release node encountered - looking for resource class " + plugin);
try {
switch (resourcePlugin.release(resourceType, key, ctx)) {
case SUCCESS:
- outValue = "success";
+ outValue = SvcLogicConstants.SUCCESS;
break;
case NOT_FOUND:
outValue = "not-found";
break;
case FAILURE:
default:
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} catch (SvcLogicException e) {
LOG.error("Caught exception from resource plugin", e);
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} else {
LOG.warn("Could not find SvcLogicResource object for plugin " + plugin);
package org.onap.ccsdk.sli.core.sli.provider.base;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
select = SvcLogicExpressionResolver.evaluateAsKey(selectExpr, node, ctx);
}
- String outValue = "failure";
+ String outValue = SvcLogicConstants.FAILURE;
if (LOG.isDebugEnabled()) {
LOG.debug("reserve node encountered - looking for resource class " + plugin);
try {
switch (resourcePlugin.reserve(resourceType, select, key, pfx, ctx)) {
case SUCCESS:
- outValue = "success";
+ outValue = SvcLogicConstants.SUCCESS;
break;
case NOT_FOUND:
outValue = "not-found";
break;
case FAILURE:
default:
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} catch (SvcLogicException e) {
LOG.error("Caught exception from resource plugin", e);
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} else {
LOG.warn("Could not find SvcLogicResource object for plugin " + plugin);
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
public class SaveNodeExecutor extends AbstractSvcLogicNodeExecutor {
private static final Logger LOG = LoggerFactory.getLogger(SaveNodeExecutor.class);
- private static final String FAILURE= "failure";
+ private static final String FAILURE= SvcLogicConstants.FAILURE;
@Override
public SvcLogicNode execute(SvcLogicServiceBase svc, SvcLogicNode node, SvcLogicContext ctx)
try {
switch (resourcePlugin.save(resourceType, force, localOnly, key, parmMap, pfx, ctx)) {
case SUCCESS:
- outValue = "success";
+ outValue = SvcLogicConstants.SUCCESS;
break;
case NOT_FOUND:
outValue = "not-found";
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
Map<String, String> parmMap = getResolvedParameters(node,ctx);
- String outValue = "failure";
+ String outValue = SvcLogicConstants.FAILURE;
if (LOG.isDebugEnabled()) {
LOG.debug("save node encountered - looking for resource class " + plugin);
try {
switch (resourcePlugin.update(resourceType, key, parmMap, pfx, ctx)) {
case SUCCESS:
- outValue = "success";
+ outValue = SvcLogicConstants.SUCCESS;
break;
case NOT_FOUND:
outValue = "not-found";
break;
case FAILURE:
default:
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} catch (SvcLogicException e) {
LOG.error("Caught exception from resource plugin", e);
- outValue = "failure";
+ outValue = SvcLogicConstants.FAILURE;
}
} else {
LOG.warn("Could not find SvcLogicResource object for plugin " + plugin);
}
LOG.debug("testResult was " + testResult + " which is not equal to true, exiting while loop.");
} catch (BreakNodeException e) {
- LOG.debug("WhileNodeExecutor caught break");
+ LOG.debug("WhileNodeExecutor caught break" + e.getMessage());
}
return (null);
}
--- /dev/null
+package org.onap.ccsdk.sli.core.sli.provider.base;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+import java.util.LinkedList;\r
+import java.util.Map;\r
+import java.util.Map.Entry;\r
+import org.junit.Test;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicParser;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicStore;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+public class GraphTests {\r
+\r
+ private static final Logger LOG = LoggerFactory.getLogger(GraphTests.class);\r
+ private static final SvcLogicStore store = new InMemorySvcLogicStore();\r
+ private static final HashMapResolver resolver = new HashMapResolver();\r
+ private static final SvcLogicServiceBase svc = new SvcLogicServiceImplBase(store, resolver);\r
+ private static final SvcLogicParser p = new SvcLogicParser();\r
+ // Write a very simple recorder so record nodes can be used during debugging\r
+ private static final SvcLogicRecorder recorder = new SvcLogicRecorder() {\r
+ @Override\r
+ public void record(Map<String, String> map) throws SvcLogicException {\r
+ map.remove("level");\r
+ for (Entry<String, String> entry : map.entrySet()) {\r
+ LOG.debug(entry.getKey() + " = " + entry.getValue());\r
+ }\r
+ }\r
+ };\r
+\r
+ @Test\r
+ public void testBreakNode() throws Exception {\r
+ // This graph as a for node that will loop with start 0 and end 999\r
+ // in the loop idx is printed and variable "a" is incremented by 1\r
+ // there is an if block in the loop that when a equals 2 a break node should execute and break out of the for\r
+ // loop\r
+ SvcLogicContext ctx = executeGraph("src/test/resources/breakGraph.xml");\r
+ assertTrue(ctx.isSuccess());\r
+ assertEquals("2", ctx.getAttribute("idx")); // the break should happen when idx equals 2\r
+ assertEquals("3", ctx.getAttribute("a")); // incrementing a happens before the break so a should be idx + 1\r
+ }\r
+\r
+ public SvcLogicContext executeGraph(String pathToGraph) throws SvcLogicException {\r
+ return executeGraph(pathToGraph, new SvcLogicContext());\r
+ }\r
+\r
+ public SvcLogicContext executeGraph(String pathToGraph, SvcLogicContext context) throws SvcLogicException {\r
+ resolver.addSvcLogicRecorder("org.onap.ccsdk.sli.core.sli.recording.Slf4jRecorder", recorder);\r
+ LinkedList<SvcLogicGraph> graphList = p.parse(pathToGraph);\r
+ SvcLogicGraph graph = graphList.get(0);\r
+ store.store(graph);\r
+ store.activate(graph);\r
+ return svc.execute(graph, context);\r
+ }\r
+\r
+}\r
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
-
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
SvcLogicNode node = new SvcLogicNode(1, "return", graph);
String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx);
String outValue = executor.mapOutcome(o, emitsOutcome);
- assertEquals("success",outValue);
+ assertEquals(SvcLogicConstants.SUCCESS,outValue);
}
//Newer plugins can set the attribute emitsOutcome to true, if so they should return a string
SvcLogicNode node = new SvcLogicNode(1, "return", graph);
String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx);
String outValue = executor.mapOutcome(o, emitsOutcome);
- assertEquals("success",outValue);
+ assertEquals(SvcLogicConstants.SUCCESS,outValue);
}
}
--- /dev/null
+<service-logic\r
+ xmlns='http://www.onap.org/sdnc/svclogic'\r
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.onap.org/sdnc/svclogic ./svclogic.xsd' module='JUNIT' version='1'>\r
+ <method rpc='BREAK' mode='sync'>\r
+ <block>\r
+ <set>\r
+ <parameter name='a' value='0' />\r
+ </set>\r
+ <for index='idx' start='0' end='999' >\r
+ <record plugin="org.onap.ccsdk.sli.core.sli.recording.Slf4jRecorder">\r
+ <parameter name="logger" value="message-log" />\r
+ <parameter name="level" value="error" />\r
+ <parameter name="field1" value="`$idx`" />\r
+ </record>\r
+ <set>\r
+ <parameter name='a' value='`$a + 1`' />\r
+ </set>\r
+ <switch test="`$idx == 2`">\r
+ <outcome value='true'>\r
+ <break/>\r
+ </outcome>\r
+ </switch>\r
+ </for>\r
+ </block>\r
+ </method>\r
+</service-logic>
\ No newline at end of file
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
try {
checkParameters(parameters, new String[]{"root"}, LOG);
} catch (Exception ex) {
- return "failure";
+ return SvcLogicConstants.FAILURE;
}
String root = parameters.get("root");
if (StringUtils.isEmpty(root)) {
- return "failure";
+ return SvcLogicConstants.FAILURE;
}
// set context memory to the the properties passed with root as prefix
setParameterValuesToRoot(parameters, ctx, root);
- return "success";
+ return SvcLogicConstants.SUCCESS;
}
private static boolean setParameterValuesToRoot(Map<String, String> parameters, SvcLogicContext ctx, String root) {
checkParameters(parameters, new String[]{"prefixKey", "keyName", "keyValue"}, LOG);
} catch (Exception e) {
LOG.error("a required parameter is missing");
- return "failure";
+ return SvcLogicConstants.FAILURE;
}
String prefixKey = parameters.get("prefixKey");
if (StringUtils.isEmpty(keyName) || StringUtils.isEmpty(keyValue) || StringUtils.isEmpty(prefixKey)) {
LOG.error("a required parameters value is empty or null");
- return "failure";
+ return SvcLogicConstants.FAILURE;
}
int listLength = getArrayLength(ctx, prefixKey);
+ "but " + map.size() + " entries were found in context memory "
+ "where the key begins with: " + prefixKey);
- return "failure";
+ return SvcLogicConstants.FAILURE;
}
} else if (ctxListContains(containParams, ctx) == "false") {
setNewEntryInList(parameters, ctx, keyName, keyValue, prefixKey, valuePrefixKey, listLength);
} catch (SvcLogicException e) {
LOG.error("Call to ctxListContains failed: " + e.getMessage());
- return "failure";
+ return SvcLogicConstants.FAILURE;
}
- return "success";
+ return SvcLogicConstants.SUCCESS;
}
private static void setNewEntryInList(Map<String, String> parameters, SvcLogicContext ctx, String keyName,
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils.LogLevel;
Map<String, String> parameters = new HashMap<>();
parameters.put("root", "RootVal");
parameters.put("valueRoot", "ValueRootVal");
- assertEquals("success", SliPluginUtils.setPropertiesForRoot(parameters, ctx));
+ assertEquals(SvcLogicConstants.SUCCESS, SliPluginUtils.setPropertiesForRoot(parameters, ctx));
}
@Test
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-
import java.util.HashMap;
import java.util.Random;
-
import org.junit.Before;
import org.junit.Test;
+import org.onap.ccsdk.sli.core.sli.SvcLogicConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.slf4j.Logger;
parameters.put("keyName", "testKey");
parameters.put("keyValue", "testValue");
- assertEquals("success", SliPluginUtils.setPropertiesForList(parameters, ctx));
+ assertEquals(SvcLogicConstants.SUCCESS, SliPluginUtils.setPropertiesForList(parameters, ctx));
}
}
package org.onap.ccsdk.sli.core.utils;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class JREFileResolverTest {
package org.onap.ccsdk.sli.core.utils;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class KarafRootFileResolverTest {
package org.onap.ccsdk.sli.core.utils.common;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver;
@Test
public void getSuccessfulResolutionMessage() throws Exception {
- final PropertiesFileResolver resolver = new BundleContextFileResolver("success", BundleContexFileResolverTest.class);
+ final PropertiesFileResolver resolver =
+ new BundleContextFileResolver("success", BundleContexFileResolverTest.class);
assertEquals("success", resolver.getSuccessfulResolutionMessage());
}
package org.onap.ccsdk.sli.core.utils.common;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import java.io.File;
import java.util.Optional;
import org.junit.Test;
package org.onap.ccsdk.sli.core.utils.common;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import java.io.File;
import java.util.Optional;
import org.junit.Test;
package org.onap.ccsdk.sli.core.utils.dblib;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import java.io.File;
import java.util.Optional;
import org.junit.Test;
package org.onap.ccsdk.sli.core.utils.dblib;
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import java.io.File;
import java.util.Optional;
import org.junit.Test;