KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > j2eedo > TestJ2eedoJ2ee


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 9, 2004 @author fmillevi@yahoo.com
22  *
23  */

24 package org.objectweb.speedo.j2eedo;
25
26 import javax.jdo.JDOException;
27 import javax.jdo.JDOFatalException;
28
29 import org.objectweb.speedo.j2eedo.common.HTTPTools;
30 import org.objectweb.speedo.j2eedo.web.ApplicationServlet;
31 import org.objectweb.util.monolog.api.BasicLevel;
32
33 /**
34  * This class defines junit application tests. The different actions are
35  * performed throulaunch an HTTP request on a J2EE application server.
36  * <p>
37  * <b>It's assume that the j2eedo application have been deployed on it.</b>
38  *
39  * @author fmillevi@yahoo.com
40  * @see TestJ2eedoApplication
41  */

42 public class TestJ2eedoJ2ee extends TestJ2eedoApplication {
43     protected final String JavaDoc TESTJ2EE = getLoggerName() + ".j2ee";
44     protected final String JavaDoc URL = getLoggerName() + ".url";
45     protected final String JavaDoc HTTPPARAMS = getLoggerName() + ".httpParams";
46
47     protected String JavaDoc url = null;
48     protected String JavaDoc httpParams = null;
49
50     /**
51      * Empty constructor, call the TestJ2eedoApplication constructor and gets
52      * the specific parameters for J2EE application test
53      *
54      * @param s
55      * name of class
56      */

57     public TestJ2eedoJ2ee(String JavaDoc s) {
58         super(s);
59         this.url =
60             System.getProperty(this.URL, "http://localhost:9000/j2eedo/");
61         this.httpParams =
62             System.getProperty(
63                 this.HTTPPARAMS,
64                 ApplicationServlet.WITH_GETPM_PARAMETER + "=true");
65     }
66
67     protected void setUp() {
68         super.setUp();
69         if (null == this.url)
70             return;
71         try {
72             logger.log(BasicLevel.INFO, HTTPTools.getURL(
73                     this.url + "evictall.do",
74                     this.httpParams
75                         + "&"
76                         + ApplicationServlet.PARAMETER_ACTION
77                         + "=evictall",
78                     "GET",
79                     logger));
80         } catch (Exception JavaDoc e) {
81             logger.log(BasicLevel.ERROR, "");
82         }
83         
84     }
85     protected void displayTestParameters() {
86         if (!logger.isLoggable(BasicLevel.INFO))
87             return;
88         super.displayTestParameters();
89
90         logger.log(
91             BasicLevel.INFO,
92             "\n\tJ2EE application URL: "
93                 + this.url
94                 + "\n\tHTTP default parameters : "
95                 + this.httpParams);
96     }
97
98     /**
99      * This method executes the action pass as parameters throught an HTTP get
100      * URL call.
101      *
102      * @param action
103      * defines the type of action to be performed.
104      * @exception Exception
105      * in case of error detected during HTTP call
106      * @exception
107      * @see org.objectweb.speedo.j2eedo.bo.DatabaseImpl
108      * @see org.objectweb.speedo.j2eedo.TestJ2eedoApplication#performMethod(java.lang.String)
109      */

110     protected String JavaDoc performMethod(String JavaDoc action)
111         throws Exception JavaDoc, JDOException, JDOFatalException {
112         String JavaDoc str = "";
113         try {
114             return HTTPTools.getURL(
115                 this.url + action + ".do",
116                 this.httpParams
117                     + "&"
118                     + ApplicationServlet.PARAMETER_ACTION
119                     + "="
120                     + action,
121                 "GET",
122                 logger);
123         } catch (Exception JavaDoc e) {
124             logger.log(
125                 BasicLevel.ERROR,
126                 "HTTP:The call \""
127                     + this.url
128                     + action
129                     + ".do?"
130                     + this.httpParams
131                     + "&"
132                     + ApplicationServlet.PARAMETER_ACTION
133                     + "="
134                     + action
135                     + "\" throws Exception ",
136                 e);
137             assertTrue(
138                 "HTTP:The call \""
139                     + this.url
140                     + action
141                     + ".do?"
142                     + this.httpParams
143                     + "&"
144                     + ApplicationServlet.PARAMETER_ACTION
145                     + "="
146                     + action
147                     + "\" throws Exception :\n"
148                     + e.toString(),
149                 false);
150             throw e;
151         }
152     }
153
154     /**
155      * This method calls action of the DatabaseImpl class throught an HTTP call
156      * using an <b>EJB session container</b>
157      *
158      * @see org.objectweb.speedo.j2eedo.bo.DatabaseImpl
159      */

160     public void testHTTPCallSessionContainer() {
161         if (this.simpleTestOnly)
162             return;
163         if (null == this.url)
164             return;
165         this.httpParams =
166             ApplicationServlet.WITH_TRANSACTION_PARAMETER
167                 + "=false&"
168                 + ApplicationServlet.TYPE_CONTAINER_PARAMETER
169                 + "=true&"
170                 + ApplicationServlet.WITH_GETPM_PARAMETER
171                 + "=false";
172         this.perform();
173     }
174
175     /**
176      * This method calls action of the DatabaseImpl class throught an HTTP call
177      * using an <b>EJB session container</b>. , the servlet <b>gets the
178      * persistence manager</b>
179      *
180      * @see org.objectweb.speedo.j2eedo.bo.DatabaseImpl
181      */

182     public void testHTTPCallSessionContainerWithPM() {
183         if (this.simpleTestOnly)
184             return;
185         if (null == this.url)
186             return;
187         this.httpParams =
188             ApplicationServlet.WITH_TRANSACTION_PARAMETER
189                 + "=false&"
190                 + ApplicationServlet.TYPE_CONTAINER_PARAMETER
191                 + "=true&"
192                 + ApplicationServlet.WITH_GETPM_PARAMETER
193                 + "=true";
194         this.perform();
195     }
196
197     /**
198      * This method calls action of the DatabaseImpl class throught an HTTP call
199      * <b>without any transaction</b> is started, the servlet <b>gets the
200      * persistence manager</b>
201      *
202      * @see org.objectweb.speedo.j2eedo.bo.DatabaseImpl
203      */

204     public void testHTTPWithTransWithGetPM() {
205         if (this.simpleTestOnly)
206             return;
207         if (null == this.url)
208             return;
209         this.httpParams =
210             ApplicationServlet.WITH_TRANSACTION_PARAMETER
211                 + "=true&"
212                 + ApplicationServlet.WITH_GETPM_PARAMETER
213                 + "=true";
214         this.perform();
215     }
216 }
Popular Tags