d1c7fdb7be40aa80121d52da66ce8713f77f1f16
[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  * Modification 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 testGetDownloadConfigTemplateByVnf() throws SvcLogicException {
176
177         SvcLogicContext ctx = new SvcLogicContext();
178         ctx.setAttribute("vnf-type", "test");
179         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
180         QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test");
181         assertEquals(status, QueryStatus.SUCCESS);
182     }
183
184     @Test
185     public void testSaveConfigTxLog() throws SvcLogicException, IOException {
186
187         SvcLogicContext ctx = new SvcLogicContext();
188         String message = IOUtils.toString(
189                 TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"),
190                 STRING_ENCODING);
191         ctx.setAttribute("request-id", "1234");
192         String escapedMessage = StringEscapeUtils.escapeSql(message);
193         ctx.setAttribute("log-message", escapedMessage);
194         ctx.setAttribute("log-message-type", "request");
195         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
196         QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test");
197         assertEquals(status, QueryStatus.SUCCESS);
198     }
199
200     @Test
201     public void testGetVnfcReferenceByVnfTypeNActionWithTemplateModelId() throws Exception {
202         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
203         SvcLogicContext ctx = new SvcLogicContext();
204         String prefix="test";
205         String templateModelId = "template001";
206         dbService.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, prefix, templateModelId);
207     }
208
209     @Test
210     public void testGetTemplateWithTemplateModelId() throws Exception {
211         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
212         SvcLogicContext ctx = new SvcLogicContext();
213         String prefix="test";
214         String templateModelId = "template001";
215         String fileCategory="testCategory";
216         dbService.getTemplateWithTemplateModelId(ctx, prefix, fileCategory, templateModelId);
217     }
218
219     @Test
220     public void testgetTemplateByVnfTypeNActionWithTemplateModelId() throws Exception {
221         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
222         SvcLogicContext ctx = new SvcLogicContext();
223         String prefix="test";
224         String templateModelId = "template001";
225         String fileCategory="testCategory";
226         dbService.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, prefix, fileCategory, templateModelId);
227     }
228
229     @Test
230     public void testGetConfigFileReferenceByVnfType() throws Exception {
231         SvcLogicContext ctx = new SvcLogicContext();
232         ctx.setAttribute("vnf-type", "test");
233         ctx.setAttribute("request-action", "Configure");
234         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
235         QueryStatus status = dbService.getConfigFileReferenceByVnfType(ctx, "test");
236         assertEquals(status, QueryStatus.SUCCESS);
237
238     }
239     
240     @Test
241     public void testGetTemplateByArtifactType() throws Exception {
242         SvcLogicContext ctx = new SvcLogicContext();
243         ctx.setAttribute("vnf-type", "test");
244         ctx.setAttribute("request-action", "Configure");
245         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
246         QueryStatus status = dbService.getTemplateByArtifactType(ctx, "test","XML","APPC-CONFIG");
247         assertEquals(QueryStatus.SUCCESS, status);
248
249     }
250     
251     @Test
252     public void testCleanContextPropertyByPrefix()
253     {
254         SvcLogicContext ctx = new SvcLogicContext();
255         ctx.setAttribute("vnf-type", "test");
256         ctx.setAttribute("request-action", "Configure");
257         ctx.setAttribute(".vnfc-type", "Configure");
258         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
259         dbService.cleanContextPropertyByPrefix(ctx, "test");
260         assertEquals(2,ctx.getAttributeKeySet().size());
261     }
262 }