Announcement Announcement Module
Collapse
No announcement yet.
Aspectj Java1.4 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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.

      Comment


      • #4
        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.

        Comment


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

          Have a look at this link

          Comment


          • #6
            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 ?

            Comment


            • #7
              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.

              Comment


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

                Comment

                Working...
                X