diff options
author | Sandeep J <sandeejh@in.ibm.com> | 2018-09-24 01:03:37 +0530 |
---|---|---|
committer | Sandeep J <sandeejh@in.ibm.com> | 2018-09-24 01:07:07 +0530 |
commit | f029e358bf9318ac03ba1be27912f52d296feacd (patch) | |
tree | e0b7e123c833b8d12a458a249226f582138560b8 /dblib/provider | |
parent | 9e8138f54edbf4cc8a0309f9e149953e08d3280e (diff) |
formatted code and added test case
to increase code coverage in CachedDataSourceTest
Issue-ID: CCSDK-595
Change-Id: I10c2fec758bfb93587b4f5b096828a43a64039b0
Signed-off-by: Sandeep J <sandeejh@in.ibm.com>
Diffstat (limited to 'dblib/provider')
-rw-r--r-- | dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceTest.java | 159 |
1 files changed, 81 insertions, 78 deletions
diff --git a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceTest.java index 6385c1b57..c463f38bb 100644 --- a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceTest.java +++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceTest.java @@ -1,6 +1,9 @@ package org.onap.ccsdk.sli.core.dblib; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.sql.SQLFeatureNotSupportedException; import java.util.Properties; @@ -14,81 +17,81 @@ import org.slf4j.LoggerFactory; public class CachedDataSourceTest { - private static final Properties props = new Properties(); - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - props.setProperty("org.onap.ccsdk.sli.dbtype", "jdbc"); - props.setProperty("org.onap.ccsdk.sli.jdbc.hosts", "localhost"); - props.setProperty("org.onap.ccsdk.sli.jdbc.url", "jdbc:mysql://dbhost:3306/test"); - props.setProperty("org.onap.ccsdk.sli.jdbc.driver", "org.mariadb.jdbc.Driver"); - props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); - props.setProperty("org.onap.ccsdk.sli.jdbc.user", "dbuser"); - props.setProperty("org.onap.ccsdk.sli.jdbc.password", "passw0rd"); - props.setProperty("org.onap.ccsdk.sli.jdbc.connection.name", "testdb01"); - props.setProperty("org.onap.ccsdk.sli.jdbc.connection.timeout", "50"); - props.setProperty("org.onap.ccsdk.sli.jdbc.request.timeout", "100"); - props.setProperty("org.onap.ccsdk.sli.jdbc.limit.init", "10"); - props.setProperty("org.onap.ccsdk.sli.jdbc.limit.min", "10"); - props.setProperty("org.onap.ccsdk.sli.jdbc.limit.max", "20"); - props.setProperty("org.onap.dblib.connection.recovery", "false"); - } - - @Test - public void testCachedDataSource() { - BaseDBConfiguration config = new JDBCConfiguration(props); - CachedDataSource ds = new JdbcDBCachedDataSource(config); - assertNotNull(ds); - } - - @Test - public void testConfigure() { - BaseDBConfiguration config = new JDBCConfiguration(props); - - CachedDataSource ds = new JdbcDBCachedDataSource(config); - assertNotNull(ds.configure(config)); - } - - @Test - public void testSetInitialDelay() { - BaseDBConfiguration config = new JDBCConfiguration(props); - CachedDataSource ds = new JdbcDBCachedDataSource(config); - ds.setInitialDelay(1000L); - assertTrue(ds.getInitialDelay() == 1000L); - } - - @Test - public void testSetInterval() { - BaseDBConfiguration config = new JDBCConfiguration(props); - CachedDataSource ds = new JdbcDBCachedDataSource(config); - ds.setInterval(1000L); - assertTrue(ds.getInterval() == 1000L); - } - - @Test - public void testSetExpectedCompletionTime() { - BaseDBConfiguration config = new JDBCConfiguration(props); - CachedDataSource ds = new JdbcDBCachedDataSource(config); - ds.setExpectedCompletionTime(100L); - assertTrue(ds.getExpectedCompletionTime() == 100L); - } - - @Test - public void testSetUnprocessedFailoverThreshold() { - BaseDBConfiguration config = new JDBCConfiguration(props); - CachedDataSource ds = new JdbcDBCachedDataSource(config); - ds.setUnprocessedFailoverThreshold(100L); - assertTrue(ds.getUnprocessedFailoverThreshold() == 100L); - } - - @Test - public void testGetParentLogger() { - BaseDBConfiguration config = new JDBCConfiguration(props); - CachedDataSource ds = new JdbcDBCachedDataSource(config); - try { - assertNull(ds.getParentLogger()); - } catch (SQLFeatureNotSupportedException e) { - LoggerFactory.getLogger(CachedDataSourceTest.class).warn("Test Failure", e); - } - } + private static final Properties props = new Properties(); + private static BaseDBConfiguration config; + private static CachedDataSource ds; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + props.setProperty("org.onap.ccsdk.sli.dbtype", "jdbc"); + props.setProperty("org.onap.ccsdk.sli.jdbc.hosts", "localhost"); + props.setProperty("org.onap.ccsdk.sli.jdbc.url", "jdbc:mysql://dbhost:3306/test"); + props.setProperty("org.onap.ccsdk.sli.jdbc.driver", "org.mariadb.jdbc.Driver"); + props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); + props.setProperty("org.onap.ccsdk.sli.jdbc.user", "dbuser"); + props.setProperty("org.onap.ccsdk.sli.jdbc.password", "passw0rd"); + props.setProperty("org.onap.ccsdk.sli.jdbc.connection.name", "testdb01"); + props.setProperty("org.onap.ccsdk.sli.jdbc.connection.timeout", "50"); + props.setProperty("org.onap.ccsdk.sli.jdbc.request.timeout", "100"); + props.setProperty("org.onap.ccsdk.sli.jdbc.limit.init", "10"); + props.setProperty("org.onap.ccsdk.sli.jdbc.limit.min", "10"); + props.setProperty("org.onap.ccsdk.sli.jdbc.limit.max", "20"); + props.setProperty("org.onap.dblib.connection.recovery", "false"); + + config = new JDBCConfiguration(props); + ds = new JdbcDBCachedDataSource(config); + } + + @Test + public void testCachedDataSource() { + assertNotNull(ds); + } + + @Test + public void testConfigure() { + + assertNotNull(ds.configure(config)); + } + + @Test + public void testSetInitialDelay() { + ds.setInitialDelay(1000L); + assertTrue(ds.getInitialDelay() == 1000L); + } + + @Test + public void testSetInterval() { + ds.setInterval(1000L); + assertTrue(ds.getInterval() == 1000L); + } + + @Test + public void testSetExpectedCompletionTime() { + ds.setExpectedCompletionTime(100L); + assertTrue(ds.getExpectedCompletionTime() == 100L); + } + + @Test + public void testSetUnprocessedFailoverThreshold() { + ds.setUnprocessedFailoverThreshold(100L); + assertTrue(ds.getUnprocessedFailoverThreshold() == 100L); + } + + @Test + public void testGetParentLogger() { + try { + assertNull(ds.getParentLogger()); + } catch (SQLFeatureNotSupportedException e) { + LoggerFactory.getLogger(CachedDataSourceTest.class).warn("Test Failure", e); + } + } + + @Test + public void testGettersForJdbcDBCachedDataSource() { + + assertEquals("jdbc:mysql://dbhost:3306/test", ((JdbcDBCachedDataSource) ds).getDbUrl()); + assertEquals("dbuser", ((JdbcDBCachedDataSource) ds).getDbUserId()); + assertEquals("passw0rd", ((JdbcDBCachedDataSource) ds).getDbPasswd()); + assertEquals("testdb01", ((JdbcDBCachedDataSource) ds).toString()); + } }
\ No newline at end of file |