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.annotation.Resource;
027: import javax.ejb.CreateException;
028: import javax.ejb.EJB;
029: import javax.ejb.SessionContext;
030: import javax.ejb.Stateless;
031: import javax.ejb.RemoteHome;
032: import javax.persistence.EntityManager;
033: import javax.persistence.EntityManagerFactory;
034: import javax.persistence.PersistenceUnit;
035: import javax.persistence.PersistenceContext;
036: import javax.sql.DataSource;
037: import javax.jms.ConnectionFactory;
038: import javax.jms.Session;
039: import javax.jms.Topic;
040: import javax.jms.MessageProducer;
041: import javax.jms.QueueConnectionFactory;
042: import javax.jms.TopicConnectionFactory;
043: import javax.jms.JMSException;
044:
045: @RemoteHome(org.apache.openejb.test.stateless.EncStatelessHome.class)
046: @Stateless
047: public class AnnotatedFieldInjectionStatelessBean {
048:
049: @Resource
050: private SessionContext ejbContext;
051: @EJB(beanName="BasicBmpBean")
052: private BasicBmpHome bmpHome;
053: @EJB(beanName="BasicStatefulBean")
054: private BasicStatefulHome statefulHome;
055: @EJB(beanName="BasicStatelessBean")
056: private BasicStatelessHome statelessHome;
057: @Resource
058: private String striing = "1";
059: @Resource
060: private Double doouble = 1.0D;
061: @Resource
062: private Long loong = 1L;
063: @Resource
064: private Float flooat = 1.0F;
065: @Resource
066: private Integer inteeger = 1;
067: @Resource
068: private Short shoort = (short) 1;
069: @Resource
070: private Boolean booolean = true;
071: @Resource
072: private Byte byyte = (byte) 1;
073: @Resource
074: private Character chaaracter = 'D';
075: @Resource
076: private DataSource daataSource;
077: @Resource
078: private ConnectionFactory coonnectionFactory;
079: @Resource
080: private QueueConnectionFactory queueCoonnectionFactory;
081: @Resource
082: private TopicConnectionFactory topicCoonnectionFactory;
083: @PersistenceUnit(unitName="openjpa-test-unit")
084: private EntityManagerFactory emf;
085: @PersistenceContext(unitName="openjpa-test-unit")
086: private EntityManager em;
087: @EJB
088: private BasicStatelessBusinessLocal statelessBusinessLocal;
089: @EJB
090: private BasicStatelessBusinessRemote statelessBusinessRemote;
091: @EJB
092: private BasicStatefulBusinessLocal statefulBusinessLocal;
093: @EJB
094: private BasicStatefulBusinessRemote statefulBusinessRemote;
095:
096: public void ejbCreate() throws CreateException {
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: }
|