2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Ericsson
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.flow.controller.executorImpl;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNull;
26 import java.util.HashMap;
28 import java.util.Properties;
29 import org.junit.Before;
30 import org.junit.Rule;
31 import org.junit.Test;
32 import org.junit.rules.ExpectedException;
33 import org.junit.runner.RunWith;
34 import org.mockito.Matchers;
35 import org.mockito.Mockito;
36 import org.onap.appc.flow.controller.data.Transaction;
37 import org.onap.appc.flow.controller.utils.FlowControllerConstants;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
40 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
41 import org.osgi.framework.FrameworkUtil;
42 import org.powermock.api.mockito.PowerMockito;
43 import org.powermock.core.classloader.annotations.PrepareForTest;
44 import org.powermock.modules.junit4.PowerMockRunner;
45 import org.powermock.reflect.Whitebox;
46 import com.att.eelf.configuration.EELFLogger;
47 import com.att.eelf.configuration.EELFLogger.Level;
48 import com.att.eelf.configuration.EELFManager;
49 import org.osgi.framework.Bundle;
50 import org.osgi.framework.BundleContext;
51 import org.osgi.framework.ServiceReference;
53 @RunWith(PowerMockRunner.class)
54 @PrepareForTest(FrameworkUtil.class)
55 public class GraphExecutorTest {
57 private final BundleContext bundleContext = Mockito.mock(BundleContext.class);
58 private final Bundle bundleService = Mockito.mock(Bundle.class);
59 private final ServiceReference sref = Mockito.mock(ServiceReference.class);
60 private SvcLogicService svcLogic = null;
61 private Map<String, String> params;
62 private EELFLogger log = EELFManager.getInstance().getLogger(GraphExecutor.class);
65 public ExpectedException expectedEx = ExpectedException.none();
68 public void setUp() throws NoSuchFieldException, IllegalAccessException {
69 log.setLevel(Level.DEBUG);
70 svcLogic = Mockito.mock(SvcLogicService.class);
71 PowerMockito.mockStatic(FrameworkUtil.class);
72 PowerMockito.when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
73 PowerMockito.when(bundleService.getBundleContext()).thenReturn(bundleContext);
74 PowerMockito.when(bundleContext.getServiceReference(SvcLogicService.NAME)).thenReturn(sref);
75 PowerMockito.when(bundleContext.<SvcLogicService>getService(sref)).thenReturn(svcLogic);
76 params = new HashMap<>();
80 public void testExecuteGraph() throws SvcLogicException {
81 GraphExecutor graphExecutor = new GraphExecutor();
82 Whitebox.setInternalState(GraphExecutor.class, "log", log);
83 Properties properties = new Properties();
84 properties.put("TEST", "TEST");
85 Mockito.when(svcLogic.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
86 Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(properties);
87 assertEquals(properties, graphExecutor.executeGraph(null, null, null, null, new Properties()));
91 public void testExecute() throws Exception {
92 GraphExecutor graphExecutor = new GraphExecutor();
93 Whitebox.setInternalState(GraphExecutor.class, "log", log);
94 Properties properties = new Properties();
95 properties.put("TEST", "TEST");
96 Transaction transaction = Mockito.spy(new Transaction());
97 transaction.setExecutionRPC("EXECUTION_RPC");
98 transaction.setPayload("PAYLOAD");
99 SvcLogicContext ctx = new SvcLogicContext();
100 ctx.setAttribute("TEST", "TEST");
101 Mockito.when(svcLogic.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
102 Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(properties);
103 assertNull(graphExecutor.execute(transaction, ctx));
107 public void testExecuteWithLongPropertyValue() throws Exception {
108 GraphExecutor graphExecutor = new GraphExecutor();
109 Whitebox.setInternalState(GraphExecutor.class, "log", log);
110 Properties properties = new Properties();
111 properties.put("TEST", "Lorem ipsum dolor sit amet, prompta mediocrem quo an, eos odio esse pertinax an."
112 + " Vis timeam suscipiantur no, eos ex vidisse appareat. Vel ipsum verterem in, qui eu cetero"
113 + " vituperatoribus. Semper insolens contentiones mei ea, vitae persius suavitate no quo, prompta"
114 + " impedit minimum cu sed. Everti disputationi id eam, essent.");
115 Transaction transaction = Mockito.spy(new Transaction());
116 transaction.setExecutionRPC("EXECUTION_RPC");
117 transaction.setPayload("PAYLOAD");
118 SvcLogicContext ctx = new SvcLogicContext();
119 ctx.setAttribute("TEST", "TEST");
120 Mockito.when(svcLogic.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
121 Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(properties);
122 assertNull(graphExecutor.execute(transaction, ctx));
126 public void testExecuteFailure() throws Exception {
127 GraphExecutor graphExecutor = new GraphExecutor();
128 Whitebox.setInternalState(GraphExecutor.class, "log", log);
129 Properties properties = new Properties();
130 properties.put(GraphExecutor.SVC_LOGIC_STATUS_PARAM, FlowControllerConstants.FAILURE);
131 Transaction transaction = Mockito.spy(new Transaction());
132 transaction.setExecutionRPC("EXECUTION_RPC");
133 transaction.setPayload("PAYLOAD");
134 SvcLogicContext ctx = new SvcLogicContext();
135 ctx.setAttribute("TEST", "TEST");
136 Mockito.when(svcLogic.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
137 Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(properties);
138 assertNull(graphExecutor.execute(transaction, ctx));
142 public void testExecuteSuccess() throws Exception {
143 GraphExecutor graphExecutor = new GraphExecutor();
144 Whitebox.setInternalState(GraphExecutor.class, "log", log);
145 Properties properties = new Properties();
146 properties.put(GraphExecutor.SVC_LOGIC_STATUS_PARAM, FlowControllerConstants.SUCCESS);
147 Transaction transaction = Mockito.spy(new Transaction());
148 transaction.setExecutionRPC("EXECUTION_RPC");
149 transaction.setPayload("PAYLOAD");
150 SvcLogicContext ctx = new SvcLogicContext();
151 ctx.setAttribute("TEST", "TEST");
152 Mockito.when(svcLogic.execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
153 Mockito.anyString(), Mockito.any(Properties.class))).thenReturn(properties);
154 assertNull(graphExecutor.execute(transaction, ctx));