KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > testsuite > simple > NumbersTest


1 /*
2  Copyright (C) 2002-2004 MySQL AB
3
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of version 2 of the GNU General Public License as
6  published by the Free Software Foundation.
7
8  There are special exceptions to the terms and conditions of the GPL
9  as it is applied to this software. View the full text of the
10  exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
11  software distribution.
12
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22
23
24  */

25 package testsuite.simple;
26
27 import testsuite.BaseTestCase;
28
29 import java.sql.SQLException JavaDoc;
30
31 /**
32  *
33  * @author Mark Matthews
34  * @version $Id: NumbersTest.java,v 1.1.2.2 2005/05/19 15:52:24 mmatthews Exp $
35  */

36 public class NumbersTest extends BaseTestCase {
37     // ~ Static fields/initializers
38
// ---------------------------------------------
39

40     private static final long TEST_BIGINT_VALUE = 6147483647L;
41
42     // ~ Constructors
43
// -----------------------------------------------------------
44

45     /**
46      * Creates a new NumbersTest object.
47      *
48      * @param name
49      * DOCUMENT ME!
50      */

51     public NumbersTest(String JavaDoc name) {
52         super(name);
53     }
54
55     // ~ Methods
56
// ----------------------------------------------------------------
57

58     /**
59      * Runs all test cases in this test suite
60      *
61      * @param args
62      */

63     public static void main(String JavaDoc[] args) {
64         junit.textui.TestRunner.run(NumbersTest.class);
65     }
66
67     /**
68      * DOCUMENT ME!
69      *
70      * @throws Exception
71      * DOCUMENT ME!
72      */

73     public void setUp() throws Exception JavaDoc {
74         super.setUp();
75         createTestTable();
76     }
77
78     /**
79      * DOCUMENT ME!
80      *
81      * @throws SQLException
82      * DOCUMENT ME!
83      */

84     public void testNumbers() throws SQLException JavaDoc {
85         this.rs = this.stmt.executeQuery("SELECT * from number_test");
86
87         while (this.rs.next()) {
88             long minBigInt = this.rs.getLong(1);
89             long maxBigInt = this.rs.getLong(2);
90             long testBigInt = this.rs.getLong(3);
91             assertTrue("Minimum bigint not stored correctly",
92                     (minBigInt == Long.MIN_VALUE));
93             assertTrue("Maximum bigint not stored correctly",
94                     (maxBigInt == Long.MAX_VALUE));
95             assertTrue("Test bigint not stored correctly",
96                     (TEST_BIGINT_VALUE == testBigInt));
97         }
98     }
99
100     private void createTestTable() throws SQLException JavaDoc {
101         try {
102             this.stmt.executeUpdate("DROP TABLE number_test");
103         } catch (SQLException JavaDoc sqlEx) {
104             ;
105         }
106
107         this.stmt
108                 .executeUpdate("CREATE TABLE number_test (minBigInt bigint, maxBigInt bigint, testBigInt bigint)");
109         this.stmt
110                 .executeUpdate("INSERT INTO number_test (minBigInt,maxBigInt,testBigInt) values ("
111                         + Long.MIN_VALUE
112                         + ","
113                         + Long.MAX_VALUE
114                         + ","
115                         + TEST_BIGINT_VALUE + ")");
116     }
117 }
118
Popular Tags