aboutsummaryrefslogtreecommitdiffstats
path: root/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli
diff options
context:
space:
mode:
Diffstat (limited to 'sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli')
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/BadPlugin.java56
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyAdaptor.java54
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyRecorder.java14
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyResource.java97
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java60
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java30
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/LunchSelectorPlugin.java78
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java108
-rwxr-xr-xsli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java219
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolverTest.java123
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java38
11 files changed, 24 insertions, 853 deletions
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/BadPlugin.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/BadPlugin.java
deleted file mode 100644
index f5a39f50..00000000
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/BadPlugin.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.sli.provider;
-
-import java.util.Map;
-
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
-
-
-public class BadPlugin implements SvcLogicJavaPlugin {
- public String selectLunch(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- String day = parameters.get("day");
- if (day == null || day.length() < 1) {
- throw new SvcLogicException("What day is it?");
- }
- switch (day) {
- case ("monday"): {
- return "pizza";
- }
- case ("tuesday"): {
- return "soup";
- }
- case ("wednesday"): {
- return "salad";
- }
- case ("thursday"): {
- return "sushi";
- }
- case ("friday"): {
- return "bbq";
- }
- }
- throw new SvcLogicException("Lunch cannot be served");
- }
-}
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyAdaptor.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyAdaptor.java
deleted file mode 100644
index 0f3893ef..00000000
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyAdaptor.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- *
- */
-package org.onap.ccsdk.sli.core.sli.provider;
-
-import java.util.Map;
-import org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor;
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-
-/**
- * @author dt5972
- *
- */
-
-public class DummyAdaptor implements SvcLogicAdaptor {
-
- /* (non-Javadoc)
- * @see org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor#configure(java.lang.String, java.util.Map, org.onap.ccsdk.sli.core.sli.SvcLogicContext)
- */
- @Override
- public ConfigStatus configure(String key, Map<String, String> parameters, SvcLogicContext ctx) {
-
- if ("ALREADY_ACTIVE".equalsIgnoreCase(key)) {
- return ConfigStatus.ALREADY_ACTIVE;
- } else if ("NOT_FOUND".equalsIgnoreCase(key)) {
- return ConfigStatus.NOT_FOUND;
- }else if ("NOT_READY".equalsIgnoreCase(key)) {
- return ConfigStatus.NOT_READY;
- } else if ("FAILURE".equalsIgnoreCase(key)) {
- return ConfigStatus.FAILURE;
- } else if ("SUCCESS".equalsIgnoreCase(key)) {
- return ConfigStatus.SUCCESS;
- }
-
- return ConfigStatus.SUCCESS;
- }
-
- /* (non-Javadoc)
- * @see org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor#activate(java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext)
- */
- @Override
- public ConfigStatus activate(String key, SvcLogicContext ctx) {
- return ConfigStatus.SUCCESS;
- }
-
- /* (non-Javadoc)
- * @see org.onap.ccsdk.sli.core.sli.SvcLogicAdaptor#deactivate(java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext)
- */
- @Override
- public ConfigStatus deactivate(String key, SvcLogicContext ctx) {
- return ConfigStatus.SUCCESS;
- }
-
-}
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyRecorder.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyRecorder.java
deleted file mode 100644
index e87f9628..00000000
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyRecorder.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.onap.ccsdk.sli.core.sli.provider;
-
-import java.util.Map;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicRecorder;
-
-public class DummyRecorder implements SvcLogicRecorder {
-
- @Override
- public void record(Map<String, String> parmMap) throws SvcLogicException {
- return;
- }
-
-}
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyResource.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyResource.java
deleted file mode 100644
index 2f784186..00000000
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/DummyResource.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/**
- *
- */
-package org.onap.ccsdk.sli.core.sli.provider;
-
-import java.util.Map;
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
-
-/**
- * @author dt5972
- *
- */
-public class DummyResource implements SvcLogicResource {
-
- /* (non-Javadoc)
- * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#isAvailable(java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext)
- */
- @Override
- public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx)
- throws SvcLogicException {
- return QueryStatus.SUCCESS;
- }
-
- /* (non-Javadoc)
- * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#exists(java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext)
- */
- @Override
- public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx)
- throws SvcLogicException {
- return QueryStatus.SUCCESS;
- }
-
- /* (non-Javadoc)
- * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#query(java.lang.String, boolean, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext)
- */
- @Override
- public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix,
- String orderBy, SvcLogicContext ctx) throws SvcLogicException {
- return QueryStatus.SUCCESS;
- }
-
- /* (non-Javadoc)
- * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#reserve(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext)
- */
- @Override
- public QueryStatus reserve(String resource, String select, String key, String prefix, SvcLogicContext ctx)
- throws SvcLogicException {
- return QueryStatus.SUCCESS;
- }
-
- /* (non-Javadoc)
- * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#save(java.lang.String, boolean, boolean, java.lang.String, java.util.Map, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext)
- */
- @Override
- public QueryStatus save(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms,
- String prefix, SvcLogicContext ctx) throws SvcLogicException {
- return QueryStatus.SUCCESS;
- }
-
- /* (non-Javadoc)
- * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#release(java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext)
- */
- @Override
- public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
-
- return QueryStatus.SUCCESS;
- }
-
- /* (non-Javadoc)
- * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#delete(java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext)
- */
- @Override
- public QueryStatus delete(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
- return QueryStatus.SUCCESS;
- }
-
- /* (non-Javadoc)
- * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#notify(java.lang.String, java.lang.String, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext)
- */
- @Override
- public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx)
- throws SvcLogicException {
- return QueryStatus.SUCCESS;
- }
-
- /* (non-Javadoc)
- * @see org.onap.ccsdk.sli.core.sli.SvcLogicResource#update(java.lang.String, java.lang.String, java.util.Map, java.lang.String, org.onap.ccsdk.sli.core.sli.SvcLogicContext)
- */
- @Override
- public QueryStatus update(String resource, String key, Map<String, String> parms, String prefix,
- SvcLogicContext ctx) throws SvcLogicException {
- return QueryStatus.SUCCESS;
- }
-
-}
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java
deleted file mode 100644
index 33ce6f69..00000000
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ExecuteNodeExecutorTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.sli.provider;
-
-import java.util.Map.Entry;
-
-import org.onap.ccsdk.sli.core.sli.DuplicateValueException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
-import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
-import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
-import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
-import org.onap.ccsdk.sli.core.sli.provider.ExecuteNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.SvcLogicServiceImpl;
-
-import junit.framework.TestCase;
-
-public class ExecuteNodeExecutorTest extends TestCase {
- public class MockExecuteNodeExecutor extends ExecuteNodeExecutor {
-
- protected SvcLogicJavaPlugin getSvcLogicJavaPlugin(String pluginName) {
- return (SvcLogicJavaPlugin) new LunchSelectorPlugin();
- }
-
- protected String evaluate(SvcLogicExpression expr, SvcLogicNode node,
- SvcLogicContext ctx) throws SvcLogicException {
- return "selectLunch";
- }
- }
-
- public void testBadPlugin() throws DuplicateValueException, SvcLogicException {
- LunchSelectorPlugin p = new LunchSelectorPlugin();
- MockExecuteNodeExecutor execute = new MockExecuteNodeExecutor();
- SvcLogicNode node = new SvcLogicNode(0, "", "", new SvcLogicGraph());
- node.setAttribute("method", "selectLunch");
- SvcLogicPropertiesProvider resourceProvider = new SvcLogicPropertiesProviderImpl();
- execute.execute(new SvcLogicServiceImpl(resourceProvider), new SvcLogicNode(0, "", "", new SvcLogicGraph()), new SvcLogicContext());
- }
-
-}
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java
index 445df36f..6d466bc7 100644
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java
+++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java
@@ -24,7 +24,6 @@ package org.onap.ccsdk.sli.core.sli.provider;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
-
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -34,27 +33,46 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
+
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
import org.onap.ccsdk.sli.core.sli.SvcLogicParser;
import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceRegistration;
+import org.onap.ccsdk.sli.core.sli.provider.base.BlockNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.BreakNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.CallNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.ConfigureNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.DeleteNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.ExecuteNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.ExistsNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.ForNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.GetResourceNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.IsAvailableNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.NotifyNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.RecordNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.ReleaseNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.ReserveNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.ReturnNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.SaveNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.SetNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.AbstractSvcLogicNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.SvcLogicPropertiesProvider;
+import org.onap.ccsdk.sli.core.sli.provider.base.SwitchNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.UpdateNodeExecutor;
+import org.onap.ccsdk.sli.core.sli.provider.base.WhileNodeExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ITCaseSvcLogicGraphExecutor {
private static final Logger LOG = LoggerFactory.getLogger(SvcLogicGraph.class);
- private static final Map<String, SvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, SvcLogicNodeExecutor>() {
+ private static final Map<String, AbstractSvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, AbstractSvcLogicNodeExecutor>() {
{
put("block", new BlockNodeExecutor());
put("break", new BreakNodeExecutor());
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/LunchSelectorPlugin.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/LunchSelectorPlugin.java
deleted file mode 100644
index b86edb06..00000000
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/LunchSelectorPlugin.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.sli.provider;
-
-import java.util.Map;
-
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
-
-
-
-public class LunchSelectorPlugin implements SvcLogicJavaPlugin {
- public class UnknownLunchDayException extends Exception{
-
- public UnknownLunchDayException(String string) {
- super(string);
- }
-
- }
- class Sandwhich {
- String meat;
- String cheese;
-
- public Sandwhich(String meat, String cheese) {
- this.meat = meat;
- this.cheese = cheese;
- }
- }
-
- public String selectLunch(Map<String, String> parameters, SvcLogicContext ctx) throws Exception {
- String day = parameters.get("day");
- if (day == null || day.length() < 1) {
- throw new UnknownLunchDayException("What day is it?");
- }
- switch (day) {
- case ("monday"): {
- return "pizza";
- }
- case ("tuesday"): {
- return "soup";
- }
- case ("wednesday"): {
- return "salad";
- }
- case ("thursday"): {
- return "sushi";
- }
- case ("friday"): {
- return "bbq";
- }
- }
- throw new SvcLogicException("Lunch cannot be served");
- }
-
- public Sandwhich makeLunch(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- return new Sandwhich("ham", "american");
- }
-}
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java
deleted file mode 100644
index 98e0753d..00000000
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PluginTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.sli.provider;
-
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
-import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
-import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
-import org.onap.ccsdk.sli.core.sli.provider.ExecuteNodeExecutor;
-import org.onap.ccsdk.sli.core.sli.provider.SvcLogicExpressionResolver;
-
-import junit.framework.TestCase;
-
-public class PluginTest extends TestCase {
-
- // The existing plugins work just like a VoidDummyPlugin
- // They will return null simply because they are all void
- // The attribute emitsOutcome will not be present, the expected outcome is success when no exception is thrown by the plugin
- public void testOldPlugin() throws Exception {
- ExecuteNodeExecutor executor = new ExecuteNodeExecutor();
- SvcLogicJavaPlugin plugin = new VoidDummyPlugin();
-
- Class pluginClass = plugin.getClass();
- Method pluginMethod = pluginClass.getMethod("dummy", Map.class, SvcLogicContext.class);
- Map<String, String> parmMap = new HashMap<String, String>();
- SvcLogicContext ctx = new SvcLogicContext();
- Object o = pluginMethod.invoke(plugin, parmMap, ctx);
-
- SvcLogicGraph graph = new 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);
- }
-
- //Newer plugins can set the attribute emitsOutcome to true, if so they should return a string
- //The string represents the outcome value
- public void testNewPlugin() throws Exception {
- ExecuteNodeExecutor executor = new ExecuteNodeExecutor();
- SvcLogicJavaPlugin plugin = new LunchSelectorPlugin();
-
- Class pluginClass = plugin.getClass();
- Method pluginMethod = pluginClass.getMethod("selectLunch", Map.class, SvcLogicContext.class);
-
- Map<String, String> parmMap = new HashMap<String, String>();
- SvcLogicContext ctx = new SvcLogicContext();
-
- parmMap.put("day", "monday");
- Object o = pluginMethod.invoke(plugin, parmMap, ctx);
- SvcLogicGraph graph = new SvcLogicGraph();
- SvcLogicNode node = new SvcLogicNode(1, "return", graph);
- node.setAttribute("emitsOutcome", "true");
- String emitsOutcome = SvcLogicExpressionResolver.evaluate(node.getAttribute("emitsOutcome"), node, ctx);
- String outValue = executor.mapOutcome(o, emitsOutcome);
- assertEquals("pizza", outValue);
-
- parmMap.put("day", "tuesday");
- outValue = (String) pluginMethod.invoke(plugin, parmMap, ctx);
- o = pluginMethod.invoke(plugin, parmMap, ctx);
- outValue = executor.mapOutcome(o, emitsOutcome);
- assertEquals("soup",outValue);
-
- }
-
- //APPC had some legacy plugins returning objects which should not be treated as outcomes
- //The attribute emitsOutcome will not be set
- //The outcome should be success as it has always been
- public void testObjPlugin() throws Exception{
- ExecuteNodeExecutor executor = new ExecuteNodeExecutor();
- SvcLogicJavaPlugin plugin = new LunchSelectorPlugin();
-
- Class pluginClass = plugin.getClass();
- Method pluginMethod = pluginClass.getMethod("makeLunch", Map.class, SvcLogicContext.class);
-
- Map<String, String> parmMap = new HashMap<String, String>();
- SvcLogicContext ctx = new SvcLogicContext();
- Object o = pluginMethod.invoke(plugin, parmMap, ctx);
- SvcLogicGraph graph = new 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);
- }
-
-}
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java
deleted file mode 100755
index 7c6f4ce5..00000000
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SetNodeExecutorTest.java
+++ /dev/null
@@ -1,219 +0,0 @@
-package org.onap.ccsdk.sli.core.sli.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import java.util.LinkedList;
-import org.junit.Test;
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
-import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
-import org.onap.ccsdk.sli.core.sli.SvcLogicParser;
-
-public class SetNodeExecutorTest {
- @Test
- public void clearProperties() throws Exception {
- SetNodeExecutor sne = new SetNodeExecutor();
- SvcLogicContext ctx = new SvcLogicContext();
-
- SvcLogicParser slp = new SvcLogicParser();
- LinkedList<SvcLogicGraph> graph = slp.parse("src/test/resources/clearValues.xml");
- SvcLogicNode root = graph.getFirst().getRootNode();
- SvcLogicNode nodeOne = root.getOutcomeValue("1");
- SvcLogicNode nodeTwo = root.getOutcomeValue("2");
-
- sne.execute(nodeOne, ctx);
- sne.execute(nodeTwo, ctx);
-
- assertNull(ctx.getAttribute("si.field1"));
- assertNull(ctx.getAttribute("si.field2"));
- assertNull(ctx.getAttribute("si.field3"));
- assertNull(ctx.getAttribute("si.subarray[0]"));
- assertNull(ctx.getAttribute("si.subarray[1]"));
- assertNull(ctx.getAttribute("si.subarray[2]"));
- assertNull(ctx.getAttribute("si.subarray_length"));
- assertEquals("6", ctx.getAttribute("search1"));
- assertEquals("KeepMe!", ctx.getAttribute("simonSays"));
- }
-
- @Test
- public void clearMultipleArrayProperties() throws Exception {
- SetNodeExecutor sne = new SetNodeExecutor();
- SvcLogicContext ctx = new SvcLogicContext();
-
- SvcLogicParser slp = new SvcLogicParser();
- LinkedList<SvcLogicGraph> graph = slp.parse("src/test/resources/clearMultipleArrayValues.xml");
- SvcLogicNode root = graph.getFirst().getRootNode();
- SvcLogicNode nodeOne = root.getOutcomeValue("1");
- SvcLogicNode nodeTwo = root.getOutcomeValue("2");
-
- sne.execute(nodeOne, ctx);
- sne.execute(nodeTwo, ctx);
-
- assertNull(ctx.getAttribute("si[0].field1"));
- assertNull(ctx.getAttribute("si[1].field2"));
- assertNull(ctx.getAttribute("si[2].field3"));
- assertNull(ctx.getAttribute("si_length"));
- assertNull(ctx.getAttribute("si[0].subarray[0]"));
- assertNull(ctx.getAttribute("si[0].subarray[1]"));
- assertNull(ctx.getAttribute("si[0].subarray[2]"));
- assertNull(ctx.getAttribute("si[0].subarray_length"));
- assertEquals("6", ctx.getAttribute("search1"));
- assertEquals("KeepMe!", ctx.getAttribute("simonSays"));
- }
-
- @Test
- public void clearSingleArrayProperties() throws Exception {
- SetNodeExecutor sne = new SetNodeExecutor();
- SvcLogicContext ctx = new SvcLogicContext();
-
- SvcLogicParser slp = new SvcLogicParser();
- LinkedList<SvcLogicGraph> graph = slp.parse("src/test/resources/clearSingleArrayValues.xml");
- SvcLogicNode root = graph.getFirst().getRootNode();
- SvcLogicNode nodeOne = root.getOutcomeValue("1");
- SvcLogicNode nodeTwo = root.getOutcomeValue("2");
-
- sne.execute(nodeOne, ctx);
- sne.execute(nodeTwo, ctx);
-
- assertNull(ctx.getAttribute("si[0].field1"));
- assertNull(ctx.getAttribute("si[0].subarray[0]"));
- assertNull(ctx.getAttribute("si[0].subarray[1]"));
- assertNull(ctx.getAttribute("si[0].subarray[2]"));
- assertNull(ctx.getAttribute("si[0].subarray_length"));
-
- // TODO: This is just setting up elements as null but note reducing the size of Array.
- assertEquals("3",ctx.getAttribute("si_length"));
-
- assertEquals("2",ctx.getAttribute("si[1].field2"));
- assertEquals("3", ctx.getAttribute("si[2].field3"));
- assertEquals("6", ctx.getAttribute("search1"));
- assertEquals("KeepMe!", ctx.getAttribute("simonSays"));
- }
-
- @Test
- public void clearSingleSubArrayProperties() throws Exception {
- SetNodeExecutor sne = new SetNodeExecutor();
- SvcLogicContext ctx = new SvcLogicContext();
-
- SvcLogicParser slp = new SvcLogicParser();
- LinkedList<SvcLogicGraph> graph = slp.parse("src/test/resources/clearSingleSubArrayValues.xml");
- SvcLogicNode root = graph.getFirst().getRootNode();
- SvcLogicNode nodeOne = root.getOutcomeValue("1");
- SvcLogicNode nodeTwo = root.getOutcomeValue("2");
-
- sne.execute(nodeOne, ctx);
- sne.execute(nodeTwo, ctx);
-
- assertEquals("1",ctx.getAttribute("tmp.si[0].field1"));
- assertEquals("2",ctx.getAttribute("tmp.si[1].field2"));
- assertEquals("3", ctx.getAttribute("tmp.si[2].field3"));
- assertEquals("3", ctx.getAttribute("tmp.si_length"));
-
- assertEquals("a",ctx.getAttribute("tmp.si[0].subarray[0]"));
-
- // TODO: This is setting up element as Empty instead null
- //assertNull(ctx.getAttribute("tmp.si[0].subarray[1]"));
- assertEquals("", ctx.getAttribute("tmp.si[0].subarray[1]"));
-
- assertEquals("c", ctx.getAttribute("tmp.si[0].subarray[2]"));
- assertEquals("3", ctx.getAttribute("tmp.si[0].subarray_length"));
-
- assertEquals("x",ctx.getAttribute("tmp.si[1].subarray[0]"));
- assertEquals("y",ctx.getAttribute("tmp.si[1].subarray[1]"));
- assertEquals("z", ctx.getAttribute("tmp.si[1].subarray[2]"));
- assertEquals("3", ctx.getAttribute("tmp.si[1].subarray_length"));
-
- assertEquals("6", ctx.getAttribute("search1"));
- assertEquals("KeepMe!", ctx.getAttribute("simonSays"));
- }
-
- @Test
- public void clearSubArrayProperties() throws Exception {
- SetNodeExecutor sne = new SetNodeExecutor();
- SvcLogicContext ctx = new SvcLogicContext();
-
- SvcLogicParser slp = new SvcLogicParser();
- LinkedList<SvcLogicGraph> graph = slp.parse("src/test/resources/clearSubArrayValues.xml");
- SvcLogicNode root = graph.getFirst().getRootNode();
- SvcLogicNode nodeOne = root.getOutcomeValue("1");
- SvcLogicNode nodeTwo = root.getOutcomeValue("2");
-
- sne.execute(nodeOne, ctx);
- sne.execute(nodeTwo, ctx);
-
- assertEquals("1", ctx.getAttribute("si[0].field1"));
- assertEquals("2",ctx.getAttribute("si[1].field2"));
- assertEquals("3", ctx.getAttribute("si[2].field3"));
- assertEquals("3", ctx.getAttribute("si_length"));
- assertNull(ctx.getAttribute("si[0].subarray[0]"));
- assertNull(ctx.getAttribute("si[0].subarray[1]"));
- assertNull(ctx.getAttribute("si[0].subarray[2]"));
- assertNull(ctx.getAttribute("si[0].subarray_length"));
-
- assertEquals("6", ctx.getAttribute("search1"));
- assertEquals("KeepMe!", ctx.getAttribute("simonSays"));
- }
-
- @Test
- public void arrayPattern() {
- SetNodeExecutor sne = new SetNodeExecutor();
- String source = "one.two[0].three[0].four";
- assertEquals("one.two.three.four", source.replaceAll(sne.arrayPattern, ""));
- }
-
- @Test
- public void subtreeCopy() throws Exception {
- SetNodeExecutor sne = new SetNodeExecutor();
- SvcLogicContext ctx = new SvcLogicContext();
-
- SvcLogicParser slp = new SvcLogicParser();
- LinkedList<SvcLogicGraph> graph = slp.parse("src/test/resources/copyValues.xml");
- SvcLogicNode root = graph.getFirst().getRootNode();
- SvcLogicNode nodeOne = root.getOutcomeValue("1");
- SvcLogicNode nodeTwo = root.getOutcomeValue("2");
-
- sne.execute(nodeOne, ctx);
- sne.execute(nodeTwo, ctx);
-
- assertEquals("1", ctx.getAttribute("si.field1"));
- assertEquals("2", ctx.getAttribute("si.field2"));
- assertEquals("3", ctx.getAttribute("si.field3"));
- assertEquals("1", ctx.getAttribute("rootTwo.field1"));
- assertEquals("2", ctx.getAttribute("rootTwo.field2"));
- assertEquals("3", ctx.getAttribute("rootTwo.field3"));
- }
-
- @Test
- public void clearNestedSubArrayProperties() throws Exception {
- SetNodeExecutor sne = new SetNodeExecutor();
- SvcLogicContext ctx = new SvcLogicContext();
-
- SvcLogicParser slp = new SvcLogicParser();
- LinkedList<SvcLogicGraph> graph = slp.parse("src/test/resources/clearNestedSubArrayValues.xml");
- SvcLogicNode root = graph.getFirst().getRootNode();
- SvcLogicNode nodeOne = root.getOutcomeValue("1");
- SvcLogicNode nodeTwo = root.getOutcomeValue("2");
-
- sne.execute(nodeOne, ctx);
- sne.execute(nodeTwo, ctx);
-
- assertEquals("1", ctx.getAttribute("tmp.si[0].field1"));
- assertEquals("2",ctx.getAttribute("tmp.si[1].field2"));
- assertEquals("3", ctx.getAttribute("tmp.si[2].field3"));
- assertEquals("3", ctx.getAttribute("tmp.si_length"));
-
- assertNull(ctx.getAttribute("tmp.si[0].subarray[0]"));
- assertNull(ctx.getAttribute("tmp.si[0].subarray[1]"));
- assertNull(ctx.getAttribute("tmp.si[0].subarray[2]"));
- assertNull(ctx.getAttribute("tmp.si[0].subarray_length"));
-
- assertEquals("x", ctx.getAttribute("tmp.si[1].subarray[0]"));
- assertEquals("y",ctx.getAttribute("tmp.si[1].subarray[1]"));
- assertEquals("z", ctx.getAttribute("tmp.si[1].subarray[2]"));
- assertEquals("3", ctx.getAttribute("tmp.si[1].subarray_length"));
-
- assertEquals("6", ctx.getAttribute("search1"));
- assertEquals("KeepMe!", ctx.getAttribute("simonSays"));
- }
-
-}
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolverTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolverTest.java
deleted file mode 100644
index a08144ee..00000000
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicExpressionResolverTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.sli.provider;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.onap.ccsdk.sli.core.sli.SvcLogicExprListener;
-import org.onap.ccsdk.sli.core.sli.SvcLogicExpression;
-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.SvcLogicExpressionResolver;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-public class SvcLogicExpressionResolverTest extends TestCase {
-
-
- private static final Logger LOG = LoggerFactory
- .getLogger(SvcLogicExpressionResolver.class);
-
- public void testEvaluate()
- {
- InputStream testStr = getClass().getResourceAsStream("/expression.tests");
- BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
-
- try
- {
- SvcLogicContext ctx = new SvcLogicContext();
- SvcLogicGraph graph = new SvcLogicGraph();
- SvcLogicNode node = new SvcLogicNode(1, "return", graph);
- graph.setRootNode(node);
-
- String line = null;
- int lineNo = 0;
- while ((line = testsReader.readLine()) != null) {
- ++lineNo;
- if (line.startsWith("#"))
- {
- 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);
- ctx.setAttribute(name.substring(1), value);
- }
- else
- {
-
- LOG.info("Setting node attribute "+name+" = "+value);
- node.setAttribute(name, value);
-
- }
- }
- 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)
- {
- fail("Unable to parse expression "+testExpr);
- }
- else
- {
- LOG.info("Evaluating parsed expression "+expr.asParsedExpr());
- String exprValue = SvcLogicExpressionResolver.evaluate(expr, node, ctx);
- if (exprValue == null)
- {
- fail("Unable to evaluate expression "+testExpr);
- }
- else
- {
- LOG.info("Expression " + testExpr + " evaluates to " + exprValue);
- if (expectedValue != null) {
- Assert.assertEquals("Line " + lineNo + ": " + testExpr, expectedValue, exprValue);
- }
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- LOG.error("Caught exception", e);
- fail("Caught exception");
- }
- }
-
-}
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java
deleted file mode 100644
index 8c7b0d30..00000000
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/VoidDummyPlugin.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : CCSDK
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.ccsdk.sli.core.sli.provider;
-
-import java.util.Map;
-
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
-
-
-
-public class VoidDummyPlugin implements SvcLogicJavaPlugin {
-
- public void dummy(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- return;
- }
-
-}