Diff for revision 1230
=== modified file 'build.xml'
--- build.xml 2010-02-08 19:04:31 +0000
+++ build.xml 2010-02-19 18:17:04 +0000
@@ -364,11 +364,25 @@
<compilerarg value="-Xlint:deprecation" />
</javac>
</target>
-
+
+ <!-- init before we do tests -->
+ <target name="init-tests">
+ <!-- create mysql test database -->
+ <sql driver="com.mysql.jdbc.Driver"
+ url="jdbc:mysql://${mysql.host}"
+ userid="${mysql.user}"
+ password="${mysql.pass}"
+ classpath="${opt.classpath}"
+ onerror="continue">
+ <transaction src="test-data/mysql/drop.sql"/>
+ <transaction src="test-data/mysql/create.sql"/>
+ </sql>
+ </target>
+
<!-- tests a particular class -->
<!-- the class to test needs to be specified on the command line by using:
-Dclass=FULL_CLASSNAME -->
- <target name="test-single" depends="compile,compile-tests">
+ <target name="test-single" depends="compile,compile-tests,init-tests">
<fail unless="class">Must set property 'class'</fail>
<junit haltonfailure="true">
<classpath path="${junit.classpath}" />
@@ -378,7 +392,7 @@
</target>
<!-- run all tests and generate reports -->
- <target name="test" depends="clean,compile,compile-tests">
+ <target name="test" depends="clean,compile,compile-tests,init-tests">
<delete dir="${dir.docs.junit}" />
<mkdir dir="${dir.docs.junit}" />
=== modified file 'sockso.properties-sample'
--- sockso.properties-sample 2010-01-30 15:19:26 +0000
+++ sockso.properties-sample 2010-02-19 18:17:04 +0000
@@ -19,3 +19,7 @@
jstestdriver.port=9876
jstestdriver.version=1.2
+
+mysql.host=localhost
+mysql.user=root
+mysql.pass=
=== modified file 'src/com/pugh/sockso/db/MySQLDatabase.java'
--- src/com/pugh/sockso/db/MySQLDatabase.java 2009-05-17 21:40:18 +0000
+++ src/com/pugh/sockso/db/MySQLDatabase.java 2010-02-19 18:17:04 +0000
@@ -39,6 +39,22 @@
final String dbPass = options.has(Options.OPT_DBPASS) ? options.valueOf(Options.OPT_DBPASS).toString() : "";
final String dbName = options.has(Options.OPT_DBNAME) ? options.valueOf(Options.OPT_DBNAME).toString() : "sockso";
+ connect( dbHost, dbUser, dbPass, dbName );
+
+ }
+
+ /**
+ * Connect using the specified credentials
+ *
+ * @param dbHost
+ * @param dbUser
+ * @param dbPass
+ * @param dbName
+ *
+ */
+
+ public void connect( final String dbHost, final String dbUser, final String dbPass, final String dbName ) throws DatabaseConnectionException {
+
try {
// connect to server
@@ -255,7 +271,7 @@
try {
final String sql = " create table indexer ( " +
- " id unsigned int not null, " +
+ " id int unsigned not null, " +
" last_modified datetime not null, " +
" primary key ( id ) " +
" ) ";
=== added directory 'test-data/mysql'
=== added file 'test-data/mysql/create.sql'
--- test-data/mysql/create.sql 1970-01-01 00:00:00 +0000
+++ test-data/mysql/create.sql 2010-02-19 18:17:04 +0000
@@ -0,0 +1,2 @@
+
+create database sockso_test;
=== added file 'test-data/mysql/drop.sql'
--- test-data/mysql/drop.sql 1970-01-01 00:00:00 +0000
+++ test-data/mysql/drop.sql 2010-02-19 18:17:04 +0000
@@ -0,0 +1,2 @@
+
+drop database sockso_test;
=== modified file 'test/com/pugh/sockso/db/DatabaseTest.java'
--- test/com/pugh/sockso/db/DatabaseTest.java 2009-05-17 13:32:07 +0000
+++ test/com/pugh/sockso/db/DatabaseTest.java 2010-02-19 18:17:04 +0000
@@ -17,6 +17,7 @@
import java.sql.ResultSetMetaData;
import java.io.File;
+import java.io.FileInputStream;
import org.apache.log4j.Logger;
@@ -43,6 +44,26 @@
new File( "test-database.log" ).delete();
}
}
+
+ /**
+ * this test only runs if mysql is configured in sockso.properties
+ * @throws Exception
+ */
+ public void testMySqlDatabase() throws Exception {
+ java.util.Properties props = new java.util.Properties();
+ props.load( new FileInputStream("sockso.properties") );
+ if ( props.getProperty("mysql.user") != null ) {
+ MySQLDatabase db = new MySQLDatabase();
+ db.connect(
+ props.getProperty("mysql.host"),
+ props.getProperty("mysql.user"),
+ props.getProperty("mysql.pass"),
+ "sockso_test"
+ );
+ doTableTests( db );
+ doPropertiesTests( db );
+ }
+ }
private void doTableTests( Database db ) {
@@ -101,17 +122,6 @@
}
- private void doQueryTest( final String sql, final Database db ) {
- ResultSet rs = null;
- try {
- rs = db.query( sql );
- }
- catch ( final SQLException e ) {
- fail( e.getMessage() );
- }
- assertNotNull( rs );
- }
-
public void doPropertiesTests( Database db ) {
doPropertyTest( db, Constants.SERVER_PORT, "4444" );
doPropertyTest( db, Constants.WWW_TITLE, "Sockso" );