Sep 8th, 2008, 10:19 AM
Quick question :
Can I use Aspectj with Java 1.4 using the standard Spring distribution ?
Background : if possible I would like to advise a non-spring method. If a specific third party class logs an error (log.ERROR()), then I want my unit test to fail. The plan is to intercept the log.ERROR() and throw an exception. The project is constrained to Java 1.4.
No idea if there is a better way.
Sep 8th, 2008, 01:28 PM
I'm not sure that's the best way to achieve your goal.
What kind of logging are you thinking of? Commons-logging? Log4J?
Suppose you use log4j and write to a log-file. Then you can fail your test when the log file contains an ERROR. Therefor you would read the file and chech if any line matches an ERROR message.
Sep 8th, 2008, 01:33 PM
Yes, Log4J via Commons Logging. You are right, it is certainly possible to read the log output and then fail the test. I was thinking AOP would be simpler.
Sep 9th, 2008, 07:09 AM
Hmm, reading the log files does not seem to be an option as I need to clear out the log between each test in the suite, and the logging classes keep the log open for appending until the suite is completed. The system actually uses the slf4j api which connects into log4j. The third party classes are wired into the commons logging api.
Sep 9th, 2008, 09:43 AM
You could do this by using another appender for log4j instead of a file-appender.
Have a look at this link
Sep 9th, 2008, 11:45 AM
Good reference - however I think it depends on the log4j api, and I don't see how to access that functionality through the commons logging api ?
Sep 9th, 2008, 01:49 PM
The only dependency on the log4j api is for implementing the appender (AppenderForTesting). When you configure log4j with this appender, commons-logging will pick it up and use log4j for logging.
From there you access the appender in your unit tests through its static methods.
Sep 11th, 2008, 05:21 AM
Yes, it works - amazing. Thanks for the recommendation. Martin.