2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.appc.data.services.db;
22 import static org.junit.Assert.assertEquals;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.Enumeration;
26 import java.util.Properties;
27 import org.apache.commons.io.IOUtils;
28 import org.apache.commons.lang.StringEscapeUtils;
29 import org.junit.Test;
30 import org.openecomp.sdnc.sli.SvcLogicContext;
31 import org.openecomp.sdnc.sli.SvcLogicException;
32 import org.openecomp.sdnc.sli.SvcLogicResource.QueryStatus;
33 import org.openecomp.appc.data.services.db.DGGeneralDBService;
35 public class TestDGGeneralDBService {
36 DGGeneralDBService dbService;
37 private static String STRING_ENCODING = "utf-8";
41 Properties props = new Properties();
42 InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
43 if (propStr == null) {
44 System.err.println("src/test/resources/svclogic.properties missing");
49 } catch (Exception e) {
51 System.err.println("Could not initialize properties");
53 // Add properties to global properties
54 Enumeration propNames = props.keys();
55 while (propNames.hasMoreElements()) {
56 String propName = (String) propNames.nextElement();
57 System.setProperty(propName, props.getProperty(propName));
59 dbService = DGGeneralDBService.initialise();
62 @Test(expected = Exception.class)
63 public void testGetUploadConfig() throws SvcLogicException {
65 SvcLogicContext ctx = new SvcLogicContext();
66 ctx.setAttribute("vnf-name", "test");
67 ctx.setAttribute("vnf-id", "test");
68 QueryStatus status = dbService.getUploadConfigInfo(ctx, "test");
69 assertEquals(status, "SUCCESS");
73 @Test(expected = Exception.class)
74 public void testGetDeviceProtocolByVnfType() throws SvcLogicException {
75 SvcLogicContext ctx = new SvcLogicContext();
76 ctx.setAttribute("vnf-type", "test");
77 QueryStatus status = dbService.getDeviceProtocolByVnfType(ctx, "test");
78 assertEquals(status, "SUCCESS");
81 @Test(expected = Exception.class)
82 public void testGettConfigFileReferenceByFileTypeNVnfType() throws SvcLogicException {
83 SvcLogicContext ctx = new SvcLogicContext();
84 ctx.setAttribute("vnf-type", "test");
85 QueryStatus status = dbService.getConfigFileReferenceByFileTypeNVnfType(ctx, "test", "device_configuration");
86 assertEquals(status, "SUCCESS");
90 @Test(expected = Exception.class)
91 public void testGetDeviceAuthenticationByVnfType() throws Exception {
92 SvcLogicContext ctx = new SvcLogicContext();
93 ctx.setAttribute("vnf-type", "test");
94 QueryStatus status = dbService.getDeviceAuthenticationByVnfType(ctx, "test");
95 assertEquals(status, "SUCCESS");
99 @Test(expected = Exception.class)
100 public void testGetTemplate() throws Exception {
101 SvcLogicContext ctx = new SvcLogicContext();
102 ctx.setAttribute("vnfc-type", "test");
103 ctx.setAttribute("request-action", "Configure");
104 QueryStatus status = dbService.getTemplate(ctx, "test", "config_template");
105 assertEquals(status, "SUCCESS");
109 @Test(expected = Exception.class)
110 public void testGetTemplateByVnfTypeNAction() throws Exception {
111 SvcLogicContext ctx = new SvcLogicContext();
112 ctx.setAttribute("vnf-type", "test");
113 ctx.setAttribute("request-action", "Configure");
114 QueryStatus status = dbService.getTemplateByVnfTypeNAction(ctx, "test", "config_template");
115 assertEquals(status, "SUCCESS");
119 @Test(expected = Exception.class)
120 public void testGetTemplateByTemplateName() throws Exception {
121 SvcLogicContext ctx = new SvcLogicContext();
122 ctx.setAttribute("request-action", "Configure");
123 ctx.setAttribute("vnf-type", "test");
124 QueryStatus status = dbService.getTemplateByTemplateName(ctx, "test", "template.json");
125 assertEquals(status, "SUCCESS");
129 @Test(expected = Exception.class)
130 public void testGetTemplateByVnfType() throws SvcLogicException {
132 SvcLogicContext ctx = new SvcLogicContext();
133 ctx.setAttribute("vnf-type", "test");
134 QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template");
135 assertEquals(status, "SUCCESS");
139 @Test(expected = Exception.class)
140 public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException {
142 SvcLogicContext ctx = new SvcLogicContext();
143 ctx.setAttribute("vnf-type", "test");
144 ctx.setAttribute("request-action", "ConfigModify");
145 QueryStatus status = dbService.getConfigureActionDGByVnfTypeNAction(ctx, "test");
146 assertEquals(status, "SUCCESS");
150 @Test(expected = Exception.class)
151 public void testGetConfigureActionDGByVnfType() throws SvcLogicException {
152 SvcLogicContext ctx = new SvcLogicContext();
153 ctx.setAttribute("vnf-type", "test");
154 QueryStatus status = dbService.getConfigureActionDGByVnfType(ctx, "test");
155 assertEquals(status, "SUCCESS");
159 @Test(expected = Exception.class)
160 public void testGetMaxConfigFileId() throws SvcLogicException {
162 SvcLogicContext ctx = new SvcLogicContext();
163 ctx.setAttribute("vnf-id", "test");
164 ctx.setAttribute("vm-name", "test");
165 QueryStatus status = dbService.getMaxConfigFileId(ctx, "test", "device_configuration");
166 assertEquals(status, "SUCCESS");
170 @Test(expected = Exception.class)
171 public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException {
173 SvcLogicContext ctx = new SvcLogicContext();
174 ctx.setAttribute("vnf-id", "test");
175 ctx.setAttribute("vm-name", "test");
176 QueryStatus status = dbService.getConfigFilesByVnfVmNCategory(ctx, "test", "device_configuration", "test",
178 assertEquals(status, "SUCCESS");
182 @Test(expected = Exception.class)
183 public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException {
185 SvcLogicContext ctx = new SvcLogicContext();
186 ctx.setAttribute("vnf-type", "test");
187 QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test");
188 assertEquals(status, "SUCCESS");
191 @Test(expected = Exception.class)
192 public void testSaveConfigTxLog() throws SvcLogicException, IOException {
194 SvcLogicContext ctx = new SvcLogicContext();
195 String message = IOUtils.toString(
196 TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"),
198 ctx.setAttribute("request-id", "1234");
199 String escapedMessage = StringEscapeUtils.escapeSql(message);
200 ctx.setAttribute("log-message", escapedMessage);
201 ctx.setAttribute("log-message-type", "request");
202 QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test");
203 assertEquals(status, "SUCCESS");