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