001: /*
002: * Speedo: an implementation of JDO compliant personality on top of JORM
003: * generic I/O sub-system. Copyright (C) 2001-2004 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU Lesser General Public License as published by the
007: * Free Software Foundation; either version 2 of the License, or (at your
008: * option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful, but WITHOUT
011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
013: * for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public License
016: * along with this library; if not, write to the Free Software Foundation,
017: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * Release: 1.0
020: *
021: * Created on Apr 9, 2004 @author fmillevi@yahoo.com
022: *
023: */
024: package org.objectweb.speedo.j2eedo;
025:
026: import javax.jdo.JDOException;
027: import javax.jdo.JDOFatalException;
028:
029: import org.objectweb.speedo.j2eedo.common.HTTPTools;
030: import org.objectweb.speedo.j2eedo.web.ApplicationServlet;
031: import org.objectweb.util.monolog.api.BasicLevel;
032:
033: /**
034: * This class defines junit application tests. The different actions are
035: * performed throulaunch an HTTP request on a J2EE application server.
036: * <p>
037: * <b>It's assume that the j2eedo application have been deployed on it.</b>
038: *
039: * @author fmillevi@yahoo.com
040: * @see TestJ2eedoApplication
041: */
042: public class TestJ2eedoJ2ee extends TestJ2eedoApplication {
043: protected final String TESTJ2EE = getLoggerName() + ".j2ee";
044: protected final String URL = getLoggerName() + ".url";
045: protected final String HTTPPARAMS = getLoggerName() + ".httpParams";
046:
047: protected String url = null;
048: protected String httpParams = null;
049:
050: /**
051: * Empty constructor, call the TestJ2eedoApplication constructor and gets
052: * the specific parameters for J2EE application test
053: *
054: * @param s
055: * name of class
056: */
057: public TestJ2eedoJ2ee(String s) {
058: super (s);
059: this .url = System.getProperty(this .URL,
060: "http://localhost:9000/j2eedo/");
061: this .httpParams = System
062: .getProperty(this .HTTPPARAMS,
063: ApplicationServlet.WITH_TRANSACTION_PARAMETER
064: + "=true");
065: }
066:
067: protected void setUp() {
068: super .setUp();
069: if (null == this .url)
070: return;
071: try {
072: logger.log(BasicLevel.INFO, HTTPTools.getURL(this .url
073: + "evictall.do",
074: this .httpParams + "&"
075: + ApplicationServlet.PARAMETER_ACTION
076: + "=evictall", "GET", logger));
077: } catch (Exception e) {
078: logger.log(BasicLevel.ERROR, "");
079: }
080:
081: }
082:
083: protected void displayTestParameters() {
084: if (!logger.isLoggable(BasicLevel.INFO))
085: return;
086: super .displayTestParameters();
087:
088: logger.log(BasicLevel.INFO, "\n\tJ2EE application URL: "
089: + this .url + "\n\tHTTP default parameters : "
090: + this .httpParams);
091: }
092:
093: /**
094: * This method executes the action pass as parameters throught an HTTP get
095: * URL call.
096: *
097: * @param action
098: * defines the type of action to be performed.
099: * @exception Exception
100: * in case of error detected during HTTP call
101: * @exception
102: * @see org.objectweb.speedo.j2eedo.bo.DatabaseImpl
103: * @see org.objectweb.speedo.j2eedo.TestJ2eedoApplication#performMethod(java.lang.String)
104: */
105: protected String performMethod(String action) throws Exception,
106: JDOException, JDOFatalException {
107: String str = "";
108: try {
109: return HTTPTools.getURL(this .url + action + ".do",
110: this .httpParams + "&"
111: + ApplicationServlet.PARAMETER_ACTION + "="
112: + action, "GET", logger);
113: } catch (Exception e) {
114: logger.log(BasicLevel.ERROR, "HTTP:The call \"" + this .url
115: + action + ".do?" + this .httpParams + "&"
116: + ApplicationServlet.PARAMETER_ACTION + "="
117: + action + "\" throws Exception ", e);
118: assertTrue(
119: "HTTP:The call \"" + this .url + action + ".do?"
120: + this .httpParams + "&"
121: + ApplicationServlet.PARAMETER_ACTION + "="
122: + action + "\" throws Exception :\n"
123: + e.toString(), false);
124: throw e;
125: }
126: }
127:
128: /**
129: * This method calls action of the DatabaseImpl class throught an HTTP call
130: * using an <b>EJB session container</b>
131: *
132: * @see org.objectweb.speedo.j2eedo.bo.DatabaseImpl
133: */
134: public void testHTTPCallSessionContainer() {
135: if (this .simpleTestOnly)
136: return;
137: if (null == this .url)
138: return;
139: this .httpParams = ApplicationServlet.WITH_TRANSACTION_PARAMETER
140: + "=false&"
141: + ApplicationServlet.TYPE_CONTAINER_PARAMETER
142: + "=true&" + ApplicationServlet.JDOTX + "=false";
143: this .perform();
144: }
145:
146: /**
147: * This method calls action of the DatabaseImpl class throught an HTTP call
148: * using an <b>EJB session container</b>. , the servlet <b>gets the
149: * persistence manager</b>
150: *
151: * @see org.objectweb.speedo.j2eedo.bo.DatabaseImpl
152: */
153: public void testHTTPCallSessionContainerWithJdoTx() {
154: if (this .simpleTestOnly)
155: return;
156: if (null == this .url)
157: return;
158: this .httpParams = ApplicationServlet.WITH_TRANSACTION_PARAMETER
159: + "=false&"
160: + ApplicationServlet.TYPE_CONTAINER_PARAMETER
161: + "=true&" + ApplicationServlet.JDOTX + "=true";
162: this .perform();
163: }
164:
165: /**
166: * This method calls action of the DatabaseImpl class throught an HTTP call
167: * <b>without any transaction</b> is started, the servlet <b>gets the
168: * persistence manager</b>
169: *
170: * @see org.objectweb.speedo.j2eedo.bo.DatabaseImpl
171: */
172: public void testHTTPWithTransWithJdoTx() {
173: if (this .simpleTestOnly)
174: return;
175: if (null == this .url)
176: return;
177: this .httpParams = ApplicationServlet.WITH_TRANSACTION_PARAMETER
178: + "=true&" + ApplicationServlet.JDOTX + "=true";
179: this.perform();
180: }
181: }
|