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-2019 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=========================================================
25 package org.onap.appc.data.services.db;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNull;
30 import java.io.IOException;
31 import org.apache.commons.io.IOUtils;
32 import org.apache.commons.lang.StringEscapeUtils;
33 import org.junit.Test;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
37 import org.onap.appc.data.services.db.DGGeneralDBService;
39 public class TestDGGeneralDBService {
40 DGGeneralDBService dbService;
41 private static String STRING_ENCODING = "utf-8";
44 public void testGetUploadConfig() throws SvcLogicException {
46 SvcLogicContext ctx = new SvcLogicContext();
47 ctx.setAttribute("vnf-name", "test");
48 ctx.setAttribute("vnf-id", "test");
49 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
50 QueryStatus status = dbService.getUploadConfigInfo(ctx, "test");
51 assertEquals(status, QueryStatus.SUCCESS);
56 public void testGetDeviceProtocolByVnfType() throws SvcLogicException {
57 SvcLogicContext ctx = new SvcLogicContext();
58 ctx.setAttribute("vnf-type", "test");
59 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
60 QueryStatus status = dbService.getDeviceProtocolByVnfType(ctx, "test");
61 assertEquals(status, QueryStatus.SUCCESS);
65 public void testGettConfigFileReferenceByFileTypeNVnfType() throws SvcLogicException {
66 SvcLogicContext ctx = new SvcLogicContext();
67 ctx.setAttribute("vnf-type", "test");
68 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
69 QueryStatus status = dbService.getConfigFileReferenceByFileTypeNVnfType(ctx, "test", "device_configuration");
70 assertEquals(status, QueryStatus.SUCCESS);
75 public void testGetDeviceAuthenticationByVnfType() throws Exception {
76 SvcLogicContext ctx = new SvcLogicContext();
77 ctx.setAttribute("vnf-type", "test");
78 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
79 QueryStatus status = dbService.getDeviceAuthenticationByVnfType(ctx, "test");
80 assertEquals(status, QueryStatus.SUCCESS);
85 public void testGetTemplate() throws Exception {
86 SvcLogicContext ctx = new SvcLogicContext();
87 ctx.setAttribute("vnfc-type", "test");
88 ctx.setAttribute("request-action", "Configure");
89 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
90 QueryStatus status = dbService.getTemplate(ctx, "test", "config_template");
91 assertEquals(status, QueryStatus.SUCCESS);
96 public void testGetTemplateByVnfTypeNAction() throws Exception {
97 SvcLogicContext ctx = new SvcLogicContext();
98 ctx.setAttribute("vnf-type", "test");
99 ctx.setAttribute("request-action", "ConfigScaleOut");
100 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
101 QueryStatus status = dbService.getTemplateByVnfTypeNAction(ctx, "test", "config_template");
102 assertEquals(status, QueryStatus.SUCCESS);
107 public void testGetTemplateByTemplateName() throws Exception {
108 SvcLogicContext ctx = new SvcLogicContext();
109 ctx.setAttribute("request-action", "Configure");
110 ctx.setAttribute("vnf-type", "test");
111 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
112 QueryStatus status = dbService.getTemplateByTemplateName(ctx, "test", "template.json");
113 assertEquals(status, QueryStatus.SUCCESS);
118 public void testGetTemplateByVnfType() throws SvcLogicException {
120 SvcLogicContext ctx = new SvcLogicContext();
121 ctx.setAttribute("vnf-type", "test");
122 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
123 QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template");
124 assertEquals(status, QueryStatus.SUCCESS);
129 public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException {
131 SvcLogicContext ctx = new SvcLogicContext();
132 ctx.setAttribute("vnf-type", "test");
133 ctx.setAttribute("request-action", "ConfigModify");
134 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
135 QueryStatus status = dbService.getConfigureActionDGByVnfTypeNAction(ctx, "test");
136 assertEquals(status, QueryStatus.SUCCESS);
141 public void testGetConfigureActionDGByVnfType() throws SvcLogicException {
142 SvcLogicContext ctx = new SvcLogicContext();
143 ctx.setAttribute("vnf-type", "test");
144 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
145 QueryStatus status = dbService.getConfigureActionDGByVnfType(ctx, "test");
146 assertEquals(status, QueryStatus.SUCCESS);
151 public void testGetMaxConfigFileId() throws SvcLogicException {
153 SvcLogicContext ctx = new SvcLogicContext();
154 ctx.setAttribute("vnf-id", "test");
155 ctx.setAttribute("vm-name", "test");
156 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
157 QueryStatus status = dbService.getMaxConfigFileId(ctx, "test", "device_configuration");
158 assertEquals(status, QueryStatus.SUCCESS);
163 public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException {
165 SvcLogicContext ctx = new SvcLogicContext();
166 ctx.setAttribute("vnf-id", "test");
167 ctx.setAttribute("vm-name", "test");
168 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
169 QueryStatus status = dbService.getConfigFilesByVnfVmNCategory(ctx, "test", "device_configuration", "test",
171 assertEquals(status, QueryStatus.SUCCESS);
176 public void getVnfcReferenceByVnfcTypeNAction() throws SvcLogicException {
178 SvcLogicContext ctx = new SvcLogicContext();
179 ctx.setAttribute("vnf-type", "testVnf");
180 ctx.setAttribute("vnfc-type", "testVnfc");
181 ctx.setAttribute("request-action", "Configure");
182 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
183 QueryStatus status = dbService.getVnfcReferenceByVnfcTypeNAction(ctx, "test");
184 assertEquals(QueryStatus.SUCCESS, status);
188 public void testSaveConfigFiles() throws SvcLogicException {
190 SvcLogicContext ctx = new SvcLogicContext();
191 ctx.setAttribute("data-source", "test");
192 ctx.setAttribute("service-instance-id", "test");
193 ctx.setAttribute("request-action", "test");
194 ctx.setAttribute("vnf-type", "test");
195 ctx.setAttribute("vnfc-type", "test");
196 ctx.setAttribute("vnf-id", "test");
197 ctx.setAttribute("vnf-name", "test");
198 ctx.setAttribute("vm-name", "test");
199 ctx.setAttribute("file-category", "test");
200 ctx.setAttribute("file-content", "test");
202 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
203 QueryStatus status = dbService.saveConfigFiles(ctx, "test");
204 assertEquals(QueryStatus.SUCCESS, status);
209 public void testSavePrepareRelationship() throws SvcLogicException {
211 SvcLogicContext ctx = new SvcLogicContext();
212 ctx.setAttribute("service-instance-id", "test");
213 ctx.setAttribute("request-id", "test");
216 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
217 QueryStatus status = dbService.savePrepareRelationship(ctx, "test","test", "test");
218 assertEquals(QueryStatus.SUCCESS,status);
223 public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException {
225 SvcLogicContext ctx = new SvcLogicContext();
226 ctx.setAttribute("vnf-type", "test");
227 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
228 QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test");
229 assertEquals(QueryStatus.SUCCESS,status);
233 public void testSaveConfigTxLog() throws SvcLogicException, IOException {
235 SvcLogicContext ctx = new SvcLogicContext();
236 String message = IOUtils.toString(
237 TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"),
239 ctx.setAttribute("request-id", "1234");
240 String escapedMessage = StringEscapeUtils.escapeSql(message);
241 ctx.setAttribute("log-message", escapedMessage);
242 ctx.setAttribute("log-message-type", "request");
243 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
244 QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test");
245 assertEquals(status, QueryStatus.SUCCESS);
249 public void testGetVnfcReferenceByVnfTypeNActionWithTemplateModelId() throws Exception {
250 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
251 SvcLogicContext ctx = new SvcLogicContext();
252 String prefix="test";
253 String templateModelId = "template001";
254 dbService.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, prefix, templateModelId);
258 public void testGetTemplateWithTemplateModelId() throws Exception {
259 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
260 SvcLogicContext ctx = new SvcLogicContext();
261 String prefix="test";
262 String templateModelId = "template001";
263 String fileCategory="testCategory";
264 dbService.getTemplateWithTemplateModelId(ctx, prefix, fileCategory, templateModelId);
268 public void testgetTemplateByVnfTypeNActionWithTemplateModelId() throws Exception {
269 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
270 SvcLogicContext ctx = new SvcLogicContext();
271 String prefix="test";
272 String templateModelId = "template001";
273 String fileCategory="testCategory";
274 dbService.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, prefix, fileCategory, templateModelId);
278 public void testGetConfigFileReferenceByVnfType() throws Exception {
279 SvcLogicContext ctx = new SvcLogicContext();
280 ctx.setAttribute("vnf-type", "test");
281 ctx.setAttribute("request-action", "Configure");
282 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
283 QueryStatus status = dbService.getConfigFileReferenceByVnfType(ctx, "test");
284 assertEquals(status, QueryStatus.SUCCESS);
289 public void testGetTemplateByArtifactType() throws Exception {
290 SvcLogicContext ctx = new SvcLogicContext();
291 ctx.setAttribute("vnf-type", "test");
292 ctx.setAttribute("request-action", "Configure");
293 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
294 QueryStatus status = dbService.getTemplateByArtifactType(ctx, "test","XML","APPC-CONFIG");
295 assertEquals(QueryStatus.SUCCESS, status);
300 public void testGetCapability() throws Exception {
301 SvcLogicContext ctx = new SvcLogicContext();
302 ctx.setAttribute("vnf-type", "test");
303 ctx.setAttribute("artifactName", "template001");
304 ctx.setAttribute("maxInternalVersion", "1234");
305 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
306 String status = dbService.getCapability(ctx, "test");
312 public void testCleanContextPropertyByPrefix()
314 SvcLogicContext ctx = new SvcLogicContext();
315 ctx.setAttribute("vnf-type", "test");
316 ctx.setAttribute("request-action", "Configure");
317 ctx.setAttribute(".vnfc-type", "Configure");
318 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
319 dbService.cleanContextPropertyByPrefix(ctx, "test");
320 assertEquals(2,ctx.getAttributeKeySet().size());
324 public void testSaveUploadConfig() throws SvcLogicException
326 SvcLogicContext ctx = new SvcLogicContext();
327 ctx.setAttribute("request-id", "test");
328 ctx.setAttribute("request-action", "Configure");
329 ctx.setAttribute("originator-id", "test");
330 ctx.setAttribute("vnf-id", "test");
331 ctx.setAttribute("vm-name", "test");
332 ctx.setAttribute("vnf-host-ip-address", "10.0.0.1");
333 ctx.setAttribute("vnf-type", "test");
334 ctx.setAttribute("vnfc-type", "test");
335 ctx.setAttribute("tmp.escaped.devicerunningconfig", "10.0.0.1");
337 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
338 QueryStatus status= dbService.saveUploadConfig(ctx, "test");
339 assertEquals(QueryStatus.SUCCESS, status);
343 public void testUpdateUploadConfig() throws SvcLogicException
345 SvcLogicContext ctx = new SvcLogicContext();
347 ctx.setAttribute("vnf-type", "test");
348 ctx.setAttribute("vnfc-type", "test");
350 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
351 QueryStatus status= dbService.updateUploadConfig(ctx, "test",10);
352 assertEquals(QueryStatus.SUCCESS, status);