1 package org.onap.appc.data.services.node;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.mockito.Matchers.anyString;
6 import static org.mockito.Matchers.eq;
7 import static org.mockito.Mockito.atLeastOnce;
8 import static org.mockito.Mockito.mock;
9 import static org.mockito.Mockito.spy;
10 import static org.mockito.Mockito.verify;
11 import static org.mockito.Mockito.when;
12 import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_FILES_PREFIX;
13 import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_FILE_ID_PARAM;
14 import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_PARAMS;
15 import static org.onap.appc.data.services.node.ConfigResourceNode.CONF_ACTION_PREFIX;
16 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_FILE_TYPE;
17 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_PREFIX;
18 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_PROTOCOL_PREFIX;
19 import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_FILE_TYPE;
20 import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_PREFIX;
21 import static org.onap.appc.data.services.node.ConfigResourceNode.FILE_CATEGORY_PARAM;
22 import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_FILE_TYPE;
23 import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_PREFIX;
24 import static org.onap.appc.data.services.node.ConfigResourceNode.MAX_CONF_FILE_PREFIX;
25 import static org.onap.appc.data.services.node.ConfigResourceNode.PREPARE_RELATIONSHIP_PARAM;
26 import static org.onap.appc.data.services.node.ConfigResourceNode.SDC_IND;
27 import static org.onap.appc.data.services.node.ConfigResourceNode.SITE_LOCATION_PARAM;
28 import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_FILE_TYPE;
29 import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_PREFIX;
30 import static org.onap.appc.data.services.node.ConfigResourceNode.TMP_CONVERTCONFIG_ESC_DATA;
31 import static org.onap.appc.data.services.node.ConfigResourceNode.TMP_MERGE_MERGED_DATA;
32 import static org.onap.appc.data.services.node.ConfigResourceNode.UNABLE_TO_SAVE_RELATIONSHIP_STR;
33 import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_ID_PARAM;
34 import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_INFO_PREFIX;
35 import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_PREFIX;
36 import com.fasterxml.jackson.databind.JsonNode;
37 import com.fasterxml.jackson.databind.ObjectMapper;
38 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
39 import java.util.HashMap;
40 import org.junit.Before;
41 import org.junit.Rule;
42 import org.junit.Test;
43 import org.junit.rules.ExpectedException;
44 import org.onap.appc.data.services.AppcDataServiceConstant;
45 import org.onap.appc.data.services.db.DGGeneralDBService;
46 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
47 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
48 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
49 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
51 public class ConfigResourceNodeTest {
53 private HashMap<String, String> inParams;
54 private SvcLogicContext contextMock;
57 public ExpectedException expectedException = ExpectedException.none();
61 contextMock = mock(SvcLogicContext.class);
62 inParams = new HashMap<>();
68 * {"capabilities":{"vnfc":[],"vm":[{"ConfigureTest":["SSC","MMSC"]}],"vf-module":[],"vnf":["ConfigModify","HealthCheck"]}}
71 public void shouldProcessCapabilitiesForVMLevel() throws Exception {
72 SvcLogicContext ctx = new SvcLogicContext();
73 ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
74 String findCapability = "Restart";
75 JsonNodeFactory.instance.objectNode();
77 "[{\"Restart\":[\"SSC\",\"MMC\"]},{\"Rebuild\":[\"SSC\"]},{\"Migrate\":[\"SSC\"]},{\"Snapshot\":[\"SSC\"]},{\"Start\":[\"SSC\"]},{\"Stop\":[\"SSC\"]}]";
78 ObjectMapper m = new ObjectMapper();
79 JsonNode subCapabilities = m.readTree(subCaps);
80 String vServerId = "testServer";
81 ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code", "MMC");
82 ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-name", "testVnfc");
83 node.processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
84 String result = ctx.getAttribute("capabilities");
85 assertEquals(result, "Supported");
89 public void shouldCheckIfCapabilityCheckNeeded() {
90 ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
91 String findCapability = "Start";
92 String capLevel = "vnf";
93 boolean result = node.checkIfCapabilityCheckNeeded(capLevel, findCapability);
98 public void should_add_attribute_with_success_if_get_config_file_succeed() throws SvcLogicException {
99 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
101 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
102 configResourceNode.getConfigFileReference(inParams, contextMock);
104 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
108 public void should_add_attribute_with_success_if_get_config_info_succeed() throws SvcLogicException {
109 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
111 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
112 configResourceNode.getCommonConfigInfo(inParams, contextMock);
114 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
118 public void should_add_attribute_with_success_if_get_template_succeed() throws SvcLogicException {
119 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
121 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
122 configResourceNode.getTemplate(inParams, contextMock);
124 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
128 public void should_add_attribute_with_success_if_save_config_files_succeed() throws SvcLogicException {
129 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
131 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
132 configResourceNode.saveConfigFiles(inParams, contextMock);
134 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
138 public void should_add_attribute_with_success_if_update_upload_config_succeed() throws SvcLogicException {
139 when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234");
141 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
143 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
144 configResourceNode.updateUploadConfig(inParams, contextMock);
146 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
150 public void should_add_attribute_with_success_if_get_download_config_template_by_vnf_type_succeed()
151 throws SvcLogicException {
152 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
154 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
155 configResourceNode.getDownloadConfigTemplateByVnf(inParams, contextMock);
157 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
161 public void should_add_attribute_with_success_if_get_ssm_chain_succeed() throws SvcLogicException {
162 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
164 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
165 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
167 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
171 public void should_add_attribute_with_success_if_save_prepare_relationship_succeed() throws SvcLogicException {
172 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
174 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
175 configResourceNode.savePrepareRelationship(inParams, contextMock);
177 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
181 public void should_throw_exception_on_device_config_missing() throws Exception {
182 DGGeneralDBService dbServiceMock =
183 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX,
184 DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND).build();
186 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
188 expectedException.expect(SvcLogicException.class);
189 expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
190 configResourceNode.getConfigFileReference(inParams, contextMock);
194 public void should_throw_exception_on_device_config_failure() throws Exception {
195 DGGeneralDBService dbServiceMock =
196 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX,
197 DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE).build();
199 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
201 expectedException.expect(SvcLogicException.class);
202 expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
203 configResourceNode.getConfigFileReference(inParams, contextMock);
207 public void should_throw_exception_on_success_param_missing() throws Exception {
209 DGGeneralDBService dbServiceMock =
210 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE,
211 SvcLogicResource.QueryStatus.NOT_FOUND).build();
213 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
215 expectedException.expect(SvcLogicException.class);
216 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
217 configResourceNode.getConfigFileReference(inParams, contextMock);
221 public void should_throw_exception_on_success_param_failure() throws Exception {
222 DGGeneralDBService dbServiceMock =
223 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE,
224 SvcLogicResource.QueryStatus.FAILURE).build();
226 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
228 expectedException.expect(SvcLogicException.class);
229 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
230 configResourceNode.getConfigFileReference(inParams, contextMock);
234 public void should_throw_exception_on_failure_param_missing() throws Exception {
236 DGGeneralDBService dbServiceMock =
237 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE,
238 SvcLogicResource.QueryStatus.NOT_FOUND).build();
240 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
242 expectedException.expect(SvcLogicException.class);
243 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
244 configResourceNode.getConfigFileReference(inParams, contextMock);
248 public void should_throw_exception_on_failure_param_failure() throws Exception {
249 DGGeneralDBService dbServiceMock =
250 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE,
251 SvcLogicResource.QueryStatus.FAILURE).build();
253 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
255 expectedException.expect(SvcLogicException.class);
256 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
257 configResourceNode.getConfigFileReference(inParams, contextMock);
261 public void should_throw_exception_on_log_param_missing() throws Exception {
263 DGGeneralDBService dbServiceMock =
264 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE,
265 SvcLogicResource.QueryStatus.NOT_FOUND).build();
267 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
269 expectedException.expect(SvcLogicException.class);
270 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
271 configResourceNode.getConfigFileReference(inParams, contextMock);
275 public void should_throw_exception_on_log_param_failure() throws Exception {
276 DGGeneralDBService dbServiceMock =
277 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE,
278 SvcLogicResource.QueryStatus.FAILURE).build();
280 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
282 expectedException.expect(SvcLogicException.class);
283 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
284 configResourceNode.getConfigFileReference(inParams, contextMock);
288 public void should_throw_exception_on_device_protocol_missing() throws SvcLogicException {
289 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
290 .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build();
292 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
294 expectedException.expect(SvcLogicException.class);
295 expectedException.expectMessage("Unable to Read device_interface_protocol");
296 configResourceNode.getCommonConfigInfo(inParams, contextMock);
300 public void should_throw_exception_on_device_protocol_failure() throws SvcLogicException {
301 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
302 .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
304 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
306 expectedException.expect(SvcLogicException.class);
307 expectedException.expectMessage("Unable to Read device_interface_protocol");
308 configResourceNode.getCommonConfigInfo(inParams, contextMock);
312 public void should_throw_exception_on_conf_action_by_vnf_action_failure() throws SvcLogicException {
313 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
314 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
316 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
318 expectedException.expect(SvcLogicException.class);
319 expectedException.expectMessage("Unable to Read configure_action_dg");
320 configResourceNode.getCommonConfigInfo(inParams, contextMock);
324 public void should_throw_exception_on_conf_action_missing() throws SvcLogicException {
325 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
326 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
327 .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build();
329 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
331 expectedException.expect(SvcLogicException.class);
332 expectedException.expectMessage("Unable to Read configure_action_dg");
333 configResourceNode.getCommonConfigInfo(inParams, contextMock);
337 public void should_throw_exception_on_conf_action_failure() throws SvcLogicException {
338 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
339 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
340 .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
342 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
344 expectedException.expect(SvcLogicException.class);
345 expectedException.expectMessage("Unable to Read configure_action_dg");
346 configResourceNode.getCommonConfigInfo(inParams, contextMock);
350 public void should_throw_exception_on_db_template_failure() throws SvcLogicException {
351 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
352 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
354 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
355 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE).build();
357 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
359 expectedException.expect(SvcLogicException.class);
360 expectedException.expectMessage("Unable to Read some file category");
361 configResourceNode.getTemplate(inParams, contextMock);
365 public void should_throw_exception_on_db_template_by_action_failure() throws SvcLogicException {
366 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
367 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
369 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
370 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
371 .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE)
374 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
376 expectedException.expect(SvcLogicException.class);
377 expectedException.expectMessage("Unable to Read some file category");
378 configResourceNode.getTemplate(inParams, contextMock);
382 public void should_throw_exception_on_db_template_by_action_missing() 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.NOT_FOUND)
388 .getTemplateByVnfTypeNAction("some prefix", "some file category",
389 SvcLogicResource.QueryStatus.NOT_FOUND)
392 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
394 expectedException.expect(SvcLogicException.class);
395 expectedException.expectMessage("Unable to Read some file category");
396 configResourceNode.getTemplate(inParams, contextMock);
400 public void should_throw_exception_on_db_template_by_name_missing() throws SvcLogicException {
401 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
402 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
404 SvcLogicContext context = new SvcLogicContext();
405 context.setAttribute("template-name", "test template");
407 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
408 .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.NOT_FOUND)
411 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
413 expectedException.expect(SvcLogicException.class);
414 expectedException.expectMessage("Unable to Read some file category template");
415 configResourceNode.getTemplate(inParams, context);
419 public void should_throw_exception_on_db_template_by_name_failure() throws SvcLogicException {
420 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
421 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
423 SvcLogicContext context = new SvcLogicContext();
424 context.setAttribute("template-name", "test template");
426 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
427 .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.FAILURE)
430 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
432 expectedException.expect(SvcLogicException.class);
433 expectedException.expectMessage("Unable to Read some file category template");
434 configResourceNode.getTemplate(inParams, context);
438 public void should_throw_exception_on_save_config_failure() throws SvcLogicException {
439 SvcLogicContext context = new SvcLogicContext();
440 context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
442 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
443 .saveConfigFiles(CONFIG_FILES_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
445 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
447 expectedException.expect(SvcLogicException.class);
448 expectedException.expectMessage("Unable to Save some file category in configfiles");
449 configResourceNode.saveConfigFiles(inParams, context);
453 public void should_throw_exception_on_get_max_config_id_missing() throws SvcLogicException {
454 SvcLogicContext context = new SvcLogicContext();
455 context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
457 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
458 .getMaxConfigFileId(MAX_CONF_FILE_PREFIX, "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
461 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
463 expectedException.expect(SvcLogicException.class);
464 expectedException.expectMessage("Unable to get some file category from configfiles");
466 configResourceNode.saveConfigFiles(inParams, context);
470 public void should_throw_exception_on_save_config_files_failure() throws SvcLogicException {
471 SvcLogicContext context = new SvcLogicContext();
472 context.setAttribute(CONFIG_FILE_ID_PARAM, "some file id");
474 DGGeneralDBService dbServiceMock =
475 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
476 SvcLogicResource.QueryStatus.FAILURE).build();
478 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
480 expectedException.expect(SvcLogicException.class);
481 expectedException.expectMessage("Unable to save prepare_relationship");
482 configResourceNode.saveConfigFiles(inParams, context);
486 public void should_throw_exception_on_save_upload_config_failure() throws SvcLogicException {
487 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
488 .saveUploadConfig(UPLOAD_CONFIG_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
490 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
492 expectedException.expect(SvcLogicException.class);
493 expectedException.expectMessage("Unable to Save configuration in upload_config");
494 configResourceNode.updateUploadConfig(inParams, contextMock);
498 public void should_throw_exception_on_get_upload_config_failure() throws SvcLogicException {
499 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
500 .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
502 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
504 expectedException.expect(SvcLogicException.class);
505 expectedException.expectMessage("Unable to get record from upload_config");
506 configResourceNode.updateUploadConfig(inParams, contextMock);
510 public void should_throw_exception_on_get_upload_config_missing() throws SvcLogicException {
511 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
512 .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build();
514 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
516 expectedException.expect(SvcLogicException.class);
517 expectedException.expectMessage("Unable to get record from upload_config");
518 configResourceNode.updateUploadConfig(inParams, contextMock);
522 public void should_throw_exception_on_update_upload_config_failure() throws SvcLogicException {
523 when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234");
525 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
526 .updateUploadConfig(UPLOAD_CONFIG_PREFIX, 1234, SvcLogicResource.QueryStatus.FAILURE).build();
528 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
530 expectedException.expect(SvcLogicException.class);
531 expectedException.expectMessage("Unable to upload upload_config");
532 configResourceNode.updateUploadConfig(inParams, contextMock);
536 public void should_throw_exception_on_get_download_config_failure() throws SvcLogicException {
537 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
539 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
540 .getDownloadConfigTemplateByVnf("some prefix", SvcLogicResource.QueryStatus.FAILURE).build();
542 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
544 expectedException.expect(SvcLogicException.class);
545 expectedException.expectMessage("Unable to get download config template.");
546 configResourceNode.getDownloadConfigTemplateByVnf(inParams, contextMock);
550 public void should_throw_exception_on_get_ssm_chain_failure() throws SvcLogicException {
551 when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
553 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
554 .getTemplateByArtifactType("smm", "smm", "some location", SvcLogicResource.QueryStatus.FAILURE).build();
556 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
558 expectedException.expect(SvcLogicException.class);
559 expectedException.expectMessage("Unable to Read smm file");
560 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
564 public void should_throw_exception_on_get_ca_chain_failure() throws SvcLogicException {
565 when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
567 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().getTemplateByArtifactType("intermediate-ca-chain",
568 "intermediate_ca_chain", "some location", SvcLogicResource.QueryStatus.FAILURE).build();
570 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
572 expectedException.expect(SvcLogicException.class);
573 expectedException.expectMessage("Unable to Read intermediate_ca_chain file");
574 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
578 public void should_throw_exception_on_get_server_certificate_and_key_failure() throws SvcLogicException {
579 when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
581 DGGeneralDBService dbServiceMock =
582 new MockDbServiceBuilder().getTemplateByArtifactType("server-certificate-and-key",
583 "server_certificate_and_key", "some location", SvcLogicResource.QueryStatus.FAILURE).build();
585 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
587 expectedException.expect(SvcLogicException.class);
588 expectedException.expectMessage("Unable to Read server_certificate_and_key file");
589 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
593 public void should_throw_exception_on_save_prepare_relationship_failure() throws SvcLogicException {
594 inParams.put(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND, "some sdnc index");
595 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_ID, "some file id");
597 DGGeneralDBService dbServiceMock =
598 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
599 "some sdnc index", QueryStatus.FAILURE).build();
601 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
603 expectedException.expect(SvcLogicException.class);
604 expectedException.expectMessage(UNABLE_TO_SAVE_RELATIONSHIP_STR);
605 configResourceNode.savePrepareRelationship(inParams, contextMock);
609 public void should_save_save_config_files_for_empty_config_params() throws SvcLogicException {
611 when(contextMock.getAttribute(TMP_CONVERTCONFIG_ESC_DATA)).thenReturn("some esc data");
612 when(contextMock.getAttribute("configuration")).thenReturn("some configuration");
613 when(contextMock.getAttribute(CONFIG_PARAMS)).thenReturn("");
615 DGGeneralDBService dbServiceMock =
616 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
617 "some sdnc index", QueryStatus.FAILURE).build();
619 ConfigResourceNode configResourceNode = spy(new ConfigResourceNode(dbServiceMock));
620 configResourceNode.saveConfigBlock(inParams, contextMock);
622 verify(configResourceNode).saveDeviceConfiguration(inParams, contextMock, "Request", "some esc data",
623 "some configuration");
624 verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
628 public void should_save_save_config_files_for_non_empty_config_params() throws SvcLogicException {
630 when(contextMock.getAttribute(TMP_CONVERTCONFIG_ESC_DATA)).thenReturn("some esc data");
631 when(contextMock.getAttribute(TMP_MERGE_MERGED_DATA)).thenReturn("merged data");
632 when(contextMock.getAttribute(CONFIG_PARAMS)).thenReturn("non empty");
634 DGGeneralDBService dbServiceMock =
635 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
636 "some sdnc index", QueryStatus.FAILURE).build();
638 ConfigResourceNode configResourceNode = spy(new ConfigResourceNode(dbServiceMock));
639 configResourceNode.saveConfigBlock(inParams, contextMock);
641 verify(configResourceNode).saveDeviceConfiguration(inParams, contextMock, "Configurator", "some esc data",
643 verify(configResourceNode).saveConfigBlock(inParams, contextMock);
644 verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));