01: /**
02: * EasyBeans
03: * Copyright (C) 2006 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: UserTransactionTester.java 1970 2007-10-16 11:49:25Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.tests.common.resources;
25:
26: import javax.annotation.Resource;
27: import javax.naming.Context;
28: import javax.naming.InitialContext;
29: import javax.transaction.UserTransaction;
30:
31: import org.ow2.easybeans.tests.common.exception.CustomException00;
32:
33: /**
34: * UserTransaction Tester.
35: * @author Eduardo Studzinski Estima de Castro
36: * @author Gisele Pinheiro Souza
37: *
38: */
39: public class UserTransactionTester {
40:
41: /**
42: * Injected UserTransaction.
43: */
44: @Resource
45: private UserTransaction utx;
46:
47: /**
48: * Default Constructor.
49: */
50: public UserTransactionTester() {
51: }
52:
53: /**
54: * Tests an userTransaction access.
55: * @throws Exception if a problem occurs.
56: */
57: protected void access00() throws Exception {
58: checkInstance(utx);
59: }
60:
61: /**
62: * Checks if an user transaction reference is working well.
63: * @param utx reference
64: * @throws Exception if a problem occurs
65: */
66: public static void checkInstance(final UserTransaction utx)
67: throws Exception {
68: if (utx == null) {
69: throw new CustomException00(
70: "UserTransaction reference is null.");
71: }
72: utx.begin();
73: utx.commit();
74: }
75:
76: /**
77: * Checks if an user transaction reference can be obtained using the JNDI API.
78: * @throws Exception if a problem occurs
79: */
80: public static void checkJNDI() throws Exception {
81: Context ctx = new InitialContext();
82:
83: UserTransaction utx = (UserTransaction) ctx
84: .lookup("java:comp/env/UserTransaction");
85: if (utx == null) {
86: throw new Exception(
87: "UserTransaction reference obtained using JNDI API is null.");
88: }
89: }
90: }
|