Add coverage for ConfigResourceNode-5 05/30805/1
authorkurczews <krzysztof.kurczewski@nokia.com>
Tue, 30 Jan 2018 14:29:39 +0000 (15:29 +0100)
committerkurczews <krzysztof.kurczewski@nokia.com>
Thu, 8 Feb 2018 06:56:34 +0000 (07:56 +0100)
Change-Id: If1f1ad7608563031c5f397a225a5576fdbcf59bd
Issue-ID: APPC-441
Signed-off-by: kurczews <krzysztof.kurczewski@nokia.com>
appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java
appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java
appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java

index 8895a82..c0580b4 100644 (file)
@@ -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;
 
index 6ecc1ed..e4e245e 100644 (file)
@@ -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;
@@ -137,6 +138,26 @@ public class ConfigResourceNodeTest {
         verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
     }
 
+    @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()
@@ -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
index 40bf697..2da8d53 100644 (file)
@@ -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;
     }