1 22 package org.jboss.test.xa.test; 23 24 import java.rmi.*; 25 26 27 import javax.naming.Context ; 28 import javax.naming.InitialContext ; 29 import javax.ejb.DuplicateKeyException ; 30 import javax.ejb.Handle ; 31 import javax.ejb.EJBMetaData ; 32 import javax.ejb.FinderException ; 33 34 import java.util.Date ; 35 import java.util.Properties ; 36 import java.util.Collection ; 37 import java.util.Iterator ; 38 import java.util.Enumeration ; 39 40 import junit.framework.Test; 41 import junit.framework.TestCase; 42 import junit.framework.TestSuite; 43 44 import org.jboss.test.JBossTestCase; 45 46 import org.jboss.test.xa.interfaces.CantSeeDataException; 47 import org.jboss.test.xa.interfaces.XATest; 48 import org.jboss.test.xa.interfaces.XATestHome; 49 50 public class XAUnitTestCase 51 extends JBossTestCase 52 { 53 org.jboss.logging.Logger log = getLog(); 54 public XAUnitTestCase(String name) 55 { 56 super(name); 57 } 58 59 public void testXABean() throws Exception { 60 int test = 0; 61 62 Context ctx = new InitialContext (); 63 64 System.out.print(++test+"- "+"Looking up the XATest home..."); 66 67 XATestHome home; 68 69 try { 70 home = (XATestHome) ctx.lookup("XATest"); 71 72 if (home == null) throw new Exception ("No Home!"); 73 log.debug("OK"); 74 } catch (Exception e) { 75 log.debug("Could not lookup the context: the beans are probably not deployed"); 77 log.debug("Check the server trace for details"); 78 79 throw e; 80 } 81 82 System.out.print(++test+"- "+"Creating an the XATest bean..."); 84 XATest bean; 85 try { 86 bean = home.create(); 87 if(bean == null) throw new Exception ("No Bean!"); 88 log.debug("OK"); 89 } catch (Exception e) { 90 log.debug("Could not create the bean!"); 92 log.debug("Check the server trace for details"); 93 log.debug("failed", e); 94 95 96 throw e; 97 } 98 99 System.out.print(++test+"- "+"Creating required tables..."); 101 try { 102 bean.createTables(); 103 log.debug("OK"); 104 } 105 catch (Exception e) { 106 log.debug("\nFailed to create tables"); 107 throw e; 108 } 109 110 System.out.print(++test+"- "+"Clearing any old data..."); 112 try { 113 bean.clearData(); 114 log.debug("OK"); 115 } catch(Exception e) { 116 log.debug("Could not clear the data: did you create the table in both data sources?"); 118 log.debug("CREATE TABLE XA_TEST(ID INTEGER NOT NULL PRIMARY KEY, DATA INTEGER NOT NULL)"); 119 120 throw e; 121 } 122 123 System.out.print(++test+"- "+"Testing DB connections..."); 125 try { 126 bean.doWork(); 127 log.debug("OK"); 128 } catch(CantSeeDataException e) { 129 log.debug("sort of worked."); 130 log.debug(e.getMessage()); 131 } catch(Exception e) { 132 log.debug("Error during DB test!"); 134 log.debug("Check the server trace for details"); 135 136 throw e; 137 } 138 } 139 140 141 public static Test suite() throws Exception 142 { 143 return getDeploySetup(XAUnitTestCase.class, "xatest.jar"); 144 } 145 146 } 147 | Popular Tags |