Results 1 to 8 of 8

Thread: Aspectj Java1.4

  1. #1
    Join Date
    Feb 2006
    Location
    London
    Posts
    77

    Default Aspectj Java1.4

    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.

    Thanks

    Martin

  2. #2
    Join Date
    Dec 2007
    Location
    Belgium
    Posts
    24

    Default

    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.

  3. #3
    Join Date
    Feb 2006
    Location
    London
    Posts
    77

    Default

    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.

  4. #4
    Join Date
    Feb 2006
    Location
    London
    Posts
    77

    Default

    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.

  5. #5
    Join Date
    Dec 2007
    Location
    Belgium
    Posts
    24

    Default

    You could do this by using another appender for log4j instead of a file-appender.

    Have a look at this link

  6. #6
    Join Date
    Feb 2006
    Location
    London
    Posts
    77

    Default

    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 ?

  7. #7
    Join Date
    Dec 2007
    Location
    Belgium
    Posts
    24

    Default

    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.

  8. #8
    Join Date
    Feb 2006
    Location
    London
    Posts
    77

    Default

    Yes, it works - amazing. Thanks for the recommendation. Martin.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •