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.dbervices;
24 import static org.junit.Assert.assertNull;
26 import java.util.ArrayList;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.rules.ExpectedException;
31 import org.mockito.Mockito;
32 import org.onap.appc.flow.controller.data.Transaction;
33 import org.onap.appc.flow.controller.utils.FlowControllerConstants;
34 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
35 import org.onap.ccsdk.sli.core.dblib.DbLibService;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
40 public class FlowControlDBServiceTest {
42 //private DbLibService dbLibService = Mockito.mock(DbLibService.class);
43 private DbLibServiceQueries dblib = Mockito.mock(DbLibServiceQueries.class);
44 private FlowControlDBService dbService;
47 public ExpectedException expectedEx = ExpectedException.none();
50 public void testGetFlowReferenceData() throws SvcLogicException {
51 dbService = new FlowControlDBService(dblib);
52 SvcLogicContext ctx = new SvcLogicContext();
53 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
54 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
55 .thenReturn(QueryStatus.FAILURE);
56 expectedEx.expect(SvcLogicException.class);
57 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
58 dbService.getFlowReferenceData(ctx, null, new SvcLogicContext());
62 public void testGetEndpointByAction() {
63 dbService = new FlowControlDBService(dblib);
64 assertNull(dbService.getEndPointByAction(null));
68 public void testGetDesignTimeFlowModelFirstQueryException() throws SvcLogicException {
69 dbService = new FlowControlDBService(dblib);
70 SvcLogicContext ctx = new SvcLogicContext();
71 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
72 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
73 .thenReturn(QueryStatus.FAILURE);
74 expectedEx.expect(SvcLogicException.class);
75 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
76 dbService.getDesignTimeFlowModel(ctx);
80 public void testGetDesignTimeFlowModelSecondQueryException() throws SvcLogicException {
81 dbService = new FlowControlDBService(dblib);
82 SvcLogicContext ctx = new SvcLogicContext();
83 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
84 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
85 .thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
86 expectedEx.expect(SvcLogicException.class);
87 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
88 dbService.getDesignTimeFlowModel(ctx);
92 public void testGetDesignTimeFlowModelNullLocalContext() throws SvcLogicException {
93 dbService = new FlowControlDBService(dblib);
94 assertNull(dbService.getDesignTimeFlowModel(null));
98 public void testLoadSequenceIntoDb() throws SvcLogicException {
99 dbService = new FlowControlDBService(dblib);
100 SvcLogicContext ctx = new SvcLogicContext();
101 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
102 Mockito.when(dblib.save(Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
103 .thenReturn(QueryStatus.FAILURE);
104 expectedEx.expect(SvcLogicException.class);
105 expectedEx.expectMessage("Error While processing storing Artifact: ");
106 dbService.loadSequenceIntoDB(ctx);
110 public void testGetProtocolTypeFirstException() throws SvcLogicException {
111 dbService = new FlowControlDBService(dblib);
112 SvcLogicContext ctx = new SvcLogicContext();
113 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
114 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class),
115 Mockito.any(ArrayList.class)))
116 .thenReturn(QueryStatus.FAILURE);
117 expectedEx.expect(SvcLogicException.class);
118 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
119 dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
123 public void testGetProtocolTypeSecondException() throws SvcLogicException {
124 dbService = Mockito.spy(new FlowControlDBService(dblib));
125 SvcLogicContext ctx = new SvcLogicContext();
126 ctx.setAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM, "1");
127 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class),
128 Mockito.any(ArrayList.class)))
129 .thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
130 Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
131 expectedEx.expect(SvcLogicException.class);
132 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
133 dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
137 public void testHasSingleProtocolFirstException() throws SvcLogicException {
138 dbService = Mockito.spy(new FlowControlDBService(dblib));
139 SvcLogicContext ctx = new SvcLogicContext();
140 ctx.setAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM, "2");
141 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class),
142 Mockito.any(ArrayList.class)))
143 .thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
144 Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
145 expectedEx.expect(SvcLogicException.class);
146 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
147 dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
148 Mockito.verify(dbService).getSvcLogicContext();
152 public void testHasSingleProtocolSecondException() throws SvcLogicException {
153 dbService = Mockito.spy(new FlowControlDBService(dblib));
154 SvcLogicContext ctx = new SvcLogicContext();
155 ctx.setAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM, "2");
156 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class),
157 Mockito.any(ArrayList.class)))
158 .thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.SUCCESS)
159 .thenReturn(QueryStatus.FAILURE);
160 Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
161 expectedEx.expect(SvcLogicException.class);
162 expectedEx.expectMessage("Got more than 2 values..");
163 dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
164 Mockito.verify(dbService).getSvcLogicContext();
168 public void testHasSingleProtocolThirdException() throws SvcLogicException {
169 dbService = Mockito.spy(new FlowControlDBService(dblib));
170 SvcLogicContext ctx = Mockito.spy(new SvcLogicContext());
171 Mockito.when(ctx.getAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM)).thenReturn("2").thenReturn("1");
172 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class),
173 Mockito.any(ArrayList.class)))
174 .thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.SUCCESS)
175 .thenReturn(QueryStatus.FAILURE);
176 Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
177 expectedEx.expect(SvcLogicException.class);
178 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
179 dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
180 Mockito.verify(dbService).getSvcLogicContext();
184 public void testHasSingleProtocolSuccessFlow() throws SvcLogicException {
185 dbService = Mockito.spy(new FlowControlDBService(dblib));
186 SvcLogicContext ctx = Mockito.spy(new SvcLogicContext());
187 Mockito.when(ctx.getAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM)).thenReturn("2").thenReturn("1");
188 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class),
189 Mockito.any(ArrayList.class)))
190 .thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.SUCCESS)
191 .thenReturn(QueryStatus.SUCCESS);
192 Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
193 Transaction transaction = Mockito.spy(new Transaction());
194 dbService.populateModuleAndRPC(transaction, "vnf_type");
195 Mockito.verify(transaction).setExecutionRPC(null);
199 public void testGetDependencyInfoFirstException() throws SvcLogicException {
200 dbService = new FlowControlDBService(dblib);
201 SvcLogicContext ctx = new SvcLogicContext();
202 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
203 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
204 .thenReturn(QueryStatus.FAILURE);
205 expectedEx.expect(SvcLogicException.class);
206 expectedEx.expectMessage("Error - while getting dependencydata ");
207 dbService.getDependencyInfo(ctx);
211 public void testGetDependencyInfoSecondException() throws SvcLogicException {
212 dbService = new FlowControlDBService(dblib);
213 SvcLogicContext ctx = new SvcLogicContext();
214 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
215 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
216 .thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
217 expectedEx.expect(SvcLogicException.class);
218 expectedEx.expectMessage("Error - while getting dependencyData ");
219 dbService.getDependencyInfo(ctx);
223 public void testGetCapabilitiesDataFirstException() throws SvcLogicException {
224 dbService = new FlowControlDBService(dblib);
225 SvcLogicContext ctx = new SvcLogicContext();
226 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
227 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
228 .thenReturn(QueryStatus.FAILURE);
229 expectedEx.expect(SvcLogicException.class);
230 expectedEx.expectMessage("Error - while getting capabilitiesData ");
231 dbService.getCapabilitiesData(ctx);
235 public void testGetCapabilitiesDataSecondException() throws SvcLogicException {
236 dbService = new FlowControlDBService(dblib);
237 SvcLogicContext ctx = new SvcLogicContext();
238 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
239 Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
240 .thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
241 expectedEx.expect(SvcLogicException.class);
242 expectedEx.expectMessage("Error - while getting capabilitiesData ");
243 dbService.getCapabilitiesData(ctx);