View Javadoc

1   /*
2    * Copyright (c) 2002 Peter Antman, Teknik i Media  <peter.antman@tim.se>
3    *
4    * $Id: ServerAliveTest.java,v 1.1.1.1 2004/05/19 12:33:41 pra Exp $
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 of the License, or (at your option) any 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  USA
19   */
20  package org.backsource.alert.agent;
21  import java.net.URL;
22  
23  import org.backsource.alert.PropertyConstants;
24  import org.backsource.alert.AlertError;
25  /***
26   * Agent that test a certain url and check the content returned.
27   *
28   * <p>Is for example used to check JBoss servers by accessing the HTML
29   * adapter of the JMX server. It uses two properties {@link org.backsource.alert.PropertyConstants#SERVER_ALIVE_URL} and {@link org.backsource.alert.PropertyConstants#SERVER_ALIVE_FIND}.Se {@link UrlCase} for properties partaining to authentication.</p> 
30   *
31   *
32   * @author <a href="mailto:pra@tim.se">Peter Antman</a>
33   * @version $Revision: 1.1.1.1 $
34   */
35  
36  public class ServerAliveTest extends UrlCase{
37     URL url = null;
38     String find = null;
39     public ServerAliveTest (String name){
40        super(name);
41     }
42  
43     protected void setUp() throws Exception{
44        super.setUp();
45        String t = prop.getProperty(PropertyConstants.SERVER_ALIVE_URL);
46        url = new URL(t);
47        find = prop.getProperty(PropertyConstants.SERVER_ALIVE_FIND);
48     }
49  
50     /***
51      * The agent/test method.
52      *
53      * <p>Checks that the given url returns 200 and contains the string given in {@link org.backsource.alert.PropertyConstants#SERVER_ALIVE_FIND}.</p>
54      */
55     public void testServerAlive() {
56        try {
57           checkUrl(url,find);
58        } catch ( AlertError e) {
59           throw new AlertError("Server probably dead: " + e);
60        } // end of try-catch
61        
62  
63     }
64     
65     public static void main(String[] args){
66        try {
67           ServerAliveTest t = new ServerAliveTest("main");
68           t.url = new URL("http://10.72.9.11:8082/ViewObjectRes//Amsterdam%3Aservice%3DServiceFactory");
69           t.find="<TITLE>MBean View of Amsterdam:service=ServiceFactory</TITLE>";
70           t.testServerAlive();
71        } catch (Exception  e) {
72           e.printStackTrace();
73        } // end of try-catch
74        
75     }
76  } // ServerAliveTest