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: TestMDBContext.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.messagedriven.containermanaged.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.TIMER;
030: import static org.ow2.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.USER_TRANSACTION;
031:
032: import org.ow2.easybeans.tests.common.ejbs.mdb.containermanaged.context.MDBContext;
033: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.OperationChecker;
034: import org.ow2.easybeans.tests.common.jms.JMSManager;
035: import org.testng.annotations.AfterClass;
036: import org.testng.annotations.AfterMethod;
037: import org.testng.annotations.BeforeClass;
038: import org.testng.annotations.BeforeMethod;
039: import org.testng.annotations.Test;
040:
041: /**
042: * Verifies if the MessageDrivenContext is working properly.
043: * @reference JSR 220-PROPOSED FINAL - Message-Driven Bean Component Contract
044: * @requirement Application Server must be running.<br>
045: * MDB:<li>org.ow2.easybeans.tests.common.ejbs.mdb.containermanaged.context.MDBContext</li>
046: * (Ant task: install.jar.tests.messagedrivencontext)
047: * @author Eduardo Studzinski Estima de Castro
048: * @author Gisele Pinheiro Souza
049: */
050: public class TestMDBContext {
051:
052: /**
053: * JMS Manager.
054: */
055: private JMSManager jmsQueue;
056:
057: /**
058: * Log checker.
059: */
060: private OperationChecker checker;
061:
062: /**
063: * Creates the JMS manager.
064: * @throws Exception if there is a problem.
065: */
066: @BeforeClass
067: public void startUp00() throws Exception {
068: jmsQueue = new JMSManager(
069: JMSManager.DEFAULT_QUEUE_CONNECTION_FACTORY,
070: JMSManager.DEFAULT_QUEUE);
071: checker = new OperationChecker();
072: }
073:
074: /**
075: * Gets the bean logger instance and clears previous tests information.
076: * @throws Exception if there is a problem with the bean initialization.
077: */
078: @BeforeMethod
079: public void startUp01() throws Exception {
080: checker.deleteAll();
081: }
082:
083: /**
084: * Verifies if the getCallerPrincipal() is working properly.
085: * @input a message
086: * @output a logged onMessage() event
087: * @throws Exception if a problem occurs.
088: */
089: @Test
090: public void testCallerPrincipal() throws Exception {
091: jmsQueue.sendControlMessage(MDBContext.MESSAGE_TYPE,
092: GET_CALLER_PRINCIPAL);
093: checker.check(MDBContext.class.getName(), ON_MESSAGE,
094: GET_CALLER_PRINCIPAL);
095: }
096:
097: /**
098: * Verifies if the getRollbackOnly()/setRollbackOnly() is working properly.
099: * @input a message
100: * @output a logged onMessage() event
101: * @throws Exception if a problem occurs.
102: */
103: @Test
104: public void testGetRollbackOnly() throws Exception {
105: jmsQueue.sendControlMessage(MDBContext.MESSAGE_TYPE,
106: GET_ROLLBACK_ONLY);
107: checker.check(MDBContext.class.getName(), ON_MESSAGE,
108: GET_ROLLBACK_ONLY);
109: }
110:
111: /**
112: * Verifies if the getTimerService() is working properly.
113: * @input a message
114: * @output a logged onMessage() event
115: * @throws Exception if a problem occurs.
116: */
117: @Test
118: public void testGetTimerService() throws Exception {
119: jmsQueue.sendControlMessage(MDBContext.MESSAGE_TYPE, TIMER);
120: checker.check(MDBContext.class.getName(), ON_MESSAGE, TIMER);
121: }
122:
123: /**
124: * Verifies if the getUserTransaction() is working properly.
125: * @input a message
126: * @output a logged onMessage() event
127: * @throws Exception if a problem occurs.
128: */
129: @Test
130: public void testUserTransaction() throws Exception {
131: jmsQueue.sendControlMessage(MDBContext.MESSAGE_TYPE,
132: USER_TRANSACTION);
133: checker.check(MDBContext.class.getName(), ON_MESSAGE,
134: USER_TRANSACTION);
135: }
136:
137: /**
138: * Clears logs.
139: * @throws Exception if a problem occurs.
140: */
141: @AfterMethod
142: public void tearDown() throws Exception {
143: checker.deleteAll();
144: }
145:
146: /**
147: * Clears logs.
148: * @throws Exception if a problem occurs.
149: */
150: @AfterClass
151: public void tearDownClass() throws Exception {
152: jmsQueue.close();
153: }
154: }
|