Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

DTOResultSetTest.java

Go to the documentation of this file.
00001 package net.threebit.utils.sosc.test;
00002 
00003 /*
00004         Copyright 2003 Shawn Deleurme
00005         Copyright 2003 Kevin O'Donnell
00006 
00007         This program is free software; you can redistribute it and/or modify
00008         it under the terms of the GNU General Public License as published by
00009         the Free Software Foundation; either version 2 of the License, or
00010         (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016 
00017         You should have received a copy of the GNU General Public License
00018         along with this program; if not, write to the Free Software
00019         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 import java.io.*;
00023 import java.util.*;
00024 import java.util.logging.*;
00025 import java.sql.Date;
00026 import java.sql.ResultSetMetaData;
00027 import java.sql.Types;
00028 import junit.framework.*;
00029 import net.threebit.utils.sosc.*;
00030 
00035 public class DTOResultSetTest extends TestCase {
00036 
00037         public void test1() throws Exception {
00038                 final String col1 = "StringColumn1";
00039                 final String val1 = "value1";
00040                 final String col2 = "StringColumn2";
00041                 final String val2 = "value2";
00042                 final String col3 = "col3";
00043                 final Date val3 = new Date( new java.util.Date().getTime() );
00044 
00045                 DTOResultSet r = new DTOResultSet();
00046 
00047                 // Add the first row.
00048                 r.moveToInsertRow();
00049                 r.updateString(col1,val1);
00050                 r.updateString(col2,val2);
00051                 r.updateDate(col3,val3);
00052                 r.insertRow();
00053 
00054                 // Reset and read it.
00055                 r.beforeFirst();
00056                 assertTrue(r.getRow() == 0);
00057                 assertTrue(r.next());
00058                 assertTrue(r.getRow() == 1);
00059                 assertTrue(val1.equals( r.getString( col1 )));
00060                 assertTrue(val2.equals( r.getString( col2 )));
00061                 assertTrue(val3.equals( r.getDate( col3 )));
00062                 assertTrue(val3.equals( r.getObject( col3 )));
00063                 assertTrue(! r.next());
00064                 assertTrue(r.getRow() == 0);
00065                 System.out.println("" + r);
00066                 r.close();
00067                 System.out.println("" + r);
00068         }
00069 
00070         public void test2() throws Exception {
00071                 DTOResultSet r = new DTOResultSet();
00072 
00073                 for (int x = 1; x < 100; x++) {
00074                         r.moveToInsertRow();
00075                         r.updateString("column1",""+x);
00076                         r.insertRow();
00077                 }
00078 
00079                 r.beforeFirst();
00080                 int x = 0;
00081                 while (r.next()) {
00082                         if (x++ >= 100) { throw new Exception("TO MANY ROWS!"); }
00083                         assertTrue(x == r.getRow());
00084                         assertTrue((""+x).equals(r.getString("column1")));
00085                 }
00086                 r.close();
00087         }
00088 
00089         public void test3 () throws Exception {
00090                 DTOResultSet r = new DTOResultSet();
00091 
00092                 r.moveToInsertRow();
00093                 r.updateString("col1","v1");
00094                 r.updateString("col2","v2");
00095                 r.insertRow();
00096                 r.updateString("col1","v3");
00097                 r.updateString("col2","v4");
00098                 r.insertRow();
00099 
00100                 r.beforeFirst();
00101 
00102                 ResultSetMetaData md = r.getMetaData();
00103                 assertTrue(md.getColumnCount() == 2);
00104                 assertTrue(md.getColumnType(r.findColumn("col2")) == Types.VARCHAR);
00105 
00106         }
00107 
00108         public void test4 () throws Exception {
00109                 DTOResultSet r = new DTOResultSet();
00110 
00111                 r.moveToInsertRow();
00112                 r.updateString("col1","v1");
00113                 r.updateString("col2","v2");
00114                 r.insertRow();
00115                 r.updateString("col1","v3");
00116                 r.updateString("col2","v4");
00117                 r.insertRow();
00118 
00119                 r.beforeFirst();
00120 
00121                 DTOResultSet r2 = new DTOResultSet(r);
00122 
00123                 ResultSetMetaData md = r2.getMetaData();
00124                 assertTrue(md.getColumnCount() == 2);
00125                 assertTrue(md.getColumnType(r2.findColumn("col2")) == Types.VARCHAR);
00126 
00127                 assertTrue(r2.next());
00128                 assertTrue("v1".equals(r2.getString("col1")));
00129                 assertTrue("v2".equals(r2.getString("col2")));
00130 
00131                 assertTrue(r2.next());
00132                 assertTrue("v3".equals(r2.getString("col1")));
00133                 assertTrue("v4".equals(r2.getString("col2")));
00134 
00135                 assertTrue(! r2.next());
00136         }
00137 
00138 }

Generated on Mon Jul 14 17:19:20 2003 for SOSC by doxygen1.2.15