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