2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.artifact.handler.dbservices;
26 import java.nio.charset.Charset;
27 import org.json.JSONObject;
28 import org.junit.Ignore;
29 import org.junit.Test;
30 import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.powermock.reflect.Whitebox;
33 import static org.junit.Assert.assertEquals;
35 public class DBServiceTest {
38 public void testSaveArtifacts() throws Exception {
39 MockDBService dbService = MockDBService.initialise();
40 SvcLogicContext ctx = new SvcLogicContext();
41 ctx.setAttribute("test", "test");
42 int internalVersion = 1;
43 dbService.saveArtifacts(ctx, internalVersion);
47 public void testSaveArtifactsException() throws Exception {
48 MockDBService dbService = MockDBService.initialise();
49 SvcLogicContext ctx = new SvcLogicContext();
50 ctx.setAttribute("test", "test");
51 int internalVersion = 1;
52 dbService.saveArtifacts(ctx, internalVersion);
56 public void testLogData() throws Exception {
57 MockDBService dbService = MockDBService.initialise();
58 SvcLogicContext ctx = new SvcLogicContext();
59 ctx.setAttribute("test", "test");
60 String prefix = "test";
61 dbService.logData(ctx, prefix);
66 public void testLogDataException() throws Exception {
67 MockDBService dbService = MockDBService.initialise();
68 SvcLogicContext ctx = new SvcLogicContext();
69 ctx.setAttribute("test", "test");
70 String prefix = "test";
71 dbService.logData(ctx, prefix);
75 public void testProcessConfigActionDg() throws Exception {
76 MockDBService dbService = MockDBService.initialise();
77 SvcLogicContext ctx = new SvcLogicContext();
78 ctx.setAttribute("test", "test");
79 boolean isUpdate = true;
80 ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference");
81 dbService.processConfigActionDg(ctx, isUpdate);
85 public void testProcessConfigActionDgException() throws Exception {
86 MockDBService dbService = MockDBService.initialise();
87 SvcLogicContext ctx = new SvcLogicContext();
88 ctx.setAttribute("test", "test");
89 boolean isUpdate = true;
90 ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference");
91 dbService.processConfigActionDg(ctx, isUpdate);
95 public void testGetModelDataInformationbyArtifactName() throws Exception {
96 MockDBService dbService = MockDBService.initialise();
97 SvcLogicContext ctx = new SvcLogicContext();
98 ctx.setAttribute("test", "test");
99 String artifactName = "test";
100 dbService.getModelDataInformationbyArtifactName(artifactName);
104 public void testGetModelDataInformationbyArtifactNameException() throws Exception {
105 MockDBService dbService = MockDBService.initialise();
106 SvcLogicContext ctx = new SvcLogicContext();
107 ctx.setAttribute("test", "test");
108 String artifactName = "test";
109 dbService.getModelDataInformationbyArtifactName(artifactName);
113 public void testUpdateYangContents() throws Exception {
114 MockDBService dbService = MockDBService.initialise();
115 SvcLogicContext ctx = new SvcLogicContext();
116 ctx.setAttribute("test", "test");
117 String artifactName = "test";
118 String artifactId = "TestArtifact";
119 String yangContents = "TestYangContents";
120 dbService.updateYangContents(ctx, artifactId, yangContents);
124 public void testUpdateYangContentsException() throws Exception {
125 MockDBService dbService = MockDBService.initialise();
126 SvcLogicContext ctx = new SvcLogicContext();
127 ctx.setAttribute("test", "test");
128 String artifactName = "test";
129 String artifactId = "TestArtifact";
130 String yangContents = "TestYangContents";
131 dbService.updateYangContents(ctx, artifactId, yangContents);
135 public void testInsertProtocolReference() throws Exception {
136 MockDBService dbService = MockDBService.initialise();
137 SvcLogicContext ctx = new SvcLogicContext();
138 ctx.setAttribute("test", "test");
139 String vnfType = "testVnf";
140 String protocol = "testProtocol";
141 String action = "testAction";
142 String actionLevel = "testActionLevel";
143 String template = "testTemplateData";
144 dbService.insertProtocolReference(ctx, vnfType, protocol, action, actionLevel, template);
149 public void testInsertProtocolReferenceException() throws Exception {
150 MockDBService dbService = MockDBService.initialise();
151 SvcLogicContext ctx = new SvcLogicContext();
152 ctx.setAttribute("test", "test");
153 String vnfType = "testVnf";
154 String protocol = "testProtocol";
155 String action = "testAction";
156 String actionLevel = "testActionLevel";
157 String template = "testTemplateData";
158 dbService.insertProtocolReference(ctx, vnfType, protocol, action, actionLevel, template);
162 public void testprocessDpwnloadDGReference() throws Exception {
163 MockDBService dbService = MockDBService.initialise();
164 SvcLogicContext ctx = new SvcLogicContext();
165 ctx.setAttribute("test", "test");
166 boolean isUpdate = true;
167 dbService.processDownloadDgReference(ctx, isUpdate);
171 public void testprocessDpwnloadDGReferenceException() throws Exception {
172 MockDBService dbService = MockDBService.initialise();
173 SvcLogicContext ctx = new SvcLogicContext();
174 ctx.setAttribute("test", "test");
175 boolean isUpdate = true;
176 dbService.processDownloadDgReference(ctx, isUpdate);
180 public void testProcessVnfcReference() throws Exception {
181 MockDBService dbService = MockDBService.initialise();
182 SvcLogicContext ctx = new SvcLogicContext();
183 ctx.setAttribute("test", "test");
184 boolean isUpdate = false;
185 dbService.processVnfcReference(ctx, isUpdate);
189 public void testProcessVnfcReferenceException() throws Exception {
190 MockDBService dbService = MockDBService.initialise();
191 SvcLogicContext ctx = new SvcLogicContext();
192 ctx.setAttribute("test", "test");
193 boolean isUpdate = true;
194 dbService.processVnfcReference(ctx, isUpdate);
198 public void testProcessDeviceAuthentication() throws Exception {
199 MockDBService dbService = MockDBService.initialise();
200 SvcLogicContext ctx = new SvcLogicContext();
201 ctx.setAttribute("test", "test");
202 boolean isUpdate = true;
203 dbService.processDeviceAuthentication(ctx, isUpdate);
207 public void testProcessDeviceAuthenticationException() throws Exception {
208 MockDBService dbService = MockDBService.initialise();
209 SvcLogicContext ctx = new SvcLogicContext();
210 ctx.setAttribute("test", "test");
211 boolean isUpdate = true;
212 dbService.processDeviceAuthentication(ctx, isUpdate);
216 public void testProcessDeviceInterfaceProtocol() throws Exception {
217 MockDBService dbService = MockDBService.initialise();
218 SvcLogicContext ctx = new SvcLogicContext();
219 ctx.setAttribute("test", "test");
220 boolean isUpdate = true;
221 dbService.processDeviceInterfaceProtocol(ctx, isUpdate);
225 public void testProcessDeviceInterfaceProtocolException() throws Exception {
226 MockDBService dbService = MockDBService.initialise();
227 SvcLogicContext ctx = new SvcLogicContext();
228 ctx.setAttribute("test", "test");
229 boolean isUpdate = true;
230 dbService.processDeviceInterfaceProtocol(ctx, isUpdate);
234 public void testProcessSdcReferences() throws Exception {
235 MockDBService dbService = MockDBService.initialise();
236 SvcLogicContext ctx = new SvcLogicContext();
237 ctx.setAttribute("test", "test");
238 ctx.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, "testCategory");
239 boolean isUpdate = true;
240 dbService.processSdcReferences(ctx, isUpdate);
244 public void testProcessSdcReferencesException() throws Exception {
245 MockDBService dbService = MockDBService.initialise();
246 SvcLogicContext ctx = new SvcLogicContext();
247 ctx.setAttribute("test", "test");
248 boolean isUpdate = true;
249 dbService.processSdcReferences(ctx, isUpdate);
253 public void testIsArtifactUpdateRequired() throws Exception {
254 MockDBService dbService = MockDBService.initialise();
255 SvcLogicContext ctx = new SvcLogicContext();
256 ctx.setAttribute("test", "test");
258 dbService.isArtifactUpdateRequired(ctx, db);
262 public void testIsArtifactUpdateRequiredExcetion() throws Exception {
263 MockDBService dbService = MockDBService.initialise();
264 SvcLogicContext ctx = new SvcLogicContext();
265 ctx.setAttribute("test", "test");
267 dbService.isArtifactUpdateRequired(ctx, db);
272 public void testgetArtifactID() throws Exception {
273 MockDBService dbService = MockDBService.initialise();
274 SvcLogicContext ctx = new SvcLogicContext();
275 ctx.setAttribute("test", "test");
277 dbService.getArtifactID(ctx, db);
281 public void testgetArtifactIDException() throws Exception {
282 MockDBService dbService = MockDBService.initialise();
283 SvcLogicContext ctx = new SvcLogicContext();
284 ctx.setAttribute("test", "test");
286 dbService.getArtifactID(ctx, db);
289 public void testGetDownLoadDGReference() throws Exception {
290 MockDBService dbService = MockDBService.initialise();
291 SvcLogicContext ctx = new SvcLogicContext();
292 ctx.setAttribute("test", "test");
293 ctx.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL, "CLI");
294 assertEquals("TestDG", dbService.getDownLoadDGReference(ctx));