From 2689f9392e7864cc5f87f1268c5a1e7494655b22 Mon Sep 17 00:00:00 2001 From: wenshao Date: Tue, 28 Aug 2012 08:59:35 +0800 Subject: [PATCH] add DruidDataSourceC3P0Adapter.java testcase --- .../pool/DruidDataSourceC3P0Adapter.java | 6 +- .../pool/DruidDataSourceC3P0AdapterTest.java | 81 +++++++++++++++++++ 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/alibaba/druid/pool/DruidDataSourceC3P0Adapter.java b/src/main/java/com/alibaba/druid/pool/DruidDataSourceC3P0Adapter.java index 4f6b25ab20..dba9e942e3 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidDataSourceC3P0Adapter.java +++ b/src/main/java/com/alibaba/druid/pool/DruidDataSourceC3P0Adapter.java @@ -279,8 +279,6 @@ public class DruidDataSourceC3P0Adapter implements DataSource, DruidDataSourceC3 } public void setMaxStatementsPerConnection(int maxStatementsPerConnection) { - dataSource.setPoolPreparedStatements(maxStatementsPerConnection > 0); - dataSource.setMaxPoolPreparedStatementPerConnectionSize(maxStatementsPerConnection); } @@ -289,8 +287,6 @@ public class DruidDataSourceC3P0Adapter implements DataSource, DruidDataSourceC3 } public void setMaxStatements(int maxStatements) { - dataSource.setPoolPreparedStatements(maxStatements > 0); - dataSource.setMaxOpenPreparedStatements(maxStatements); } @@ -493,6 +489,6 @@ public class DruidDataSourceC3P0Adapter implements DataSource, DruidDataSourceC3 } public Logger getParentLogger() throws SQLFeatureNotSupportedException { - throw new SQLFeatureNotSupportedException(); + return dataSource.getParentLogger(); } } diff --git a/src/test/java/com/alibaba/druid/bvt/pool/DruidDataSourceC3P0AdapterTest.java b/src/test/java/com/alibaba/druid/bvt/pool/DruidDataSourceC3P0AdapterTest.java index d98421fae1..4ada4a1e46 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/DruidDataSourceC3P0AdapterTest.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/DruidDataSourceC3P0AdapterTest.java @@ -1,6 +1,7 @@ package com.alibaba.druid.bvt.pool; import java.sql.Connection; +import java.sql.SQLFeatureNotSupportedException; import org.junit.Assert; @@ -46,4 +47,84 @@ public class DruidDataSourceC3P0AdapterTest extends TestCase { public void test_getJdbcUrl() throws Exception { Assert.assertEquals("jdbc:mock:xxx", dataSource.getJdbcUrl()); } + + public void test_getParentLogger_err() throws Exception { + Exception error = null; + try { + dataSource.getParentLogger(); + } catch (SQLFeatureNotSupportedException e) { + error = e; + } + Assert.assertNotNull(error); + } + + public void test_propertyCycle() throws Exception { + dataSource.setPropertyCycle(3); + Assert.assertEquals(3, dataSource.getPropertyCycle()); + } + + public void test_acquireIncrement() throws Exception { + dataSource.setAcquireIncrement(4); + Assert.assertEquals(4, dataSource.getAcquireIncrement()); + } + + public void test_overrideDefaultPassword() throws Exception { + dataSource.setOverrideDefaultPassword("x2"); + Assert.assertEquals("x2", dataSource.getOverrideDefaultPassword()); + } + + public void test_overrideDefaultUser() throws Exception { + dataSource.setOverrideDefaultUser("x1"); + Assert.assertEquals("x1", dataSource.getOverrideDefaultUser()); + } + + public void test_factoryClassLocation() throws Exception { + dataSource.setFactoryClassLocation("x3"); + Assert.assertEquals("x3", dataSource.getFactoryClassLocation()); + } + + public void test_maxConnectionAge() throws Exception { + dataSource.setMaxConnectionAge(123); + Assert.assertEquals(123, dataSource.getMaxConnectionAge()); + } + + public void test_connectionCustomizerClassName() throws Exception { + dataSource.setConnectionCustomizerClassName("x4"); + Assert.assertEquals("x4", dataSource.getConnectionCustomizerClassName()); + } + + public void test_maxIdleTimeExcessConnections() throws Exception { + dataSource.setMaxIdleTimeExcessConnections(101); + Assert.assertEquals(101, dataSource.getMaxIdleTimeExcessConnections()); + } + + public void test_maxAdministrativeTaskTime() throws Exception { + dataSource.setMaxAdministrativeTaskTime(102); + Assert.assertEquals(102, dataSource.getMaxAdministrativeTaskTime()); + } + + public void test_userOverridesAsString() throws Exception { + dataSource.setUserOverridesAsString("x5"); + Assert.assertEquals("x5", dataSource.getUserOverridesAsString()); + } + + public void test_usesTraditionalReflectiveProxies() throws Exception { + dataSource.setUsesTraditionalReflectiveProxies(true); + Assert.assertEquals(true, dataSource.isUsesTraditionalReflectiveProxies()); + } + + public void test_forceIgnoreUnresolvedTransactions() throws Exception { + dataSource.setForceIgnoreUnresolvedTransactions(true); + Assert.assertEquals(true, dataSource.isForceIgnoreUnresolvedTransactions()); + } + + public void test_automaticTestTable() throws Exception { + dataSource.setAutomaticTestTable("x6"); + Assert.assertEquals("x6", dataSource.getAutomaticTestTable()); + } + + public void test_connectionTesterClassName() throws Exception { + dataSource.setConnectionTesterClassName("x6"); + Assert.assertEquals("x6", dataSource.getConnectionTesterClassName()); + } }