Skip to content

Commit

Permalink
test: add tests for getBigDecimal of int4 field in both text and bina…
Browse files Browse the repository at this point in the history
…ry modes
  • Loading branch information
vlsi committed Nov 13, 2015
1 parent 6eaedec commit faac288
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 127 deletions.
18 changes: 18 additions & 0 deletions org/postgresql/test/CursorFetchBinaryTest.java
@@ -0,0 +1,18 @@
package org.postgresql.test;

import java.util.Properties;

import org.postgresql.test.jdbc2.CursorFetchTest;

public class CursorFetchBinaryTest extends CursorFetchTest {
public CursorFetchBinaryTest(String name)
{
super(name);
}

@Override
protected void updateProperties(Properties props)
{
forceBinary(props);
}
}
48 changes: 48 additions & 0 deletions org/postgresql/test/jdbc2/BaseTest.java
@@ -0,0 +1,48 @@
package org.postgresql.test.jdbc2;

import junit.framework.TestCase;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import org.postgresql.PGProperty;
import org.postgresql.test.TestUtil;

public class BaseTest extends TestCase {
protected Connection con;

public BaseTest(String name)
{
super(name);

try
{
new org.postgresql.Driver();
}
catch (Exception ex)
{
/* ignore */
}
}

protected void updateProperties(Properties props) {
}

protected void forceBinary(Properties props)
{
PGProperty.PREPARE_THRESHOLD.set(props, -1);
}

protected void setUp() throws Exception
{
Properties props = new Properties();
updateProperties(props);
con = TestUtil.openDB(props);
}

protected void tearDown() throws SQLException
{
TestUtil.closeDB(con);
}
}
16 changes: 16 additions & 0 deletions org/postgresql/test/jdbc2/BatchExecuteBinaryTest.java
@@ -0,0 +1,16 @@
package org.postgresql.test.jdbc2;

import java.util.Properties;

public class BatchExecuteBinaryTest extends BatchExecuteTest {
public BatchExecuteBinaryTest(String name)
{
super(name);
}

@Override
protected void updateProperties(Properties props)
{
forceBinary(props);
}
}
31 changes: 10 additions & 21 deletions org/postgresql/test/jdbc2/BatchExecuteTest.java
Expand Up @@ -7,18 +7,14 @@
*/
package org.postgresql.test.jdbc2;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.sql.BatchUpdateException;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.junit.Test;
import org.postgresql.test.TestUtil;
import org.postgresql.util.PSQLException;

import junit.framework.TestCase;

import java.sql.*;

/* TODO tests that can be added to this test case
* - SQLExceptions chained to a BatchUpdateException
Expand All @@ -28,26 +24,19 @@
/*
* Test case for Statement.batchExecute()
*/
public class BatchExecuteTest extends TestCase
public class BatchExecuteTest extends BaseTest
{

private Connection con;

public BatchExecuteTest(String name)
{
super(name);
try
{
Class.forName("org.postgresql.Driver");
}
catch( Exception ex){}
}

// Set up the fixture for this testcase: a connection to a database with
// a table for this test.
protected void setUp() throws Exception
{
con = TestUtil.openDB();
super.setUp();
Statement stmt = con.createStatement();

// Drop the test table if it already exists for some reason. It is
Expand All @@ -65,12 +54,12 @@ protected void setUp() throws Exception
}

// Tear down the fixture for this test case.
protected void tearDown() throws Exception
protected void tearDown() throws SQLException
{
con.setAutoCommit(true);

TestUtil.dropTable(con, "testbatch");
TestUtil.closeDB(con);
super.tearDown();
}

public void testSupportsBatchUpdates() throws Exception
Expand Down
12 changes: 4 additions & 8 deletions org/postgresql/test/jdbc2/CursorFetchTest.java
Expand Up @@ -9,37 +9,33 @@

import java.sql.*;

import junit.framework.TestCase;

import org.postgresql.test.TestUtil;

/*
* Tests for using non-zero setFetchSize().
*/
public class CursorFetchTest extends TestCase
public class CursorFetchTest extends BaseTest
{
private Connection con;

public CursorFetchTest(String name)
{
super(name);
}

protected void setUp() throws Exception
{
con = TestUtil.openDB();
super.setUp();
TestUtil.createTable(con, "test_fetch", "value integer");
con.setAutoCommit(false);
}

protected void tearDown() throws Exception
protected void tearDown() throws SQLException
{
if (!con.getAutoCommit())
con.rollback();

con.setAutoCommit(true);
TestUtil.dropTable(con, "test_fetch");
TestUtil.closeDB(con);
super.tearDown();
}

protected void createRows(int count) throws Exception
Expand Down
4 changes: 4 additions & 0 deletions org/postgresql/test/jdbc2/Jdbc2TestSuite.java
Expand Up @@ -11,6 +11,7 @@

import junit.framework.TestSuite;

import org.postgresql.test.CursorFetchBinaryTest;
import org.postgresql.test.TestUtil;

/*
Expand Down Expand Up @@ -64,13 +65,15 @@ public static TestSuite suite() throws Exception

// PreparedStatement
suite.addTestSuite(PreparedStatementTest.class);
suite.addTestSuite(PreparedStatementBinaryTest.class);
suite.addTestSuite(StatementTest.class);

// ServerSide Prepared Statements
suite.addTestSuite(ServerPreparedStmtTest.class);

// BatchExecute
suite.addTestSuite(BatchExecuteTest.class);
suite.addTestSuite(BatchExecuteBinaryTest.class);


// Other misc tests, based on previous problems users have had or specific
Expand All @@ -89,6 +92,7 @@ public static TestSuite suite() throws Exception

suite.addTestSuite(CallableStmtTest.class );
suite.addTestSuite(CursorFetchTest.class);
suite.addTestSuite(CursorFetchBinaryTest.class);
suite.addTestSuite(ServerCursorTest.class);

suite.addTestSuite(IntervalTest.class);
Expand Down
16 changes: 16 additions & 0 deletions org/postgresql/test/jdbc2/PreparedStatementBinaryTest.java
@@ -0,0 +1,16 @@
package org.postgresql.test.jdbc2;

import java.util.Properties;

public class PreparedStatementBinaryTest extends PreparedStatementTest {
public PreparedStatementBinaryTest(String name)
{
super(name);
}

@Override
protected void updateProperties(Properties props)
{
forceBinary(props);
}
}

0 comments on commit faac288

Please sign in to comment.