1
2
3
4
5
6
7
8
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
45 plugin = null;
46 }
47
48
49 if ("org.astrogrid.tableserver.test.SampleStarsPlugin".equals(plugin)) {
50 SampleStarsPlugin.initConfig();
51 }
52
53
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
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
88
89
90
91
92
93
94
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
100
101
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
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 }