001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or 1any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: F_JonasAdminJoramProperties.java 7676 2005-11-17 15:04:14Z pelletib $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jonasadmin.test.joram;
025:
026: import javax.management.MBeanServerConnection;
027: import javax.management.ObjectName;
028:
029: import junit.framework.TestSuite;
030:
031: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
032: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminFiles;
033: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
034: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
035: import org.xml.sax.SAXException;
036:
037: import com.meterware.httpunit.HttpUnitOptions;
038: import com.meterware.httpunit.WebLink;
039: import com.meterware.httpunit.WebResponse;
040: import com.meterware.httpunit.WebTable;
041:
042: /**
043: * Define a class to test the JOnAS Admin console
044: * Test properties of joram platform
045: * @author kemlerp
046: *
047: */
048: public class F_JonasAdminJoramProperties extends JonasAdminTestCase {
049:
050: /**
051: * URL of the Joram Platform
052: */
053: private static final String URL_JONASADMIN_JORAM = "EditJoramPlatform.do";
054:
055: /**
056: * Name of the file of jonasAdmin test properties
057: */
058: private static final String JONASADMINTEST_PROPERTY_NAME = "jonasAdminTests";
059:
060: /**
061: * Name of the property joram.version
062: */
063: private static final String JORAM_VERSION = "joram.version";
064:
065: /**
066: * Name of the property joram.serverId
067: */
068: private static final String JORAM_SERVER_ID = "joram.serverId";
069:
070: /**
071: * Name of the property joram.serverName
072: */
073: private static final String JORAM_SERVER_NAME = "joram.serverName";
074:
075: /**
076: * Name of the property joram.collocated
077: */
078: private static final String JORAM_COLLOCATED = "joram.collocated";
079:
080: /**
081: * Name of the property joram.persistent
082: */
083: private static final String JORAM_PERSISTENT = "joram.persistent";
084:
085: /**
086: * Name of the property joram.connectingTimer
087: */
088: private static final String JORAM_CONNECTING_TIMER = "joram.connectingTimer";
089:
090: /**
091: * Name of the property joram.connectionPendingTimer
092: */
093: private static final String JORAM_CONNECTION_PENDING_TIMER = "joram.connectionPendingTimer";
094:
095: /**
096: * Name of the property joram.transactedSessionMaximumIdleness
097: */
098: private static final String JORAM_TRANSACTED_SESSION_MAXIMUM_IDLENESS = "joram.transactedSessionMaximumIdleness";
099:
100: /**
101: * Name of the property joram.timeoutToAbortRequest
102: */
103: private static final String JORAM_TIMEOUT_TO_ABORT_REQUEST = "joram.timeoutToAbortRequest";
104:
105: /**
106: * Name of the property joram.defaultThresholdForDMQ
107: */
108: private static final String JORAM_DEFAULT_THRESHOLD = "joram.defaultThresholdForDMQ";
109:
110: /**
111: * Constructor with a specified name
112: * @param s name
113: */
114: public F_JonasAdminJoramProperties(String s) {
115: super (s, URL_JONASADMIN);
116: }
117:
118: /**
119: * Main method
120: * @param args the arguments
121: */
122: public static void main(String[] args) {
123:
124: String testtorun = null;
125: // Get args
126: for (int argn = 0; argn < args.length; argn++) {
127: String sArg = args[argn];
128: if (sArg.equals("-n")) {
129: testtorun = args[++argn];
130: }
131: }
132: if (testtorun == null) {
133: junit.textui.TestRunner.run(suite());
134: } else {
135: junit.textui.TestRunner
136: .run(new F_JonasAdminJoramProperties(testtorun));
137: }
138: }
139:
140: /**
141: * Get a new TestSuite for this class
142: * @return a new TestSuite for this class
143: */
144: public static TestSuite suite() {
145: return new TestSuite(F_JonasAdminJoramProperties.class);
146: }
147:
148: /**
149: * Setup need for these tests
150: * jonasAdmin is required
151: * @throws Exception if it fails
152: */
153: protected void setUp() throws Exception {
154: super .setUp();
155:
156: if (wc.getCurrentPage().getURL() == null) {
157: useWar("jonasAdmin");
158: // login to jonas admin
159: try {
160: JonasAdminAuth.doValidAuth(wc, url);
161: } catch (Exception e) {
162: fail("authentification failed : " + e);
163: }
164: } else {
165: // if there was an error, the connection must be restablished
166: try {
167: wc.getFrameContents(FRAME_TREE);
168: } catch (Exception e) {
169: wc.getResponse(urlLogOut);
170: // login to jonas admin
171: try {
172: JonasAdminAuth.doValidAuth(wc, url);
173: } catch (Exception auth) {
174: fail("authentification failed : " + auth);
175: }
176: }
177: }
178: }
179:
180: /**
181: * Test properties of joram
182: * @throws Exception if error occurs
183: */
184: public void testJoramProperties() throws Exception {
185:
186: JonasAdminUtils utils = new JonasAdminUtils();
187: MBeanServerConnection server = getMBeanServer();
188:
189: if (jProp.isResource()) {
190: // Joram platform is in jonas
191: if (isRarLoaded("joram_for_jonas_ra")) {
192: // Disable errors of javascript
193: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
194: // Disable exception thrown on error status
195: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
196:
197: // READ joram properties from MBeans
198: ObjectName on = ObjectName
199: .getInstance("joramClient:type=JoramAdapter,*");
200: ObjectName joramAdapterON = (ObjectName) server
201: .queryNames(on, null).iterator().next();
202:
203: String version = joramAdapterON
204: .getKeyProperty("version");
205: String serverId = ((Short) server.getAttribute(
206: joramAdapterON, "ServerId")).toString();
207: String serverName = (String) server.getAttribute(
208: joramAdapterON, "ServerName");
209: String collocatedServer = "" + jProp.isJMSCollocated();
210: String persistentServer = ((Boolean) server
211: .getAttribute(joramAdapterON,
212: "PersistentPlatform")).toString();
213: String connectingTimer = ((Integer) server
214: .getAttribute(joramAdapterON, "ConnectingTimer"))
215: .toString();
216: String connectionPendingTimer = ((Integer) server
217: .getAttribute(joramAdapterON, "CnxPendingTimer"))
218: .toString();
219: String transactedSessionMaximumIdleness = ((Integer) server
220: .getAttribute(joramAdapterON, "TxPendingTimer"))
221: .toString();
222: String timeoutToAbortRequest = ""
223: + ((Long) server.getAttribute(joramAdapterON,
224: "TimeOutToAbortRequest")).longValue();
225: String hostName = (String) server.getAttribute(
226: joramAdapterON, "HostName");
227: String portNumber = ((Integer) server.getAttribute(
228: joramAdapterON, "ServerPort")).toString();
229: String fileName = (String) server.getAttribute(
230: joramAdapterON, "AdminFileXML");
231:
232: String defaultThreshold = "Not set";
233: Object defaultDMQinstance = server.getAttribute(
234: joramAdapterON, "DefaultDMQ");
235: if (defaultDMQinstance != null) {
236: defaultThreshold = defaultDMQinstance.toString();
237: }
238: // Go to Joram Platform
239: WebResponse wr = wc.getFrameContents(FRAME_TREE);
240: WebLink link = wr.getFirstMatchingLink(
241: WebLink.MATCH_URL_STRING, URL_JONASADMIN_JORAM);
242: link.click();
243: wr = wc.getFrameContents(FRAME_CONTENT);
244:
245: // Get table
246: try {
247: WebTable versionTable = utils.getTable(wr, 0);
248: WebTable currentJoramTable = utils.getTable(wr, 3);
249: WebTable timerTable = utils.getTable(wr, 6);
250: WebTable dmqTable = utils.getTable(wr, 9);
251:
252: // Get name of administration task file
253: //String fileName = currentJoramTable.getTableCell(6, 2).getText();
254:
255: // Get server port from administration task file
256: //String serverPort = JonasAdminFiles.getJoramServerPort(fileName);
257:
258: // Get host name from administration task file
259: //String hostName = JonasAdminFiles.getJoramHostName(fileName);
260:
261: // Verify
262: assertEquals(
263: "It is not the expected joram version. ",
264: version, versionTable.getTableCell(0, 2)
265: .getText());
266: assertEquals(
267: "It is not the expected joram local server id. ",
268: serverId, currentJoramTable.getTableCell(0,
269: 2).getText());
270: assertEquals(
271: "It is not the expected joram local server name. ",
272: serverName, currentJoramTable.getTableCell(
273: 1, 2).getText());
274: assertEquals(
275: "It is not the expected joram local host name. ",
276: hostName, currentJoramTable.getTableCell(2,
277: 2).getText());
278: assertEquals(
279: "It is not the expected joram local server port. ",
280: portNumber, currentJoramTable.getTableCell(
281: 3, 2).getText());
282: assertEquals(
283: "It is not the expected value of the collocated server attribut. ",
284: collocatedServer, currentJoramTable
285: .getTableCell(4, 2).getText());
286: assertEquals(
287: "It is not the expected value of the persistent server attribut. ",
288: persistentServer, currentJoramTable
289: .getTableCell(5, 2).getText());
290: assertEquals(
291: "It is not the expected joram configuration file name. ",
292: fileName, currentJoramTable.getTableCell(6,
293: 2).getText());
294: assertEquals(
295: "It is not the expected connecting timer. ",
296: connectingTimer, timerTable.getTableCell(0,
297: 2).getText());
298: assertEquals(
299: "It is not the expected connection pending timer. ",
300: connectionPendingTimer, timerTable
301: .getTableCell(1, 2).getText());
302: assertEquals(
303: "It is not the expected transacted session maximum idleness. ",
304: transactedSessionMaximumIdleness,
305: timerTable.getTableCell(2, 2).getText());
306: assertEquals(
307: "It is not the expected timeout to abort request. ",
308: timeoutToAbortRequest, timerTable
309: .getTableCell(3, 2).getText());
310: assertEquals(
311: "It is not the expected default threshold for DMQ. ",
312: defaultThreshold, dmqTable.getTableCell(1,
313: 2).getText());
314: } catch (SAXException e) {
315: fail("Tables are not correct.");
316: }
317: }
318: }
319:
320: }
321:
322: /**
323: * Tear Down cleanUp action
324: * @throws Exception if an error occurs
325: */
326: public void tearDown() throws Exception {
327: super.tearDown();
328: }
329: }
|