001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: * --------------------------------------------------------------------------
021: * $Id: F_Remon.java 7533 2005-10-19 15:55:05Z durieuxp $
022: * --------------------------------------------------------------------------
023: */
024:
025: package org.objectweb.jonas.jtests.clients.entity;
026:
027: import java.rmi.RemoteException;
028: import java.util.Collection;
029: import java.util.Iterator;
030: import javax.ejb.EJBObject;
031: import javax.ejb.FinderException;
032: import javax.ejb.RemoveException;
033: import javax.naming.NamingException;
034: import javax.rmi.PortableRemoteObject;
035: import junit.framework.Assert;
036: import junit.framework.Test;
037: import junit.framework.TestSuite;
038: import org.objectweb.jonas.jtests.beans.relation.remon.Main;
039: import org.objectweb.jonas.jtests.beans.relation.remon.MainHome;
040: import org.objectweb.jonas.jtests.util.JTestCase;
041:
042: /**
043: * This test suite tests specifics mapping used in some applications
044: * for example, cmr field and cmp field mapped on the same table column
045: * @author Philippe Durieux
046: */
047: public class F_Remon extends JTestCase {
048:
049: /**
050: * Reference on the remote Home's
051: */
052: private static MainHome mainhome = null;
053:
054: /**
055: * Standard constructor
056: */
057: public F_Remon(String name) {
058: super (name);
059: }
060:
061: protected boolean isInit = false;
062:
063: /**
064: * setup is called before each test case.
065: * If not initialized, load the remon bean and lookup the Home.
066: */
067: protected void setUp() {
068: super .setUp();
069: if (!isInit) {
070: useBeans("remon", false);
071: try {
072: mainhome = (MainHome) PortableRemoteObject.narrow(ictx
073: .lookup("relation_remon_MainHome"),
074: MainHome.class);
075: } catch (NamingException e) {
076: fail("Cannot get bean home: " + e.getMessage());
077: }
078: isInit = true;
079: }
080: }
081:
082: /**
083: * teardown is called after each test case.
084: * Notes for debugging :
085: * To see DataBase state after a test is passed :
086: * Replace the cleanall() by sync(false).
087: */
088: protected void tearDown() throws Exception {
089: cleanall();
090: //sync(false);
091: }
092:
093: /**
094: * Cleanup all the remon after each test, to make tests independant.
095: * Use transaction to avoid known bugs during cleanup.
096: * (With no transaction -> 1 remove will fail)
097: */
098: private void cleanall() throws Exception {
099: debug("remove all beans");
100:
101: // In case there is a problem during remove, we must unload
102: // the bean to restart properly.
103: try {
104: cleanAllBeans(mainhome);
105: } catch (Exception e) {
106: error("Exception in cleanup: " + e);
107: unloadBeans("remon");
108: isInit = false;
109: }
110: }
111:
112: private void cleanAllBeans(MainHome home) throws RemoteException,
113: RemoveException {
114: try {
115: Collection c = home.findAll();
116: for (Iterator i = c.iterator(); i.hasNext();) {
117: EJBObject p = (EJBObject) i.next();
118: p.remove();
119: }
120: } catch (FinderException e) {
121: }
122: }
123:
124: // ---------------------------------------------------------------
125: // Set of the tests that are passed automatically.
126: // ---------------------------------------------------------------
127:
128: public void testCreateMain() throws Exception {
129: mainhome.create("A1", "100", "at1");
130: }
131:
132: /**
133: * Run all the tests of this suite.
134: */
135: public static Test suite() {
136: return new TestSuite(F_Remon.class);
137: }
138:
139: public static void main(String args[]) throws Exception {
140: String testtorun = null;
141:
142: // Get args
143: for (int argn = 0; argn < args.length; argn++) {
144: String sarg = args[argn];
145: if (sarg.equals("-n")) {
146: testtorun = args[++argn];
147: }
148: }
149: if (testtorun == null) {
150: junit.textui.TestRunner.run(suite());
151: } else {
152: junit.textui.TestRunner.run(new F_Remon(testtorun));
153: }
154: }
155:
156: }
|