[weld-commits] Weld SVN: r5837 - cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Mon Feb 15 06:02:52 EST 2010


Author: jharting
Date: 2010-02-15 06:02:52 -0500 (Mon, 15 Feb 2010)
New Revision: 5837

Added:
   cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/AnimalInterceptor.java
   cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Cow.java
   cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Hen.java
Removed:
   cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/GoatInterceptor.java
Modified:
   cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Goat.java
   cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/LifecycleCallbackInterceptorTest.java
Log:
Tests for WELD-436

Copied: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/AnimalInterceptor.java (from rev 5715, cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/GoatInterceptor.java)
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/AnimalInterceptor.java	                        (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/AnimalInterceptor.java	2010-02-15 11:02:52 UTC (rev 5837)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.jsr299.tck.interceptors.tests.lifecycleCallback;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+class AnimalInterceptor
+{
+   private static Set<Class<?>> postConstructInterceptorCalledFor = new HashSet<Class<?>>();
+   private static Set<Class<?>> preDestroyInterceptorCalledFor = new HashSet<Class<?>>();
+
+   @PostConstruct
+   public void postConstruct(InvocationContext ctx)
+   {
+      postConstructInterceptorCalledFor.add(ctx.getTarget().getClass());
+      try
+      {
+         ctx.proceed();
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   @AroundInvoke
+   public Object intercept(InvocationContext ctx) throws Exception
+   {
+      if (ctx.getMethod().getName().equals("echo"))
+      {
+         return ctx.proceed() + ctx.getParameters()[0].toString();
+      }
+      else
+      {
+         return ctx.proceed();
+      }
+   }
+
+   @PreDestroy
+   public void preDestroy(InvocationContext ctx)
+   {
+      preDestroyInterceptorCalledFor.add(ctx.getTarget().getClass());
+      try
+      {
+         ctx.proceed();
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public static boolean isPostConstructInterceptorCalled(Class<?> clazz)
+   {
+      return postConstructInterceptorCalledFor.contains(clazz);
+   }
+
+   public static boolean isPreDestroyInterceptorCalled(Class<?> clazz)
+   {
+      return preDestroyInterceptorCalledFor.contains(clazz);
+   }
+}

Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Cow.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Cow.java	                        (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Cow.java	2010-02-15 11:02:52 UTC (rev 5837)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.jsr299.tck.interceptors.tests.lifecycleCallback;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.RequestScoped;
+import javax.interceptor.Interceptors;
+
+ at Interceptors(AnimalInterceptor.class)
+ at RequestScoped
+class Cow
+{
+   private static boolean postConstructInterceptorCalled = false;
+   private static boolean preDestroyInterceptorCalled = false;
+
+   @PostConstruct
+   public void postConstruct()
+   {
+      postConstructInterceptorCalled = true;
+   }
+
+   public String echo(String message)
+   {
+      return message;
+   }
+
+   @PreDestroy
+   public void preDestroy()
+   {
+      preDestroyInterceptorCalled = true;
+   }
+
+   public static boolean isPostConstructInterceptorCalled()
+   {
+      return postConstructInterceptorCalled;
+   }
+
+   public static boolean isPreDestroyInterceptorCalled()
+   {
+      return preDestroyInterceptorCalled;
+   }
+}

Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Goat.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Goat.java	2010-02-15 08:42:46 UTC (rev 5836)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Goat.java	2010-02-15 11:02:52 UTC (rev 5837)
@@ -20,7 +20,7 @@
 import javax.annotation.PreDestroy;
 import javax.interceptor.Interceptors;
 
- at Interceptors(GoatInterceptor.class)
+ at Interceptors(AnimalInterceptor.class)
 class Goat
 {
    private static boolean postConstructInterceptorCalled = false;
@@ -31,12 +31,12 @@
    {
       postConstructInterceptorCalled = true;
    }
-   
+
    public String echo(String message)
    {
       return message;
    }
-   
+
    @PreDestroy
    public void preDestroy()
    {

Deleted: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/GoatInterceptor.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/GoatInterceptor.java	2010-02-15 08:42:46 UTC (rev 5836)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/GoatInterceptor.java	2010-02-15 11:02:52 UTC (rev 5837)
@@ -1,71 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed 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.jboss.jsr299.tck.interceptors.tests.lifecycleCallback;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.InvocationContext;
-
-class GoatInterceptor
-{
-   private static boolean postConstructInterceptorCalled = false;
-   private static boolean preDestroyInterceptorCalled = false;
-
-   @PostConstruct
-   public void postConstruct(InvocationContext ctx)
-   {
-      postConstructInterceptorCalled = true;
-      try
-      {
-         ctx.proceed();
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-   
-   @AroundInvoke
-   public Object intercept(InvocationContext ctx) throws Exception {
-      return ctx.proceed() + ctx.getParameters()[0].toString();
-   }
-   
-   @PreDestroy
-   public void preDestroy(InvocationContext ctx)
-   {
-      preDestroyInterceptorCalled = true;
-      try
-      {
-         ctx.proceed();
-      }
-      catch (Exception e)
-      {
-         throw new RuntimeException(e);
-      }
-   }
-   
-   public static boolean isPostConstructInterceptorCalled()
-   {
-      return postConstructInterceptorCalled;
-   }
-
-   public static boolean isPreDestroyInterceptorCalled()
-   {
-      return preDestroyInterceptorCalled;
-   }
-}

Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Hen.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Hen.java	                        (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Hen.java	2010-02-15 11:02:52 UTC (rev 5837)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.jsr299.tck.interceptors.tests.lifecycleCallback;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.ApplicationScoped;
+import javax.interceptor.Interceptors;
+
+ at Interceptors(AnimalInterceptor.class)
+ at ApplicationScoped
+class Hen
+{
+   private static boolean postConstructInterceptorCalled = false;
+   private static boolean preDestroyInterceptorCalled = false;
+
+   @PostConstruct
+   public void postConstruct()
+   {
+      postConstructInterceptorCalled = true;
+   }
+   
+   public String echo(String message)
+   {
+      return message;
+   }
+   
+   @PreDestroy
+   public void preDestroy()
+   {
+      preDestroyInterceptorCalled = true;
+   }
+
+   public static boolean isPostConstructInterceptorCalled()
+   {
+      return postConstructInterceptorCalled;
+   }
+
+   public static boolean isPreDestroyInterceptorCalled()
+   {
+      return preDestroyInterceptorCalled;
+   }
+}

Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/LifecycleCallbackInterceptorTest.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/LifecycleCallbackInterceptorTest.java	2010-02-15 08:42:46 UTC (rev 5836)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/LifecycleCallbackInterceptorTest.java	2010-02-15 11:02:52 UTC (rev 5837)
@@ -31,34 +31,53 @@
 {
    @Test
    @SpecAssertion(section = "5", id = "a")
+   // WELD-436
    public void testPostConstructInterceptor()
    {
       getInstanceByType(Goat.class);
       assert Goat.isPostConstructInterceptorCalled();
-      assert GoatInterceptor.isPostConstructInterceptorCalled();
+      assert AnimalInterceptor.isPostConstructInterceptorCalled(Goat.class);
+      getInstanceByType(Hen.class);
+      assert Hen.isPostConstructInterceptorCalled();
+      assert AnimalInterceptor.isPostConstructInterceptorCalled(Hen.class);
+      getInstanceByType(Cow.class);
+      assert Cow.isPostConstructInterceptorCalled();
+      assert AnimalInterceptor.isPostConstructInterceptorCalled(Cow.class);
    }
-   
+
    @Test
    @SpecAssertion(section = "5", id = "a")
+   // WELD-436
    public void testPreDestroyInterceptor()
    {
-      // create the instance
-      Bean<Goat> bean = getBeans(Goat.class).iterator().next();
-      CreationalContext<Goat> ctx = getCurrentManager().createCreationalContext(bean);
-      Goat instance = (Goat) getCurrentManager().getReference(bean, Goat.class, ctx);
+      createAndDestroyInstance(Goat.class);
+      assert Goat.isPreDestroyInterceptorCalled();
+      assert AnimalInterceptor.isPreDestroyInterceptorCalled(Goat.class);
+      createAndDestroyInstance(Hen.class);
+      assert Hen.isPreDestroyInterceptorCalled();
+      assert AnimalInterceptor.isPreDestroyInterceptorCalled(Hen.class);
+      createAndDestroyInstance(Hen.class);
+      assert Hen.isPreDestroyInterceptorCalled();
+      assert AnimalInterceptor.isPreDestroyInterceptorCalled(Hen.class);
+   }
+
+   @SuppressWarnings("unchecked")
+   private <T> void createAndDestroyInstance(Class<T> clazz)
+   {
+      Bean<T> bean = getBeans(clazz).iterator().next();
+      CreationalContext<T> ctx = getCurrentManager().createCreationalContext(bean);
+      T instance = (T) getCurrentManager().getReference(bean, clazz, ctx);
       // destroy the instance
       bean.destroy(instance, ctx);
-      assert Goat.isPreDestroyInterceptorCalled();
-      assert GoatInterceptor.isPreDestroyInterceptorCalled();
    }
-   
+
    @Test
    @SpecAssertion(section = "5", id = "c")
    public void testAroundInvokeAndLifeCycleCallbackInterceptorsCanBeDefinedOnTheSameClass()
    {
       assert getInstanceByType(Goat.class).echo("foo").equals("foofoo");
    }
-   
+
    @Test
    @SpecAssertion(section = "5", id = "j")
    public void testPublicLifecycleInterceptorMethod()
@@ -66,7 +85,7 @@
       getInstanceByType(Chicken.class);
       assert PublicLifecycleInterceptor.isIntercepted();
    }
-   
+
    @Test
    @SpecAssertion(section = "5", id = "k")
    public void testProtectedLifecycleInterceptorMethod()
@@ -74,7 +93,7 @@
       getInstanceByType(Chicken.class);
       assert ProtectedLifecycleInterceptor.isIntercepted();
    }
-   
+
    @Test
    @SpecAssertion(section = "5", id = "l")
    public void testPrivateLifecycleInterceptorMethod()
@@ -82,7 +101,7 @@
       getInstanceByType(Chicken.class);
       assert PrivateLifecycleInterceptor.isIntercepted();
    }
-   
+
    @Test
    @SpecAssertion(section = "5", id = "m")
    public void testPackagePrivateLifecycleInterceptorMethod()
@@ -90,7 +109,7 @@
       getInstanceByType(Chicken.class);
       assert PackagePrivateLifecycleInterceptor.isIntercepted();
    }
-   
+
    @Test
    @SpecAssertion(section = "8", id = "c")
    public void testLifeCycleCallbackInterceptorNotInvokedForMethodLevelInterceptor()



More information about the weld-commits mailing list