aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-data-services/provider/src/test/java/org
diff options
context:
space:
mode:
authorkurczews <krzysztof.kurczewski@nokia.com>2018-01-30 13:37:29 +0100
committerkurczews <krzysztof.kurczewski@nokia.com>2018-02-06 08:30:04 +0100
commitb8db77008335b0a36586f2abf365148731dda69c (patch)
tree15d89eb71869dc4b68fd0b8c8858b6150ca74923 /appc-config/appc-data-services/provider/src/test/java/org
parentf86fd5fa0249b08a44f0d2586f78462b946695d7 (diff)
Add coverage for ConfigResourceNode-3
Change-Id: I10fd36f64a773b3a0b424ab89d2de5a5cedfb0ec Issue-ID: APPC-441 Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
Diffstat (limited to 'appc-config/appc-data-services/provider/src/test/java/org')
-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
2 files changed, 89 insertions, 0 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 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;
}