From: Balaji, Ramya (rb111y) Date: Thu, 1 Mar 2018 02:01:47 +0000 (-0500) Subject: ConfigScaleOut flow changes X-Git-Tag: v1.3.0~205 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=84919d3230ad04b6a78f52e37449ba5d34c9a033;p=appc.git ConfigScaleOut flow changes Code changes and unit test cases to include template id when retrieving vnfc reference data and artifacts from tables. Cleaned up Unit Tests. Issue-ID: APPC-619,APPC-620 Change-Id: I8db08be19b9fa094a07e5c5597c45327824cfb01 Signed-off-by: Balaji, Ramya (rb111y) --- diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java index 303c974f9..b14eb1c02 100644 --- a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java +++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/db/DGGeneralDBService.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -42,6 +42,7 @@ public class DGGeneralDBService { private static DGGeneralDBService dgGeneralDBService = null; public static DGGeneralDBService initialise() { + if (dgGeneralDBService == null) { dgGeneralDBService = new DGGeneralDBService(); } @@ -54,6 +55,12 @@ public class DGGeneralDBService { } } + protected DGGeneralDBService(SqlResource svcLogic) { + if (serviceLogic == null) { + serviceLogic = svcLogic; + } + } + public QueryStatus getDeviceProtocolByVnfType(SvcLogicContext ctx, String prefix) throws SvcLogicException { QueryStatus status = null; if (serviceLogic != null && ctx != null) { @@ -117,8 +124,8 @@ public class DGGeneralDBService { + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " + " AND file_category = '" + fileCategory + "'" + " AND action = $request-action " + " AND vnf_type = $vnf-type ) ; "; - status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } return status; } @@ -291,7 +298,7 @@ public class DGGeneralDBService { } - + public QueryStatus getTemplateByArtifactType(SvcLogicContext ctx, String prefix, String fileCategory, String artifactType) throws SvcLogicException { QueryStatus status = null; @@ -307,27 +314,27 @@ public class DGGeneralDBService { } return status; } - - + + public QueryStatus getConfigFilesByVnfVmNCategory(SvcLogicContext ctx, String prefix, String fileCategory, String vnfId, String vmName) throws SvcLogicException { QueryStatus status = null; if (serviceLogic != null && ctx != null) { - + String key = "SELECT file_content , config_file_id " + " FROM CONFIGFILES " + " WHERE config_file_id = ( SELECT MAX(config_file_id) configfileid " + " FROM CONFIGFILES " + " WHERE file_category = '" + fileCategory + "'" + " AND vnf_id = '" + vnfId + "'" + " AND vm_name = '" + vmName + "' ) ; "; - - + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); } return status; } - - + + public QueryStatus getDownloadConfigTemplateByVnf(SvcLogicContext ctx, String prefix) throws SvcLogicException { QueryStatus status = null; @@ -337,16 +344,16 @@ public class DGGeneralDBService { } return status; } - - - + + + public QueryStatus saveConfigTransactionLog(SvcLogicContext ctx, String prefix) throws SvcLogicException { QueryStatus status = null; if (serviceLogic != null && ctx != null) { - - + + String key = "INSERT INTO CONFIG_TRANSACTION_LOG " + " SET request_id = $request-id , " + " message_type = $log-message-type , " + " message = $log-message ;"; @@ -354,61 +361,61 @@ public class DGGeneralDBService { status = serviceLogic.save("SQL", false, false, key, null, prefix, ctx); - + } return status; } - + public QueryStatus getVnfcReferenceByVnfcTypeNAction(SvcLogicContext ctx, String prefix) throws SvcLogicException { QueryStatus status = null; if (serviceLogic != null && ctx != null) { - + String key = "SELECT * " + " FROM VNFC_REFERENCE " + " WHERE vnf_type = $vnf-type " + " AND vnfc_type = $vnfc-type " + " AND action = $request-action " + " ORDER BY vm_instance, vnfc_instance ; "; - - + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); } return status; } - + public QueryStatus getVnfcReferenceByVnfTypeNAction(SvcLogicContext ctx, String prefix) throws SvcLogicException { QueryStatus status = null; if (serviceLogic != null && ctx != null) { - + String key = "SELECT * " + " FROM VNFC_REFERENCE " + " WHERE vnf_type = $vnf-type " + " AND action = $request-action " + " ORDER BY vm_instance, vnfc_instance ; "; - + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); } return status; } - - + + public QueryStatus getUploadConfigInfo(SvcLogicContext ctx, String prefix) throws SvcLogicException { QueryStatus status = null; if (serviceLogic != null && ctx != null) { - + String key = "SELECT * , UNIX_TIMESTAMP(UPLOAD_DATE) UPLOAD_TIMESTAMP " + " FROM UPLOAD_CONFIG " + " WHERE upload_config_id = " + "( SELECT MAX(upload_config_id) uploadconfigid " + " FROM UPLOAD_CONFIG " + " WHERE vnf_id = $vnf-id AND vm_name = $vm-name ) ; "; - + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); } return status; @@ -445,4 +452,62 @@ public class DGGeneralDBService { return localContext.getAttribute("artifact-content"); } -} \ No newline at end of file + public QueryStatus getTemplateWithTemplateModelId(SvcLogicContext ctx, String prefix, String fileCategory, + String templateModelId) throws SvcLogicException { + QueryStatus status = null; + String templatePattern = "'%_"+ templateModelId +"%'"; + if (serviceLogic != null && ctx != null) { + String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " + + " FROM ASDC_ARTIFACTS " + + " WHERE asdc_artifacts_id = ( SELECT MAX(a.asdc_artifacts_id) configfileid " + + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " + + " AND file_category = '" + fileCategory + "'" + " AND action = $request-action " + + " AND vnf_type = $vnf-type " + " AND vnfc_type = $vnfc-type ) and ASDC_ARTIFACTS.artifact_name like " + + templatePattern + "; "; + log.info("getTemplateWithTemplateModelId()::: with template:::"+ key); + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + + public QueryStatus getTemplateByVnfTypeNActionWithTemplateModelId(SvcLogicContext ctx, String prefix, + String fileCategory, String templateModelId) throws SvcLogicException { + QueryStatus status = null; + String templatePattern = "'%_"+ templateModelId +"%'"; + if (serviceLogic != null && ctx != null) { + String key = "SELECT artifact_content file_content , asdc_artifacts_id config_file_id " + + " FROM ASDC_ARTIFACTS " + + " WHERE asdc_artifacts_id = (SELECT MAX(a.asdc_artifacts_id) configfileid " + + " FROM ASDC_ARTIFACTS a, ASDC_REFERENCE b " + " WHERE a.artifact_name = b.artifact_name " + + " AND file_category = '" + fileCategory + "'" + " AND action = $request-action " + + " AND vnf_type = $vnf-type ) and ASDC_ARTIFACTS.artifact_name like " + + templatePattern + "; "; + log.info("getTemplateByVnfTypeNActionWithTemplateModelId()::: with template:::"+ key); + + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + + } + + public QueryStatus getVnfcReferenceByVnfTypeNActionWithTemplateModelId(SvcLogicContext ctx, String prefix, + String templateModelId) throws SvcLogicException { + QueryStatus status = null; + if (serviceLogic != null && ctx != null) { + + String key = "SELECT * " + + " FROM VNFC_REFERENCE " + + " WHERE vnf_type = $vnf-type " + + " AND action = $request-action " + + " AND template_id = '" + + templateModelId + "'" + + " ORDER BY vm_instance, vnfc_instance ; "; + + log.info("getVnfcReferenceByVnfTypeNActionWithTemplateModelId()::: with template:::"+ key); + status = serviceLogic.query("SQL", false, null, key, prefix, null, ctx); + } + return status; + } + +} 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 c0580b43b..856648210 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -190,6 +190,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin { String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY); String templateName = ctx.getAttribute("template-name"); + String templateModelId = ctx.getAttribute("template-model-id"); QueryStatus status; String responsePrefix1 = ""; @@ -200,22 +201,51 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin { log.info("RESPONSEPREFIX1 : " + responsePrefix1); if (StringUtils.isBlank(templateName)) { + if (StringUtils.isNotBlank(templateModelId)) { + status = db.getTemplateWithTemplateModelId(ctx, responsePrefix, fileCategory,templateModelId); + if (status == QueryStatus.FAILURE) { + throw new QueryException(UNABLE_TO_READ_STR + fileCategory); + } + if (!(status == QueryStatus.NOT_FOUND) ) { + ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("GetTemplate Successful "); + return; + } + } status = db.getTemplate(ctx, responsePrefix, fileCategory); if (status == QueryStatus.FAILURE) { throw new QueryException(UNABLE_TO_READ_STR + fileCategory); } if (status == QueryStatus.NOT_FOUND) { + if (StringUtils.isNotBlank(templateModelId)) { + status = db.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix, fileCategory,templateModelId); + if (status == QueryStatus.FAILURE) { + throw new QueryException(UNABLE_TO_READ_STR + fileCategory); + } + if (!(status == QueryStatus.NOT_FOUND) ) { + ctx.setAttribute(responsePrefix1 + AppcDataServiceConstant.OUTPUT_PARAM_STATUS, + AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS); + log.info("GetTemplate Successful "); + return; + } + } + if (status == QueryStatus.NOT_FOUND) { - status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory); - if (status == QueryStatus.FAILURE) { - throw new QueryException(UNABLE_TO_READ_STR + fileCategory); - } + status = db.getTemplateByVnfTypeNAction(ctx, responsePrefix, fileCategory); - if (status == QueryStatus.NOT_FOUND) { - throw new QueryException(UNABLE_TO_READ_STR + fileCategory); + if (status == QueryStatus.FAILURE) { + throw new QueryException(UNABLE_TO_READ_STR + fileCategory); + } + + if (status == QueryStatus.NOT_FOUND) { + throw new QueryException(UNABLE_TO_READ_STR + fileCategory); + } } + + } } else { @@ -629,20 +659,33 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin { log.info("Received getVnfcReference call with params : " + inParams); String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX); - QueryStatus status; + String templateModelId = ctx.getAttribute("template-model-id"); + log.info("getVnfcReference():::"+templateModelId); + QueryStatus status = null; try { if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) { + + status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix); if (status == QueryStatus.FAILURE) { throw new QueryException("Unable to Read vnfc-reference"); } + } - status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix); + if (StringUtils.isNotBlank(templateModelId)) { + status = db.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix,templateModelId); + if (status == QueryStatus.FAILURE) { + throw new QueryException("Unable to Read vnfc-reference with template-model-id"); + } + } + if (StringUtils.isBlank(templateModelId) || (StringUtils.isNotBlank(templateModelId) && (status == QueryStatus.NOT_FOUND))) { + status = db.getVnfcReferenceByVnfTypeNAction(ctx, responsePrefix); - if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) { - throw new QueryException("Unable to Read vnfc reference"); + if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) { + throw new QueryException("Unable to Read vnfc reference"); + } } responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : ""; @@ -794,4 +837,5 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin { } return capabilityCheckNeeded; } -} \ No newline at end of file + +} diff --git a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/MockDGGeneralDBService.java b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/MockDGGeneralDBService.java new file mode 100644 index 000000000..fea367037 --- /dev/null +++ b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/MockDGGeneralDBService.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.data.services.db; + +public class MockDGGeneralDBService extends DGGeneralDBService { + + private static MockSvcLogicResource serviceLogic = new MockSvcLogicResource(); + + public MockDGGeneralDBService() { + + super(serviceLogic); + serviceLogic = new MockSvcLogicResource(); + } + + public MockDGGeneralDBService(MockSvcLogicResource serviceLogic) { + super(serviceLogic); + this.serviceLogic = serviceLogic; + } + + public static MockDGGeneralDBService initialise() { + MockDGGeneralDBService mockDGGeneralDBService = new MockDGGeneralDBService(serviceLogic); + return mockDGGeneralDBService; + } +} diff --git a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/MockSvcLogicResource.java b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/MockSvcLogicResource.java new file mode 100644 index 000000000..ef7b7d520 --- /dev/null +++ b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/MockSvcLogicResource.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.data.services.db; + +import java.util.Map; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; +import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; + +public class MockSvcLogicResource extends SqlResource { + + + + @Override + public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, + String orderBy, SvcLogicContext ctx) throws SvcLogicException { + + return QueryStatus.SUCCESS; + } + + @Override + public QueryStatus save(String resource, boolean force, boolean localOnly, String key, Map parms, + String prefix, SvcLogicContext ctx) throws SvcLogicException { + + return QueryStatus.SUCCESS; + } + + +} diff --git a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestDGGeneralDBService.java b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestDGGeneralDBService.java index 91f05c1d4..23f0bcb1d 100644 --- a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestDGGeneralDBService.java +++ b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestDGGeneralDBService.java @@ -2,22 +2,22 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ @@ -25,9 +25,6 @@ package org.onap.appc.data.services.db; import static org.junit.Assert.assertEquals; import java.io.IOException; -import java.io.InputStream; -import java.util.Enumeration; -import java.util.Properties; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringEscapeUtils; import org.junit.Test; @@ -40,159 +37,149 @@ public class TestDGGeneralDBService { DGGeneralDBService dbService; private static String STRING_ENCODING = "utf-8"; - // @Before - public void setUp() { - Properties props = new Properties(); - InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); - if (propStr == null) { - System.err.println("src/test/resources/svclogic.properties missing"); - } - try { - props.load(propStr); - propStr.close(); - } catch (Exception e) { - e.printStackTrace(); - System.err.println("Could not initialize properties"); - } - // Add properties to global properties - Enumeration propNames = props.keys(); - while (propNames.hasMoreElements()) { - String propName = (String) propNames.nextElement(); - System.setProperty(propName, props.getProperty(propName)); - } - dbService = DGGeneralDBService.initialise(); - } - - @Test(expected = Exception.class) + @Test public void testGetUploadConfig() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("vnf-name", "test"); ctx.setAttribute("vnf-id", "test"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getUploadConfigInfo(ctx, "test"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testGetDeviceProtocolByVnfType() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("vnf-type", "test"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getDeviceProtocolByVnfType(ctx, "test"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testGettConfigFileReferenceByFileTypeNVnfType() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("vnf-type", "test"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getConfigFileReferenceByFileTypeNVnfType(ctx, "test", "device_configuration"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testGetDeviceAuthenticationByVnfType() throws Exception { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("vnf-type", "test"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getDeviceAuthenticationByVnfType(ctx, "test"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testGetTemplate() throws Exception { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("vnfc-type", "test"); ctx.setAttribute("request-action", "Configure"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getTemplate(ctx, "test", "config_template"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testGetTemplateByVnfTypeNAction() throws Exception { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("vnf-type", "test"); - ctx.setAttribute("request-action", "Configure"); + ctx.setAttribute("request-action", "ConfigScaleOut"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getTemplateByVnfTypeNAction(ctx, "test", "config_template"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testGetTemplateByTemplateName() throws Exception { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("request-action", "Configure"); ctx.setAttribute("vnf-type", "test"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getTemplateByTemplateName(ctx, "test", "template.json"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testGetTemplateByVnfType() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("vnf-type", "test"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getTemplateByVnfType(ctx, "test", "config_template"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testGetConfigureActionDGByVnfTypeNAction() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("vnf-type", "test"); ctx.setAttribute("request-action", "ConfigModify"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getConfigureActionDGByVnfTypeNAction(ctx, "test"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testGetConfigureActionDGByVnfType() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("vnf-type", "test"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getConfigureActionDGByVnfType(ctx, "test"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testGetMaxConfigFileId() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("vnf-id", "test"); ctx.setAttribute("vm-name", "test"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getMaxConfigFileId(ctx, "test", "device_configuration"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testGetConfigFilesByVnfVmNCategory() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("vnf-id", "test"); ctx.setAttribute("vm-name", "test"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getConfigFilesByVnfVmNCategory(ctx, "test", "device_configuration", "test", "ibcx0001vm001"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testGetDownloadConfigTemplateByVnf() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("vnf-type", "test"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.getDownloadConfigTemplateByVnf(ctx, "test"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } - @Test(expected = Exception.class) + @Test public void testSaveConfigTxLog() throws SvcLogicException, IOException { SvcLogicContext ctx = new SvcLogicContext(); @@ -203,8 +190,37 @@ public class TestDGGeneralDBService { String escapedMessage = StringEscapeUtils.escapeSql(message); ctx.setAttribute("log-message", escapedMessage); ctx.setAttribute("log-message-type", "request"); + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); QueryStatus status = dbService.saveConfigTransactionLog(ctx, "test"); - assertEquals(status, "SUCCESS"); + assertEquals(status, QueryStatus.SUCCESS); } + @Test + public void testGetVnfcReferenceByVnfTypeNActionWithTemplateModelId() throws Exception { + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + String prefix="test"; + String templateModelId = "template001"; + dbService.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, prefix, templateModelId); + } + + @Test + public void testGetTemplateWithTemplateModelId() throws Exception { + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + String prefix="test"; + String templateModelId = "template001"; + String fileCategory="testCategory"; + dbService.getTemplateWithTemplateModelId(ctx, prefix, fileCategory, templateModelId); + } + + @Test + public void testgetTemplateByVnfTypeNActionWithTemplateModelId() throws Exception { + MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + String prefix="test"; + String templateModelId = "template001"; + String fileCategory="testCategory"; + dbService.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, prefix, fileCategory, templateModelId); + } }