Update license header in appc-flow-controller file
[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-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
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  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.flow.executor.node;
25
26 import static org.mockito.Matchers.any;
27 import static org.mockito.Matchers.anyBoolean;
28 import static org.mockito.Matchers.anyString;
29
30 import java.util.Map;
31
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;
51
52 @PrepareForTest({ SqlResource.class, SvcLogicResource.class })
53 @RunWith(PowerMockRunner.class)
54 public class FlowControlDBServiceTest {
55
56 @Mock
57      SvcLogicResource serviceLogic;
58 @Mock
59 SqlResource sqlrs;
60 @Mock
61 QueryStatus dblibSvc ;
62
63     private static FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();
64
65     private Transaction transaction;;
66
67     @Before
68     public void setUp() throws Exception {
69         serviceLogic = new SqlResource();
70     }
71
72
73     /*public final void testGetFlowReferenceData() throws Exception {
74
75         SvcLogicContext localContext = new SvcLogicContext();
76         FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();
77         PowerMockito.spy(SqlResource.class);
78
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));
82
83         dgGeneralDBService.getFlowReferenceData(localContext, inParams, localContext);
84         //Assert.assertEquals("SUCCESS", status);
85         //Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
86
87     }*/
88
89     @Test(expected=Exception.class)
90     public final void testGetFlowReferenceData() throws Exception {
91
92         SvcLogicContext localContext = new SvcLogicContext();
93         FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();
94         PowerMockito.spy(FlowControlDBService.class);
95
96
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);
101
102     }
103
104
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);
112
113
114
115
116     }
117
118     @Ignore("Test is taking 60 seconds")
119     @Test(expected=Exception.class)
120     public final void testLoadSequenceIntoDB() throws SvcLogicException {
121
122
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();
128
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))
133                     .thenReturn(status);
134             Assert.assertEquals("SUCCESS", status);
135             Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);*/
136
137
138
139     }
140
141     @Ignore
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);;
148
149
150     }
151
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);
159
160     }
161
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);
169
170     }
171
172 }