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=========================================================
24 package org.onap.appc.data.services.db;
26 import static org.junit.Assert.assertEquals;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.util.Enumeration;
30 import java.util.Properties;
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";
45 Properties props = new Properties();
46 InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
47 if (propStr == null) {
48 System.err.println("src/test/resources/svclogic.properties missing");
53 } catch (Exception e) {
55 System.err.println("Could not initialize properties");
57 // Add properties to global properties
58 Enumeration propNames = props.keys();
59 while (propNames.hasMoreElements()) {
60 String propName = (String) propNames.nextElement();
61 System.setProperty(propName, props.getProperty(propName));
63 dbService = DGGeneralDBService.initialise();
66 @Test(expected = Exception.class)
67 public void testGetUploadConfig() throws SvcLogicException {
69 SvcLogicContext ctx = new SvcLogicContext();
70 ctx.setAttribute("vnf-name", "test");
71 ctx.setAttribute("vnf-id", "test");
72 QueryStatus status = dbService.getUploadConfigInfo(ctx, "test");
73 assertEquals(status, "SUCCESS");
77 @Test(expected = Exception.class)
78 public void testGetDeviceProtocolByVnfType() throws SvcLogicException {
79 SvcLogicContext ctx = new SvcLogicContext();
80 ctx.setAttribute("vnf-type", "test");
81 QueryStatus status = dbService.getDeviceProtocolByVnfType(ctx, "test");
82 assertEquals(status, "SUCCESS");
85 @Test(expected = Exception.class)
86 public void testGettConfigFileReferenceByFileTypeNVnfType() throws SvcLogicException {
87 SvcLogicContext ctx = new SvcLogicContext();
88 ctx.setAttribute("vnf-type", "test");
89 QueryStatus status = dbService.getConfigFileReferenceByFileTypeNVnfType(ctx, "test", "device_configuration");
90 assertEquals(status, "SUCCESS");
94 @Test(expected = Exception.class)
95 public void testGetDeviceAuthenticationByVnfType() throws Exception {
96 SvcLogicContext ctx = new SvcLogicContext();
97 ctx.setAttribute("vnf-type", "test");
98 QueryStatus status = dbService.getDeviceAuthenticationByVnfType(ctx, "test");
99 assertEquals(status, "SUCCESS");
103 @Test(expected = Exception.class)
104 public void testGetTemplate() throws Exception {
105 SvcLogicContext ctx = new SvcLogicContext();
106 ctx.setAttribute("vnfc-type", "test");
107 ctx.setAttribute("request-action", "Configure");
108 QueryStatus status = dbService.getTemplate(ctx, "test", "config_template");
109 assertEquals(status, "SUCCESS");
113 @Test(expected = Exception.class)
114 public void testGetTemplateByVnfTypeNAction() throws Exception {
115 SvcLogicContext ctx = new SvcLogicContext();
116 ctx.setAttribute("vnf-type", "test");
117 ctx.setAttribute("request-action", "Configure");
118 QueryStatus status = dbService.getTemplateByVnfTypeNAction(ctx, "test", "config_template");
119 assertEquals(status, "SUCCESS");
123 @Test(expected = Exception.class)
124 public void testGetTemplateByTemplateName() throws Exception {
125 SvcLogicContext ctx = new SvcLogicContext();
126 ctx.setAttribute("request-action", "Configure");
127 ctx.setAttribute("vnf-type", "test");
128 QueryStatus status = dbService.getTemplateByTemplateName(ctx, "test", "template.json");
129 assertEquals(status, "SUCCESS");
133 @Test(expected = Exception.class)
134 public void testGetTemplateByVnfType() throws SvcLogicException {
136 SvcLogicContext ctx = new SvcLogicContext();
137 ctx.setAttribute("vnf-type", "test");
138 QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template");
139 assertEquals(status, "SUCCESS");
143 @Test(expected = Exception.class)
144 public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException {
146 SvcLogicContext ctx = new SvcLogicContext();
147 ctx.setAttribute("vnf-type", "test");
148 ctx.setAttribute("request-action", "ConfigModify");
149 QueryStatus status = dbService.getConfigureActionDGByVnfTypeNAction(ctx, "test");
150 assertEquals(status, "SUCCESS");
154 @Test(expected = Exception.class)
155 public void testGetConfigureActionDGByVnfType() throws SvcLogicException {
156 SvcLogicContext ctx = new SvcLogicContext();
157 ctx.setAttribute("vnf-type", "test");
158 QueryStatus status = dbService.getConfigureActionDGByVnfType(ctx, "test");
159 assertEquals(status, "SUCCESS");
163 @Test(expected = Exception.class)
164 public void testGetMaxConfigFileId() throws SvcLogicException {
166 SvcLogicContext ctx = new SvcLogicContext();
167 ctx.setAttribute("vnf-id", "test");
168 ctx.setAttribute("vm-name", "test");
169 QueryStatus status = dbService.getMaxConfigFileId(ctx, "test", "device_configuration");
170 assertEquals(status, "SUCCESS");
174 @Test(expected = Exception.class)
175 public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException {
177 SvcLogicContext ctx = new SvcLogicContext();
178 ctx.setAttribute("vnf-id", "test");
179 ctx.setAttribute("vm-name", "test");
180 QueryStatus status = dbService.getConfigFilesByVnfVmNCategory(ctx, "test", "device_configuration", "test",
182 assertEquals(status, "SUCCESS");
186 @Test(expected = Exception.class)
187 public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException {
189 SvcLogicContext ctx = new SvcLogicContext();
190 ctx.setAttribute("vnf-type", "test");
191 QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test");
192 assertEquals(status, "SUCCESS");
195 @Test(expected = Exception.class)
196 public void testSaveConfigTxLog() throws SvcLogicException, IOException {
198 SvcLogicContext ctx = new SvcLogicContext();
199 String message = IOUtils.toString(
200 TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"),
202 ctx.setAttribute("request-id", "1234");
203 String escapedMessage = StringEscapeUtils.escapeSql(message);
204 ctx.setAttribute("log-message", escapedMessage);
205 ctx.setAttribute("log-message-type", "request");
206 QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test");
207 assertEquals(status, "SUCCESS");