ec173146aa80662992dc322957a9a4ced95e5618
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APP-C
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.openecomp.appc.data.services.db;
21
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;
34
35 public class TestDGGeneralDBService {
36     DGGeneralDBService dbService;
37     private static String STRING_ENCODING = "utf-8";
38
39     // @Before
40     public void setUp() {
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");
45         }
46         try {
47             props.load(propStr);
48             propStr.close();
49         } catch (Exception e) {
50             e.printStackTrace();
51             System.err.println("Could not initialize properties");
52         }
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));
58         }
59         dbService = DGGeneralDBService.initialise();
60     }
61
62     @Test(expected = Exception.class)
63     public void testGetUploadConfig() throws SvcLogicException {
64
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");
70
71     }
72
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");
79     }
80
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");
87
88     }
89
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");
96
97     }
98
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");
106
107     }
108
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");
116
117     }
118
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");
126
127     }
128
129     @Test(expected = Exception.class)
130     public void testGetTemplateByVnfType() throws SvcLogicException {
131
132         SvcLogicContext ctx = new SvcLogicContext();
133         ctx.setAttribute("vnf-type", "test");
134         QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template");
135         assertEquals(status, "SUCCESS");
136
137     }
138
139     @Test(expected = Exception.class)
140     public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException {
141
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");
147
148     }
149
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");
156
157     }
158
159     @Test(expected = Exception.class)
160     public void testGetMaxConfigFileId() throws SvcLogicException {
161
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");
167
168     }
169
170     @Test(expected = Exception.class)
171     public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException {
172
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",
177                 "ibcx0001vm001");
178         assertEquals(status, "SUCCESS");
179
180     }
181
182     @Test(expected = Exception.class)
183     public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException {
184
185         SvcLogicContext ctx = new SvcLogicContext();
186         ctx.setAttribute("vnf-type", "test");
187         QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test");
188         assertEquals(status, "SUCCESS");
189     }
190
191     @Test(expected = Exception.class)
192     public void testSaveConfigTxLog() throws SvcLogicException, IOException {
193
194         SvcLogicContext ctx = new SvcLogicContext();
195         String message = IOUtils.toString(
196                 TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"),
197                 STRING_ENCODING);
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");
204     }
205
206 }