Update license header in appc-inbound files
[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  * 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.artifact.handler.dbservices;
25
26 import java.nio.charset.Charset;
27 import org.json.JSONObject;
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 org.powermock.reflect.Whitebox;
33 import static org.junit.Assert.assertEquals;
34
35 public class DBServiceTest {
36
37     @Test
38     public void testSaveArtifacts() throws Exception {
39         MockDBService dbService = MockDBService.initialise();
40         SvcLogicContext ctx = new SvcLogicContext();
41         ctx.setAttribute("test", "test");
42         int internalVersion = 1;
43         dbService.saveArtifacts(ctx, internalVersion);
44     }
45
46     @Test
47     public void testSaveArtifactsException() throws Exception {
48         MockDBService dbService = MockDBService.initialise();
49         SvcLogicContext ctx = new SvcLogicContext();
50         ctx.setAttribute("test", "test");
51         int internalVersion = 1;
52         dbService.saveArtifacts(ctx, internalVersion);
53     }
54
55     @Test
56     public void testLogData() throws Exception {
57         MockDBService dbService = MockDBService.initialise();
58         SvcLogicContext ctx = new SvcLogicContext();
59         ctx.setAttribute("test", "test");
60         String prefix = "test";
61         dbService.logData(ctx, prefix);
62     }
63
64
65     @Test
66     public void testLogDataException() throws Exception {
67         MockDBService dbService = MockDBService.initialise();
68         SvcLogicContext ctx = new SvcLogicContext();
69         ctx.setAttribute("test", "test");
70         String prefix = "test";
71         dbService.logData(ctx, prefix);
72     }
73
74     @Test
75     public void testProcessConfigActionDg() throws Exception {
76         MockDBService dbService = MockDBService.initialise();
77         SvcLogicContext ctx = new SvcLogicContext();
78         ctx.setAttribute("test", "test");
79         boolean isUpdate = true;
80         ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference");
81         dbService.processConfigActionDg(ctx, isUpdate);
82     }
83
84     @Test
85     public void testProcessConfigActionDgException() throws Exception {
86         MockDBService dbService = MockDBService.initialise();
87         SvcLogicContext ctx = new SvcLogicContext();
88         ctx.setAttribute("test", "test");
89         boolean isUpdate = true;
90         ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference");
91         dbService.processConfigActionDg(ctx, isUpdate);
92     }
93
94     @Test
95     public void testGetModelDataInformationbyArtifactName() throws Exception {
96         MockDBService dbService = MockDBService.initialise();
97         SvcLogicContext ctx = new SvcLogicContext();
98         ctx.setAttribute("test", "test");
99         String artifactName = "test";
100         dbService.getModelDataInformationbyArtifactName(artifactName);
101     }
102
103     @Test
104     public void testGetModelDataInformationbyArtifactNameException() throws Exception {
105         MockDBService dbService = MockDBService.initialise();
106         SvcLogicContext ctx = new SvcLogicContext();
107         ctx.setAttribute("test", "test");
108         String artifactName = "test";
109         dbService.getModelDataInformationbyArtifactName(artifactName);
110     }
111
112     @Test
113     public void testUpdateYangContents() throws Exception {
114         MockDBService dbService = MockDBService.initialise();
115         SvcLogicContext ctx = new SvcLogicContext();
116         ctx.setAttribute("test", "test");
117         String artifactName = "test";
118         String artifactId = "TestArtifact";
119         String yangContents = "TestYangContents";
120         dbService.updateYangContents(ctx, artifactId, yangContents);
121     }
122
123     @Test
124     public void testUpdateYangContentsException() throws Exception {
125         MockDBService dbService = MockDBService.initialise();
126         SvcLogicContext ctx = new SvcLogicContext();
127         ctx.setAttribute("test", "test");
128         String artifactName = "test";
129         String artifactId = "TestArtifact";
130         String yangContents = "TestYangContents";
131         dbService.updateYangContents(ctx, artifactId, yangContents);
132     }
133
134     @Test
135     public void testInsertProtocolReference() throws Exception {
136         MockDBService dbService = MockDBService.initialise();
137         SvcLogicContext ctx = new SvcLogicContext();
138         ctx.setAttribute("test", "test");
139         String vnfType = "testVnf";
140         String protocol = "testProtocol";
141         String action = "testAction";
142         String actionLevel = "testActionLevel";
143         String template = "testTemplateData";
144         dbService.insertProtocolReference(ctx, vnfType, protocol, action, actionLevel, template);
145     }
146
147
148     @Test
149     public void testInsertProtocolReferenceException() throws Exception {
150         MockDBService dbService = MockDBService.initialise();
151         SvcLogicContext ctx = new SvcLogicContext();
152         ctx.setAttribute("test", "test");
153         String vnfType = "testVnf";
154         String protocol = "testProtocol";
155         String action = "testAction";
156         String actionLevel = "testActionLevel";
157         String template = "testTemplateData";
158         dbService.insertProtocolReference(ctx, vnfType, protocol, action, actionLevel, template);
159     }
160
161     @Test
162     public void testprocessDpwnloadDGReference() throws Exception {
163         MockDBService dbService = MockDBService.initialise();
164         SvcLogicContext ctx = new SvcLogicContext();
165         ctx.setAttribute("test", "test");
166         boolean isUpdate = true;
167         dbService.processDownloadDgReference(ctx, isUpdate);
168     }
169
170     @Test
171     public void testprocessDpwnloadDGReferenceException() throws Exception {
172         MockDBService dbService = MockDBService.initialise();
173         SvcLogicContext ctx = new SvcLogicContext();
174         ctx.setAttribute("test", "test");
175         boolean isUpdate = true;
176         dbService.processDownloadDgReference(ctx, isUpdate);
177     }
178
179     @Test
180     public void testProcessVnfcReference() throws Exception {
181         MockDBService dbService = MockDBService.initialise();
182         SvcLogicContext ctx = new SvcLogicContext();
183         ctx.setAttribute("test", "test");
184         boolean isUpdate = false;
185         dbService.processVnfcReference(ctx, isUpdate);
186     }
187
188     @Test
189     public void testProcessVnfcReferenceException() throws Exception {
190         MockDBService dbService = MockDBService.initialise();
191         SvcLogicContext ctx = new SvcLogicContext();
192         ctx.setAttribute("test", "test");
193         boolean isUpdate = true;
194         dbService.processVnfcReference(ctx, isUpdate);
195     }
196
197     //@Test
198     public void testProcessDeviceAuthentication() throws Exception {
199         MockDBService dbService = MockDBService.initialise();
200         SvcLogicContext ctx = new SvcLogicContext();
201         ctx.setAttribute("test", "test");
202         boolean isUpdate = true;
203         dbService.processDeviceAuthentication(ctx, isUpdate);
204     }
205
206     //@Test
207     public void testProcessDeviceAuthenticationException() throws Exception {
208         MockDBService dbService = MockDBService.initialise();
209         SvcLogicContext ctx = new SvcLogicContext();
210         ctx.setAttribute("test", "test");
211         boolean isUpdate = true;
212         dbService.processDeviceAuthentication(ctx, isUpdate);
213     }
214
215     @Test
216     public void testProcessDeviceInterfaceProtocol() throws Exception {
217         MockDBService dbService = MockDBService.initialise();
218         SvcLogicContext ctx = new SvcLogicContext();
219         ctx.setAttribute("test", "test");
220         boolean isUpdate = true;
221         dbService.processDeviceInterfaceProtocol(ctx, isUpdate);
222     }
223
224     @Test
225     public void testProcessDeviceInterfaceProtocolException() throws Exception {
226         MockDBService dbService = MockDBService.initialise();
227         SvcLogicContext ctx = new SvcLogicContext();
228         ctx.setAttribute("test", "test");
229         boolean isUpdate = true;
230         dbService.processDeviceInterfaceProtocol(ctx, isUpdate);
231     }
232
233     @Test
234     public void testProcessSdcReferences() throws Exception {
235         MockDBService dbService = MockDBService.initialise();
236         SvcLogicContext ctx = new SvcLogicContext();
237         ctx.setAttribute("test", "test");
238         ctx.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, "testCategory");
239         boolean isUpdate = true;
240         dbService.processSdcReferences(ctx, isUpdate);
241     }
242
243     @Ignore
244     public void testProcessSdcReferencesException() throws Exception {
245         MockDBService dbService = MockDBService.initialise();
246         SvcLogicContext ctx = new SvcLogicContext();
247         ctx.setAttribute("test", "test");
248         boolean isUpdate = true;
249         dbService.processSdcReferences(ctx, isUpdate);
250     }
251
252     @Test
253     public void testIsArtifactUpdateRequired() throws Exception {
254         MockDBService dbService = MockDBService.initialise();
255         SvcLogicContext ctx = new SvcLogicContext();
256         ctx.setAttribute("test", "test");
257         String db = "db";
258         dbService.isArtifactUpdateRequired(ctx, db);
259     }
260
261     @Test
262     public void testIsArtifactUpdateRequiredExcetion() throws Exception {
263         MockDBService dbService = MockDBService.initialise();
264         SvcLogicContext ctx = new SvcLogicContext();
265         ctx.setAttribute("test", "test");
266         String db = "db";
267         dbService.isArtifactUpdateRequired(ctx, db);
268     }
269
270
271     @Test
272     public void testgetArtifactID() throws Exception {
273         MockDBService dbService = MockDBService.initialise();
274         SvcLogicContext ctx = new SvcLogicContext();
275         ctx.setAttribute("test", "test");
276         String db = "db";
277         dbService.getArtifactID(ctx, db);
278     }
279
280     @Test
281     public void testgetArtifactIDException() throws Exception {
282         MockDBService dbService = MockDBService.initialise();
283         SvcLogicContext ctx = new SvcLogicContext();
284         ctx.setAttribute("test", "test");
285         String db = "db";
286         dbService.getArtifactID(ctx, db);
287     }
288     @Test
289     public void testGetDownLoadDGReference() throws Exception {
290         MockDBService dbService = MockDBService.initialise();
291         SvcLogicContext ctx = new SvcLogicContext();
292         ctx.setAttribute("test", "test");
293         ctx.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL, "CLI");
294         assertEquals("TestDG", dbService.getDownLoadDGReference(ctx));
295     }
296 }
297