001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: TestMDBBeanManagedContext.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.messagedriven.beanmanaged.context;
025:
026: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.ON_MESSAGE;
027: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.GET_CALLER_PRINCIPAL;
028: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.GET_ROLLBACK_ONLY;
029: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.SET_ROLLBACK_ONLY;
030: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.TIMER;
031: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.USER_TRANSACTION;
032:
033: import org.ow2.easybeans.tests.common.ejbs.mdb.beanmanaged.context.MDBBeanManagedContext;
034: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.OperationChecker;
035: import org.ow2.easybeans.tests.common.jms.JMSManager;
036: import org.testng.annotations.AfterClass;
037: import org.testng.annotations.AfterMethod;
038: import org.testng.annotations.BeforeClass;
039: import org.testng.annotations.BeforeMethod;
040: import org.testng.annotations.Test;
041:
042: /**
043: * Verifies if the MessageDrivenContext is working properly.
044: * @reference JSR 220-PROPOSED FINAL - Message-Driven Bean Component Contract
045: * @requirement Application Server must be running.<br>
046: * MDB:<li>org.ow2.easybeans.tests.common.ejbs.mdb.beanmanaged.context.MDBBeanManagedContext</li>
047: * (Ant task: install.jar.tests.messagedrivencontext)
048: * @author Eduardo Studzinski Estima de Castro
049: * @author Gisele Pinheiro Souza
050: */
051: public class TestMDBBeanManagedContext {
052:
053: /**
054: * JMS Manager.
055: */
056: private JMSManager jmsQueue;
057:
058: /**
059: * Log checker.
060: */
061: private OperationChecker checker;
062:
063: /**
064: * Creates the JMS manager.
065: * @throws Exception if there is a problem.
066: */
067: @BeforeClass
068: public void startUp00() throws Exception {
069: jmsQueue = new JMSManager(
070: JMSManager.DEFAULT_QUEUE_CONNECTION_FACTORY,
071: JMSManager.DEFAULT_QUEUE);
072: checker = new OperationChecker();
073: }
074:
075: /**
076: * Gets the bean logger instance and clears previous tests information.
077: * @throws Exception if there is a problem with the bean initialization.
078: */
079: @BeforeMethod
080: public void startUp01() throws Exception {
081: checker.deleteAll();
082: }
083:
084: /**
085: * Verifies if the getCallerPrincipal() is working properly.
086: * @input a message
087: * @output a logged onMessage() event
088: * @throws Exception if a problem occurs.
089: */
090: @Test
091: public void testCallerPrincipal() throws Exception {
092: jmsQueue.sendControlMessage(MDBBeanManagedContext.MESSAGE_TYPE,
093: GET_CALLER_PRINCIPAL);
094: checker.check(MDBBeanManagedContext.class.getName(),
095: ON_MESSAGE, GET_CALLER_PRINCIPAL);
096: }
097:
098: /**
099: * Verifies if the getRollbackOnly() is working properly.
100: * @input a message
101: * @output a logged onMessage() event
102: * @throws Exception if a problem occurs.
103: */
104: @Test
105: public void testGetRollbackOnly() throws Exception {
106: jmsQueue.sendControlMessage(MDBBeanManagedContext.MESSAGE_TYPE,
107: GET_ROLLBACK_ONLY);
108: checker.check(MDBBeanManagedContext.class.getName(),
109: ON_MESSAGE, GET_ROLLBACK_ONLY);
110: }
111:
112: /**
113: * Verifies if the getRollbackOnly() is working properly.
114: * @input a message
115: * @output a logged onMessage() event
116: * @throws Exception if a problem occurs.
117: */
118: @Test
119: public void testSetRollbackOnly() throws Exception {
120: jmsQueue.sendControlMessage(MDBBeanManagedContext.MESSAGE_TYPE,
121: SET_ROLLBACK_ONLY);
122: checker.check(MDBBeanManagedContext.class.getName(),
123: ON_MESSAGE, SET_ROLLBACK_ONLY);
124: }
125:
126: /**
127: * Verifies if the getTimerService() is working properly.
128: * @input a message
129: * @output a logged onMessage() event
130: * @throws Exception if a problem occurs.
131: */
132: @Test
133: public void testGetTimerService() throws Exception {
134: jmsQueue.sendControlMessage(MDBBeanManagedContext.MESSAGE_TYPE,
135: TIMER);
136: checker.check(MDBBeanManagedContext.class.getName(),
137: ON_MESSAGE, TIMER);
138: }
139:
140: /**
141: * Verifies if the getUserTransaction() is working properly.
142: * @input a message
143: * @output a logged onMessage() event
144: * @throws Exception if a problem occurs.
145: */
146: @Test
147: public void testUserTransaction() throws Exception {
148: jmsQueue.sendControlMessage(MDBBeanManagedContext.MESSAGE_TYPE,
149: USER_TRANSACTION);
150: checker.check(MDBBeanManagedContext.class.getName(),
151: ON_MESSAGE, USER_TRANSACTION);
152: }
153:
154: /**
155: * Clears logs.
156: * @throws Exception if a problem occurs.
157: */
158: @AfterMethod
159: public void tearDown() throws Exception {
160: checker.deleteAll();
161: }
162:
163: /**
164: * Clears logs.
165: * @throws Exception if a problem occurs.
166: */
167: @AfterClass
168: public void tearDownClass() throws Exception {
169: jmsQueue.close();
170: }
171: }
|