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;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.rules.ExpectedException;
28 import org.mockito.Mockito;
29 import org.onap.appc.flow.controller.data.Transaction;
30 import org.onap.appc.flow.controller.utils.FlowControllerConstants;
31 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
36 public class FlowControlDBServiceTest {
38 private SqlResource sqlResource = Mockito.mock(SqlResource.class);
39 private FlowControlDBService dbService;
42 public ExpectedException expectedEx = ExpectedException.none();
45 public void testGetFlowReferenceData() throws SvcLogicException {
46 dbService = new FlowControlDBService(sqlResource);
47 SvcLogicContext ctx = new SvcLogicContext();
48 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
49 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
50 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
51 Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.FAILURE);
52 expectedEx.expect(SvcLogicException.class);
53 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
54 dbService.getFlowReferenceData(ctx, null, new SvcLogicContext());
58 public void testGetEndpointByAction() {
59 dbService = new FlowControlDBService(sqlResource);
60 assertNull(dbService.getEndPointByAction(null));
64 public void testGetDesignTimeFlowModelFirstQueryException() throws SvcLogicException {
65 dbService = new FlowControlDBService(sqlResource);
66 SvcLogicContext ctx = new SvcLogicContext();
67 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
68 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
69 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
70 Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.FAILURE);
71 expectedEx.expect(SvcLogicException.class);
72 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
73 dbService.getDesignTimeFlowModel(ctx);
77 public void testGetDesignTimeFlowModelSecondQueryException() throws SvcLogicException {
78 dbService = new FlowControlDBService(sqlResource);
79 SvcLogicContext ctx = new SvcLogicContext();
80 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
81 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
82 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
83 Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
84 expectedEx.expect(SvcLogicException.class);
85 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
86 dbService.getDesignTimeFlowModel(ctx);
90 public void testGetDesignTimeFlowModelNullLocalContext() throws SvcLogicException {
91 dbService = new FlowControlDBService(sqlResource);
92 assertNull(dbService.getDesignTimeFlowModel(null));
96 public void testLoadSequenceIntoDb() throws SvcLogicException {
97 dbService = new FlowControlDBService(sqlResource);
98 SvcLogicContext ctx = new SvcLogicContext();
99 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
100 Mockito.when(sqlResource.save(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyString(),
101 Mockito.any(), Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
102 .thenReturn(QueryStatus.FAILURE);
103 expectedEx.expect(SvcLogicException.class);
104 expectedEx.expectMessage("Error While processing storing Artifact: ");
105 dbService.loadSequenceIntoDB(ctx);
109 public void testGetProtocolTypeFirstException() throws SvcLogicException {
110 dbService = new FlowControlDBService(sqlResource);
111 SvcLogicContext ctx = new SvcLogicContext();
112 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
113 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
114 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
115 Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.FAILURE);
116 expectedEx.expect(SvcLogicException.class);
117 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
118 dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
122 public void testGetProtocolTypeSecondException() throws SvcLogicException {
123 dbService = Mockito.spy(new FlowControlDBService(sqlResource));
124 SvcLogicContext ctx = new SvcLogicContext();
125 ctx.setAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM, "1");
126 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
127 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
128 Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
129 Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
130 expectedEx.expect(SvcLogicException.class);
131 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
132 dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
136 public void testHasSingleProtocolFirstException() throws SvcLogicException {
137 dbService = Mockito.spy(new FlowControlDBService(sqlResource));
138 SvcLogicContext ctx = new SvcLogicContext();
139 ctx.setAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM, "2");
140 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
141 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
142 Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
143 Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
144 expectedEx.expect(SvcLogicException.class);
145 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
146 dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
147 Mockito.verify(dbService).getSvcLogicContext();
151 public void testHasSingleProtocolSecondException() throws SvcLogicException {
152 dbService = Mockito.spy(new FlowControlDBService(sqlResource));
153 SvcLogicContext ctx = new SvcLogicContext();
154 ctx.setAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM, "2");
155 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
156 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
157 Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.SUCCESS)
158 .thenReturn(QueryStatus.FAILURE);
159 Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
160 expectedEx.expect(SvcLogicException.class);
161 expectedEx.expectMessage("Got more than 2 values..");
162 dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
163 Mockito.verify(dbService).getSvcLogicContext();
167 public void testHasSingleProtocolThirdException() throws SvcLogicException {
168 dbService = Mockito.spy(new FlowControlDBService(sqlResource));
169 SvcLogicContext ctx = Mockito.spy(new SvcLogicContext());
170 Mockito.when(ctx.getAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM)).thenReturn("2").thenReturn("1");
171 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
172 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
173 Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.SUCCESS)
174 .thenReturn(QueryStatus.FAILURE);
175 Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
176 expectedEx.expect(SvcLogicException.class);
177 expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
178 dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
179 Mockito.verify(dbService).getSvcLogicContext();
183 public void testHasSingleProtocolSuccessFlow() throws SvcLogicException {
184 dbService = Mockito.spy(new FlowControlDBService(sqlResource));
185 SvcLogicContext ctx = Mockito.spy(new SvcLogicContext());
186 Mockito.when(ctx.getAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM)).thenReturn("2").thenReturn("1");
187 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
188 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
189 Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.SUCCESS)
190 .thenReturn(QueryStatus.SUCCESS);
191 Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
192 Transaction transaction = Mockito.spy(new Transaction());
193 dbService.populateModuleAndRPC(transaction, "vnf_type");
194 Mockito.verify(transaction).setExecutionRPC(null);
198 public void testGetDependencyInfoFirstException() throws SvcLogicException {
199 dbService = new FlowControlDBService(sqlResource);
200 SvcLogicContext ctx = new SvcLogicContext();
201 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
202 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
203 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
204 Mockito.any(SvcLogicContext.class))).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(sqlResource);
213 SvcLogicContext ctx = new SvcLogicContext();
214 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
215 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
216 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
217 Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
218 expectedEx.expect(SvcLogicException.class);
219 expectedEx.expectMessage("Error - while getting dependencyData ");
220 dbService.getDependencyInfo(ctx);
224 public void testGetCapabilitiesDataFirstException() throws SvcLogicException {
225 dbService = new FlowControlDBService(sqlResource);
226 SvcLogicContext ctx = new SvcLogicContext();
227 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
228 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
229 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
230 Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.FAILURE);
231 expectedEx.expect(SvcLogicException.class);
232 expectedEx.expectMessage("Error - while getting capabilitiesData ");
233 dbService.getCapabilitiesData(ctx);
237 public void testGetCapabilitiesDataSecondException() throws SvcLogicException {
238 dbService = new FlowControlDBService(sqlResource);
239 SvcLogicContext ctx = new SvcLogicContext();
240 ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
241 Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
242 Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
243 Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
244 expectedEx.expect(SvcLogicException.class);
245 expectedEx.expectMessage("Error - while getting capabilitiesData ");
246 dbService.getCapabilitiesData(ctx);