KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > messagedriven > containermanaged > context > TestMDBContext


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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: TestMDBContext.java 979 2006-07-28 13:19:50Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.messagedriven.containermanaged.context;
26
27 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.CallbackType.ON_MESSAGE;
28 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.GET_CALLER_PRINCIPAL;
29 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.GET_ROLLBACK_ONLY;
30 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.TIMER;
31 import static org.objectweb.easybeans.tests.common.ejbs.entity.callbacklogger.OperationType.USER_TRANSACTION;
32
33 import org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.context.MDBContext;
34 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.callbacklogger.OperationChecker;
35 import org.objectweb.easybeans.tests.common.jms.JMSManager;
36 import org.testng.annotations.AfterClass;
37 import org.testng.annotations.AfterMethod;
38 import org.testng.annotations.BeforeClass;
39 import org.testng.annotations.BeforeMethod;
40 import org.testng.annotations.Test;
41
42 /**
43  * Verifies if the MessageDrivenContext is working properly.
44  * @reference JSR 220-PROPOSED FINAL - Message-Driven Bean Component Contract
45  * @requirement Application Server must be running.<br>
46  * MDB:<li>org.objectweb.easybeans.tests.common.ejbs.mdb.containermanaged.context.MDBContext</li>
47  * (Ant task: install.jar.tests.messagedrivencontext)
48  * @author Eduardo Studzinski Estima de Castro
49  * @author Gisele Pinheiro Souza
50  */

51 public class TestMDBContext {
52
53     /**
54      * JMS Manager.
55      */

56     private JMSManager jmsQueue;
57
58     /**
59      * Log checker.
60      */

61     private OperationChecker checker;
62
63     /**
64      * Creates the JMS manager.
65      * @throws Exception if there is a problem.
66      */

67     @BeforeClass
68     public void startUp00() throws Exception JavaDoc {
69         jmsQueue = new JMSManager(JMSManager.DEFAULT_QUEUE_CONNECTION_FACTORY, JMSManager.DEFAULT_QUEUE);
70         checker = new OperationChecker();
71     }
72
73     /**
74      * Gets the bean logger instance and clears previous tests information.
75      * @throws Exception if there is a problem with the bean initialization.
76      */

77     @BeforeMethod
78     public void startUp01() throws Exception JavaDoc {
79         checker.deleteAll();
80     }
81
82     /**
83      * Verifies if the getCallerPrincipal() is working properly.
84      * @input a message
85      * @output a logged onMessage() event
86      * @throws Exception if a problem occurs.
87      */

88     @Test
89     public void testCallerPrincipal() throws Exception JavaDoc {
90         jmsQueue.sendControlMessage(MDBContext.MESSAGE_TYPE, GET_CALLER_PRINCIPAL);
91         checker.check(MDBContext.class.getName(), ON_MESSAGE, GET_CALLER_PRINCIPAL);
92     }
93
94     /**
95      * Verifies if the getRollbackOnly()/setRollbackOnly() is working properly.
96      * @input a message
97      * @output a logged onMessage() event
98      * @throws Exception if a problem occurs.
99      */

100     @Test
101     public void testGetRollbackOnly() throws Exception JavaDoc {
102         jmsQueue.sendControlMessage(MDBContext.MESSAGE_TYPE, GET_ROLLBACK_ONLY);
103         checker.check(MDBContext.class.getName(), ON_MESSAGE, GET_ROLLBACK_ONLY);
104     }
105
106     /**
107      * Verifies if the getTimerService() is working properly.
108      * @input a message
109      * @output a logged onMessage() event
110      * @throws Exception if a problem occurs.
111      */

112     @Test
113     public void testGetTimerService() throws Exception JavaDoc {
114         jmsQueue.sendControlMessage(MDBContext.MESSAGE_TYPE, TIMER);
115         checker.check(MDBContext.class.getName(), ON_MESSAGE, TIMER);
116     }
117
118     /**
119      * Verifies if the getUserTransaction() is working properly.
120      * @input a message
121      * @output a logged onMessage() event
122      * @throws Exception if a problem occurs.
123      */

124     @Test
125     public void testUserTransaction() throws Exception JavaDoc {
126         jmsQueue.sendControlMessage(MDBContext.MESSAGE_TYPE, USER_TRANSACTION);
127         checker.check(MDBContext.class.getName(), ON_MESSAGE, USER_TRANSACTION);
128     }
129
130     /**
131      * Clears logs.
132      * @throws Exception if a problem occurs.
133      */

134     @AfterMethod
135     public void tearDown() throws Exception JavaDoc {
136         checker.deleteAll();
137     }
138
139     /**
140      * Clears logs.
141      * @throws Exception if a problem occurs.
142      */

143     @AfterClass
144     public void tearDownClass() throws Exception JavaDoc {
145         jmsQueue.close();
146     }
147 }
148
Popular Tags