001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.xa.test;
023:
024: import java.rmi.*;
025:
026: import javax.naming.Context;
027: import javax.naming.InitialContext;
028: import javax.ejb.DuplicateKeyException;
029: import javax.ejb.Handle;
030: import javax.ejb.EJBMetaData;
031: import javax.ejb.FinderException;
032:
033: import java.util.Date;
034: import java.util.Properties;
035: import java.util.Collection;
036: import java.util.Iterator;
037: import java.util.Enumeration;
038:
039: import junit.framework.Test;
040: import junit.framework.TestCase;
041: import junit.framework.TestSuite;
042:
043: import org.jboss.test.JBossTestCase;
044:
045: import org.jboss.test.xa.interfaces.CantSeeDataException;
046: import org.jboss.test.xa.interfaces.XATest;
047: import org.jboss.test.xa.interfaces.XATestHome;
048:
049: /* This needs lots more work to be an acceptable test case.
050: Aside from needing an xa-capable database, we need an xa-test-service.xml
051: file to deploy the two ConnectionFactoryLoaders.
052: Then the printing needs to be changed to assertions.
053:
054:
055: */
056:
057: public class XAUnitTestCase extends JBossTestCase {
058: org.apache.log4j.Category log = getLog();
059:
060: public XAUnitTestCase(String name) {
061: super (name);
062: }
063:
064: public void testXABean() throws Exception {
065: int test = 0;
066:
067: Context ctx = new InitialContext();
068:
069: // sed kicks ass
070: System.out.print(++test + "- "
071: + "Looking up the XATest home...");
072:
073: XATestHome home;
074:
075: try {
076: home = (XATestHome) ctx.lookup("XATest");
077:
078: if (home == null)
079: throw new Exception("No Home!");
080: log.debug("OK");
081: } catch (Exception e) {
082: // sed kicks ass
083: log
084: .debug("Could not lookup the context: the beans are probably not deployed");
085: log.debug("Check the server trace for details");
086:
087: throw e;
088: }
089:
090: // sed kicks ass
091: System.out.print(++test + "- "
092: + "Creating an the XATest bean...");
093: XATest bean;
094: try {
095: bean = home.create();
096: if (bean == null)
097: throw new Exception("No Bean!");
098: log.debug("OK");
099: } catch (Exception e) {
100: // sed kicks ass
101: log.debug("Could not create the bean!");
102: log.debug("Check the server trace for details");
103: log.debug("failed", e);
104:
105: throw e;
106: }
107:
108: // sed kicks ass
109: System.out.print(++test + "- " + "Creating required tables...");
110: try {
111: bean.createTables();
112: log.debug("OK");
113: } catch (Exception e) {
114: log.debug("\nFailed to create tables");
115: throw e;
116: }
117:
118: // sed kicks ass
119: System.out.print(++test + "- " + "Clearing any old data...");
120: try {
121: bean.clearData();
122: log.debug("OK");
123: } catch (Exception e) {
124: // sed kicks ass
125: log
126: .debug("Could not clear the data: did you create the table in both data sources?");
127: log
128: .debug("CREATE TABLE XA_TEST(ID INTEGER NOT NULL PRIMARY KEY, DATA INTEGER NOT NULL)");
129:
130: throw e;
131: }
132:
133: // sed kicks ass
134: System.out.print(++test + "- " + "Testing DB connections...");
135: try {
136: bean.doWork();
137: log.debug("OK");
138: } catch (CantSeeDataException e) {
139: log.debug("sort of worked.");
140: log.debug(e.getMessage());
141: } catch (Exception e) {
142: // sed kicks ass
143: log.debug("Error during DB test!");
144: log.debug("Check the server trace for details");
145:
146: throw e;
147: }
148: }
149:
150: public static Test suite() throws Exception {
151: return getDeploySetup(XAUnitTestCase.class, "xatest.jar");
152: }
153:
154: }
|