openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1432423 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/creation/ test/java/org/apache/webbeans/newtests/interceptors/resolution/ test/java/org/apache/webbeans/newtests/interceptors/resolution/intercepto...
Date Sat, 12 Jan 2013 13:52:01 GMT
Author: struberg
Date: Sat Jan 12 13:52:00 2013
New Revision: 1432423

URL: http://svn.apache.org/viewvc?rev=1432423&view=rev
Log:
OWB-344 more tests for interceptor method detection

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestIntercepted1.java
  (contents, props changed)
      - copied, changed from r1432402, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/bindings/Transactional.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestInterceptor1.java
      - copied, changed from r1432402, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/TransactionalInterceptor.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestInterceptorParent.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorBeanBuilderTest.java
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.xml

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java?rev=1432423&r1=1432422&r2=1432423&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/AbstractBeanBuilder.java
Sat Jan 12 13:52:00 2013
@@ -162,6 +162,12 @@ public abstract class AbstractBeanBuilde
         {
             AnnotatedMethod alreadyDefined = it.next();
 
+            if (alreadyDefined == annotatedMethod)
+            {
+                // we don't remove ourself
+                continue;
+            }
+
             if (methodName == null)
             {
                 methodName = annotatedMethod.getJavaMember().getName();

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorBeanBuilderTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorBeanBuilderTest.java?rev=1432423&r1=1432422&r2=1432423&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorBeanBuilderTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/InterceptorBeanBuilderTest.java
Sat Jan 12 13:52:00 2013
@@ -28,6 +28,9 @@ import java.util.Collection;
 import org.apache.webbeans.component.creation.CdiInterceptorBeanBuilder;
 import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.newtests.interceptors.factory.beans.ClassInterceptedClass;
+import org.apache.webbeans.newtests.interceptors.resolution.interceptors.TestIntercepted1;
+import org.apache.webbeans.newtests.interceptors.resolution.interceptors.TestInterceptor1;
+import org.apache.webbeans.newtests.interceptors.resolution.interceptors.TestInterceptorParent;
 import org.apache.webbeans.test.component.intercept.webbeans.SecureAndTransactionalInterceptor;
 import org.apache.webbeans.test.component.intercept.webbeans.TransactionalInterceptor;
 import org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional;
@@ -49,6 +52,9 @@ public class InterceptorBeanBuilderTest 
         beanClasses.add(ClassInterceptedClass.class);
         beanClasses.add(Transactional.class);
         beanClasses.add(TransactionalInterceptor.class);
+        beanClasses.add(TestIntercepted1.class);
+        beanClasses.add(TestInterceptor1.class);
+        beanClasses.add(TestInterceptorParent.class);
 
         startContainer(beanClasses, beanXmls);
 
@@ -81,4 +87,36 @@ public class InterceptorBeanBuilderTest 
 
         shutDownContainer();
     }
+
+    @Test
+    public void testClassLevelParentInterceptor() throws Exception
+    {
+        Collection<String> beanXmls = new ArrayList<String>();
+        beanXmls.add(getXmlPath(this.getClass().getPackage().getName(), InterceptorResolutionServiceTest.class.getSimpleName()));
+
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(TestIntercepted1.class);
+        beanClasses.add(TestInterceptor1.class);
+        beanClasses.add(TestInterceptorParent.class);
+
+        startContainer(beanClasses, beanXmls);
+
+        AnnotatedType<TestInterceptor1> annotatedType = getBeanManager().createAnnotatedType(TestInterceptor1.class);
+
+        CdiInterceptorBeanBuilder<TestInterceptor1> ibb
+                = new CdiInterceptorBeanBuilder<TestInterceptor1>(getWebBeansContext(),
annotatedType);
+        ibb.defineCdiInterceptorRules();
+        Interceptor<TestInterceptor1> bean = ibb.getBean();
+        Assert.assertNotNull(bean);
+
+        Assert.assertTrue(bean.intercepts(InterceptionType.AROUND_INVOKE));
+        Assert.assertTrue(bean.intercepts(InterceptionType.AROUND_TIMEOUT));
+        Assert.assertTrue(bean.intercepts(InterceptionType.PRE_DESTROY));
+        Assert.assertTrue(bean.intercepts(InterceptionType.POST_CONSTRUCT));
+        Assert.assertFalse(bean.intercepts(InterceptionType.PRE_PASSIVATE));
+        Assert.assertFalse(bean.intercepts(InterceptionType.POST_ACTIVATE));
+        Assert.assertEquals(1, bean.getInterceptorBindings().size());
+
+        shutDownContainer();
+    }
 }

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestIntercepted1.java
(from r1432402, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/bindings/Transactional.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestIntercepted1.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestIntercepted1.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/bindings/Transactional.java&r1=1432402&r2=1432423&rev=1432423&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/bindings/Transactional.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestIntercepted1.java
Sat Jan 12 13:52:00 2013
@@ -16,19 +16,18 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.webbeans.test.component.intercept.webbeans.bindings;
+package org.apache.webbeans.newtests.interceptors.resolution.interceptors;
 
+import javax.interceptor.InterceptorBinding;
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-import javax.interceptor.InterceptorBinding;
-
 @InterceptorBinding
 @Retention(RetentionPolicy.RUNTIME)
 @Target( { ElementType.TYPE, ElementType.METHOD })
-public @interface Transactional 
+public @interface TestIntercepted1
 {
 
 }

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestIntercepted1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestInterceptor1.java
(from r1432402, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/TransactionalInterceptor.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestInterceptor1.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestInterceptor1.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/TransactionalInterceptor.java&r1=1432402&r2=1432423&rev=1432423&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/intercept/webbeans/TransactionalInterceptor.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestInterceptor1.java
Sat Jan 12 13:52:00 2013
@@ -16,32 +16,87 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.webbeans.test.component.intercept.webbeans;
+package org.apache.webbeans.newtests.interceptors.resolution.interceptors;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.interceptor.AroundInvoke;
+import javax.interceptor.AroundTimeout;
 import javax.interceptor.Interceptor;
 import javax.interceptor.InvocationContext;
 
-import org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional;
+import org.apache.webbeans.util.ExceptionUtil;
+
 
 @Interceptor
-@Transactional
-public class TransactionalInterceptor
+@TestIntercepted1
+public class TestInterceptor1 extends TestInterceptorParent
 {
+    public static int invocationCount = 0;
+    public static int exceptionCount = 0;
+    public static int postConstructCount = 0;
 
     @AroundInvoke
     public Object caller(InvocationContext context) throws Exception
     {
         try
         {
-            ShoppingCard.CALLED = true;
+            invocationCount++;
             return context.proceed();
             
-        }catch(Exception e)
+        } catch(Exception e)
+        {
+            exceptionCount++;
+            throw e;
+        }
+    }
+
+    /**
+     * another name -> no invocation -> 2 interceptors
+     */
+    @PostConstruct
+    public void anotherPostConstruct(InvocationContext context)
+    {
+        postConstructCount++;
+        try
+        {
+            context.proceed();
+        }
+        catch (Exception e)
+        {
+            ExceptionUtil.throwAsRuntimeException(e);
+        }
+
+    }
+
+    /**
+     * 2 private methods -> 2 interceptors
+     */
+    @PreDestroy
+    private void preDestroy(InvocationContext context)
+    {
+        preDestroyCount++;
+        try
+        {
+            context.proceed();
+        }
+        catch (Exception e)
         {
-            ShoppingCard.CALLED = false;
+            ExceptionUtil.throwAsRuntimeException(e);
         }
-        
-        return null;
+
+    }
+
+    /**
+     * overridden method -> only 1 interceptor
+     * @param context
+     */
+    @AroundTimeout
+    public Object aroundTimeout(InvocationContext context) throws Exception
+    {
+        aroundTimeoutCount++;
+        return context.proceed();
     }
+
+
 }

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestInterceptorParent.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestInterceptorParent.java?rev=1432423&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestInterceptorParent.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/resolution/interceptors/TestInterceptorParent.java
Sat Jan 12 13:52:00 2013
@@ -0,0 +1,70 @@
+/*
+ * 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.newtests.interceptors.resolution.interceptors;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.interceptor.AroundTimeout;
+import javax.interceptor.InvocationContext;
+
+import org.apache.webbeans.util.ExceptionUtil;
+
+
+public class TestInterceptorParent
+{
+    public static int postConstructCount = 0;
+    public static int preDestroyCount = 0;
+    public static int aroundTimeoutCount = 0;
+
+    @PostConstruct
+    public void postConstruct(InvocationContext context)
+    {
+        postConstructCount++;
+        try
+        {
+            context.proceed();
+        }
+        catch (Exception e)
+        {
+            ExceptionUtil.throwAsRuntimeException(e);
+        }
+    }
+
+    @PreDestroy
+    private void preDestroy(InvocationContext context)
+    {
+        preDestroyCount++;
+        try
+        {
+            context.proceed();
+        }
+        catch (Exception e)
+        {
+            ExceptionUtil.throwAsRuntimeException(e);
+        }
+    }
+
+    @AroundTimeout
+    public Object aroundTimeout(InvocationContext context) throws Exception
+    {
+        aroundTimeoutCount++;
+        return context.proceed();
+    }
+
+}

Modified: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.xml?rev=1432423&r1=1432422&r2=1432423&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.xml
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/newtests/interceptors/resolution/InterceptorResolutionServiceTest.xml
Sat Jan 12 13:52:00 2013
@@ -22,6 +22,7 @@ under the License.
         <class>org.apache.webbeans.test.component.intercept.webbeans.TransactionalInterceptor</class>
         <class>org.apache.webbeans.test.component.intercept.webbeans.ActionInterceptor</class>
         <class>org.apache.webbeans.test.component.intercept.webbeans.SecureInterceptor</class>
+        <class>org.apache.webbeans.newtests.interceptors.resolution.interceptors.TestInterceptor1</class>
     </interceptors>
     <decorators>
         <class>org.apache.webbeans.test.component.decorator.clean.ServiceDecorator</class>



Mime
View raw message