views:

47

answers:

2

I'm using Spring 3.0, and I have a set of methods like this:

@Transactional (value = "authTransactionManager")
public void remove(User user) {
    ...
}

I use 2 different transaction managers and specify necessary manager (authTransactionManager in example above).

I was curious what would happen if I specify nonexistent manager. I expected compile exception or runtime exception, but everything worked fine. That's why I have doubts about any transactions were ever supported in my methods.

How can I test it? (maybe, spring is so smart that uses any available manager when nonexistent manager specified and all my doubts are unfounded?)

+2  A: 

You could turn on debug-level logging, this is generally what I do when debugging these kind of transaction problems!

Spring is quite good about logging transactions.

Phill Sacre
+1, your answer really helped me. the only thing I don't know still is which transaction manager is used: I see in logs that both managers are loaded and I also see that only one of them used (i.e. I see only 1 commit). but logs don't contain information about which one is used.
Roman
A: 

Here are 2 options:

(1) Use integration tests. You could use tools like dbUnit to load data into the database, and then write tests against the DB, using transactions. (We do this all the time to test our XML Hibernate mappings. In fact, the tests execute as part of the automated build.)

(2) Use FIT tests. These are quite a different beast: functional tests for the system. FIT tests will require 'fixtures' to act as glue between your tests and your system, but they could help with this issue. (It might be overkill in this case.)

In both cases, you have the option of either (a) doing some quick-and-dirty testing as a sanity check or (b) designing a testing subsystem that goes into your automated build. (We use both integration tests and FIT tests for case (b)).

Michael Easter