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

DbToolTest.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.sql.*;
00024 import java.util.*;
00025 import javax.xml.transform.stream.*;
00026 import javax.xml.transform.*;
00027 import junit.framework.*;
00028 import net.threebit.utils.sosc.*;
00029 import java.util.logging.*;
00030 
00035 public class DbToolTest extends TestCase {
00036 
00037         String url = System.getProperty("net.threebit.utils.sosc.DbTool.jdbcURL");
00038         String className = System.getProperty("net.threebit.utils.sosc.DbTool.jdbcURLClassName");
00039         String userName = System.getProperty("net.threebit.utils.sosc.DbTool.jdbcURLUserName");
00040         String password = System.getProperty("net.threebit.utils.sosc.DbTool.jdbcURLPassword");
00041 
00042         private DbTool getDb() throws Exception {
00043                 if (url == null) { throw new Exception("net.threebit.utils.sosc.DbTool.jdbcURL property has not been set"); }
00044                 if (className == null) { throw new Exception("net.threebit.utils.sosc.DbTool.jdbcURLClassName property has not been set"); }
00045                 if (userName == null) { throw new Exception("net.threebit.utils.sosc.DbTool.jdbcURLUserName property has not been set"); }
00046                 if (password == null) { throw new Exception("net.threebit.utils.sosc.DbTool.jdbcURLPassword property has not been set"); }
00047                 return new DbTool(className, url,userName,password);
00048         }
00049 
00050         /*
00051         public void test20() throws Exception {
00052                 DbTool db = getDb();
00053                 ArrayList list = new ArrayList();
00054                 String r1 = "('1','2','3')";
00055                 String r2 = "(1,2,3)";
00056                 list.add("1");
00057                 list.add("2");
00058                 list.add("3");
00059 
00060                 System.out.println("r1  : >>" + r1 + "<<");
00061                 System.out.println("out : >>" + db.inClause(list,true) + "<<");
00062                 System.out.println( db.inClause(list,true) );
00063                 assertTrue( r1.equals(db.inClause(list,false)));
00064 
00065                 System.out.println("r2  : >>" + r2 + "<<");
00066                 System.out.println("out : >>" + db.inClause(list,true) + "<<");
00067                 assertTrue( r2.equals(db.inClause(list,false)));
00068         }
00069         */
00070 
00071         public void testQuote1() throws Exception {
00072                 DbTool db = getDb();
00073                 assertTrue(db.quote(null) == null);
00074                 assertTrue(db.quote("test").equals("'test'"));
00075                 assertTrue(db.quote("o'donnell").equals("'o''donnell'"));
00076         }
00077 
00078         public void test2() throws Exception {
00079                 DbTool db = getDb();
00080                 StringBuffer sb = new StringBuffer();
00081                 db.resultSetToXML(db.query("select 'one' as a, 'two' as b, 'three' as c"), sb, Integer.MAX_VALUE);
00082                 String baseLine = 
00083                         "<resultSet>\n" +
00084                         "<row>\n" +
00085                         "\t<a>one</a>\n" +
00086                         "\t<b>two</b>\n" +
00087                         "\t<c>three</c>\n" +
00088                         "</row>\n" +
00089                         "</resultSet>\n"
00090                 ;
00091                 //System.out.println("sb: '" + sb + "'");
00092                 //System.out.println("baseLine: '" + baseLine + "'");
00093                 assertTrue(baseLine.equals(sb.toString()));
00094         }
00095 
00096         public void test3() throws Exception {
00097                 DbTool db = getDb();
00098                 ResultSet r = db.query("exec oreivrworkstackpop;");
00099                 assertTrue(r != null);
00100         }
00101 
00102         public void test4() throws Exception {
00103                 DbTool db = getDb();
00104                 StringBuffer sb = db.resultSetToXML(db.query("select 1 as one;"));
00105                 assertTrue(sb != null);
00106         }
00107 
00108 }

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