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.Mockito.mock;
14 import org.onap.appc.data.services.db.DGGeneralDBService;
15 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_FILE_TYPE;
16 import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_PREFIX;
17 import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_FILE_TYPE;
18 import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_PREFIX;
19 import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_FILE_TYPE;
20 import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_PREFIX;
21 import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_FILE_TYPE;
22 import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_PREFIX;
23 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
24 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
27 public class ConfigResourceNodeTest {
29 private HashMap<String, String> inParams;
30 private SvcLogicContext contextMock;
33 public ExpectedException expectedException = ExpectedException.none();
37 contextMock = mock(SvcLogicContext.class);
38 inParams = new HashMap<>();
44 * {"capabilities":{"vnfc":[],"vm":[{"ConfigureTest":["SSC","MMSC"]}],"vf-module":[],"vnf":["ConfigModify","HealthCheck"]}}
48 public void shouldProcessCapabilitiesForVMLevel() throws Exception {
49 SvcLogicContext ctx = new SvcLogicContext();
50 ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
51 String findCapability = "Restart";
52 JsonNodeFactory.instance.objectNode();
53 String subCaps = "[{\"Restart\":[\"SSC\",\"MMC\"]},{\"Rebuild\":[\"SSC\"]},{\"Migrate\":[\"SSC\"]},{\"Snapshot\":[\"SSC\"]},{\"Start\":[\"SSC\"]},{\"Stop\":[\"SSC\"]}]";
54 ObjectMapper m = new ObjectMapper();
55 JsonNode subCapabilities = m.readTree(subCaps);
56 String vServerId = "testServer";
57 ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code", "MMC");
58 ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-name", "testVnfc");
59 node.processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
60 String result = ctx.getAttribute("capabilities");
61 assertEquals(result, "Supported");
65 public void shouldCheckIfCapabilityCheckNeeded() {
66 ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
67 String findCapability = "Start";
68 String capLevel = "vnf";
69 boolean result = node.checkIfCapabilityCheckNeeded(capLevel, findCapability);
74 public void should_not_throw_if_all_db_params_return_success() throws SvcLogicException {
75 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
77 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
78 configResourceNode.getConfigFileReference(inParams, contextMock);
82 public void should_throw_exception_on_device_config_missing() throws Exception {
83 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
84 .configFileReference(DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
87 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
89 expectedException.expect(SvcLogicException.class);
90 expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
91 configResourceNode.getConfigFileReference(inParams, contextMock);
95 public void should_throw_exception_on_device_config_failure() throws Exception {
96 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
97 .configFileReference(DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
100 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
102 expectedException.expect(SvcLogicException.class);
103 expectedException.expectMessage("Unable to Read ConfigFileReference:device-configuration");
104 configResourceNode.getConfigFileReference(inParams, contextMock);
108 public void should_throw_exception_on_success_param_missing() throws Exception {
110 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
111 .configFileReference(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
114 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
116 expectedException.expect(SvcLogicException.class);
117 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
118 configResourceNode.getConfigFileReference(inParams, contextMock);
122 public void should_throw_exception_on_success_param_failure() throws Exception {
123 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
124 .configFileReference(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
127 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
129 expectedException.expect(SvcLogicException.class);
130 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_success");
131 configResourceNode.getConfigFileReference(inParams, contextMock);
135 public void should_throw_exception_on_failure_param_missing() throws Exception {
137 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
138 .configFileReference(FAILURE_PREFIX, FAILURE_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_error");
145 configResourceNode.getConfigFileReference(inParams, contextMock);
149 public void should_throw_exception_on_failure_param_failure() throws Exception {
150 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
151 .configFileReference(FAILURE_PREFIX, FAILURE_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
154 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
156 expectedException.expect(SvcLogicException.class);
157 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_error");
158 configResourceNode.getConfigFileReference(inParams, contextMock);
162 public void should_throw_exception_on_log_param_missing() throws Exception {
164 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
165 .configFileReference(LOG_PREFIX, LOG_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_log");
172 configResourceNode.getConfigFileReference(inParams, contextMock);
176 public void should_throw_exception_on_log_param_failure() throws Exception {
177 DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
178 .configFileReference(LOG_PREFIX, LOG_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
181 ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
183 expectedException.expect(SvcLogicException.class);
184 expectedException.expectMessage("Unable to Read ConfigFileReference:configuration_log");
185 configResourceNode.getConfigFileReference(inParams, contextMock);