KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > xa > test > XAUnitTestCase


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.test.xa.test;
23
24 import java.rmi.*;
25
26
27 import javax.naming.Context JavaDoc;
28 import javax.naming.InitialContext JavaDoc;
29 import javax.ejb.DuplicateKeyException JavaDoc;
30 import javax.ejb.Handle JavaDoc;
31 import javax.ejb.EJBMetaData JavaDoc;
32 import javax.ejb.FinderException JavaDoc;
33
34 import java.util.Date JavaDoc;
35 import java.util.Properties JavaDoc;
36 import java.util.Collection JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.Enumeration JavaDoc;
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 JavaDoc name)
55     {
56         super(name);
57     }
58
59     public void testXABean() throws Exception JavaDoc {
60         int test = 0;
61
62         Context JavaDoc ctx = new InitialContext JavaDoc();
63
64          // sed kicks ass
65
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 JavaDoc("No Home!");
73             log.debug("OK");
74         } catch (Exception JavaDoc e) {
75              // sed kicks ass
76
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          // sed kicks ass
83
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 JavaDoc("No Bean!");
88             log.debug("OK");
89         } catch (Exception JavaDoc e) {
90              // sed kicks ass
91
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          // sed kicks ass
100
System.out.print(++test+"- "+"Creating required tables...");
101         try {
102             bean.createTables();
103             log.debug("OK");
104         }
105         catch (Exception JavaDoc e) {
106             log.debug("\nFailed to create tables");
107             throw e;
108         }
109
110          // sed kicks ass
111
System.out.print(++test+"- "+"Clearing any old data...");
112         try {
113             bean.clearData();
114             log.debug("OK");
115         } catch(Exception JavaDoc e) {
116              // sed kicks ass
117
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          // sed kicks ass
124
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 JavaDoc e) {
132              // sed kicks ass
133
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 JavaDoc
142    {
143       return getDeploySetup(XAUnitTestCase.class, "xatest.jar");
144    }
145
146 }
147
Popular Tags