2 Replies Latest reply on Nov 19, 2009 9:04 AM by nizzy

    aop.xml to pass parameters to interceptor

    nizzy

      Hi All,

      I'm experiencing behaviour that seems bizarre to me, hoefully someone can explain it to me.

      aop.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <aop>
      
       <bind pointcut="execution(public CardEmailUtil->new())">
       <interceptor class="GenericInterceptor">
       <attribute name="mockObjectName">MockEmailer</attribute>
       </interceptor>
       </bind>
      
       <bind pointcut="execution(public CardJPAHelper->new(..))">
       <interceptor class="GenericInterceptor">
       <attribute name="mockObjectName">mock-jpa-helper</attribute>
       </interceptor>
       </bind>
      
      </aop>
      


      So i'm using AOP to mock out certain calls when unit testing. I thought I could use a GenericInterceptor and pass it different attributes, shown in aop.xml.

      However this is not the behaviour I'm experiencing. Although I'm intercepting the CardJPAHelper constructor, the mockObjectName set in the GenericInterceptor is "MockEmailer".

      Apparently it is the first entry in aop.xml that sets the mockObjectName, I have verified this by changing the order they appear in the xml.

      Have I misunderstood how to define the pointcut in aop.xml?

      Any help appreciated.

        • 1. Re: aop.xml to pass parameters to interceptor
          kabirkhan


          <?xml version="1.0" encoding="UTF-8"?>
          <aop>
           <interceptor class="GenericInterceptor" name="A">
           <attribute name="mockObjectName">MockEmailer</attribute>
           </interceptor>
           <interceptor class="GenericInterceptor" name="B">
           <attribute name="mockObjectName">mock-jpa-helper</attribute>
           </interceptor>
          
           <bind pointcut="execution(public CardEmailUtil->new())">
           <interceptor-ref name="A"/>
           </bind>
          
           <bind pointcut="execution(public CardJPAHelper->new(..))">
           <interceptor-ref name="B"/>
           </bind>
          </aop>
          



          • 2. Re: aop.xml to pass parameters to interceptor
            nizzy

            Was just reading the reference manual and the schema, realised should prbably be done that way.

            Should have done that first!!

            Thanks for the reply.