Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: migrate to Junit4 #883

Merged
merged 7 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pgjdbc/src/test/java/org/postgresql/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,11 @@ In your test method you can use the fixture that is setup for it
by the test case.

If you decide to add a new test case, you should do two things:
1) Add a class that extends junit.framework.TestCase. It should
1) Add a test class. It should
contain setUp() and tearDown() methods that create and destroy
the fixture respectively.
2) Edit $JDBC_SRC/org/postgresql/test/jdbc2/Jdbc2TestSuite.java or
$JDBC_SRC/org/postgresql/test/jdbc3/Jdbc3TestSuite.java and add a
suite.addTestSuite() call for your class. This will make the test case
$JDBC_SRC/org/postgresql/test/jdbc3/Jdbc3TestSuite.java and add your class. This will make the test case
part of the test suite.

6 Guidelines for developing new tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,14 @@

package org.postgresql.test.extensions;

import org.postgresql.test.TestUtil;

import junit.framework.JUnit4TestAdapter;
import junit.framework.TestSuite;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

/*
* Executes all known tests for PostgreSQL extensions supported by JDBC driver
*/
public class ExtensionsTestSuite extends TestSuite {

/*
* The main entry point for JUnit
*/
public static TestSuite suite() throws Exception {
TestSuite suite = new TestSuite();

Connection connection = TestUtil.openDB();
try {
if (isHStoreEnabled(connection)) {
suite.addTest(new JUnit4TestAdapter(HStoreTest.class));
}
} finally {
connection.close();
}

return suite;
}

/**
* Not all servers have hstore extensions installed.
*/
private static boolean isHStoreEnabled(Connection conn) {
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 'a=>1'::hstore::text");
rs.close();
stmt.close();
return true;
} catch (SQLException sqle) {
return false;
}
}

@RunWith(Suite.class)
@Suite.SuiteClasses(HStoreTest.class)
public class ExtensionsTestSuite {
}

28 changes: 17 additions & 11 deletions pgjdbc/src/test/java/org/postgresql/test/extensions/HStoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -31,26 +32,31 @@

