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 org.apache.openejb.test.entity.bmp.BasicBmpHome;
019: import org.apache.openejb.test.stateless.BasicStatelessHome;
020: import org.apache.openejb.test.stateless.BasicStatelessBusinessLocal;
021: import org.apache.openejb.test.stateless.BasicStatelessBusinessRemote;
022: import org.apache.openejb.test.TestFailureException;
023:
024: import javax.ejb.SessionBean;
025: import javax.ejb.SessionContext;
026: import javax.ejb.CreateException;
027: import javax.ejb.EJBException;
028: import javax.sql.DataSource;
029: import javax.persistence.EntityManagerFactory;
030: import javax.persistence.EntityManager;
031: import javax.jms.ConnectionFactory;
032: import javax.jms.Session;
033: import javax.jms.Topic;
034: import javax.jms.MessageProducer;
035: import javax.jms.QueueConnectionFactory;
036: import javax.jms.TopicConnectionFactory;
037: import javax.jms.JMSException;
038:
039: import junit.framework.Assert;
040: import junit.framework.AssertionFailedError;
041:
042: import java.rmi.RemoteException;
043:
044: /**
045: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
046: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
047: */
048: public class SetterInjectionStatefulBean implements SessionBean {
049:
050: private String name;
051: private SessionContext ejbContextField;
052: private BasicBmpHome bmpHomeField;
053: private BasicStatefulHome statefulHomeField;
054: private BasicStatelessHome statelessHomeField;
055: private String striingField;
056: private Double dooubleField;
057: private Long loongField;
058: private Float flooatField;
059: private Integer inteegerField;
060: private Short shoortField;
061: private Boolean boooleanField;
062: private Byte byyteField;
063: private Character chaaracterField;
064: private DataSource daataSourceField;
065: private ConnectionFactory coonnectionFactory;
066: private QueueConnectionFactory queueCoonnectionFactory;
067: private TopicConnectionFactory topicCoonnectionFactory;
068: private EntityManagerFactory emfField;
069: private EntityManager emField;
070: private EntityManager eemField;
071: private EntityManager pemField;
072: private BasicStatelessBusinessLocal statelessBusinessLocalField;
073: private BasicStatelessBusinessRemote statelessBusinessRemoteField;
074: private BasicStatefulBusinessLocal statefulBusinessLocalField;
075: private BasicStatefulBusinessRemote statefulBusinessRemoteField;
076:
077: public BasicStatefulBusinessLocal getStatefulBusinessLocal() {
078: return statefulBusinessLocalField;
079: }
080:
081: public void setStatefulBusinessLocal(
082: BasicStatefulBusinessLocal statefulBusinessLocal) {
083: this .statefulBusinessLocalField = statefulBusinessLocal;
084: }
085:
086: public BasicStatefulBusinessRemote getStatefulBusinessRemote() {
087: return statefulBusinessRemoteField;
088: }
089:
090: public void setStatefulBusinessRemote(
091: BasicStatefulBusinessRemote statefulBusinessRemote) {
092: this .statefulBusinessRemoteField = statefulBusinessRemote;
093: }
094:
095: public BasicStatelessBusinessLocal getStatelessBusinessLocal() {
096: return statelessBusinessLocalField;
097: }
098:
099: public void setStatelessBusinessLocal(
100: BasicStatelessBusinessLocal statelessBusinessLocal) {
101: this .statelessBusinessLocalField = statelessBusinessLocal;
102: }
103:
104: public BasicStatelessBusinessRemote getStatelessBusinessRemote() {
105: return statelessBusinessRemoteField;
106: }
107:
108: public void setStatelessBusinessRemote(
109: BasicStatelessBusinessRemote statelessBusinessRemote) {
110: this .statelessBusinessRemoteField = statelessBusinessRemote;
111: }
112:
113: public BasicBmpHome getBmpHome() {
114: return bmpHomeField;
115: }
116:
117: public void setBmpHome(BasicBmpHome bmpHome) {
118: this .bmpHomeField = bmpHome;
119: }
120:
121: public Boolean getBooolean() {
122: return boooleanField;
123: }
124:
125: public void setBooolean(Boolean booolean) {
126: this .boooleanField = booolean;
127: }
128:
129: public Byte getByyte() {
130: return byyteField;
131: }
132:
133: public void setByyte(Byte byyte) {
134: this .byyteField = byyte;
135: }
136:
137: public Character getChaaracter() {
138: return chaaracterField;
139: }
140:
141: public void setChaaracter(Character chaaracter) {
142: this .chaaracterField = chaaracter;
143: }
144:
145: public DataSource getDaataSource() {
146: return daataSourceField;
147: }
148:
149: public void setDaataSource(DataSource daataSource) {
150: this .daataSourceField = daataSource;
151: }
152:
153: public ConnectionFactory getCoonnectionFactory() {
154: return coonnectionFactory;
155: }
156:
157: public void setCoonnectionFactory(
158: ConnectionFactory coonnectionFactory) {
159: this .coonnectionFactory = coonnectionFactory;
160: }
161:
162: public QueueConnectionFactory getQueueCoonnectionFactory() {
163: return queueCoonnectionFactory;
164: }
165:
166: public void setQueueCoonnectionFactory(
167: QueueConnectionFactory queueCoonnectionFactory) {
168: this .queueCoonnectionFactory = queueCoonnectionFactory;
169: }
170:
171: public TopicConnectionFactory getTopicCoonnectionFactory() {
172: return topicCoonnectionFactory;
173: }
174:
175: public void setTopicCoonnectionFactory(
176: TopicConnectionFactory topicCoonnectionFactory) {
177: this .topicCoonnectionFactory = topicCoonnectionFactory;
178: }
179:
180: public Double getDoouble() {
181: return dooubleField;
182: }
183:
184: public void setDoouble(Double doouble) {
185: this .dooubleField = doouble;
186: }
187:
188: public EntityManager getEem() {
189: return eemField;
190: }
191:
192: public void setEem(EntityManager eem) {
193: this .eemField = eem;
194: }
195:
196: public SessionContext getEjbContext() {
197: return ejbContextField;
198: }
199:
200: public void setEjbContext(SessionContext ejbContext) {
201: this .ejbContextField = ejbContext;
202: }
203:
204: public EntityManager getEm() {
205: return emField;
206: }
207:
208: public void setEm(EntityManager em) {
209: this .emField = em;
210: }
211:
212: public EntityManagerFactory getEmf() {
213: return emfField;
214: }
215:
216: public void setEmf(EntityManagerFactory emf) {
217: this .emfField = emf;
218: }
219:
220: public Float getFlooat() {
221: return flooatField;
222: }
223:
224: public void setFlooat(Float flooat) {
225: this .flooatField = flooat;
226: }
227:
228: public Integer getInteeger() {
229: return inteegerField;
230: }
231:
232: public void setInteeger(Integer inteeger) {
233: this .inteegerField = inteeger;
234: }
235:
236: public Long getLoong() {
237: return loongField;
238: }
239:
240: public void setLoong(Long loong) {
241: this .loongField = loong;
242: }
243:
244: public String getName() {
245: return name;
246: }
247:
248: public void setName(String name) {
249: this .name = name;
250: }
251:
252: public EntityManager getPem() {
253: return pemField;
254: }
255:
256: public void setPem(EntityManager pem) {
257: this .pemField = pem;
258: }
259:
260: public Short getShoort() {
261: return shoortField;
262: }
263:
264: public void setShoort(Short shoort) {
265: this .shoortField = shoort;
266: }
267:
268: public BasicStatefulHome getStatefulHome() {
269: return statefulHomeField;
270: }
271:
272: public void setStatefulHome(BasicStatefulHome statefulHome) {
273: this .statefulHomeField = statefulHome;
274: }
275:
276: public BasicStatelessHome getStatelessHome() {
277: return statelessHomeField;
278: }
279:
280: public void setStatelessHome(BasicStatelessHome statelessHome) {
281: this .statelessHomeField = statelessHome;
282: }
283:
284: public String getStriing() {
285: return striingField;
286: }
287:
288: public void setStriing(String striing) {
289: this .striingField = striing;
290: }
291:
292: //=============================
293: // Home interface methods
294: //
295:
296: /**
297: * Maps to EncStatefulHome.create
298: *
299: * @param name
300: * @throws javax.ejb.CreateException
301: * @see EncStatefulHome#create
302: */
303: public void ejbCreate(String name) throws CreateException {
304: this .name = name;
305: }
306:
307: //
308: // Home interface methods
309: //=============================
310:
311: //=============================
312: // Remote interface methods
313: //
314:
315: public void lookupEntityBean() throws TestFailureException {
316: try {
317: Assert.assertNotNull("The EJBObject is null", bmpHomeField);
318: } catch (AssertionFailedError afe) {
319: throw new TestFailureException(afe);
320: }
321: }
322:
323: public void lookupStatefulBean() throws TestFailureException {
324: try {
325: Assert.assertNotNull("The EJBObject is null",
326: statefulHomeField);
327: } catch (AssertionFailedError afe) {
328: throw new TestFailureException(afe);
329: }
330: }
331:
332: public void lookupStatelessBean() throws TestFailureException {
333: try {
334: Assert.assertNotNull("The EJBObject is null",
335: statelessHomeField);
336: } catch (AssertionFailedError afe) {
337: throw new TestFailureException(afe);
338: }
339: }
340:
341: public void lookupStatelessBusinessLocal()
342: throws TestFailureException {
343: try {
344: Assert.assertNotNull("The EJB BusinessLocal is null",
345: statelessBusinessLocalField);
346: } catch (AssertionFailedError afe) {
347: throw new TestFailureException(afe);
348: }
349: }
350:
351: public void lookupStatelessBusinessRemote()
352: throws TestFailureException {
353: try {
354: Assert.assertNotNull("The EJB BusinessRemote is null",
355: statelessBusinessRemoteField);
356: } catch (AssertionFailedError afe) {
357: throw new TestFailureException(afe);
358: }
359: }
360:
361: public void lookupStatefulBusinessLocal()
362: throws TestFailureException {
363: try {
364: Assert.assertNotNull("The EJB BusinessLocal is null",
365: statefulBusinessLocalField);
366: } catch (AssertionFailedError afe) {
367: throw new TestFailureException(afe);
368: }
369: }
370:
371: public void lookupStatefulBusinessRemote()
372: throws TestFailureException {
373: try {
374: Assert.assertNotNull("The EJB BusinessRemote is null",
375: statefulBusinessRemoteField);
376: } catch (AssertionFailedError afe) {
377: throw new TestFailureException(afe);
378: }
379: }
380:
381: public void lookupStringEntry() throws TestFailureException {
382: try {
383: String expected = new String("1");
384: Assert.assertNotNull("The String looked up is null",
385: striingField);
386: Assert.assertEquals(expected, striingField);
387: } catch (AssertionFailedError afe) {
388: throw new TestFailureException(afe);
389: }
390: }
391:
392: public void lookupDoubleEntry() throws TestFailureException {
393: try {
394: Double expected = new Double(1.0D);
395:
396: Assert.assertNotNull("The Double looked up is null",
397: dooubleField);
398: Assert.assertEquals(expected, dooubleField);
399:
400: } catch (AssertionFailedError afe) {
401: throw new TestFailureException(afe);
402: }
403: }
404:
405: public void lookupLongEntry() throws TestFailureException {
406: try {
407: Long expected = new Long(1L);
408:
409: Assert.assertNotNull("The Long looked up is null",
410: loongField);
411: Assert.assertEquals(expected, loongField);
412: } catch (AssertionFailedError afe) {
413: throw new TestFailureException(afe);
414: }
415: }
416:
417: public void lookupFloatEntry() throws TestFailureException {
418: try {
419: Float expected = new Float(1.0F);
420:
421: Assert.assertNotNull("The Float looked up is null",
422: flooatField);
423: Assert.assertEquals(expected, flooatField);
424: } catch (AssertionFailedError afe) {
425: throw new TestFailureException(afe);
426: }
427: }
428:
429: public void lookupIntegerEntry() throws TestFailureException {
430: try {
431: Integer expected = new Integer(1);
432:
433: Assert.assertNotNull("The Integer looked up is null",
434: inteegerField);
435: Assert.assertEquals(expected, inteegerField);
436:
437: } catch (AssertionFailedError afe) {
438: throw new TestFailureException(afe);
439: }
440: }
441:
442: public void lookupShortEntry() throws TestFailureException {
443: try {
444: Short expected = new Short((short) 1);
445:
446: Assert.assertNotNull("The Short looked up is null",
447: shoortField);
448: Assert.assertEquals(expected, shoortField);
449: } catch (AssertionFailedError afe) {
450: throw new TestFailureException(afe);
451: }
452: }
453:
454: public void lookupBooleanEntry() throws TestFailureException {
455: try {
456: Boolean expected = new Boolean(true);
457:
458: Assert.assertNotNull("The Boolean looked up is null",
459: boooleanField);
460: Assert.assertEquals(expected, boooleanField);
461: } catch (AssertionFailedError afe) {
462: throw new TestFailureException(afe);
463: }
464: }
465:
466: public void lookupByteEntry() throws TestFailureException {
467: try {
468: Byte expected = new Byte((byte) 1);
469:
470: Assert.assertNotNull("The Byte looked up is null",
471: byyteField);
472: Assert.assertEquals(expected, byyteField);
473: } catch (AssertionFailedError afe) {
474: throw new TestFailureException(afe);
475: }
476: }
477:
478: public void lookupCharacterEntry() throws TestFailureException {
479: try {
480: Character expected = new Character('D');
481:
482: Assert.assertNotNull("The Character looked up is null",
483: chaaracterField);
484: Assert.assertEquals(expected, chaaracterField);
485: } catch (AssertionFailedError afe) {
486: throw new TestFailureException(afe);
487: }
488: }
489:
490: public void lookupResource() throws TestFailureException {
491: try {
492: Assert.assertNotNull("The DataSource is null",
493: daataSourceField);
494: } catch (AssertionFailedError afe) {
495: throw new TestFailureException(afe);
496: }
497: }
498:
499: public void lookupJMSConnectionFactory()
500: throws TestFailureException {
501: try {
502: try {
503: testJmsConnection(coonnectionFactory.createConnection());
504: testJmsConnection(queueCoonnectionFactory
505: .createConnection());
506: testJmsConnection(topicCoonnectionFactory
507: .createConnection());
508: } catch (Exception e) {
509: e.printStackTrace();
510: Assert.fail("Received Exception " + e.getClass()
511: + " : " + e.getMessage());
512: }
513: } catch (AssertionFailedError afe) {
514: throw new TestFailureException(afe);
515: }
516: }
517:
518: private void testJmsConnection(javax.jms.Connection connection)
519: throws JMSException {
520: Session session = connection.createSession(false,
521: Session.DUPS_OK_ACKNOWLEDGE);
522: Topic topic = session.createTopic("test");
523: MessageProducer producer = session.createProducer(topic);
524: producer.send(session.createMessage());
525: producer.close();
526: session.close();
527: connection.close();
528: }
529:
530: public void lookupPersistenceUnit() throws TestFailureException {
531: try {
532: Assert.assertNotNull("The EntityManagerFactory is null",
533: emfField);
534: } catch (AssertionFailedError afe) {
535: throw new TestFailureException(afe);
536: }
537: }
538:
539: public void lookupPersistenceContext() throws TestFailureException {
540: try {
541: Assert.assertNotNull("The EntityManager is null", emField);
542:
543: try {
544: // call a do nothing method to assure entity manager actually exists
545: emField.getFlushMode();
546: } catch (Exception e) {
547: Assert.fail("Received Exception " + e.getClass()
548: + " : " + e.getMessage());
549: }
550: } catch (AssertionFailedError afe) {
551: throw new TestFailureException(afe);
552: }
553: }
554:
555: public void lookupSessionContext() throws TestFailureException {
556: try {
557: // TODO: DMB: Can't seem to find where to make this work
558: // Assert.assertNotNull("The SessionContext is null", ejbContext);
559: } catch (AssertionFailedError afe) {
560: throw new TestFailureException(afe);
561: }
562:
563: }
564:
565: public void ejbActivate() throws EJBException, RemoteException {
566: }
567:
568: public void ejbPassivate() throws EJBException, RemoteException {
569: }
570:
571: public void ejbRemove() throws EJBException, RemoteException {
572: }
573:
574: public void setSessionContext(SessionContext sessionContext)
575: throws EJBException, RemoteException {
576: }
577:
578: public String remove(String arg) {
579: return arg;
580: }
581: }
|