1 /*$Id: FitsQuerierTest.java,v 1.9 2005/03/21 18:45:55 mch Exp $
2 *
3 * Copyright (C) AstroGrid. All rights reserved.
4 *
5 * This software is published under the terms of the AstroGrid
6 * Software License version 1.2, a copy of which has been included
7 * with this distribution in the LICENSE.txt file.
8 *
9 **/
10 package org.astrogrid.datacenter.queriers.fits;
11
12 import java.io.File;
13 import java.io.FileWriter;
14 import java.io.IOException;
15 import java.io.StringWriter;
16 import java.net.URISyntaxException;
17 import junit.framework.Test;
18 import junit.framework.TestCase;
19 import junit.framework.TestSuite;
20 import org.astrogrid.account.LoginAccount;
21 import org.astrogrid.cfg.ConfigFactory;
22 import org.astrogrid.datacenter.fits.FitsTestSupport;
23 import org.astrogrid.dataservice.queriers.Querier;
24 import org.astrogrid.dataservice.queriers.QuerierPluginFactory;
25 import org.astrogrid.fitsserver.fits.FitsQuerierPlugin;
26 import org.astrogrid.fitsserver.setup.IndexGenerator;
27 import org.astrogrid.query.SimpleQueryMaker;
28 import org.astrogrid.query.adql.AdqlQueryMaker;
29 import org.astrogrid.query.returns.ReturnTable;
30 import org.astrogrid.slinger.targets.NullTarget;
31 import org.astrogrid.slinger.targets.TargetMaker;
32 import org.astrogrid.xmldb.client.XMLDBFactory;
33 import org.w3c.dom.Document;
34 import org.astrogrid.xml.DomHelper;
35 import java.io.*;
36 import org.xmldb.api.base.Collection;
37
38 /*** Test the Fits processing classes
39 */
40 public class FitsQuerierTest extends TestCase
41 {
42 private static boolean uploadedFiles = false;
43 private static boolean registeredDB = false;
44
45 public FitsQuerierTest() {
46
47 }
48
49 public static void upload(String collName, org.w3c.dom.Node doc) {
50 XMLDBFactory xdb2 = new XMLDBFactory();
51 Collection coll = null;
52 try {
53 coll = xdb2.openAdminCollection(FitsQuerierPlugin.FITS_DEFAULT_COLLECTION + "/" + collName);
54 xdb2.storeXMLResource(coll,doc);
55 }catch(Exception e) {
56 e.printStackTrace();
57 }finally {
58 try {
59 xdb2.closeCollection(coll);
60 }catch(Exception e1) {
61 e1.printStackTrace();
62 }
63 }
64 }
65
66 public void setUp() throws Exception {
67 super.setUp();
68 System.out.println("Try to find exist.xml");
69 ConfigFactory.getCommonConfig().setProperty("xmldb.uri", "xmldb:exist://");
70 ConfigFactory.getCommonConfig().setProperty("xmldb.driver", "org.exist.xmldb.DatabaseImpl");
71 ConfigFactory.getCommonConfig().setProperty("xmldb.query.service", "XQueryService");
72 ConfigFactory.getCommonConfig().setProperty("xmldb.admin.user", "admin");
73 ConfigFactory.getCommonConfig().setProperty("xmldb.admin.password", "");
74 if(!registeredDB) {
75 File fi = new File("target/test-classes/exist.xml");
76 System.out.println("Got the File now try to register the db");
77 if(fi != null) {
78 XMLDBFactory.registerDB(fi.getAbsolutePath());
79 }
80 System.out.println("database registered now set the query plugin");
81 registeredDB = true;
82 }//if
83 ConfigFactory.getCommonConfig().setProperty(QuerierPluginFactory.QUERIER_PLUGIN_KEY, FitsQuerierPlugin.class.getName());
84
85
86 if(!uploadedFiles) {
87 System.out.println("plug in set now try out upload sample fits file");
88 Document fitsFile = askQueryFromFile("SampleFits.xml");
89 System.out.println("Got xml sample document now upload to exist db");
90 System.out.println("the fitsFile = " + DomHelper.DocumentToString(fitsFile));
91 upload("CDSDataTest",fitsFile);
92 uploadedFiles = true;
93 }
94 }
95
96 /*** Check to see the right plugin is made */
97 public void testPluginClass() throws IOException, IOException, URISyntaxException {
98 System.out.println("entered testPlugin");
99 //Querier querier = Querier.makeQuerier(LoginAccount.ANONYMOUS, SimpleQueryMaker.makeConeQuery(300, 60, 12, new NullTarget(), ReturnTable.VOTABLE), this);
100
101 //assertTrue("Plugin '"+querier.getPlugin()+"' not FitsQuerierPlugin", querier.getPlugin() instanceof FitsQuerierPlugin);
102 }
103
104 public void testQuery() throws Exception
105 {
106 System.out.println("entered testQuery");
107
108 Document doc = askQueryFromFile("ADQLQueryForFits1.xml");
109 StringWriter sw = new StringWriter();
110 Querier querier = Querier.makeQuerier(LoginAccount.ANONYMOUS, AdqlQueryMaker.makeQuery(doc.getDocumentElement(), TargetMaker.makeTarget(sw), ReturnTable.VOTABLE), this);
111 querier.ask();
112 String results = sw.toString();
113 System.out.println("THE RESULTS OF QUERY = " + results);
114 }
115
116 protected Document askQueryFromFile(String queryFile) throws Exception {
117 System.out.println("entered askQueryFromFile");
118
119 assertNotNull(queryFile);
120 InputStream is = this.getClass().getResourceAsStream(queryFile);
121
122 assertNotNull("Could not open query file :" + queryFile,is);
123 Document queryDoc = DomHelper.newDocument(is);
124
125 //Document queryDoc = DomHelper.newDocument(new File(queryFile));
126 return queryDoc;
127 }
128
129
130
131 public static Test suite()
132 {
133 // Reflection is used here to add all the testXXX() methods to the suite.
134 return new TestSuite(FitsQuerierTest.class);
135 }
136
137
138 /***
139 * Runs the test case.
140 */
141
142 public static void main(String args[]) throws IOException
143 {
144 junit.textui.TestRunner.run(suite());
145 }
146
147
148 }
149
150
151 /*
152 $Log: FitsQuerierTest.java,v $
153 Revision 1.9 2005/03/21 18:45:55 mch
154 Naughty big lump of changes
155
156 Revision 1.8 2005/03/11 14:50:59 KevinBenson
157 added catch for parserconfigurationexception
158
159 Revision 1.7 2005/03/10 16:42:55 mch
160 Split fits, sql and xdb
161
162 Revision 1.6 2005/03/10 14:01:35 KevinBenson
163 new test for FitsQuerier
164
165 Revision 1.4 2005/03/08 15:03:24 KevinBenson
166 new stuff for Fits querier to work with an internal xml database
167
168 Revision 1.3 2005/02/28 19:36:39 mch
169 Fixes to tests
170
171 Revision 1.2 2005/02/28 18:47:05 mch
172 More compile fixes
173
174 Revision 1.1.1.1 2005/02/17 18:37:35 mch
175 Initial checkin
176
177 Revision 1.1.1.1 2005/02/16 17:11:25 mch
178 Initial checkin
179
180 Revision 1.8.2.3 2004/11/29 21:52:18 mch
181 Fixes to skynode, log.error(), getstem, status logger, etc following tests on grendel
182
183 Revision 1.8.2.2 2004/11/23 11:55:06 mch
184 renamved makeTarget methods
185
186 Revision 1.8.2.1 2004/11/22 00:57:16 mch
187 New interfaces for SIAP etc and new slinger package
188
189 Revision 1.8 2004/11/11 20:42:50 mch
190 Fixes to Vizier plugin, introduced SkyNode, started SssImagePlugin
191
192 Revision 1.7 2004/11/09 17:42:22 mch
193 Fixes to tests after fixes for demos, incl adding closable to targetIndicators
194
195 Revision 1.6 2004/11/03 00:17:56 mch
196 PAL_MCH Candidate 2 merge
197
198 Revision 1.5.6.1 2004/11/02 19:41:26 mch
199 Split TargetIndicator to indicator and maker
200
201 Revision 1.5 2004/10/18 13:11:30 mch
202 Lumpy Merge
203
204 Revision 1.4.2.2 2004/10/16 14:35:53 mch
205 Forwardable null targets
206
207 Revision 1.4.2.1 2004/10/15 19:59:06 mch
208 Lots of changes during trip to CDS to improve int test pass rate
209
210 Revision 1.4 2004/10/08 17:14:23 mch
211 Clearer separation of metadata and querier plugins, and improvements to VoResource plugin mechanisms
212
213 Revision 1.3 2004/10/07 10:34:44 mch
214 Fixes to Cone maker functions and reading/writing String comparisons from Query
215
216 Revision 1.2 2004/10/06 21:12:17 mch
217 Big Lump of changes to pass Query OM around instead of Query subclasses, and TargetIndicator mixed into Slinger
218
219 Revision 1.1 2004/09/28 15:11:33 mch
220 Moved server test directory to pal
221
222 Revision 1.22 2004/09/08 17:51:49 mch
223 Fixes to log and metadata views
224
225 Revision 1.21 2004/09/01 12:10:58 mch
226 added results.toHtml
227
228 Revision 1.20 2004/08/25 23:38:34 mch
229 (Days changes) moved many query- and results- related classes, renamed packages, added tests, added CIRCLE to sql/adql parsers
230
231 Revision 1.19 2004/08/19 08:32:48 mch
232 Fix to target indicator
233
234 Revision 1.18 2004/08/18 21:36:28 mch
235 Added better error msg
236
237 Revision 1.17 2004/08/18 18:44:12 mch
238 Created metadata plugin service and added helper methods
239
240 Revision 1.16 2004/08/17 20:19:36 mch
241 Moved TargetIndicator to client
242
243 Revision 1.15 2004/03/14 04:13:16 mch
244 Wrapped output target in TargetIndicator
245
246 Revision 1.14 2004/03/13 23:38:56 mch
247 Test fixes and better front-end JSP access
248
249 Revision 1.13 2004/03/12 20:11:09 mch
250 It05 Refactor (Client)
251
252 Revision 1.12 2004/03/12 04:54:06 mch
253 It05 MCH Refactor
254
255 Revision 1.11 2004/03/09 21:05:57 mch
256 Removed hugely long Fits tests
257
258 Revision 1.10 2004/03/08 15:58:26 mch
259 Fixes to ensure old ADQL interface works alongside new one and with old plugins
260
261 Revision 1.9 2004/03/08 00:31:28 mch
262 Split out webservice implementations for versioning
263
264 Revision 1.8 2004/02/24 16:03:48 mch
265 Config refactoring and moved datacenter It04.1 VoSpaceStuff to myspace StoreStuff
266
267 Revision 1.7 2004/02/16 23:07:05 mch
268 Moved DummyQueriers to std server and switched to AttomConfig
269
270 Revision 1.6 2004/01/23 11:14:09 nw
271 altered to extend org.astrogrid.test.OptionalTestCase -
272 means that these tests can be disabled as needed
273
274 Revision 1.5 2004/01/14 16:00:13 nw
275 tidied up switching out long tests.
276
277 Revision 1.4 2004/01/13 00:33:14 nw
278 Merged in branch providing
279 * sql pass-through
280 * replace Certification by User
281 * Rename _query as Query
282
283 Revision 1.3.6.2 2004/01/08 09:43:40 nw
284 replaced adql front end with a generalized front end that accepts
285 a range of query languages (pass-thru sql at the moment)
286
287 Revision 1.3.6.1 2004/01/07 13:02:09 nw
288 removed Community object, now using User object from common
289
290 Revision 1.3 2003/12/03 19:37:03 mch
291 Introduced DirectDelegate, fixed DummyQuerier
292
293 Revision 1.2 2003/12/01 20:58:42 mch
294 Abstracting coarse-grained plugin
295
296 Revision 1.1 2003/11/28 20:00:24 mch
297 Added cone search test
298
299
300 */