openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1622141 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/event/ test/java/org/apache/webbeans/test/portable/
Date Tue, 02 Sep 2014 22:05:49 GMT
Author: struberg
Date: Tue Sep  2 22:05:49 2014
New Revision: 1622141

URL: http://svn.apache.org/r1622141
Log:
OWB-997 add unit test and throw error if WithAnnotations is used on anything else than ProcessAnnoatedType

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/WithAnnotationTest.java
  (with props)
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java?rev=1622141&r1=1622140&r2=1622141&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ContainerEventObserverMethodImpl.java
Tue Sep  2 22:05:49 2014
@@ -55,6 +55,12 @@ public class ContainerEventObserverMetho
     }
 
     @Override
+    protected void checkObserverCondition(AnnotatedParameter<T> annotatedObservesParameter)
+    {
+        // all fine
+    }
+
+    @Override
     protected void invoke(final Object object, final Object[] args) throws IllegalAccessException,
InvocationTargetException
     {
         ExtensionAware extensionAware = null;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=1622141&r1=1622140&r2=1622141&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
Tue Sep  2 22:05:49 2014
@@ -42,8 +42,10 @@ import javax.enterprise.event.Transactio
 import javax.enterprise.inject.spi.AnnotatedMethod;
 import javax.enterprise.inject.spi.AnnotatedParameter;
 import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.DefinitionException;
 import javax.enterprise.inject.spi.EventMetadata;
 import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.WithAnnotations;
 
 import org.apache.webbeans.component.AbstractOwbBean;
 import org.apache.webbeans.component.WebBeansType;
@@ -95,7 +97,7 @@ public class ObserverMethodImpl<T> imple
 
     /** the type of the observed event */
     private final Type observedEventType;
-    
+
     /** the transaction phase */
     private final TransactionPhase phase;
     
@@ -164,8 +166,19 @@ public class ObserverMethodImpl<T> imple
                 injectionPoints.add(InjectionPointFactory.getPartialInjectionPoint(bean,
parameter, qualifierAnnots));
             }
         }
+
+        checkObserverCondition(annotatedObservesParameter);
     }
-    
+
+    protected void checkObserverCondition(AnnotatedParameter<T> annotatedObservesParameter)
+    {
+        if (annotatedObservesParameter.getAnnotation(WithAnnotations.class) != null)
+        {
+            throw new DefinitionException("@WithAnnotations must only be used for ProcessAnnotatedType
events");
+        }
+    }
+
+
     /**
      * {@inheritDoc}
      */

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/WithAnnotationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/WithAnnotationTest.java?rev=1622141&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/WithAnnotationTest.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/WithAnnotationTest.java
Tue Sep  2 22:05:49 2014
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.test.portable;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.enterprise.inject.spi.WithAnnotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test &#064WithAnnotation; annotation
+ */
+public class WithAnnotationTest extends AbstractUnitTest
+{
+
+    @Test
+    public void testWithAnnotation()
+    {
+        WithAnnotationExtension.scannedClasses = 0;
+
+        addExtension(new WithAnnotationExtension());
+        startContainer(WithoutAnyAnnotation.class, WithAnnotatedClass.class, WithAnnotatedField.class,
WithAnnotatedMethod.class);
+
+        Assert.assertEquals(3, WithAnnotationExtension.scannedClasses);
+    }
+
+
+    public static class WithAnnotationExtension implements Extension
+    {
+        public static int scannedClasses = 0;
+
+        public void processClassess(@Observes @WithAnnotations(MyAnnoation.class) ProcessAnnotatedType
pat)
+        {
+            scannedClasses += 1;
+        }
+
+        public void dontProcessClassess(@Observes @WithAnnotations(AnotherAnnoation.class)
ProcessAnnotatedType pat)
+        {
+            throw new IllegalStateException("This observer must not get called by the container!");
+        }
+    }
+
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD})
+    public static @interface MyAnnoation
+    {
+    }
+
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD})
+    public static @interface AnotherAnnoation
+    {
+    }
+
+
+    /**
+     * This class should not get picked up by the {@link org.apache.webbeans.test.portable.WithAnnotationTest.WithAnnotationExtension}
+     */
+    @ApplicationScoped
+    public static class WithoutAnyAnnotation
+    {
+        public int getMeanintOfLife()
+        {
+            return 42;
+        }
+    }
+
+
+    @ApplicationScoped
+    @MyAnnoation
+    public static class WithAnnotatedClass
+    {
+        public int getMeanintOfLife()
+        {
+            return 42;
+        }
+    }
+
+    @ApplicationScoped
+    public static class WithAnnotatedField
+    {
+        @MyAnnoation
+        private int x;
+
+        public int getMeanintOfLife()
+        {
+            return 42;
+        }
+    }
+
+    @ApplicationScoped
+    public static class WithAnnotatedMethod
+    {
+        @MyAnnoation
+        public int getMeanintOfLife()
+        {
+            return 42;
+        }
+    }
+
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/portable/WithAnnotationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message