summaryrefslogtreecommitdiffstats
path: root/appc-config/appc-flow-controller/provider/src/test
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-02-27 09:59:54 +0000
committerTakamune Cho <takamune.cho@att.com>2019-02-27 20:21:44 +0000
commit8ed27a86af9811816db99195f65fb2a50e4f37b2 (patch)
tree59436c41296f981ebca0e85937554db6367c76f2 /appc-config/appc-flow-controller/provider/src/test
parentabe5b13384dc8d275e8395899e02818ef7c8fae4 (diff)
Test coverage in DBService
Increase coverage from 71% to 98% Fix for Sonar major issue on branch coverage Issue-ID: APPC-1499 Change-Id: I74261af92b3263a03d29d476ad097182e6112ad9 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-config/appc-flow-controller/provider/src/test')
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/dbervices/FlowControlDBServiceTest.java248
1 files changed, 248 insertions, 0 deletions
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/dbervices/FlowControlDBServiceTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/dbervices/FlowControlDBServiceTest.java
new file mode 100644
index 000000000..25c8ee500
--- /dev/null
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/dbervices/FlowControlDBServiceTest.java
@@ -0,0 +1,248 @@
+/*
+ * ============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.dbervices;
+
+import static org.junit.Assert.assertNull;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+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.adaptors.resource.sql.SqlResource;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+
+public class FlowControlDBServiceTest {
+
+ private SqlResource sqlResource = Mockito.mock(SqlResource.class);
+ private FlowControlDBService dbService;
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Test
+ public void testGetFlowReferenceData() throws SvcLogicException {
+ dbService = new FlowControlDBService(sqlResource);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.FAILURE);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
+ dbService.getFlowReferenceData(ctx, null, new SvcLogicContext());
+ }
+
+ @Test
+ public void testGetEndpointByAction() {
+ dbService = new FlowControlDBService(sqlResource);
+ assertNull(dbService.getEndPointByAction(null));
+ }
+
+ @Test
+ public void testGetDesignTimeFlowModelFirstQueryException() throws SvcLogicException {
+ dbService = new FlowControlDBService(sqlResource);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.FAILURE);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
+ dbService.getDesignTimeFlowModel(ctx);
+ }
+
+ @Test
+ public void testGetDesignTimeFlowModelSecondQueryException() throws SvcLogicException {
+ dbService = new FlowControlDBService(sqlResource);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
+ dbService.getDesignTimeFlowModel(ctx);
+ }
+
+ @Test
+ public void testGetDesignTimeFlowModelNullLocalContext() throws SvcLogicException {
+ dbService = new FlowControlDBService(sqlResource);
+ assertNull(dbService.getDesignTimeFlowModel(null));
+ }
+
+ @Test
+ public void testLoadSequenceIntoDb() throws SvcLogicException {
+ dbService = new FlowControlDBService(sqlResource);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
+ Mockito.when(sqlResource.save(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.any(), Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
+ .thenReturn(QueryStatus.FAILURE);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Error While processing storing Artifact: ");
+ dbService.loadSequenceIntoDB(ctx);
+ }
+
+ @Test
+ public void testGetProtocolTypeFirstException() throws SvcLogicException {
+ dbService = new FlowControlDBService(sqlResource);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.FAILURE);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
+ dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
+ }
+
+ @Test
+ public void testGetProtocolTypeSecondException() throws SvcLogicException {
+ dbService = Mockito.spy(new FlowControlDBService(sqlResource));
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM, "1");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
+ Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
+ dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
+ }
+
+ @Test
+ public void testHasSingleProtocolFirstException() throws SvcLogicException {
+ dbService = Mockito.spy(new FlowControlDBService(sqlResource));
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM, "2");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
+ Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
+ dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
+ Mockito.verify(dbService).getSvcLogicContext();
+ }
+
+ @Test
+ public void testHasSingleProtocolSecondException() throws SvcLogicException {
+ dbService = Mockito.spy(new FlowControlDBService(sqlResource));
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM, "2");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.SUCCESS)
+ .thenReturn(QueryStatus.FAILURE);
+ Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Got more than 2 values..");
+ dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
+ Mockito.verify(dbService).getSvcLogicContext();
+ }
+
+ @Test
+ public void testHasSingleProtocolThirdException() throws SvcLogicException {
+ dbService = Mockito.spy(new FlowControlDBService(sqlResource));
+ SvcLogicContext ctx = Mockito.spy(new SvcLogicContext());
+ Mockito.when(ctx.getAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM)).thenReturn("2").thenReturn("1");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.SUCCESS)
+ .thenReturn(QueryStatus.FAILURE);
+ Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage(FlowControlDBService.GET_FLOW_REF_DATA_ERROR);
+ dbService.populateModuleAndRPC(new Transaction(), "vnf_type");
+ Mockito.verify(dbService).getSvcLogicContext();
+ }
+
+ @Test
+ public void testHasSingleProtocolSuccessFlow() throws SvcLogicException {
+ dbService = Mockito.spy(new FlowControlDBService(sqlResource));
+ SvcLogicContext ctx = Mockito.spy(new SvcLogicContext());
+ Mockito.when(ctx.getAttribute(FlowControlDBService.COUNT_PROTOCOL_PARAM)).thenReturn("2").thenReturn("1");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.SUCCESS)
+ .thenReturn(QueryStatus.SUCCESS);
+ Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
+ Transaction transaction = Mockito.spy(new Transaction());
+ dbService.populateModuleAndRPC(transaction, "vnf_type");
+ Mockito.verify(transaction).setExecutionRPC(null);
+ }
+
+ @Test
+ public void testGetDependencyInfoFirstException() throws SvcLogicException {
+ dbService = new FlowControlDBService(sqlResource);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.FAILURE);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Error - while getting dependencydata ");
+ dbService.getDependencyInfo(ctx);
+ }
+
+ @Test
+ public void testGetDependencyInfoSecondException() throws SvcLogicException {
+ dbService = new FlowControlDBService(sqlResource);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Error - while getting dependencyData ");
+ dbService.getDependencyInfo(ctx);
+ }
+
+ @Test
+ public void testGetCapabilitiesDataFirstException() throws SvcLogicException {
+ dbService = new FlowControlDBService(sqlResource);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.FAILURE);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Error - while getting capabilitiesData ");
+ dbService.getCapabilitiesData(ctx);
+ }
+
+ @Test
+ public void testGetCapabilitiesDataSecondException() throws SvcLogicException {
+ dbService = new FlowControlDBService(sqlResource);
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute(FlowControllerConstants.ACTION_LEVEL, "action_level");
+ Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+ Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.FAILURE);
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Error - while getting capabilitiesData ");
+ dbService.getCapabilitiesData(ctx);
+ }
+}