[weld-commits] Weld SVN: r4844 - in cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests: lifecycleCallback and 1 other directory.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Mon Nov 9 04:01:23 EST 2009
Author: jharting
Date: 2009-11-09 04:01:22 -0500 (Mon, 09 Nov 2009)
New Revision: 4844
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Chicken.java
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/GoatInterceptor.java
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/PackagePrivateLifecycleInterceptor.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/PrivateLifecycleInterceptor.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/ProtectedLifecycleInterceptor.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/PublicLifecycleInterceptor.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Sheep.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/SheepInterceptor.java
Log:
Tests for lifecycle callback interceptor methods.
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Chicken.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Chicken.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Chicken.java 2009-11-09 09:01:22 UTC (rev 4844)
@@ -0,0 +1,9 @@
+package org.jboss.jsr299.tck.interceptors.tests.lifecycleCallback;
+
+import javax.interceptor.Interceptors;
+
+ at Interceptors( { PublicLifecycleInterceptor.class, ProtectedLifecycleInterceptor.class, PackagePrivateLifecycleInterceptor.class, PrivateLifecycleInterceptor.class })
+class Chicken
+{
+
+}
Added: 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 (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Goat.java 2009-11-09 09:01:22 UTC (rev 4844)
@@ -0,0 +1,39 @@
+package org.jboss.jsr299.tck.interceptors.tests.lifecycleCallback;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.interceptor.Interceptors;
+
+ at Interceptors(GoatInterceptor.class)
+class Goat
+{
+ 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;
+ }
+}
Added: 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 (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/GoatInterceptor.java 2009-11-09 09:01:22 UTC (rev 4844)
@@ -0,0 +1,55 @@
+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/LifecycleCallbackInterceptorTest.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/LifecycleCallbackInterceptorTest.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/LifecycleCallbackInterceptorTest.java 2009-11-09 09:01:22 UTC (rev 4844)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, 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.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+
+import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecVersion;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.testng.annotations.Test;
+
+ at Artifact
+ at SpecVersion(spec = "int", version = "3.1.PFD")
+public class LifecycleCallbackInterceptorTest extends AbstractJSR299Test
+{
+ @Test
+ @SpecAssertion(section = "5", id = "a")
+ public void testPostConstructInterceptor()
+ {
+ getInstanceByType(Goat.class);
+ assert Goat.isPostConstructInterceptorCalled();
+ assert GoatInterceptor.isPostConstructInterceptorCalled();
+ }
+
+ @Test(groups = "ri-broken")
+ @SpecAssertion(section = "5", id = "a")
+ // WELD-279
+ 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);
+ // 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()
+ {
+ getInstanceByType(Chicken.class);
+ assert PublicLifecycleInterceptor.isIntercepted();
+ }
+
+ @Test
+ @SpecAssertion(section = "5", id = "k")
+ public void testProtectedLifecycleInterceptorMethod()
+ {
+ getInstanceByType(Chicken.class);
+ assert ProtectedLifecycleInterceptor.isIntercepted();
+ }
+
+ @Test
+ @SpecAssertion(section = "5", id = "l")
+ public void testPrivateLifecycleInterceptorMethod()
+ {
+ getInstanceByType(Chicken.class);
+ assert PrivateLifecycleInterceptor.isIntercepted();
+ }
+
+ @Test
+ @SpecAssertion(section = "5", id = "m")
+ public void testPackagePrivateLifecycleInterceptorMethod()
+ {
+ getInstanceByType(Chicken.class);
+ assert PackagePrivateLifecycleInterceptor.isIntercepted();
+ }
+
+ @Test
+ @SpecAssertion(section = "8", id = "c")
+ public void testLifeCycleCallbackInterceptorNotInvokedForMethodLevelInterceptor()
+ {
+ assert getInstanceByType(Sheep.class).foo().equals("bar");
+ assert SheepInterceptor.isAroundInvokeCalled();
+ assert !SheepInterceptor.isPostConstructCalled();
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/PackagePrivateLifecycleInterceptor.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/PackagePrivateLifecycleInterceptor.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/PackagePrivateLifecycleInterceptor.java 2009-11-09 09:01:22 UTC (rev 4844)
@@ -0,0 +1,28 @@
+package org.jboss.jsr299.tck.interceptors.tests.lifecycleCallback;
+
+import javax.annotation.PostConstruct;
+import javax.interceptor.InvocationContext;
+
+class PackagePrivateLifecycleInterceptor
+{
+ private static boolean intercepted = false;
+
+ @PostConstruct
+ void postConstruct(InvocationContext ctx)
+ {
+ intercepted = true;
+ try
+ {
+ ctx.proceed();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ public static boolean isIntercepted()
+ {
+ return intercepted;
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/PrivateLifecycleInterceptor.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/PrivateLifecycleInterceptor.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/PrivateLifecycleInterceptor.java 2009-11-09 09:01:22 UTC (rev 4844)
@@ -0,0 +1,28 @@
+package org.jboss.jsr299.tck.interceptors.tests.lifecycleCallback;
+
+import javax.annotation.PostConstruct;
+import javax.interceptor.InvocationContext;
+
+class PrivateLifecycleInterceptor
+{
+ private static boolean intercepted = false;
+
+ @PostConstruct
+ private void postConstruct(InvocationContext ctx)
+ {
+ intercepted = true;
+ try
+ {
+ ctx.proceed();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ public static boolean isIntercepted()
+ {
+ return intercepted;
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/ProtectedLifecycleInterceptor.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/ProtectedLifecycleInterceptor.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/ProtectedLifecycleInterceptor.java 2009-11-09 09:01:22 UTC (rev 4844)
@@ -0,0 +1,28 @@
+package org.jboss.jsr299.tck.interceptors.tests.lifecycleCallback;
+
+import javax.annotation.PostConstruct;
+import javax.interceptor.InvocationContext;
+
+class ProtectedLifecycleInterceptor
+{
+ private static boolean intercepted = false;
+
+ @PostConstruct
+ protected void postConstruct(InvocationContext ctx)
+ {
+ intercepted = true;
+ try
+ {
+ ctx.proceed();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ public static boolean isIntercepted()
+ {
+ return intercepted;
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/PublicLifecycleInterceptor.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/PublicLifecycleInterceptor.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/PublicLifecycleInterceptor.java 2009-11-09 09:01:22 UTC (rev 4844)
@@ -0,0 +1,28 @@
+package org.jboss.jsr299.tck.interceptors.tests.lifecycleCallback;
+
+import javax.annotation.PostConstruct;
+import javax.interceptor.InvocationContext;
+
+class PublicLifecycleInterceptor
+{
+ private static boolean intercepted = false;
+
+ @PostConstruct
+ void postConstruct(InvocationContext ctx)
+ {
+ intercepted = true;
+ try
+ {
+ ctx.proceed();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ public static boolean isIntercepted()
+ {
+ return intercepted;
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Sheep.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Sheep.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/Sheep.java 2009-11-09 09:01:22 UTC (rev 4844)
@@ -0,0 +1,12 @@
+package org.jboss.jsr299.tck.interceptors.tests.lifecycleCallback;
+
+import javax.interceptor.Interceptors;
+
+class Sheep
+{
+ @Interceptors(SheepInterceptor.class)
+ public String foo()
+ {
+ return "bar";
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/SheepInterceptor.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/SheepInterceptor.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/lifecycleCallback/SheepInterceptor.java 2009-11-09 09:01:22 UTC (rev 4844)
@@ -0,0 +1,34 @@
+package org.jboss.jsr299.tck.interceptors.tests.lifecycleCallback;
+
+import javax.annotation.PostConstruct;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+class SheepInterceptor
+{
+ private static boolean postConstructCalled = false;
+ private static boolean aroundInvokeCalled = false;
+
+ @PostConstruct
+ public void postConstruct()
+ {
+ postConstructCalled = true;
+ }
+
+ @AroundInvoke
+ public Object aroundInvoke(InvocationContext ctx) throws Exception
+ {
+ aroundInvokeCalled = true;
+ return ctx.proceed();
+ }
+
+ public static boolean isPostConstructCalled()
+ {
+ return postConstructCalled;
+ }
+
+ public static boolean isAroundInvokeCalled()
+ {
+ return aroundInvokeCalled;
+ }
+}
\ No newline at end of file
More information about the weld-commits
mailing list