diff options
Diffstat (limited to 'appc-config/appc-data-services/provider/src/test')
3 files changed, 170 insertions, 59 deletions
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<String, String> 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); + } } |