diff options
3 files changed, 143 insertions, 10 deletions
diff --git a/appc-config/appc-flow-controller/provider/pom.xml b/appc-config/appc-flow-controller/provider/pom.xml index 84de63be8..19cbee450 100644 --- a/appc-config/appc-flow-controller/provider/pom.xml +++ b/appc-config/appc-flow-controller/provider/pom.xml @@ -36,11 +36,6 @@ <dependencies> <dependency> - <groupId>equinoxSDK381</groupId> - <artifactId>org.eclipse.osgi</artifactId> - <version>${equinox.osgi.version}</version> - </dependency> - <dependency> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>sli-provider</artifactId> </dependency> diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/GraphExecutor.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/GraphExecutor.java index 7a1e58284..261d64e7a 100644 --- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/GraphExecutor.java +++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/GraphExecutor.java @@ -3,6 +3,8 @@ * ONAP : APPC * ================================================================================ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +22,6 @@ */ package org.onap.appc.flow.controller.executorImpl; -import org.json.JSONObject; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; import java.util.Enumeration; import java.util.Map; import java.util.Properties; @@ -35,12 +34,14 @@ import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; public class GraphExecutor implements FlowExecutorInterface { - private static final EELFLogger log = EELFManager.getInstance().getLogger(GraphExecutor.class); - private static final String SVC_LOGIC_STATUS_PARAM = "SvcLogic.status"; + private static EELFLogger log = EELFManager.getInstance().getLogger(GraphExecutor.class); + static final String SVC_LOGIC_STATUS_PARAM = "SvcLogic.status"; private SvcLogicService svcLogic = null; diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/executorImpl/GraphExecutorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/executorImpl/GraphExecutorTest.java new file mode 100644 index 000000000..d7a4ce22f --- /dev/null +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/executorImpl/GraphExecutorTest.java @@ -0,0 +1,137 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 Ericsson + * ================================================================================ + * 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.appc.flow.controller.executorImpl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.onap.appc.flow.controller.data.Transaction; +import org.onap.appc.flow.controller.utils.FlowControllerConstants; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService; +import org.osgi.framework.FrameworkUtil; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.reflect.Whitebox; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFLogger.Level; +import com.att.eelf.configuration.EELFManager; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +@RunWith(PowerMockRunner.class) +@PrepareForTest(FrameworkUtil.class) +public class GraphExecutorTest { + + private final BundleContext bundleContext = Mockito.mock(BundleContext.class); + private final Bundle bundleService = Mockito.mock(Bundle.class); + private final ServiceReference sref = Mockito.mock(ServiceReference.class); + private SvcLogicService svcLogic = null; + private Map<String, String> params; + private EELFLogger log = EELFManager.getInstance().getLogger(GraphExecutor.class); + + @Rule + public ExpectedException expectedEx = ExpectedException.none(); + + @Before + public void setUp() throws NoSuchFieldException, IllegalAccessException { + log.setLevel(Level.DEBUG); + svcLogic = Mockito.mock(SvcLogicService.class); + PowerMockito.mockStatic(FrameworkUtil.class); + PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService); + PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext); + PowerMockito.when(bundleContext.getServiceReference(SvcLogicService.NAME)).thenReturn(sref); + PowerMockito.when(bundleContext.<SvcLogicService>getService(sref)).thenReturn(svcLogic); + params = new HashMap<>(); + } + + @Test + public void testExecuteGraph() throws SvcLogicException { + GraphExecutor graphExecutor = new GraphExecutor(); + Whitebox.setInternalState(GraphExecutor.class, "log", log); + Properties properties = new Properties(); + properties.put("TEST", "TEST"); + Mockito.when(svcLogic.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(properties); + assertEquals(properties, graphExecutor.executeGraph(null, null, null, null, new Properties())); + } + + @Test + public void testExecute() throws Exception { + GraphExecutor graphExecutor = new GraphExecutor(); + Whitebox.setInternalState(GraphExecutor.class, "log", log); + Properties properties = new Properties(); + properties.put("TEST", "TEST"); + Transaction transaction = Mockito.spy(new Transaction()); + transaction.setExecutionRPC("EXECUTION_RPC"); + transaction.setPayload("PAYLOAD"); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("TEST", "TEST"); + Mockito.when(svcLogic.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(properties); + assertNull(graphExecutor.execute(transaction, ctx)); + } + + @Test + public void testExecuteFailure() throws Exception { + GraphExecutor graphExecutor = new GraphExecutor(); + Whitebox.setInternalState(GraphExecutor.class, "log", log); + Properties properties = new Properties(); + properties.put(GraphExecutor.SVC_LOGIC_STATUS_PARAM, FlowControllerConstants.FAILURE); + Transaction transaction = Mockito.spy(new Transaction()); + transaction.setExecutionRPC("EXECUTION_RPC"); + transaction.setPayload("PAYLOAD"); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("TEST", "TEST"); + Mockito.when(svcLogic.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(properties); + assertNull(graphExecutor.execute(transaction, ctx)); + } + + @Test + public void testExecuteSuccess() throws Exception { + GraphExecutor graphExecutor = new GraphExecutor(); + Whitebox.setInternalState(GraphExecutor.class, "log", log); + Properties properties = new Properties(); + properties.put(GraphExecutor.SVC_LOGIC_STATUS_PARAM, FlowControllerConstants.SUCCESS); + Transaction transaction = Mockito.spy(new Transaction()); + transaction.setExecutionRPC("EXECUTION_RPC"); + transaction.setPayload("PAYLOAD"); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("TEST", "TEST"); + Mockito.when(svcLogic.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(properties); + assertNull(graphExecutor.execute(transaction, ctx)); + } +} |