1 package org.onap.appc.data.services.node;
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 org.onap.appc.data.services.AppcDataServiceConstant;
18 import org.onap.appc.data.services.db.DGGeneralDBService;
19 import static org.onap.appc.data.services.node.ConfigResourceNode.CONF_ACTION_PREFIX;
20 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_FILE_TYPE;
21 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_PREFIX;
22 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_PROTOCOL_PREFIX;
23 import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_FILE_TYPE;
24 import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_PREFIX;
25 import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_FILE_TYPE;
26 import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_PREFIX;
27 import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_FILE_TYPE;
28 import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_PREFIX;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
33 public class ConfigResourceNodeTest {
35 private HashMap<String, String> inParams;
36 private SvcLogicContext contextMock;
39 public ExpectedException expectedException = ExpectedException.none();
43 contextMock = mock(SvcLogicContext.class);
44 inParams = new HashMap<>();
50 * {"capabilities":{"vnfc":[],"vm":[{"ConfigureTest":["SSC","MMSC"]}],"vf-module":[],"vnf":["ConfigModify","HealthCheck"]}}
53 public void shouldProcessCapabilitiesForVMLevel() throws Exception {
54 SvcLogicContext ctx = new SvcLogicContext();
55 ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
56 String findCapability = "Restart";
57 JsonNodeFactory.instance.objectNode();
58 String subCaps = "[{\"Restart\":[\"SSC\",\"MMC\"]},{\"Rebuild\":[\"SSC\"]},{\"Migrate\":[\"SSC\"]},{\"Snapshot\":[\"SSC\"]},{\"Start\":[\"SSC\"]},{\"Stop\":[\"SSC\"]}]";
59 ObjectMapper m = new ObjectMapper();
60 JsonNode subCapabilities = m.readTree(subCaps);
61 String vServerId = "testServer";
62 ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code", "MMC");
63 ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-name", "testVnfc");
64 node.processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
65 String result = ctx.getAttribute("capabilities");
66 assertEquals(result, "Supported");
70 public void shouldCheckIfCapabilityCheckNeeded() {
71 ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
72 String findCapability = "Start";
73 String capLevel = "vnf";
74 boolean result = node.checkIfCapabilityCheckNeeded(capLevel, findCapability);
79 public void should_add_attribute_with_success_if_get_config_file_succeed() throws SvcLogicException {
80 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
82 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
83 configResourceNode.getConfigFileReference(inParams, contextMock);
85 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
89 public void should_add_attribute_with_success_if_get_config_info_succeed() throws SvcLogicException {
90 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
92 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
93 configResourceNode.getCommonConfigInfo(inParams, contextMock);
95 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
99 public void should_add_attribute_with_success_if_get_template_succeed() throws SvcLogicException {
100 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
102 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
103 configResourceNode.getTemplate(inParams, contextMock);
105 verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
109 public void should_throw_exception_on_device_config_missing() throws Exception {
110 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
111 .getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
114 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
116 expectedException.expect(SvcLogicException.class);
117 expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
118 configResourceNode.getConfigFileReference(inParams, contextMock);
122 public void should_throw_exception_on_device_config_failure() throws Exception {
123 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
124 .getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
127 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
129 expectedException.expect(SvcLogicException.class);
130 expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
131 configResourceNode.getConfigFileReference(inParams, contextMock);
135 public void should_throw_exception_on_success_param_missing() throws Exception {
137 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
138 .getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
141 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
143 expectedException.expect(SvcLogicException.class);
144 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
145 configResourceNode.getConfigFileReference(inParams, contextMock);
149 public void should_throw_exception_on_success_param_failure() throws Exception {
150 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
151 .getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
154 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
156 expectedException.expect(SvcLogicException.class);
157 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
158 configResourceNode.getConfigFileReference(inParams, contextMock);
162 public void should_throw_exception_on_failure_param_missing() throws Exception {
164 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
165 .getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
168 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
170 expectedException.expect(SvcLogicException.class);
171 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
172 configResourceNode.getConfigFileReference(inParams, contextMock);
176 public void should_throw_exception_on_failure_param_failure() throws Exception {
177 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
178 .getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
181 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
183 expectedException.expect(SvcLogicException.class);
184 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
185 configResourceNode.getConfigFileReference(inParams, contextMock);
189 public void should_throw_exception_on_log_param_missing() throws Exception {
191 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
192 .getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
195 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
197 expectedException.expect(SvcLogicException.class);
198 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
199 configResourceNode.getConfigFileReference(inParams, contextMock);
203 public void should_throw_exception_on_log_param_failure() throws Exception {
204 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
205 .getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
208 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
210 expectedException.expect(SvcLogicException.class);
211 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
212 configResourceNode.getConfigFileReference(inParams, contextMock);
216 public void should_throw_exception_on_device_protocol_missing() throws SvcLogicException {
217 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
218 .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
221 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
223 expectedException.expect(SvcLogicException.class);
224 expectedException.expectMessage("Unable to Read device_interface_protocol");
225 configResourceNode.getCommonConfigInfo(inParams, contextMock);
229 public void should_throw_exception_on_device_protocol_failure() throws SvcLogicException {
230 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
231 .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
234 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
236 expectedException.expect(SvcLogicException.class);
237 expectedException.expectMessage("Unable to Read device_interface_protocol");
238 configResourceNode.getCommonConfigInfo(inParams, contextMock);
242 public void should_throw_exception_on_conf_action_by_vnf_action_failure() throws SvcLogicException {
243 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
244 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
247 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
249 expectedException.expect(SvcLogicException.class);
250 expectedException.expectMessage("Unable to Read configure_action_dg");
251 configResourceNode.getCommonConfigInfo(inParams, contextMock);
255 public void should_throw_exception_on_conf_action_missing() throws SvcLogicException {
256 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
257 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
258 .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
261 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
263 expectedException.expect(SvcLogicException.class);
264 expectedException.expectMessage("Unable to Read configure_action_dg");
265 configResourceNode.getCommonConfigInfo(inParams, contextMock);
269 public void should_throw_exception_on_conf_action_failure() throws SvcLogicException {
270 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
271 .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
272 .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
275 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
277 expectedException.expect(SvcLogicException.class);
278 expectedException.expectMessage("Unable to Read configure_action_dg");
279 configResourceNode.getCommonConfigInfo(inParams, contextMock);
283 public void should_throw_exception_on_db_template_failure() throws SvcLogicException {
284 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
285 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
287 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
288 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE)
291 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
293 expectedException.expect(SvcLogicException.class);
294 expectedException.expectMessage("Unable to Read some file category");
295 configResourceNode.getTemplate(inParams, contextMock);
299 public void should_throw_exception_on_db_template_by_action_failure() throws SvcLogicException {
300 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
301 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
303 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
304 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
305 .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE)
308 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
310 expectedException.expect(SvcLogicException.class);
311 expectedException.expectMessage("Unable to Read some file category");
312 configResourceNode.getTemplate(inParams, contextMock);
316 public void should_throw_exception_on_db_template_by_action_missing() throws SvcLogicException {
317 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
318 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
320 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
321 .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
322 .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
325 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
327 expectedException.expect(SvcLogicException.class);
328 expectedException.expectMessage("Unable to Read some file category");
329 configResourceNode.getTemplate(inParams, contextMock);
333 public void should_throw_exception_on_db_template_by_name_missing() throws SvcLogicException {
334 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
335 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
337 SvcLogicContext context = new SvcLogicContext();
338 context.setAttribute("template-name", "test template");
340 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
341 .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.NOT_FOUND)
344 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
346 expectedException.expect(SvcLogicException.class);
347 expectedException.expectMessage("Unable to Read some file category template");
348 configResourceNode.getTemplate(inParams, context);
352 public void should_throw_exception_on_db_template_by_name_failure() throws SvcLogicException {
353 inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
354 inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
356 SvcLogicContext context = new SvcLogicContext();
357 context.setAttribute("template-name", "test template");
359 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
360 .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.FAILURE)
363 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
365 expectedException.expect(SvcLogicException.class);
366 expectedException.expectMessage("Unable to Read some file category template");
367 configResourceNode.getTemplate(inParams, context);