1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.dataservice.service;
12
13
14
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.StringWriter;
18 import java.lang.reflect.Constructor;
19 import java.net.URL;
20 import java.security.Principal;
21 import javax.xml.parsers.ParserConfigurationException;
22 import junit.framework.TestCase;
23 import org.astrogrid.account.LoginAccount;
24 import org.astrogrid.cfg.ConfigFactory;
25 import org.astrogrid.dataservice.api.nvocone.NvoConeSearcher;
26 import org.astrogrid.dataservice.impl.roe.SssImagePlugin;
27 import org.astrogrid.dataservice.metadata.VoDescriptionServer;
28 import org.astrogrid.dataservice.queriers.QuerierPlugin;
29 import org.astrogrid.dataservice.queriers.QuerierPluginFactory;
30 import org.astrogrid.dataservice.service.skynode.v074.SkyNodeService;
31 import org.astrogrid.dataservice.service.soap.AxisDataService_v06;
32 import org.astrogrid.query.Query;
33 import org.astrogrid.query.QueryException;
34 import org.astrogrid.query.SimpleQueryMaker;
35 import org.astrogrid.query.adql.Adql074Writer;
36 import org.astrogrid.query.returns.ReturnTable;
37 import org.astrogrid.query.sql.SqlParser;
38 import org.astrogrid.slinger.targets.TargetIdentifier;
39 import org.astrogrid.slinger.targets.TargetMaker;
40 import org.astrogrid.xml.DomHelper;
41 import org.xml.sax.SAXException;
42
43 /*** Unit test for checking an installation - checks location of config files, etc.
44 * <p>
45 * not intended for use during development - hence the different naming convention.
46 * @author Noel Winstanley nw@jb.man.ac.uk 28-Nov-2003
47 *
48 * (MCH Dec ratpak - removed 'fails' so that original exceptions propogate nicely
49 * to nice web self-test page)
50 */
51 public class InstallationSelfCheck extends TestCase {
52
53 private Principal testPrincipal = new LoginAccount("SelfTest", "localhost");
54
55 /*** Checks we can create the various interfaces */
56 public void testInstantiateServer() throws IOException {
57 new AxisDataService_v06();
58 new SkyNodeService();
59 }
60
61 /*** Checks the characteristics of the plugin */
62 public void testPluginDefinition() throws Exception {
63 String pluginClass = ConfigFactory.getCommonConfig().getString(QuerierPluginFactory.QUERIER_PLUGIN_KEY);
64 assertNotNull(QuerierPluginFactory.QUERIER_PLUGIN_KEY + " is not defined",pluginClass);
65
66 Class plugin = null;
67
68 plugin = Class.forName(pluginClass);
69 assertNotNull(QuerierPluginFactory.QUERIER_PLUGIN_KEY + " could not be found",plugin);
70
71 assertTrue(QuerierPluginFactory.QUERIER_PLUGIN_KEY + " does not extend QuerierPlugin",QuerierPlugin.class.isAssignableFrom(plugin));
72
73 Constructor constr = plugin.getConstructor(new Class[]{ });
74 assertNotNull("Plugin class must provide constructor(String,Query)",constr);
75 }
76
77 /***
78 * Creates a test query from properties, defaulting to cone(30,-80,0.1)
79 */
80 public Query makeTestQuery(TargetIdentifier target, String format) throws QueryException, ParserConfigurationException, IOException, SAXException {
81 String sql = ConfigFactory.getCommonConfig().getString("datacenter.testquery.sql", null);
82 if (sql != null) {
83 return SqlParser.makeQuery(sql, target, format);
84 }
85
86 String ra = ConfigFactory.getCommonConfig().getString("datacenter.testquery.ra","30");
87 String dec = ConfigFactory.getCommonConfig().getString("datacenter.testquery.dec","-80");
88 String radius = ConfigFactory.getCommonConfig().getString("datacenter.testquery.radius","0.1");
89 return SimpleQueryMaker.makeConeQuery(Double.parseDouble(ra),Double.parseDouble(dec),Double.parseDouble(radius), target, format);
90 }
91
92 /*** Checks the querier/plugin operates - runs a test query that will exercise it
93 * direct to the data server - so
94 * this will also test the connection to the backend database, but not any of the
95 * public interfaces */
96 public void testQueryDirect() throws Throwable {
97
98 StringWriter sw = new StringWriter();
99 DataServer server = new DataServer();
100 server.askQuery(testPrincipal,makeTestQuery(TargetMaker.makeTarget(sw), ReturnTable.VOTABLE), this);
101 }
102
103 /*** Checks that we can submit ADQL through the AxisDataService, again an internal check */
104 public void testAxisServiceClassAdql() throws Throwable {
105
106 AxisDataService_v06 server = new AxisDataService_v06();
107 Query testQuery = makeTestQuery(TargetMaker.makeTarget(""), ReturnTable.VOTABLE);
108 String adql = Adql074Writer.makeAdql(testQuery);
109 String votable = server.askAdql(DomHelper.newDocument(adql).getDocumentElement(), ReturnTable.VOTABLE);
110 assertNotNull(votable);
111 }
112
113 /*** Checks that we can submit a count query with ADQL through the AxisDataService c*/
114 public void testAxisServiceClassCount() throws Throwable {
115
116 AxisDataService_v06 server = new AxisDataService_v06();
117 Query testQuery = makeTestQuery(TargetMaker.makeTarget(""), ReturnTable.VOTABLE);
118 String adql = Adql074Writer.makeAdql(testQuery);
119 long count = server.askCount(DomHelper.newDocument(adql).getDocumentElement());
120 }
121
122 /*** Checks that we can a cone search, which only really applies to sky services... */
123 public void testCone() throws Throwable {
124
125
126 String endpoint = ServletHelper.getUrlStem()+"/SubmitCone";
127
128 NvoConeSearcher searcher = new NvoConeSearcher(endpoint);
129
130 InputStream is = searcher.coneSearch(30, -80, 0.1);
131
132 assertNotNull(is);
133 }
134
135 /*** Checks that we can reach the SOAP service
136 public void testSoapv06() throws Throwable {
137
138 //this test is called as a servlet, so get url stem from servlet context
139 String endpoint = ServletHelper.getUrlStem()+"/services/AxisDataService05";
140
141
142 InputStream is = new URL(endpoint).openStream();
143
144 assertNotNull(is);
145 }
146
147 /** Checks that the SkyNode interface works OK using the generated SkyNode
148 * binding *
149 public void testSkyNodeAxisBinding() throws Throwable {
150
151 //this test is called as a servlet, so get url stem from servlet context
152 String endpoint = ServletHelper.getUrlStem()+"/services/SkyNode074";
153
154 //make the query - a cone search around the south pole
155 if (ConfigFactory.getCommonConfig().getString(StdSqlWriter.CONE_SEARCH_DEC_COL_KEY, null) == null) {
156 fail("Would test using a search on DEC, but "+StdSqlWriter.CONE_SEARCH_DEC_COL_KEY+" and/or "+StdSqlWriter.CONE_SEARCH_TABLE_KEY+" is not set");
157 }
158 SelectType adql = new SelectType();
159 //select
160 adql.setSelectionList(new SelectionListType());
161 adql.getSelectionList().setItem(new SelectionItemType[] { new AllSelectionItemType() });
162
163 //from
164 FromType from = new FromType();
165 TableType fromTable = new TableType();
166 fromTable.setName(ConfigFactory.getCommonConfig().getString(StdSqlWriter.CONE_SEARCH_TABLE_KEY));
167 fromTable.setAlias(ConfigFactory.getCommonConfig().getString(StdSqlWriter.CONE_SEARCH_TABLE_KEY));
168 from.setTable(new FromTableType[] { fromTable});
169 adql.setFrom(from);
170
171
172 adql.setWhere(new WhereType());
173 ComparisonPredType comp = new ComparisonPredType();
174 comp.setArg(new ScalarExpressionType[2]);
175 adql.getWhere().setCondition(comp);
176 ColumnReferenceType decCol = new ColumnReferenceType();
177 decCol.setName(ConfigFactory.getCommonConfig().getString(StdSqlWriter.CONE_SEARCH_DEC_COL_KEY));
178 decCol.setTable(ConfigFactory.getCommonConfig().getString(StdSqlWriter.CONE_SEARCH_TABLE_KEY));
179 comp.setArg(0, decCol);
180 AtomType decValue = new AtomType();
181 decValue.setLiteral(new RealType());
182 ((RealType) decValue.getLiteral()).setValue(-89.5);
183 comp.setArg(1, decValue);
184 comp.setComparison(ComparisonType.fromValue("<"));
185
186 //construct SOAP client
187 SkyNodeSoap skyNodeClient = new SkyNodeLocator().getSkyNodeSoap(new URL(endpoint));
188
189 //make call
190 VOData vodata = skyNodeClient.performQuery(adql, "VOTABLE");
191
192 //check results
193 assertNotNull(vodata);
194 }
195 */
196
197
198 /*** Would check the CEA Interface, but the CEA stuff is very clever and so
199 completely obscure for all practical purposes *
200 public void testCea() throws IOException {
201 new DatacenterApplication();
202 }
203 */
204
205 /*** Checks that the CEA interface works OK. Except that again CEA wouldn't be
206 * straightforward to use like any other SOAP service, oh no.
207 public void testCeaSoapBinding() throws Throwable {
208
209
210 //construct SOAP client
211 SkyNodeSoap skyNodeClient = new SkyNodeLocator().getSkyNodeSoap(new URL(endpoint));
212
213 //make call
214 VOData vodata = skyNodeClient.performQuery(adql, "VOTABLE");
215
216 //check results
217 assertNotNull(vodata);
218 }
219 */
220
221 /***
222 * Checks metadata is OK
223 */
224 public void testMetadata() throws IOException {
225 VoDescriptionServer.getVoDescription();
226 }
227
228 /*** For running standalone, so it can be used from an IDE for quick tests against services */
229 public static void main(String[] args) {
230
231 ConfigFactory.getCommonConfig().setProperty(QuerierPluginFactory.QUERIER_PLUGIN_KEY, SssImagePlugin.class.getName());
232 ServletHelper.setUrlStem("http://grendel12.roe.ac.uk:8080/pal-sss");
233
234
235 junit.textui.TestRunner.run(InstallationSelfCheck.class);
236 }
237 }
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254