23f0bcb1dcc7548f9a7d173d2f4782c86be55f7f
[appc.git] / appc-config / appc-data-services / provider / src / test / java / org / onap / appc / data / services / db / TestDGGeneralDBService.java
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  * 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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24 package org.onap.appc.data.services.db;
25
26 import static org.junit.Assert.assertEquals;
27 import java.io.IOException;
28 import org.apache.commons.io.IOUtils;
29 import org.apache.commons.lang.StringEscapeUtils;
30 import org.junit.Test;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
34 import org.onap.appc.data.services.db.DGGeneralDBService;
35
36 public class TestDGGeneralDBService {
37     DGGeneralDBService dbService;
38     private static String STRING_ENCODING = "utf-8";
39
40     @Test
41     public void testGetUploadConfig() throws SvcLogicException {
42
43         SvcLogicContext ctx = new SvcLogicContext();
44         ctx.setAttribute("vnf-name", "test");
45         ctx.setAttribute("vnf-id", "test");
46         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
47         QueryStatus status = dbService.getUploadConfigInfo(ctx, "test");
48         assertEquals(status, QueryStatus.SUCCESS);
49
50     }
51
52     @Test
53     public void testGetDeviceProtocolByVnfType() throws SvcLogicException {
54         SvcLogicContext ctx = new SvcLogicContext();
55         ctx.setAttribute("vnf-type", "test");
56         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
57         QueryStatus status = dbService.getDeviceProtocolByVnfType(ctx, "test");
58         assertEquals(status, QueryStatus.SUCCESS);
59     }
60
61     @Test
62     public void testGettConfigFileReferenceByFileTypeNVnfType() throws SvcLogicException {
63         SvcLogicContext ctx = new SvcLogicContext();
64         ctx.setAttribute("vnf-type", "test");
65         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
66         QueryStatus status = dbService.getConfigFileReferenceByFileTypeNVnfType(ctx, "test", "device_configuration");
67         assertEquals(status, QueryStatus.SUCCESS);
68
69     }
70
71     @Test
72     public void testGetDeviceAuthenticationByVnfType() throws Exception {
73         SvcLogicContext ctx = new SvcLogicContext();
74         ctx.setAttribute("vnf-type", "test");
75         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
76         QueryStatus status = dbService.getDeviceAuthenticationByVnfType(ctx, "test");
77         assertEquals(status, QueryStatus.SUCCESS);
78
79     }
80
81     @Test
82     public void testGetTemplate() throws Exception {
83         SvcLogicContext ctx = new SvcLogicContext();
84         ctx.setAttribute("vnfc-type", "test");
85         ctx.setAttribute("request-action", "Configure");
86         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
87         QueryStatus status = dbService.getTemplate(ctx, "test", "config_template");
88         assertEquals(status, QueryStatus.SUCCESS);
89
90     }
91
92     @Test
93     public void testGetTemplateByVnfTypeNAction() throws Exception {
94         SvcLogicContext ctx = new SvcLogicContext();
95         ctx.setAttribute("vnf-type", "test");
96         ctx.setAttribute("request-action", "ConfigScaleOut");
97         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
98         QueryStatus status = dbService.getTemplateByVnfTypeNAction(ctx, "test", "config_template");
99         assertEquals(status, QueryStatus.SUCCESS);
100
101     }
102
103     @Test
104     public void testGetTemplateByTemplateName() throws Exception {
105         SvcLogicContext ctx = new SvcLogicContext();
106         ctx.setAttribute("request-action", "Configure");
107         ctx.setAttribute("vnf-type", "test");
108         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
109         QueryStatus status = dbService.getTemplateByTemplateName(ctx, "test", "template.json");
110         assertEquals(status, QueryStatus.SUCCESS);
111
112     }
113
114     @Test
115     public void testGetTemplateByVnfType() throws SvcLogicException {
116
117         SvcLogicContext ctx = new SvcLogicContext();
118         ctx.setAttribute("vnf-type", "test");
119         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
120         QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template");
121         assertEquals(status, QueryStatus.SUCCESS);
122
123     }
124
125     @Test
126     public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException {
127
128         SvcLogicContext ctx = new SvcLogicContext();
129         ctx.setAttribute("vnf-type", "test");
130         ctx.setAttribute("request-action", "ConfigModify");
131         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
132         QueryStatus status = dbService.getConfigureActionDGByVnfTypeNAction(ctx, "test");
133         assertEquals(status, QueryStatus.SUCCESS);
134
135     }
136
137     @Test
138     public void testGetConfigureActionDGByVnfType() throws SvcLogicException {
139         SvcLogicContext ctx = new SvcLogicContext();
140         ctx.setAttribute("vnf-type", "test");
141         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
142         QueryStatus status = dbService.getConfigureActionDGByVnfType(ctx, "test");
143         assertEquals(status, QueryStatus.SUCCESS);
144
145     }
146
147     @Test
148     public void testGetMaxConfigFileId() throws SvcLogicException {
149
150         SvcLogicContext ctx = new SvcLogicContext();
151         ctx.setAttribute("vnf-id", "test");
152         ctx.setAttribute("vm-name", "test");
153         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
154         QueryStatus status = dbService.getMaxConfigFileId(ctx, "test", "device_configuration");
155         assertEquals(status, QueryStatus.SUCCESS);
156
157     }
158
159     @Test
160     public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException {
161
162         SvcLogicContext ctx = new SvcLogicContext();
163         ctx.setAttribute("vnf-id", "test");
164         ctx.setAttribute("vm-name", "test");
165         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
166         QueryStatus status = dbService.getConfigFilesByVnfVmNCategory(ctx, "test", "device_configuration", "test",
167                 "ibcx0001vm001");
168         assertEquals(status, QueryStatus.SUCCESS);
169
170     }
171
172     @Test
173     public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException {
174
175         SvcLogicContext ctx = new SvcLogicContext();
176         ctx.setAttribute("vnf-type", "test");
177         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
178         QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test");
179         assertEquals(status, QueryStatus.SUCCESS);
180     }
181
182     @Test
183     public void testSaveConfigTxLog() throws SvcLogicException, IOException {
184
185         SvcLogicContext ctx = new SvcLogicContext();
186         String message = IOUtils.toString(
187                 TestDGGeneralDBService.class.getClassLoader().getResourceAsStream("query/message3.txt"),
188                 STRING_ENCODING);
189         ctx.setAttribute("request-id", "1234");
190         String escapedMessage = StringEscapeUtils.escapeSql(message);
191         ctx.setAttribute("log-message", escapedMessage);
192         ctx.setAttribute("log-message-type", "request");
193         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
194         QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test");
195         assertEquals(status, QueryStatus.SUCCESS);
196     }
197
198     @Test
199     public void testGetVnfcReferenceByVnfTypeNActionWithTemplateModelId() throws Exception {
200         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
201         SvcLogicContext ctx = new SvcLogicContext();
202         String prefix="test";
203         String templateModelId = "template001";
204         dbService.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, prefix, templateModelId);
205     }
206
207     @Test
208     public void testGetTemplateWithTemplateModelId() throws Exception {
209         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
210         SvcLogicContext ctx = new SvcLogicContext();
211         String prefix="test";
212         String templateModelId = "template001";
213         String fileCategory="testCategory";
214         dbService.getTemplateWithTemplateModelId(ctx, prefix, fileCategory, templateModelId);
215     }
216
217     @Test
218     public void testgetTemplateByVnfTypeNActionWithTemplateModelId() throws Exception {
219         MockDGGeneralDBService dbService =     MockDGGeneralDBService.initialise();
220         SvcLogicContext ctx = new SvcLogicContext();
221         String prefix="test";
222         String templateModelId = "template001";
223         String fileCategory="testCategory";
224         dbService.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, prefix, fileCategory, templateModelId);
225     }
226 }