You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ma...@apache.org on 2007/04/06 06:42:20 UTC
svn commit: r526053 - in /incubator/openejb/trunk/openejb3/itests:
openejb-itests-beans/
openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/
openejb-itests-beans/src/main/resources/META-INF/
openejb-itests-client/src/main/java/org/apache/op...
Author: manugeorge
Date: Thu Apr 5 21:42:19 2007
New Revision: 526053
URL: http://svn.apache.org/viewvc?view=rev&rev=526053
Log:
Basic Tests for Mdb Interceptor functionality.
Added:
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/InterceptorMdbBean.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/InterceptorMdbObject.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/MdbInterceptor.java
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/mdb/MdbInterceptorTests.java
Modified:
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/pom.xml
incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/openejb-jar.xml
incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/mdb/MdbTestSuite.java
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/pom.xml?view=diff&rev=526053&r1=526052&r2=526053
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/pom.xml (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/pom.xml Thu Apr 5 21:42:19 2007
@@ -34,8 +34,12 @@
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-annotation_1.0_spec</artifactId>
+ <artifactId>geronimo-interceptor_3.0_spec</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.0_spec</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.1_spec</artifactId>
Added: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/InterceptorMdbBean.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/InterceptorMdbBean.java?view=auto&rev=526053
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/InterceptorMdbBean.java (added)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/InterceptorMdbBean.java Thu Apr 5 21:42:19 2007
@@ -0,0 +1,142 @@
+/**
+ *
+ * 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.openejb.test.mdb;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJBException;
+import javax.ejb.MessageDriven;
+import javax.ejb.MessageDrivenBean;
+import javax.ejb.MessageDrivenContext;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptors;
+import javax.interceptor.InvocationContext;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.naming.InitialContext;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+import org.apache.openejb.test.TestFailureException;
+
+@Interceptors ({MdbInterceptor.class})
+@MessageDriven(activationConfig = {
+ @ActivationConfigProperty(propertyName="destinationType", propertyValue = "javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName="destination", propertyValue = "InterceptorMdbBean")})
+public class InterceptorMdbBean implements MessageListener, MessageDrivenBean {
+
+ private boolean classLevelBusinessMethodInterception = false;
+ private boolean methodLevelBusinessMethodInterception = false;
+ protected static boolean classLevelCreateMethodInterception = false;
+ private boolean methodLevelCreateMethodInterception = false;
+ private MessageDrivenContext mdbContext;
+ private Session session;
+ private Connection connection;
+ protected MdbInvoker mdbInvoker;
+ @Resource(name="jms", type=javax.jms.QueueConnectionFactory.class)
+ private ConnectionFactory connectionFactory;
+
+ public void onMessage(Message msg) {
+ try {
+ classLevelBusinessMethodInterception = msg.getBooleanProperty("ClassLevelBusinessMethodInterception");
+ methodLevelBusinessMethodInterception = msg.getBooleanProperty("MethodLevelBusinessMethodInterception");
+ try {
+ msg.acknowledge();
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ mdbInvoker.onMessage(msg);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AroundInvoke
+ public Object mdbInterceptor(InvocationContext ctx) throws Exception
+ {
+ Object[] objArr = ctx.getParameters();
+ Message msg = (Message)objArr[0];
+ msg.setBooleanProperty("MethodLevelBusinessMethodInterception",true);
+ ctx.setParameters(objArr);
+ return ctx.proceed();
+ }
+
+ @PostConstruct
+ public void ejbCreate() throws EJBException
+ {
+ methodLevelCreateMethodInterception = true;
+ }
+
+
+ public void checkMethodLevelBusinessMethodInterception() throws TestFailureException{
+ try {
+ Assert.assertTrue("Method Level Business Method Interception failed for Mdb", methodLevelBusinessMethodInterception);
+ } catch (AssertionFailedError afe) {
+ throw new TestFailureException(afe);
+ }
+ }
+
+ public void checkMethodLevelCreateMethodInterception() throws TestFailureException{
+ try {
+ Assert.assertTrue("Method Level Business Method Interception failed for Mdb", methodLevelCreateMethodInterception);
+ } catch (AssertionFailedError afe) {
+ throw new TestFailureException(afe);
+ }
+ }
+
+
+ public void checkClassLevelBusinessMethodInterception() throws TestFailureException{
+ try {
+ Assert.assertTrue("Class Level Business Method Interception failed for Mdb", classLevelBusinessMethodInterception);
+ } catch (AssertionFailedError afe) {
+ throw new TestFailureException(afe);
+ }
+ }
+
+ public void checkClassLevelCreateMethodInterception() throws TestFailureException{
+ try {
+ Assert.assertTrue("Class Level Business Method Interception failed for Mdb", classLevelCreateMethodInterception);
+ } catch (AssertionFailedError afe) {
+ throw new TestFailureException(afe);
+ }
+ }
+
+
+ public void ejbRemove() throws EJBException {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException {
+ this.mdbContext = ctx;
+ try {
+ mdbInvoker = new MdbInvoker(connectionFactory, this);
+ } catch (Exception e) {
+ throw new EJBException(e);
+ }
+ }
+
+}
Added: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/InterceptorMdbObject.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/InterceptorMdbObject.java?view=auto&rev=526053
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/InterceptorMdbObject.java (added)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/InterceptorMdbObject.java Thu Apr 5 21:42:19 2007
@@ -0,0 +1,33 @@
+/**
+ *
+ * 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.openejb.test.mdb;
+
+import org.apache.openejb.test.TestFailureException;
+
+public interface InterceptorMdbObject {
+
+ public void checkClassLevelBusinessMethodInterception() throws TestFailureException;
+
+ public void checkMethodLevelBusinessMethodInterception() throws TestFailureException;
+
+ public void checkClassLevelCreateMethodInterception() throws TestFailureException;
+
+ public void checkMethodLevelCreateMethodInterception() throws TestFailureException;
+
+}
Added: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/MdbInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/MdbInterceptor.java?view=auto&rev=526053
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/MdbInterceptor.java (added)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/java/org/apache/openejb/test/mdb/MdbInterceptor.java Thu Apr 5 21:42:19 2007
@@ -0,0 +1,69 @@
+/**
+ *
+ * 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.openejb.test.mdb;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.ejb.EJBException;
+import javax.ejb.MessageDrivenContext;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+import javax.jms.Message;
+
+import org.apache.openejb.test.entity.bmp.BasicBmpHome;
+import org.apache.openejb.test.stateful.BasicStatefulHome;
+import org.apache.openejb.test.stateless.BasicStatelessHome;
+
+public class MdbInterceptor {
+ @Resource
+ private MessageDrivenContext mdbContext;
+ @EJB(beanName = "BasicBmpBean")
+ private BasicBmpHome bmpHome;
+ @EJB(beanName = "BasicStatefulBean")
+ private BasicStatefulHome statefulHome;
+ @EJB(beanName = "BasicStatelessBean")
+ private BasicStatelessHome statelessHome;
+
+
+ @AroundInvoke
+ public Object mdbInterceptor(InvocationContext ctx) throws Exception
+ {
+ Object[] objArr = ctx.getParameters();
+ Message msg = (Message)objArr[0];
+ msg.clearProperties();
+ msg.setBooleanProperty("ClassLevelBusinessMethodInterception",true);
+ ctx.setParameters(objArr);
+ return ctx.proceed();
+ }
+
+ @PreDestroy
+ public void interceptRemove(InvocationContext ctx) throws Exception {
+ ctx.proceed();
+ }
+
+ @PostConstruct
+ public void postConstruct(InvocationContext ctx) throws Exception {
+ InterceptorMdbBean.classLevelCreateMethodInterception = true;
+ ctx.proceed();
+ }
+
+
+}
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/openejb-jar.xml
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/openejb-jar.xml?view=diff&rev=526053&r1=526052&r2=526053
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/openejb-jar.xml (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-beans/src/main/resources/META-INF/openejb-jar.xml Thu Apr 5 21:42:19 2007
@@ -341,5 +341,9 @@
<resource-link res-ref-name="queueConnectionFactory" res-id="Default JMS Connection Factory"/>
<resource-link res-ref-name="topicConnectionFactory" res-id="Default JMS Connection Factory"/>
</ejb-deployment>
- <ejb-deployment ejb-name="TimerSyncBean" deployment-id="TimerSyncBean" container-id="Default Stateless Container"/>
+ <ejb-deployment ejb-name="TimerSyncBean" deployment-id="TimerSyncBean" container-id="Default Stateless Container"/>
+ <ejb-deployment ejb-name="InterceptorMdbBean" deployment-id="InterceptorMdbBean" container-id="Default MDB Container">
+ <resource-link res-ref-name="jms" res-id="Default JMS Connection Factory"/>
+ </ejb-deployment>
+
</openejb-jar>
Added: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/mdb/MdbInterceptorTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/mdb/MdbInterceptorTests.java?view=auto&rev=526053
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/mdb/MdbInterceptorTests.java (added)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/mdb/MdbInterceptorTests.java Thu Apr 5 21:42:19 2007
@@ -0,0 +1,92 @@
+/**
+ *
+ * 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.openejb.test.mdb;
+
+import org.apache.openejb.test.TestFailureException;
+import org.apache.openejb.test.TestManager;
+
+public class MdbInterceptorTests extends MdbTestClient {
+
+ public MdbInterceptorTests() {
+ super("MDBInterceptor.");
+ // TODO Auto-generated constructor stub
+ }
+ protected InterceptorMdbObject ejbObject;
+
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ejbObject = MdbProxy.newProxyInstance(InterceptorMdbObject.class, connectionFactory, "InterceptorMdbBean");
+ TestManager.getDatabase().createEntityTable();
+ }
+
+ protected void tearDown() throws Exception {
+ MdbProxy.destroyProxy(ejbObject);
+ try {
+ TestManager.getDatabase().dropEntityTable();
+ } catch (Exception e){
+ throw e;
+ } finally {
+ super.tearDown();
+ }
+ }
+
+ public void test01_checkClassLevelBusinessMethodInterception() {
+ try{
+ ejbObject.checkClassLevelBusinessMethodInterception();
+ } catch (TestFailureException e){
+ throw e.error;
+ } catch (Exception e){
+ fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ }
+
+ public void test02_checkMethodLevelBusinessMethodInterception() {
+ try{
+ ejbObject.checkMethodLevelBusinessMethodInterception();
+ } catch (TestFailureException e){
+ throw e.error;
+ } catch (Exception e){
+ fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ }
+
+ public void test03_checkClassLevelCreateMethodInterception() {
+ try{
+ ejbObject.checkClassLevelCreateMethodInterception();
+ } catch (TestFailureException e){
+ throw e.error;
+ } catch (Exception e){
+ fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ }
+
+ public void test04_checkMethodLevelCreateMethodInterception() {
+ try{
+ ejbObject.checkMethodLevelCreateMethodInterception();
+ } catch (TestFailureException e){
+ throw e.error;
+ } catch (Exception e){
+ fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
+ }
+ }
+
+
+}
Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/mdb/MdbTestSuite.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/mdb/MdbTestSuite.java?view=diff&rev=526053&r1=526052&r2=526053
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/mdb/MdbTestSuite.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/mdb/MdbTestSuite.java Thu Apr 5 21:42:19 2007
@@ -53,6 +53,7 @@
suite.addTest(new MdbFieldInjectionTests());
suite.addTest(new MdbSetterInjectionTests());
suite.addTest(new MdbAnnotatedFieldInjectionTests());
+ suite.addTest(new MdbInterceptorTests());
return suite;
}