4 Replies Latest reply on Nov 8, 2007 5:18 AM by fbenvegna

    TestNG and EJB3 interceptors

    fbenvegna

      I have a EJB3 interceptor inside Stateless with Seam 2.0.0-CR3.
      Deployment and invocation from facelet works fine.
      The same ejb method invoked from TestNG doesn't execute interceptor.
      Is problem related to embeddable EJB3 container configuration ?
      Thank you


      public class DomainValidator {
      
       @AroundInvoke
       public Object validate(InvocationContext invocationContext) throws Exception {
       Method method = invocationContext.getMethod();
       Object[] parameters = invocationContext.getParameters();
      
       System.out.println("---------------------------------------------------------------");
       System.out.println(method.getName());
       System.out.println(parameters);
       System.out.println("---------------------------------------------------------------");
      
       return invocationContext.proceed( );
       }
      }
      


      @Stateless
      @TransactionAttribute(TransactionAttributeType.SUPPORTS)
      @Interceptors(DomainValidator.class)
      @Name("groupManager")
      public class GroupManager extends AbstractManager implements IGroupManager {
      ...
      ...
      
       public String hello() {
       return "CIAO";
       }
      
      ...
      }
      


        • 1. Re: TestNG and EJB3 interceptors
          pmuir

          Try making it a Seam interceptor rather than an EJB interceptor - this will certainly work.

          • 2. Re: TestNG and EJB3 interceptors
            fbenvegna

            SeamInterceptor doesn't work

            @Target(ElementType.TYPE)
            @Retention(RetentionPolicy.RUNTIME)
            @Interceptors(DomainValidator.class)
            public @interface Validated {
            
            }
            


            @Stateless
            @Validated
            @Interceptors(SeamInterceptor.class)
            @Name("groupManager")
            @TransactionAttribute(TransactionAttributeType.SUPPORTS)
            public class GroupManager extends AbstractManager implements IGroupManager {
            ...
            ...
            }
            


            @Interceptor
            public class DomainValidator {
            
             @AroundInvoke
             public Object validate(InvocationContext invocationContext) throws Exception {
             Method method = invocationContext.getMethod();
             Object[] parameters = invocationContext.getParameters();
            
             Object instance = invocationContext.getTarget();
            
             System.out.println("========================================>");
            
             return invocationContext.proceed();
             }
            }
            


            Please, help me
            Have you any idea ?

            • 3. Re: TestNG and EJB3 interceptors
              fbenvegna

              I tried with Seam 2.0.0.GA... doesn't work too!
              Testing EJB3 interceptors is very important because many business operation and validation must be tested without deployment on AS.

              • 4. Re: TestNG and EJB3 interceptors
                fbenvegna

                My problem was test.
                I add a @BeforeMethod method inside test class for creating EJB and interceptor works fine.
                I don't know if it's a good solution.
                If you have any idea or comment, tell me please.

                 @BeforeMethod
                 public void before() throws Exception {
                 if (groupManager == null)
                 new FacesRequest() {
                 protected void invokeApplication() throws Exception {
                 groupManager = (IGroupManager) Component
                 .getInstance("groupManager");
                 }
                 }.run();
                 }