summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkurczews <krzysztof.kurczewski@nokia.com>2018-01-30 15:29:39 +0100
committerkurczews <krzysztof.kurczewski@nokia.com>2018-02-08 07:56:34 +0100
commit189470a161b6ac86615595706b32da0760ce3190 (patch)
treebf49ecffc6335d3dae5c6d413d388031bc2f7548
parentde5e2530e34fae0798ccffb7360618265e62be3e (diff)
Add coverage for ConfigResourceNode-5
Change-Id: If1f1ad7608563031c5f397a225a5576fdbcf59bd Issue-ID: APPC-441 Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
-rw-r--r--appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java4
-rw-r--r--appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java81
-rw-r--r--appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java16
3 files changed, 100 insertions, 1 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 8895a82c0..c0580b43b 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
@@ -79,6 +79,8 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
static final String UNABLE_TO_SAVE_RELATIONSHIP_STR = "Unable to save prepare_relationship";
+ static final String SITE_LOCATION_PARAM = "site-location";
+
private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigResourceNode.class);
private final DGGeneralDBService db;
@@ -465,7 +467,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
log.info("Received saveStyleSheet call with params : " + inParams);
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
- String siteLocation = ctx.getAttribute("site-location");
+ String siteLocation = ctx.getAttribute(SITE_LOCATION_PARAM);
QueryStatus status;
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 6ecc1ed40..e4e245ecf 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
@@ -30,6 +30,7 @@ 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.SITE_LOCATION_PARAM;
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;
@@ -138,6 +139,26 @@ public class ConfigResourceNodeTest {
}
@Test
+ public void should_add_attribute_with_success_if_get_download_config_template_by_vnf_type_succeed() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ configResourceNode.getDownloadConfigTemplateByVnf(inParams, contextMock);
+
+ verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
+ }
+
+ @Test
+ public void should_add_attribute_with_success_if_get_ssm_chain_succeed() throws SvcLogicException {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ configResourceNode.getSmmChainKeyFiles(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)
@@ -502,4 +523,64 @@ public class ConfigResourceNodeTest {
configResourceNode.updateUploadConfig(inParams, contextMock);
}
+ @Test
+ public void should_throw_exception_on_get_download_config_failure() throws SvcLogicException {
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getDownloadConfigTemplateByVnf("some prefix", SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to get download config template.");
+ configResourceNode.getDownloadConfigTemplateByVnf(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_get_ssm_chain_failure() throws SvcLogicException {
+ when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getTemplateByArtifactType("smm", "smm", "some location", SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read smm file");
+ configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_get_ca_chain_failure() throws SvcLogicException {
+ when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getTemplateByArtifactType("intermediate-ca-chain", "intermediate_ca_chain", "some location", SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read intermediate_ca_chain file");
+ configResourceNode.getSmmChainKeyFiles(inParams, contextMock);
+ }
+
+ @Test
+ public void should_throw_exception_on_get_server_certificate_and_key_failure() throws SvcLogicException {
+ when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location");
+
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getTemplateByArtifactType("server-certificate-and-key", "server_certificate_and_key", "some location", SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read server_certificate_and_key file");
+ configResourceNode.getSmmChainKeyFiles(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 40bf69733..2da8d5316 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
@@ -121,6 +121,22 @@ class MockDbServiceBuilder {
return this;
}
+ public MockDbServiceBuilder getDownloadConfigTemplateByVnf(String prefix, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getDownloadConfigTemplateByVnf(any(SvcLogicContext.class), eq(prefix));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder getTemplateByArtifactType(String prefix, String fileCategory, String artifactType, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getTemplateByArtifactType(any(SvcLogicContext.class), eq(prefix), eq(fileCategory), eq(artifactType));
+
+ return this;
+ }
+
DGGeneralDBService build() {
return dbServiceMock;
}