2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2018-2019 IBM.
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.data.services.node;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertNotNull;
29 import static org.mockito.Matchers.anyString;
30 import static org.mockito.Matchers.eq;
31 import static org.mockito.Mockito.atLeastOnce;
32 import static org.mockito.Mockito.mock;
33 import static org.mockito.Mockito.spy;
34 import static org.mockito.Mockito.verify;
35 import static org.mockito.Mockito.when;
36 import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_FILES_PREFIX;
37 import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_FILE_ID_PARAM;
38 import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_PARAMS;
39 import static org.onap.appc.data.services.node.ConfigResourceNode.CONF_ACTION_PREFIX;
40 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_FILE_TYPE;
41 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_PREFIX;
42 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_PROTOCOL_PREFIX;
43 import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_FILE_TYPE;
44 import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_PREFIX;
45 import static org.onap.appc.data.services.node.ConfigResourceNode.FILE_CATEGORY_PARAM;
46 import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_FILE_TYPE;
47 import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_PREFIX;
48 import static org.onap.appc.data.services.node.ConfigResourceNode.MAX_CONF_FILE_PREFIX;
49 import static org.onap.appc.data.services.node.ConfigResourceNode.PREPARE_RELATIONSHIP_PARAM;
50 import static org.onap.appc.data.services.node.ConfigResourceNode.SDC_IND;
51 import static org.onap.appc.data.services.node.ConfigResourceNode.SITE_LOCATION_PARAM;
52 import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_FILE_TYPE;
53 import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_PREFIX;
54 import static org.onap.appc.data.services.node.ConfigResourceNode.TMP_CONVERTCONFIG_ESC_DATA;
55 import static org.onap.appc.data.services.node.ConfigResourceNode.TMP_MERGE_MERGED_DATA;
56 import static org.onap.appc.data.services.node.ConfigResourceNode.UNABLE_TO_SAVE_RELATIONSHIP_STR;
57 import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_ID_PARAM;
58 import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_INFO_PREFIX;
59 import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_PREFIX;
60 import com.fasterxml.jackson.databind.JsonNode;
61 import com.fasterxml.jackson.databind.ObjectMapper;
62 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
63 import java.util.HashMap;
64 import org.junit.Before;
65 import org.junit.Rule;
66 import org.junit.Test;
67 import org.junit.rules.ExpectedException;
68 import org.onap.appc.data.services.AppcDataServiceConstant;
69 import org.onap.appc.data.services.db.DGGeneralDBService;
70 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
71 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
72 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
73 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
75 public class ConfigResourceNodeTest {
77 private HashMap<String, String> inParams;
78 private SvcLogicContext contextMock;
81 public ExpectedException expectedException = ExpectedException.none();
85 contextMock = mock(SvcLogicContext.class);
86 inParams = new HashMap<>();
92 * {"capabilities":{"vnfc":[],"vm":[{"ConfigureTest":["SSC","MMSC"]}],"vf-module":[],"vnf":["ConfigModify","HealthCheck"]}}
95 public void shouldProcessCapabilitiesForVMLevel() throws Exception {
96 SvcLogicContext ctx = new SvcLogicContext();
97 ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
98 String findCapability = "Restart";
99 JsonNodeFactory.instance.objectNode();
101 "[{\"Restart\":[\"SSC\",\"MMC\"]},{\"Rebuild\":[\"SSC\"]},{\"Migrate\":[\"SSC\"]},{\"Snapshot\":[\"SSC\"]},{\"Start\":[\"SSC\"]},{\"Stop\":[\"SSC\"]}]";
102 ObjectMapper m = new ObjectMapper();
103 JsonNode subCapabilities = m.readTree(subCaps);
104 String vServerId = "testServer";
105 ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code", "MMC");
106 ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-name", "testVnfc");
107 node.processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
108 String result = ctx.getAttribute("capabilities");
109 assertEquals(result, "Supported");
113 public void shouldCheckIfCapabilityCheckNeeded() {
114 ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
115 String findCapability = "Start";
116 String capLevel = "vnf";
117 boolean result = node.checkIfCapabilityCheckNeeded(capLevel, findCapability);
122 public void should_add_attribute_with_success_if_get_config_file_succeed() throws SvcLogicException {
123 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
125 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
126 configResourceNode.getConfigFileReference(inParams, contextMock);
128 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
132 public void should_add_attribute_with_success_if_get_config_info_succeed() throws SvcLogicException {
133 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
135 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
136 configResourceNode.getCommonConfigInfo(inParams, contextMock);
138 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
142 public void should_add_attribute_with_success_if_get_template_succeed() throws SvcLogicException {
143 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
145 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
146 configResourceNode.getTemplate(inParams, contextMock);
147 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
151 public void testGetVnfcReference() throws Exception {
152 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
153 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
154 contextMock.setAttribute("template-model-id", "testModelId");
155 contextMock.setAttribute("vnfc-type", "testVnfcType");
156 configResourceNode.getVnfcReference(inParams, contextMock);
157 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
161 public void testGetCapability() throws Exception {
162 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
163 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
164 contextMock.setAttribute("responsePrefix", "testResponsePrefix");
165 contextMock.setAttribute("caplevel", "testCapLevel");
166 contextMock.setAttribute("checkCapability", "testCheckCapability");
167 contextMock.setAttribute("vServerId", "testVServerId");
168 contextMock.setAttribute("vnf-type", "testVnfType");
169 configResourceNode.getCapability(inParams, contextMock);
170 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
174 public void testGetConfigFilesByVnfVmNCategory() throws Exception {
175 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
176 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
177 contextMock.setAttribute("responsePrefix", "testResponsePrefix");
178 contextMock.setAttribute("fileCategory", "testFileCategory");
179 contextMock.setAttribute("vnfId", "testVnfId");
180 contextMock.setAttribute("vmName", "testVmName");
181 configResourceNode.getConfigFilesByVnfVmNCategory(inParams, contextMock);
182 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
186 public void should_add_attribute_with_success_if_save_config_files_succeed() throws SvcLogicException {
187 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
189 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
190 configResourceNode.saveConfigFiles(inParams, contextMock);
192 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
196 public void should_add_attribute_with_success_if_update_upload_config_succeed() throws SvcLogicException {
197 when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234");
199 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
201 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
202 configResourceNode.updateUploadConfig(inParams, contextMock);
204 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
208 public void should_add_attribute_with_success_if_get_download_config_template_by_vnf_type_succeed()
209 throws SvcLogicException {
210 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
212 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
213 configResourceNode.getDownloadConfigTemplateByVnf(inParams, contextMock);
215 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
219 public void should_add_attribute_with_success_if_get_ssm_chain_succeed() throws SvcLogicException {
220 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
222 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
223 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
225 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
229 public void should_add_attribute_with_success_if_save_prepare_relationship_succeed() throws SvcLogicException {
230 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
232 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
233 configResourceNode.savePrepareRelationship(inParams, contextMock);
235 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
239 public void should_throw_exception_on_device_config_missing() throws Exception {
240 DGGeneralDBService dbServiceMock =
241 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX,
242 DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND).build();
244 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
246 expectedException.expect(SvcLogicException.class);
247 expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
248 configResourceNode.getConfigFileReference(inParams, contextMock);
252 public void should_throw_exception_on_device_config_failure() throws Exception {
253 DGGeneralDBService dbServiceMock =
254 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX,
255 DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE).build();
257 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
259 expectedException.expect(SvcLogicException.class);
260 expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
261 configResourceNode.getConfigFileReference(inParams, contextMock);
265 public void should_throw_exception_on_success_param_missing() throws Exception {
267 DGGeneralDBService dbServiceMock =
268 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE,
269 SvcLogicResource.QueryStatus.NOT_FOUND).build();
271 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
273 expectedException.expect(SvcLogicException.class);
274 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
275 configResourceNode.getConfigFileReference(inParams, contextMock);
279 public void should_throw_exception_on_success_param_failure() throws Exception {
280 DGGeneralDBService dbServiceMock =
281 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE,
282 SvcLogicResource.QueryStatus.FAILURE).build();
284 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
286 expectedException.expect(SvcLogicException.class);
287 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
288 configResourceNode.getConfigFileReference(inParams, contextMock);
292 public void should_throw_exception_on_failure_param_missing() throws Exception {
294 DGGeneralDBService dbServiceMock =
295 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE,
296 SvcLogicResource.QueryStatus.NOT_FOUND).build();
298 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
300 expectedException.expect(SvcLogicException.class);
301 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
302 configResourceNode.getConfigFileReference(inParams, contextMock);
306 public void should_throw_exception_on_failure_param_failure() throws Exception {
307 DGGeneralDBService dbServiceMock =
308 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE,
309 SvcLogicResource.QueryStatus.FAILURE).build();
311 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
313 expectedException.expect(SvcLogicException.class);
314 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
315 configResourceNode.getConfigFileReference(inParams, contextMock);
319 public void should_throw_exception_on_log_param_missing() throws Exception {
321 DGGeneralDBService dbServiceMock =
322 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE,
323 SvcLogicResource.QueryStatus.NOT_FOUND).build();
325 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
327 expectedException.expect(SvcLogicException.class);
328 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
329 configResourceNode.getConfigFileReference(inParams, contextMock);
333 public void should_throw_exception_on_log_param_failure() throws Exception {
334 DGGeneralDBService dbServiceMock =
335 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE,
336 SvcLogicResource.QueryStatus.FAILURE).build();
338 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
340 expectedException.expect(SvcLogicException.class);
341 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
342 configResourceNode.getConfigFileReference(inParams, contextMock);
346 public void should_throw_exception_on_device_protocol_missing() throws SvcLogicException {
347 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
348 .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build();
350 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
352 expectedException.expect(SvcLogicException.class);
353 expectedException.expectMessage("Unable to Read device_interface_protocol");
354 configResourceNode.getCommonConfigInfo(inParams, contextMock);
358 public void should_throw_exception_on_device_protocol_failure() throws SvcLogicException {
359 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
360 .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
362 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
364 expectedException.expect(SvcLogicException.class);
365 expectedException.expectMessage("Unable to Read device_interface_protocol");
366 configResourceNode.getCommonConfigInfo(inParams, contextMock);
370 public void should_throw_exception_on_conf_action_by_vnf_action_failure() throws SvcLogicException {
371 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
372 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
374 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
376 expectedException.expect(SvcLogicException.class);
377 expectedException.expectMessage("Unable to Read configure_action_dg");
378 configResourceNode.getCommonConfigInfo(inParams, contextMock);
382 public void should_throw_exception_on_conf_action_missing() throws SvcLogicException {
383 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
384 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
385 .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build();
387 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
389 expectedException.expect(SvcLogicException.class);
390 expectedException.expectMessage("Unable to Read configure_action_dg");
391 configResourceNode.getCommonConfigInfo(inParams, contextMock);
395 public void should_throw_exception_on_conf_action_failure() throws SvcLogicException {
396 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
397 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
398 .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
400 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
402 expectedException.expect(SvcLogicException.class);
403 expectedException.expectMessage("Unable to Read configure_action_dg");
404 configResourceNode.getCommonConfigInfo(inParams, contextMock);
408 public void should_throw_exception_on_db_template_failure() throws SvcLogicException {
409 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
410 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
412 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
413 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE).build();
415 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
417 expectedException.expect(SvcLogicException.class);
418 expectedException.expectMessage("Unable to Read some file category");
419 configResourceNode.getTemplate(inParams, contextMock);
423 public void should_throw_exception_on_db_template_by_action_failure() throws SvcLogicException {
424 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
425 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
427 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
428 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
429 .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE)
432 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
434 expectedException.expect(SvcLogicException.class);
435 expectedException.expectMessage("Unable to Read some file category");
436 configResourceNode.getTemplate(inParams, contextMock);
440 public void should_throw_exception_on_db_template_by_action_missing() throws SvcLogicException {
441 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
442 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
444 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
445 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
446 .getTemplateByVnfTypeNAction("some prefix", "some file category",
447 SvcLogicResource.QueryStatus.NOT_FOUND)
450 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
452 expectedException.expect(SvcLogicException.class);
453 expectedException.expectMessage("Unable to Read some file category");
454 configResourceNode.getTemplate(inParams, contextMock);
458 public void should_throw_exception_on_db_template_by_name_missing() throws SvcLogicException {
459 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
460 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
462 SvcLogicContext context = new SvcLogicContext();
463 context.setAttribute("template-name", "test template");
465 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
466 .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.NOT_FOUND)
469 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
471 expectedException.expect(SvcLogicException.class);
472 expectedException.expectMessage("Unable to Read some file category template");
473 configResourceNode.getTemplate(inParams, context);
477 public void should_throw_exception_on_db_template_by_name_failure() throws SvcLogicException {
478 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
479 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
481 SvcLogicContext context = new SvcLogicContext();
482 context.setAttribute("template-name", "test template");
484 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
485 .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.FAILURE)
488 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
490 expectedException.expect(SvcLogicException.class);
491 expectedException.expectMessage("Unable to Read some file category template");
492 configResourceNode.getTemplate(inParams, context);
496 public void should_throw_exception_on_save_config_failure() throws SvcLogicException {
497 SvcLogicContext context = new SvcLogicContext();
498 context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
500 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
501 .saveConfigFiles(CONFIG_FILES_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
503 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
505 expectedException.expect(SvcLogicException.class);
506 expectedException.expectMessage("Unable to Save some file category in configfiles");
507 configResourceNode.saveConfigFiles(inParams, context);
511 public void should_throw_exception_on_get_max_config_id_missing() throws SvcLogicException {
512 SvcLogicContext context = new SvcLogicContext();
513 context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
515 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
516 .getMaxConfigFileId(MAX_CONF_FILE_PREFIX, "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
519 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
521 expectedException.expect(SvcLogicException.class);
522 expectedException.expectMessage("Unable to get some file category from configfiles");
524 configResourceNode.saveConfigFiles(inParams, context);
528 public void should_throw_exception_on_save_config_files_failure() throws SvcLogicException {
529 SvcLogicContext context = new SvcLogicContext();
530 context.setAttribute(CONFIG_FILE_ID_PARAM, "some file id");
532 DGGeneralDBService dbServiceMock =
533 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
534 SvcLogicResource.QueryStatus.FAILURE).build();
536 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
538 expectedException.expect(SvcLogicException.class);
539 expectedException.expectMessage("Unable to save prepare_relationship");
540 configResourceNode.saveConfigFiles(inParams, context);
544 public void should_throw_exception_on_save_upload_config_failure() throws SvcLogicException {
545 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
546 .saveUploadConfig(UPLOAD_CONFIG_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
548 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
550 expectedException.expect(SvcLogicException.class);
551 expectedException.expectMessage("Unable to Save configuration in upload_config");
552 configResourceNode.updateUploadConfig(inParams, contextMock);
556 public void should_throw_exception_on_get_upload_config_failure() throws SvcLogicException {
557 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
558 .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
560 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
562 expectedException.expect(SvcLogicException.class);
563 expectedException.expectMessage("Unable to get record from upload_config");
564 configResourceNode.updateUploadConfig(inParams, contextMock);
568 public void should_throw_exception_on_get_upload_config_missing() throws SvcLogicException {
569 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
570 .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build();
572 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
574 expectedException.expect(SvcLogicException.class);
575 expectedException.expectMessage("Unable to get record from upload_config");
576 configResourceNode.updateUploadConfig(inParams, contextMock);
580 public void should_throw_exception_on_update_upload_config_failure() throws SvcLogicException {
581 when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234");
583 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
584 .updateUploadConfig(UPLOAD_CONFIG_PREFIX, 1234, SvcLogicResource.QueryStatus.FAILURE).build();
586 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
588 expectedException.expect(SvcLogicException.class);
589 expectedException.expectMessage("Unable to upload upload_config");
590 configResourceNode.updateUploadConfig(inParams, contextMock);
594 public void should_throw_exception_on_get_download_config_failure() throws SvcLogicException {
595 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
597 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
598 .getDownloadConfigTemplateByVnf("some prefix", SvcLogicResource.QueryStatus.FAILURE).build();
600 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
602 expectedException.expect(SvcLogicException.class);
603 expectedException.expectMessage("Unable to get download config template.");
604 configResourceNode.getDownloadConfigTemplateByVnf(inParams, contextMock);
608 public void should_throw_exception_on_get_ssm_chain_failure() throws SvcLogicException {
609 when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
611 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
612 .getTemplateByArtifactType("smm", "smm", "some location", SvcLogicResource.QueryStatus.FAILURE).build();
614 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
616 expectedException.expect(SvcLogicException.class);
617 expectedException.expectMessage("Unable to Read smm file");
618 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
622 public void should_throw_exception_on_get_ca_chain_failure() throws SvcLogicException {
623 when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
625 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().getTemplateByArtifactType("intermediate-ca-chain",
626 "intermediate_ca_chain", "some location", SvcLogicResource.QueryStatus.FAILURE).build();
628 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
630 expectedException.expect(SvcLogicException.class);
631 expectedException.expectMessage("Unable to Read intermediate_ca_chain file");
632 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
636 public void should_throw_exception_on_get_server_certificate_and_key_failure() throws SvcLogicException {
637 when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
639 DGGeneralDBService dbServiceMock =
640 new MockDbServiceBuilder().getTemplateByArtifactType("server-certificate-and-key",
641 "server_certificate_and_key", "some location", SvcLogicResource.QueryStatus.FAILURE).build();
643 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
645 expectedException.expect(SvcLogicException.class);
646 expectedException.expectMessage("Unable to Read server_certificate_and_key file");
647 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
651 public void should_throw_exception_on_save_prepare_relationship_failure() throws SvcLogicException {
652 inParams.put(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND, "some sdnc index");
653 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_ID, "some file id");
655 DGGeneralDBService dbServiceMock =
656 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
657 "some sdnc index", QueryStatus.FAILURE).build();
659 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
661 expectedException.expect(SvcLogicException.class);
662 expectedException.expectMessage(UNABLE_TO_SAVE_RELATIONSHIP_STR);
663 configResourceNode.savePrepareRelationship(inParams, contextMock);
667 public void should_save_save_config_files_for_empty_config_params() throws SvcLogicException {
669 when(contextMock.getAttribute(TMP_CONVERTCONFIG_ESC_DATA)).thenReturn("some esc data");
670 when(contextMock.getAttribute("configuration")).thenReturn("some configuration");
671 when(contextMock.getAttribute(CONFIG_PARAMS)).thenReturn("");
673 DGGeneralDBService dbServiceMock =
674 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
675 "some sdnc index", QueryStatus.FAILURE).build();
677 ConfigResourceNode configResourceNode = spy(new ConfigResourceNode(dbServiceMock));
678 configResourceNode.saveConfigBlock(inParams, contextMock);
680 verify(configResourceNode).saveDeviceConfiguration(inParams, contextMock, "Request", "some esc data",
681 "some configuration");
682 verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
686 public void should_save_save_config_files_for_non_empty_config_params() throws SvcLogicException {
688 when(contextMock.getAttribute(TMP_CONVERTCONFIG_ESC_DATA)).thenReturn("some esc data");
689 when(contextMock.getAttribute(TMP_MERGE_MERGED_DATA)).thenReturn("merged data");
690 when(contextMock.getAttribute(CONFIG_PARAMS)).thenReturn("non empty");
692 DGGeneralDBService dbServiceMock =
693 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
694 "some sdnc index", QueryStatus.FAILURE).build();
696 ConfigResourceNode configResourceNode = spy(new ConfigResourceNode(dbServiceMock));
697 configResourceNode.saveConfigBlock(inParams, contextMock);
699 verify(configResourceNode).saveDeviceConfiguration(inParams, contextMock, "Configurator", "some esc data",
701 verify(configResourceNode).saveConfigBlock(inParams, contextMock);
702 verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
706 public void testSaveTemplateConfig() throws SvcLogicException
708 SvcLogicContext context = new SvcLogicContext();
709 context.setAttribute(CONFIG_FILE_ID_PARAM, "some file id");
711 DGGeneralDBService dbServiceMock =
712 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
713 SvcLogicResource.QueryStatus.FAILURE).build();
715 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
716 configResourceNode.saveTemplateConfig(inParams, contextMock);
718 verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
722 public void testSaveStyleSheetConfig() throws SvcLogicException
724 SvcLogicContext context = new SvcLogicContext();
725 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "test");
726 context.setAttribute("tmp.merge.mergedData", "test");
727 context.setAttribute("tmp.convertconfig.escapeData", "test");
728 context.setAttribute("tmp.merge.mergedData", "test");
729 DGGeneralDBService dbServiceMock =
730 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
731 SvcLogicResource.QueryStatus.FAILURE).build();
733 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
734 configResourceNode.saveStyleSheetConfig(inParams, contextMock);
736 verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
740 public void testSaveConfigTransactionLog() throws SvcLogicException
742 SvcLogicContext context = new SvcLogicContext();
743 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "test");
744 inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE, "test");
745 inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE, "test");
747 context.setAttribute("request-id", "test");
748 DGGeneralDBService dbServiceMock =
749 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
750 SvcLogicResource.QueryStatus.FAILURE).build();
752 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
753 configResourceNode.saveConfigTransactionLog(inParams, contextMock);
754 assertEquals(null,contextMock.getAttribute("log-message"));