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