unitils

April 16th, 2007

I recently moved some code from JDBC Templates to Hibernate, Spring and JPA annotations. While not rocket science still something that is slightly tedious to test…. Also if you mock, you are not entirely sure that everything actually works as expected in a full stack. With a bit of Google-Fu I stumbled upon Unitils.

First off - you need to configure unitils to work against a test-db, put
the unitils.properties file into the classpath of your test source

# Properties for the PropertiesDataSourceFactory
#database.driverClassName=org.hsqldb.jdbcDriver
database.driverClassName=org.postgresql.Driver
#database.url=jdbc:hsqldb:mem:javabot-test
database.url=jdbc:postgresql:javabot-test
database.userName=username
database.password=password
# This property specifies the underlying DBMS implementation. Supported values are 'oracle', 'db2', 'mysql', 'hsqldb' and 'postgresql'.
# The value of this property defines which vendor specific implementations of DbSupport and ConstraintsDisabler are chosen.
database.dialect=postgresql
# This property specifies the database schema that is used. This schema name is used to qualify all tables when (amongst
# others) clearing / dropping tables / inserting test data.
# NOTE: schema name is case sensitive
database.schemaName=public
updateDataBaseSchema.enabled=true
dbMaintainer.fileScriptSource.scripts.location=src/tests/javabot/dbscripts
dbMaintainer.generateDTD.enabled=TRUE
# DbUnit database DTD file path
dtdGenerator.dtd.filename=src/tests/javabot/dbscripts/test.dtd

Following the Spring-Tutorial I was able to quickly whip up a spring-context.

The magic is in this line :

<bean id=”dataSource” class=”org.unitils.database.UnitilsDataSource” />

So essentially you replace your existing data source, and use the unitils one.

 Which now will let me via these lines
@SpringApplicationContext("test-application-config.xml")
public class BaseServiceTest extends UnitilsTestNG {
    @SpringApplicationContext
    ApplicationContext springApplicationContext;
}
This base class then makes us ready for testing......
 public class SeenDaoTest extends BaseServiceTest { 

    @SpringBeanByType
    private SeenDao seenDao; 

    @Test
    public void addSeen() {
       seenDao.logSeen("nick","channel","message");
       Assert.assertTrue(seenDao.isSeen("nick","channel"));
    }
}

Contained beneath the hood we now have a complete Spring / Hibernate live database test!

Duct Taping together a SAP Poller.

March 11th, 2007

Disclaimer - As this was done without access to a SAP system, I’ll figure out the performance bits in part 2

We use SAP extensively where I work, this led me to wanting a SAP monitor.

Licensing and it’s proprietary nature I think would not permit me to check something like this into the OpenNMS sources so I decided to look into breaking out the functionality of a monitor into a stand-alone project complete with a Maven2 setup. Hopefully this can be used for new ‘Proprietary’ monitors and successfully extend OpenNMS within your own organisation.

An OpenNMS monitor is a fairly simple object, returning a predefined set of information, a lot of what I did here is really code duplication but I wanted to avoid relying on opennms-services (The project that contains all existing monitors, collectors and daemons) too much.

My goal was a single JAR that you could include in your Capsd and Poller configs that monitored a full SAP Login.

Read the rest of this entry »

Wickedly cool

March 5th, 2007

Lately I’ve been playing around with Wicket, a really nice Web framework.

I’ve gotten less than fond of SpringMVC and JSP using it for a while, it just seems so backwards…..

I found several nice tutorials on the net such as this one as well as the Wicket tutorials. Right now I’m looking at integrating old code (JSP), and Acegi for a possible migration path

What I’ve seen so far is easy to sum up :

  • Wicket-Spring is dead easy, annotation exposed @SpringBeans make Dao access a snap
  • Using AJAX is suddenly a matter of Java
  • You can start designing pages/panels/labels and so on in an ‘elegant’ manner
  • I’ve already been able to reuse code
  • HTML is HTML - and easy to work with

I actually managed to whip together a Wicket Application in a few days. It is entertaining to work with, adding shiny stuff is really easy while you can develop Java code and keep those last bits of hair you have saved for ripping out in a CSS nightmare that you hopefully after finding Wicket will not have to deal with.

So I’d go out on a limb and say that Wicket == Rogaine for developers.

Oh well, here we go.

February 26th, 2007

w00t