043283fb146cb51eed966968eb6f242984197790
[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.openecomp.appc.artifact.handler.dbservices;
26
27 import java.nio.charset.Charset;
28 import org.json.JSONObject;
29 import org.junit.Test;
30 import org.openecomp.appc.artifact.handler.utils.SdcArtifactHandlerConstants;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.powermock.reflect.Whitebox;
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(expected = Exception.class)
46     public void testSaveArtifactsException() throws Exception {
47         DBService dbService = DBService.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(expected = Exception.class)
65     public void testLogDataException() throws Exception {
66         DBService dbService = DBService.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(expected = Exception.class)
84     public void testProcessConfigActionDgException() throws Exception {
85         DBService dbService = DBService.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(expected = Exception.class)
103     public void testGetModelDataInformationbyArtifactNameException() throws Exception {
104         DBService dbService = DBService.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(expected = Exception.class)
123     public void testUpdateYangContentsException() throws Exception {
124         DBService dbService = DBService.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(expected = Exception.class)
148     public void testInsertProtocolReferenceException() throws Exception {
149         DBService dbService = DBService.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(expected = Exception.class)
170     public void testprocessDpwnloadDGReferenceException() throws Exception {
171         DBService dbService = DBService.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 = true;
184         dbService.processVnfcReference(ctx, isUpdate);
185     }
186
187     @Test(expected = Exception.class)
188     public void testProcessVnfcReferenceException() throws Exception {
189         DBService dbService = DBService.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         boolean isUpdate = true;
202         dbService.processDeviceAuthentication(ctx, isUpdate);
203     }
204
205     @Test(expected = Exception.class)
206     public void testProcessDeviceAuthenticationException() throws Exception {
207         DBService dbService = DBService.initialise();
208         SvcLogicContext ctx = new SvcLogicContext();
209         ctx.setAttribute("test", "test");
210         boolean isUpdate = true;
211         dbService.processDeviceAuthentication(ctx, isUpdate);
212     }
213
214     @Test
215     public void testProcessDeviceInterfaceProtocol() throws Exception {
216         MockDBService dbService = MockDBService.initialise();
217         SvcLogicContext ctx = new SvcLogicContext();
218         ctx.setAttribute("test", "test");
219         boolean isUpdate = true;
220         dbService.processDeviceInterfaceProtocol(ctx, isUpdate);
221     }
222
223     @Test(expected = Exception.class)
224     public void testProcessDeviceInterfaceProtocolException() throws Exception {
225         DBService dbService = DBService.initialise();
226         SvcLogicContext ctx = new SvcLogicContext();
227         ctx.setAttribute("test", "test");
228         boolean isUpdate = true;
229         dbService.processDeviceInterfaceProtocol(ctx, isUpdate);
230     }
231
232     @Test
233     public void testProcessSdcReferences() throws Exception {
234         MockDBService dbService = MockDBService.initialise();
235         SvcLogicContext ctx = new SvcLogicContext();
236         ctx.setAttribute("test", "test");
237         boolean isUpdate = true;
238         dbService.processSdcReferences(ctx, isUpdate);
239     }
240
241     @Test(expected = Exception.class)
242     public void testProcessSdcReferencesException() throws Exception {
243         DBService dbService = DBService.initialise();
244         SvcLogicContext ctx = new SvcLogicContext();
245         ctx.setAttribute("test", "test");
246         boolean isUpdate = true;
247         dbService.processSdcReferences(ctx, isUpdate);
248     }
249
250     @Test
251     public void testIsArtifactUpdateRequired() throws Exception {
252         MockDBService dbService = MockDBService.initialise();
253         SvcLogicContext ctx = new SvcLogicContext();
254         ctx.setAttribute("test", "test");
255         String db = "db";
256         dbService.isArtifactUpdateRequired(ctx, db);
257     }
258
259     @Test(expected = Exception.class)
260     public void testIsArtifactUpdateRequiredExcetion() throws Exception {
261         DBService dbService = DBService.initialise();
262         SvcLogicContext ctx = new SvcLogicContext();
263         ctx.setAttribute("test", "test");
264         String db = "db";
265         dbService.isArtifactUpdateRequired(ctx, db);
266     }
267
268
269     @Test
270     public void testgetArtifactID() throws Exception {
271         MockDBService dbService = MockDBService.initialise();
272         SvcLogicContext ctx = new SvcLogicContext();
273         ctx.setAttribute("test", "test");
274         String db = "db";
275         dbService.getArtifactID(ctx, db);
276     }
277
278     @Test(expected = Exception.class)
279     public void testgetArtifactIDException() throws Exception {
280         DBService dbService = DBService.initialise();
281         SvcLogicContext ctx = new SvcLogicContext();
282         ctx.setAttribute("test", "test");
283         String db = "db";
284         dbService.getArtifactID(ctx, db);
285     }
286 }
287