I'm authoring a web application that requires runtime access to different database - as in, the user actually types in the database connection info (host url, username, password) via a web form, and then some logic gets run against that database. I understand this architecture is wonky, but trust me it's appropriate for this application.
I've got the abstraction and basic code framework down just fine (business logic bean calls dao interface, dao interface in turn has an iBatis implementation), and everything is easily unit testable. I've got a nice dynamic mock of the dao interface (using jmock).
However, I want to add transactional support. Declarative transactions in spring essentially assume that you have one or more static data sources around at app launch time (so that the data sources can be configured in the application context xml file). This obviously is not going to work for me, because I'm creating data sources/connections on the fly at runtime.
So I decide to use programmatic transactions, specifically TransactionTemplate and transaction callbacks. I can (and did) code all of this up without any difficulty. The problem is figuring out how to test it. I don't want to test that business logic layer against a live database, I want to use my mock DAO. But the mock DAO doesn't have a real data source, and therefore I can't create a transaction manager/template. But the business logic bean expects one to be there because the business logic layer is the spring-suggested layer in which to include programmatic transaction code.
I'm kind of spinning in circles here.. any advice?