2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.artifact.handler.dbservices;
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;
36 public class DBServiceTest {
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
181 public void testProcessVnfcReference() throws Exception {
182 MockDBService dbService = MockDBService.initialise();
183 SvcLogicContext ctx = new SvcLogicContext();
184 ctx.setAttribute("test", "test");
185 boolean isUpdate = false;
186 dbService.processVnfcReference(ctx, isUpdate);
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);
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);
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);
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);
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);
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);
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);
254 public void testIsArtifactUpdateRequired() throws Exception {
255 MockDBService dbService = MockDBService.initialise();
256 SvcLogicContext ctx = new SvcLogicContext();
257 ctx.setAttribute("test", "test");
259 dbService.isArtifactUpdateRequired(ctx, db);
263 public void testIsArtifactUpdateRequiredExcetion() throws Exception {
264 MockDBService dbService = MockDBService.initialise();
265 SvcLogicContext ctx = new SvcLogicContext();
266 ctx.setAttribute("test", "test");
268 dbService.isArtifactUpdateRequired(ctx, db);
273 public void testgetArtifactID() throws Exception {
274 MockDBService dbService = MockDBService.initialise();
275 SvcLogicContext ctx = new SvcLogicContext();
276 ctx.setAttribute("test", "test");
278 dbService.getArtifactID(ctx, db);
282 public void testgetArtifactIDException() throws Exception {
283 MockDBService dbService = MockDBService.initialise();
284 SvcLogicContext ctx = new SvcLogicContext();
285 ctx.setAttribute("test", "test");
287 dbService.getArtifactID(ctx, db);
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));