diff options
author | Patrick Brady <patrick.brady@att.com> | 2019-07-23 11:54:01 -0700 |
---|---|---|
committer | Patrick Brady <patrick.brady@att.com> | 2019-07-24 21:55:12 +0000 |
commit | b14db107c5dd7eadbfecde037ad68633775502de (patch) | |
tree | c77ca884a2710af459ca90e295d812ee5630c7d6 /appc-config/appc-data-services/provider/src/test | |
parent | e0bdc35d8428a574c6decc6075b8d8ef98f05d5f (diff) |
Prepared statements for DG services
Convert sql queries to prepared statements in other
parts of appc.
Change-Id: If29225394de2ab286e4f2f7bdd17f6af6b286576
Signed-off-by: Patrick Brady <patrick.brady@att.com>
Issue-ID: OJSI-25
Diffstat (limited to 'appc-config/appc-data-services/provider/src/test')
-rw-r--r-- | appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/MockDGGeneralDBService.java | 15 | ||||
-rw-r--r-- | appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/MockDbLibServiceQueries.java (renamed from appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/MockSvcLogicResource.java) | 31 | ||||
-rw-r--r-- | appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestDGGeneralDBService.java | 36 |
3 files changed, 65 insertions, 17 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 index 5aed72a25..adc080581 100644 --- 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 @@ -21,23 +21,24 @@ package org.onap.appc.data.services.db; + public class MockDGGeneralDBService extends DGGeneralDBService { - private static MockSvcLogicResource serviceLogic = new MockSvcLogicResource(); + private static MockDbLibServiceQueries dbLibServiceQueries = new MockDbLibServiceQueries(); public MockDGGeneralDBService() { - super(serviceLogic); - serviceLogic = new MockSvcLogicResource(); + super(dbLibServiceQueries); + dbLibServiceQueries = new MockDbLibServiceQueries(); } - public MockDGGeneralDBService(MockSvcLogicResource serviceLogic) { - super(serviceLogic); - this.serviceLogic = serviceLogic; + public MockDGGeneralDBService(MockDbLibServiceQueries dbLibServiceQueries) { + super(dbLibServiceQueries); + this.dbLibServiceQueries = dbLibServiceQueries; } public static MockDGGeneralDBService initialise() { - MockDGGeneralDBService mockDGGeneralDBService = new MockDGGeneralDBService(serviceLogic); + MockDGGeneralDBService mockDGGeneralDBService = new MockDGGeneralDBService(dbLibServiceQueries); 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/MockDbLibServiceQueries.java index e4dbbc15d..91dd1c11f 100644 --- 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/MockDbLibServiceQueries.java @@ -21,6 +21,7 @@ package org.onap.appc.data.services.db; +import java.util.ArrayList; import java.util.Map; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; @@ -28,20 +29,40 @@ 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 { +public class MockDbLibServiceQueries extends DbLibServiceQueries { + public MockDbLibServiceQueries() { + super(null,true); + } + + @Override + public QueryStatus query(String query, SvcLogicContext ctx, String prefix, ArrayList<String> arguments) { + + return QueryStatus.SUCCESS; + } + @Override + public QueryStatus query(String query, SvcLogicContext ctx, ArrayList<String> arguments) { + return QueryStatus.SUCCESS; + } + @Override + public QueryStatus query(String query, String prefix, SvcLogicContext ctx) { + return QueryStatus.SUCCESS; + } @Override - public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, - String orderBy, SvcLogicContext ctx) throws SvcLogicException { + public QueryStatus query(String query, SvcLogicContext ctx) { 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 { + public QueryStatus save(String query, SvcLogicContext ctx, ArrayList<String> arguments) { + + return QueryStatus.SUCCESS; + } + @Override + public QueryStatus save(String query, SvcLogicContext ctx) { 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 fbb8cf8b9..ae5518dc9 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 @@ -26,11 +26,21 @@ package org.onap.appc.data.services.db; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.io.IOException; +import java.util.ArrayList; + +import javax.sql.rowset.CachedRowSet; + import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringEscapeUtils; import org.junit.Test; +import org.onap.ccsdk.sli.core.dblib.DbLibService; 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; @@ -268,12 +278,28 @@ public class TestDGGeneralDBService { @Test public void testGetTemplateWithTemplateModelId() throws Exception { - MockDGGeneralDBService dbService = MockDGGeneralDBService.initialise(); + DbLibService mockDbLibService = mock(DbLibService.class); + CachedRowSet mockCachedRowSet = mock(CachedRowSet.class); + when(mockCachedRowSet.next()).thenReturn(false); + DGGeneralDBService dbService = new DGGeneralDBService(mockDbLibService); SvcLogicContext ctx = new SvcLogicContext(); - String prefix="test"; - String templateModelId = "template001"; - String fileCategory="testCategory"; - dbService.getTemplateWithTemplateModelId(ctx, prefix, fileCategory, templateModelId); + ctx.setAttribute("request-action", "testRequestAction"); + ctx.setAttribute("vnf-type", "testVnfType"); + ctx.setAttribute("vnfc-type", "testVnfcType"); + String expectedStatement = "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 = ? AND action = ? AND vnf_type = ? AND vnfc_type = ? )" + + " and ASDC_ARTIFACTS.artifact_name like ? ; "; + ArrayList<String> expectedArguments = new ArrayList<>(); + expectedArguments.add("testFileCategory"); + expectedArguments.add("testRequestAction"); + expectedArguments.add("testVnfType"); + expectedArguments.add("testVnfcType"); + String templateModelId = "testTemplateModelId"; + expectedArguments.add("%_"+ templateModelId +"%"); + when(mockDbLibService.getData(any(), any(), any())).thenReturn(mockCachedRowSet); + dbService.getTemplateWithTemplateModelId(ctx, "testPrefix", "testFileCategory", templateModelId); + verify(mockDbLibService,times(1)).getData(expectedStatement, expectedArguments, null); } @Test |