You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2014/10/06 22:59:59 UTC

svn commit: r1629763 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/util/AnnotationUtil.java test/java/org/apache/webbeans/test/interceptors/extension/BeforeBeanDiscoveryImplTest.java

Author: rmannibucau
Date: Mon Oct  6 20:59:58 2014
New Revision: 1629763

URL: http://svn.apache.org/r1629763
Log:
OWB-1017 wrong test to match interceptor binding from AnnotatedType, thanks Antonin Stefanutti to have found it and provided a sample

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/extension/BeforeBeanDiscoveryImplTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java?rev=1629763&r1=1629762&r2=1629763&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java Mon Oct  6 20:59:58 2014
@@ -188,7 +188,7 @@ public final class AnnotationUtil
 
         // check if the annotationTypes are equal
         if (qualifier1AnnotationType == null
-                || !qualifier1AnnotationType.equals(annotation2.annotationType()))
+                || !annotation1.annotationType().equals(annotation2.annotationType()))
         {
             return false;
         }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/extension/BeforeBeanDiscoveryImplTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/extension/BeforeBeanDiscoveryImplTest.java?rev=1629763&r1=1629762&r2=1629763&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/extension/BeforeBeanDiscoveryImplTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/interceptors/extension/BeforeBeanDiscoveryImplTest.java Mon Oct  6 20:59:58 2014
@@ -23,6 +23,7 @@ import org.apache.webbeans.container.Ann
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.junit.Test;
 
+import javax.annotation.Priority;
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
@@ -30,7 +31,9 @@ import javax.enterprise.inject.spi.Annot
 import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.BeforeBeanDiscovery;
 import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.util.AnnotationLiteral;
 import javax.enterprise.util.Nonbinding;
+import javax.interceptor.AroundConstruct;
 import javax.interceptor.AroundInvoke;
 import javax.interceptor.Interceptor;
 import javax.interceptor.InterceptorBinding;
@@ -62,6 +65,90 @@ public class BeforeBeanDiscoveryImplTest
         assertEquals("bean", instance.noInterceptor());
     }
 
+    @Test
+    public void classAndMethod() {
+        addExtension(new OwbExtension());
+        addInterceptor(OwbMethodInterceptor.class);
+        startContainer(OwbBean.class);
+
+        final OwbBean instance = getInstance(OwbBean.class);
+        assertEquals("ok", instance.method());
+        assertEquals(0, instance.getCounter());
+    }
+
+    @OwbClassBinding
+    public static class OwbBean {
+        private int counter;
+
+        @OwbMethodBinding
+        public String method() {
+            throw new UnsupportedOperationException();
+        }
+
+        public void incr() {
+            counter++;
+        }
+
+        public int getCounter() {
+            return counter;
+        }
+    }
+
+    public static class OwbExtension implements Extension {
+        private void addInterceptorBindings(@Observes BeforeBeanDiscovery bbd, BeanManager manager) {
+            final AnnotatedType<OwbMethodBinding> annotatedType1 = manager.createAnnotatedType(OwbMethodBinding.class);
+            final Set<Annotation> annotations = annotatedType1.getAnnotations();
+            annotations.add(new EmptyAnnotationLiteral<InterceptorBinding>() {});
+
+            final AnnotatedType<OwbMethodBinding> annotatedType = new AnnotatedTypeWrapper<OwbMethodBinding>(this, annotatedType1) {
+                @Override
+                public Set<Annotation> getAnnotations()
+                {
+                    return annotations;
+                }
+
+                @Override
+                public boolean isAnnotationPresent(final Class<? extends Annotation> aClass)
+                {
+                    return super.isAnnotationPresent(aClass) || InterceptorBinding.class == aClass;
+                }
+            };
+            bbd.addInterceptorBinding(annotatedType);
+        }
+    }
+
+    @InterceptorBinding
+    @Target({ ElementType.TYPE, ElementType.METHOD })
+    @Retention(RetentionPolicy.RUNTIME)
+    static @interface OwbClassBinding {
+    }
+
+    //@InterceptorBinding
+    @Target({ ElementType.TYPE, ElementType.METHOD })
+    @Retention(RetentionPolicy.RUNTIME)
+    static @interface OwbMethodBinding {
+    }
+
+    @OwbMethodBinding
+    @Interceptor
+    @Priority(1000 + 10)
+    static class OwbMethodInterceptor {
+        @AroundConstruct
+        private Object constructor(InvocationContext context) throws Exception {
+            final Object proceed = context.proceed();
+            OwbBean.class.cast(context.getTarget()).incr();
+            return proceed;
+        }
+
+        @AroundInvoke
+        private Object method(InvocationContext context) throws Exception {
+            if (context.getMethod().getName().equals("method")) {
+                return "ok";
+            }
+            return context.proceed();
+        }
+    }
+
     public static class TheExtension implements Extension
     {
         void obs(@Observes final BeforeBeanDiscovery bbd, final BeanManager bm)