summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java31
-rw-r--r--appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java65
-rw-r--r--appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java24
3 files changed, 109 insertions, 11 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 b60e6a81a..40a8f5ecf 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
@@ -57,6 +57,15 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
static final String DEVICE_PROTOCOL_PREFIX = "tmp.deviceinterfaceprotocol";
static final String CONF_ACTION_PREFIX = "tmp.configureactiondg";
+ static final String CONFIG_FILES_PREFIX = "tmp.configFiles";
+ static final String MAX_CONF_FILE_PREFIX = "tmp.configfilesmax";
+
+ static final String PREPARE_RELATIONSHIP_PARAM = "tmp.preparerel";
+ static final String CONFIG_FILE_ID_PARAM = "tmp.configfilesmax.configfileid";
+ static final String FILE_CATEGORY_PARAM = "file-category";
+
+ static final String SDC_IND = "N";
+
private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
private final DGGeneralDBService db;
@@ -224,18 +233,18 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
try {
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- QueryStatus status = db.saveConfigFiles(ctx, "tmp.configFiles");
+ QueryStatus status = db.saveConfigFiles(ctx, CONFIG_FILES_PREFIX);
if (status == QueryStatus.FAILURE)
- throw new Exception("Unable to Save " + ctx.getAttribute("file-category") + " in configfiles");
+ throw new Exception("Unable to Save " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " in configfiles");
- status = db.getMaxConfigFileId(ctx, "tmp.configfilesmax", ctx.getAttribute("file-category"));
+ status = db.getMaxConfigFileId(ctx, MAX_CONF_FILE_PREFIX, ctx.getAttribute(FILE_CATEGORY_PARAM));
if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
- throw new Exception("Unable to get " + ctx.getAttribute("file-category") + " from configfiles");
+ throw new Exception("Unable to get " + ctx.getAttribute(FILE_CATEGORY_PARAM) + " from configfiles");
- status = db.savePrepareRelationship(ctx, "tmp.preparerel",
- ctx.getAttribute("tmp.configfilesmax.configfileid"), "N");
+ status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
+ ctx.getAttribute(CONFIG_FILE_ID_PARAM), SDC_IND);
if (status == QueryStatus.FAILURE)
throw new Exception("Unable to save prepare_relationship");
@@ -304,7 +313,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
- QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel", fileId, sdcArtifactInd);
+ QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM, fileId, sdcArtifactInd);
if (status == QueryStatus.FAILURE)
throw new Exception("Unable to save prepare_relationship");
@@ -385,7 +394,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
}
- QueryStatus status = db.savePrepareRelationship(ctx, "tmp.preparerel",
+ QueryStatus status = db.savePrepareRelationship(ctx, PREPARE_RELATIONSHIP_PARAM,
ctx.getAttribute("config-template.config-file-id"), "Y");
if (status == QueryStatus.FAILURE)
throw new Exception("Unable to save prepare_relationship");
@@ -476,7 +485,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
String fileContent, String deviceConfig) throws SvcLogicException {
ctx.setAttribute("data-source", dataSource);
ctx.setAttribute("file-content", fileContent);
- ctx.setAttribute("file-category", "device_configuration");
+ ctx.setAttribute(FILE_CATEGORY_PARAM, "device_configuration");
ctx.setAttribute("deviceconfig-file-content", deviceConfig);
saveConfigFiles(inParams, ctx);
@@ -485,14 +494,14 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
public void saveConfigurationBlock(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
ctx.setAttribute("data-source", "Request");
ctx.setAttribute("file-content", ctx.getAttribute("tmp.convertconfig.escapeData"));
- ctx.setAttribute("file-category", "configuration_block");
+ ctx.setAttribute(FILE_CATEGORY_PARAM, "configuration_block");
saveConfigFiles(inParams, ctx);
}
public void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
ctx.setAttribute("data-source", ctx.getAttribute("originator-id"));
ctx.setAttribute("file-content", ctx.getAttribute("configuration-params"));
- ctx.setAttribute("file-category", "config_data");
+ ctx.setAttribute(FILE_CATEGORY_PARAM, "config_data");
saveConfigFiles(inParams, ctx);
}
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 b7a9b90db..694ee0caf 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
@@ -16,16 +16,22 @@ 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.CONFIG_FILE_ID_PARAM;
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.FILE_CATEGORY_PARAM;
import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_FILE_TYPE;
import static org.onap.appc.data.services.node.ConfigResourceNode.LOG_PREFIX;
+import static org.onap.appc.data.services.node.ConfigResourceNode.MAX_CONF_FILE_PREFIX;
+import static org.onap.appc.data.services.node.ConfigResourceNode.PREPARE_RELATIONSHIP_PARAM;
+import static org.onap.appc.data.services.node.ConfigResourceNode.SDC_IND;
import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_FILE_TYPE;
import static org.onap.appc.data.services.node.ConfigResourceNode.SUCCESS_PREFIX;
+import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_FILES_PREFIX;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
@@ -106,6 +112,16 @@ public class ConfigResourceNodeTest {
}
@Test
+ public void should_add_attribute_with_success_if_save_config_files_succeed() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ configResourceNode.saveConfigFiles(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()
.getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND)
@@ -367,4 +383,53 @@ public class ConfigResourceNodeTest {
configResourceNode.getTemplate(inParams, context);
}
+ @Test
+ public void should_throw_exception_on_save_config_failure() throws SvcLogicException {
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .saveConfigFiles(CONFIG_FILES_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Save some file category in configfiles");
+ configResourceNode.saveConfigFiles(inParams, context);
+ }
+
+ @Test
+ public void should_throw_exception_on_get_max_config_id_missing() throws SvcLogicException {
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getMaxConfigFileId(MAX_CONF_FILE_PREFIX, "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to get some file category from configfiles");
+
+ configResourceNode.saveConfigFiles(inParams, context);
+ }
+
+ @Test
+ public void should_throw_exception_on_save_config_files_failure() throws SvcLogicException {
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute(CONFIG_FILE_ID_PARAM, "some file id");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND, SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to save prepare_relationship");
+ configResourceNode.saveConfigFiles(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 d71212cb5..e7198b26d 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
@@ -78,6 +78,30 @@ class MockDbServiceBuilder {
return this;
}
+ public MockDbServiceBuilder saveConfigFiles(String prefix, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .saveConfigFiles(any(SvcLogicContext.class), eq(prefix));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder getMaxConfigFileId(String prefix, String fileCategory, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getMaxConfigFileId(any(SvcLogicContext.class), eq(prefix), eq(fileCategory));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder savePrepareRelationship(String prefix, String field, String sdnc, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .savePrepareRelationship(any(SvcLogicContext.class), eq(prefix), eq(field), eq(sdnc));
+
+ return this;
+ }
+
DGGeneralDBService build() {
return dbServiceMock;
}