Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca5d71c

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 parent90670eb commitca5d71c

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
<propertyname="major"value="7" />
1818
<propertyname="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+
<propertyname="database"value="jdbc:postgresql:test" />
27+
<propertyname="username"value="test" />
28+
<propertyname="password"value="password" />
29+
<propertyname="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
<availableproperty="jdk1.2+"classname="java.lang.ThreadLocal" />
3041
<availableproperty="jdk1.3+"classname="java.lang.StrictMath" />
3142
<availableproperty="jdk1.2e+"classname="javax.sql.DataSource" />
43+
<availableproperty="junit"classname="junit.framework.Test" />
3244
</target>
3345

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

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

116133
<!-- This builds the jar file containing the driver-->
117134
<targetname="jar"depends="compile,examples">
118-
<jarjarfile="${jars}/postgresql.jar"basedir="${dest}"includes="org/**" />
135+
<jarjarfile="${jars}/postgresql.jar"basedir="${dest}"includes="${package}/**"excludes="${package}/test/**"/>
119136
<jarjarfile="${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+
<targetname="test"depends="jar"if="junit">
156+
<javacsrcdir="${src}"destdir="${dest}">
157+
<includename="${package}/test/jdbc2/**"if="jdk1.2+" />
158+
<includename="${package}/test/java2ee/**"if="jdk1.2e+" />
159+
</javac>
160+
<javafork="yes"classname="junit.${junit.ui}.TestRunner"taskname="junit"failonerror="true">
161+
<argvalue="org.postgresql.test.JDBC2Tests" />
162+
<syspropertykey="database"value="${database}" />
163+
<syspropertykey="username"value="${username}" />
164+
<syspropertykey="password"value="${password}" />
165+
<classpath>
166+
<pathelementlocation="${dest}" />
167+
<pathelementpath="${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
<propertycategory="sys"name="CheckStable"value="1" />
1010
<propertycategory="sys"name="Company"value="" />
1111
<propertycategory="sys"name="Copyright"value="Copyright (c) 2001" />
12-
<propertycategory="sys"name="DefaultPackage"value="org.postgresql" />
12+
<propertycategory="sys"name="DefaultPackage"value="org.postgresql.test.jdbc2" />
1313
<propertycategory="sys"name="Description"value="" />
1414
<propertycategory="sys"name="DocPath"value="doc" />
1515
<propertycategory="sys"name="ExcludeClassEnabled"value="0" />
1616
<propertycategory="sys"name="JDK"value="java 1.3.0-C" />
1717
<propertycategory="sys"name="LastTag"value="0" />
18-
<propertycategory="sys"name="Libraries"value="" />
18+
<propertycategory="sys"name="Libraries"value="JUnit" />
1919
<propertycategory="sys"name="MakeStable"value="0" />
2020
<propertycategory="sys"name="OutPath"value="build" />
2121
<propertycategory="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 =newBigDecimal(s);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
packageorg.postgresql.test;
2+
3+
importjunit.framework.TestSuite;
4+
importjunit.framework.TestCase;
5+
6+
importorg.postgresql.test.jdbc2.*;
7+
importjava.sql.*;
8+
9+
/**
10+
* Executes all known tests for JDBC2
11+
*/
12+
publicclassJDBC2TestsextendsTestSuite {
13+
/**
14+
* Returns the Test database JDBC URL
15+
*/
16+
publicstaticStringgetURL() {
17+
returnSystem.getProperty("database");
18+
}
19+
20+
/**
21+
* Returns the Postgresql username
22+
*/
23+
publicstaticStringgetUser() {
24+
returnSystem.getProperty("username");
25+
}
26+
27+
/**
28+
* Returns the user's password
29+
*/
30+
publicstaticStringgetPassword() {
31+
returnSystem.getProperty("password");
32+
}
33+
34+
/**
35+
* helper - opens a connection. Static so other classes can call it.
36+
*/
37+
publicstaticjava.sql.ConnectionopenDB() {
38+
try {
39+
Class.forName("org.postgresql.Driver");
40+
returnjava.sql.DriverManager.getConnection(JDBC2Tests.getURL(),JDBC2Tests.getUser(),JDBC2Tests.getPassword());
41+
}catch(ClassNotFoundExceptionex) {
42+
TestCase.assert(ex.getMessage(),false);
43+
}catch(SQLExceptionex) {
44+
TestCase.assert(ex.getMessage(),false);
45+
}
46+
returnnull;
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+
publicstaticvoidcloseDB(Connectionconn) {
54+
try {
55+
if(conn!=null)
56+
conn.close();
57+
}catch(SQLExceptionex) {
58+
TestCase.assert(ex.getMessage(),false);
59+
}
60+
}
61+
62+
/**
63+
* The main entry point for JUnit
64+
*/
65+
publicstaticTestSuitesuite() {
66+
TestSuitesuite=newTestSuite();
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+
returnsuite;
93+
}
94+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
packageorg.postgresql.test.jdbc2;
2+
3+
importjunit.framework.TestCase;
4+
5+
publicclassANTTestextendsTestCase {
6+
publicANTTest(Stringname) {
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+
publicvoidtestANT() {
15+
Stringurl=System.getProperty("database");
16+
Stringusr=System.getProperty("username");
17+
Stringpsw=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+
packageorg.postgresql.test.jdbc2;
2+
3+
importorg.postgresql.test.JDBC2Tests;
4+
importjunit.framework.TestCase;
5+
importjava.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+
publicclassConnectionTestextendsTestCase {
17+
18+
/**
19+
* Constructor
20+
*/
21+
publicConnectionTest(Stringname) {
22+
super(name);
23+
}
24+
25+
/**
26+
* Tests the two forms of createStatement()
27+
*/
28+
publicvoidtestCreateStatement() {
29+
try {
30+
java.sql.Connectionconn =JDBC2Tests.openDB();
31+
32+
// A standard Statement
33+
java.sql.Statementstat =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(SQLExceptionex) {
43+
assert(ex.getMessage(),false);
44+
}
45+
}
46+
47+
/**
48+
* Tests the two forms of prepareStatement()
49+
*/
50+
publicvoidtestPrepareStatement() {
51+
try {
52+
java.sql.Connectionconn =JDBC2Tests.openDB();
53+
54+
Stringsql ="select source,cost,imageid from test_c";
55+
56+
// A standard Statement
57+
java.sql.PreparedStatementstat =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(SQLExceptionex) {
67+
assert(ex.getMessage(),false);
68+
}
69+
}
70+
71+
/**
72+
* Put the test for createPrepareCall here
73+
*/
74+
publicvoidtestPrepareCall() {
75+
}
76+
77+
/**
78+
* Test nativeSQL
79+
*/
80+
publicvoidtestNativeSQL() {
81+
// For now do nothing as it returns itself
82+
}
83+
84+
/**
85+
* Test autoCommit (both get & set)
86+
*/
87+
publicvoidtestTransactions() {
88+
try {
89+
java.sql.Connectioncon =JDBC2Tests.openDB();
90+
java.sql.Statementst;
91+
java.sql.ResultSetrs;
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(SQLExceptionex) {
125+
assert(ex.getMessage(),false);
126+
}
127+
}
128+
129+
/**
130+
* Simple test to see if isClosed works
131+
*/
132+
publicvoidtestIsClosed() {
133+
try {
134+
Connectioncon =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(SQLExceptionex) {
145+
assert(ex.getMessage(),false);
146+
}
147+
}
148+
149+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp