Archive for August, 2009

JDBC/log4j and JRuby

Have been experimental with various Java technologies (At this time, JDBC, reading from properties files and log4j) and tying it all together with JRuby – Which I might add runs also in compiled mode as well.

Simple use of properties files in JRuby involves

# Initialize the properties object from java.util
# Refer to http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html
# on how to use.
properties = java.util::Properties.new
# Make sure that propertyfile exists!
properties.load(java.io.FileInputStream.new("propertyfile.properties"))
puts properties.getProperty("propertykey")

Now for some jdbc action! (The below code is well commented.. Enjoy!)

require 'java' # So we can use the sexy java goodness!
# Make sure you download this from the mysql site! (Link: http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-3.1.10.zip/from/pick)
require 'mysql-connector-java-3.1.10-bin.jar'
import 'com.mysql.jdbc.Driver' # Load the JDBC Driver

# Replace 'conn_string' with the JDBC Connection string (e.g. jdbc:mysql://localhost:3306/DBNAME)
# Replace 'uid' with the database username
# Replace 'pwd' with the database password
conn = java.sql::DriverManager.getConnection(conn_string, uid, pwd);
# Prepared queries are teh win
stmt = conn.prepareStatement("select field from table where otherfield = ?")
stmt.setString(1, "Whatwearesearchingfor") # First param
stmt.executeQuery
while rs.next do
puts rs.getString("field")
end
stmt.close # Because we should close what we open
conn.close # Same as above

And finally, some log4j thrown in!

require 'log4j-1.2.15.jar' # Assume you have already done require java
# The below is how you use log4j controlled by XML
import org.apache.log4j.Logger
import org.apache.log4j.xml.DOMConfigurator
logger = Logger.getLogger("LoggerName") # LoggerName would be defined in the XML file
DOMConfigurator.configure("log4j.xml")
logger.info "This would log an INFO entry if it were configured to be shown"
# Additionally you can use debug, info, warn, error, fatal

The results have been to a good degree of success. All I will need now to create a kickass and open source web frontend testing framework is:

  • Celerity
  • log4j
  • JDBC
  • properties files

I’ve basically got 90% of the functionality of a commercial tool right here!  Schweet!

Tags: , , , ,

Experimentation with the Celerity Test Framework

Just was doing some basic experimentation and reading on a JRuby test framework called Celerity (thanks to my DZone RSS Feed).

On initial thoughts, it seems like it a better open source test framework than Selenium is (Runs in headless/CLI mode by the looks of things AND the FAQ claims that it handles popups which  Selenium doesn’t).

Failing that if the popup handling is true, then for web based testing it probably makes a good rival to HP/Mercury’s QuickTest Professional tool (especially if you can multi-thread it using Ruby/JRuby’s threading).

The learning curve isn’t so bad if you can understand the HTML DOM (i.e. you aren’t a record and playback test monkey)

Tags: , ,

Some very useful things I’ve used GIT for (other than code)

I have been using GIT for a couple of months and have found some useful things which I thought I might share.

No server needed – Yes that right it exists on its own and all basic functions work properly.

Folder backup/replication – I’ve set up bare repositories on both my dropbox account as well as my jailbroken iPhone which I keep backup copies of my documents as well as a complete version history (sometimes branch history). And the cost in disk space isn’t that much as well. I can always delete and re-create the repository if it takes up too much disk.

Version constrol of applications which do not have integrated version control. As git is very lightweight (and only keeps a single folder for its object repository) AND it does not need a server I use GIT for some word documents I work on (eventually I’m going to put ALL my word processing documents and photoshop files into GIT). Having multiple levels of undo is too hard to give up.

I’m just wondering if it will work for more specialist applications which do not have this (thinking of setting up a scheduled task which does a daily commit)

And of course the other features that version control shines + the benefits of having a DVCS over a centralized model.

Tags:

Google Wave Integration to this blog?


I know Google Wave is still in private developer beta, but from watching the Google Wave keynote it looks like a very promising technology to follow (looks like a mashup between an email, a blog, and social networking site!).

Tags: ,

Well it’s done!


Well it’s done. My new blog which is dedicated to building innovation and ideas out of the randomness and serendipity of day to day IT has finally come to fruition.

As you can see this site is very new, but this will hopefully have a lot more juicy stuff as time goes on

Tags: