summaryrefslogtreecommitdiffstats
path: root/appc-config
diff options
context:
space:
mode:
Diffstat (limited to 'appc-config')
-rw-r--r--appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java14
-rw-r--r--appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java204
-rw-r--r--appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java50
3 files changed, 251 insertions, 17 deletions
diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java
index 8b9b8ddfa..b60e6a81a 100644
--- a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java
+++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java
@@ -54,6 +54,9 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
static final String LOG_PREFIX = "configfilereference-log";
static final String LOG_FILE_TYPE = "log";
+ static final String DEVICE_PROTOCOL_PREFIX = "tmp.deviceinterfaceprotocol";
+ static final String CONF_ACTION_PREFIX = "tmp.configureactiondg";
+
private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
private final DGGeneralDBService db;
@@ -118,17 +121,17 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
try {
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- QueryStatus status = db.getDeviceProtocolByVnfType(ctx, "tmp.deviceinterfaceprotocol");
+ QueryStatus status = db.getDeviceProtocolByVnfType(ctx, DEVICE_PROTOCOL_PREFIX);
if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
throw new Exception("Unable to Read device_interface_protocol");
- status = db.getConfigureActionDGByVnfTypeNAction(ctx, "tmp.configureactiondg");
+ status = db.getConfigureActionDGByVnfTypeNAction(ctx, CONF_ACTION_PREFIX);
if (status == QueryStatus.FAILURE)
throw new Exception("Unable to Read configure_action_dg");
if (status == QueryStatus.NOT_FOUND) {
- status = db.getConfigureActionDGByVnfType(ctx, "tmp.configureactiondg");
+ status = db.getConfigureActionDGByVnfType(ctx, CONF_ACTION_PREFIX);
if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
throw new Exception("Unable to Read configure_action_dg");
@@ -147,8 +150,9 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
}
}
-
- // fileCategory Can be config_template, parameter_definitions, parameter_yang
+ /**
+ * FileCategory can be config_template, parameter_definitions, parameter_yang
+ */
public void getTemplate(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
log.info("Received getTemplate call with params : " + inParams);
diff --git a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java
index 6ee7a9da7..b7a9b90db 100644
--- a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java
+++ b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java
@@ -10,10 +10,16 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import org.onap.appc.data.services.AppcDataServiceConstant;
import org.onap.appc.data.services.db.DGGeneralDBService;
+import static org.onap.appc.data.services.node.ConfigResourceNode.CONF_ACTION_PREFIX;
import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_FILE_TYPE;
import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_CONF_PREFIX;
+import static org.onap.appc.data.services.node.ConfigResourceNode.DEVICE_PROTOCOL_PREFIX;
import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_FILE_TYPE;
import static org.onap.appc.data.services.node.ConfigResourceNode.FAILURE_PREFIX;
import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_FILE_TYPE;
@@ -40,9 +46,8 @@ public class ConfigResourceNodeTest {
/**
* Example data:
- *
+ * <p>
* {"capabilities":{"vnfc":[],"vm":[{"ConfigureTest":["SSC","MMSC"]}],"vf-module":[],"vnf":["ConfigModify","HealthCheck"]}}
- *
*/
@Test
public void shouldProcessCapabilitiesForVMLevel() throws Exception {
@@ -71,17 +76,39 @@ public class ConfigResourceNodeTest {
}
@Test
- public void should_not_throw_if_all_db_params_return_success() throws SvcLogicException {
+ public void should_add_attribute_with_success_if_get_config_file_succeed() throws SvcLogicException {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
configResourceNode.getConfigFileReference(inParams, contextMock);
+
+ verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
+ }
+
+ @Test
+ public void should_add_attribute_with_success_if_get_config_info_succeed() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ configResourceNode.getCommonConfigInfo(inParams, contextMock);
+
+ verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
+ }
+
+ @Test
+ public void should_add_attribute_with_success_if_get_template_succeed() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ configResourceNode.getTemplate(inParams, contextMock);
+
+ verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
}
@Test
public void should_throw_exception_on_device_config_missing() throws Exception {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .configFileReference(DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
+ .getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
.build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -94,7 +121,7 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_device_config_failure() throws Exception {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .configFileReference(DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
+ .getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
.build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -108,7 +135,7 @@ public class ConfigResourceNodeTest {
public void should_throw_exception_on_success_param_missing() throws Exception {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .configFileReference(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
+ .getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
.build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -121,7 +148,7 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_success_param_failure() throws Exception {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .configFileReference(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
+ .getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
.build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -135,7 +162,7 @@ public class ConfigResourceNodeTest {
public void should_throw_exception_on_failure_param_missing() throws Exception {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .configFileReference(FAILURE_PREFIX, FAILURE_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
+ .getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
.build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -148,7 +175,7 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_failure_param_failure() throws Exception {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .configFileReference(FAILURE_PREFIX, FAILURE_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
+ .getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
.build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -162,7 +189,7 @@ public class ConfigResourceNodeTest {
public void should_throw_exception_on_log_param_missing() throws Exception {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .configFileReference(LOG_PREFIX, LOG_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
+ .getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
.build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -175,7 +202,7 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_log_param_failure() throws Exception {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .configFileReference(LOG_PREFIX, LOG_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
+ .getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE)
.build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -185,4 +212,159 @@ public class ConfigResourceNodeTest {
configResourceNode.getConfigFileReference(inParams, contextMock);
}
+ @Test
+ public void should_throw_exception_on_device_protocol_missing() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read device_interface_protocol");
+ configResourceNode.getCommonConfigInfo(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_device_protocol_failure() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read device_interface_protocol");
+ configResourceNode.getCommonConfigInfo(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_conf_action_by_vnf_action_failure() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read configure_action_dg");
+ configResourceNode.getCommonConfigInfo(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_conf_action_missing() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
+ .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read configure_action_dg");
+ configResourceNode.getCommonConfigInfo(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_conf_action_failure() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
+ .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read configure_action_dg");
+ configResourceNode.getCommonConfigInfo(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_db_template_failure() throws SvcLogicException {
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read some file category");
+ configResourceNode.getTemplate(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_db_template_by_action_failure() throws SvcLogicException {
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
+ .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read some file category");
+ configResourceNode.getTemplate(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_db_template_by_action_missing() throws SvcLogicException {
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
+ .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read some file category");
+ configResourceNode.getTemplate(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_db_template_by_name_missing() throws SvcLogicException {
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
+
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute("template-name", "test template");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.NOT_FOUND)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read some file category template");
+ configResourceNode.getTemplate(inParams, context);
+ }
+
+ @Test
+ public void should_throw_exception_on_db_template_by_name_failure() throws SvcLogicException {
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
+
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute("template-name", "test template");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read some file category template");
+ configResourceNode.getTemplate(inParams, context);
+ }
+
} \ No newline at end of file
diff --git a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java
index 04379e5dc..d71212cb5 100644
--- a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java
+++ b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java
@@ -22,7 +22,7 @@ class MockDbServiceBuilder {
.getConfigFileReferenceByFileTypeNVnfType(any(SvcLogicContext.class), anyString(), anyString());
}
- MockDbServiceBuilder configFileReference(String prefix, String fileType, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ MockDbServiceBuilder getConfigFileReferenceByFileTypeNVnfType(String prefix, String fileType, SvcLogicResource.QueryStatus status) throws SvcLogicException {
doReturn(status)
.when(dbServiceMock)
.getConfigFileReferenceByFileTypeNVnfType(any(SvcLogicContext.class), eq(prefix), eq(fileType));
@@ -30,6 +30,54 @@ class MockDbServiceBuilder {
return this;
}
+ public MockDbServiceBuilder getDeviceProtocolByVnfType(String prefix, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getDeviceProtocolByVnfType(any(SvcLogicContext.class), eq(prefix));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder getConfigureActionDGByVnfTypeNAction(String prefix, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getConfigureActionDGByVnfTypeNAction(any(SvcLogicContext.class), eq(prefix));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder getConfigureActionDGByVnfType(String prefix, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getConfigureActionDGByVnfType(any(SvcLogicContext.class), eq(prefix));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder getTemplate(String prefix, String fileCategory, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getTemplate(any(SvcLogicContext.class), eq(prefix), eq(fileCategory));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder getTemplateByVnfTypeNAction(String prefix, String fileCategory, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getTemplateByVnfTypeNAction(any(SvcLogicContext.class), eq(prefix), eq(fileCategory));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder getTemplateByTemplateName(String prefix, String fileCategory, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getTemplateByTemplateName(any(SvcLogicContext.class), eq(prefix), eq(fileCategory));
+
+ return this;
+ }
+
DGGeneralDBService build() {
return dbServiceMock;
}