bcf6493397ef70087fc6f9b55a8300fd833509bb
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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 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
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
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.
22  *
23  * ============LICENSE_END=========================================================
24  */
25 package org.onap.appc.data.services.db;
26
27 import static org.junit.Assert.assertEquals;
28
29 import java.io.IOException;
30 import org.apache.commons.io.IOUtils;
31 import org.apache.commons.lang.StringEscapeUtils;
32 import org.junit.Test;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
36 import org.onap.appc.data.services.db.DGGeneralDBService;
37
38 public class TestDGGeneralDBService {
39     DGGeneralDBService dbService;
40     private static String STRING_ENCODING = "utf-8";
41
42     @Test
43     public void testGetUploadConfig() throws SvcLogicException {
44
45         SvcLogicContext ctx = new SvcLogicContext();
46         ctx.setAttribute("vnf-name", "test");
47         ctx.setAttribute("vnf-id", "test");
48         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
49         QueryStatus status = dbService.getUploadConfigInfo(ctx, "test");
50         assertEquals(status, QueryStatus.SUCCESS);
51
52     }
53
54     @Test
55     public void testGetDeviceProtocolByVnfType() throws SvcLogicException {
56         SvcLogicContext ctx = new SvcLogicContext();
57         ctx.setAttribute("vnf-type", "test");
58         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
59         QueryStatus status = dbService.getDeviceProtocolByVnfType(ctx, "test");
60         assertEquals(status, QueryStatus.SUCCESS);
61     }
62
63     @Test
64     public void testGettConfigFileReferenceByFileTypeNVnfType() throws SvcLogicException {
65         SvcLogicContext ctx = new SvcLogicContext();
66         ctx.setAttribute("vnf-type", "test");
67         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
68         QueryStatus status = dbService.getConfigFileReferenceByFileTypeNVnfType(ctx, "test", "device_configuration");
69         assertEquals(status, QueryStatus.SUCCESS);
70
71     }
72
73     @Test
74     public void testGetDeviceAuthenticationByVnfType() throws Exception {
75         SvcLogicContext ctx = new SvcLogicContext();
76         ctx.setAttribute("vnf-type", "test");
77         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
78         QueryStatus status = dbService.getDeviceAuthenticationByVnfType(ctx, "test");
79         assertEquals(status, QueryStatus.SUCCESS);
80
81     }
82
83     @Test
84     public void testGetTemplate() throws Exception {
85         SvcLogicContext ctx = new SvcLogicContext();
86         ctx.setAttribute("vnfc-type", "test");
87         ctx.setAttribute("request-action", "Configure");
88         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
89         QueryStatus status = dbService.getTemplate(ctx, "test", "config_template");
90         assertEquals(status, QueryStatus.SUCCESS);
91
92     }
93
94     @Test
95     public void testGetTemplateByVnfTypeNAction() throws Exception {
96         SvcLogicContext ctx = new SvcLogicContext();
97         ctx.setAttribute("vnf-type", "test");
98         ctx.setAttribute("request-action", "ConfigScaleOut");
99         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
100         QueryStatus status = dbService.getTemplateByVnfTypeNAction(ctx, "test", "config_template");
101         assertEquals(status, QueryStatus.SUCCESS);
102
103     }
104
105     @Test
106     public void testGetTemplateByTemplateName() throws Exception {
107         SvcLogicContext ctx = new SvcLogicContext();
108         ctx.setAttribute("request-action", "Configure");
109         ctx.setAttribute("vnf-type", "test");
110         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
111         QueryStatus status = dbService.getTemplateByTemplateName(ctx, "test", "template.json");
112         assertEquals(status, QueryStatus.SUCCESS);
113
114     }
115
116     @Test
117     public void testGetTemplateByVnfType() throws SvcLogicException {
118
119         SvcLogicContext ctx = new SvcLogicContext();
120         ctx.setAttribute("vnf-type", "test");
121         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
122         QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template");
123         assertEquals(status, QueryStatus.SUCCESS);
124
125     }
126
127     @Test
128     public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException {
129
130         SvcLogicContext ctx = new SvcLogicContext();
131         ctx.setAttribute("vnf-type", "test");
132         ctx.setAttribute("request-action", "ConfigModify");
133         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
134         QueryStatus status = dbService.getConfigureActionDGByVnfTypeNAction(ctx, "test");
135         assertEquals(status, QueryStatus.SUCCESS);
136
137     }
138
139     @Test
140     public void testGetConfigureActionDGByVnfType() throws SvcLogicException {
141         SvcLogicContext ctx = new SvcLogicContext();
142         ctx.setAttribute("vnf-type", "test");
143         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
144         QueryStatus status = dbService.getConfigureActionDGByVnfType(ctx, "test");
145         assertEquals(status, QueryStatus.SUCCESS);
146
147     }
148
149     @Test
150     public void testGetMaxConfigFileId() throws SvcLogicException {
151
152         SvcLogicContext ctx = new SvcLogicContext();
153         ctx.setAttribute("vnf-id", "test");
154         ctx.setAttribute("vm-name", "test");
155         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
156         QueryStatus status = dbService.getMaxConfigFileId(ctx, "test", "device_configuration");
157         assertEquals(status, QueryStatus.SUCCESS);
158
159     }
160
161     @Test
162     public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException {
163
164         SvcLogicContext ctx = new SvcLogicContext();
165         ctx.setAttribute("vnf-id", "test");
166         ctx.setAttribute("vm-name", "test");
167         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
168         QueryStatus status = dbService.getConfigFilesByVnfVmNCategory(ctx, "test", "device_configuration", "test",
169                 "ibcx0001vm001");
170         assertEquals(status, QueryStatus.SUCCESS);
171
172     }
173
174     @Test
175     public void getVnfcReferenceByVnfcTypeNAction() throws SvcLogicException {
176
177         SvcLogicContext ctx = new SvcLogicContext();
178         ctx.setAttribute("vnf-type", "testVnf");
179         ctx.setAttribute("vnfc-type", "testVnfc");
180         ctx.setAttribute("request-action", "Configure");
181         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
182         QueryStatus status = dbService.getVnfcReferenceByVnfcTypeNAction(ctx, "test");
183         assertEquals(QueryStatus.SUCCESS, status);
184     }
185     
186     @Test
187     public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException {
188
189         SvcLogicContext ctx = new SvcLogicContext();
190         ctx.setAttribute("vnf-type", "test");
191         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
192         QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test");
193         assertEquals(status, QueryStatus.SUCCESS);
194     }
195
196     @Test
197     public void testSaveConfigTxLog() throws SvcLogicException, IOException {
198
199         SvcLogicContext ctx = new SvcLogicContext();
200         String message = IOUtils.toString(
201                 TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"),
202                 STRING_ENCODING);
203         ctx.setAttribute("request-id", "1234");
204         String escapedMessage = StringEscapeUtils.escapeSql(message);
205         ctx.setAttribute("log-message", escapedMessage);
206         ctx.setAttribute("log-message-type", "request");
207         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
208         QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test");
209         assertEquals(status, QueryStatus.SUCCESS);
210     }
211
212     @Test
213     public void testGetVnfcReferenceByVnfTypeNActionWithTemplateModelId() throws Exception {
214         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
215         SvcLogicContext ctx = new SvcLogicContext();
216         String prefix="test";
217         String templateModelId = "template001";
218         dbService.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, prefix, templateModelId);
219     }
220
221     @Test
222     public void testGetTemplateWithTemplateModelId() throws Exception {
223         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
224         SvcLogicContext ctx = new SvcLogicContext();
225         String prefix="test";
226         String templateModelId = "template001";
227         String fileCategory="testCategory";
228         dbService.getTemplateWithTemplateModelId(ctx, prefix, fileCategory, templateModelId);
229     }
230
231     @Test
232     public void testgetTemplateByVnfTypeNActionWithTemplateModelId() throws Exception {
233         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
234         SvcLogicContext ctx = new SvcLogicContext();
235         String prefix="test";
236         String templateModelId = "template001";
237         String fileCategory="testCategory";
238         dbService.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, prefix, fileCategory, templateModelId);
239     }
240
241     @Test
242     public void testGetConfigFileReferenceByVnfType() throws Exception {
243         SvcLogicContext ctx = new SvcLogicContext();
244         ctx.setAttribute("vnf-type", "test");
245         ctx.setAttribute("request-action", "Configure");
246         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
247         QueryStatus status = dbService.getConfigFileReferenceByVnfType(ctx, "test");
248         assertEquals(status, QueryStatus.SUCCESS);
249
250     }
251     
252     @Test
253     public void testGetTemplateByArtifactType() throws Exception {
254         SvcLogicContext ctx = new SvcLogicContext();
255         ctx.setAttribute("vnf-type", "test");
256         ctx.setAttribute("request-action", "Configure");
257         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
258         QueryStatus status = dbService.getTemplateByArtifactType(ctx, "test","XML","APPC-CONFIG");
259         assertEquals(QueryStatus.SUCCESS, status);
260
261     }
262     
263     @Test
264     public void testCleanContextPropertyByPrefix()
265     {
266         SvcLogicContext ctx = new SvcLogicContext();
267         ctx.setAttribute("vnf-type", "test");
268         ctx.setAttribute("request-action", "Configure");
269         ctx.setAttribute(".vnfc-type", "Configure");
270         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
271         dbService.cleanContextPropertyByPrefix(ctx, "test");
272         assertEquals(2,ctx.getAttributeKeySet().size());
273     }
274 }