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