KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jonasadmin > test > jonasserver > F_JonasAdminSaveAll


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: F_JonasAdminSaveAll.java,v 1.2 2005/07/12 13:20:01 kemlerp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jonasadmin.test.jonasserver;
27
28 import java.io.File JavaDoc;
29
30 import junit.framework.TestSuite;
31
32 import org.objectweb.jonas.jonasadmin.test.catalina.ConnectorUtils;
33 import org.objectweb.jonas.jonasadmin.test.logging.LoggerUtils;
34 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
35 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminFiles;
36 import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
37
38 import com.meterware.httpunit.HttpUnitOptions;
39 import com.meterware.httpunit.WebConversation;
40 import com.meterware.httpunit.WebLink;
41 import com.meterware.httpunit.WebResponse;
42 import com.meterware.httpunit.WebTable;
43
44
45 /**
46  * Class for testing Save All in jonasAdmin
47  * @author Paul Kemler
48  *
49  */

50 public class F_JonasAdminSaveAll extends JonasAdminTestCase {
51
52     /**
53      * URL of the Server Management
54      */

55     private static final String JavaDoc URL_JONASADMIN_SERVER = "EditJonasServer.do";
56
57     /**
58      * URL of the SERVLET SERVER
59      */

60     private static final String JavaDoc URL_JONASADMIN_SERVLET_SERVER = "EditServletServer.do";
61
62     /**
63      * URL of the SAVE ALL button
64      */

65     private static final String JavaDoc URL_JONASADMIN_SAVE_ALL = "SaveCatalina.do";
66
67     /**
68      * URL of welcome
69      */

70     private static final String JavaDoc URL_WELCOME = "/jonasAdmin/Welcome.do";
71
72     /**
73      * A 2nd connection to jonasAdmin
74      */

75     private static WebConversation wc2 = new WebConversation();
76
77     /**
78      * Time of beginning testAllLinks
79      */

80     private String JavaDoc beginTime;
81
82     /**
83      * Time of ending testAllLinks
84      */

85     private String JavaDoc endTime;
86
87     /**
88      * Constructor with a specified name
89      * @param s name
90      */

91     public F_JonasAdminSaveAll(String JavaDoc s) {
92         super(s, URL_JONASADMIN);
93     }
94
95     /**
96      * Constructor with a specified name
97      * @param wc the WebConversation of the suite test
98      * @param s name
99      */

100     public F_JonasAdminSaveAll(WebConversation wc, String JavaDoc s) {
101         super(wc, s, URL_JONASADMIN);
102     }
103
104     /**
105      * Main method
106      * @param args the arguments
107      */

108     public static void main(String JavaDoc[] args) {
109
110         String JavaDoc testtorun = null;
111         // Get args
112
for (int argn = 0; argn < args.length; argn++) {
113             String JavaDoc sArg = args[argn];
114             if (sArg.equals("-n")) {
115                 testtorun = args[++argn];
116             }
117         }
118         if (testtorun == null) {
119             junit.textui.TestRunner.run(suite());
120         } else {
121             junit.textui.TestRunner.run(new F_JonasAdminSaveAll(testtorun));
122         }
123     }
124
125     /**
126      * Get a new TestSuite for this class
127      * @return a new TestSuite for this class
128      */

129     public static TestSuite suite() {
130         return new TestSuite(F_JonasAdminSaveAll.class);
131     }
132
133     /**
134      * Get a new TestSuite for this class
135      * @param wc the WebConversation
136      * @return a new TestSuite for this class with the WebConversation instance
137      */

138     public static TestSuite suite(WebConversation wc) {
139         TestSuite suite = new TestSuite();
140         suite.addTest(new F_JonasAdminSaveAll(wc, "testSaveAll"));
141         return suite;
142     }
143
144     /**
145      * Setup need for these tests
146      * jonasAdmin is required
147      * @throws Exception if it fails
148      */

149     protected void setUp() throws Exception JavaDoc {
150         super.setUp();
151
152         // Get time
153
beginTime = getTime();
154
155         if (wc.getCurrentPage().getURL() == null) {
156             useWar("jonasAdmin");
157             // login to jonas admin
158
try {
159                 JonasAdminAuth.doValidAuth(wc, url);
160             } catch (Exception JavaDoc e) {
161                 fail("authentification failed : " + e);
162             }
163         } else {
164             // if there was an error, the connection must be restablished
165
try {
166                 wc.getFrameContents(FRAME_TREE);
167             } catch (Exception JavaDoc e) {
168                 wc.getResponse(urlLogOut);
169                 // login to jonas admin
170
try {
171                     JonasAdminAuth.doValidAuth(wc, url);
172                 } catch (Exception JavaDoc auth) {
173                     fail("authentification failed : " + auth);
174                 }
175             }
176         }
177     }
178
179     /**
180      * Test Servlet server 'Save all'
181      * @throws Exception if error occurs
182      *
183      */

184     public void testSaveAll() throws Exception JavaDoc {
185
186         WebResponse wr;
187         WebLink link;
188         WebTable table;
189
190         // Disable errors of javascript
191
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
192         // Disable exception thrown on error status
193
HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
194
195         // OPEN A SECOND CONNECTION
196
// login to jonas admin
197
try {
198             JonasAdminAuth.doValidAuth(wc2, url);
199         } catch (Exception JavaDoc e) {
200             fail("authentification failed : " + e);
201         }
202
203         if (jProp.isCatalina()) {
204             // Go to jonas server management
205
wr = wc.getFrameContents(FRAME_TREE);
206             link = wr.getFirstMatchingLink( WebLink.MATCH_URL_STRING, URL_JONASADMIN_SERVER);
207             link.click();
208             wr = wc.getFrameContents(FRAME_CONTENT);
209             // Go to servlet server
210
link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_SERVLET_SERVER);
211             link.click();
212             wr = wc.getFrameContents(FRAME_CONTENT);
213
214             // Create new connector
215
String JavaDoc port = ConnectorUtils.createNewConnector(wc2, "http");
216             // Create new logger
217
LoggerUtils.createNewEngineLogger(wc2);
218
219             // Save all
220
link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING, URL_JONASADMIN_SAVE_ALL);
221             link.click();
222             wr = wc.getFrameContents(FRAME_CONTENT);
223
224             // Remove created connector
225
ConnectorUtils.deleteConnector(wc2, port);
226             // Remove logger
227
LoggerUtils.deleteLogger(wc2, null);
228
229             // Get server.xml and test file.
230
XMLTest xmlTest = new XMLTest("");
231             File JavaDoc serverXml = JonasAdminFiles.getServerXmlFile();
232             xmlTest.testServerXml(serverXml, port);
233
234         }
235     }
236
237     /**
238      * Tear Down
239      * cleanUp action
240      */

241     public void tearDown() throws Exception JavaDoc {
242         // Get time
243
endTime = getTime();
244
245         // Recover last server.xml configuration
246
JonasAdminFiles.recoverServerConf(beginTime, endTime);
247     }
248 }
249
Popular Tags