KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > j2eedo > test > BasicTest


1 /*
2  * Speedo: an implementation of JDO compliant personality on top of JORM
3  * generic I/O sub-system. Copyright (C) 2001-2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Release: 1.0
20  *
21  * Created on Apr 19, 2004 @author franck.milleville@cgey.com
22  *
23  */

24 package org.objectweb.speedo.j2eedo.test;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collections JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30
31 import javax.jdo.JDOException;
32 import javax.jdo.JDOFatalException;
33 import javax.jdo.JDOHelper;
34 import javax.jdo.PersistenceManagerFactory;
35
36 import org.objectweb.speedo.j2eedo.bo.DatabaseImpl;
37 import org.objectweb.speedo.j2eedo.common.PMHolder;
38 import org.objectweb.util.monolog.api.BasicLevel;
39
40 /**
41  * Exceute 20 times all {@link org.objectweb.speedo.j2eedo.bo.DatabaseImpl
42  * DatabaseImpl actions}
43  * @author fmillevi@yahoo.com
44  * @see MainLauncher
45  */

46 public class BasicTest extends MainLauncher {
47     
48     private static final int NUMBER_OF_TEST = 20;
49
50     /**
51      * This method connects to the database using the default speedo properties
52      * file and calls the test method doTest
53      *
54      * @param args not used
55      * @throws JDOException
56      * @throws Exception
57      * @see #doTest()
58      */

59     public static void main(String JavaDoc[] args) throws JDOException, Exception JavaDoc {
60         BasicTest ml = new BasicTest();
61         ml.initPMF();
62         ml.doTest();
63     }
64     
65     /**
66      * It calls several times each known actions
67      * @see org.objectweb.speedo.j2eedo.test.MainLauncher#doTest()
68      */

69     public void doTest() throws JDOException, Exception JavaDoc {
70         final List JavaDoc methodsList = new ArrayList JavaDoc();
71
72         for (int i = 0; i < DatabaseImpl.actionArray.length; i++)
73             for (int j = 0; j < NUMBER_OF_TEST; j++)
74                 methodsList.add(DatabaseImpl.actionArray[i]);
75
76         String JavaDoc action = null;
77         String JavaDoc returnStr = null;
78         Iterator JavaDoc iter = null;
79         PersistenceManagerFactory pmf =
80             JDOHelper.getPersistenceManagerFactory(p);
81         PMHolder pmHolder = new PMHolder(pmf);
82
83         DatabaseImpl databaseImpl = new DatabaseImpl(pmHolder);
84
85         int j = 0;
86
87         Collections.shuffle(methodsList);
88         iter = methodsList.iterator();
89         while (iter.hasNext()) {
90             if (0 == (j++ % 100.0))
91                 logger.log(
92                     BasicLevel.INFO,
93                     j + " actions called...");
94             action = (String JavaDoc) iter.next();
95             // check if the action need to start a transaction
96
logger.log(BasicLevel.DEBUG, "Calls method:" + action);
97             try {
98                 returnStr = databaseImpl.doAction(action, true);
99             } catch (JDOFatalException e) {
100                 logger.log(
101                     BasicLevel.WARN,
102                     "Action '"
103                         + action
104                         + "' throws a JDOFatalException exception :",
105                     e);
106             } catch (JDOException e) {
107                 logger.log(
108                     BasicLevel.WARN,
109                     "Action '" + action + "' throws a JDO exception :",
110                     e);
111             } catch (Exception JavaDoc e) {
112                 logger.log(
113                     BasicLevel.WARN,
114                     "Action '" + action + "' throws an exception :",
115                     e);
116             }
117
118             logger.log(
119                 BasicLevel.DEBUG,
120                 "The method " + action + " returns:\n" + returnStr);
121         }
122     }
123 }
124
Popular Tags