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.stateless;
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.stateful.BasicStatefulBusinessLocal;
023: import org.apache.openejb.test.stateful.BasicStatefulBusinessRemote;
024: import org.apache.openejb.test.stateful.BasicStatefulHome;
025:
026: import javax.ejb.CreateException;
027: import javax.ejb.EJBException;
028: import javax.ejb.SessionBean;
029: import javax.ejb.SessionContext;
030: import javax.jms.ConnectionFactory;
031: import javax.jms.MessageProducer;
032: import javax.jms.QueueConnectionFactory;
033: import javax.jms.Session;
034: import javax.jms.Topic;
035: import javax.jms.TopicConnectionFactory;
036: import javax.jms.JMSException;
037: import javax.persistence.EntityManager;
038: import javax.persistence.EntityManagerFactory;
039: import javax.sql.DataSource;
040: import java.rmi.RemoteException;
041:
042: /**
043: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
044: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
045: */
046: public class FieldInjectionStatelessBean implements SessionBean {
047:
048: private SessionContext ejbContext;
049: private BasicBmpHome bmpHome;
050: private BasicStatefulHome statefulHome;
051: private BasicStatelessHome statelessHome;
052: private String striing;
053: private Double doouble;
054: private Long loong;
055: private Float flooat;
056: private Integer inteeger;
057: private Short shoort;
058: private Boolean booolean;
059: private Byte byyte;
060: private Character chaaracter;
061: private DataSource daataSource;
062: private ConnectionFactory coonnectionFactory;
063: private QueueConnectionFactory queueCoonnectionFactory;
064: private TopicConnectionFactory topicCoonnectionFactory;
065: private EntityManagerFactory emf;
066: private EntityManager em;
067: private EntityManager eem;
068: private EntityManager pem;
069: private BasicStatelessBusinessLocal statelessBusinessLocal;
070: private BasicStatelessBusinessRemote statelessBusinessRemote;
071: private BasicStatefulBusinessLocal statefulBusinessLocal;
072: private BasicStatefulBusinessRemote statefulBusinessRemote;
073:
074: public void ejbCreate() throws CreateException {
075: }
076:
077: public void lookupEntityBean() throws TestFailureException {
078: try {
079: Assert.assertNotNull("The EJBObject is null", bmpHome);
080: } catch (AssertionFailedError afe) {
081: throw new TestFailureException(afe);
082: }
083: }
084:
085: public void lookupStatefulBean() throws TestFailureException {
086: try {
087: Assert.assertNotNull("The EJBObject is null", statefulHome);
088: } catch (AssertionFailedError afe) {
089: throw new TestFailureException(afe);
090: }
091: }
092:
093: public void lookupStatelessBean() throws TestFailureException {
094: try {
095: Assert
096: .assertNotNull("The EJBObject is null",
097: statelessHome);
098: } catch (AssertionFailedError afe) {
099: throw new TestFailureException(afe);
100: }
101: }
102:
103: public void lookupStatelessBusinessLocal()
104: throws TestFailureException {
105: try {
106: Assert.assertNotNull("The EJB BusinessLocal is null",
107: statelessBusinessLocal);
108: } catch (AssertionFailedError afe) {
109: throw new TestFailureException(afe);
110: }
111: }
112:
113: public void lookupStatelessBusinessRemote()
114: throws TestFailureException {
115: try {
116: Assert.assertNotNull("The EJB BusinessRemote is null",
117: statelessBusinessRemote);
118: } catch (AssertionFailedError afe) {
119: throw new TestFailureException(afe);
120: }
121: }
122:
123: public void lookupStatefulBusinessLocal()
124: throws TestFailureException {
125: try {
126: Assert.assertNotNull("The EJB BusinessLocal is null",
127: statefulBusinessLocal);
128: } catch (AssertionFailedError afe) {
129: throw new TestFailureException(afe);
130: }
131: }
132:
133: public void lookupStatefulBusinessRemote()
134: throws TestFailureException {
135: try {
136: Assert.assertNotNull("The EJB BusinessRemote is null",
137: statefulBusinessRemote);
138: } catch (AssertionFailedError afe) {
139: throw new TestFailureException(afe);
140: }
141: }
142:
143: public void lookupStringEntry() throws TestFailureException {
144: try {
145: String expected = new String("1");
146: Assert.assertNotNull("The String looked up is null",
147: striing);
148: Assert.assertEquals(expected, striing);
149: } catch (AssertionFailedError afe) {
150: throw new TestFailureException(afe);
151: }
152: }
153:
154: public void lookupDoubleEntry() throws TestFailureException {
155: try {
156: Double expected = new Double(1.0D);
157:
158: Assert.assertNotNull("The Double looked up is null",
159: doouble);
160: Assert.assertEquals(expected, doouble);
161:
162: } catch (AssertionFailedError afe) {
163: throw new TestFailureException(afe);
164: }
165: }
166:
167: public void lookupLongEntry() throws TestFailureException {
168: try {
169: Long expected = new Long(1L);
170:
171: Assert.assertNotNull("The Long looked up is null", loong);
172: Assert.assertEquals(expected, loong);
173: } catch (AssertionFailedError afe) {
174: throw new TestFailureException(afe);
175: }
176: }
177:
178: public void lookupFloatEntry() throws TestFailureException {
179: try {
180: Float expected = new Float(1.0F);
181:
182: Assert.assertNotNull("The Float looked up is null", flooat);
183: Assert.assertEquals(expected, flooat);
184: } catch (AssertionFailedError afe) {
185: throw new TestFailureException(afe);
186: }
187: }
188:
189: public void lookupIntegerEntry() throws TestFailureException {
190: try {
191: Integer expected = new Integer(1);
192:
193: Assert.assertNotNull("The Integer looked up is null",
194: inteeger);
195: Assert.assertEquals(expected, inteeger);
196:
197: } catch (AssertionFailedError afe) {
198: throw new TestFailureException(afe);
199: }
200: }
201:
202: public void lookupShortEntry() throws TestFailureException {
203: try {
204: Short expected = new Short((short) 1);
205:
206: Assert.assertNotNull("The Short looked up is null", shoort);
207: Assert.assertEquals(expected, shoort);
208: } catch (AssertionFailedError afe) {
209: throw new TestFailureException(afe);
210: }
211: }
212:
213: public void lookupBooleanEntry() throws TestFailureException {
214: try {
215: Boolean expected = new Boolean(true);
216:
217: Assert.assertNotNull("The Boolean looked up is null",
218: booolean);
219: Assert.assertEquals(expected, booolean);
220: } catch (AssertionFailedError afe) {
221: throw new TestFailureException(afe);
222: }
223: }
224:
225: public void lookupByteEntry() throws TestFailureException {
226: try {
227: Byte expected = new Byte((byte) 1);
228:
229: Assert.assertNotNull("The Byte looked up is null", byyte);
230: Assert.assertEquals(expected, byyte);
231: } catch (AssertionFailedError afe) {
232: throw new TestFailureException(afe);
233: }
234: }
235:
236: public void lookupCharacterEntry() throws TestFailureException {
237: try {
238: Character expected = new Character('D');
239:
240: Assert.assertNotNull("The Character looked up is null",
241: chaaracter);
242: Assert.assertEquals(expected, chaaracter);
243: } catch (AssertionFailedError afe) {
244: throw new TestFailureException(afe);
245: }
246: }
247:
248: public void lookupResource() throws TestFailureException {
249: try {
250: Assert.assertNotNull("The DataSource is null", daataSource);
251: } catch (AssertionFailedError afe) {
252: throw new TestFailureException(afe);
253: }
254: }
255:
256: public void lookupJMSConnectionFactory()
257: throws TestFailureException {
258: try {
259: try {
260: testJmsConnection(coonnectionFactory.createConnection());
261: testJmsConnection(queueCoonnectionFactory
262: .createConnection());
263: testJmsConnection(topicCoonnectionFactory
264: .createConnection());
265: } catch (Exception e) {
266: e.printStackTrace();
267: Assert.fail("Received Exception " + e.getClass()
268: + " : " + e.getMessage());
269: }
270: } catch (AssertionFailedError afe) {
271: throw new TestFailureException(afe);
272: }
273: }
274:
275: private void testJmsConnection(javax.jms.Connection connection)
276: throws JMSException {
277: Session session = connection.createSession(false,
278: Session.DUPS_OK_ACKNOWLEDGE);
279: Topic topic = session.createTopic("test");
280: MessageProducer producer = session.createProducer(topic);
281: producer.send(session.createMessage());
282: producer.close();
283: session.close();
284: connection.close();
285: }
286:
287: public void lookupPersistenceUnit() throws TestFailureException {
288: try {
289: Assert.assertNotNull("The EntityManagerFactory is null",
290: emf);
291: } catch (AssertionFailedError afe) {
292: throw new TestFailureException(afe);
293: }
294: }
295:
296: public void lookupPersistenceContext() throws TestFailureException {
297: try {
298: Assert.assertNotNull("The EntityManager is null", em);
299:
300: try {
301: // call a do nothing method to assure entity manager actually exists
302: em.getFlushMode();
303: } catch (Exception e) {
304: Assert.fail("Received Exception " + e.getClass()
305: + " : " + e.getMessage());
306: }
307: } catch (AssertionFailedError afe) {
308: throw new TestFailureException(afe);
309: }
310: }
311:
312: public void lookupSessionContext() throws TestFailureException {
313: try {
314: // TODO: DMB: Can't seem to find where to make this work
315: // Assert.assertNotNull("The SessionContext is null", ejbContext);
316: } catch (AssertionFailedError afe) {
317: throw new TestFailureException(afe);
318: }
319:
320: }
321:
322: public void ejbActivate() throws EJBException, RemoteException {
323: }
324:
325: public void ejbPassivate() throws EJBException, RemoteException {
326: }
327:
328: public void ejbRemove() throws EJBException, RemoteException {
329: }
330:
331: public void setSessionContext(SessionContext sessionContext)
332: throws EJBException, RemoteException {
333: }
334:
335: public String remove(String arg) {
336: return arg;
337: }
338: }
|