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:
022: package org.objectweb.jonas.jtests.clients.entity;
023:
024: import java.util.Collection;
025: import javax.naming.NamingException;
026: import javax.rmi.PortableRemoteObject;
027: import junit.framework.Test;
028: import junit.framework.TestSuite;
029: import org.objectweb.jonas.jtests.beans.ebasic.*;
030:
031: /**
032: * This is an advanced test suite for home interface on pk auto incremented CMP2
033: */
034: public class F_PkAutoEC2 extends A_Cmp2Util {
035:
036: private static String BEAN_HOME_PKAUTO = "pkautoobjectcmp2Home";
037:
038: protected static pkautoObjectHome pkautoobjectcmp2home = null;
039:
040: public F_PkAutoEC2(String name) {
041: super (name);
042: }
043:
044: protected boolean isInit = false;
045:
046: protected void setUp() {
047: super .setUp();
048: boolean ok = false;
049: int nbtry = 0;
050: while (!ok && nbtry < 3) {
051: if (!isInit) {
052: // load bean if not loaded yet
053: useBeans("ebasic", false);
054: // lookup home used in the tests
055: try {
056: pkautoobjectcmp2home = (pkautoObjectHome) PortableRemoteObject
057: .narrow(ictx.lookup(BEAN_HOME_PKAUTO),
058: pkautoObjectHome.class);
059: } catch (NamingException e) {
060: fail("Cannot get bean home: " + e.getMessage());
061: }
062: // check if tables have been initialized
063: try {
064: Collection bpk = pkautoobjectcmp2home.findAll();
065: if (bpk.isEmpty()) {
066: throw new Exception("Table vide");
067: }
068: } catch (Exception e) {
069: // Make the initialization needed for the tests
070: try {
071: utx.begin();
072: for (int i = 1; i <= 10; i++) {
073: pkautoobjectcmp2home.create(10, 20);
074: }
075: } catch (Exception i) {
076: i.printStackTrace(System.out);
077: fail("InitialState creation problem: " + i);
078: } finally {
079: try {
080: utx.commit();
081: } catch (Exception ii) {
082: }
083: }
084: }
085: isInit = true;
086: }
087: // Check that all is OK. Sometimes, a test has failed and has corrupted
088: // the bean state in the database. We must unload and reload the bean then.
089: nbtry++;
090: try {
091: if (initStateOK()) {
092: ok = true;
093: }
094: } catch (Exception e) {
095: e.printStackTrace(System.out);
096: }
097: if (!ok) {
098: isInit = false;
099: unloadBeans("ebasic");
100: }
101: }
102: }
103:
104: /*
105: * Check that we are in the same state as after the tables creation for thoses beans A and B
106: * (ie if it is the initial state)
107: */
108: boolean initStateOK() throws Exception {
109: msgerror = new StringBuffer();
110: Collection bpk = pkautoobjectcmp2home.findAll();
111: return (bpk.size() == 10);
112: }
113:
114: /**
115: *
116: */
117: public void testEmpty() throws Exception {
118: checkIsInitialState();
119: }
120:
121: /**
122: */
123: public static Test suite() {
124: return new TestSuite(F_PkAutoEC2.class);
125: }
126:
127: public static void main(String args[]) {
128: String testtorun = null;
129: // Get args
130: for (int argn = 0; argn < args.length; argn++) {
131: String s_arg = args[argn];
132: Integer i_arg;
133: if (s_arg.equals("-n")) {
134: testtorun = args[++argn];
135: }
136: }
137: if (testtorun == null) {
138: junit.textui.TestRunner.run(suite());
139: } else {
140: junit.textui.TestRunner.run(new F_PkAutoEC2(testtorun));
141: }
142: }
143: }
|