aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-data-services/provider/src/test
diff options
context:
space:
mode:
authorkurczews <krzysztof.kurczewski@nokia.com>2018-01-30 14:39:46 +0100
committerkurczews <krzysztof.kurczewski@nokia.com>2018-02-07 08:26:25 +0100
commit5196c90db81f24343a3ed9e685592b6210722573 (patch)
tree2abfc2521ac6d95fb05e09b0f4eaf68cbc8cddd6 /appc-config/appc-data-services/provider/src/test
parentb8db77008335b0a36586f2abf365148731dda69c (diff)
Add coverage for ConfigResourceNode-4
Change-Id: I14f4afe16cb8b475f39927c1ee8d79594a01d5bc Issue-ID: APPC-441 Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
Diffstat (limited to 'appc-config/appc-data-services/provider/src/test')
-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
2 files changed, 95 insertions, 6 deletions
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;
}