View Javadoc

1   /*
2    * Copyright (c) 2002 Peter Antman, Teknik i Media  <peter.antman@tim.se>
3    *
4    * $Id: DbAliveTest.java,v 1.1.1.1 2004/05/19 12:33:40 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  import org.backsource.alert.PropertyConstants;
23  import org.backsource.alert.AlertError;
24  /***
25   * Legacy class from in that check a servlet that access a database.
26   *
27   * <p>User the property {@link org.backsource.alert.PropertyConstants#DB_ALIVE_URL} to point to the servlet.Se {@link UrlCase} for properties partaining to authentication.</p>
28   *
29   *
30   * @author <a href="mailto:pra@tim.se">Peter Antman</a>
31   * @version $Revision: 1.1.1.1 $
32   */
33  
34  public class DbAliveTest extends UrlCase{
35     URL url;
36     public DbAliveTest (String name){
37        super(name);
38     }
39     
40     protected void setUp() throws Exception{
41        super.setUp();
42        String t = prop.getProperty(PropertyConstants.DB_ALIVE_URL);
43        url = new URL(t);
44     }
45  
46     /***
47      * The test method that checks if the db servlet is ok.
48      */
49     public void testDbAlive() {
50        try {
51           checkUrl(url);
52        } catch ( AlertError e) {
53           throw new AlertError("Database/or server probably dead: " + e);
54        } // end of try-catch
55        
56  
57     }
58     public static void main(String[] args){
59        try {
60           DbAliveTest t = new DbAliveTest("main");
61           t.url = new URL("http://localhost:8080/alert/DbServlet");
62           t.testDbAlive();
63        } catch (Exception  e) {
64           e.printStackTrace();
65        } // end of try-catch try {
66     }
67  } // DbAliveTest