KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > bmt > DeploymentDescriptorTesterBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.test.bmt;
23
24 import javax.ejb.EJB JavaDoc;
25 import javax.ejb.TransactionAttribute JavaDoc;
26 import javax.ejb.TransactionAttributeType JavaDoc;
27 import javax.transaction.TransactionManager JavaDoc;
28 import javax.transaction.Transaction JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import org.jboss.logging.Logger;
31 import org.jboss.annotation.JndiInject;
32
33 /**
34  * @version <tt>$Revision: 45473 $</tt>
35  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
36  */

37 public class DeploymentDescriptorTesterBean implements DeploymentDescriptorTesterRemote
38 {
39    @EJB JavaDoc DeploymentDescriptorStatelessLocal stateless;
40    @JndiInject(jndiName="java:/TransactionManager") TransactionManager JavaDoc tm;
41
42
43    protected static Logger log = Logger.getLogger(DeploymentDescriptorTesterBean.class);
44
45    public void testStatelessWithTx() throws Exception JavaDoc
46    {
47       stateless.beginCommitEnd();
48       stateless.beginRollbackEnd();
49
50       try
51       {
52          stateless.beginNoEnd();
53       }
54       catch (Exception JavaDoc e)
55       {
56          if (e instanceof TestException) throw e;
57          log.info("should be EJBException thrown that begin and no end was called: ", e);
58       }
59    }
60
61    @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
62    public void testStatelessWithoutTx() throws Exception JavaDoc
63    {
64       stateless.beginCommitEnd();
65       if (tm.getTransaction() != null) throw new RuntimeException JavaDoc("tx is associated");
66       stateless.beginRollbackEnd();
67       if (tm.getTransaction() != null) throw new RuntimeException JavaDoc("tx is associated");
68
69       try
70       {
71          stateless.beginNoEnd();
72       }
73       catch (Exception JavaDoc e)
74       {
75          if (e instanceof TestException) throw e;
76          log.info("should be EJBException thrown that begin and no end was called: ", e);
77       }
78       if (tm.getTransaction() != null) throw new RuntimeException JavaDoc("tx is associated");
79    }
80
81    DeploymentDescriptorStatefulLocal getStateful() throws Exception JavaDoc
82    {
83       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
84       return (DeploymentDescriptorStatefulLocal)ctx.lookup("DeploymentDescriptorStateful/local");
85    }
86
87    public void testStatefulWithTx() throws Exception JavaDoc
88    {
89       DeploymentDescriptorStatefulLocal stateful = getStateful();
90       Transaction JavaDoc tx = stateful.beginNoEnd();
91       stateful.endCommit(tx);
92       tx = stateful.beginNoEnd();
93       stateful.endRollback(tx);
94
95       stateful.beginCommitEnd();
96       stateful.beginRollbackEnd();
97
98    }
99
100    @TransactionAttribute JavaDoc(TransactionAttributeType.NOT_SUPPORTED)
101    public void testStatefulWithoutTx() throws Exception JavaDoc
102    {
103       DeploymentDescriptorStatefulLocal stateful = getStateful();
104       Transaction JavaDoc tx = stateful.beginNoEnd();
105       if (tm.getTransaction() != null) throw new RuntimeException JavaDoc("tx is associated");
106       stateful.endCommit(tx);
107       if (tm.getTransaction() != null) throw new RuntimeException JavaDoc("tx is associated");
108       tx = stateful.beginNoEnd();
109       if (tm.getTransaction() != null) throw new RuntimeException JavaDoc("tx is associated");
110       stateful.endRollback(tx);
111       if (tm.getTransaction() != null) throw new RuntimeException JavaDoc("tx is associated");
112
113       stateful.beginCommitEnd();
114       if (tm.getTransaction() != null) throw new RuntimeException JavaDoc("tx is associated");
115       stateful.beginRollbackEnd();
116       if (tm.getTransaction() != null) throw new RuntimeException JavaDoc("tx is associated");
117
118    }
119 }
120
Popular Tags