KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > httpunit > AdminTest


1 /*
2  * Copyright 2002-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package test.httpunit;
19
20 import com.meterware.httpunit.*;
21
22 /**
23  * test the services
24  * @author Steve Loughran
25  * @created Jul 10, 2002 12:09:06 AM
26  */

27
28 public class AdminTest extends HttpUnitTestBase {
29
30     private String JavaDoc servlet;
31
32     private String JavaDoc invalid_service;
33
34     private boolean isProduction=false;
35
36     public AdminTest(String JavaDoc name) {
37         super(name);
38     }
39
40     /**
41      * The JUnit setup method
42      *
43      */

44     public void setUp() throws Exception JavaDoc {
45         super.setUp();
46         servlet = url + "/servlet/AdminServlet";
47     }
48
49     /**
50      * verify the page is there
51      * @throws Exception
52      */

53     public void testPage() throws Exception JavaDoc {
54         WebRequest request = new GetMethodWebRequest(servlet);
55         assertStringInBody(request, "Server");
56     }
57
58     /**
59      * dev systems have commands
60      * @throws Exception
61      */

62     public void testPageHasCommands() throws Exception JavaDoc {
63         WebRequest request = new GetMethodWebRequest(servlet);
64         assertStringInBody(request, "Server");
65         WebConversation session = new WebConversation();
66         WebResponse response = session.getResponse(request);
67         String JavaDoc body = response.getText();
68         assertTrue("start server", body.indexOf("start server")>0);
69         assertTrue("stop server", body.indexOf("stop server") > 0);
70         assertTrue("Current Load",body.indexOf("Current load") > 0);
71     }
72
73     /**
74      * test stop command
75      * @throws Exception
76      */

77     public void testStop() throws Exception JavaDoc {
78         WebRequest request = new GetMethodWebRequest(servlet);
79         request.setParameter("cmd", "stop");
80         assertStringInBody(request, "Server is stopped");
81     }
82
83     /**
84      * test start command
85      * @throws Exception
86      */

87     public void testStart() throws Exception JavaDoc {
88         WebRequest request = new GetMethodWebRequest(servlet);
89         request.setParameter("cmd", "start");
90         assertStringInBody(request, "Server is running");
91     }
92
93 }
94
Popular Tags