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_JonasAdminDiscovery.java 7381 2005-09-14 16:00:02Z kemlerp $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jonasadmin.test.service.discovery;
025:
026: import junit.framework.TestSuite;
027:
028: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
029: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
030: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
031:
032: import com.meterware.httpunit.HTMLElement;
033: import com.meterware.httpunit.HttpUnitOptions;
034: import com.meterware.httpunit.WebLink;
035: import com.meterware.httpunit.WebResponse;
036: import com.meterware.httpunit.WebTable;
037:
038: /**
039: * Class for testing discovery service
040: * @author Paul Kemler
041: *
042: */
043: public class F_JonasAdminDiscovery extends JonasAdminTestCase {
044:
045: /**
046: * URL of discovery service
047: */
048: private static final String URL_JONASADMIN_DISCOVERY = "EditServiceDiscovery.do";
049:
050: /**
051: * number of tabs when you are in discovery
052: */
053: private static final int NUMBER_OF_TABS_FOR_DISCOVERY = 1;
054:
055: /**
056: * Constructor with a specified name
057: * @param s name
058: */
059: public F_JonasAdminDiscovery(String s) {
060: super (s, URL_JONASADMIN);
061: }
062:
063: /**
064: * Main method
065: * @param args the arguments
066: */
067: public static void main(String[] args) {
068:
069: String testtorun = null;
070: // Get args
071: for (int argn = 0; argn < args.length; argn++) {
072: String sArg = args[argn];
073: if (sArg.equals("-n")) {
074: testtorun = args[++argn];
075: }
076: }
077: if (testtorun == null) {
078: junit.textui.TestRunner.run(suite());
079: } else {
080: junit.textui.TestRunner.run(new F_JonasAdminDiscovery(
081: testtorun));
082: }
083: }
084:
085: /**
086: * Get a new TestSuite for this class
087: * @return a new TestSuite for this class
088: */
089: public static TestSuite suite() {
090: return new TestSuite(F_JonasAdminDiscovery.class);
091: }
092:
093: /**
094: * Setup need for these tests
095: * jonasAdmin is required
096: * @throws Exception if it fails
097: */
098: protected void setUp() throws Exception {
099: super .setUp();
100:
101: if (wc.getCurrentPage().getURL() == null) {
102: useWar("jonasAdmin");
103: // login to jonas admin
104: try {
105: JonasAdminAuth.doValidAuth(wc, url);
106: } catch (Exception e) {
107: fail("authentification failed : " + e);
108: }
109: } else {
110: // if there was an error, the connection must be restablished
111: try {
112: wc.getFrameContents(FRAME_TREE);
113: } catch (Exception e) {
114: wc.getResponse(urlLogOut);
115: // login to jonas admin
116: try {
117: JonasAdminAuth.doValidAuth(wc, url);
118: } catch (Exception auth) {
119: fail("authentification failed : " + auth);
120: }
121: }
122: }
123: }
124:
125: /**
126: * Test discovery table
127: * @throws Exception if error occurs
128: *
129: */
130: public void testDiscovery() throws Exception {
131:
132: WebResponse wr;
133: WebLink link;
134: WebTable table;
135: WebTable tabTable;
136: int selectedTab;
137: JonasAdminUtils utils = new JonasAdminUtils();
138:
139: // Disable errors of javascript
140: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
141: // Disable exception thrown on error status
142: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
143:
144: // Test only if the discovery service is enabled
145: if (jProp.isDiscovery()) {
146:
147: // Go to discovery service
148: wr = wc.getFrameContents(FRAME_TREE);
149: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
150: URL_JONASADMIN_DISCOVERY);
151: link.click();
152: wr = wc.getFrameContents(FRAME_CONTENT);
153: selectedTab = 1;
154:
155: // Verify multicast infos
156: table = utils.getTable(wr, 0);
157: // Multicast address
158: String address = jProp.getPropertiesEnv().getProperty(
159: "jonas.service.discovery.multicast.address");
160: assertEquals("It is not the expected multicast address. ",
161: address, table.getTableCell(0, 2).getText());
162: // Multicast port
163: String port = jProp.getPropertiesEnv().getProperty(
164: "jonas.service.discovery.multicast.port");
165: assertEquals("It is not the expected multicast port. ",
166: port, table.getTableCell(1, 2).getText());
167:
168: // Verify action
169: String master = table.getTableCell(2, 2).getText();
170: table = utils.getTable(wr, 3);
171: if (master.equals("true")) {
172: // class="btnDisabled"
173: HTMLElement[] btnDisabled = table.getTableCell(0, 0)
174: .getElementsWithAttribute("class",
175: "btnDisabled");
176: assertEquals(
177: "The class of the Start button is not 'btnDisabled'. ",
178: 1, btnDisabled.length);
179:
180: // No link
181: WebLink[] btnLink = table.getTableCell(0, 0).getLinks();
182: assertEquals("There is a link on the Start button. ",
183: 0, btnLink.length);
184: } else {
185: // No class="btnDisabled"
186: HTMLElement[] btnDisabled = table.getTableCell(0, 0)
187: .getElementsWithAttribute("class",
188: "btnDisabled");
189: assertEquals(
190: "The class of the Start button is not 'btnDisabled'. ",
191: 0, btnDisabled.length);
192:
193: // link=/DiscoveryServiceStartMaster.do
194: WebLink[] btnLink = table.getTableCell(0, 0).getLinks();
195: assertEquals("There is no link on the Start button. ",
196: 1, btnLink.length);
197: assertTrue(
198: "It is not the expected URL of the Start button. ",
199: btnLink[0].getURLString().endsWith(
200: "/DiscoveryServiceStartMaster.do"));
201:
202: // Start Master
203: btnLink[0].click();
204: wr = wc.getFrameContents(FRAME_CONTENT);
205:
206: // Verify is master
207: table = utils.getTable(wr, 0);
208: master = table.getTableCell(2, 2).getText();
209: assertEquals("It is not master. ", "true", master);
210: table = utils.getTable(wr, 3);
211: // class="btnDisabled"
212: btnDisabled = table.getTableCell(0, 0)
213: .getElementsWithAttribute("class",
214: "btnDisabled");
215: assertEquals(
216: "The class of the Start button is not 'btnDisabled'. ",
217: 1, btnDisabled.length);
218:
219: // No link
220: btnLink = table.getTableCell(0, 0).getLinks();
221: assertEquals("There is a link on the Start button. ",
222: 0, btnLink.length);
223: }
224:
225: // Verify there is 1 tab
226: tabTable = utils.getTabTable(wr);
227: testTabs(tabTable, NUMBER_OF_TABS_FOR_DISCOVERY,
228: selectedTab, "Problem in 'Discovery' tab.");
229: }
230: }
231:
232: /**
233: * Tear Down cleanUp action
234: * @throws Exception if an error occurs
235: */
236: public void tearDown() throws Exception {
237: super.tearDown();
238: }
239:
240: }
|