[weld-commits] Weld SVN: r4768 - in cdi-tck/trunk/impl/src/main: java/org/jboss/jsr299/tck/interceptors and 3 other directories.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Sun Nov 8 03:33:47 EST 2009
Author: jharting
Date: 2009-11-08 03:33:47 -0500 (Sun, 08 Nov 2009)
New Revision: 4768
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor1.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor2.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor3.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor4.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor5.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor6.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor7.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor8.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor9.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/InvocationContextTest.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/SimpleBean.java
Modified:
cdi-tck/trunk/impl/src/main/resources/tck-audit-int.xml
Log:
Added tests for InvocationContext implementation.
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor1.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor1.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor1.java 2009-11-08 08:33:47 UTC (rev 4768)
@@ -0,0 +1,28 @@
+package org.jboss.jsr299.tck.interceptors.tests.invocationContext;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+class Interceptor1
+{
+ private static boolean getTargetOK = false;
+
+ @AroundInvoke
+ public Object aroundInvoke(InvocationContext ctx) throws Exception
+ {
+ SimpleBean target = (SimpleBean) ctx.getTarget();
+ int id1 = target.getId();
+ int id2 = (Integer) ctx.proceed();
+
+ if (id1 == id2)
+ {
+ getTargetOK = true;
+ }
+ return id1;
+ }
+
+ public static boolean isGetTargetOK()
+ {
+ return getTargetOK;
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor2.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor2.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor2.java 2009-11-08 08:33:47 UTC (rev 4768)
@@ -0,0 +1,13 @@
+package org.jboss.jsr299.tck.interceptors.tests.invocationContext;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+class Interceptor2
+{
+ @AroundInvoke
+ public Object intercept(InvocationContext ctx) throws Exception
+ {
+ return ctx.getTimer() == null;
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor3.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor3.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor3.java 2009-11-08 08:33:47 UTC (rev 4768)
@@ -0,0 +1,13 @@
+package org.jboss.jsr299.tck.interceptors.tests.invocationContext;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+class Interceptor3
+{
+ @AroundInvoke
+ public Object intercept(InvocationContext ctx) throws Exception
+ {
+ return ctx.getMethod().equals(SimpleBean.class.getMethod("testGetMethod"));
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor4.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor4.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor4.java 2009-11-08 08:33:47 UTC (rev 4768)
@@ -0,0 +1,22 @@
+package org.jboss.jsr299.tck.interceptors.tests.invocationContext;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+class Interceptor4
+{
+ @AroundInvoke
+ public Object intercept(InvocationContext ctx) throws Exception
+ {
+ Object[] parameters = ctx.getParameters();
+ assert (Integer) parameters[0] == 1;
+ assert (Integer) parameters[1] == 2;
+ // modify parameter values
+ Integer[] newParameters = new Integer[] { 2, 3 };
+ ctx.setParameters(newParameters);
+ // verify getParameters() returns actual values
+ assert newParameters[0].equals(ctx.getParameters()[0]);
+ assert newParameters[1].equals(ctx.getParameters()[1]);
+ return ctx.proceed();
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor5.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor5.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor5.java 2009-11-08 08:33:47 UTC (rev 4768)
@@ -0,0 +1,15 @@
+package org.jboss.jsr299.tck.interceptors.tests.invocationContext;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+class Interceptor5
+{
+ @AroundInvoke
+ public Object intercept(InvocationContext ctx) throws Exception
+ {
+ Integer[] parameters = new Integer[] { 1, 2, 3 };
+ ctx.setParameters(parameters);
+ return ctx.proceed();
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor6.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor6.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor6.java 2009-11-08 08:33:47 UTC (rev 4768)
@@ -0,0 +1,16 @@
+package org.jboss.jsr299.tck.interceptors.tests.invocationContext;
+
+import java.util.HashSet;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+class Interceptor6
+{
+ @AroundInvoke
+ public Object intercept(InvocationContext ctx) throws Exception {
+ Object[] parameters = new Object[]{"1", new HashSet<Integer>()};
+ ctx.setParameters(parameters);
+ return ctx.proceed();
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor7.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor7.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor7.java 2009-11-08 08:33:47 UTC (rev 4768)
@@ -0,0 +1,20 @@
+package org.jboss.jsr299.tck.interceptors.tests.invocationContext;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+class Interceptor7
+{
+ private static boolean proceedReturnsNull = false;
+
+ @AroundInvoke
+ public Object intercept(InvocationContext ctx) throws Exception {
+ proceedReturnsNull = ctx.proceed() == null;
+ return null;
+ }
+
+ public static boolean isProceedReturnsNull()
+ {
+ return proceedReturnsNull;
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor8.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor8.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor8.java 2009-11-08 08:33:47 UTC (rev 4768)
@@ -0,0 +1,23 @@
+package org.jboss.jsr299.tck.interceptors.tests.invocationContext;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+class Interceptor8
+{
+ private static boolean contextDataOK = false;
+
+ @AroundInvoke
+ public Object intercept(InvocationContext ctx) throws Exception
+ {
+ ctx.getContextData().put("foo", "bar");
+ Object result = ctx.proceed();
+ contextDataOK = ctx.getContextData().get("foo").equals("barbar");
+ return result;
+ }
+
+ public static boolean isContextDataOK()
+ {
+ return contextDataOK;
+ }
+}
\ No newline at end of file
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor9.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor9.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/Interceptor9.java 2009-11-08 08:33:47 UTC (rev 4768)
@@ -0,0 +1,21 @@
+package org.jboss.jsr299.tck.interceptors.tests.invocationContext;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+class Interceptor9
+{
+ private static boolean contextDataOK = false;
+
+ @AroundInvoke
+ public Object intercept(InvocationContext ctx) throws Exception {
+ contextDataOK = ctx.getContextData().get("foo").equals("bar");
+ ctx.getContextData().put("foo", "barbar");
+ return ctx.proceed();
+ }
+
+ public static boolean isContextDataOK()
+ {
+ return contextDataOK;
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/InvocationContextTest.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/InvocationContextTest.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/InvocationContextTest.java 2009-11-08 08:33:47 UTC (rev 4768)
@@ -0,0 +1,107 @@
+/*
+ * 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.invocationContext;
+
+import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+import org.jboss.test.audit.annotations.SpecVersion;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.testng.annotations.Test;
+
+/**
+ * Tests for the InvocationContext implementation
+ * @author Jozef Hartinger
+ *
+ */
+
+ at Artifact
+ at SpecVersion(spec = "int", version = "3.1.PFD")
+public class InvocationContextTest extends AbstractJSR299Test
+{
+ @Test
+ @SpecAssertion(section = "6", id = "d")
+ public void testGetTargetMethod()
+ {
+ SimpleBean instance = getInstanceByType(SimpleBean.class);
+ instance.setId(10);
+ assert instance.getId() == 10;
+ assert Interceptor1.isGetTargetOK();
+ }
+
+ @Test
+ @SpecAssertion(section = "6", id = "f")
+ public void testGetTimerMethod()
+ {
+ assert getInstanceByType(SimpleBean.class).testGetTimer();
+ }
+
+ @Test
+ @SpecAssertion(section = "6", id = "g")
+ public void testGetMethodMethod()
+ {
+ assert getInstanceByType(SimpleBean.class).testGetMethod();
+ }
+
+ @Test(groups = "ri-broken")
+ @SpecAssertions( {
+ @SpecAssertion(section = "6", id = "i"),
+ @SpecAssertion(section = "6", id = "j"),
+ @SpecAssertion(section = "6", id = "k")
+ })
+ // WELD-275
+ public void testMethodParameters()
+ {
+ assert getInstanceByType(SimpleBean.class).add(1, 2) == 5;
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class, groups = "ri-broken")
+ @SpecAssertion(section = "6", id = "la")
+ // WELD-275
+ public void testIllegalNumberOfParameters()
+ {
+ getInstanceByType(SimpleBean.class).add2(1, 1);
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class, groups = "ri-broken")
+ @SpecAssertion(section = "6", id = "lb")
+ // WELD-275
+ public void testIllegalTypeOfParameters()
+ {
+ assert getInstanceByType(SimpleBean.class).add3(1, 1) == 2;
+ }
+
+ @Test
+ @SpecAssertion(section = "6", id = "o")
+ public void testProceedReturnsNullForVoidMethod()
+ {
+ getInstanceByType(SimpleBean.class).voidMethod();
+ assert Interceptor7.isProceedReturnsNull();
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "1", id = "d"),
+ @SpecAssertion(section = "6", id = "a")
+ })
+ public void testContextData()
+ {
+ getInstanceByType(SimpleBean.class).foo();
+ assert Interceptor8.isContextDataOK();
+ assert Interceptor9.isContextDataOK();
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/SimpleBean.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/SimpleBean.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/interceptors/tests/invocationContext/SimpleBean.java 2009-11-08 08:33:47 UTC (rev 4768)
@@ -0,0 +1,59 @@
+package org.jboss.jsr299.tck.interceptors.tests.invocationContext;
+
+import javax.interceptor.Interceptors;
+
+class SimpleBean
+{
+ private int id = 0;
+
+ @Interceptors(Interceptor1.class)
+ public int getId()
+ {
+ return id;
+ }
+
+ public void setId(int id)
+ {
+ this.id = id;
+ }
+
+ @Interceptors(Interceptor2.class)
+ public boolean testGetTimer()
+ {
+ return false;
+ }
+
+ @Interceptors(Interceptor3.class)
+ public boolean testGetMethod()
+ {
+ return false;
+ }
+
+ @Interceptors(Interceptor4.class)
+ public int add(int i, int j)
+ {
+ return i + j;
+ }
+
+ @Interceptors(Interceptor5.class)
+ public int add2(int i, int j)
+ {
+ return i + j;
+ }
+
+ @Interceptors(Interceptor6.class)
+ public int add3(int i, int j)
+ {
+ return i + j;
+ }
+
+ @Interceptors(Interceptor7.class)
+ public void voidMethod()
+ {
+ }
+
+ @Interceptors( { Interceptor8.class, Interceptor9.class })
+ public void foo()
+ {
+ }
+}
Modified: cdi-tck/trunk/impl/src/main/resources/tck-audit-int.xml
===================================================================
--- cdi-tck/trunk/impl/src/main/resources/tck-audit-int.xml 2009-11-08 08:29:57 UTC (rev 4767)
+++ cdi-tck/trunk/impl/src/main/resources/tck-audit-int.xml 2009-11-08 08:33:47 UTC (rev 4768)
@@ -109,9 +109,24 @@
<text>Around-invoke methods may be defined on interceptor classes and the target class (or superclass). However, only one around-invoke method may be present on a given class.</text>
</assertion>
- <assertion id="c">
+ <group>
<text>Around-invoke methods can have |public|, |private|, |protected|, or |package| level access. An around-invoke method must not be declared as |final| or |static|.</text>
- </assertion>
+ <assertion id="ca">
+ <text>Test with a |public| method.</text>
+ </assertion>
+
+ <assertion id="cb">
+ <text>Test with a |private| method.</text>
+ </assertion>
+
+ <assertion id="cc">
+ <text>Test with a |protected| method.</text>
+ </assertion>
+
+ <assertion id="cd">
+ <text>Test with a |package| method.</text>
+ </assertion>
+ </group>
<assertion id="d">
<text>Around-invoke methods have the following signature: |Object <METHOD>(InvocationContext) throws Exception|</text>
@@ -480,7 +495,7 @@
<text>The |getTarget()| method returns the associated target instance.</text>
</assertion>
- <assertion id="e">
+ <assertion id="e" testable="false">
<text>The |getTimer()| method returns the timer object associated with a timeout method invocation.</text>
</assertion>
@@ -512,9 +527,15 @@
<text>The |setParameters()| method modifies the parameters used for the target class method invocation. Modifying the parameter value does not affect the determination of the method that is invoked on the target class. </text>
</assertion>
- <assertion id="l">
+ <group>
<text>The parameter types must match the types for the target class method, and the number of parameters supplied must equal the number of parameters on the target class method, or an |IllegalArgumentException| is thrown.</text>
- </assertion>
+ <assertion id = "la">
+ <text>Test parameter types.</text>
+ </assertion>
+ <assertion id = "lb">
+ <text>Test number of parameters.</text>
+ </assertion>
+ </group>
<assertion id="m">
<text>The |proceed()| method causes the invocation of the next interceptor method in the chain, or when called from the last |AroundInvoke| interceptor method, the target class method.</text>
More information about the weld-commits
mailing list