001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.test.stateful;
017:
018: import junit.framework.Assert;
019: import junit.framework.AssertionFailedError;
020: import org.apache.openejb.test.TestFailureException;
021: import org.apache.openejb.test.entity.bmp.BasicBmpHome;
022: import org.apache.openejb.test.stateless.BasicStatelessHome;
023: import org.apache.openejb.test.stateless.BasicStatelessBusinessLocal;
024: import org.apache.openejb.test.stateless.BasicStatelessBusinessRemote;
025:
026: import javax.ejb.CreateException;
027: import javax.ejb.SessionContext;
028: import javax.ejb.SessionBean;
029: import javax.ejb.EJBException;
030: import javax.persistence.EntityManager;
031: import javax.persistence.EntityManagerFactory;
032: import javax.sql.DataSource;
033: import javax.naming.InitialContext;
034: import javax.jms.ConnectionFactory;
035: import javax.jms.Session;
036: import javax.jms.Topic;
037: import javax.jms.MessageProducer;
038: import javax.jms.QueueConnectionFactory;
039: import javax.jms.TopicConnectionFactory;
040: import javax.jms.JMSException;
041: import java.rmi.RemoteException;
042:
043: /**
044: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
045: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
046: */
047: public class FieldInjectionStatefulBean implements SessionBean {
048:
049: private String name;
050: private SessionContext ejbContext;
051: private BasicBmpHome bmpHome;
052: private BasicStatefulHome statefulHome;
053: private BasicStatelessHome statelessHome;
054: private String striing;
055: private Double doouble;
056: private Long loong;
057: private Float flooat;
058: private Integer inteeger;
059: private Short shoort;
060: private Boolean booolean;
061: private Byte byyte;
062: private Character chaaracter;
063: private DataSource daataSource;
064: private ConnectionFactory coonnectionFactory;
065: private QueueConnectionFactory queueCoonnectionFactory;
066: private TopicConnectionFactory topicCoonnectionFactory;
067: private EntityManagerFactory emf;
068: private EntityManager em;
069: private EntityManager eem;
070: private EntityManager pem;
071: private BasicStatelessBusinessLocal statelessBusinessLocal;
072: private BasicStatelessBusinessRemote statelessBusinessRemote;
073: private BasicStatefulBusinessLocal statefulBusinessLocal;
074: private BasicStatefulBusinessRemote statefulBusinessRemote;
075:
076: //=============================
077: // Home interface methods
078: //
079:
080: /**
081: * Maps to EncStatefulHome.create
082: *
083: * @param name
084: * @throws javax.ejb.CreateException
085: * @see EncStatefulHome#create
086: */
087: public void ejbCreate(String name) throws CreateException {
088: this .name = name;
089: }
090:
091: //
092: // Home interface methods
093: //=============================
094:
095: //=============================
096: // Remote interface methods
097: //
098:
099: public void lookupEntityBean() throws TestFailureException {
100: try {
101: Assert.assertNotNull("The EJBObject is null", bmpHome);
102: } catch (AssertionFailedError afe) {
103: throw new TestFailureException(afe);
104: }
105: }
106:
107: public void lookupStatefulBean() throws TestFailureException {
108: try {
109: Assert.assertNotNull("The EJBObject is null", statefulHome);
110: } catch (AssertionFailedError afe) {
111: throw new TestFailureException(afe);
112: }
113: }
114:
115: public void lookupStatelessBean() throws TestFailureException {
116: try {
117: Assert
118: .assertNotNull("The EJBObject is null",
119: statelessHome);
120: } catch (AssertionFailedError afe) {
121: throw new TestFailureException(afe);
122: }
123: }
124:
125: public void lookupStatelessBusinessLocal()
126: throws TestFailureException {
127: try {
128: Assert.assertNotNull("The EJB BusinessLocal is null",
129: statelessBusinessLocal);
130: } catch (AssertionFailedError afe) {
131: throw new TestFailureException(afe);
132: }
133: }
134:
135: public void lookupStatelessBusinessRemote()
136: throws TestFailureException {
137: try {
138: Assert.assertNotNull("The EJB BusinessRemote is null",
139: statelessBusinessRemote);
140: } catch (AssertionFailedError afe) {
141: throw new TestFailureException(afe);
142: }
143: }
144:
145: public void lookupStatefulBusinessLocal()
146: throws TestFailureException {
147: try {
148: Assert.assertNotNull("The EJB BusinessLocal is null",
149: statefulBusinessLocal);
150: } catch (AssertionFailedError afe) {
151: throw new TestFailureException(afe);
152: }
153: }
154:
155: public void lookupStatefulBusinessRemote()
156: throws TestFailureException {
157: try {
158: Assert.assertNotNull("The EJB BusinessRemote is null",
159: statefulBusinessRemote);
160: } catch (AssertionFailedError afe) {
161: throw new TestFailureException(afe);
162: }
163: }
164:
165: public void lookupStringEntry() throws TestFailureException {
166: try {
167: String expected = new String("1");
168: Assert.assertNotNull("The String looked up is null",
169: striing);
170: Assert.assertEquals(expected, striing);
171: } catch (AssertionFailedError afe) {
172: throw new TestFailureException(afe);
173: }
174: }
175:
176: public void lookupDoubleEntry() throws TestFailureException {
177: try {
178: Double expected = new Double(1.0D);
179:
180: Assert.assertNotNull("The Double looked up is null",
181: doouble);
182: Assert.assertEquals(expected, doouble);
183:
184: } catch (AssertionFailedError afe) {
185: throw new TestFailureException(afe);
186: }
187: }
188:
189: public void lookupLongEntry() throws TestFailureException {
190: try {
191: Long expected = new Long(1L);
192:
193: Assert.assertNotNull("The Long looked up is null", loong);
194: Assert.assertEquals(expected, loong);
195: } catch (AssertionFailedError afe) {
196: throw new TestFailureException(afe);
197: }
198: }
199:
200: public void lookupFloatEntry() throws TestFailureException {
201: try {
202: Float expected = new Float(1.0F);
203:
204: Assert.assertNotNull("The Float looked up is null", flooat);
205: Assert.assertEquals(expected, flooat);
206: } catch (AssertionFailedError afe) {
207: throw new TestFailureException(afe);
208: }
209: }
210:
211: public void lookupIntegerEntry() throws TestFailureException {
212: try {
213: Integer expected = new Integer(1);
214:
215: Assert.assertNotNull("The Integer looked up is null",
216: inteeger);
217: Assert.assertEquals(expected, inteeger);
218:
219: } catch (AssertionFailedError afe) {
220: throw new TestFailureException(afe);
221: }
222: }
223:
224: public void lookupShortEntry() throws TestFailureException {
225: try {
226: Short expected = new Short((short) 1);
227:
228: Assert.assertNotNull("The Short looked up is null", shoort);
229: Assert.assertEquals(expected, shoort);
230: } catch (AssertionFailedError afe) {
231: throw new TestFailureException(afe);
232: }
233: }
234:
235: public void lookupBooleanEntry() throws TestFailureException {
236: try {
237: Boolean expected = new Boolean(true);
238:
239: Assert.assertNotNull("The Boolean looked up is null",
240: booolean);
241: Assert.assertEquals(expected, booolean);
242: } catch (AssertionFailedError afe) {
243: throw new TestFailureException(afe);
244: }
245: }
246:
247: public void lookupByteEntry() throws TestFailureException {
248: try {
249: Byte expected = new Byte((byte) 1);
250:
251: Assert.assertNotNull("The Byte looked up is null", byyte);
252: Assert.assertEquals(expected, byyte);
253: } catch (AssertionFailedError afe) {
254: throw new TestFailureException(afe);
255: }
256: }
257:
258: public void lookupCharacterEntry() throws TestFailureException {
259: try {
260: Character expected = new Character('D');
261:
262: Assert.assertNotNull("The Character looked up is null",
263: chaaracter);
264: Assert.assertEquals(expected, chaaracter);
265: } catch (AssertionFailedError afe) {
266: throw new TestFailureException(afe);
267: }
268: }
269:
270: public void lookupResource() throws TestFailureException {
271: try {
272: Assert.assertNotNull("The DataSource is null", daataSource);
273: } catch (AssertionFailedError afe) {
274: throw new TestFailureException(afe);
275: }
276: }
277:
278: public void lookupJMSConnectionFactory()
279: throws TestFailureException {
280: try {
281: try {
282: testJmsConnection(coonnectionFactory.createConnection());
283: testJmsConnection(queueCoonnectionFactory
284: .createConnection());
285: testJmsConnection(topicCoonnectionFactory
286: .createConnection());
287: } catch (Exception e) {
288: e.printStackTrace();
289: Assert.fail("Received Exception " + e.getClass()
290: + " : " + e.getMessage());
291: }
292: } catch (AssertionFailedError afe) {
293: throw new TestFailureException(afe);
294: }
295: }
296:
297: private void testJmsConnection(javax.jms.Connection connection)
298: throws JMSException {
299: Session session = connection.createSession(false,
300: Session.DUPS_OK_ACKNOWLEDGE);
301: Topic topic = session.createTopic("test");
302: MessageProducer producer = session.createProducer(topic);
303: producer.send(session.createMessage());
304: producer.close();
305: session.close();
306: connection.close();
307: }
308:
309: public void lookupPersistenceUnit() throws TestFailureException {
310: try {
311: Assert.assertNotNull("The EntityManagerFactory is null",
312: emf);
313: } catch (AssertionFailedError afe) {
314: throw new TestFailureException(afe);
315: }
316: }
317:
318: public void lookupPersistenceContext() throws TestFailureException {
319: try {
320: Assert.assertNotNull("The EntityManager is null", em);
321:
322: try {
323: // call a do nothing method to assure entity manager actually exists
324: em.getFlushMode();
325: } catch (Exception e) {
326: Assert.fail("Received Exception " + e.getClass()
327: + " : " + e.getMessage());
328: }
329: } catch (AssertionFailedError afe) {
330: throw new TestFailureException(afe);
331: }
332: }
333:
334: public void lookupSessionContext() throws TestFailureException {
335: try {
336: // TODO: DMB: Can't seem to find where to make this work
337: // Assert.assertNotNull("The SessionContext is null", ejbContext);
338: } catch (AssertionFailedError afe) {
339: throw new TestFailureException(afe);
340: }
341:
342: }
343:
344: public void ejbActivate() throws EJBException, RemoteException {
345: }
346:
347: public void ejbPassivate() throws EJBException, RemoteException {
348: }
349:
350: public void ejbRemove() throws EJBException, RemoteException {
351: }
352:
353: public void setSessionContext(SessionContext sessionContext)
354: throws EJBException, RemoteException {
355: }
356:
357: public String remove(String arg) {
358: return arg;
359: }
360: }
|