00001 package net.threebit.utils.sosc.test;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
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
00092
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 }