public class HStoreTest extends BaseTest4 {

private Connection _conn;

@Override
public void setUp() throws Exception {
super.setUp();
_conn = con;
Assume.assumeTrue("server has installed hstore", isHStoreEnabled(con));
Assume.assumeFalse("hstore is not supported in simple protocol only mode",
preferQueryMode == PreferQueryMode.SIMPLE);
Assume.assumeTrue("hstore requires PostgreSQL 8.3+",
TestUtil.haveMinimumServerVersion(con, ServerVersion.v8_3));
}

@Override
public void tearDown() throws SQLException {
TestUtil.closeDB(_conn);
private static boolean isHStoreEnabled(Connection conn) {
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 'a=>1'::hstore::text");
rs.close();
stmt.close();
return true;
} catch (SQLException sqle) {
return false;
}
}

@Test
public void testHStoreSelect() throws SQLException {
PreparedStatement pstmt = _conn.prepareStatement("SELECT 'a=>1,b=>2'::hstore");
PreparedStatement pstmt = con.prepareStatement("SELECT 'a=>1,b=>2'::hstore");
ResultSet rs = pstmt.executeQuery();
assertEquals(Map.class.getName(), rs.getMetaData().getColumnClassName(1));
assertTrue(rs.next());
Expand All @@ -66,7 +72,7 @@ public void testHStoreSelect() throws SQLException {

@Test
public void testHStoreSelectNullValue() throws SQLException {
PreparedStatement pstmt = _conn.prepareStatement("SELECT 'a=>NULL'::hstore");
PreparedStatement pstmt = con.prepareStatement("SELECT 'a=>NULL'::hstore");
ResultSet rs = pstmt.executeQuery();
assertEquals(Map.class.getName(), rs.getMetaData().getColumnClassName(1));
assertTrue(rs.next());
Expand All @@ -78,7 +84,7 @@ public void testHStoreSelectNullValue() throws SQLException {
@Test
public void testHStoreSend() throws SQLException {
Map<String, Integer> correct = Collections.singletonMap("a", 1);
PreparedStatement pstmt = _conn.prepareStatement("SELECT ?::text");
PreparedStatement pstmt = con.prepareStatement("SELECT ?::text");
pstmt.setObject(1, correct);
ResultSet rs = pstmt.executeQuery();
assertEquals(String.class.getName(), rs.getMetaData().getColumnClassName(1));
Expand All @@ -89,7 +95,7 @@ public void testHStoreSend() throws SQLException {
@Test
public void testHStoreUsingPSSetObject4() throws SQLException {
Map<String, Integer> correct = Collections.singletonMap("a", 1);
PreparedStatement pstmt = _conn.prepareStatement("SELECT ?::text");
PreparedStatement pstmt = con.prepareStatement("SELECT ?::text");
pstmt.setObject(1, correct, Types.OTHER, -1);
ResultSet rs = pstmt.executeQuery();
assertEquals(String.class.getName(), rs.getMetaData().getColumnClassName(1));
Expand All @@ -100,7 +106,7 @@ public void testHStoreUsingPSSetObject4() throws SQLException {
@Test
public void testHStoreSendEscaped() throws SQLException {
Map<String, String> correct = Collections.singletonMap("a", "t'e\ns\"t");
PreparedStatement pstmt = _conn.prepareStatement("SELECT ?");
PreparedStatement pstmt = con.prepareStatement("SELECT ?");
pstmt.setObject(1, correct);
ResultSet rs = pstmt.executeQuery();
assertEquals(Map.class.getName(), rs.getMetaData().getColumnClassName(1));
Expand Down
218 changes: 96 additions & 122 deletions pgjdbc/src/test/java/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,139 +7,113 @@

import org.postgresql.core.ParserTest;
import org.postgresql.core.ReturningParserTest;
import org.postgresql.core.ServerVersion;
import org.postgresql.core.v3.V3ParameterListTests;
import org.postgresql.jdbc.DeepBatchedInsertStatementTest;
import org.postgresql.test.TestUtil;
import org.postgresql.test.core.NativeQueryBindLengthTest;
import org.postgresql.test.util.ExpressionPropertiesTest;
import org.postgresql.test.util.LruCacheTest;
import org.postgresql.test.util.ServerVersionParseTest;
import org.postgresql.test.util.ServerVersionTest;
import org.postgresql.util.ReaderInputStreamTest;

import junit.framework.JUnit4TestAdapter;
import junit.framework.TestSuite;

import java.sql.Connection;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

/*
* Executes all known tests for JDBC2 and includes some utility methods.
*/
public class Jdbc2TestSuite extends TestSuite {

/*
* The main entry point for JUnit
*/
public static TestSuite suite() throws Exception {
TestSuite suite = new TestSuite();

//
// Add one line per class in our test cases. These should be in order of
// complexity.

// ANTTest should be first as it ensures that test parameters are
// being sent to the suite.
//
suite.addTest(new JUnit4TestAdapter(ANTTest.class));

// Basic Driver internals
suite.addTest(new JUnit4TestAdapter(DriverTest.class));
suite.addTest(new JUnit4TestAdapter(ConnectionTest.class));
suite.addTest(new JUnit4TestAdapter(DatabaseMetaDataTest.class));
suite.addTest(new JUnit4TestAdapter(DatabaseMetaDataPropertiesTest.class));
suite.addTest(new JUnit4TestAdapter(SearchPathLookupTest.class));
suite.addTest(new JUnit4TestAdapter(EncodingTest.class));
suite.addTest(new JUnit4TestAdapter(ExpressionPropertiesTest.class));
suite.addTest(new JUnit4TestAdapter(ColumnSanitiserDisabledTest.class));
suite.addTest(new JUnit4TestAdapter(ColumnSanitiserEnabledTest.class));
suite.addTest(new JUnit4TestAdapter(LruCacheTest.class));
suite.addTest(new JUnit4TestAdapter(ReaderInputStreamTest.class));
suite.addTest(new JUnit4TestAdapter(ServerVersionParseTest.class));
suite.addTest(new JUnit4TestAdapter(ServerVersionTest.class));

// Connectivity/Protocols

suite.addTest(new JUnit4TestAdapter(TypeCacheDLLStressTest.class));

// ResultSet
suite.addTest(new JUnit4TestAdapter(ResultSetTest.class));
suite.addTest(new JUnit4TestAdapter(ResultSetMetaDataTest.class));
suite.addTest(new JUnit4TestAdapter(ArrayTest.class));
suite.addTest(new JUnit4TestAdapter(RefCursorTest.class));

// Time, Date, Timestamp, PGTime, PGTimestamp
suite.addTest(new JUnit4TestAdapter(DateTest.class));
suite.addTest(new JUnit4TestAdapter(TimeTest.class));
suite.addTest(new JUnit4TestAdapter(TimestampTest.class));
suite.addTest(new JUnit4TestAdapter(TimezoneTest.class));
suite.addTest(new JUnit4TestAdapter(PGTimeTest.class));
suite.addTest(new JUnit4TestAdapter(PGTimestampTest.class));
suite.addTest(new JUnit4TestAdapter(TimezoneCachingTest.class));
suite.addTest(new JUnit4TestAdapter(ParserTest.class));
suite.addTest(new JUnit4TestAdapter(ReturningParserTest.class));

// PreparedStatement
suite.addTest(new JUnit4TestAdapter(PreparedStatementTest.class));
suite.addTest(new JUnit4TestAdapter(StatementTest.class));
suite.addTest(new JUnit4TestAdapter(QuotationTest.class));

// ServerSide Prepared Statements
suite.addTest(new JUnit4TestAdapter(ServerPreparedStmtTest.class));

// BatchExecute
suite.addTest(new JUnit4TestAdapter(BatchExecuteTest.class));
suite.addTest(new JUnit4TestAdapter(BatchFailureTest.class));

suite.addTest(new JUnit4TestAdapter(BatchedInsertReWriteEnabledTest.class));
suite.addTest(new JUnit4TestAdapter(NativeQueryBindLengthTest.class));
suite.addTest(new JUnit4TestAdapter(DeepBatchedInsertStatementTest.class));

// Other misc tests, based on previous problems users have had or specific
// features some applications require.
suite.addTest(new JUnit4TestAdapter(JBuilderTest.class));
suite.addTest(new JUnit4TestAdapter(MiscTest.class));
suite.addTest(new JUnit4TestAdapter(NotifyTest.class));
suite.addTest(new JUnit4TestAdapter(DatabaseEncodingTest.class));

// Fastpath/LargeObject
suite.addTest(new JUnit4TestAdapter(BlobTest.class));
suite.addTest(new JUnit4TestAdapter(BlobTransactionTest.class));

suite.addTest(new JUnit4TestAdapter(UpdateableResultTest.class));

suite.addTest(new JUnit4TestAdapter(CallableStmtTest.class));
suite.addTest(new JUnit4TestAdapter(CursorFetchTest.class));
suite.addTest(new JUnit4TestAdapter(ConcurrentStatementFetch.class));
suite.addTest(new JUnit4TestAdapter(ServerCursorTest.class));

suite.addTest(new JUnit4TestAdapter(IntervalTest.class));
suite.addTest(new JUnit4TestAdapter(GeometricTest.class));

suite.addTest(new JUnit4TestAdapter(LoginTimeoutTest.class));
suite.addTest(new JUnit4TestAdapter(TestACL.class));

suite.addTest(new JUnit4TestAdapter(ConnectTimeoutTest.class));

suite.addTest(new JUnit4TestAdapter(PGPropertyTest.class));

suite.addTest(new JUnit4TestAdapter(V3ParameterListTests.class));

Connection conn = TestUtil.openDB();
suite.addTest(new JUnit4TestAdapter(CopyTest.class));
suite.addTest(new JUnit4TestAdapter(CopyLargeFileTest.class));

if (TestUtil.haveMinimumServerVersion(conn, ServerVersion.v9_3)) {
suite.addTest(new JUnit4TestAdapter(ServerErrorTest.class));
}

if (TestUtil.haveMinimumServerVersion(conn, ServerVersion.v9_5)) {
suite.addTest(new JUnit4TestAdapter(UpsertTest.class));
}

conn.close();

// That's all folks
return suite;
}
@RunWith(Suite.class)
@Suite.SuiteClasses({
ANTTest.class,

DriverTest.class,
ConnectionTest.class,
DatabaseMetaDataTest.class,
DatabaseMetaDataPropertiesTest.class,
SearchPathLookupTest.class,
EncodingTest.class,
ExpressionPropertiesTest.class,
ColumnSanitiserDisabledTest.class,
ColumnSanitiserEnabledTest.class,
LruCacheTest.class,
ReaderInputStreamTest.class,
ServerVersionParseTest.class,
ServerVersionTest.class,

DriverTest.class,
ConnectionTest.class,
DatabaseMetaDataTest.class,
DatabaseMetaDataPropertiesTest.class,
SearchPathLookupTest.class,
EncodingTest.class,
ExpressionPropertiesTest.class,
ColumnSanitiserDisabledTest.class,
ColumnSanitiserEnabledTest.class,
LruCacheTest.class,
ReaderInputStreamTest.class,
ServerVersionParseTest.class,
ServerVersionTest.class,

TypeCacheDLLStressTest.class,

ResultSetTest.class,
ResultSetMetaDataTest.class,
ArrayTest.class,
RefCursorTest.class,

DateTest.class,
TimeTest.class,
TimestampTest.class,
TimezoneTest.class,
PGTimeTest.class,
PGTimestampTest.class,
TimezoneCachingTest.class,
ParserTest.class,
ReturningParserTest.class,

PreparedStatementTest.class,
StatementTest.class,
QuotationTest.class,

ServerPreparedStmtTest.class,

BatchExecuteTest.class,
BatchFailureTest.class,

BatchedInsertReWriteEnabledTest.class,
NativeQueryBindLengthTest.class,
DeepBatchedInsertStatementTest.class,
JBuilderTest.class,
MiscTest.class,
NotifyTest.class,
DatabaseEncodingTest.class,

BlobTest.class,
BlobTransactionTest.class,

UpdateableResultTest.class,

CallableStmtTest.class,
CursorFetchTest.class,
ConcurrentStatementFetch.class,
ServerCursorTest.class,

IntervalTest.class,
GeometricTest.class,

LoginTimeoutTest.class,
TestACL.class,

ConnectTimeoutTest.class,

PGPropertyTest.class,

V3ParameterListTests.class,

CopyTest.class,
CopyLargeFileTest.class,
ServerErrorTest.class,
UpsertTest.class
})
public class Jdbc2TestSuite {
}
Loading