package org.onap.appc.flow.controller.dbervices;
import static org.junit.Assert.assertNull;
+
+import java.util.ArrayList;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
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.dblib.DbLibService;
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 DbLibService dbLibService = Mockito.mock(DbLibService.class);
+ private DbLibServiceQueries dblib = Mockito.mock(DbLibServiceQueries.class);
private FlowControlDBService dbService;
@Rule
@Test
public void testGetFlowReferenceData() throws SvcLogicException {
- dbService = new FlowControlDBService(sqlResource);
+ dbService = new FlowControlDBService(dblib);
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);
+ Mockito.when(dblib.query(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);
+ dbService = new FlowControlDBService(dblib);
assertNull(dbService.getEndPointByAction(null));
}
@Test
public void testGetDesignTimeFlowModelFirstQueryException() throws SvcLogicException {
- dbService = new FlowControlDBService(sqlResource);
+ dbService = new FlowControlDBService(dblib);
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);
+ Mockito.when(dblib.query(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);
+ dbService = new FlowControlDBService(dblib);
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);
+ Mockito.when(dblib.query(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);
+ dbService = new FlowControlDBService(dblib);
assertNull(dbService.getDesignTimeFlowModel(null));
}
@Test
public void testLoadSequenceIntoDb() throws SvcLogicException {
- dbService = new FlowControlDBService(sqlResource);
+ dbService = new FlowControlDBService(dblib);
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)))
+ Mockito.when(dblib.save(Mockito.anyString(), Mockito.any(SvcLogicContext.class)))
.thenReturn(QueryStatus.FAILURE);
expectedEx.expect(SvcLogicException.class);
expectedEx.expectMessage("Error While processing storing Artifact: ");
@Test
public void testGetProtocolTypeFirstException() throws SvcLogicException {
- dbService = new FlowControlDBService(sqlResource);
+ dbService = new FlowControlDBService(dblib);
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);
+ Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class),
+ Mockito.any(ArrayList.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));
+ dbService = Mockito.spy(new FlowControlDBService(dblib));
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(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class),
+ Mockito.any(ArrayList.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);
@Test
public void testHasSingleProtocolFirstException() throws SvcLogicException {
- dbService = Mockito.spy(new FlowControlDBService(sqlResource));
+ dbService = Mockito.spy(new FlowControlDBService(dblib));
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(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class),
+ Mockito.any(ArrayList.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);
@Test
public void testHasSingleProtocolSecondException() throws SvcLogicException {
- dbService = Mockito.spy(new FlowControlDBService(sqlResource));
+ dbService = Mockito.spy(new FlowControlDBService(dblib));
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)
+ Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class),
+ Mockito.any(ArrayList.class)))
+ .thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.SUCCESS)
.thenReturn(QueryStatus.FAILURE);
Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
expectedEx.expect(SvcLogicException.class);
@Test
public void testHasSingleProtocolThirdException() throws SvcLogicException {
- dbService = Mockito.spy(new FlowControlDBService(sqlResource));
+ dbService = Mockito.spy(new FlowControlDBService(dblib));
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)
+ Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class),
+ Mockito.any(ArrayList.class)))
+ .thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.SUCCESS)
.thenReturn(QueryStatus.FAILURE);
Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
expectedEx.expect(SvcLogicException.class);
@Test
public void testHasSingleProtocolSuccessFlow() throws SvcLogicException {
- dbService = Mockito.spy(new FlowControlDBService(sqlResource));
+ dbService = Mockito.spy(new FlowControlDBService(dblib));
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)
+ Mockito.when(dblib.query(Mockito.anyString(), Mockito.any(SvcLogicContext.class),
+ Mockito.any(ArrayList.class)))
+ .thenReturn(QueryStatus.SUCCESS).thenReturn(QueryStatus.SUCCESS)
.thenReturn(QueryStatus.SUCCESS);
Mockito.when(dbService.getSvcLogicContext()).thenReturn(ctx);
Transaction transaction = Mockito.spy(new Transaction());
@Test
public void testGetDependencyInfoFirstException() throws SvcLogicException {
- dbService = new FlowControlDBService(sqlResource);
+ dbService = new FlowControlDBService(dblib);
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);
+ Mockito.when(dblib.query(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);
+ dbService = new FlowControlDBService(dblib);
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);
+ Mockito.when(dblib.query(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);
+ dbService = new FlowControlDBService(dblib);
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);
+ Mockito.when(dblib.query(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);
+ dbService = new FlowControlDBService(dblib);
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);
+ Mockito.when(dblib.query(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);