Add coverage for ConfigResourceNode-5
[appc.git] / appc-config / appc-data-services / provider / src / test / java / org / onap / appc / data / services / node / ConfigResourceNodeTest.java
1 package org.onap.appc.data.services.node;
2
3 import com.fasterxml.jackson.databind.JsonNode;
4 import com.fasterxml.jackson.databind.ObjectMapper;
5 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
6 import java.util.HashMap;
7 import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertFalse;
9 import org.junit.Before;
10 import org.junit.Rule;
11 import org.junit.Test;
12 import org.junit.rules.ExpectedException;
13 import static org.mockito.Matchers.anyString;
14 import static org.mockito.Matchers.eq;
15 import static org.mockito.Mockito.mock;
16 import static org.mockito.Mockito.verify;
17 import static org.mockito.Mockito.when;
18 import org.onap.appc.data.services.AppcDataServiceConstant;
19 import org.onap.appc.data.services.db.DGGeneralDBService;
20 import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_FILE_ID_PARAM;
21 import static org.onap.appc.data.services.node.ConfigResourceNode.CONF_ACTION_PREFIX;
22 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_FILE_TYPE;
23 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_PREFIX;
24 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_PROTOCOL_PREFIX;
25 import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_FILE_TYPE;
26 import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_PREFIX;
27 import static org.onap.appc.data.services.node.ConfigResourceNode.FILE_CATEGORY_PARAM;
28 import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_FILE_TYPE;
29 import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_PREFIX;
30 import static org.onap.appc.data.services.node.ConfigResourceNode.MAX_CONF_FILE_PREFIX;
31 import static org.onap.appc.data.services.node.ConfigResourceNode.PREPARE_RELATIONSHIP_PARAM;
32 import static org.onap.appc.data.services.node.ConfigResourceNode.SDC_IND;
33 import static org.onap.appc.data.services.node.ConfigResourceNode.SITE_LOCATION_PARAM;
34 import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_FILE_TYPE;
35 import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_PREFIX;
36 import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_FILES_PREFIX;
37 import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_ID_PARAM;
38 import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_INFO_PREFIX;
39 import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_PREFIX;
40 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
41 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
42 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
43
44 public class ConfigResourceNodeTest {
45
46     private HashMap<String, String> inParams;
47     private SvcLogicContext contextMock;
48
49     @Rule
50     public ExpectedException expectedException = ExpectedException.none();
51
52     @Before
53     public void setUp() {
54         contextMock = mock(SvcLogicContext.class);
55         inParams = new HashMap<>();
56     }
57
58     /**
59      * Example data:
60      * <p>
61      * {"capabilities":{"vnfc":[],"vm":[{"ConfigureTest":["SSC","MMSC"]}],"vf-module":[],"vnf":["ConfigModify","HealthCheck"]}}
62      */
63     @Test
64     public void shouldProcessCapabilitiesForVMLevel() throws Exception {
65         SvcLogicContext ctx = new SvcLogicContext();
66         ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
67         String findCapability = "Restart";
68         JsonNodeFactory.instance.objectNode();
69         String subCaps = "[{\"Restart\":[\"SSC\",\"MMC\"]},{\"Rebuild\":[\"SSC\"]},{\"Migrate\":[\"SSC\"]},{\"Snapshot\":[\"SSC\"]},{\"Start\":[\"SSC\"]},{\"Stop\":[\"SSC\"]}]";
70         ObjectMapper m = new ObjectMapper();
71         JsonNode subCapabilities = m.readTree(subCaps);
72         String vServerId = "testServer";
73         ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code", "MMC");
74         ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-name", "testVnfc");
75         node.processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
76         String result = ctx.getAttribute("capabilities");
77         assertEquals(result, "Supported");
78     }
79
80     @Test
81     public void shouldCheckIfCapabilityCheckNeeded() {
82         ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
83         String findCapability = "Start";
84         String capLevel = "vnf";
85         boolean result = node.checkIfCapabilityCheckNeeded(capLevel, findCapability);
86         assertFalse(result);
87     }
88
89     @Test
90     public void should_add_attribute_with_success_if_get_config_file_succeed() throws SvcLogicException {
91         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
92
93         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
94         configResourceNode.getConfigFileReference(inParams, contextMock);
95
96         verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
97     }
98
99     @Test
100     public void should_add_attribute_with_success_if_get_config_info_succeed() throws SvcLogicException {
101         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
102
103         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
104         configResourceNode.getCommonConfigInfo(inParams, contextMock);
105
106         verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
107     }
108
109     @Test
110     public void should_add_attribute_with_success_if_get_template_succeed() throws SvcLogicException {
111         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
112
113         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
114         configResourceNode.getTemplate(inParams, contextMock);
115
116         verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
117     }
118
119     @Test
120     public void should_add_attribute_with_success_if_save_config_files_succeed() throws SvcLogicException {
121         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
122
123         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
124         configResourceNode.saveConfigFiles(inParams, contextMock);
125
126         verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
127     }
128
129     @Test
130     public void should_add_attribute_with_success_if_update_upload_config_succeed() throws SvcLogicException {
131         when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234");
132
133         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
134
135         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
136         configResourceNode.updateUploadConfig(inParams, contextMock);
137
138         verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
139     }
140
141     @Test
142     public void should_add_attribute_with_success_if_get_download_config_template_by_vnf_type_succeed() throws SvcLogicException {
143         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
144
145         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
146         configResourceNode.getDownloadConfigTemplateByVnf(inParams, contextMock);
147
148         verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
149     }
150
151     @Test
152     public void should_add_attribute_with_success_if_get_ssm_chain_succeed() throws SvcLogicException {
153         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
154
155         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
156         configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
157
158         verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
159     }
160
161     @Test
162     public void should_throw_exception_on_device_config_missing() throws Exception {
163         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
164             .getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
165             .build();
166
167         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
168
169         expectedException.expect(SvcLogicException.class);
170         expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
171         configResourceNode.getConfigFileReference(inParams, contextMock);
172     }
173
174     @Test
175     public void should_throw_exception_on_device_config_failure() throws Exception {
176         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
177             .getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
178             .build();
179
180         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
181
182         expectedException.expect(SvcLogicException.class);
183         expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
184         configResourceNode.getConfigFileReference(inParams, contextMock);
185     }
186
187     @Test
188     public void should_throw_exception_on_success_param_missing() throws Exception {
189
190         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
191             .getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
192             .build();
193
194         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
195
196         expectedException.expect(SvcLogicException.class);
197         expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
198         configResourceNode.getConfigFileReference(inParams, contextMock);
199     }
200
201     @Test
202     public void should_throw_exception_on_success_param_failure() throws Exception {
203         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
204             .getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
205             .build();
206
207         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
208
209         expectedException.expect(SvcLogicException.class);
210         expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
211         configResourceNode.getConfigFileReference(inParams, contextMock);
212     }
213
214     @Test
215     public void should_throw_exception_on_failure_param_missing() throws Exception {
216
217         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
218             .getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
219             .build();
220
221         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
222
223         expectedException.expect(SvcLogicException.class);
224         expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
225         configResourceNode.getConfigFileReference(inParams, contextMock);
226     }
227
228     @Test
229     public void should_throw_exception_on_failure_param_failure() throws Exception {
230         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
231             .getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
232             .build();
233
234         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
235
236         expectedException.expect(SvcLogicException.class);
237         expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
238         configResourceNode.getConfigFileReference(inParams, contextMock);
239     }
240
241     @Test
242     public void should_throw_exception_on_log_param_missing() throws Exception {
243
244         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
245             .getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
246             .build();
247
248         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
249
250         expectedException.expect(SvcLogicException.class);
251         expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
252         configResourceNode.getConfigFileReference(inParams, contextMock);
253     }
254
255     @Test
256     public void should_throw_exception_on_log_param_failure() throws Exception {
257         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
258             .getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
259             .build();
260
261         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
262
263         expectedException.expect(SvcLogicException.class);
264         expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
265         configResourceNode.getConfigFileReference(inParams, contextMock);
266     }
267
268     @Test
269     public void should_throw_exception_on_device_protocol_missing() throws SvcLogicException {
270         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
271             .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
272             .build();
273
274         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
275
276         expectedException.expect(SvcLogicException.class);
277         expectedException.expectMessage("Unable to Read device_interface_protocol");
278         configResourceNode.getCommonConfigInfo(inParams, contextMock);
279     }
280
281     @Test
282     public void should_throw_exception_on_device_protocol_failure() throws SvcLogicException {
283         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
284             .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
285             .build();
286
287         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
288
289         expectedException.expect(SvcLogicException.class);
290         expectedException.expectMessage("Unable to Read device_interface_protocol");
291         configResourceNode.getCommonConfigInfo(inParams, contextMock);
292     }
293
294     @Test
295     public void should_throw_exception_on_conf_action_by_vnf_action_failure() throws SvcLogicException {
296         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
297             .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
298             .build();
299
300         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
301
302         expectedException.expect(SvcLogicException.class);
303         expectedException.expectMessage("Unable to Read configure_action_dg");
304         configResourceNode.getCommonConfigInfo(inParams, contextMock);
305     }
306
307     @Test
308     public void should_throw_exception_on_conf_action_missing() throws SvcLogicException {
309         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
310             .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
311             .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
312             .build();
313
314         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
315
316         expectedException.expect(SvcLogicException.class);
317         expectedException.expectMessage("Unable to Read configure_action_dg");
318         configResourceNode.getCommonConfigInfo(inParams, contextMock);
319     }
320
321     @Test
322     public void should_throw_exception_on_conf_action_failure() throws SvcLogicException {
323         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
324             .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
325             .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
326             .build();
327
328         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
329
330         expectedException.expect(SvcLogicException.class);
331         expectedException.expectMessage("Unable to Read configure_action_dg");
332         configResourceNode.getCommonConfigInfo(inParams, contextMock);
333     }
334
335     @Test
336     public void should_throw_exception_on_db_template_failure() throws SvcLogicException {
337         inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
338         inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
339
340         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
341             .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE)
342             .build();
343
344         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
345
346         expectedException.expect(SvcLogicException.class);
347         expectedException.expectMessage("Unable to Read some file category");
348         configResourceNode.getTemplate(inParams, contextMock);
349     }
350
351     @Test
352     public void should_throw_exception_on_db_template_by_action_failure() throws SvcLogicException {
353         inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
354         inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
355
356         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
357             .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
358             .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE)
359             .build();
360
361         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
362
363         expectedException.expect(SvcLogicException.class);
364         expectedException.expectMessage("Unable to Read some file category");
365         configResourceNode.getTemplate(inParams, contextMock);
366     }
367
368     @Test
369     public void should_throw_exception_on_db_template_by_action_missing() throws SvcLogicException {
370         inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
371         inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
372
373         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
374             .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
375             .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
376             .build();
377
378         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
379
380         expectedException.expect(SvcLogicException.class);
381         expectedException.expectMessage("Unable to Read some file category");
382         configResourceNode.getTemplate(inParams, contextMock);
383     }
384
385     @Test
386     public void should_throw_exception_on_db_template_by_name_missing() throws SvcLogicException {
387         inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
388         inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
389
390         SvcLogicContext context = new SvcLogicContext();
391         context.setAttribute("template-name", "test template");
392
393         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
394             .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.NOT_FOUND)
395             .build();
396
397         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
398
399         expectedException.expect(SvcLogicException.class);
400         expectedException.expectMessage("Unable to Read some file category template");
401         configResourceNode.getTemplate(inParams, context);
402     }
403
404     @Test
405     public void should_throw_exception_on_db_template_by_name_failure() throws SvcLogicException {
406         inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
407         inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
408
409         SvcLogicContext context = new SvcLogicContext();
410         context.setAttribute("template-name", "test template");
411
412         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
413             .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.FAILURE)
414             .build();
415
416         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
417
418         expectedException.expect(SvcLogicException.class);
419         expectedException.expectMessage("Unable to Read some file category template");
420         configResourceNode.getTemplate(inParams, context);
421     }
422
423     @Test
424     public void should_throw_exception_on_save_config_failure() throws SvcLogicException {
425         SvcLogicContext context = new SvcLogicContext();
426         context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
427
428         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
429             .saveConfigFiles(CONFIG_FILES_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
430             .build();
431
432         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
433
434         expectedException.expect(SvcLogicException.class);
435         expectedException.expectMessage("Unable to Save some file category in configfiles");
436         configResourceNode.saveConfigFiles(inParams, context);
437     }
438
439     @Test
440     public void should_throw_exception_on_get_max_config_id_missing() throws SvcLogicException {
441         SvcLogicContext context = new SvcLogicContext();
442         context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
443
444         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
445             .getMaxConfigFileId(MAX_CONF_FILE_PREFIX, "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
446             .build();
447
448         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
449
450         expectedException.expect(SvcLogicException.class);
451         expectedException.expectMessage("Unable to get some file category from configfiles");
452
453         configResourceNode.saveConfigFiles(inParams, context);
454     }
455
456     @Test
457     public void should_throw_exception_on_save_config_files_failure() throws SvcLogicException {
458         SvcLogicContext context = new SvcLogicContext();
459         context.setAttribute(CONFIG_FILE_ID_PARAM, "some file id");
460
461         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
462             .savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND, SvcLogicResource.QueryStatus.FAILURE)
463             .build();
464
465         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
466
467         expectedException.expect(SvcLogicException.class);
468         expectedException.expectMessage("Unable to save prepare_relationship");
469         configResourceNode.saveConfigFiles(inParams, context);
470     }
471
472     @Test
473     public void should_throw_exception_on_save_upload_config_failure() throws SvcLogicException {
474         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
475             .saveUploadConfig(UPLOAD_CONFIG_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
476             .build();
477
478         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
479
480         expectedException.expect(SvcLogicException.class);
481         expectedException.expectMessage("Unable to Save configuration in upload_config");
482         configResourceNode.updateUploadConfig(inParams, contextMock);
483     }
484
485     @Test
486     public void should_throw_exception_on_get_upload_config_failure() throws SvcLogicException {
487         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
488             .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
489             .build();
490
491         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
492
493         expectedException.expect(SvcLogicException.class);
494         expectedException.expectMessage("Unable to get record from upload_config");
495         configResourceNode.updateUploadConfig(inParams, contextMock);
496     }
497
498     @Test
499     public void should_throw_exception_on_get_upload_config_missing() throws SvcLogicException {
500         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
501             .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
502             .build();
503
504         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
505
506         expectedException.expect(SvcLogicException.class);
507         expectedException.expectMessage("Unable to get record from upload_config");
508         configResourceNode.updateUploadConfig(inParams, contextMock);
509     }
510
511     @Test
512     public void should_throw_exception_on_update_upload_config_failure() throws SvcLogicException {
513         when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234");
514
515         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
516             .updateUploadConfig(UPLOAD_CONFIG_PREFIX, 1234, SvcLogicResource.QueryStatus.FAILURE)
517             .build();
518
519         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
520
521         expectedException.expect(SvcLogicException.class);
522         expectedException.expectMessage("Unable to upload upload_config");
523         configResourceNode.updateUploadConfig(inParams, contextMock);
524     }
525
526     @Test
527     public void should_throw_exception_on_get_download_config_failure() throws SvcLogicException {
528         inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
529
530         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
531             .getDownloadConfigTemplateByVnf("some prefix", SvcLogicResource.QueryStatus.FAILURE)
532             .build();
533
534         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
535
536         expectedException.expect(SvcLogicException.class);
537         expectedException.expectMessage("Unable to get download config template.");
538         configResourceNode.getDownloadConfigTemplateByVnf(inParams, contextMock);
539     }
540
541     @Test
542     public void should_throw_exception_on_get_ssm_chain_failure() throws SvcLogicException {
543         when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
544
545         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
546             .getTemplateByArtifactType("smm", "smm", "some location", SvcLogicResource.QueryStatus.FAILURE)
547             .build();
548
549         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
550
551         expectedException.expect(SvcLogicException.class);
552         expectedException.expectMessage("Unable to Read smm file");
553         configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
554     }
555
556     @Test
557     public void should_throw_exception_on_get_ca_chain_failure() throws SvcLogicException {
558         when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
559
560         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
561             .getTemplateByArtifactType("intermediate-ca-chain", "intermediate_ca_chain", "some location", SvcLogicResource.QueryStatus.FAILURE)
562             .build();
563
564         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
565
566         expectedException.expect(SvcLogicException.class);
567         expectedException.expectMessage("Unable to Read intermediate_ca_chain file");
568         configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
569     }
570
571     @Test
572     public void should_throw_exception_on_get_server_certificate_and_key_failure() throws SvcLogicException {
573         when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
574
575         DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
576             .getTemplateByArtifactType("server-certificate-and-key", "server_certificate_and_key", "some location", SvcLogicResource.QueryStatus.FAILURE)
577             .build();
578
579         ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
580
581         expectedException.expect(SvcLogicException.class);
582         expectedException.expectMessage("Unable to Read server_certificate_and_key file");
583         configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
584     }
585
586 }