Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ca5d71c

Browse files
author
Peter Mount
committed
Some updates prior to retrieving a fresh cvs copy:
Tue Feb 06 19:00:00 GMT 2001 peter@retep.org.uk - Completed first two TestCase's for the test suite. JUnit is now recognised by ant.
1 parent 90670eb commit ca5d71c

File tree

8 files changed

+388
-5
lines changed

8 files changed

+388
-5
lines changed

src/interfaces/jdbc/CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Tue Feb 06 19:00:00 GMT 2001 peter@retep.org.uk
2+
- Completed first two TestCase's for the test suite. JUnit is now
3+
recognised by ant.
4+
15
Wed Jan 31 08:46:00 GMT 2001 peter@retep.org.uk
26
- Some minor additions to Statement to make our own extensions more
37
portable.

src/interfaces/jdbc/build.xml

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
build file to allow ant (http://jakarta.apache.org/ant/) to be used
44
to build the PostgreSQL JDBC Driver.
55
6-
$Id: build.xml,v 1.4 2001/01/18 17:37:11 peter Exp $
6+
$Id: build.xml,v 1.5 2001/02/07 09:13:20 peter Exp $
77
88
-->
99

@@ -17,6 +17,17 @@
1717
<property name="major" value="7" />
1818
<property name="minor" value="1" />
1919

20+
<!--
21+
defaults for the tests - overide these if required
22+
junit.ui is one of textui, awtui or swingui
23+
24+
password must be something. Doesnt matter if trust is used!
25+
-->
26+
<property name="database" value="jdbc:postgresql:test" />
27+
<property name="username" value="test" />
28+
<property name="password" value="password" />
29+
<property name="junit.ui" value="textui" />
30+
2031
<!--
2132
This is a simpler method than utils.CheckVersion
2233
It defaults to jdbc1, but builds jdbc2 if the java.lang.Byte class is
@@ -29,6 +40,7 @@
2940
<available property="jdk1.2+" classname="java.lang.ThreadLocal" />
3041
<available property="jdk1.3+" classname="java.lang.StrictMath" />
3142
<available property="jdk1.2e+" classname="javax.sql.DataSource" />
43+
<available property="junit" classname="junit.framework.Test" />
3244
</target>
3345

3446
<!--
@@ -47,6 +59,10 @@
4759
<property name="connectclass" value="org.postgresql.jdbc1.Connection" />
4860
<available property="connectclass" value="org.postgresql.jdbc2.Connection" classname="java.lang.ThreadLocal" />
4961

62+
<!-- comment out 1.3+ stuff -->
63+
<property name="jdk13only" value="//" />
64+
<available property="jdk13only" value="" classname="java.lang.StrictMath" />
65+
5066
<!-- Some defaults -->
5167
<filter token="MAJORVERSION" value="${major}" />
5268
<filter token="MINORVERSION" value="${minor}" />
@@ -86,6 +102,7 @@
86102
<exclude name="${package}/largeobject/PGblob.java" unless="jdk1.2+" />
87103
<exclude name="${package}/PostgresqlDataSource.java" unless="jdk1.2e+" />
88104
<exclude name="${package}/xa/**" unless="jdk1.2e+" />
105+
<exclude name="${package}/test/**" unless="junit" />
89106
</javac>
90107
<copy todir="${dest}" overwrite="true" filtering="on">
91108
<fileset dir="${src}">
@@ -115,7 +132,7 @@
115132

116133
<!-- This builds the jar file containing the driver -->
117134
<target name="jar" depends="compile,examples">
118-
<jar jarfile="${jars}/postgresql.jar" basedir="${dest}" includes="org/**" />
135+
<jar jarfile="${jars}/postgresql.jar" basedir="${dest}" includes="${package}/**" excludes="${package}/test/**"/>
119136
<jar jarfile="${jars}/postgresql-examples.jar" basedir="${dest}" includes="example/**" />
120137
</target>
121138

@@ -132,4 +149,23 @@
132149
</copy>
133150
</target>
134151

135-
</project>
152+
<!--
153+
This compiles and executes the JUnit tests
154+
-->
155+
<target name="test" depends="jar" if="junit">
156+
<javac srcdir="${src}" destdir="${dest}">
157+
<include name="${package}/test/jdbc2/**" if="jdk1.2+" />
158+
<include name="${package}/test/java2ee/**" if="jdk1.2e+" />
159+
</javac>
160+
<java fork="yes" classname="junit.${junit.ui}.TestRunner" taskname="junit" failonerror="true">
161+
<arg value="org.postgresql.test.JDBC2Tests" />
162+
<sysproperty key="database" value="${database}" />
163+
<sysproperty key="username" value="${username}" />
164+
<sysproperty key="password" value="${password}" />
165+
<classpath>
166+
<pathelement location="${dest}" />
167+
<pathelement path="${java.class.path}" />
168+
</classpath>
169+
</java>
170+
</target>
171+
</project>

src/interfaces/jdbc/jdbc.jpx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
<property category="sys" name="CheckStable" value="1" />
1010
<property category="sys" name="Company" value="" />
1111
<property category="sys" name="Copyright" value="Copyright (c) 2001" />
12-
<property category="sys" name="DefaultPackage" value="org.postgresql" />
12+
<property category="sys" name="DefaultPackage" value="org.postgresql.test.jdbc2" />
1313
<property category="sys" name="Description" value="" />
1414
<property category="sys" name="DocPath" value="doc" />
1515
<property category="sys" name="ExcludeClassEnabled" value="0" />
1616
<property category="sys" name="JDK" value="java 1.3.0-C" />
1717
<property category="sys" name="LastTag" value="0" />
18-
<property category="sys" name="Libraries" value="" />
18+
<property category="sys" name="Libraries" value="JUnit" />
1919
<property category="sys" name="MakeStable" value="0" />
2020
<property category="sys" name="OutPath" value="build" />
2121
<property category="sys" name="SourcePath" value="." />

src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException
353353

354354
if (s != null)
355355
{
356+
356357
try
357358
{
358359
val = new BigDecimal(s);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package org.postgresql.test;
2+
3+
import junit.framework.TestSuite;
4+
import junit.framework.TestCase;
5+
6+
import org.postgresql.test.jdbc2.*;
7+
import java.sql.*;
8+
9+
/**
10+
* Executes all known tests for JDBC2
11+
*/
12+
public class JDBC2Tests extends TestSuite {
13+
/**
14+
* Returns the Test database JDBC URL
15+
*/
16+
public static String getURL() {
17+
return System.getProperty("database");
18+
}
19+
20+
/**
21+
* Returns the Postgresql username
22+
*/
23+
public static String getUser() {
24+
return System.getProperty("username");
25+
}
26+
27+
/**
28+
* Returns the user's password
29+
*/
30+
public static String getPassword() {
31+
return System.getProperty("password");
32+
}
33+
34+
/**
35+
* helper - opens a connection. Static so other classes can call it.
36+
*/
37+
public static java.sql.Connection openDB() {
38+
try {
39+
Class.forName("org.postgresql.Driver");
40+
return java.sql.DriverManager.getConnection(JDBC2Tests.getURL(),JDBC2Tests.getUser(),JDBC2Tests.getPassword());
41+
} catch(ClassNotFoundException ex) {
42+
TestCase.assert(ex.getMessage(),false);
43+
} catch(SQLException ex) {
44+
TestCase.assert(ex.getMessage(),false);
45+
}
46+
return null;
47+
}
48+
49+
/**
50+
* Helper - closes an open connection. This rewrites SQLException to a failed
51+
* assertion. It's static so other classes can use it.
52+
*/
53+
public static void closeDB(Connection conn) {
54+
try {
55+
if(conn!=null)
56+
conn.close();
57+
} catch(SQLException ex) {
58+
TestCase.assert(ex.getMessage(),false);
59+
}
60+
}
61+
62+
/**
63+
* The main entry point for JUnit
64+
*/
65+
public static TestSuite suite() {
66+
TestSuite suite= new TestSuite();
67+
68+
//
69+
// Add one line per class in our test cases. These should be in order of
70+
// complexity.
71+
//
72+
// ie: ANTTest should be first as it ensures that test parameters are
73+
// being sent to the suite.
74+
//
75+
76+
// Basic Driver internals
77+
suite.addTestSuite(ANTTest.class);
78+
suite.addTestSuite(DriverTest.class);
79+
suite.addTestSuite(ConnectionTest.class);
80+
81+
// Connectivity/Protocols
82+
83+
// ResultSet
84+
85+
// PreparedStatement
86+
87+
// MetaData
88+
89+
// Fastpath/LargeObject
90+
91+
// That's all folks
92+
return suite;
93+
}
94+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.postgresql.test.jdbc2;
2+
3+
import junit.framework.TestCase;
4+
5+
public class ANTTest extends TestCase {
6+
public ANTTest(String name) {
7+
super(name);
8+
}
9+
10+
/**
11+
* This tests the acceptsURL() method with a couple of good and badly formed
12+
* jdbc urls
13+
*/
14+
public void testANT() {
15+
String url=System.getProperty("database");
16+
String usr=System.getProperty("username");
17+
String psw=System.getProperty("password");
18+
19+
assert(url!=null);
20+
assert(usr!=null);
21+
assert(psw!=null);
22+
23+
assert(!url.equals(""));
24+
assert(!usr.equals(""));
25+
}
26+
}
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package org.postgresql.test.jdbc2;
2+
3+
import org.postgresql.test.JDBC2Tests;
4+
import junit.framework.TestCase;
5+
import java.sql.*;
6+
7+
/**
8+
* TestCase to test the internal functionality of org.postgresql.jdbc2.Connection
9+
* and it's superclass.
10+
*
11+
* PS: Do you know how difficult it is to type on a train? ;-)
12+
*
13+
* $Id: ConnectionTest.java,v 1.1 2001/02/07 09:13:20 peter Exp $
14+
*/
15+
16+
public class ConnectionTest extends TestCase {
17+
18+
/**
19+
* Constructor
20+
*/
21+
public ConnectionTest(String name) {
22+
super(name);
23+
}
24+
25+
/**
26+
* Tests the two forms of createStatement()
27+
*/
28+
public void testCreateStatement() {
29+
try {
30+
java.sql.Connection conn = JDBC2Tests.openDB();
31+
32+
// A standard Statement
33+
java.sql.Statement stat = conn.createStatement();
34+
assert(stat!=null);
35+
stat.close();
36+
37+
// Ask for Updateable ResultSets
38+
stat = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_UPDATABLE);
39+
assert(stat!=null);
40+
stat.close();
41+
42+
} catch(SQLException ex) {
43+
assert(ex.getMessage(),false);
44+
}
45+
}
46+
47+
/**
48+
* Tests the two forms of prepareStatement()
49+
*/
50+
public void testPrepareStatement() {
51+
try {
52+
java.sql.Connection conn = JDBC2Tests.openDB();
53+
54+
String sql = "select source,cost,imageid from test_c";
55+
56+
// A standard Statement
57+
java.sql.PreparedStatement stat = conn.prepareStatement(sql);
58+
assert(stat!=null);
59+
stat.close();
60+
61+
// Ask for Updateable ResultSets
62+
stat = conn.prepareStatement(sql,java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_UPDATABLE);
63+
assert(stat!=null);
64+
stat.close();
65+
66+
} catch(SQLException ex) {
67+
assert(ex.getMessage(),false);
68+
}
69+
}
70+
71+
/**
72+
* Put the test for createPrepareCall here
73+
*/
74+
public void testPrepareCall() {
75+
}
76+
77+
/**
78+
* Test nativeSQL
79+
*/
80+
public void testNativeSQL() {
81+
// For now do nothing as it returns itself
82+
}
83+
84+
/**
85+
* Test autoCommit (both get & set)
86+
*/
87+
public void testTransactions() {
88+
try {
89+
java.sql.Connection con = JDBC2Tests.openDB();
90+
java.sql.Statement st;
91+
java.sql.ResultSet rs;
92+
93+
// Turn it off
94+
con.setAutoCommit(false);
95+
assert(!con.getAutoCommit());
96+
97+
// Turn it back on
98+
con.setAutoCommit(true);
99+
assert(con.getAutoCommit());
100+
101+
// Now test commit
102+
st = con.createStatement();
103+
st.executeUpdate("insert into test_a (imagename,image,id) values ('comttest',1234,5678)");
104+
105+
con.setAutoCommit(false);
106+
107+
// Now update image to 9876 and commit
108+
st.executeUpdate("update test_a set image=9876 where id=5678");
109+
con.commit();
110+
rs = st.executeQuery("select image from test_a where id=5678");
111+
assert(rs.next());
112+
assert(rs.getInt(1)==9876);
113+
rs.close();
114+
115+
// Now try to change it but rollback
116+
st.executeUpdate("update test_a set image=1111 where id=5678");
117+
con.rollback();
118+
rs = st.executeQuery("select image from test_a where id=5678");
119+
assert(rs.next());
120+
assert(rs.getInt(1)==9876); // Should not change!
121+
rs.close();
122+
123+
JDBC2Tests.closeDB(con);
124+
} catch(SQLException ex) {
125+
assert(ex.getMessage(),false);
126+
}
127+
}
128+
129+
/**
130+
* Simple test to see if isClosed works
131+
*/
132+
public void testIsClosed() {
133+
try {
134+
Connection con = JDBC2Tests.openDB();
135+
136+
// Should not say closed
137+
assert(!con.isClosed());
138+
139+
JDBC2Tests.closeDB(con);
140+
141+
// Should now say closed
142+
assert(con.isClosed());
143+
144+
} catch(SQLException ex) {
145+
assert(ex.getMessage(),false);
146+
}
147+
}
148+
149+
}

0 commit comments

Comments
 (0)