View Javadoc

1   /*$Id: InstallationPropertiesCheck.java,v 1.6 2006/10/17 10:11:41 clq2 Exp $
2    * Created on 28-Nov-2003
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid
7    * Software License version 1.2, a copy of which has been included
8    * with this distribution in the LICENSE.txt file.
9    *
10   **/
11  package org.astrogrid.dataservice.service;
12  
13  import java.util.Vector;
14  import junit.framework.TestCase;
15  import org.astrogrid.cfg.ConfigFactory;
16  import org.astrogrid.cfg.PropertyNotFoundException;
17  import org.astrogrid.tableserver.test.SampleStarsPlugin;
18  
19  
20  /*** Unit test for checking an installation - checks that all properties
21   * are at least present.
22   * <p>
23   * not intended for use during development - hence the different naming convention.
24   * @author Noel Winstanley nw@jb.man.ac.uk 28-Nov-2003
25   *
26   * (MCH Dec ratpak - removed 'fails' so that original exceptions propogate nicely
27   * to nice web self-test page)
28   */
29  public class InstallationPropertiesCheck extends TestCase {
30     
31     /*** Checks that all expected properties are set */
32     public void testAllPropertiesSet()
33     {
34        boolean allOK = true;
35        String test;
36        Vector accum = new Vector();
37  
38        String plugin;
39        try {
40          plugin = ConfigFactory.getCommonConfig().getString(
41                "datacenter.querier.plugin");
42        }
43        catch (PropertyNotFoundException e) {
44          // Ignore this one so we can report it to the user later
45          plugin = null;
46        }
47  
48        // Catch any properties set by the sample plugin
49        if ("org.astrogrid.tableserver.test.SampleStarsPlugin".equals(plugin)) {
50           SampleStarsPlugin.initConfig();
51        }
52  
53        // Check all properties are set
54        allOK = allOK && checkSet("datacenter.url", accum);
55        allOK = allOK && checkSet("datacenter.metadoc.file", accum);
56        allOK = allOK && checkSet("datacenter.querier.plugin", accum);
57        allOK = allOK && checkSet("datacenter.sqlmaker.xslt", accum);
58        allOK = allOK && checkSet("db.trigfuncs.in.radians", accum);
59  
60        allOK = allOK && checkSet("datacenter.max.return", accum);
61        allOK = allOK && checkSet("datacenter.max.queries", accum);
62        allOK = allOK && checkSet("datacenter.sql.timeout", accum);
63  
64        allOK = allOK && checkSet("datacenter.self-test.table", accum);
65        allOK = allOK && checkSet("datacenter.self-test.column1", accum);
66        allOK = allOK && checkSet("datacenter.self-test.column2", accum);
67  
68        allOK = allOK && checkSet("datacenter.implements.conesearch", accum);
69        allOK = allOK && checkSet("conesearch.table", accum);
70        allOK = allOK && checkSet("conesearch.ra.column", accum);
71        allOK = allOK && checkSet("conesearch.dec.column", accum);
72        allOK = allOK && checkSet("conesearch.columns.units", accum);
73  
74        allOK = allOK && checkSet("datacenter.name", accum);
75        allOK = allOK && checkSet("datacenter.description", accum);
76  
77        allOK = allOK && checkSet("datacenter.authorityId", accum);
78        allOK = allOK && checkSet("datacenter.resourceKey", accum);
79  
80        // Assume we need at least one resource (something to publish)
81        allOK = allOK && checkSet("datacenter.resource.plugin.1", accum);
82  
83        allOK = allOK && checkSet("org.astrogrid.registry.admin.endpoint", accum);
84        allOK = allOK && checkSet("org.astrogrid.registry.query.endpoint", accum);
85        allOK = allOK && checkSet("org.astrogrid.registry.query.altendpoint", accum);
86        allOK = allOK && checkSet("cea.component.manager.class", accum);
87        // These ones aren't compulsory:
88        // datacenter.publisher
89        // datacenter.contact.name
90        // datacenter.contact.email
91        // datacenter.ucd.version
92        //
93  
94        // These ones are used by the jdbc plugin
95        if ("org.astrogrid.tableserver.jdbc.JdbcPlugin".equals(plugin)) {
96          allOK = allOK && checkSet("datacenter.plugin.jdbc.user", accum);
97          allOK = allOK && checkSet("datacenter.plugin.jdbc.drivers", accum);
98          allOK = allOK && checkSet("datacenter.plugin.jdbc.url", accum);
99          // This one is allowed to be empty - it's possible that the RDBMS
100         // has no password
101         //allOK = allOK && checkSet("datacenter.plugin.jdbc.password", accum);
102       }
103 
104       String accumString = "";
105       for (int i = 0; i < accum.size(); i++) {
106         accumString = accumString + (String)accum.elementAt(i);
107       }
108       assertTrue("SOME PROPERTIES ARE NOT SET!<br/>\n" + accumString,allOK);
109    }
110 
111    protected boolean checkSet(String name, Vector accum)
112    {
113       String property;
114       try {
115          property = ConfigFactory.getCommonConfig().getString(name);
116       } 
117       catch (PropertyNotFoundException e) {
118         // Ignore this one so we can report it to the user later
119         property = null;
120       }
121       if (property == null) {
122         accum.add(
123           "<br/>\nProperty '" + name + "' is not set, please set it!"); 
124 
125         return false;
126       }
127       if (property.equals("")) {
128         accum.add(
129           "<br/>\nProperty '" + name + "' is not set, please set it!"); 
130         return false;
131       }
132       return true;
133    }
134 }