KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > enventry > unit > EnvEntryTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.test.enventry.unit;
23
24 import javax.jms.Connection JavaDoc;
25 import javax.jms.ConnectionFactory JavaDoc;
26 import javax.jms.Destination JavaDoc;
27 import javax.jms.MapMessage JavaDoc;
28 import javax.jms.MessageConsumer JavaDoc;
29 import javax.jms.MessageProducer JavaDoc;
30 import javax.jms.Queue JavaDoc;
31 import javax.jms.Session JavaDoc;
32 import javax.jms.TextMessage JavaDoc;
33 import javax.naming.InitialContext JavaDoc;
34
35 import org.jboss.ejb3.test.enventry.TestEnvEntry;
36 import org.jboss.test.JBossTestCase;
37 import junit.framework.Test;
38
39 /**
40  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
41  * @version <tt>$Revision: 44696 $</tt>
42  */

43 public class EnvEntryTestCase extends JBossTestCase
44 {
45   
46    public EnvEntryTestCase(String JavaDoc name)
47    {
48       super(name);
49    }
50
51    public void testEnvEntries() throws Exception JavaDoc
52    {
53       TestEnvEntry test = (TestEnvEntry)getInitialContext().lookup("TestEnvEntry");
54       assertNotNull(test);
55       
56       int maxExceptions = test.getMaxExceptions();
57       assertEquals(15, maxExceptions);
58       
59       int minExceptions = test.getMinExceptions();
60       assertEquals(5, minExceptions);
61       
62       int numExceptions = test.getNumExceptions();
63       assertEquals(10, numExceptions);
64       
65       TestEnvEntry etest = (TestEnvEntry)getInitialContext().lookup("ExtendedTestEnvEntry");
66       assertNotNull(etest);
67       
68       maxExceptions = etest.getMaxExceptions();
69       assertEquals(14, maxExceptions);
70       
71       minExceptions = etest.getMinExceptions();
72       assertEquals(6, minExceptions);
73       
74       numExceptions = etest.getNumExceptions();
75       assertEquals(11, numExceptions);
76    }
77
78    public void testEnvEntriesMDB() throws Exception JavaDoc {
79       InitialContext JavaDoc ctx = getInitialContext();
80
81       ConnectionFactory JavaDoc factory = (ConnectionFactory JavaDoc)ctx.lookup("ConnectionFactory");
82       Connection JavaDoc con = factory.createConnection();
83       try {
84          Destination JavaDoc dest = (Destination JavaDoc) ctx.lookup("queue/testEnvEntry");
85          
86          Session JavaDoc session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
87          MessageProducer JavaDoc producer = session.createProducer(dest);
88          
89          Queue JavaDoc replyQueue = session.createTemporaryQueue();
90          MessageConsumer JavaDoc consumer = session.createConsumer(replyQueue);
91          
92          con.start();
93          
94          TextMessage JavaDoc msg = session.createTextMessage();
95          msg.setJMSReplyTo(replyQueue);
96          msg.setText("This is message one");
97          producer.send(msg);
98          
99          MapMessage JavaDoc replyMsg = (MapMessage JavaDoc) consumer.receive(5000);
100          assertNotNull(replyMsg);
101          assertEquals(16, replyMsg.getInt("maxExceptions"));
102          assertEquals(12, replyMsg.getInt("numExceptions"));
103          assertEquals(7, replyMsg.getInt("minExceptions"));
104       }
105       finally {
106          con.close();
107       }
108    }
109
110    public static Test suite() throws Exception JavaDoc
111    {
112       return getDeploySetup(EnvEntryTestCase.class, "enventry.jar");
113    }
114
115 }
116
Popular Tags