aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-data-services/provider
diff options
context:
space:
mode:
Diffstat (limited to 'appc-config/appc-data-services/provider')
-rw-r--r--appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java13
-rw-r--r--appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java72
-rw-r--r--appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java29
3 files changed, 103 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 40a8f5ecf..887f561cf 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
@@ -59,10 +59,13 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
static final String CONFIG_FILES_PREFIX = "tmp.configFiles";
static final String MAX_CONF_FILE_PREFIX = "tmp.configfilesmax";
+ static final String UPLOAD_CONFIG_PREFIX = "tmp.uploadConfig";
+ static final String UPLOAD_CONFIG_INFO_PREFIX = "tmp.uploadConfigInfo";
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 UPLOAD_CONFIG_ID_PARAM = "tmp.uploadConfigInfo.UPLOAD-CONFIG-ID";
static final String SDC_IND = "N";
@@ -274,18 +277,18 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
ctx.setAttribute("tmp.escaped.devicerunningconfig",
EscapeUtils.escapeSql(ctx.getAttribute("device-running-config")));
- QueryStatus status = db.saveUploadConfig(ctx, "tmp.uploadConfig");
+ QueryStatus status = db.saveUploadConfig(ctx, UPLOAD_CONFIG_PREFIX);
if (status == QueryStatus.FAILURE)
throw new Exception("Unable to Save configuration in upload_config");
- status = db.getUploadConfigInfo(ctx, "tmp.uploadConfigInfo");
+ status = db.getUploadConfigInfo(ctx, UPLOAD_CONFIG_INFO_PREFIX);
if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE)
throw new Exception("Unable to get record from upload_config");
- status = db.updateUploadConfig(ctx, "tmp.uploadConfig",
- Integer.parseInt(ctx.getAttribute("tmp.uploadConfigInfo.UPLOAD-CONFIG-ID")));
+ status = db.updateUploadConfig(ctx, UPLOAD_CONFIG_PREFIX,
+ Integer.parseInt(ctx.getAttribute(UPLOAD_CONFIG_ID_PARAM)));
if (status == QueryStatus.FAILURE)
throw new Exception("Unable to upload upload_config");
@@ -482,7 +485,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
}
public void saveDeviceConfiguration(Map<String, String> inParams, SvcLogicContext ctx, String dataSource,
- String fileContent, String deviceConfig) throws SvcLogicException {
+ String fileContent, String deviceConfig) throws SvcLogicException {
ctx.setAttribute("data-source", dataSource);
ctx.setAttribute("file-content", fileContent);
ctx.setAttribute(FILE_CATEGORY_PARAM, "device_configuration");
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 694ee0caf..6ecc1ed40 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
@@ -14,6 +14,7 @@ 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 static org.mockito.Mockito.when;
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;
@@ -32,6 +33,9 @@ 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 static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_ID_PARAM;
+import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_INFO_PREFIX;
+import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_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;
@@ -122,6 +126,18 @@ public class ConfigResourceNodeTest {
}
@Test
+ public void should_add_attribute_with_success_if_update_upload_config_succeed() throws SvcLogicException {
+ when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ configResourceNode.updateUploadConfig(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)
@@ -344,7 +360,7 @@ public class ConfigResourceNodeTest {
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");
@@ -432,4 +448,58 @@ public class ConfigResourceNodeTest {
configResourceNode.saveConfigFiles(inParams, context);
}
+ @Test
+ public void should_throw_exception_on_save_upload_config_failure() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .saveUploadConfig(UPLOAD_CONFIG_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Save configuration in upload_config");
+ configResourceNode.updateUploadConfig(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_get_upload_config_failure() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to get record from upload_config");
+ configResourceNode.updateUploadConfig(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_get_upload_config_missing() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to get record from upload_config");
+ configResourceNode.updateUploadConfig(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_update_upload_config_failure() throws SvcLogicException {
+ when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .updateUploadConfig(UPLOAD_CONFIG_PREFIX, 1234, SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to upload upload_config");
+ configResourceNode.updateUploadConfig(inParams, contextMock);
+ }
+
} \ 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 e7198b26d..40bf69733 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
@@ -1,7 +1,6 @@
package org.onap.appc.data.services.node;
import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -16,10 +15,6 @@ class MockDbServiceBuilder {
MockDbServiceBuilder() throws SvcLogicException {
dbServiceMock = mock(DGGeneralDBService.class);
-
- doReturn(SvcLogicResource.QueryStatus.SUCCESS)
- .when(dbServiceMock)
- .getConfigFileReferenceByFileTypeNVnfType(any(SvcLogicContext.class), anyString(), anyString());
}
MockDbServiceBuilder getConfigFileReferenceByFileTypeNVnfType(String prefix, String fileType, SvcLogicResource.QueryStatus status) throws SvcLogicException {
@@ -102,6 +97,30 @@ class MockDbServiceBuilder {
return this;
}
+ public MockDbServiceBuilder saveUploadConfig(String prefix, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .saveUploadConfig(any(SvcLogicContext.class), eq(prefix));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder getUploadConfigInfo(String prefix, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getUploadConfigInfo(any(SvcLogicContext.class), eq(prefix));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder updateUploadConfig(String prefix, int maxId, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .updateUploadConfig(any(SvcLogicContext.class), eq(prefix), eq(maxId));
+
+ return this;
+ }
+
DGGeneralDBService build() {
return dbServiceMock;
}