2 * ============LICENSE_START=======================================================
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
15 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.artifact.handler.dbservices;
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;
34 public class DBServiceTest {
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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"));
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"));
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);
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);
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"));
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);
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);
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);
276 public void testIsArtifactUpdateRequired() throws Exception {
277 MockDBService dbService = MockDBService.initialise();
278 SvcLogicContext ctx = new SvcLogicContext();
279 ctx.setAttribute("test", "test");
281 dbService.isArtifactUpdateRequired(ctx, db);
285 public void testIsArtifactUpdateRequiredExcetion() throws Exception {
286 MockDBService dbService = MockDBService.initialise();
287 SvcLogicContext ctx = new SvcLogicContext();
288 ctx.setAttribute("test", "test");
290 dbService.isArtifactUpdateRequired(ctx, db);
295 public void testgetArtifactID() throws Exception {
296 MockDBService dbService = MockDBService.initialise();
297 SvcLogicContext ctx = new SvcLogicContext();
298 ctx.setAttribute("test", "test");
300 dbService.getArtifactID(ctx, db);
304 public void testgetArtifactIDException() throws Exception {
305 MockDBService dbService = MockDBService.initialise();
306 SvcLogicContext ctx = new SvcLogicContext();
307 ctx.setAttribute("test", "test");
309 dbService.getArtifactID(ctx, db);
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));