2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modification Copyright (C) 2018 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.mockito.Matchers.anyString;
29 import static org.mockito.Matchers.eq;
30 import static org.mockito.Mockito.atLeastOnce;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.spy;
33 import static org.mockito.Mockito.verify;
34 import static org.mockito.Mockito.when;
35 import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_FILES_PREFIX;
36 import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_FILE_ID_PARAM;
37 import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_PARAMS;
38 import static org.onap.appc.data.services.node.ConfigResourceNode.CONF_ACTION_PREFIX;
39 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_FILE_TYPE;
40 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_PREFIX;
41 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_PROTOCOL_PREFIX;
42 import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_FILE_TYPE;
43 import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_PREFIX;
44 import static org.onap.appc.data.services.node.ConfigResourceNode.FILE_CATEGORY_PARAM;
45 import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_FILE_TYPE;
46 import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_PREFIX;
47 import static org.onap.appc.data.services.node.ConfigResourceNode.MAX_CONF_FILE_PREFIX;
48 import static org.onap.appc.data.services.node.ConfigResourceNode.PREPARE_RELATIONSHIP_PARAM;
49 import static org.onap.appc.data.services.node.ConfigResourceNode.SDC_IND;
50 import static org.onap.appc.data.services.node.ConfigResourceNode.SITE_LOCATION_PARAM;
51 import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_FILE_TYPE;
52 import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_PREFIX;
53 import static org.onap.appc.data.services.node.ConfigResourceNode.TMP_CONVERTCONFIG_ESC_DATA;
54 import static org.onap.appc.data.services.node.ConfigResourceNode.TMP_MERGE_MERGED_DATA;
55 import static org.onap.appc.data.services.node.ConfigResourceNode.UNABLE_TO_SAVE_RELATIONSHIP_STR;
56 import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_ID_PARAM;
57 import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_INFO_PREFIX;
58 import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_PREFIX;
59 import com.fasterxml.jackson.databind.JsonNode;
60 import com.fasterxml.jackson.databind.ObjectMapper;
61 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
62 import java.util.HashMap;
63 import org.junit.Before;
64 import org.junit.Rule;
65 import org.junit.Test;
66 import org.junit.rules.ExpectedException;
67 import org.onap.appc.data.services.AppcDataServiceConstant;
68 import org.onap.appc.data.services.db.DGGeneralDBService;
69 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
70 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
71 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
72 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
74 public class ConfigResourceNodeTest {
76 private HashMap<String, String> inParams;
77 private SvcLogicContext contextMock;
80 public ExpectedException expectedException = ExpectedException.none();
84 contextMock = mock(SvcLogicContext.class);
85 inParams = new HashMap<>();
91 * {"capabilities":{"vnfc":[],"vm":[{"ConfigureTest":["SSC","MMSC"]}],"vf-module":[],"vnf":["ConfigModify","HealthCheck"]}}
94 public void shouldProcessCapabilitiesForVMLevel() throws Exception {
95 SvcLogicContext ctx = new SvcLogicContext();
96 ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
97 String findCapability = "Restart";
98 JsonNodeFactory.instance.objectNode();
100 "[{\"Restart\":[\"SSC\",\"MMC\"]},{\"Rebuild\":[\"SSC\"]},{\"Migrate\":[\"SSC\"]},{\"Snapshot\":[\"SSC\"]},{\"Start\":[\"SSC\"]},{\"Stop\":[\"SSC\"]}]";
101 ObjectMapper m = new ObjectMapper();
102 JsonNode subCapabilities = m.readTree(subCaps);
103 String vServerId = "testServer";
104 ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code", "MMC");
105 ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-name", "testVnfc");
106 node.processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
107 String result = ctx.getAttribute("capabilities");
108 assertEquals(result, "Supported");
112 public void shouldCheckIfCapabilityCheckNeeded() {
113 ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
114 String findCapability = "Start";
115 String capLevel = "vnf";
116 boolean result = node.checkIfCapabilityCheckNeeded(capLevel, findCapability);
121 public void should_add_attribute_with_success_if_get_config_file_succeed() throws SvcLogicException {
122 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
124 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
125 configResourceNode.getConfigFileReference(inParams, contextMock);
127 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
131 public void should_add_attribute_with_success_if_get_config_info_succeed() throws SvcLogicException {
132 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
134 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
135 configResourceNode.getCommonConfigInfo(inParams, contextMock);
137 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
141 public void should_add_attribute_with_success_if_get_template_succeed() throws SvcLogicException {
142 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
144 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
145 configResourceNode.getTemplate(inParams, contextMock);
146 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
150 public void testGetVnfcReference() throws Exception {
151 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
152 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
153 contextMock.setAttribute("template-model-id", "testModelId");
154 contextMock.setAttribute("vnfc-type", "testVnfcType");
155 configResourceNode.getVnfcReference(inParams, contextMock);
156 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
160 public void should_add_attribute_with_success_if_save_config_files_succeed() throws SvcLogicException {
161 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
163 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
164 configResourceNode.saveConfigFiles(inParams, contextMock);
166 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
170 public void should_add_attribute_with_success_if_update_upload_config_succeed() throws SvcLogicException {
171 when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234");
173 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
175 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
176 configResourceNode.updateUploadConfig(inParams, contextMock);
178 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
182 public void should_add_attribute_with_success_if_get_download_config_template_by_vnf_type_succeed()
183 throws SvcLogicException {
184 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
186 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
187 configResourceNode.getDownloadConfigTemplateByVnf(inParams, contextMock);
189 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
193 public void should_add_attribute_with_success_if_get_ssm_chain_succeed() throws SvcLogicException {
194 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
196 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
197 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
199 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
203 public void should_add_attribute_with_success_if_save_prepare_relationship_succeed() throws SvcLogicException {
204 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
206 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
207 configResourceNode.savePrepareRelationship(inParams, contextMock);
209 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
213 public void should_throw_exception_on_device_config_missing() throws Exception {
214 DGGeneralDBService dbServiceMock =
215 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX,
216 DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND).build();
218 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
220 expectedException.expect(SvcLogicException.class);
221 expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
222 configResourceNode.getConfigFileReference(inParams, contextMock);
226 public void should_throw_exception_on_device_config_failure() throws Exception {
227 DGGeneralDBService dbServiceMock =
228 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX,
229 DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE).build();
231 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
233 expectedException.expect(SvcLogicException.class);
234 expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
235 configResourceNode.getConfigFileReference(inParams, contextMock);
239 public void should_throw_exception_on_success_param_missing() throws Exception {
241 DGGeneralDBService dbServiceMock =
242 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE,
243 SvcLogicResource.QueryStatus.NOT_FOUND).build();
245 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
247 expectedException.expect(SvcLogicException.class);
248 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
249 configResourceNode.getConfigFileReference(inParams, contextMock);
253 public void should_throw_exception_on_success_param_failure() throws Exception {
254 DGGeneralDBService dbServiceMock =
255 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE,
256 SvcLogicResource.QueryStatus.FAILURE).build();
258 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
260 expectedException.expect(SvcLogicException.class);
261 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
262 configResourceNode.getConfigFileReference(inParams, contextMock);
266 public void should_throw_exception_on_failure_param_missing() throws Exception {
268 DGGeneralDBService dbServiceMock =
269 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE,
270 SvcLogicResource.QueryStatus.NOT_FOUND).build();
272 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
274 expectedException.expect(SvcLogicException.class);
275 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
276 configResourceNode.getConfigFileReference(inParams, contextMock);
280 public void should_throw_exception_on_failure_param_failure() throws Exception {
281 DGGeneralDBService dbServiceMock =
282 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE,
283 SvcLogicResource.QueryStatus.FAILURE).build();
285 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
287 expectedException.expect(SvcLogicException.class);
288 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
289 configResourceNode.getConfigFileReference(inParams, contextMock);
293 public void should_throw_exception_on_log_param_missing() throws Exception {
295 DGGeneralDBService dbServiceMock =
296 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE,
297 SvcLogicResource.QueryStatus.NOT_FOUND).build();
299 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
301 expectedException.expect(SvcLogicException.class);
302 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
303 configResourceNode.getConfigFileReference(inParams, contextMock);
307 public void should_throw_exception_on_log_param_failure() throws Exception {
308 DGGeneralDBService dbServiceMock =
309 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE,
310 SvcLogicResource.QueryStatus.FAILURE).build();
312 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
314 expectedException.expect(SvcLogicException.class);
315 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
316 configResourceNode.getConfigFileReference(inParams, contextMock);
320 public void should_throw_exception_on_device_protocol_missing() throws SvcLogicException {
321 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
322 .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build();
324 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
326 expectedException.expect(SvcLogicException.class);
327 expectedException.expectMessage("Unable to Read device_interface_protocol");
328 configResourceNode.getCommonConfigInfo(inParams, contextMock);
332 public void should_throw_exception_on_device_protocol_failure() throws SvcLogicException {
333 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
334 .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
336 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
338 expectedException.expect(SvcLogicException.class);
339 expectedException.expectMessage("Unable to Read device_interface_protocol");
340 configResourceNode.getCommonConfigInfo(inParams, contextMock);
344 public void should_throw_exception_on_conf_action_by_vnf_action_failure() throws SvcLogicException {
345 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
346 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
348 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
350 expectedException.expect(SvcLogicException.class);
351 expectedException.expectMessage("Unable to Read configure_action_dg");
352 configResourceNode.getCommonConfigInfo(inParams, contextMock);
356 public void should_throw_exception_on_conf_action_missing() throws SvcLogicException {
357 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
358 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
359 .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build();
361 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
363 expectedException.expect(SvcLogicException.class);
364 expectedException.expectMessage("Unable to Read configure_action_dg");
365 configResourceNode.getCommonConfigInfo(inParams, contextMock);
369 public void should_throw_exception_on_conf_action_failure() throws SvcLogicException {
370 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
371 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
372 .getConfigureActionDGByVnfType(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_db_template_failure() throws SvcLogicException {
383 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
384 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
386 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
387 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE).build();
389 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
391 expectedException.expect(SvcLogicException.class);
392 expectedException.expectMessage("Unable to Read some file category");
393 configResourceNode.getTemplate(inParams, contextMock);
397 public void should_throw_exception_on_db_template_by_action_failure() throws SvcLogicException {
398 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
399 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
401 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
402 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
403 .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE)
406 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
408 expectedException.expect(SvcLogicException.class);
409 expectedException.expectMessage("Unable to Read some file category");
410 configResourceNode.getTemplate(inParams, contextMock);
414 public void should_throw_exception_on_db_template_by_action_missing() throws SvcLogicException {
415 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
416 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
418 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
419 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
420 .getTemplateByVnfTypeNAction("some prefix", "some file category",
421 SvcLogicResource.QueryStatus.NOT_FOUND)
424 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
426 expectedException.expect(SvcLogicException.class);
427 expectedException.expectMessage("Unable to Read some file category");
428 configResourceNode.getTemplate(inParams, contextMock);
432 public void should_throw_exception_on_db_template_by_name_missing() throws SvcLogicException {
433 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
434 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
436 SvcLogicContext context = new SvcLogicContext();
437 context.setAttribute("template-name", "test template");
439 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
440 .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.NOT_FOUND)
443 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
445 expectedException.expect(SvcLogicException.class);
446 expectedException.expectMessage("Unable to Read some file category template");
447 configResourceNode.getTemplate(inParams, context);
451 public void should_throw_exception_on_db_template_by_name_failure() throws SvcLogicException {
452 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
453 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
455 SvcLogicContext context = new SvcLogicContext();
456 context.setAttribute("template-name", "test template");
458 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
459 .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.FAILURE)
462 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
464 expectedException.expect(SvcLogicException.class);
465 expectedException.expectMessage("Unable to Read some file category template");
466 configResourceNode.getTemplate(inParams, context);
470 public void should_throw_exception_on_save_config_failure() throws SvcLogicException {
471 SvcLogicContext context = new SvcLogicContext();
472 context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
474 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
475 .saveConfigFiles(CONFIG_FILES_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
477 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
479 expectedException.expect(SvcLogicException.class);
480 expectedException.expectMessage("Unable to Save some file category in configfiles");
481 configResourceNode.saveConfigFiles(inParams, context);
485 public void should_throw_exception_on_get_max_config_id_missing() throws SvcLogicException {
486 SvcLogicContext context = new SvcLogicContext();
487 context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
489 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
490 .getMaxConfigFileId(MAX_CONF_FILE_PREFIX, "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
493 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
495 expectedException.expect(SvcLogicException.class);
496 expectedException.expectMessage("Unable to get some file category from configfiles");
498 configResourceNode.saveConfigFiles(inParams, context);
502 public void should_throw_exception_on_save_config_files_failure() throws SvcLogicException {
503 SvcLogicContext context = new SvcLogicContext();
504 context.setAttribute(CONFIG_FILE_ID_PARAM, "some file id");
506 DGGeneralDBService dbServiceMock =
507 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
508 SvcLogicResource.QueryStatus.FAILURE).build();
510 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
512 expectedException.expect(SvcLogicException.class);
513 expectedException.expectMessage("Unable to save prepare_relationship");
514 configResourceNode.saveConfigFiles(inParams, context);
518 public void should_throw_exception_on_save_upload_config_failure() throws SvcLogicException {
519 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
520 .saveUploadConfig(UPLOAD_CONFIG_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
522 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
524 expectedException.expect(SvcLogicException.class);
525 expectedException.expectMessage("Unable to Save configuration in upload_config");
526 configResourceNode.updateUploadConfig(inParams, contextMock);
530 public void should_throw_exception_on_get_upload_config_failure() throws SvcLogicException {
531 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
532 .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
534 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
536 expectedException.expect(SvcLogicException.class);
537 expectedException.expectMessage("Unable to get record from upload_config");
538 configResourceNode.updateUploadConfig(inParams, contextMock);
542 public void should_throw_exception_on_get_upload_config_missing() throws SvcLogicException {
543 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
544 .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build();
546 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
548 expectedException.expect(SvcLogicException.class);
549 expectedException.expectMessage("Unable to get record from upload_config");
550 configResourceNode.updateUploadConfig(inParams, contextMock);
554 public void should_throw_exception_on_update_upload_config_failure() throws SvcLogicException {
555 when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234");
557 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
558 .updateUploadConfig(UPLOAD_CONFIG_PREFIX, 1234, SvcLogicResource.QueryStatus.FAILURE).build();
560 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
562 expectedException.expect(SvcLogicException.class);
563 expectedException.expectMessage("Unable to upload upload_config");
564 configResourceNode.updateUploadConfig(inParams, contextMock);
568 public void should_throw_exception_on_get_download_config_failure() throws SvcLogicException {
569 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
571 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
572 .getDownloadConfigTemplateByVnf("some prefix", SvcLogicResource.QueryStatus.FAILURE).build();
574 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
576 expectedException.expect(SvcLogicException.class);
577 expectedException.expectMessage("Unable to get download config template.");
578 configResourceNode.getDownloadConfigTemplateByVnf(inParams, contextMock);
582 public void should_throw_exception_on_get_ssm_chain_failure() throws SvcLogicException {
583 when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
585 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
586 .getTemplateByArtifactType("smm", "smm", "some location", SvcLogicResource.QueryStatus.FAILURE).build();
588 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
590 expectedException.expect(SvcLogicException.class);
591 expectedException.expectMessage("Unable to Read smm file");
592 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
596 public void should_throw_exception_on_get_ca_chain_failure() throws SvcLogicException {
597 when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
599 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().getTemplateByArtifactType("intermediate-ca-chain",
600 "intermediate_ca_chain", "some location", SvcLogicResource.QueryStatus.FAILURE).build();
602 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
604 expectedException.expect(SvcLogicException.class);
605 expectedException.expectMessage("Unable to Read intermediate_ca_chain file");
606 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
610 public void should_throw_exception_on_get_server_certificate_and_key_failure() throws SvcLogicException {
611 when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
613 DGGeneralDBService dbServiceMock =
614 new MockDbServiceBuilder().getTemplateByArtifactType("server-certificate-and-key",
615 "server_certificate_and_key", "some location", SvcLogicResource.QueryStatus.FAILURE).build();
617 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
619 expectedException.expect(SvcLogicException.class);
620 expectedException.expectMessage("Unable to Read server_certificate_and_key file");
621 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
625 public void should_throw_exception_on_save_prepare_relationship_failure() throws SvcLogicException {
626 inParams.put(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND, "some sdnc index");
627 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_ID, "some file id");
629 DGGeneralDBService dbServiceMock =
630 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
631 "some sdnc index", QueryStatus.FAILURE).build();
633 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
635 expectedException.expect(SvcLogicException.class);
636 expectedException.expectMessage(UNABLE_TO_SAVE_RELATIONSHIP_STR);
637 configResourceNode.savePrepareRelationship(inParams, contextMock);
641 public void should_save_save_config_files_for_empty_config_params() throws SvcLogicException {
643 when(contextMock.getAttribute(TMP_CONVERTCONFIG_ESC_DATA)).thenReturn("some esc data");
644 when(contextMock.getAttribute("configuration")).thenReturn("some configuration");
645 when(contextMock.getAttribute(CONFIG_PARAMS)).thenReturn("");
647 DGGeneralDBService dbServiceMock =
648 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
649 "some sdnc index", QueryStatus.FAILURE).build();
651 ConfigResourceNode configResourceNode = spy(new ConfigResourceNode(dbServiceMock));
652 configResourceNode.saveConfigBlock(inParams, contextMock);
654 verify(configResourceNode).saveDeviceConfiguration(inParams, contextMock, "Request", "some esc data",
655 "some configuration");
656 verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
660 public void should_save_save_config_files_for_non_empty_config_params() throws SvcLogicException {
662 when(contextMock.getAttribute(TMP_CONVERTCONFIG_ESC_DATA)).thenReturn("some esc data");
663 when(contextMock.getAttribute(TMP_MERGE_MERGED_DATA)).thenReturn("merged data");
664 when(contextMock.getAttribute(CONFIG_PARAMS)).thenReturn("non empty");
666 DGGeneralDBService dbServiceMock =
667 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
668 "some sdnc index", QueryStatus.FAILURE).build();
670 ConfigResourceNode configResourceNode = spy(new ConfigResourceNode(dbServiceMock));
671 configResourceNode.saveConfigBlock(inParams, contextMock);
673 verify(configResourceNode).saveDeviceConfiguration(inParams, contextMock, "Configurator", "some esc data",
675 verify(configResourceNode).saveConfigBlock(inParams, contextMock);
676 verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));