KickJava   Java API By Example, From Geeks To Geeks.

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


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.JalistoFactory;
28 import org.objectweb.jalisto.se.api.Session;
29 import org.objectweb.jalisto.se.api.JalistoProperties;
30 import org.objectweb.jalisto.se.test.data.Author;
31 import org.objectweb.jalisto.se.test.data.Book;
32 import org.objectweb.jalisto.se.test.workbench.JalistoTestCase;
33 import org.objectweb.jalisto.se.test.workbench.JalistoTestSuite;
34
35 public class InitStoreTestCase extends JalistoTestCase {
36     public InitStoreTestCase() {
37     }
38
39     public InitStoreTestCase(String JavaDoc name) {
40         super(name);
41     }
42
43     public static Test suite() {
44         JalistoTestSuite suite = new JalistoTestSuite();
45         InitStoreTestCase tc = (InitStoreTestCase) newTestCase(suite, new InitStoreTestCase());
46
47         tc.define();
48
49         tc.printSessionProperties();
50
51         tc.sameSession();
52         tc.twoSessionsWithDifferentUserMode();
53
54         tc.finishTests();
55
56         return suite;
57     }
58
59     public void printSessionProperties() {
60         if (session.getInternalSession().isRemoteSession()) {
61             out("IS REMOTE SESSION");
62             return;
63         }
64         JalistoProperties props = session.getInternalSession().getProperties();
65         if (props.isMonoImplementation()) {
66             out("USE MONO SESSION");
67         } else {
68             out("USE MULTI SESSION");
69         }
70
71     }
72
73     public void sameSession() {
74         if (session.getInternalSession().isRemoteSession()) {
75             out("can't execute this test with remote client");
76             return;
77         }
78         String JavaDoc path = getJalistoPropertiesFilename();
79         JalistoProperties jalistoProps = JalistoFactory.getInternalFactory().getProperties(path);
80         if (jalistoProps.isMonoImplementation()) {
81             Session session1 = JalistoFactory.getSession(path);
82             Session session2 = JalistoFactory.getSession(path);
83             assertTrue("sessions must be equals in mono mode", session1 == session2);
84         }
85     }
86
87     public void twoSessionsWithDifferentUserMode() {
88         if (session.getInternalSession().isRemoteSession()) {
89             out("can't execute this test with remote client");
90             return;
91         }
92         String JavaDoc path;
93         if (session.getInternalSession().getProperties().isMonoImplementation()) {
94             path = "jalisto-multi.properties";
95         } else {
96             path = "jalisto-mono.properties";
97         }
98         Session parallelSession = JalistoFactory.getSession(path);
99         try {
100             parallelSession.openSession();
101             parallelSession.currentTransaction().begin();
102             parallelSession.currentTransaction().commit();
103         } finally {
104             if (parallelSession != null) {
105                 if (parallelSession.currentTransaction().isActive()) {
106                     parallelSession.currentTransaction().commit();
107                 }
108                 if (parallelSession.isOpen()) {
109                     parallelSession.closeSession();
110                 }
111             }
112         }
113     }
114
115     private static void out(Object JavaDoc message) {
116         String JavaDoc s = "--> " + String.valueOf(message);
117         System.out.println(s);
118     }
119
120     /**
121      * **************************************************************************************
122      */

123
124     public void define() {
125         super.initSession(false);
126         if (!session.getInternalSession().isRemoteSession()) {
127             super.define(Author.getMetaDescription());
128             super.define(Book.getMetaDescription());
129         }
130     }
131
132     public void finishTests() {
133         super.finishTests();
134     }
135 }
136
Popular Tags