KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > test > core > suite > ReadOnlyTestCase


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.test.core.suite;
25
26 import junit.framework.Test;
27 import org.objectweb.jalisto.se.test.data.Book;
28 import org.objectweb.jalisto.se.test.workbench.JalistoTestCase;
29 import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite;
30 import org.objectweb.jalisto.se.api.Extent;
31 import org.objectweb.jalisto.se.api.Session;
32 import org.objectweb.jalisto.se.api.Transaction;
33 import org.objectweb.jalisto.se.JalistoFactory;
34
35 public class ReadOnlyTestCase extends JalistoTestCase {
36
37     private final static int number_of_books = 50;
38
39     public ReadOnlyTestCase() {
40     }
41
42     public ReadOnlyTestCase(String JavaDoc name) {
43         super(name);
44     }
45
46     protected void tearDownOnce() throws Exception JavaDoc {
47         super.tearDownOnce();
48         System.out.println("tearDownOnce for ReadOnly test");
49         if ((roTx != null) && (roTx.isActive())) {
50             roTx.rollback();
51         }
52         if ((roSession != null) && (roSession.isOpen())) {
53             roSession.closeSession();
54         }
55     }
56
57     public static Test suite() {
58         JalistoTestSuite suite = new JalistoTestSuite();
59         ReadOnlyTestCase tc = (ReadOnlyTestCase) newTestCase(suite, new ReadOnlyTestCase());
60
61         tc.initSession();
62
63         tc.populate(number_of_books);
64
65         tc.initRoSession();
66         tc.extentTest(number_of_books);
67
68         tc.finishTests();
69
70         return suite;
71     }
72
73     public void initRoSession() {
74         endTransaction();
75         closeSession();
76         JalistoFactory.getInternalFactory().cleanFactory();
77         roSession = JalistoFactory.getSession("jalisto-ro.properties");
78         roSession.openSession();
79         roTx = roSession.currentTransaction();
80     }
81
82     public void extentTest(int number) {
83         roTx.begin();
84         Extent extent = roSession.getExtent(Book.class).readFully();
85         assertEquals("must be equal", number, extent.size());
86         roTx.commit();
87     }
88
89     private Transaction roTx;
90     private Session roSession;
91
92     /*****************************************************************************************************/
93
94     public void initSession() {
95         super.initSession(true);
96         define(Book.getMetaDescription());
97     }
98
99     public void cleanUp(Class JavaDoc aClass) {
100         super.cleanUp(aClass);
101     }
102
103     public void finishTests() {
104         super.finishTests();
105     }
106
107     public void populate(int i) {
108         super.populate(i);
109     }
110 }
111
Popular Tags