Permalink
Browse files

refactor: migrate tests to junit4 (#685)

  • Loading branch information...
AlexElin authored and vlsi committed Jan 20, 2017
1 parent b2cdd05 commit faab499853c56f67cb70fb242f75b918452f2a6f
Showing with 711 additions and 367 deletions.
  1. +3 −3 pgjdbc/src/main/java/org/postgresql/core/Parser.java
  2. +2 −0 pgjdbc/src/test/java/org/postgresql/test/jdbc2/ArrayTest.java
  3. +21 −10 pgjdbc/src/test/java/org/postgresql/test/jdbc2/BlobTest.java
  4. +12 −9 pgjdbc/src/test/java/org/postgresql/test/jdbc2/BlobTransactionTest.java
  5. +10 −5 pgjdbc/src/test/java/org/postgresql/test/jdbc2/ConnectTimeoutTest.java
  6. +12 −9 pgjdbc/src/test/java/org/postgresql/test/jdbc2/CopyLargeFileTest.java
  7. +37 −19 pgjdbc/src/test/java/org/postgresql/test/jdbc2/CopyTest.java
  8. +18 −10 pgjdbc/src/test/java/org/postgresql/test/jdbc2/DatabaseEncodingTest.java
  9. +19 −9 pgjdbc/src/test/java/org/postgresql/test/jdbc2/GeometricTest.java
  10. +15 −13 pgjdbc/src/test/java/org/postgresql/test/jdbc2/GetXXXTest.java
  11. +11 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc2/JBuilderTest.java
  12. +16 −16 pgjdbc/src/test/java/org/postgresql/test/jdbc2/Jdbc2TestSuite.java
  13. +14 −5 pgjdbc/src/test/java/org/postgresql/test/jdbc2/LoginTimeoutTest.java
  14. +12 −6 pgjdbc/src/test/java/org/postgresql/test/jdbc2/MiscTest.java
  15. +14 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc2/NotifyTest.java
  16. +53 −36 pgjdbc/src/test/java/org/postgresql/test/jdbc2/PGPropertyTest.java
  17. +15 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc2/ServerErrorTest.java
  18. +55 −18 pgjdbc/src/test/java/org/postgresql/test/jdbc2/StatementTest.java
  19. +3 −14 pgjdbc/src/test/java/org/postgresql/test/jdbc2/TestACL.java
  20. +29 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc2/TimezoneTest.java
  21. +1 −1 pgjdbc/src/test/java/org/postgresql/test/jdbc2/UpdateableResultTest.java
  22. +31 −7 pgjdbc/src/test/java/org/postgresql/test/jdbc3/CompositeQueryParseTest.java
  23. +20 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc3/CompositeTest.java
  24. +12 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc3/DatabaseMetaDataTest.java
  25. +24 −11 pgjdbc/src/test/java/org/postgresql/test/jdbc3/Jdbc3BlobTest.java
  26. +20 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc3/Jdbc3SavepointTest.java
  27. +6 −6 pgjdbc/src/test/java/org/postgresql/test/jdbc3/Jdbc3TestSuite.java
  28. +12 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc3/ResultSetTest.java
  29. +9 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc3/SendRecvBufferSizeTest.java
  30. +21 −9 pgjdbc/src/test/java/org/postgresql/test/jdbc4/BlobTest.java
  31. +17 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc4/ClientInfoTest.java
  32. +15 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc4/DatabaseMetaDataTest.java
  33. +11 −6 pgjdbc/src/test/java/org/postgresql/test/jdbc4/IsValidTest.java
  34. +7 −7 pgjdbc/src/test/java/org/postgresql/test/jdbc4/Jdbc4TestSuite.java
  35. +14 −8 pgjdbc/src/test/java/org/postgresql/test/jdbc4/PGCopyInputStreamTest.java
  36. +27 −9 pgjdbc/src/test/java/org/postgresql/test/jdbc4/WrapperTest.java
  37. +37 −11 pgjdbc/src/test/java/org/postgresql/test/jdbc4/XmlTest.java
  38. +20 −10 pgjdbc/src/test/java/org/postgresql/test/jdbc42/SetObject310Test.java
  39. +34 −11 pgjdbc/src/test/java/org/postgresql/test/xa/XADataSourceTest.java
  40. +2 −1 pgjdbc/src/test/java/org/postgresql/test/xa/XATestSuite.java
@@ -947,15 +947,15 @@ public static JdbcCallParseInfo modifyJdbcCall(String jdbcSql, boolean stdString
/**
* Filter the SQL string of Java SQL Escape clauses.
*
* <p>
* Currently implemented Escape clauses are those mentioned in 11.3 in the specification.
* Basically we look through the sql string for {d xxx}, {t xxx}, {ts xxx}, {oj xxx} or {fn xxx}
* in non-string sql code. When we find them, we just strip the escape part leaving only the xxx
* part. So, something like "select * from x where d={d '2001-10-09'}" would return "select * from
* x where d= '2001-10-09'".
*
* @param p_sql the original query text
* @param replaceProcessingEnabled whether replace_processing_enabled is on
* @param p_sql the original query text
* @param replaceProcessingEnabled whether replace_processing_enabled is on
* @param standardConformingStrings whether standard_conforming_strings is on
* @return PostgreSQL-compatible SQL
* @throws SQLException if given SQL is wrong
@@ -46,12 +46,14 @@ public ArrayTest(BinaryMode binaryMode) {
return ids;
}
@Override
public void setUp() throws Exception {
super.setUp();
conn = con;
TestUtil.createTable(conn, "arrtest", "intarr int[], decarr decimal(2,1)[], strarr text[]");
}
@Override
public void tearDown() throws SQLException {
TestUtil.dropTable(conn, "arrtest");
super.tearDown();
@@ -5,12 +5,18 @@
package org.postgresql.test.jdbc2;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.postgresql.core.ServerVersion;
import org.postgresql.largeobject.LargeObject;
import org.postgresql.largeobject.LargeObjectManager;
import org.postgresql.test.TestUtil;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.InputStream;
import java.io.OutputStream;
@@ -27,24 +33,21 @@
* Some simple tests based on problems reported by users. Hopefully these will help prevent previous
* problems from re-occurring ;-)
*/
public class BlobTest extends TestCase {
private Connection con;
public class BlobTest {
private static final int LOOP = 0; // LargeObject API using loop
private static final int NATIVE_STREAM = 1; // LargeObject API using OutputStream
public BlobTest(String name) {
super(name);
}
private Connection con;
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
con = TestUtil.openDB();
TestUtil.createTable(con, "testblob", "id name,lo oid");
con.setAutoCommit(false);
}
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
con.setAutoCommit(true);
try {
Statement stmt = con.createStatement();
@@ -62,6 +65,7 @@ protected void tearDown() throws Exception {
}
}
@Test
public void testSetNull() throws Exception {
PreparedStatement pstmt = con.prepareStatement("INSERT INTO testblob(lo) VALUES (?)");
@@ -84,6 +88,7 @@ public void testSetNull() throws Exception {
pstmt.executeUpdate();
}
@Test
public void testSet() throws SQLException {
Statement stmt = con.createStatement();
stmt.execute("INSERT INTO testblob(id,lo) VALUES ('1', lo_creat(-1))");
@@ -126,6 +131,7 @@ public void testSet() throws SQLException {
/*
* Tests one method of uploading a blob to the database
*/
@Test
public void testUploadBlob_LOOP() throws Exception {
assertTrue(uploadFile("/test-file.xml", LOOP) > 0);
@@ -139,6 +145,7 @@ public void testUploadBlob_LOOP() throws Exception {
/*
* Tests one method of uploading a blob to the database
*/
@Test
public void testUploadBlob_NATIVE() throws Exception {
assertTrue(uploadFile("/test-file.xml", NATIVE_STREAM) > 0);
@@ -147,6 +154,7 @@ public void testUploadBlob_NATIVE() throws Exception {
assertTrue(compareBlobs());
}
@Test
public void testGetBytesOffset() throws Exception {
assertTrue(uploadFile("/test-file.xml", NATIVE_STREAM) > 0);
@@ -163,6 +171,7 @@ public void testGetBytesOffset() throws Exception {
assertEquals(data[3], 'l');
}
@Test
public void testMultipleStreams() throws Exception {
assertTrue(uploadFile("/test-file.xml", NATIVE_STREAM) > 0);
@@ -186,6 +195,7 @@ public void testMultipleStreams() throws Exception {
is.close();
}
@Test
public void testParallelStreams() throws Exception {
assertTrue(uploadFile("/test-file.xml", NATIVE_STREAM) > 0);
@@ -210,6 +220,7 @@ public void testParallelStreams() throws Exception {
is2.close();
}
@Test
public void testLargeLargeObject() throws Exception {
if (!TestUtil.haveMinimumServerVersion(con, ServerVersion.v9_3)) {
return;
@@ -5,9 +5,14 @@
package org.postgresql.test.jdbc2;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.postgresql.test.TestUtil;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
@@ -26,16 +31,12 @@
* Test that oid/lob are accessible in concurrent connection, in presence of the lo_manage trigger
* Require the lo module accessible in $libdir
*/
public class BlobTransactionTest extends TestCase {
public class BlobTransactionTest {
private Connection con;
private Connection con2;
public BlobTransactionTest(String name) {
super(name);
}
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
con = TestUtil.openDB();
con.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
con2 = TestUtil.openDB();
@@ -73,7 +74,8 @@ protected void setUp() throws Exception {
con2.setAutoCommit(false);
}
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
TestUtil.closeDB(con2);
con.setAutoCommit(true);
@@ -115,6 +117,7 @@ protected void tearDown() throws Exception {
return Arrays.copyOf(result, readPos);
}
@Test
public void testConcurrentReplace() throws SQLException, IOException {
// Statement stmt = con.createStatement();
// stmt.execute("INSERT INTO testblob(id,lo) VALUES ('1', lo_creat(-1))");
@@ -5,27 +5,32 @@
package org.postgresql.test.jdbc2;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.postgresql.test.TestUtil;
import junit.framework.TestCase;
import org.junit.Before;
import org.junit.Test;
import java.net.SocketTimeoutException;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
public class ConnectTimeoutTest extends TestCase {
public class ConnectTimeoutTest {
// The IP below is non-routable (see http://stackoverflow.com/a/904609/1261287)
private static final String UNREACHABLE_HOST = "10.255.255.1";
private static final String UNREACHABLE_URL = "jdbc:postgresql://" + UNREACHABLE_HOST + ":5432/test";
private static final int CONNECT_TIMEOUT = 5;
@Override
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
TestUtil.initDriver();
}
@Test
public void testTimeout() {
final Properties props = new Properties();
props.setProperty("user", "test");
@@ -5,13 +5,17 @@
package org.postgresql.test.jdbc2;
import static org.junit.Assert.assertEquals;
import org.postgresql.PGConnection;
import org.postgresql.copy.CopyManager;
import org.postgresql.test.TestUtil;
import org.postgresql.test.util.BufferGenerator;
import org.postgresql.test.util.StrangeInputStream;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
@@ -22,19 +26,17 @@
import java.sql.SQLException;
/**
* Created by amozhenin on 30.09.2015.
* @author amozhenin on 30.09.2015.
*/
public class CopyLargeFileTest extends TestCase {
public class CopyLargeFileTest {
private static final int FEED_COUNT = 10;
private Connection con;
private CopyManager copyAPI;
protected void setUp() throws Exception {
super.setUp();
@Before
public void setUp() throws Exception {
con = TestUtil.openDB();
TestUtil.createTable(con, "pgjdbc_issue366_test_glossary",
@@ -66,8 +68,8 @@ private void insertData(PreparedStatement stmt, String textId, String name) thro
stmt.executeUpdate();
}
protected void tearDown() throws Exception {
super.tearDown();
@After
public void tearDown() throws Exception {
try {
TestUtil.dropTable(con, "pgjdbc_issue366_test_data");
TestUtil.dropTable(con, "pgjdbc_issue366_test_glossary");
@@ -77,6 +79,7 @@ protected void tearDown() throws Exception {
}
}
@Test
public void testFeedTableSeveralTimesTest() throws Exception {
for (int i = 1; i <= FEED_COUNT; i++) {
feedTableAndCheckTableFeedIsOk(con);
Oops, something went wrong.

0 comments on commit faab499

Please sign in to comment.