Add value of the arguments
[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.junit.Assert.*;
27
28 import java.util.Map;
29
30 import org.junit.Test;
31 import org.onap.appc.flow.controller.data.Transaction;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
34
35 import org.powermock.reflect.Whitebox;
36
37
38 //@PrepareForTest({ SqlResource.class, SvcLogicResource.class })
39 //@RunWith(PowerMockRunner.class)
40 public class FlowControlDBServiceTest {
41     
42 //      @Mock
43 //    SvcLogicResource serviceLogic;
44 //@Mock
45 //SqlResource sqlrs;
46 //@Mock
47 //QueryStatus dblibSvc ;
48 //
49 //   private static FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();
50 //
51 //   private Transaction transaction;;
52 //
53 //   @Before
54 //   public void setUp() throws Exception {
55 //       serviceLogic = new SqlResource();
56 //   }
57 //
58 //
59 //   /*public final void testGetFlowReferenceData() throws Exception {
60 //
61 //       SvcLogicContext localContext = new SvcLogicContext();
62 //       FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();
63 //       PowerMockito.spy(SqlResource.class);
64 //
65 //       Map<String, String> inParams = null;
66 //       //PowerMockito.doReturn(dblibSvc).when(SqlResource.class, "query");
67 //       Whitebox.invokeMethod(SqlResource.class, "query",anyString(), anyBoolean(), anyString(), anyString(), anyString(), anyString(), any(SvcLogicContext.class));
68 //
69 //       dgGeneralDBService.getFlowReferenceData(localContext, inParams, localContext);
70 //       //Assert.assertEquals("SUCCESS", status);
71 //       //Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
72 //
73 //   }*/
74 //
75 //   @Test(expected=Exception.class)
76 //   public final void testGetFlowReferenceData() throws Exception {
77 //
78 //       SvcLogicContext localContext = new SvcLogicContext();
79 //       FlowControlDBService dgGeneralDBService = FlowControlDBService.initialise();
80 //       PowerMockito.spy(FlowControlDBService.class);
81 //
82 //
83 //       PowerMockito.doReturn(dgGeneralDBService).when(SqlResource.class, "query");
84 //       String status = dgGeneralDBService.getDesignTimeFlowModel(localContext);
85 //       Assert.assertEquals("SUCCESS", status);
86 //       Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
87 //
88 //   }
89 //
90 //
91 //   @Ignore("Test is taking 60 seconds")
92 //   @Test(expected=Exception.class)
93 //   public final void testGetDesignTimeFlowModel() throws Exception {
94 //       SvcLogicContext localContext = new SvcLogicContext();
95 //       String status = dgGeneralDBService.getDesignTimeFlowModel(localContext) ;
96 //       Assert.assertEquals("SUCCESS", status);
97 //       Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
98 //
99 //
100 //
101 //
102 //   }
103 //
104 //   @Ignore("Test is taking 60 seconds")
105 //   @Test(expected=Exception.class)
106 //   public final void testLoadSequenceIntoDB() throws SvcLogicException {
107 //
108 //
109 //       SvcLogicContext localContext = new SvcLogicContext();
110 //       QueryStatus status = dgGeneralDBService.loadSequenceIntoDB(localContext) ;
111 //       Assert.assertEquals("SUCCESS", status);
112 //       Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
113 //       /*SvcLogicContext ctx = new SvcLogicContext();
114 //
115 //       if (serviceLogic != null && localContext != null) {
116 //           String queryString = "INSERT INTO " + FlowControllerConstants.DB_REQUEST_ARTIFACTS
117 //                   + " set request_id =  ' kusuma_test' , action = 'Configure', action_level =  'VNF' , vnf_type = 'vComp' , category = 'config_Template'  , artifact_content = '', updated_date = sysdate() ";
118 //           Mockito.when(serviceLogic.save("SQL", false, false, queryString, null, null, localContext))
119 //                   .thenReturn(status);
120 //           Assert.assertEquals("SUCCESS", status);
121 //           Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);*/
122 //
123 //
124 //
125 //   }
126 //
127 //   @Ignore
128 //   @Test(expected=Exception.class)
129 //   public final void testPopulateModuleAndRPC() throws Exception {
130 //       SvcLogicContext localContext = new SvcLogicContext();
131 //       SvcLogicContext ctx = new SvcLogicContext();
132 //       String vnf_type = "test";
133 //    dgGeneralDBService.populateModuleAndRPC(transaction, vnf_type);;
134 //
135 //
136 //   }
137 //
138 //   @Ignore("Test is taking 60 seconds")
139 //   @Test(expected=Exception.class)
140 //   public final void testGetDependencyInfo() throws SvcLogicException {
141 //       SvcLogicContext localContext = new SvcLogicContext();
142 //        String status = dgGeneralDBService.getDependencyInfo(localContext);
143 //           Assert.assertEquals("SUCCESS", status);
144 //           Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
145 //
146 //   }
147 //
148 //   @Ignore("Test is taking 60 seconds")
149 //   @Test(expected=Exception.class)
150 //   public final void testGetCapabilitiesData() throws SvcLogicException {
151 //       SvcLogicContext localContext = new SvcLogicContext();
152 //       String status = dgGeneralDBService.getCapabilitiesData(localContext);
153 //           Assert.assertEquals("SUCCESS", status);
154 //           Assert.assertNotEquals("Error - while getting FlowReferenceData", "FAILURE", status);
155 //
156 //   }
157
158      
159     @Test
160     public final void testGetCapabilitiesData1() throws Exception {
161         MockDBService dbService = MockDBService.initialise();
162         SvcLogicContext ctx = new SvcLogicContext();
163         ctx.setAttribute("test", "test");
164         String status = dbService.getCapabilitiesData(ctx);
165         assertEquals("TestArtifactContent", status);
166
167     }
168
169     @Test
170     public final void testGetDependencyInfo() throws Exception {
171         MockDBService dbService = MockDBService.initialise();
172         SvcLogicContext ctx = new SvcLogicContext();
173         String status = dbService.getDependencyInfo(ctx);
174         assertEquals("TestArtifactContent", status);
175     }
176
177     @Test
178     public final void testGetDesignTimeFlowModel() throws Exception {
179         MockDBService dbService = MockDBService.initialise();
180         SvcLogicContext ctx = new SvcLogicContext();
181         String status = dbService.getDesignTimeFlowModel(ctx);
182         assertEquals("TestArtifactContent", status);
183     }
184
185     @Test
186     public final void testGetFlowReferenceData() throws Exception {
187         MockDBService dbService = MockDBService.initialise();
188         SvcLogicContext ctx = new SvcLogicContext();
189         Map<String, String> inParams = null;
190         dbService.getFlowReferenceData(ctx, inParams, ctx);
191         assertEquals("TestSequence", ctx.getAttribute("SEQUENCE_TYPE"));
192     }
193
194     @Test
195     public final void testLoadSequenceIntoDB1() throws Exception {
196         MockDBService dbService = MockDBService.initialise();
197         SvcLogicContext ctx = new SvcLogicContext();
198         QueryStatus result = dbService.loadSequenceIntoDB(ctx);
199         assertEquals("SUCCESS", result.toString());
200     }
201
202     @Test
203     public final void testPopulateModuleAndRPC() throws Exception {
204         MockDBService dbService = MockDBService.initialise();
205         Transaction transaction = new Transaction();
206         String vnfType = "TestVNF";
207         dbService.populateModuleAndRPC(transaction, vnfType);
208         assertEquals("TestModule", transaction.getExecutionModule());
209     }
210
211     @Test
212     public void testHasSingleProtocol() throws Exception {
213         MockDBService dbService = MockDBService.initialise();
214         SvcLogicContext ctx = new SvcLogicContext();
215         String vnfTType = "TestVNF";
216         String fn = "test";
217         Transaction transaction = new Transaction();
218         boolean result = Whitebox.invokeMethod(dbService, "hasSingleProtocol", transaction, vnfTType, fn, ctx);
219         assertEquals(true, result);
220     }
221 }