1876e2aa3c14ccb869e3c8da622bfb2183ddc80e
[appc.git] / appc-config / appc-flow-controller / provider / src / test / java / org / onap / appc / flow / executor / node / FlowControlDBServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.flow.executor.node;
26
27 import static org.mockito.Matchers.any;
28 import static org.mockito.Matchers.anyBoolean;
29 import static org.mockito.Matchers.anyString;
30
31 import java.util.Map;
32
33 import org.junit.Assert;
34 import org.junit.Before;
35 import org.junit.Ignore;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.Mock;
39 import org.onap.appc.flow.controller.data.Transaction;
40 import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
42 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
43 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
44 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
45 import org.onap.ccsdk.sli.core.dblib.DbLibService;
46 import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
47 import org.powermock.api.mockito.PowerMockito;
48 import org.powermock.core.classloader.annotations.PrepareForTest;
49 import org.powermock.modules.junit4.PowerMockRunner;
50 import org.powermock.reflect.Whitebox;
51 import org.powermock.modules.junit4.PowerMockRunner;
52
53 @PrepareForTest({ SqlResource.class, SvcLogicResource.class })
54 @RunWith(PowerMockRunner.class)
55 public class FlowControlDBServiceTest {
56
57 @Mock
58      SvcLogicResource serviceLogic;
59 @Mock
60 SqlResource sqlrs;
61 @Mock
62 QueryStatus dblibSvc ;
63
64     private static FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();
65
66     private Transaction transaction;;
67
68     @Before
69     public void setUp() throws Exception {
70         serviceLogic = new SqlResource();
71     }
72
73
74     /*public final void testGetFlowReferenceData() throws Exception {
75
76         SvcLogicContext localContext = new SvcLogicContext();
77         FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();
78         PowerMockito.spy(SqlResource.class);
79
80         Map<String, String> inParams = null;
81         //PowerMockito.doReturn(dblibSvc).when(SqlResource.class, "query");
82         Whitebox.invokeMethod(SqlResource.class, "query",anyString(), anyBoolean(), anyString(), anyString(), anyString(), anyString(), any(SvcLogicContext.class));
83
84         dgGeneralDBService.getFlowReferenceData(localContext, inParams, localContext);
85         //Assert.assertEquals("SUCCESS", status);
86         //Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
87
88     }*/
89
90     @Test(expected=Exception.class)
91     public final void testGetFlowReferenceData() throws Exception {
92
93         SvcLogicContext localContext = new SvcLogicContext();
94         FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();
95         PowerMockito.spy(FlowControlDBService.class);
96
97
98         PowerMockito.doReturn(dgGeneralDBService).when(SqlResource.class, "query");
99         String status = dgGeneralDBService.getDesignTimeFlowModel(localContext);
100         Assert.assertEquals("SUCCESS", status);
101         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
102
103     }
104
105
106     @Ignore("Test is taking 60 seconds")
107     @Test(expected=Exception.class)
108     public final void testGetDesignTimeFlowModel() throws Exception {
109         SvcLogicContext localContext = new SvcLogicContext();
110         String status = dgGeneralDBService.getDesignTimeFlowModel(localContext) ;
111         Assert.assertEquals("SUCCESS", status);
112         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
113
114
115
116
117     }
118
119     @Ignore("Test is taking 60 seconds")
120     @Test(expected=Exception.class)
121     public final void testLoadSequenceIntoDB() throws SvcLogicException {
122
123
124         SvcLogicContext localContext = new SvcLogicContext();
125         QueryStatus status = dgGeneralDBService.loadSequenceIntoDB(localContext) ;
126         Assert.assertEquals("SUCCESS", status);
127         Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
128         /*SvcLogicContext ctx = new SvcLogicContext();
129
130         if (serviceLogic != null && localContext != null) {
131             String queryString = "INSERT INTO " + FlowControllerConstants.DB_REQUEST_ARTIFACTS
132                     + " set request_id =  ' kusuma_test' , action = 'Configure', action_level =  'VNF' , vnf_type = 'vComp' , category = 'config_Template'  , artifact_content = '', updated_date = sysdate() ";
133             Mockito.when(serviceLogic.save("SQL", false, false, queryString, null, null, localContext))
134                     .thenReturn(status);
135             Assert.assertEquals("SUCCESS", status);
136             Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);*/
137
138
139
140     }
141
142     @Ignore
143     @Test(expected=Exception.class)
144     public final void testPopulateModuleAndRPC() throws Exception {
145         SvcLogicContext localContext = new SvcLogicContext();
146         SvcLogicContext ctx = new SvcLogicContext();
147         String vnf_type = "test";
148      dgGeneralDBService.populateModuleAndRPC(transaction, vnf_type);;
149
150
151     }
152
153     @Ignore("Test is taking 60 seconds")
154     @Test(expected=Exception.class)
155     public final void testGetDependencyInfo() throws SvcLogicException {
156         SvcLogicContext localContext = new SvcLogicContext();
157          String status = dgGeneralDBService.getDependencyInfo(localContext);
158             Assert.assertEquals("SUCCESS", status);
159             Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
160
161     }
162
163     @Ignore("Test is taking 60 seconds")
164     @Test(expected=Exception.class)
165     public final void testGetCapabilitiesData() throws SvcLogicException {
166         SvcLogicContext localContext = new SvcLogicContext();
167         String status = dgGeneralDBService.getCapabilitiesData(localContext);
168             Assert.assertEquals("SUCCESS", status);
169             Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
170
171     }
172
173 }