1 22 package org.jboss.ejb3.test.enventry.unit; 23 24 import javax.jms.Connection ; 25 import javax.jms.ConnectionFactory ; 26 import javax.jms.Destination ; 27 import javax.jms.MapMessage ; 28 import javax.jms.MessageConsumer ; 29 import javax.jms.MessageProducer ; 30 import javax.jms.Queue ; 31 import javax.jms.Session ; 32 import javax.jms.TextMessage ; 33 import javax.naming.InitialContext ; 34 35 import org.jboss.ejb3.test.enventry.TestEnvEntry; 36 import org.jboss.test.JBossTestCase; 37 import junit.framework.Test; 38 39 43 public class EnvEntryTestCase extends JBossTestCase 44 { 45 46 public EnvEntryTestCase(String name) 47 { 48 super(name); 49 } 50 51 public void testEnvEntries() throws Exception 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 { 79 InitialContext ctx = getInitialContext(); 80 81 ConnectionFactory factory = (ConnectionFactory )ctx.lookup("ConnectionFactory"); 82 Connection con = factory.createConnection(); 83 try { 84 Destination dest = (Destination ) ctx.lookup("queue/testEnvEntry"); 85 86 Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); 87 MessageProducer producer = session.createProducer(dest); 88 89 Queue replyQueue = session.createTemporaryQueue(); 90 MessageConsumer consumer = session.createConsumer(replyQueue); 91 92 con.start(); 93 94 TextMessage msg = session.createTextMessage(); 95 msg.setJMSReplyTo(replyQueue); 96 msg.setText("This is message one"); 97 producer.send(msg); 98 99 MapMessage replyMsg = (MapMessage ) 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 111 { 112 return getDeploySetup(EnvEntryTestCase.class, "enventry.jar"); 113 } 114 115 } 116 | Popular Tags |