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;
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");
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");
}
- 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");
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);
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);
}
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;
verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
}
+ @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()
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
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;
}