From cdd9c11b89444735350eed52d412caf3f6d85c16 Mon Sep 17 00:00:00 2001 From: Sandeep J Date: Mon, 24 Sep 2018 01:28:16 +0530 Subject: added test cases to TestDBResourceManager to increase code coverage Issue-ID: CCSDK-595 Change-Id: I8def1aa2e4108f48bc549e63e533f8a63e7a0377 Signed-off-by: Sandeep J --- .../sli/core/dblib/TestDBResourceManager.java | 63 +++++++++++++--------- 1 file changed, 39 insertions(+), 24 deletions(-) (limited to 'dblib/provider/src') diff --git a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/TestDBResourceManager.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/TestDBResourceManager.java index dca07921b..8d7d34324 100644 --- a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/TestDBResourceManager.java +++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/TestDBResourceManager.java @@ -4,6 +4,7 @@ import static org.junit.Assert.*; import java.io.InputStream; import java.net.URL; +import java.sql.SQLException; import java.util.Properties; import org.junit.Before; @@ -14,42 +15,56 @@ import ch.vorburger.mariadb4j.DBConfigurationBuilder; public class TestDBResourceManager { - DbLibService dblibSvc; + DbLibService dblibSvc; + DBResourceManager dbm; - @Before - public void setUp() throws Exception { - URL propUrl = getClass().getResource("/dblib.properties"); + @Before + public void setUp() throws Exception { + URL propUrl = getClass().getResource("/dblib.properties"); - InputStream propStr = getClass().getResourceAsStream("/dblib.properties"); + InputStream propStr = getClass().getResourceAsStream("/dblib.properties"); - Properties props = new Properties(); + Properties props = new Properties(); - props.load(propStr); + props.load(propStr); + // Start MariaDB4j database + DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); + config.setPort(0); // 0 => autom. detect free port + DB db = DB.newEmbeddedDB(config.build()); + db.start(); - // Start MariaDB4j database - DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); - config.setPort(0); // 0 => autom. detect free port - DB db = DB.newEmbeddedDB(config.build()); - db.start(); + // Override jdbc URL and database name + props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); + props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); + dblibSvc = new DBResourceManager(props); + dbm = new DBResourceManager(props); + dblibSvc.writeData("CREATE TABLE DBLIB_TEST (name varchar(20));", null, null); + dblibSvc.getData("SELECT * FROM DBLIB_TEST", null, null); - // Override jdbc URL and database name - props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); - props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); + } + @Test + public void testForceRecovery() { + dbm.testForceRecovery(); + } - dblibSvc = new DBResourceManager(props); + @Test + public void testGetConnection() throws SQLException { + assertNotNull(dbm.getConnection()); + assertNotNull(dbm.getConnection("testUser", "testPaswd")); + } - dblibSvc.writeData("CREATE TABLE DBLIB_TEST (name varchar(20));", null, null); - dblibSvc.getData("SELECT * FROM DBLIB_TEST", null, null); + @Test + public void testCleanup() { + dbm.cleanUp(); - } + } - @Test - public void test() { - - - } + @Test + public void testGetLogWriter() throws SQLException { + assertNull(dbm.getLogWriter()); + } } -- cgit 1.2.3-korg