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.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 testGetCapability() throws Exception {
161 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
162 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
163 contextMock.setAttribute("responsePrefix", "testResponsePrefix");
164 contextMock.setAttribute("caplevel", "testCapLevel");
165 contextMock.setAttribute("checkCapability", "testCheckCapability");
166 contextMock.setAttribute("vServerId", "testVServerId");
167 contextMock.setAttribute("vnf-type", "testVnfType");
168 configResourceNode.getCapability(inParams, contextMock);
169 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
173 public void testGetConfigFilesByVnfVmNCategory() throws Exception {
174 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
175 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
176 contextMock.setAttribute("responsePrefix", "testResponsePrefix");
177 contextMock.setAttribute("fileCategory", "testFileCategory");
178 contextMock.setAttribute("vnfId", "testVnfId");
179 contextMock.setAttribute("vmName", "testVmName");
180 configResourceNode.getConfigFilesByVnfVmNCategory(inParams, contextMock);
181 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
185 public void should_add_attribute_with_success_if_save_config_files_succeed() throws SvcLogicException {
186 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
188 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
189 configResourceNode.saveConfigFiles(inParams, contextMock);
191 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
195 public void should_add_attribute_with_success_if_update_upload_config_succeed() throws SvcLogicException {
196 when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234");
198 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
200 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
201 configResourceNode.updateUploadConfig(inParams, contextMock);
203 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
207 public void should_add_attribute_with_success_if_get_download_config_template_by_vnf_type_succeed()
208 throws SvcLogicException {
209 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
211 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
212 configResourceNode.getDownloadConfigTemplateByVnf(inParams, contextMock);
214 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
218 public void should_add_attribute_with_success_if_get_ssm_chain_succeed() throws SvcLogicException {
219 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
221 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
222 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
224 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
228 public void should_add_attribute_with_success_if_save_prepare_relationship_succeed() throws SvcLogicException {
229 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
231 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
232 configResourceNode.savePrepareRelationship(inParams, contextMock);
234 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
238 public void should_throw_exception_on_device_config_missing() throws Exception {
239 DGGeneralDBService dbServiceMock =
240 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX,
241 DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND).build();
243 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
245 expectedException.expect(SvcLogicException.class);
246 expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
247 configResourceNode.getConfigFileReference(inParams, contextMock);
251 public void should_throw_exception_on_device_config_failure() throws Exception {
252 DGGeneralDBService dbServiceMock =
253 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX,
254 DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE).build();
256 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
258 expectedException.expect(SvcLogicException.class);
259 expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
260 configResourceNode.getConfigFileReference(inParams, contextMock);
264 public void should_throw_exception_on_success_param_missing() throws Exception {
266 DGGeneralDBService dbServiceMock =
267 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE,
268 SvcLogicResource.QueryStatus.NOT_FOUND).build();
270 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
272 expectedException.expect(SvcLogicException.class);
273 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
274 configResourceNode.getConfigFileReference(inParams, contextMock);
278 public void should_throw_exception_on_success_param_failure() throws Exception {
279 DGGeneralDBService dbServiceMock =
280 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE,
281 SvcLogicResource.QueryStatus.FAILURE).build();
283 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
285 expectedException.expect(SvcLogicException.class);
286 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
287 configResourceNode.getConfigFileReference(inParams, contextMock);
291 public void should_throw_exception_on_failure_param_missing() throws Exception {
293 DGGeneralDBService dbServiceMock =
294 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE,
295 SvcLogicResource.QueryStatus.NOT_FOUND).build();
297 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
299 expectedException.expect(SvcLogicException.class);
300 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
301 configResourceNode.getConfigFileReference(inParams, contextMock);
305 public void should_throw_exception_on_failure_param_failure() throws Exception {
306 DGGeneralDBService dbServiceMock =
307 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE,
308 SvcLogicResource.QueryStatus.FAILURE).build();
310 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
312 expectedException.expect(SvcLogicException.class);
313 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
314 configResourceNode.getConfigFileReference(inParams, contextMock);
318 public void should_throw_exception_on_log_param_missing() throws Exception {
320 DGGeneralDBService dbServiceMock =
321 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE,
322 SvcLogicResource.QueryStatus.NOT_FOUND).build();
324 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
326 expectedException.expect(SvcLogicException.class);
327 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
328 configResourceNode.getConfigFileReference(inParams, contextMock);
332 public void should_throw_exception_on_log_param_failure() throws Exception {
333 DGGeneralDBService dbServiceMock =
334 new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE,
335 SvcLogicResource.QueryStatus.FAILURE).build();
337 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
339 expectedException.expect(SvcLogicException.class);
340 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
341 configResourceNode.getConfigFileReference(inParams, contextMock);
345 public void should_throw_exception_on_device_protocol_missing() throws SvcLogicException {
346 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
347 .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build();
349 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
351 expectedException.expect(SvcLogicException.class);
352 expectedException.expectMessage("Unable to Read device_interface_protocol");
353 configResourceNode.getCommonConfigInfo(inParams, contextMock);
357 public void should_throw_exception_on_device_protocol_failure() throws SvcLogicException {
358 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
359 .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
361 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
363 expectedException.expect(SvcLogicException.class);
364 expectedException.expectMessage("Unable to Read device_interface_protocol");
365 configResourceNode.getCommonConfigInfo(inParams, contextMock);
369 public void should_throw_exception_on_conf_action_by_vnf_action_failure() throws SvcLogicException {
370 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
371 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
373 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
375 expectedException.expect(SvcLogicException.class);
376 expectedException.expectMessage("Unable to Read configure_action_dg");
377 configResourceNode.getCommonConfigInfo(inParams, contextMock);
381 public void should_throw_exception_on_conf_action_missing() throws SvcLogicException {
382 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
383 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
384 .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build();
386 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
388 expectedException.expect(SvcLogicException.class);
389 expectedException.expectMessage("Unable to Read configure_action_dg");
390 configResourceNode.getCommonConfigInfo(inParams, contextMock);
394 public void should_throw_exception_on_conf_action_failure() throws SvcLogicException {
395 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
396 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
397 .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
399 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
401 expectedException.expect(SvcLogicException.class);
402 expectedException.expectMessage("Unable to Read configure_action_dg");
403 configResourceNode.getCommonConfigInfo(inParams, contextMock);
407 public void should_throw_exception_on_db_template_failure() throws SvcLogicException {
408 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
409 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
411 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
412 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE).build();
414 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
416 expectedException.expect(SvcLogicException.class);
417 expectedException.expectMessage("Unable to Read some file category");
418 configResourceNode.getTemplate(inParams, contextMock);
422 public void should_throw_exception_on_db_template_by_action_failure() throws SvcLogicException {
423 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
424 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
426 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
427 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
428 .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE)
431 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
433 expectedException.expect(SvcLogicException.class);
434 expectedException.expectMessage("Unable to Read some file category");
435 configResourceNode.getTemplate(inParams, contextMock);
439 public void should_throw_exception_on_db_template_by_action_missing() throws SvcLogicException {
440 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
441 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
443 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
444 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
445 .getTemplateByVnfTypeNAction("some prefix", "some file category",
446 SvcLogicResource.QueryStatus.NOT_FOUND)
449 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
451 expectedException.expect(SvcLogicException.class);
452 expectedException.expectMessage("Unable to Read some file category");
453 configResourceNode.getTemplate(inParams, contextMock);
457 public void should_throw_exception_on_db_template_by_name_missing() throws SvcLogicException {
458 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
459 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
461 SvcLogicContext context = new SvcLogicContext();
462 context.setAttribute("template-name", "test template");
464 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
465 .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.NOT_FOUND)
468 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
470 expectedException.expect(SvcLogicException.class);
471 expectedException.expectMessage("Unable to Read some file category template");
472 configResourceNode.getTemplate(inParams, context);
476 public void should_throw_exception_on_db_template_by_name_failure() throws SvcLogicException {
477 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
478 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
480 SvcLogicContext context = new SvcLogicContext();
481 context.setAttribute("template-name", "test template");
483 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
484 .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.FAILURE)
487 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
489 expectedException.expect(SvcLogicException.class);
490 expectedException.expectMessage("Unable to Read some file category template");
491 configResourceNode.getTemplate(inParams, context);
495 public void should_throw_exception_on_save_config_failure() throws SvcLogicException {
496 SvcLogicContext context = new SvcLogicContext();
497 context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
499 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
500 .saveConfigFiles(CONFIG_FILES_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
502 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
504 expectedException.expect(SvcLogicException.class);
505 expectedException.expectMessage("Unable to Save some file category in configfiles");
506 configResourceNode.saveConfigFiles(inParams, context);
510 public void should_throw_exception_on_get_max_config_id_missing() throws SvcLogicException {
511 SvcLogicContext context = new SvcLogicContext();
512 context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
514 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
515 .getMaxConfigFileId(MAX_CONF_FILE_PREFIX, "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
518 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
520 expectedException.expect(SvcLogicException.class);
521 expectedException.expectMessage("Unable to get some file category from configfiles");
523 configResourceNode.saveConfigFiles(inParams, context);
527 public void should_throw_exception_on_save_config_files_failure() throws SvcLogicException {
528 SvcLogicContext context = new SvcLogicContext();
529 context.setAttribute(CONFIG_FILE_ID_PARAM, "some file id");
531 DGGeneralDBService dbServiceMock =
532 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
533 SvcLogicResource.QueryStatus.FAILURE).build();
535 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
537 expectedException.expect(SvcLogicException.class);
538 expectedException.expectMessage("Unable to save prepare_relationship");
539 configResourceNode.saveConfigFiles(inParams, context);
543 public void should_throw_exception_on_save_upload_config_failure() throws SvcLogicException {
544 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
545 .saveUploadConfig(UPLOAD_CONFIG_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
547 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
549 expectedException.expect(SvcLogicException.class);
550 expectedException.expectMessage("Unable to Save configuration in upload_config");
551 configResourceNode.updateUploadConfig(inParams, contextMock);
555 public void should_throw_exception_on_get_upload_config_failure() throws SvcLogicException {
556 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
557 .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
559 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
561 expectedException.expect(SvcLogicException.class);
562 expectedException.expectMessage("Unable to get record from upload_config");
563 configResourceNode.updateUploadConfig(inParams, contextMock);
567 public void should_throw_exception_on_get_upload_config_missing() throws SvcLogicException {
568 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
569 .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build();
571 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
573 expectedException.expect(SvcLogicException.class);
574 expectedException.expectMessage("Unable to get record from upload_config");
575 configResourceNode.updateUploadConfig(inParams, contextMock);
579 public void should_throw_exception_on_update_upload_config_failure() throws SvcLogicException {
580 when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234");
582 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
583 .updateUploadConfig(UPLOAD_CONFIG_PREFIX, 1234, SvcLogicResource.QueryStatus.FAILURE).build();
585 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
587 expectedException.expect(SvcLogicException.class);
588 expectedException.expectMessage("Unable to upload upload_config");
589 configResourceNode.updateUploadConfig(inParams, contextMock);
593 public void should_throw_exception_on_get_download_config_failure() throws SvcLogicException {
594 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
596 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
597 .getDownloadConfigTemplateByVnf("some prefix", SvcLogicResource.QueryStatus.FAILURE).build();
599 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
601 expectedException.expect(SvcLogicException.class);
602 expectedException.expectMessage("Unable to get download config template.");
603 configResourceNode.getDownloadConfigTemplateByVnf(inParams, contextMock);
607 public void should_throw_exception_on_get_ssm_chain_failure() throws SvcLogicException {
608 when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
610 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
611 .getTemplateByArtifactType("smm", "smm", "some location", SvcLogicResource.QueryStatus.FAILURE).build();
613 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
615 expectedException.expect(SvcLogicException.class);
616 expectedException.expectMessage("Unable to Read smm file");
617 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
621 public void should_throw_exception_on_get_ca_chain_failure() throws SvcLogicException {
622 when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
624 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().getTemplateByArtifactType("intermediate-ca-chain",
625 "intermediate_ca_chain", "some location", SvcLogicResource.QueryStatus.FAILURE).build();
627 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
629 expectedException.expect(SvcLogicException.class);
630 expectedException.expectMessage("Unable to Read intermediate_ca_chain file");
631 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
635 public void should_throw_exception_on_get_server_certificate_and_key_failure() throws SvcLogicException {
636 when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
638 DGGeneralDBService dbServiceMock =
639 new MockDbServiceBuilder().getTemplateByArtifactType("server-certificate-and-key",
640 "server_certificate_and_key", "some location", SvcLogicResource.QueryStatus.FAILURE).build();
642 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
644 expectedException.expect(SvcLogicException.class);
645 expectedException.expectMessage("Unable to Read server_certificate_and_key file");
646 configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
650 public void should_throw_exception_on_save_prepare_relationship_failure() throws SvcLogicException {
651 inParams.put(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND, "some sdnc index");
652 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_ID, "some file id");
654 DGGeneralDBService dbServiceMock =
655 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
656 "some sdnc index", QueryStatus.FAILURE).build();
658 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
660 expectedException.expect(SvcLogicException.class);
661 expectedException.expectMessage(UNABLE_TO_SAVE_RELATIONSHIP_STR);
662 configResourceNode.savePrepareRelationship(inParams, contextMock);
666 public void should_save_save_config_files_for_empty_config_params() throws SvcLogicException {
668 when(contextMock.getAttribute(TMP_CONVERTCONFIG_ESC_DATA)).thenReturn("some esc data");
669 when(contextMock.getAttribute("configuration")).thenReturn("some configuration");
670 when(contextMock.getAttribute(CONFIG_PARAMS)).thenReturn("");
672 DGGeneralDBService dbServiceMock =
673 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
674 "some sdnc index", QueryStatus.FAILURE).build();
676 ConfigResourceNode configResourceNode = spy(new ConfigResourceNode(dbServiceMock));
677 configResourceNode.saveConfigBlock(inParams, contextMock);
679 verify(configResourceNode).saveDeviceConfiguration(inParams, contextMock, "Request", "some esc data",
680 "some configuration");
681 verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
685 public void should_save_save_config_files_for_non_empty_config_params() throws SvcLogicException {
687 when(contextMock.getAttribute(TMP_CONVERTCONFIG_ESC_DATA)).thenReturn("some esc data");
688 when(contextMock.getAttribute(TMP_MERGE_MERGED_DATA)).thenReturn("merged data");
689 when(contextMock.getAttribute(CONFIG_PARAMS)).thenReturn("non empty");
691 DGGeneralDBService dbServiceMock =
692 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
693 "some sdnc index", QueryStatus.FAILURE).build();
695 ConfigResourceNode configResourceNode = spy(new ConfigResourceNode(dbServiceMock));
696 configResourceNode.saveConfigBlock(inParams, contextMock);
698 verify(configResourceNode).saveDeviceConfiguration(inParams, contextMock, "Configurator", "some esc data",
700 verify(configResourceNode).saveConfigBlock(inParams, contextMock);
701 verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
705 public void testSaveTemplateConfig() throws SvcLogicException
707 SvcLogicContext context = new SvcLogicContext();
708 context.setAttribute(CONFIG_FILE_ID_PARAM, "some file id");
710 DGGeneralDBService dbServiceMock =
711 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
712 SvcLogicResource.QueryStatus.FAILURE).build();
714 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
715 configResourceNode.saveTemplateConfig(inParams, contextMock);
717 verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
721 public void testSaveStyleSheetConfig() throws SvcLogicException
723 SvcLogicContext context = new SvcLogicContext();
724 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "test");
725 context.setAttribute("tmp.merge.mergedData", "test");
726 context.setAttribute("tmp.convertconfig.escapeData", "test");
727 context.setAttribute("tmp.merge.mergedData", "test");
728 DGGeneralDBService dbServiceMock =
729 new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
730 SvcLogicResource.QueryStatus.FAILURE).build();
732 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
733 configResourceNode.saveStyleSheetConfig(inParams, contextMock);
735 verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));