2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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=========================================================
24 package org.onap.appc.data.services.db;
26 import static org.junit.Assert.assertEquals;
27 import java.io.IOException;
28 import org.apache.commons.io.IOUtils;
29 import org.apache.commons.lang.StringEscapeUtils;
30 import org.junit.Test;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
34 import org.onap.appc.data.services.db.DGGeneralDBService;
36 public class TestDGGeneralDBService {
37 DGGeneralDBService dbService;
38 private static String STRING_ENCODING = "utf-8";
41 public void testGetUploadConfig() throws SvcLogicException {
43 SvcLogicContext ctx = new SvcLogicContext();
44 ctx.setAttribute("vnf-name", "test");
45 ctx.setAttribute("vnf-id", "test");
46 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
47 QueryStatus status = dbService.getUploadConfigInfo(ctx, "test");
48 assertEquals(status, QueryStatus.SUCCESS);
53 public void testGetDeviceProtocolByVnfType() throws SvcLogicException {
54 SvcLogicContext ctx = new SvcLogicContext();
55 ctx.setAttribute("vnf-type", "test");
56 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
57 QueryStatus status = dbService.getDeviceProtocolByVnfType(ctx, "test");
58 assertEquals(status, QueryStatus.SUCCESS);
62 public void testGettConfigFileReferenceByFileTypeNVnfType() throws SvcLogicException {
63 SvcLogicContext ctx = new SvcLogicContext();
64 ctx.setAttribute("vnf-type", "test");
65 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
66 QueryStatus status = dbService.getConfigFileReferenceByFileTypeNVnfType(ctx, "test", "device_configuration");
67 assertEquals(status, QueryStatus.SUCCESS);
72 public void testGetDeviceAuthenticationByVnfType() throws Exception {
73 SvcLogicContext ctx = new SvcLogicContext();
74 ctx.setAttribute("vnf-type", "test");
75 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
76 QueryStatus status = dbService.getDeviceAuthenticationByVnfType(ctx, "test");
77 assertEquals(status, QueryStatus.SUCCESS);
82 public void testGetTemplate() throws Exception {
83 SvcLogicContext ctx = new SvcLogicContext();
84 ctx.setAttribute("vnfc-type", "test");
85 ctx.setAttribute("request-action", "Configure");
86 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
87 QueryStatus status = dbService.getTemplate(ctx, "test", "config_template");
88 assertEquals(status, QueryStatus.SUCCESS);
93 public void testGetTemplateByVnfTypeNAction() throws Exception {
94 SvcLogicContext ctx = new SvcLogicContext();
95 ctx.setAttribute("vnf-type", "test");
96 ctx.setAttribute("request-action", "ConfigScaleOut");
97 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
98 QueryStatus status = dbService.getTemplateByVnfTypeNAction(ctx, "test", "config_template");
99 assertEquals(status, QueryStatus.SUCCESS);
104 public void testGetTemplateByTemplateName() throws Exception {
105 SvcLogicContext ctx = new SvcLogicContext();
106 ctx.setAttribute("request-action", "Configure");
107 ctx.setAttribute("vnf-type", "test");
108 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
109 QueryStatus status = dbService.getTemplateByTemplateName(ctx, "test", "template.json");
110 assertEquals(status, QueryStatus.SUCCESS);
115 public void testGetTemplateByVnfType() throws SvcLogicException {
117 SvcLogicContext ctx = new SvcLogicContext();
118 ctx.setAttribute("vnf-type", "test");
119 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
120 QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template");
121 assertEquals(status, QueryStatus.SUCCESS);
126 public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException {
128 SvcLogicContext ctx = new SvcLogicContext();
129 ctx.setAttribute("vnf-type", "test");
130 ctx.setAttribute("request-action", "ConfigModify");
131 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
132 QueryStatus status = dbService.getConfigureActionDGByVnfTypeNAction(ctx, "test");
133 assertEquals(status, QueryStatus.SUCCESS);
138 public void testGetConfigureActionDGByVnfType() throws SvcLogicException {
139 SvcLogicContext ctx = new SvcLogicContext();
140 ctx.setAttribute("vnf-type", "test");
141 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
142 QueryStatus status = dbService.getConfigureActionDGByVnfType(ctx, "test");
143 assertEquals(status, QueryStatus.SUCCESS);
148 public void testGetMaxConfigFileId() throws SvcLogicException {
150 SvcLogicContext ctx = new SvcLogicContext();
151 ctx.setAttribute("vnf-id", "test");
152 ctx.setAttribute("vm-name", "test");
153 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
154 QueryStatus status = dbService.getMaxConfigFileId(ctx, "test", "device_configuration");
155 assertEquals(status, QueryStatus.SUCCESS);
160 public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException {
162 SvcLogicContext ctx = new SvcLogicContext();
163 ctx.setAttribute("vnf-id", "test");
164 ctx.setAttribute("vm-name", "test");
165 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
166 QueryStatus status = dbService.getConfigFilesByVnfVmNCategory(ctx, "test", "device_configuration", "test",
168 assertEquals(status, QueryStatus.SUCCESS);
173 public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException {
175 SvcLogicContext ctx = new SvcLogicContext();
176 ctx.setAttribute("vnf-type", "test");
177 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
178 QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test");
179 assertEquals(status, QueryStatus.SUCCESS);
183 public void testSaveConfigTxLog() throws SvcLogicException, IOException {
185 SvcLogicContext ctx = new SvcLogicContext();
186 String message = IOUtils.toString(
187 TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"),
189 ctx.setAttribute("request-id", "1234");
190 String escapedMessage = StringEscapeUtils.escapeSql(message);
191 ctx.setAttribute("log-message", escapedMessage);
192 ctx.setAttribute("log-message-type", "request");
193 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
194 QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test");
195 assertEquals(status, QueryStatus.SUCCESS);
199 public void testGetVnfcReferenceByVnfTypeNActionWithTemplateModelId() throws Exception {
200 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
201 SvcLogicContext ctx = new SvcLogicContext();
202 String prefix="test";
203 String templateModelId = "template001";
204 dbService.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, prefix, templateModelId);
208 public void testGetTemplateWithTemplateModelId() throws Exception {
209 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
210 SvcLogicContext ctx = new SvcLogicContext();
211 String prefix="test";
212 String templateModelId = "template001";
213 String fileCategory="testCategory";
214 dbService.getTemplateWithTemplateModelId(ctx, prefix, fileCategory, templateModelId);
218 public void testgetTemplateByVnfTypeNActionWithTemplateModelId() throws Exception {
219 MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise();
220 SvcLogicContext ctx = new SvcLogicContext();
221 String prefix="test";
222 String templateModelId = "template001";
223 String fileCategory="testCategory";
224 dbService.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, prefix, fileCategory, templateModelId);