2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Copyright (C) 2017 Amdocs
 
   8  * =============================================================================
 
   9  * Licensed under the Apache License, Version 2.0 (the "License");
 
  10  * you may not use this file except in compliance with the License.
 
  11  * You may obtain a copy of the License at
 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
 
  15  * Unless required by applicable law or agreed to in writing, software
 
  16  * distributed under the License is distributed on an "AS IS" BASIS,
 
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  18  * See the License for the specific language governing permissions and
 
  19  * limitations under the License.
 
  21  * ============LICENSE_END=========================================================
 
  24 package org.onap.appc.flow.executor.node;
 
  26 import static org.mockito.Matchers.any;
 
  27 import static org.mockito.Matchers.anyBoolean;
 
  28 import static org.mockito.Matchers.anyString;
 
  32 import org.junit.Assert;
 
  33 import org.junit.Before;
 
  34 import org.junit.Ignore;
 
  35 import org.junit.Test;
 
  36 import org.junit.runner.RunWith;
 
  37 import org.mockito.Mock;
 
  38 import org.onap.appc.flow.controller.data.Transaction;
 
  39 import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
 
  40 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  41 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
  42 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
 
  43 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
 
  44 import org.onap.ccsdk.sli.core.dblib.DbLibService;
 
  45 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
 
  46 import org.powermock.api.mockito.PowerMockito;
 
  47 import org.powermock.core.classloader.annotations.PrepareForTest;
 
  48 import org.powermock.modules.junit4.PowerMockRunner;
 
  49 import org.powermock.reflect.Whitebox;
 
  50 import org.powermock.modules.junit4.PowerMockRunner;
 
  52 @PrepareForTest({ SqlResource.class, SvcLogicResource.class })
 
  53 @RunWith(PowerMockRunner.class)
 
  54 public class FlowControlDBServiceTest {
 
  57      SvcLogicResource serviceLogic;
 
  61 QueryStatus dblibSvc ;
 
  63     private static FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();
 
  65     private Transaction transaction;;
 
  68     public void setUp() throws Exception {
 
  69         serviceLogic = new SqlResource();
 
  73     /*public final void testGetFlowReferenceData() throws Exception {
 
  75         SvcLogicContext localContext = new SvcLogicContext();
 
  76         FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();
 
  77         PowerMockito.spy(SqlResource.class);
 
  79         Map<String, String> inParams = null;
 
  80         //PowerMockito.doReturn(dblibSvc).when(SqlResource.class, "query");
 
  81         Whitebox.invokeMethod(SqlResource.class, "query",anyString(), anyBoolean(), anyString(), anyString(), anyString(), anyString(), any(SvcLogicContext.class));
 
  83         dgGeneralDBService.getFlowReferenceData(localContext, inParams, localContext);
 
  84         //Assert.assertEquals("SUCCESS", status);
 
  85         //Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
 
  89     @Test(expected=Exception.class)
 
  90     public final void testGetFlowReferenceData() throws Exception {
 
  92         SvcLogicContext localContext = new SvcLogicContext();
 
  93         FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();
 
  94         PowerMockito.spy(FlowControlDBService.class);
 
  97         PowerMockito.doReturn(dgGeneralDBService).when(SqlResource.class, "query");
 
  98         String status = dgGeneralDBService.getDesignTimeFlowModel(localContext);
 
  99         Assert.assertEquals("SUCCESS", status);
 
 100         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
 
 105     @Ignore("Test is taking 60 seconds")
 
 106     @Test(expected=Exception.class)
 
 107     public final void testGetDesignTimeFlowModel() throws Exception {
 
 108         SvcLogicContext localContext = new SvcLogicContext();
 
 109         String status = dgGeneralDBService.getDesignTimeFlowModel(localContext) ;
 
 110         Assert.assertEquals("SUCCESS", status);
 
 111         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
 
 118     @Ignore("Test is taking 60 seconds")
 
 119     @Test(expected=Exception.class)
 
 120     public final void testLoadSequenceIntoDB() throws SvcLogicException {
 
 123         SvcLogicContext localContext = new SvcLogicContext();
 
 124         QueryStatus status = dgGeneralDBService.loadSequenceIntoDB(localContext) ;
 
 125         Assert.assertEquals("SUCCESS", status);
 
 126         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
 
 127         /*SvcLogicContext ctx = new SvcLogicContext();
 
 129         if (serviceLogic != null && localContext != null) {
 
 130             String queryString = "INSERT INTO " + FlowControllerConstants.DB_REQUEST_ARTIFACTS
 
 131                     + " set request_id =  ' kusuma_test' , action = 'Configure', action_level =  'VNF' , vnf_type = 'vComp' , category = 'config_Template'  , artifact_content = '', updated_date = sysdate() ";
 
 132             Mockito.when(serviceLogic.save("SQL", false, false, queryString, null, null, localContext))
 
 134             Assert.assertEquals("SUCCESS", status);
 
 135             Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);*/
 
 142     @Test(expected=Exception.class)
 
 143     public final void testPopulateModuleAndRPC() throws Exception {
 
 144         SvcLogicContext localContext = new SvcLogicContext();
 
 145         SvcLogicContext ctx = new SvcLogicContext();
 
 146         String vnf_type = "test";
 
 147      dgGeneralDBService.populateModuleAndRPC(transaction, vnf_type);;
 
 152     @Ignore("Test is taking 60 seconds")
 
 153     @Test(expected=Exception.class)
 
 154     public final void testGetDependencyInfo() throws SvcLogicException {
 
 155         SvcLogicContext localContext = new SvcLogicContext();
 
 156          String status = dgGeneralDBService.getDependencyInfo(localContext);
 
 157             Assert.assertEquals("SUCCESS", status);
 
 158             Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
 
 162     @Ignore("Test is taking 60 seconds")
 
 163     @Test(expected=Exception.class)
 
 164     public final void testGetCapabilitiesData() throws SvcLogicException {
 
 165         SvcLogicContext localContext = new SvcLogicContext();
 
 166         String status = dgGeneralDBService.getCapabilitiesData(localContext);
 
 167             Assert.assertEquals("SUCCESS", status);
 
 168             Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);