[jboss-cvs] JBossAS SVN: r96130 - in projects/interceptors/trunk/jboss-interceptor/src: test/java/org/jboss/interceptors/proxy and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Nov 8 11:41:33 EST 2009
Author: marius.bogoevici
Date: 2009-11-08 11:41:32 -0500 (Sun, 08 Nov 2009)
New Revision: 96130
Added:
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FirstInterceptor.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/SecondInterceptor.java
Modified:
projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptionChain.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FootballTeam.java
projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java
Log:
Fix JBINTER-4
Modified: projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptionChain.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptionChain.java 2009-11-08 11:36:00 UTC (rev 96129)
+++ projects/interceptors/trunk/jboss-interceptor/src/main/java/org/jboss/interceptor/proxy/InterceptionChain.java 2009-11-08 16:41:32 UTC (rev 96130)
@@ -71,7 +71,7 @@
{
try
{
- return targetMethod.invoke(target, parameters);
+ return targetMethod.invoke(target, invocationContext.getParameters());
}
catch (InvocationTargetException e)
{
Added: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FirstInterceptor.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FirstInterceptor.java (rev 0)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FirstInterceptor.java 2009-11-08 16:41:32 UTC (rev 96130)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright <Year>, Red Hat, Inc. and/or its affiliates, 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.interceptors.proxy;
+
+import java.io.Serializable;
+
+import javax.annotation.PostConstruct;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+* @author Marius Bogoevici
+*/
+public class FirstInterceptor implements Serializable
+{
+
+ @AroundInvoke
+ private Object doAround(InvocationContext invocationContext) throws Exception
+ {
+ InterceptorTestLogger.add(FirstInterceptor.class, "aroundInvokeBefore");
+ Object result = invocationContext.proceed();
+ InterceptorTestLogger.add(FirstInterceptor.class, "aroundInvokeAfter");
+ return result;
+ }
+
+ @PostConstruct
+ public void doAfterConstruction(InvocationContext invocationContext) throws Exception
+ {
+ InterceptorTestLogger.add(FirstInterceptor.class, "postConstruct");
+ }
+}
Modified: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FootballTeam.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FootballTeam.java 2009-11-08 11:36:00 UTC (rev 96129)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/FootballTeam.java 2009-11-08 16:41:32 UTC (rev 96130)
@@ -48,6 +48,11 @@
return teamName;
}
+ public int echo(int i)
+ {
+ return i;
+ }
+
@PrePassivate
public void beforePassivating()
{
Modified: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java 2009-11-08 11:36:00 UTC (rev 96129)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/InterceptionTest.java 2009-11-08 16:41:32 UTC (rev 96130)
@@ -21,7 +21,6 @@
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.ByteArrayInputStream;
-import java.io.Serializable;
import org.jboss.interceptor.model.InterceptionModelBuilder;
import org.jboss.interceptor.model.InterceptionModel;
@@ -32,11 +31,6 @@
import org.junit.Assert;
import org.junit.Test;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.interceptor.AroundInvoke;
-import javax.interceptor.InvocationContext;
-
/**
* @author <a href="mailto:mariusb at redhat.com">Marius Bogoevici</a>
*/
@@ -93,9 +87,9 @@
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
- builder.interceptAroundInvoke(FootballTeam.class.getMethod("getName")).with(MyFirstInterceptor.class, MySecondInterceptor.class);
- builder.interceptPostConstruct().with(MyFirstInterceptor.class);
- builder.interceptPreDestroy().with(MySecondInterceptor.class);
+ builder.interceptAroundInvoke(FootballTeam.class.getMethod("getName")).with(FirstInterceptor.class, SecondInterceptor.class);
+ builder.interceptPostConstruct().with(FirstInterceptor.class);
+ builder.interceptPreDestroy().with(SecondInterceptor.class);
interceptionModel = builder.build();
this.interceptorRegistry = new InterceptorRegistry<Class<?>, Class<?>>();
this.interceptorRegistry.registerInterceptionModel(FootballTeam.class, interceptionModel);
@@ -108,7 +102,7 @@
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
- builder.interceptAll().with(MyFirstInterceptor.class, MySecondInterceptor.class);
+ builder.interceptAll().with(FirstInterceptor.class, SecondInterceptor.class);
interceptionModel = builder.build();
this.interceptorRegistry = new InterceptorRegistry<Class<?>, Class<?>>();
this.interceptorRegistry.registerInterceptionModel(FootballTeam.class, interceptionModel);
@@ -120,9 +114,9 @@
InterceptorTestLogger.reset();
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
- builder.interceptAll().with(MyFirstInterceptor.class);
- builder.interceptPreDestroy().with(MySecondInterceptor.class);
- builder.interceptAroundInvoke(FootballTeam.class.getMethod("getName")).with(MySecondInterceptor.class);
+ builder.interceptAll().with(FirstInterceptor.class);
+ builder.interceptPreDestroy().with(SecondInterceptor.class);
+ builder.interceptAroundInvoke(FootballTeam.class.getMethod("getName")).with(SecondInterceptor.class);
interceptionModel = builder.build();
this.interceptorRegistry = new InterceptorRegistry<Class<?>, Class<?>>();
this.interceptorRegistry.registerInterceptionModel(FootballTeam.class, interceptionModel);
@@ -133,9 +127,9 @@
{
InterceptorTestLogger.reset();
InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
- builder.interceptAll().with(MyFirstInterceptor.class);
- builder.interceptPreDestroy().with(MySecondInterceptor.class);
- builder.interceptAroundInvoke(FootballTeam.class.getMethod("getName")).with(MySecondInterceptor.class);
+ builder.interceptAll().with(FirstInterceptor.class);
+ builder.interceptPreDestroy().with(SecondInterceptor.class);
+ builder.interceptAroundInvoke(FootballTeam.class.getMethod("getName")).with(SecondInterceptor.class);
builder.ignoreGlobalInterceptors(FootballTeam.class.getMethod("getName"));
interceptionModel = builder.build();
this.interceptorRegistry = new InterceptorRegistry<Class<?>, Class<?>>();
@@ -209,6 +203,24 @@
assertRawObject(proxy);
}
+
+ @Test
+ public void testMethodParameterOverriding() throws Exception
+ {
+ InterceptorTestLogger.reset();
+
+ InterceptionModelBuilder<Class<?>, Class<?>> builder = InterceptionModelBuilder.newBuilderFor(FootballTeam.class, (Class) Class.class);
+
+ builder.interceptAroundInvoke(FootballTeam.class.getMethod("echo", int.class)).with(ParameterOverridingInterceptor.class);
+ interceptionModel = builder.build();
+ this.interceptorRegistry = new InterceptorRegistry<Class<?>, Class<?>>();
+ this.interceptorRegistry.registerInterceptionModel(FootballTeam.class, interceptionModel);
+
+ FootballTeam proxy = InterceptionUtils.proxifyInstance(new FootballTeam(TEAM_NAME), FootballTeam.class, interceptorRegistry, new DirectClassInterceptionHandlerFactory());
+ Assert.assertEquals(42, proxy.echo(1));
+ }
+
+
public void assertRawObject(FootballTeam proxy)
{
InterceptorTestLogger.reset();
@@ -229,40 +241,4 @@
}
- public static class MyFirstInterceptor implements Serializable
- {
-
- @AroundInvoke
- private Object doAround(InvocationContext invocationContext) throws Exception
- {
- InterceptorTestLogger.add(MyFirstInterceptor.class, "aroundInvokeBefore");
- Object result = invocationContext.proceed();
- InterceptorTestLogger.add(MyFirstInterceptor.class, "aroundInvokeAfter");
- return result;
- }
-
- @PostConstruct
- public void doAfterConstruction(InvocationContext invocationContext) throws Exception
- {
- InterceptorTestLogger.add(MyFirstInterceptor.class, "postConstruct");
- }
- }
-
- public static class MySecondInterceptor extends MyFirstInterceptor
- {
- @AroundInvoke
- private Object doAround(InvocationContext invocationContext) throws Exception
- {
- InterceptorTestLogger.add(MySecondInterceptor.class, "aroundInvokeBefore");
- Object result = invocationContext.proceed();
- InterceptorTestLogger.add(MySecondInterceptor.class, "aroundInvokeAfter");
- return result;
- }
-
- @PreDestroy
- private void doneHere(InvocationContext invocationContext) throws Exception
- {
- InterceptorTestLogger.add(MySecondInterceptor.class, "preDestroy");
- }
- }
}
Added: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor.java (rev 0)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/ParameterOverridingInterceptor.java 2009-11-08 16:41:32 UTC (rev 96130)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.interceptors.proxy;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class ParameterOverridingInterceptor
+{
+ @AroundInvoke
+ public Object overrideParameters(InvocationContext invocationContext) throws Exception
+ {
+ if (invocationContext.getMethod().getName().equals("echo"))
+ {
+ invocationContext.setParameters(new Object[]{Integer.valueOf(42)});
+ }
+ return invocationContext.proceed();
+ }
+}
Added: projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/SecondInterceptor.java
===================================================================
--- projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/SecondInterceptor.java (rev 0)
+++ projects/interceptors/trunk/jboss-interceptor/src/test/java/org/jboss/interceptors/proxy/SecondInterceptor.java 2009-11-08 16:41:32 UTC (rev 96130)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, 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.interceptors.proxy;
+
+import javax.annotation.PreDestroy;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+import org.jboss.interceptors.proxy.FirstInterceptor;
+
+/**
+* @author Marius Bogoevici
+*/
+public class SecondInterceptor extends FirstInterceptor
+{
+ @AroundInvoke
+ private Object doAround(InvocationContext invocationContext) throws Exception
+ {
+ InterceptorTestLogger.add(SecondInterceptor.class, "aroundInvokeBefore");
+ Object result = invocationContext.proceed();
+ InterceptorTestLogger.add(SecondInterceptor.class, "aroundInvokeAfter");
+ return result;
+ }
+
+ @PreDestroy
+ private void doneHere(InvocationContext invocationContext) throws Exception
+ {
+ InterceptorTestLogger.add(SecondInterceptor.class, "preDestroy");
+ }
+}
More information about the jboss-cvs-commits
mailing list