KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > entity > A_Cmp2Util


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  */

22
23 package org.objectweb.jonas.jtests.clients.entity;
24
25 import java.util.Collection JavaDoc;
26 import java.util.Iterator JavaDoc;
27
28 import org.objectweb.jonas.jtests.util.JTestCase;
29
30
31 /**
32  * This class is used by all tests about relation ships in Entity CMP v2.
33  * @author Helene Joanin
34  */

35
36 public abstract class A_Cmp2Util extends JTestCase {
37
38     // No transaction
39
static final int TX_NO = 1;
40     // Transaction started by the client
41
static final int TX_CALL = 2;
42     // Transaction started by the container
43
static final int TX_CONT = 3;
44     // Transaction started by the client and rollbacked
45
static final int TX_RB = 4;
46
47     public A_Cmp2Util(String JavaDoc name) {
48         super(name);
49     }
50
51     abstract boolean initStateOK() throws Exception JavaDoc;
52
53     /**
54      * Check that the initial state on database is OK
55      * after running a test.
56      */

57     void checkIsInitialState() throws Exception JavaDoc {
58         boolean isOk = true;
59         try {
60             isOk = initStateOK();
61         } catch (Exception JavaDoc e) {
62             isOk = false;
63         }
64         assertTrue("Bad Initial State: " + msgerror.toString(), isOk);
65     }
66
67     /**
68      * Compare two collections
69      */

70     static boolean isCollectionEqual(Collection JavaDoc c1, Collection JavaDoc c2) {
71         // Check if the size
72
if (c1.size() != c2.size()) {
73             return false;
74         }
75         // Check if each element of c1 belong to c2
76
Iterator JavaDoc it = c1.iterator();
77         boolean b = true;
78         while(it.hasNext() && (b = c2.contains(it.next())));
79         if (it.hasNext() || !b) {
80             return false;
81         }
82         // Check if each element of c2 belong to c1
83
it = c2.iterator();
84         b = true;
85         while(it.hasNext() && (b = c1.contains(it.next())));
86         return !it.hasNext() && b;
87     }
88
89     /**
90      * Return the substring before the '-' of the given string.
91      * Ie, return "fred" if the given string is "fred-xxxx".
92      */

93     public static String JavaDoc getStringBeforeDash(String JavaDoc s) {
94         int iDash = s.indexOf("-");
95         if (iDash < 0) {
96             throw new IllegalArgumentException JavaDoc("Bad string format for getStringBeforeDash(): "+s);
97         }
98         String JavaDoc value = s.substring(0, iDash);
99         //debug("getStringBeforeDash("+s+")="+value);
100
return value ;
101     }
102
103     /**
104      * Return the int which corresponds to the substring after the '-' of the given string.
105      * Ie, return 19 if the given string is "fred-19".
106      */

107     public static int getIntAfterDash(String JavaDoc s) {
108         int iDash = s.indexOf("-");
109         if (iDash < 0) {
110             throw new IllegalArgumentException JavaDoc("Bad string format for getStringBeforeDash(): "+s);
111         }
112         String JavaDoc sInt = s.substring(iDash+1);
113         int value = (new Integer JavaDoc(sInt)).intValue();
114         //debug("getIntAfterDash("+s+")="+value);
115
return value;
116     }
117
118 }
119
Popular Tags