Junit for code coverage in artifact-handler
[appc.git] / appc-inbound / appc-artifact-handler / provider / src / test / java / org / onap / appc / artifact / handler / dbservices / DBServiceTest.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  * Modifications Copyright (C) 2018 IBM
10  * ================================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.appc.artifact.handler.dbservices;
27
28 import org.junit.Ignore;
29 import org.junit.Test;
30 import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import static org.junit.Assert.assertEquals;
33
34 public class DBServiceTest {
35
36     @Test
37     public void testSaveArtifacts() throws Exception {
38         MockDBService dbService = MockDBService.initialise();
39         SvcLogicContext ctx = new SvcLogicContext();
40         ctx.setAttribute("test", "test");
41         int internalVersion = 1;
42         dbService.saveArtifacts(ctx, internalVersion);
43     }
44
45     @Test
46     public void testSaveArtifactsException() throws Exception {
47         MockDBService dbService = MockDBService.initialise();
48         SvcLogicContext ctx = new SvcLogicContext();
49         ctx.setAttribute("test", "test");
50         int internalVersion = 1;
51         dbService.saveArtifacts(ctx, internalVersion);
52     }
53
54     @Test
55     public void testLogData() throws Exception {
56         MockDBService dbService = MockDBService.initialise();
57         SvcLogicContext ctx = new SvcLogicContext();
58         ctx.setAttribute("test", "test");
59         String prefix = "test";
60         dbService.logData(ctx, prefix);
61     }
62
63
64     @Test
65     public void testLogDataException() throws Exception {
66         MockDBService dbService = MockDBService.initialise();
67         SvcLogicContext ctx = new SvcLogicContext();
68         ctx.setAttribute("test", "test");
69         String prefix = "test";
70         dbService.logData(ctx, prefix);
71     }
72
73     @Test
74     public void testProcessConfigActionDg() throws Exception {
75         MockDBService dbService = MockDBService.initialise();
76         SvcLogicContext ctx = new SvcLogicContext();
77         ctx.setAttribute("test", "test");
78         boolean isUpdate = true;
79         ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference");
80         dbService.processConfigActionDg(ctx, isUpdate);
81     }
82
83     @Test
84     public void testProcessConfigActionDgException() throws Exception {
85         MockDBService dbService = MockDBService.initialise();
86         SvcLogicContext ctx = new SvcLogicContext();
87         ctx.setAttribute("test", "test");
88         boolean isUpdate = true;
89         ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference");
90         dbService.processConfigActionDg(ctx, isUpdate);
91     }
92
93     @Test
94     public void testGetModelDataInformationbyArtifactName() throws Exception {
95         MockDBService dbService = MockDBService.initialise();
96         SvcLogicContext ctx = new SvcLogicContext();
97         ctx.setAttribute("test", "test");
98         String artifactName = "test";
99         dbService.getModelDataInformationbyArtifactName(artifactName);
100     }
101
102     @Test
103     public void testGetModelDataInformationbyArtifactNameException() throws Exception {
104         MockDBService dbService = MockDBService.initialise();
105         SvcLogicContext ctx = new SvcLogicContext();
106         ctx.setAttribute("test", "test");
107         String artifactName = "test";
108         dbService.getModelDataInformationbyArtifactName(artifactName);
109     }
110
111     @Test
112     public void testUpdateYangContents() throws Exception {
113         MockDBService dbService = MockDBService.initialise();
114         SvcLogicContext ctx = new SvcLogicContext();
115         ctx.setAttribute("test", "test");
116         String artifactName = "test";
117         String artifactId = "TestArtifact";
118         String yangContents = "TestYangContents";
119         dbService.updateYangContents(ctx, artifactId, yangContents);
120     }
121
122     @Test
123     public void testUpdateYangContentsException() throws Exception {
124         MockDBService dbService = MockDBService.initialise();
125         SvcLogicContext ctx = new SvcLogicContext();
126         ctx.setAttribute("test", "test");
127         String artifactName = "test";
128         String artifactId = "TestArtifact";
129         String yangContents = "TestYangContents";
130         dbService.updateYangContents(ctx, artifactId, yangContents);
131     }
132
133     @Test
134     public void testInsertProtocolReference() throws Exception {
135         MockDBService dbService = MockDBService.initialise();
136         SvcLogicContext ctx = new SvcLogicContext();
137         ctx.setAttribute("test", "test");
138         String vnfType = "testVnf";
139         String protocol = "testProtocol";
140         String action = "testAction";
141         String actionLevel = "testActionLevel";
142         String template = "testTemplateData";
143         dbService.insertProtocolReference(ctx, vnfType, protocol, action, actionLevel, template);
144     }
145
146
147     @Test
148     public void testInsertProtocolReferenceException() throws Exception {
149         MockDBService dbService = MockDBService.initialise();
150         SvcLogicContext ctx = new SvcLogicContext();
151         ctx.setAttribute("test", "test");
152         String vnfType = "testVnf";
153         String protocol = "testProtocol";
154         String action = "testAction";
155         String actionLevel = "testActionLevel";
156         String template = "testTemplateData";
157         dbService.insertProtocolReference(ctx, vnfType, protocol, action, actionLevel, template);
158     }
159
160     @Test
161     public void testprocessDpwnloadDGReference() throws Exception {
162         MockDBService dbService = MockDBService.initialise();
163         SvcLogicContext ctx = new SvcLogicContext();
164         ctx.setAttribute("test", "test");
165         boolean isUpdate = true;
166         dbService.processDownloadDgReference(ctx, isUpdate);
167     }
168
169     @Test
170     public void testprocessDpwnloadDGReferenceException() throws Exception {
171         MockDBService dbService = MockDBService.initialise();
172         SvcLogicContext ctx = new SvcLogicContext();
173         ctx.setAttribute("test", "test");
174         boolean isUpdate = true;
175         dbService.processDownloadDgReference(ctx, isUpdate);
176     }
177
178     @Test
179     public void testProcessVnfcReference() throws Exception {
180         MockDBService dbService = MockDBService.initialise();
181         SvcLogicContext ctx = new SvcLogicContext();
182         ctx.setAttribute("test", "test");
183         boolean isUpdate = false;
184         dbService.processVnfcReference(ctx, isUpdate);
185     }
186
187     @Test
188     public void testProcessVnfcReferenceException() throws Exception {
189         MockDBService dbService = MockDBService.initialise();
190         SvcLogicContext ctx = new SvcLogicContext();
191         ctx.setAttribute("test", "test");
192         boolean isUpdate = true;
193         dbService.processVnfcReference(ctx, isUpdate);
194     }
195
196     @Test
197     public void testProcessDeviceAuthentication() throws Exception {
198         MockDBService dbService = MockDBService.initialise();
199         SvcLogicContext ctx = new SvcLogicContext();
200         ctx.setAttribute("test", "test");
201         ctx.setAttribute("url", "");
202         String expectedKey ="update DEVICE_AUTHENTICATION set USER_NAME = '' , PORT_NUMBER = 0, URL = ''  where VNF_TYPE = $vnf-type  AND PROTOCOL = $device-protocol AND  ACTION = $action";
203         boolean isUpdate = true;
204         dbService.processDeviceAuthentication(ctx, isUpdate);
205         assertEquals(expectedKey,ctx.getAttribute("keys"));
206     }
207
208     @Test
209     public void testProcessDeviceAuthenticationforFalse() throws Exception {
210         MockDBService dbService = MockDBService.initialise();
211         SvcLogicContext ctx = new SvcLogicContext();
212         ctx.setAttribute("test", "test");
213         ctx.setAttribute("url", "");
214         boolean isUpdate = false;
215         dbService.processDeviceAuthentication(ctx, isUpdate);
216         assertEquals(true,ctx.getAttribute("keys").contains("DEVICE_AUTHENTICATION"));
217     }
218
219     //@Test
220     public void testProcessDeviceAuthenticationException() throws Exception {
221         MockDBService dbService = MockDBService.initialise();
222         SvcLogicContext ctx = new SvcLogicContext();
223         ctx.setAttribute("test", "test");
224         boolean isUpdate = true;
225         dbService.processDeviceAuthentication(ctx, isUpdate);
226     }
227
228     @Test
229     public void testProcessDeviceInterfaceProtocol() throws Exception {
230         MockDBService dbService = MockDBService.initialise();
231         SvcLogicContext ctx = new SvcLogicContext();
232         ctx.setAttribute("test", "test");
233         boolean isUpdate = true;
234         dbService.processDeviceInterfaceProtocol(ctx, isUpdate);
235     }
236
237     @Test
238     public void testProcessDeviceInterfaceProtocolForFalse() throws Exception {
239         MockDBService dbService = MockDBService.initialise();
240         SvcLogicContext ctx = new SvcLogicContext();
241         ctx.setAttribute("test", "test");
242         boolean isUpdate = false;
243         dbService.processDeviceInterfaceProtocol(ctx, isUpdate);
244         assertEquals(true,ctx.getAttribute("keys").contains("DEVICE_INTERFACE_PROTOCOL"));
245     }
246
247     @Test
248     public void testProcessDeviceInterfaceProtocolException() throws Exception {
249         MockDBService dbService = MockDBService.initialise();
250         SvcLogicContext ctx = new SvcLogicContext();
251         ctx.setAttribute("test", "test");
252         boolean isUpdate = true;
253         dbService.processDeviceInterfaceProtocol(ctx, isUpdate);
254     }
255
256     @Test
257     public void testProcessSdcReferences() throws Exception {
258         MockDBService dbService = MockDBService.initialise();
259         SvcLogicContext ctx = new SvcLogicContext();
260         ctx.setAttribute("test", "test");
261         ctx.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, "testCategory");
262         boolean isUpdate = true;
263         dbService.processSdcReferences(ctx, isUpdate);
264     }
265
266     @Ignore
267     public void testProcessSdcReferencesException() throws Exception {
268         MockDBService dbService = MockDBService.initialise();
269         SvcLogicContext ctx = new SvcLogicContext();
270         ctx.setAttribute("test", "test");
271         boolean isUpdate = true;
272         dbService.processSdcReferences(ctx, isUpdate);
273     }
274
275     @Test
276     public void testIsArtifactUpdateRequired() throws Exception {
277         MockDBService dbService = MockDBService.initialise();
278         SvcLogicContext ctx = new SvcLogicContext();
279         ctx.setAttribute("test", "test");
280         String db = "db";
281         dbService.isArtifactUpdateRequired(ctx, db);
282     }
283
284     @Test
285     public void testIsArtifactUpdateRequiredExcetion() throws Exception {
286         MockDBService dbService = MockDBService.initialise();
287         SvcLogicContext ctx = new SvcLogicContext();
288         ctx.setAttribute("test", "test");
289         String db = "db";
290         dbService.isArtifactUpdateRequired(ctx, db);
291     }
292
293
294     @Test
295     public void testgetArtifactID() throws Exception {
296         MockDBService dbService = MockDBService.initialise();
297         SvcLogicContext ctx = new SvcLogicContext();
298         ctx.setAttribute("test", "test");
299         String db = "db";
300         dbService.getArtifactID(ctx, db);
301     }
302
303     @Test
304     public void testgetArtifactIDException() throws Exception {
305         MockDBService dbService = MockDBService.initialise();
306         SvcLogicContext ctx = new SvcLogicContext();
307         ctx.setAttribute("test", "test");
308         String db = "db";
309         dbService.getArtifactID(ctx, db);
310     }
311     @Test
312     public void testGetDownLoadDGReference() throws Exception {
313         MockDBService dbService = MockDBService.initialise();
314         SvcLogicContext ctx = new SvcLogicContext();
315         ctx.setAttribute("test", "test");
316         ctx.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL, "CLI");
317         assertEquals("TestDG", dbService.getDownLoadDGReference(ctx));
318     }
319 }
320