diff options
Diffstat (limited to 'appc-config/appc-data-services/provider/src')
-rw-r--r-- | appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java | 235 |
1 files changed, 148 insertions, 87 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 e4e245ecf..e5c5149f3 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 @@ -1,23 +1,17 @@ package org.onap.appc.data.services.node; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import java.util.HashMap; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; 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_FILES_PREFIX; import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_FILE_ID_PARAM; +import static org.onap.appc.data.services.node.ConfigResourceNode.CONFIG_PARAMS; 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; @@ -33,13 +27,26 @@ 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; +import static org.onap.appc.data.services.node.ConfigResourceNode.TMP_CONVERTCONFIG_ESC_DATA; +import static org.onap.appc.data.services.node.ConfigResourceNode.TMP_MERGE_MERGED_DATA; +import static org.onap.appc.data.services.node.ConfigResourceNode.UNABLE_TO_SAVE_RELATIONSHIP_STR; 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 com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import java.util.HashMap; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.appc.data.services.AppcDataServiceConstant; +import org.onap.appc.data.services.db.DGGeneralDBService; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.onap.ccsdk.sli.core.sli.SvcLogicResource; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; public class ConfigResourceNodeTest { @@ -66,7 +73,8 @@ public class ConfigResourceNodeTest { ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise()); String findCapability = "Restart"; JsonNodeFactory.instance.objectNode(); - String subCaps = "[{\"Restart\":[\"SSC\",\"MMC\"]},{\"Rebuild\":[\"SSC\"]},{\"Migrate\":[\"SSC\"]},{\"Snapshot\":[\"SSC\"]},{\"Start\":[\"SSC\"]},{\"Stop\":[\"SSC\"]}]"; + String subCaps = + "[{\"Restart\":[\"SSC\",\"MMC\"]},{\"Rebuild\":[\"SSC\"]},{\"Migrate\":[\"SSC\"]},{\"Snapshot\":[\"SSC\"]},{\"Start\":[\"SSC\"]},{\"Stop\":[\"SSC\"]}]"; ObjectMapper m = new ObjectMapper(); JsonNode subCapabilities = m.readTree(subCaps); String vServerId = "testServer"; @@ -139,7 +147,8 @@ public class ConfigResourceNodeTest { } @Test - public void should_add_attribute_with_success_if_get_download_config_template_by_vnf_type_succeed() throws SvcLogicException { + 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); @@ -159,10 +168,20 @@ public class ConfigResourceNodeTest { } @Test + public void should_add_attribute_with_success_if_save_prepare_relationship_succeed() throws SvcLogicException { + DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build(); + + ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); + configResourceNode.savePrepareRelationship(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) - .build(); + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX, + DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -173,9 +192,9 @@ public class ConfigResourceNodeTest { @Test public void should_throw_exception_on_device_config_failure() throws Exception { - DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX, DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE) - .build(); + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(DEVICE_CONF_PREFIX, + DEVICE_CONF_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -187,9 +206,9 @@ public class ConfigResourceNodeTest { @Test public void should_throw_exception_on_success_param_missing() throws Exception { - DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND) - .build(); + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, + SvcLogicResource.QueryStatus.NOT_FOUND).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -200,9 +219,9 @@ public class ConfigResourceNodeTest { @Test public void should_throw_exception_on_success_param_failure() throws Exception { - DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE) - .build(); + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(SUCCESS_PREFIX, SUCCESS_FILE_TYPE, + SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -214,9 +233,9 @@ public class ConfigResourceNodeTest { @Test public void should_throw_exception_on_failure_param_missing() throws Exception { - DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND) - .build(); + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE, + SvcLogicResource.QueryStatus.NOT_FOUND).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -227,9 +246,9 @@ public class ConfigResourceNodeTest { @Test public void should_throw_exception_on_failure_param_failure() throws Exception { - DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE) - .build(); + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(FAILURE_PREFIX, FAILURE_FILE_TYPE, + SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -241,9 +260,9 @@ public class ConfigResourceNodeTest { @Test public void should_throw_exception_on_log_param_missing() throws Exception { - DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE, SvcLogicResource.QueryStatus.NOT_FOUND) - .build(); + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE, + SvcLogicResource.QueryStatus.NOT_FOUND).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -254,9 +273,9 @@ public class ConfigResourceNodeTest { @Test public void should_throw_exception_on_log_param_failure() throws Exception { - DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE, SvcLogicResource.QueryStatus.FAILURE) - .build(); + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().getConfigFileReferenceByFileTypeNVnfType(LOG_PREFIX, LOG_FILE_TYPE, + SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -268,8 +287,7 @@ public class ConfigResourceNodeTest { @Test public void should_throw_exception_on_device_protocol_missing() throws SvcLogicException { DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND) - .build(); + .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -281,8 +299,7 @@ public class ConfigResourceNodeTest { @Test public void should_throw_exception_on_device_protocol_failure() throws SvcLogicException { DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.FAILURE) - .build(); + .getDeviceProtocolByVnfType(DEVICE_PROTOCOL_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -294,8 +311,7 @@ public class ConfigResourceNodeTest { @Test public void should_throw_exception_on_conf_action_by_vnf_action_failure() throws SvcLogicException { DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE) - .build(); + .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -307,9 +323,8 @@ public class ConfigResourceNodeTest { @Test public void should_throw_exception_on_conf_action_missing() throws SvcLogicException { DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND) - .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND) - .build(); + .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND) + .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -321,9 +336,8 @@ public class ConfigResourceNodeTest { @Test public void should_throw_exception_on_conf_action_failure() throws SvcLogicException { DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND) - .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE) - .build(); + .getConfigureActionDGByVnfTypeNAction(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND) + .getConfigureActionDGByVnfType(CONF_ACTION_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -338,8 +352,7 @@ public class ConfigResourceNodeTest { inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category"); DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE) - .build(); + .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -354,9 +367,9 @@ public class ConfigResourceNodeTest { inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category"); DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND) - .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE) - .build(); + .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND) + .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE) + .build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -371,9 +384,10 @@ public class ConfigResourceNodeTest { inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category"); DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND) - .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND) - .build(); + .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND) + .getTemplateByVnfTypeNAction("some prefix", "some file category", + SvcLogicResource.QueryStatus.NOT_FOUND) + .build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -391,8 +405,8 @@ public class ConfigResourceNodeTest { context.setAttribute("template-name", "test template"); DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.NOT_FOUND) - .build(); + .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.NOT_FOUND) + .build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -410,8 +424,8 @@ public class ConfigResourceNodeTest { context.setAttribute("template-name", "test template"); DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.FAILURE) - .build(); + .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.FAILURE) + .build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -426,8 +440,7 @@ public class ConfigResourceNodeTest { context.setAttribute(FILE_CATEGORY_PARAM, "some file category"); DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .saveConfigFiles(CONFIG_FILES_PREFIX, SvcLogicResource.QueryStatus.FAILURE) - .build(); + .saveConfigFiles(CONFIG_FILES_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -442,8 +455,8 @@ public class ConfigResourceNodeTest { 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(); + .getMaxConfigFileId(MAX_CONF_FILE_PREFIX, "some file category", SvcLogicResource.QueryStatus.NOT_FOUND) + .build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -458,9 +471,9 @@ public class ConfigResourceNodeTest { 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(); + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND, + SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -472,8 +485,7 @@ public class ConfigResourceNodeTest { @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(); + .saveUploadConfig(UPLOAD_CONFIG_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -485,8 +497,7 @@ public class ConfigResourceNodeTest { @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(); + .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -498,8 +509,7 @@ public class ConfigResourceNodeTest { @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(); + .getUploadConfigInfo(UPLOAD_CONFIG_INFO_PREFIX, SvcLogicResource.QueryStatus.NOT_FOUND).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -513,8 +523,7 @@ public class ConfigResourceNodeTest { when(contextMock.getAttribute(UPLOAD_CONFIG_ID_PARAM)).thenReturn("1234"); DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .updateUploadConfig(UPLOAD_CONFIG_PREFIX, 1234, SvcLogicResource.QueryStatus.FAILURE) - .build(); + .updateUploadConfig(UPLOAD_CONFIG_PREFIX, 1234, SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -528,8 +537,7 @@ public class ConfigResourceNodeTest { inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix"); DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getDownloadConfigTemplateByVnf("some prefix", SvcLogicResource.QueryStatus.FAILURE) - .build(); + .getDownloadConfigTemplateByVnf("some prefix", SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -543,8 +551,7 @@ public class ConfigResourceNodeTest { when(contextMock.getAttribute(SITE_LOCATION_PARAM)).thenReturn("some location"); DGGeneralDBService dbServiceMock = new MockDbServiceBuilder() - .getTemplateByArtifactType("smm", "smm", "some location", SvcLogicResource.QueryStatus.FAILURE) - .build(); + .getTemplateByArtifactType("smm", "smm", "some location", SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -557,9 +564,8 @@ public class ConfigResourceNodeTest { 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(); + DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().getTemplateByArtifactType("intermediate-ca-chain", + "intermediate_ca_chain", "some location", SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -572,9 +578,9 @@ public class ConfigResourceNodeTest { 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(); + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().getTemplateByArtifactType("server-certificate-and-key", + "server_certificate_and_key", "some location", SvcLogicResource.QueryStatus.FAILURE).build(); ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); @@ -583,4 +589,59 @@ public class ConfigResourceNodeTest { configResourceNode.getSmmChainKeyFiles(inParams, contextMock); } -}
\ No newline at end of file + @Test + public void should_throw_exception_on_save_prepare_relationship_failure() throws SvcLogicException { + inParams.put(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND, "some sdnc index"); + inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_ID, "some file id"); + + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", + "some sdnc index", QueryStatus.FAILURE).build(); + + ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock); + + expectedException.expect(SvcLogicException.class); + expectedException.expectMessage(UNABLE_TO_SAVE_RELATIONSHIP_STR); + configResourceNode.savePrepareRelationship(inParams, contextMock); + } + + @Test + public void should_save_save_config_files_for_empty_config_params() throws SvcLogicException { + + when(contextMock.getAttribute(TMP_CONVERTCONFIG_ESC_DATA)).thenReturn("some esc data"); + when(contextMock.getAttribute("configuration")).thenReturn("some configuration"); + when(contextMock.getAttribute(CONFIG_PARAMS)).thenReturn(""); + + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", + "some sdnc index", QueryStatus.FAILURE).build(); + + ConfigResourceNode configResourceNode = spy(new ConfigResourceNode(dbServiceMock)); + configResourceNode.saveConfigBlock(inParams, contextMock); + + verify(configResourceNode).saveDeviceConfiguration(inParams, contextMock, "Request", "some esc data", + "some configuration"); + verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS)); + } + + @Test + public void should_save_save_config_files_for_non_empty_config_params() throws SvcLogicException { + + when(contextMock.getAttribute(TMP_CONVERTCONFIG_ESC_DATA)).thenReturn("some esc data"); + when(contextMock.getAttribute(TMP_MERGE_MERGED_DATA)).thenReturn("merged data"); + when(contextMock.getAttribute(CONFIG_PARAMS)).thenReturn("non empty"); + + DGGeneralDBService dbServiceMock = + new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", + "some sdnc index", QueryStatus.FAILURE).build(); + + ConfigResourceNode configResourceNode = spy(new ConfigResourceNode(dbServiceMock)); + configResourceNode.saveConfigBlock(inParams, contextMock); + + verify(configResourceNode).saveDeviceConfiguration(inParams, contextMock, "Configurator", "some esc data", + "merged data"); + verify(configResourceNode).saveConfigBlock(inParams, contextMock); + verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS)); + } + +} |