voruby 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. data/LICENSE +339 -0
  2. data/REQUIREMENTS +4 -0
  3. data/Rakefile.rb +296 -0
  4. data/lib/voruby/adql/adql.rb +2735 -0
  5. data/lib/voruby/adql/ext.rb +15 -0
  6. data/lib/voruby/adql/loader.rb +5 -0
  7. data/lib/voruby/adql/operations.rb +54 -0
  8. data/lib/voruby/adql/parser.rb +160 -0
  9. data/lib/voruby/adql/transforms.rb +573 -0
  10. data/lib/voruby/ext.rb +17 -0
  11. data/lib/voruby/loader.rb +4 -0
  12. data/lib/voruby/misc/propertyfile.rb +36 -0
  13. data/lib/voruby/plastic/applications.rb +174 -0
  14. data/lib/voruby/plastic/constants.rb +30 -0
  15. data/lib/voruby/plastic/loader.rb +10 -0
  16. data/lib/voruby/plastic/plastic.rb +1 -0
  17. data/lib/voruby/resources/conesearch/conesearch.rb +9 -0
  18. data/lib/voruby/resources/conesearch/conesearch_v0_2.rb +55 -0
  19. data/lib/voruby/resources/conesearch/conesearch_v0_3.rb +50 -0
  20. data/lib/voruby/resources/conesearch/conesearch_v1_0.rb +72 -0
  21. data/lib/voruby/resources/conesearch/loader.rb +4 -0
  22. data/lib/voruby/resources/loader.rb +50 -0
  23. data/lib/voruby/resources/nodes.rb +190 -0
  24. data/lib/voruby/resources/openskynode/loader.rb +4 -0
  25. data/lib/voruby/resources/openskynode/openskynode.rb +9 -0
  26. data/lib/voruby/resources/openskynode/openskynode_v0_1.rb +54 -0
  27. data/lib/voruby/resources/sia/loader.rb +5 -0
  28. data/lib/voruby/resources/sia/sia.rb +9 -0
  29. data/lib/voruby/resources/sia/sia_v0_6.rb +90 -0
  30. data/lib/voruby/resources/sia/sia_v0_7.rb +89 -0
  31. data/lib/voruby/resources/sia/sia_v1_0.rb +122 -0
  32. data/lib/voruby/resources/stsci.rb +59 -0
  33. data/lib/voruby/resources/vodataservice/coverage_v0_2.rb +195 -0
  34. data/lib/voruby/resources/vodataservice/coverage_v0_3.rb +158 -0
  35. data/lib/voruby/resources/vodataservice/loader.rb +5 -0
  36. data/lib/voruby/resources/vodataservice/vodataservice.rb +9 -0
  37. data/lib/voruby/resources/vodataservice/vodataservice_v0_4.rb +189 -0
  38. data/lib/voruby/resources/vodataservice/vodataservice_v0_5.rb +163 -0
  39. data/lib/voruby/resources/vodataservice/vodataservice_v1_0.rb +221 -0
  40. data/lib/voruby/resources/voregistry/loader.rb +4 -0
  41. data/lib/voruby/resources/voregistry/voregistry.rb +9 -0
  42. data/lib/voruby/resources/voregistry/voregistry_v0_2.rb +40 -0
  43. data/lib/voruby/resources/voregistry/voregistry_v0_3.rb +30 -0
  44. data/lib/voruby/resources/voregistry/voregistry_v1_0.rb +86 -0
  45. data/lib/voruby/resources/voresource/loader.rb +17 -0
  46. data/lib/voruby/resources/voresource/voresource.rb +9 -0
  47. data/lib/voruby/resources/voresource/voresource_v0_10.rb +322 -0
  48. data/lib/voruby/resources/voresource/voresource_v0_9.rb +405 -0
  49. data/lib/voruby/resources/voresource/voresource_v1_0.rb +230 -0
  50. data/lib/voruby/services/ext.rb +11 -0
  51. data/lib/voruby/services/gestalt/footprint.rb +95 -0
  52. data/lib/voruby/services/gestalt/wcs_fixer.rb +105 -0
  53. data/lib/voruby/services/gestalt/wesix.rb +155 -0
  54. data/lib/voruby/services/loader.rb +7 -0
  55. data/lib/voruby/services/registry/registry.rb +53 -0
  56. data/lib/voruby/services/resolver/resolver.rb +35 -0
  57. data/lib/voruby/sesame/loader.rb +6 -0
  58. data/lib/voruby/sesame/sesame_v1_0.rb +64 -0
  59. data/lib/voruby/simple/loader.rb +6 -0
  60. data/lib/voruby/simple/parameters.rb +196 -0
  61. data/lib/voruby/simple/sap.rb +446 -0
  62. data/lib/voruby/spacetime/loader.rb +3 -0
  63. data/lib/voruby/spacetime/spacetime.rb +607 -0
  64. data/lib/voruby/stc/coords_v1_20.rb +900 -0
  65. data/lib/voruby/stc/loader.rb +55 -0
  66. data/lib/voruby/stc/region_v1_20.rb +274 -0
  67. data/lib/voruby/stc/stc_v1_20.rb +1196 -0
  68. data/lib/voruby/util.rb +27 -0
  69. data/lib/voruby/voevent/loader.rb +7 -0
  70. data/lib/voruby/voevent/voevent_v1_0.rb +213 -0
  71. data/lib/voruby/voevent/voevent_v1_1.rb +196 -0
  72. data/lib/voruby/votables/chandra.rb +410 -0
  73. data/lib/voruby/votables/cnoc.rb +393 -0
  74. data/lib/voruby/votables/data.rb +179 -0
  75. data/lib/voruby/votables/galex.rb +390 -0
  76. data/lib/voruby/votables/hst.rb +391 -0
  77. data/lib/voruby/votables/int.rb +391 -0
  78. data/lib/voruby/votables/libxml_parser.rb +411 -0
  79. data/lib/voruby/votables/libxml_votable.rb +67 -0
  80. data/lib/voruby/votables/loader.rb +10 -0
  81. data/lib/voruby/votables/meta.rb +763 -0
  82. data/lib/voruby/votables/misc.rb +51 -0
  83. data/lib/voruby/votables/nsa.rb +393 -0
  84. data/lib/voruby/votables/nsar3.rb +410 -0
  85. data/lib/voruby/votables/rexml_parser.rb +408 -0
  86. data/lib/voruby/votables/rexml_votable.rb +67 -0
  87. data/lib/voruby/votables/sdss.rb +393 -0
  88. data/lib/voruby/votables/transforms.rb +388 -0
  89. data/lib/voruby/votables/tree.rb +45 -0
  90. data/lib/voruby/votables/types.rb +391 -0
  91. data/lib/voruby/votables/votable.rb +630 -0
  92. data/lib/voruby/votables/xmm.rb +394 -0
  93. data/test/adql/test1.adql +49 -0
  94. data/test/adql/test2.adql +51 -0
  95. data/test/adql/test3.adql +81 -0
  96. data/test/adql/test4.adql +53 -0
  97. data/test/adql/test5.adql +55 -0
  98. data/test/adql/test6.adql +18 -0
  99. data/test/adql/test7.adql +48 -0
  100. data/test/adql/unittest.rb +1672 -0
  101. data/test/plastic/test.rb +44 -0
  102. data/test/plastic/test.vot +5385 -0
  103. data/test/plastic/unittest.rb +66 -0
  104. data/test/resources/conesearch/conesearch_v0_3.xml +31 -0
  105. data/test/resources/conesearch/conesearch_v1_0.xml +86 -0
  106. data/test/resources/conesearch/unittest_v0_3.rb +22 -0
  107. data/test/resources/conesearch/unittest_v1_0.rb +24 -0
  108. data/test/resources/openskynode/open_sky_node_v0_1.xml +32 -0
  109. data/test/resources/openskynode/unittest_v0_1.rb +31 -0
  110. data/test/resources/sia/simple_image_access_v0_7.xml +36 -0
  111. data/test/resources/sia/simple_image_access_v1_0.xml +122 -0
  112. data/test/resources/sia/unittest_v0_7.rb +24 -0
  113. data/test/resources/sia/unittest_v1_0.rb +29 -0
  114. data/test/resources/stsci.xml +336 -0
  115. data/test/resources/unittest_stsci.rb +25 -0
  116. data/test/resources/vodataservice/catalog_service_resource_v1_0.xml +128 -0
  117. data/test/resources/vodataservice/data_collection_resource_v0_5.xml +54 -0
  118. data/test/resources/vodataservice/data_collection_resource_v1_0.xml +117 -0
  119. data/test/resources/vodataservice/data_service_resource_v1_0.xml +115 -0
  120. data/test/resources/vodataservice/sky_service_resource_v0_10.xml +45 -0
  121. data/test/resources/vodataservice/table_service_resource_v1_0.xml +122 -0
  122. data/test/resources/vodataservice/tabular_sky_service_resource_v0_10.xml +60 -0
  123. data/test/resources/vodataservice/unittest_v0_5.rb +126 -0
  124. data/test/resources/vodataservice/unittest_v1_0.rb +151 -0
  125. data/test/resources/voregistry/authority_resource_v0_3.xml +20 -0
  126. data/test/resources/voregistry/authority_resource_v1_0.xml +82 -0
  127. data/test/resources/voregistry/registry_service_v0_3.xml +20 -0
  128. data/test/resources/voregistry/registry_service_v1_0.xml +107 -0
  129. data/test/resources/voregistry/unittest_v0_3.rb +31 -0
  130. data/test/resources/voregistry/unittest_v1_0.rb +34 -0
  131. data/test/resources/voresource/organisation_resource_v1_0.xml +90 -0
  132. data/test/resources/voresource/resource_organisation_v0_10.xml +22 -0
  133. data/test/resources/voresource/resource_service_v0_10.xml +19 -0
  134. data/test/resources/voresource/resource_v0_10.xml +19 -0
  135. data/test/resources/voresource/resource_v1_0.xml +79 -0
  136. data/test/resources/voresource/service_resource_v1_0.xml +91 -0
  137. data/test/resources/voresource/unittest_v0_10.rb +61 -0
  138. data/test/resources/voresource/unittest_v0_9.rb +4 -0
  139. data/test/resources/voresource/unittest_v1_0.rb +190 -0
  140. data/test/services/gestalt/unittest.rb +74 -0
  141. data/test/services/registry/unittest.rb +34 -0
  142. data/test/services/resolver/unittest.rb +38 -0
  143. data/test/simple/unittest.rb +46 -0
  144. data/test/spacetime/unittest.rb +39 -0
  145. data/test/stc/catalog_entry_location_v1_20.xml +112 -0
  146. data/test/stc/obs_data_location_v1_20.xml +108 -0
  147. data/test/stc/search_location_v1_20.xml +54 -0
  148. data/test/stc/stc_resource_profile_v1_20.xml +60 -0
  149. data/test/stc/unittest_v1_20.rb +620 -0
  150. data/test/voevent/unittest_v1_0.rb +79 -0
  151. data/test/voevent/unittest_v1_1.rb +70 -0
  152. data/test/voevent/voevent_v1_0.xml +96 -0
  153. data/test/voevent/voevent_v1_1.xml +76 -0
  154. data/test/votables/test.vot +366 -0
  155. data/test/votables/unittest.rb +54 -0
  156. metadata +256 -0
@@ -0,0 +1,1672 @@
1
+ require 'test/unit'
2
+ require 'voruby/adql/parser'
3
+
4
+ include VORuby::ADQL
5
+
6
+ class ScalarExpressionTest < Test::Unit::TestCase
7
+ def setup
8
+ @exp = ScalarExpression.new('A string')
9
+ end
10
+
11
+ def test_to_adqls
12
+ assert_equal('A string', @exp.to_adqls)
13
+ end
14
+ end
15
+
16
+ class ClosedExprTest < Test::Unit::TestCase
17
+ def setup
18
+ @exp = ClosedExpr.new(Atom.new(12.5))
19
+ end
20
+
21
+ def test_to_adqls
22
+ assert_equal('(12.5)', @exp.to_adqls)
23
+ end
24
+ end
25
+
26
+ class BinaryOperatorTest < Test::Unit::TestCase
27
+ def test_construct
28
+ assert_raise(RuntimeError) {
29
+ op = BinaryOperator.new('^')
30
+ }
31
+
32
+ assert_nothing_raised {
33
+ op = BinaryOperator.new('+')
34
+ }
35
+
36
+ assert_nothing_raised {
37
+ op = BinaryOperator.new('//', ['//', '+', '-'])
38
+ }
39
+
40
+ assert_raise(RuntimeError){
41
+ op = BinaryOperator.new('\\', ['//', '+', '-'])
42
+ }
43
+ end
44
+
45
+ def test_to_adqls
46
+ op = BinaryOperator.new('*')
47
+ assert_equal('*', op.to_adqls)
48
+ end
49
+ end
50
+
51
+ class BinaryExprTest < Test::Unit::TestCase
52
+ def test_construct
53
+ assert_nothing_raised {
54
+ expr = BinaryExpr.new('a', '+', 'b')
55
+ }
56
+
57
+ assert_raise(RuntimeError){
58
+ expr = BinaryExpr.new('a', '++', 'b')
59
+ }
60
+ end
61
+
62
+ def test_to_adqls
63
+ expr = BinaryExpr.new('a', '+', 'b')
64
+ assert_equal('a + b', expr.to_adqls)
65
+ end
66
+ end
67
+
68
+ class UnaryOperatorTest < Test::Unit::TestCase
69
+ def test_construct
70
+ assert_raise(RuntimeError) {
71
+ op = UnaryOperator.new('++')
72
+ }
73
+
74
+ assert_nothing_raised {
75
+ op = UnaryOperator.new('+')
76
+ }
77
+
78
+ assert_nothing_raised {
79
+ op = BinaryOperator.new('++', ['++', '--'])
80
+ }
81
+
82
+ assert_raise(RuntimeError){
83
+ op = BinaryOperator.new('==', ['++', '--'])
84
+ }
85
+ end
86
+
87
+ def test_to_adqls
88
+ op = BinaryOperator.new('+')
89
+ assert_equal('+', op.to_adqls)
90
+ end
91
+ end
92
+
93
+ class UnaryExprTest < Test::Unit::TestCase
94
+ def test_construct
95
+ assert_nothing_raised {
96
+ expr = UnaryExpr.new('-', 'a.ra')
97
+ }
98
+
99
+ assert_raise(RuntimeError){
100
+ expr = UnaryExpr.new('++', 'a.ra')
101
+ }
102
+ end
103
+
104
+ def test_to_adqls
105
+ assert_equal('-a.ra', UnaryExpr.new('-', 'a.ra').to_adqls)
106
+ end
107
+ end
108
+
109
+ class ColumnReferenceTest < Test::Unit::TestCase
110
+ def setup
111
+ @ref = ColumnReference.new('o', 'objid')
112
+ end
113
+
114
+ def test_to_adqls
115
+ assert_equal('o.objid', @ref.to_adqls)
116
+ end
117
+ end
118
+
119
+ class AtomTest < Test::Unit::TestCase
120
+ def setup
121
+ @real_literal = 1.0
122
+ @int_literal = 2
123
+ @string_literal = 'a'
124
+ end
125
+
126
+ def test_construct
127
+ assert_nothing_raised {
128
+ atom = Atom.new(@real_literal, 'cm')
129
+ atom = Atom.new(@int_literal)
130
+ atom = Atom.new(@string_literal)
131
+ }
132
+ end
133
+
134
+ def test_to_adqls
135
+ assert_equal('5cm', Atom.new(5, 'cm').to_adqls)
136
+ assert_equal('100.0', Atom.new(100.0).to_adqls)
137
+ assert_equal('\'a\'', Atom.new('a').to_adqls)
138
+ end
139
+ end
140
+
141
+ class LiteralTypeTest < Test::Unit::TestCase
142
+ def setup
143
+ real_xml = '<Literal xsi:type="realType" Value="10.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'
144
+ int_xml = '<Literal xsi:type="integerType" Value="10" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'
145
+ string_xml = '<Literal xsi:type="stringType" Value="ten" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'
146
+ @real_doc = REXML::Document.new(real_xml)
147
+ @int_doc = REXML::Document.new(int_xml)
148
+ @string_doc = REXML::Document.new(string_xml)
149
+ end
150
+
151
+ def test_from_xml
152
+ assert_nothing_raised {
153
+ literal = LiteralType.from_xml(@real_doc.root)
154
+ literal = LiteralType.from_xml(@int_doc.root)
155
+ literal = LiteralType.from_xml(@string_doc.root)
156
+ }
157
+ end
158
+
159
+ def test_to_adql
160
+ assert_equal('10.0', LiteralType.from_xml(@real_doc.root).to_adqls)
161
+ assert_equal('10', LiteralType.from_xml(@int_doc.root).to_adqls)
162
+ assert_equal('ten', LiteralType.from_xml(@string_doc.root).to_adqls)
163
+ end
164
+ end
165
+
166
+ class RealTypeTest < Test::Unit::TestCase
167
+ def setup
168
+ @float = RealType.new(3.14159)
169
+ end
170
+
171
+ def test_construct
172
+ assert_raise(VORuby::VOTables::VOTable::Misc::TypeException){
173
+ float = RealType.new('5')
174
+ }
175
+ end
176
+
177
+ def test_equal
178
+ assert_equal(3.14159, @float.value)
179
+ end
180
+
181
+ def test_to_adqls
182
+ assert_equal('3.14159', @float.to_adqls)
183
+ end
184
+ end
185
+
186
+ class IntegerTypeTest < Test::Unit::TestCase
187
+ def setup
188
+ @int = IntegerType.new(7)
189
+ end
190
+
191
+ def test_construct
192
+ assert_raise(VORuby::VOTables::VOTable::Misc::TypeException){
193
+ int = IntegerType.new(5.0)
194
+ }
195
+ end
196
+
197
+ def test_equal
198
+ assert_equal(7, @int.value)
199
+ end
200
+
201
+ def test_to_adqls
202
+ assert_equal('7', @int.to_adqls)
203
+ end
204
+ end
205
+
206
+ class StringTypeTest < Test::Unit::TestCase
207
+ def setup
208
+ @string = StringType.new('test string')
209
+ end
210
+
211
+ def test_construct
212
+ assert_raise(VORuby::VOTables::VOTable::Misc::TypeException){
213
+ string = StringType.new(3.1)
214
+ }
215
+ end
216
+
217
+ def test_equal
218
+ assert_equal('test string', @string.value)
219
+ end
220
+
221
+ def test_to_adqls
222
+ assert_equal('test string', @string.to_adqls)
223
+ end
224
+ end
225
+
226
+ class SelectionOptionTest < Test::Unit::TestCase
227
+ def test_construct
228
+ assert_nothing_raised {
229
+ sel_op = SelectionOption.new('ALL')
230
+ }
231
+
232
+ assert_raise(RuntimeError){
233
+ sel_op = SelectionOption.new('NEW')
234
+ }
235
+ end
236
+
237
+ def test_to_adqls
238
+ assert_equal('DISTINCT', SelectionOption.new('DISTINCT').to_adqls)
239
+ end
240
+ end
241
+
242
+ class AllOrDistinctTest < Test::Unit::TestCase
243
+ def test_construct
244
+ assert_nothing_raised {
245
+ all_dis = AllOrDistinct.new('ALL')
246
+ all_dis = AllOrDistinct.new('NEW', ['ALL', 'DISTINCT', 'NEW'])
247
+ }
248
+
249
+ assert_raise(RuntimeError){
250
+ all_dis = AllOrDistinct.new('NEW')
251
+ }
252
+ end
253
+
254
+ def test_to_adqls
255
+ assert_equal('DISTINCT', AllOrDistinct.new('DISTINCT').to_adqls)
256
+ end
257
+ end
258
+
259
+ class TrigonometricFunctionNameTest < Test::Unit::TestCase
260
+ def test_construct
261
+ assert_nothing_raised {
262
+ trig = TrigonometricFunctionName.new('COT')
263
+ trig = TrigonometricFunctionName.new('ISIN', ['SIN', 'ASIN', 'ISIN'])
264
+ }
265
+
266
+ assert_raise(RuntimeError){
267
+ trig = TrigonometricFunctionName.new('ISIN')
268
+ }
269
+ end
270
+
271
+ def test_to_adqls
272
+ assert_equal('COT', TrigonometricFunctionName.new('COT').to_adqls)
273
+ end
274
+ end
275
+
276
+ class TrigonometricFunctionTest < Test::Unit::TestCase
277
+ def setup
278
+ @arg = ColumnReference.new('o', 'objid')
279
+ end
280
+
281
+ def test_construct
282
+ assert_nothing_raised {
283
+ trig_func = TrigonometricFunction.new('ASIN', @arg)
284
+ }
285
+
286
+ assert_raise(RuntimeError){
287
+ trig_func = TrigonometricFunction.new('NEW', @arg)
288
+ }
289
+ end
290
+
291
+ def test_to_adqls
292
+ assert_equal('ASIN(o.objid)', TrigonometricFunction.new('ASIN', @arg).to_adqls)
293
+ end
294
+ end
295
+
296
+ class MathFunctionNameTest < Test::Unit::TestCase
297
+ def test_construct
298
+ assert_nothing_raised {
299
+ math = MathFunctionName.new('ABS')
300
+ math = MathFunctionName.new('GRAD', ['ABS', 'CEILING', 'GRAD'])
301
+ }
302
+
303
+ assert_raise(RuntimeError){
304
+ math = MathFunctionName.new('GRAD')
305
+ }
306
+ end
307
+
308
+ def test_to_adqls
309
+ assert_equal('ABS', MathFunctionName.new('ABS').to_adqls)
310
+ end
311
+ end
312
+
313
+ #class MathFunctionTest < Test::Unit::TestCase
314
+ #def test_construct
315
+ # assert_nothing_raised {
316
+ # math_func = MathFunction.new('ABS')
317
+ # }
318
+
319
+ # assert_raise (RuntimeError){
320
+ # math_func = TrigonometricFunction.new('NEW')
321
+ # }
322
+ #end
323
+
324
+ #def test_to_adqls
325
+ # assert_equal('ABS', MathFunction.new('ABS').to_adqls)
326
+ #end
327
+ #end
328
+
329
+ class AggregateFunctionNameTest < Test::Unit::TestCase
330
+ def test_construct
331
+ assert_nothing_raised {
332
+ agg = AggregateFunctionName.new('MAX')
333
+ agg = AggregateFunctionName.new('DISP', ['AVG', 'DISP', 'MIN'])
334
+ }
335
+
336
+ assert_raise(RuntimeError){
337
+ agg = AggregateFunctionName.new('DISP')
338
+ }
339
+ end
340
+
341
+ def test_to_adqls
342
+ assert_equal('COUNT', AggregateFunctionName.new('COUNT').to_adqls)
343
+ end
344
+ end
345
+
346
+ # class AggregateFunctionTest < Test::Unit::TestCase
347
+ # def test_construct
348
+ # assert_nothing_raised {
349
+ # agg_func = AggregateFunction.new('MAX')
350
+ # }
351
+
352
+ # assert_raise (RuntimeError){
353
+ # agg_func = AggregateFunction.new('NEW')
354
+ # }
355
+ # end
356
+
357
+ # def test_to_adqls
358
+ # assert_equal('SUM', AggregateFunction.new('SUM').to_adqls)
359
+ # end
360
+ # end
361
+
362
+ class AliasSelectionItemTest < Test::Unit::TestCase
363
+ def setup
364
+ @alias_sel1 = AliasSelectionItem.new('o.objid', 'ObjId')
365
+ @alias_sel2 = AliasSelectionItem.new('o.objid')
366
+ end
367
+
368
+ def test_to_adqls
369
+ assert_equal('o.objid AS ObjId', @alias_sel1.to_adqls)
370
+ assert_equal('o.objid', @alias_sel2.to_adqls)
371
+ end
372
+ end
373
+
374
+ class ComparisonTest < Test::Unit::TestCase
375
+ def test_construct
376
+ assert_nothing_raised {
377
+ comp = Comparison.new('<>')
378
+ comp = Comparison.new('()', ['<>', '=', '()'])
379
+ }
380
+
381
+ assert_raise(RuntimeError){
382
+ comp = Comparison.new('!')
383
+ }
384
+ end
385
+
386
+ def test_to_adqls
387
+ assert_equal('<>', Comparison.new('<>').to_adqls)
388
+ end
389
+ end
390
+
391
+ class ArchiveTableTest < Test::Unit::TestCase
392
+ def setup
393
+ @archive1 = ArchiveTable.new('SDSS', 'PhotoPrimary', 'o')
394
+ @archive2 = ArchiveTable.new('SDSS', 'PhotoPrimary')
395
+ end
396
+
397
+ def test_to_adqls
398
+ assert_equal('SDSS:PhotoPrimary o', @archive1.to_adqls)
399
+ assert_equal('SDSS:PhotoPrimary', @archive2.to_adqls)
400
+ end
401
+ end
402
+
403
+ class IncludeTableTest < Test::Unit::TestCase
404
+ def setup
405
+ @table = IncludeTable.new('o')
406
+ end
407
+
408
+ def test_to_adqls
409
+ assert_equal('o', @table.to_adqls)
410
+ end
411
+ end
412
+
413
+ class DropTableTest < Test::Unit::TestCase
414
+ def setup
415
+ @table = DropTable.new('o')
416
+ end
417
+
418
+ def test_to_adqls
419
+ assert_equal('!o', @table.to_adqls)
420
+ end
421
+ end
422
+
423
+ class IntersectionSearchTest < Test::Unit::TestCase
424
+ def setup
425
+ @tables = [IncludeTable.new('o'),
426
+ IncludeTable.new('t'),
427
+ DropTable.new('z')]
428
+ @cond1 = XMatch.new(@tables, '>=', 0.5)
429
+ @cond2 = XMatch.new(@tables, '<=', 1.1)
430
+ end
431
+
432
+ def test_construct
433
+ assert_nothing_raised {
434
+ search = IntersectionSearch.new(@cond1, @cond2)
435
+ }
436
+ end
437
+
438
+ def test_to_adqls
439
+ search = IntersectionSearch.new(@cond1, @cond2)
440
+ assert_equal("XMATCH(o, t, !z) >= 0.5 AND XMATCH(o, t, !z) <= 1.1",
441
+ search.to_adqls)
442
+ end
443
+ end
444
+
445
+ class UnionSearchTest < Test::Unit::TestCase
446
+ def setup
447
+ @tables = [IncludeTable.new('o'),
448
+ IncludeTable.new('t'),
449
+ DropTable.new('z')]
450
+ @cond1 = XMatch.new(@tables, '>=', 0.5)
451
+ @cond2 = XMatch.new(@tables, '<=', 1.1)
452
+ end
453
+
454
+ def test_construct
455
+ assert_nothing_raised {
456
+ search = UnionSearch.new(@cond1, @cond2)
457
+ }
458
+ end
459
+
460
+ def test_to_adqls
461
+ search = UnionSearch.new(@cond1, @cond2)
462
+ assert_equal("XMATCH(o, t, !z) >= 0.5 OR XMATCH(o, t, !z) <= 1.1",
463
+ search.to_adqls)
464
+ end
465
+ end
466
+
467
+ class XMatchTest < Test::Unit::TestCase
468
+ def setup
469
+ @tables = [IncludeTable.new('o'),
470
+ IncludeTable.new('t'),
471
+ DropTable.new('z')]
472
+ end
473
+
474
+ def test_construct
475
+ assert_nothing_raised {
476
+ xmatch = XMatch.new(@tables, '<=', 3.5)
477
+ xmatch = XMatch.new(@tables,
478
+ Comparison.new('<='),
479
+ RealType.new(3.5))
480
+ }
481
+ end
482
+
483
+ def test_to_adqls
484
+ xmatch = XMatch.new(@tables, '<=', 3.5)
485
+ assert_equal("XMATCH(o, t, !z) <= 3.5", xmatch.to_adqls)
486
+ end
487
+ end
488
+
489
+ class LikePredTest < Test::Unit::TestCase
490
+ def test_construct
491
+ assert_nothing_raised {
492
+ like = LikePred.new('name', '%my_name%')
493
+ }
494
+ end
495
+
496
+ def test_to_adqls
497
+ assert_equal('name LIKE \'%my_name%\'',
498
+ LikePred.new('name', '%my_name%').to_adqls)
499
+ end
500
+ end
501
+
502
+ class NotLikePredTest < Test::Unit::TestCase
503
+ def test_construct
504
+ assert_nothing_raised {
505
+ like = NotLikePred.new('name', '%my_name%')
506
+ }
507
+ end
508
+
509
+ def test_to_adqls
510
+ assert_equal('name NOT LIKE \'%my_name%\'',
511
+ NotLikePred.new('name', '%my_name%').to_adqls)
512
+ end
513
+ end
514
+
515
+ #class ExclusiveSearchTest < Test::Unit::TestCase; end
516
+
517
+ #class SubQuerySetTest < Test::Unit::TestCase; end
518
+
519
+ class ClosedSearchTest < Test::Unit::TestCase
520
+ def setup
521
+ @tables = [IncludeTable.new('o'),
522
+ IncludeTable.new('t'),
523
+ DropTable.new('z')]
524
+ @search = XMatch.new(@tables, '<=', 3.5)
525
+ end
526
+
527
+ def test_construct
528
+ assert_nothing_raised {
529
+ cs = ClosedSearch.new(@search)
530
+ }
531
+ end
532
+
533
+ def test_to_adqls
534
+ assert_equal('(XMATCH(o, t, !z) <= 3.5)',
535
+ ClosedSearch.new(@search).to_adqls)
536
+ end
537
+ end
538
+
539
+ class ComparisonPredTest < Test::Unit::TestCase
540
+ def setup
541
+ @cond1 = ColumnReference.new('PhotoPrimary', 'objid')
542
+ @cond2 = BinaryExpr.new('a', '+', 'b')
543
+ end
544
+
545
+ def test_construct
546
+ assert_nothing_raised {
547
+ cp = ComparisonPred.new(@cond1, '<>', @cond2)
548
+ }
549
+ end
550
+
551
+ def test_to_adqls
552
+ assert_equal('PhotoPrimary.objid <> a + b',
553
+ ComparisonPred.new(@cond1, '<>', @cond2).to_adqls)
554
+ end
555
+ end
556
+
557
+ class NotBetweenPredTest < Test::Unit::TestCase
558
+ def setup
559
+ @arg1 = ColumnReference.new('PhotoPrimary', 'objid')
560
+ @arg2 = UnaryExpr.new('-', 2)
561
+ @arg3 = UnaryExpr.new('+', 3)
562
+ end
563
+
564
+ def test_construct
565
+ assert_nothing_raised {
566
+ bp = NotBetweenPred.new(@arg1, @arg2, @arg3)
567
+ }
568
+ end
569
+
570
+ def test_to_adqls
571
+ assert_equal('PhotoPrimary.objid NOT BETWEEN -2 AND +3',
572
+ NotBetweenPred.new(@arg1, @arg2, @arg3).to_adqls)
573
+ end
574
+ end
575
+
576
+ class RegionSearchTest < Test::Unit::TestCase
577
+ def test_construct
578
+ assert_nothing_raised {
579
+ rs = RegionSearch.new(Circle.new(182.5, -0.89, 8), 'overlaps')
580
+ }
581
+ end
582
+
583
+ def test_to_adqls
584
+ assert_equal('Region(\'CIRCLE J2000 182.5 -0.89 8.0\')',
585
+ RegionSearch.new(Circle.new(182.5, -0.89, 8), 'overlaps').to_adqls)
586
+ end
587
+ end
588
+
589
+ class HavingTest < Test::Unit::TestCase
590
+ def setup
591
+ @cond = RegionSearch.new(Circle.new(182.5, -0.89, 8.0), 'overlaps')
592
+ end
593
+
594
+ def test_construct
595
+ assert_nothing_raised {
596
+ h = Having.new(@cond)
597
+ }
598
+ end
599
+
600
+ def test_to_adqls
601
+ assert_equal('HAVING Region(\'CIRCLE J2000 182.5 -0.89 8.0\')',
602
+ Having.new(@cond).to_adqls)
603
+ end
604
+
605
+ def test_from_xml
606
+ xml = '<Having xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
607
+ '<Condition xsi:type="likePredType">' +
608
+ '<Arg xsi:type="columnReferenceType" Table="opt" Name="org" />' +
609
+ '<Pattern>' +
610
+ '<Literal xsi:type="stringType" Value="%esa%" />' +
611
+ '</Pattern>' +
612
+ '</Condition>' +
613
+ '</Having>'
614
+ doc = REXML::Document.new(xml)
615
+
616
+ assert_equal("HAVING opt.org LIKE '%esa%'",
617
+ Having.from_xml(doc.root).to_adqls)
618
+ end
619
+ end
620
+
621
+ class GroupByTest < Test::Unit::TestCase
622
+ def setup
623
+ @columns = [ColumnReference.new('o', 'objid'),
624
+ ColumnReference.new('o', 'type'),
625
+ ColumnReference.new('t', 'objid')]
626
+ end
627
+
628
+ def test_construct
629
+ assert_nothing_raised {
630
+ gb = GroupBy.new(@columns)
631
+ }
632
+ end
633
+
634
+ def test_to_adqls
635
+ assert_equal('GROUP BY o.objid, o.type, t.objid',
636
+ GroupBy.new(@columns).to_adqls)
637
+ end
638
+
639
+ def test_from_xml
640
+ xml = '<GroupBy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
641
+ '<Column Table="o" Name="recid"/>' +
642
+ '<Column Table="o" Name="ra"/>' +
643
+ '<Column Table="o" Name="dec"/>' +
644
+ '</GroupBy>'
645
+ doc = REXML::Document.new(xml)
646
+
647
+ assert_equal('GROUP BY o.recid, o.ra, o.dec',
648
+ GroupBy.from_xml(doc.root).to_adqls)
649
+ end
650
+ end
651
+
652
+ class WhereTest < Test::Unit::TestCase
653
+ def setup
654
+ @tables = [IncludeTable.new('o'), IncludeTable.new('t')]
655
+ @xmatch = XMatch.new(@tables, '<', 3.5)
656
+ @region = RegionSearch.new(Circle.new(182.5, -0.89, 8.5), 'overlaps')
657
+ @comp = ComparisonPred.new(
658
+ ColumnReference.new('o', 'type'),
659
+ '=',
660
+ ScalarExpression.new(3))
661
+
662
+ @cond1 = IntersectionSearch.new(@xmatch, @region)
663
+ @condition = UnionSearch.new(@cond1, @comp)
664
+ end
665
+
666
+ def test_construct
667
+ assert_nothing_raised {
668
+ w = Where.new(@condition)
669
+ }
670
+ end
671
+
672
+ def test_to_adql
673
+ assert_equal('WHERE XMATCH(o, t) < 3.5 AND Region(\'CIRCLE J2000 182.5 -0.89 8.5\') OR o.type = 3',
674
+ Where.new(@condition).to_adqls)
675
+ end
676
+
677
+ def test_from_xml
678
+ xml = '<Where xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
679
+ '<Condition xsi:type="likePredType">' +
680
+ '<Arg xsi:type="columnReferenceType" Table="opt" Name="org" />' +
681
+ '<Pattern>' +
682
+ '<Literal xsi:type="stringType" Value="%esa%" />' +
683
+ '</Pattern>' +
684
+ '</Condition>' +
685
+ '</Where>'
686
+ doc = REXML::Document.new(xml)
687
+
688
+ assert_equal("WHERE opt.org LIKE '%esa%'",
689
+ Where.from_xml(doc.root).to_adqls)
690
+ end
691
+ end
692
+
693
+ class FromTest < Test::Unit::TestCase
694
+ def setup
695
+ @tables = [ArchiveTable.new('SDSS', 'PhotoPrimary', 'o'),
696
+ ArchiveTable.new('2MASS', 'PhotoPrimary', 't')]
697
+ end
698
+
699
+ def test_construct
700
+ assert_nothing_raised {
701
+ from = From.new(@tables)
702
+ }
703
+ end
704
+
705
+ def test_to_adql
706
+ assert_equal("FROM SDSS:PhotoPrimary o, 2MASS:PhotoPrimary t",
707
+ From.new(@tables).to_adqls)
708
+ end
709
+
710
+ def test_from_xml
711
+ xml = '<From xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
712
+ '<Table xsi:type="archiveTableType" Archive="SDSS" Name="PhotoPrimary" Alias="o"/>' +
713
+ '<Table xsi:type="archiveTableType" Archive="TWOMASS" Name="PhotoPrimary" Alias="a"/>' +
714
+ '</From>'
715
+ doc = REXML::Document.new(xml)
716
+
717
+ assert_equal('FROM SDSS:PhotoPrimary o, TWOMASS:PhotoPrimary a',
718
+ From.from_xml(doc.root).to_adqls)
719
+ end
720
+ end
721
+
722
+ class SelectionListTest < Test::Unit::TestCase
723
+ def setup
724
+ @items = [ColumnReference.new('o', 'objid'),
725
+ ColumnReference.new('o', 'ra'),
726
+ ColumnReference.new('o', 'dec')]
727
+ end
728
+
729
+ def test_construct
730
+ assert_nothing_raised {
731
+ list = SelectionList.new(@items)
732
+ }
733
+ end
734
+
735
+ def test_to_adql
736
+ assert_equal("o.objid, o.ra, o.dec",
737
+ SelectionList.new(@items).to_adqls)
738
+ end
739
+
740
+ def test_from_xml
741
+ xml = '<SelectionList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
742
+ '<Item xsi:type="columnReferenceType" Table="o" Name="recid" />' +
743
+ '<Item xsi:type="columnReferenceType" Table="o" Name="ra" />' +
744
+ '<Item xsi:type="columnReferenceType" Table="o" Name="dec" />' +
745
+ '</SelectionList>'
746
+ doc = REXML::Document.new(xml)
747
+
748
+ assert_equal('o.recid, o.ra, o.dec',
749
+ SelectionList.from_xml(doc.root).to_adqls)
750
+ end
751
+ end
752
+
753
+ class SelectionLimitTest < Test::Unit::TestCase
754
+ def test_construct
755
+ assert_nothing_raised {
756
+ limit = SelectionLimit.new(10)
757
+ }
758
+
759
+ assert_raise(RuntimeError){
760
+ limit = SelectionLimit.new(-1)
761
+ limit = SelectionLimit.new(10.2)
762
+ }
763
+ end
764
+
765
+ def test_to_adqls
766
+ assert_equal("TOP 10", SelectionLimit.new(10).to_adqls)
767
+ end
768
+
769
+ def test_from_xml
770
+ xml = '<SelectionLimit Top="10"/>'
771
+ doc = REXML::Document.new(xml)
772
+
773
+ assert_equal('TOP 10', SelectionLimit.from_xml(doc.root).to_adqls)
774
+ end
775
+ end
776
+
777
+ class IntoTest < Test::Unit::TestCase
778
+ def test_construct
779
+ assert_nothing_raised {
780
+ into = Into.new('my_table')
781
+ }
782
+ end
783
+
784
+ def test_to_adqls
785
+ assert_equal('INTO my_table', Into.new('my_table').to_adqls)
786
+ end
787
+
788
+ def test_from_xml
789
+ xml = '<InTo><TableName>my_table</TableName></InTo>'
790
+ doc = REXML::Document.new(xml)
791
+
792
+ assert_equal('INTO my_table',
793
+ Into.from_xml(doc.root).to_adqls)
794
+ end
795
+ end
796
+
797
+ class OrderDirectionTest < Test::Unit::TestCase
798
+ def test_construct
799
+ assert_nothing_raised {
800
+ dir = OrderDirection.new('ASC')
801
+ dir = OrderDirection.new('NEW', ['ASC', 'DESC', 'NEW'])
802
+ }
803
+
804
+ assert_raise(RuntimeError){
805
+ dir = OrderDirection.new('NEW')
806
+ }
807
+ end
808
+
809
+ def test_to_adqls
810
+ assert_equal('ASC', OrderDirection.new('ASC').to_adqls)
811
+ end
812
+ end
813
+
814
+ class OrderOptionTest < Test::Unit::TestCase
815
+ def test_construct
816
+ assert_nothing_raised {
817
+ order = OrderOption.new('ASC')
818
+ }
819
+ end
820
+
821
+ def test_to_adqls
822
+ assert_equal('ASC', OrderOption.new('ASC').to_adqls)
823
+ end
824
+ end
825
+
826
+ class OrderTest < Test::Unit::TestCase
827
+ def setup
828
+ @expression = ColumnReference.new('o', 'objid')
829
+ end
830
+
831
+ def test_construct
832
+ assert_nothing_raised {
833
+ order = Order.new(@expression)
834
+ }
835
+ end
836
+
837
+ def test_to_adqls
838
+ assert_equal('o.objid DESC', Order.new(@expression, 'DESC').to_adqls)
839
+ end
840
+ end
841
+
842
+ class OrderExpressionTest < Test::Unit::TestCase
843
+ def setup
844
+ @orders = [Order.new(ColumnReference.new('o', 'objid')),
845
+ Order.new(ColumnReference.new('o', 'ra'), 'DESC'),
846
+ Order.new(ColumnReference.new('o', 'dec'), 'ASC')]
847
+ end
848
+
849
+ def test_construct
850
+ assert_nothing_raised {
851
+ ord_expr = OrderExpression.new(@orders)
852
+ }
853
+ end
854
+
855
+ def test_to_adqls
856
+ assert_equal('ORDER BY o.objid, o.ra DESC, o.dec ASC',
857
+ OrderExpression.new(@orders).to_adqls)
858
+ end
859
+ end
860
+
861
+ class InclusiveSearchTest < Test::Unit::TestCase
862
+ def setup
863
+ @expression = ColumnReference.new('o', 'objid')
864
+ @set = ConstantListSet.new(['IBM', 'Microsoft', 'Apple'])
865
+ end
866
+
867
+ def test_construct
868
+ assert_nothing_raised {
869
+ isearch = InclusiveSearch.new(@expression, @set)
870
+ }
871
+ end
872
+
873
+ def test_to_adqls
874
+ assert_equal("o.objid IN (\"IBM\", \"Microsoft\", \"Apple\")",
875
+ InclusiveSearch.new(@expression, @set).to_adqls)
876
+ end
877
+ end
878
+
879
+ class SelectTest < Test::Unit::TestCase
880
+ def setup
881
+ @allow = SelectionOption.new('DISTINCT')
882
+
883
+ @restrict = SelectionLimit.new(10)
884
+
885
+ @columns = [ColumnReference.new('o', 'objid'),
886
+ ColumnReference.new('o', 'ra'),
887
+ ColumnReference.new('o', 'dec'),
888
+ ColumnReference.new('o', 'type'),
889
+ ColumnReference.new('t', 'objid'),
890
+ ColumnReference.new('t', 'ra'),
891
+ ColumnReference.new('t', 'dec'),
892
+ ColumnReference.new('t', 'j_m'),
893
+ ColumnReference.new('o', 'i')]
894
+ @sel_list = SelectionList.new(@columns)
895
+
896
+ @into = Into.new('myTable')
897
+
898
+ @from_list = [ArchiveTable.new('SDSS', 'PhotoPrimary', 'o'),
899
+ ArchiveTable.new('TWOMASS', 'PhotoPrimary', 't')]
900
+ @from = From.new(@from_list)
901
+
902
+ @xmatch_tables = [IncludeTable.new('o'),
903
+ IncludeTable.new('t')]
904
+ @xmatch = XMatch.new(@xmatch_tables, '<', 3.5)
905
+ @region = RegionSearch.new(Circle.new(182.5, -0.89, 8), 'overlaps')
906
+ @xmatchregion = IntersectionSearch.new(@xmatch, @region)
907
+
908
+ @otype = ComparisonPred.new(
909
+ ColumnReference.new('o', 'type'),
910
+ '=',
911
+ Atom.new(3))
912
+ @xmatchregion_otype = IntersectionSearch.new(@xmatchregion, @otype)
913
+
914
+ @oi = ComparisonPred.new(
915
+ ColumnReference.new('o', 'i'),
916
+ '<',
917
+ Atom.new(21))
918
+ @xmatchregion_otype_oi =
919
+ IntersectionSearch.new(@xmatchregion_otype, @oi)
920
+
921
+ @tjm = ComparisonPred.new(
922
+ ColumnReference.new('t', 'j_m'),
923
+ '<',
924
+ Atom.new(18))
925
+ @xmatchregion_otype_oi_tjm =
926
+ IntersectionSearch.new(@xmatchregion_otype_oi, @tjm)
927
+
928
+ @oitjmdiff = ComparisonPred.new(
929
+ ClosedExpr.new(
930
+ BinaryExpr.new(
931
+ ColumnReference.new('o', 'i'),
932
+ '-',
933
+ ColumnReference.new('t', 'j_m')
934
+ )
935
+ ),
936
+ '>',
937
+ Atom.new(2))
938
+
939
+ @conditions = IntersectionSearch.new(
940
+ @xmatchregion_otype_oi_tjm,
941
+ @oitjmdiff)
942
+ @where = Where.new(@conditions)
943
+
944
+ @group_by = GroupBy.new(
945
+ [ColumnReference.new('o', 'ra'),
946
+ ColumnReference.new('o', 'dec')])
947
+
948
+ @having = Having.new(
949
+ ComparisonPred.new(
950
+ ColumnReference.new('o', 'objid'),
951
+ '=',
952
+ Atom.new('1234')
953
+ )
954
+ )
955
+
956
+ @order_by = OrderExpression.new(
957
+ [Order.new(ColumnReference.new('o', 'objid')),
958
+ Order.new(ColumnReference.new('o', 'ra'), 'DESC')]
959
+ )
960
+ end
961
+
962
+ def test_construct
963
+ assert_nothing_raised {
964
+ select = Select.new(@sel_list)
965
+ select = Select.new(@sel_list, @allow)
966
+ select = Select.new(@sel_list, @allow, @restrict)
967
+ select = Select.new(@sel_list, @allow, @restrict, @into)
968
+ select = Select.new(@sel_list, @allow, @restrict, @into, @from)
969
+ select = Select.new(@sel_list, nil, nil, nil,
970
+ @from, @where)
971
+ select = Select.new(@sel_list, nil, nil, nil,
972
+ @from, @where, @group_by)
973
+ select = Select.new(@sel_list, nil, nil, nil,
974
+ @from, @where, @group_by, @having, @order_by)
975
+ }
976
+ end
977
+
978
+ def test_to_adqls
979
+ adqls = 'SELECT o.objid, o.ra, o.dec, o.type, t.objid, t.ra, t.dec, t.j_m, o.i'
980
+ assert_equal(adqls, Select.new(@sel_list).to_adqls)
981
+
982
+ adqls =
983
+ 'SELECT DISTINCT ' +
984
+ 'o.objid, o.ra, o.dec, o.type, t.objid, t.ra, t.dec, t.j_m, o.i'
985
+ assert_equal(adqls, Select.new(@sel_list, @allow).to_adqls)
986
+
987
+ adqls = 'SELECT DISTINCT TOP 10 o.objid, o.ra, o.dec, o.type, t.objid, t.ra, t.dec, t.j_m, o.i'
988
+ assert_equal(adqls, Select.new(@sel_list, @allow, @restrict).to_adqls)
989
+
990
+ adqls =
991
+ 'SELECT DISTINCT TOP 10 ' +
992
+ 'o.objid, o.ra, o.dec, o.type, t.objid, t.ra, t.dec, t.j_m, o.i ' +
993
+ 'INTO myTable'
994
+ assert_equal(adqls, Select.new(@sel_list, @allow, @restrict, @into).to_adqls)
995
+
996
+ adqls =
997
+ 'SELECT DISTINCT TOP 10 ' +
998
+ 'o.objid, o.ra, o.dec, o.type, t.objid, t.ra, t.dec, t.j_m, o.i ' +
999
+ 'INTO myTable ' +
1000
+ 'FROM SDSS:PhotoPrimary o, TWOMASS:PhotoPrimary t'
1001
+ assert_equal(adqls, Select.new(@sel_list, @allow, @restrict, @into, @from).to_adqls)
1002
+
1003
+ adqls =
1004
+ 'SELECT ' +
1005
+ 'o.objid, o.ra, o.dec, o.type, t.objid, t.ra, t.dec, t.j_m, o.i ' +
1006
+ 'FROM SDSS:PhotoPrimary o, TWOMASS:PhotoPrimary t ' +
1007
+ 'WHERE ' +
1008
+ 'XMATCH(o, t) < 3.5 AND ' +
1009
+ 'Region(\'CIRCLE J2000 182.5 -0.89 8.0\') AND ' +
1010
+ 'o.type = 3 AND ' +
1011
+ 'o.i < 21 AND ' +
1012
+ 't.j_m < 18 AND ' +
1013
+ '(o.i - t.j_m) > 2 ' +
1014
+ 'GROUP BY o.ra, o.dec ' +
1015
+ 'HAVING o.objid = \'1234\' ' +
1016
+ 'ORDER BY o.objid, o.ra DESC'
1017
+ assert_equal(adqls,
1018
+ Select.new(@sel_list, nil, nil, nil, @from,
1019
+ @where, @group_by, @having, @order_by).to_adqls)
1020
+ end
1021
+ end
1022
+
1023
+ class UserDefinedFunctionTest < Test::Unit::TestCase
1024
+ def setup
1025
+ @params = [ColumnReference.new('o', 'ra'), ColumnReference.new('o', 'dec')]
1026
+ end
1027
+
1028
+ def test_construct
1029
+ assert_nothing_raised {
1030
+ udf = UserDefinedFunction.new('my_func', @params)
1031
+ }
1032
+ end
1033
+
1034
+ def test_to_adqls
1035
+ assert_equal('my_func(o.ra, o.dec)',
1036
+ UserDefinedFunction.new('my_func', @params).to_adqls)
1037
+ end
1038
+ end
1039
+
1040
+ class JointTableQualifierTest < Test::Unit::TestCase
1041
+ def test_construct
1042
+ assert_nothing_raised {
1043
+ qual = JointTableQualifier.new('INNER')
1044
+ qual = JointTableQualifier.new('FAKE', ['INNER', 'FAKE', 'CROSS'])
1045
+ }
1046
+
1047
+ assert_raise(RuntimeError){
1048
+ qual = JointTableQualifier.new('FAKE')
1049
+ }
1050
+ end
1051
+
1052
+ def test_to_adqls
1053
+ assert_equal('INNER', JointTableQualifier.new('INNER').to_adqls)
1054
+ end
1055
+ end
1056
+
1057
+ class JoinTableTest < Test::Unit::TestCase
1058
+ def setup
1059
+ @tables = ArrayOfFromTable.new(
1060
+ [ArchiveTable.new('SDSS', 'PhotoPrimary', 'o'),
1061
+ ArchiveTable.new('TWOMASS', 'PhotoPrimary', 't')]
1062
+ )
1063
+ @comp = ComparisonPred.new(
1064
+ ColumnReference.new('o', 'objid'),
1065
+ '=',
1066
+ ColumnReference.new('t', 'objid')
1067
+ )
1068
+ end
1069
+
1070
+ def test_construct
1071
+ assert_nothing_raised {
1072
+ jt = JoinTable.new('INNER', @tables, @comp)
1073
+ }
1074
+ end
1075
+
1076
+ def test_to_adqls
1077
+ assert_equal('INNER SDSS:PhotoPrimary o, TWOMASS:PhotoPrimary t ON o.objid = t.objid',
1078
+ JoinTable.new('INNER', @tables, @comp).to_adqls)
1079
+ end
1080
+ end
1081
+
1082
+ class ArrayOfFromTableTest < Test::Unit::TestCase
1083
+ def setup
1084
+ @froms =
1085
+ [ArchiveTable.new('SDSS', 'PhotoPrimary', 'o'),
1086
+ ArchiveTable.new('TWOMASS', 'PhotoPrimary', 't')]
1087
+ end
1088
+
1089
+ def test_construct
1090
+ assert_nothing_raised {
1091
+ aoft = ArrayOfFromTable.new(@froms)
1092
+ }
1093
+ end
1094
+
1095
+ def test_to_adqls
1096
+ assert_equal('SDSS:PhotoPrimary o, TWOMASS:PhotoPrimary t',
1097
+ ArrayOfFromTable.new(@froms).to_adqls)
1098
+ end
1099
+ end
1100
+
1101
+ class ArgTest < Test::Unit::TestCase
1102
+ def setup
1103
+ xml1 = '<Arg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="columnReferenceType" Table="o" Name="objid" xpathName="description" />'
1104
+ xml2 = '<Arg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="atomType">' +
1105
+ '<Literal xsi:type="stringType" Value="CDS" />' +
1106
+ '</Arg>'
1107
+ xml3 = '<Arg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Oper="-" xsi:type="binaryExprType">' +
1108
+ '<Arg Table="opt" Name="R" xsi:type="columnReferenceType"/>' +
1109
+ '<Arg Table="opt" Name="B" xsi:type="columnReferenceType"/>' +
1110
+ '</Arg>'
1111
+ xml4 = '<Arg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Oper="-" xsi:type="unaryExprType">' +
1112
+ '<Arg Table="opt" Name="R" xsi:type="columnReferenceType"/>' +
1113
+ '</Arg>'
1114
+ xml5 = '<Arg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="closedExprType">' +
1115
+ '<Arg Table="opt" Name="R" xsi:type="columnReferenceType"/>' +
1116
+ '</Arg>'
1117
+ xml6 = '<Arg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="trigonometricFunctionType" Name="SIN">' +
1118
+ '<Allow Option="DISTINCT"/>' +
1119
+ '<Arg Table="opt" Name="R" xsi:type="columnReferenceType"/>' +
1120
+ '</Arg>'
1121
+ xml7 = '<Arg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="mathFunctionType" Name="ABS">' +
1122
+ '<Allow Option="ALL"/>' +
1123
+ '<Arg Table="opt" Name="R" xsi:type="columnReferenceType"/>' +
1124
+ '</Arg>'
1125
+ xml8 = '<Arg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="aggregateFunctionType" Name="AVG">' +
1126
+ '<Arg Table="opt" Name="R" xsi:type="columnReferenceType"/>' +
1127
+ '</Arg>'
1128
+ xml9 = '<Arg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="userDefinedFunctionType">' +
1129
+ '<Name>MyFunc</Name>' +
1130
+ '<Params Table="opt" Name="R" xsi:type="columnReferenceType"/>' +
1131
+ '</Arg>'
1132
+ xml10 = '<Arg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="aliasSelectionItemType" As="myCol">' +
1133
+ '<Expression Table="opt" Name="R" xsi:type="columnReferenceType"/>' +
1134
+ '</Arg>'
1135
+ @doc1 = REXML::Document.new(xml1)
1136
+ @doc2 = REXML::Document.new(xml2)
1137
+ @doc3 = REXML::Document.new(xml3)
1138
+ @doc4 = REXML::Document.new(xml4)
1139
+ @doc5 = REXML::Document.new(xml5)
1140
+ @doc6 = REXML::Document.new(xml6)
1141
+ @doc7 = REXML::Document.new(xml7)
1142
+ @doc8 = REXML::Document.new(xml8)
1143
+ @doc9 = REXML::Document.new(xml9)
1144
+ @doc10 = REXML::Document.new(xml10)
1145
+ end
1146
+
1147
+ def test_from_xml
1148
+ assert_nothing_raised {
1149
+ arg = Arg.from_xml(@doc1.root)
1150
+ arg = Arg.from_xml(@doc2.root)
1151
+ arg = Arg.from_xml(@doc3.root)
1152
+ arg = Arg.from_xml(@doc4.root)
1153
+ arg = Arg.from_xml(@doc5.root)
1154
+ arg = Arg.from_xml(@doc6.root)
1155
+ arg = Arg.from_xml(@doc7.root)
1156
+ arg = Arg.from_xml(@doc8.root)
1157
+ arg = Arg.from_xml(@doc9.root)
1158
+ arg = Arg.from_xml(@doc10.root)
1159
+ }
1160
+ end
1161
+
1162
+ def test_to_adql
1163
+ assert_equal('o.objid', Arg.from_xml(@doc1.root).to_adqls)
1164
+ assert_equal("'CDS'", Arg.from_xml(@doc2.root).to_adqls)
1165
+ assert_equal('opt.R - opt.B', Arg.from_xml(@doc3.root).to_adqls)
1166
+ assert_equal('-opt.R', Arg.from_xml(@doc4.root).to_adqls)
1167
+ assert_equal('(opt.R)', Arg.from_xml(@doc5.root).to_adqls)
1168
+ assert_equal('SIN(DISTINCT opt.R)', Arg.from_xml(@doc6.root).to_adqls)
1169
+ assert_equal('ABS(ALL opt.R)', Arg.from_xml(@doc7.root).to_adqls)
1170
+ assert_equal('AVG(opt.R)', Arg.from_xml(@doc8.root).to_adqls)
1171
+ assert_equal('MyFunc(opt.R)', Arg.from_xml(@doc9.root).to_adqls)
1172
+ assert_equal('opt.R AS myCol', Arg.from_xml(@doc10.root).to_adqls)
1173
+ end
1174
+ end
1175
+
1176
+ class LiteralTest < Test::Unit::TestCase
1177
+ def setup
1178
+ @doc1 = REXML::Document.new('<Literal xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Value="10.0" xsi:type="realType"/>')
1179
+ @doc2 = REXML::Document.new('<Literal xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Value="10" xsi:type="integerType"/>')
1180
+ @doc3 = REXML::Document.new('<Literal xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Value="ten" xsi:type="stringType"/>')
1181
+ end
1182
+
1183
+ def test_from_xml
1184
+ assert_nothing_raised {
1185
+ lit = LiteralType.from_xml(@doc1.root)
1186
+ lit = LiteralType.from_xml(@doc2.root)
1187
+ lit = LiteralType.from_xml(@doc3.root)
1188
+ }
1189
+ end
1190
+
1191
+ def test_to_adql
1192
+ assert_equal("10.0", LiteralType.from_xml(@doc1.root).to_adqls)
1193
+ assert_equal("10", LiteralType.from_xml(@doc2.root).to_adqls)
1194
+ assert_equal('ten', LiteralType.from_xml(@doc3.root).to_adqls)
1195
+ end
1196
+ end
1197
+
1198
+ class UnitTest < Test::Unit::TestCase
1199
+ def setup
1200
+ @doc = REXML::Document.new('<Unit>cm</Unit>')
1201
+ end
1202
+
1203
+ def text_from_xml
1204
+ assert_nothing_raised {
1205
+ unit = Unit.from_xml(@doc.root)
1206
+ }
1207
+ end
1208
+
1209
+ def test_to_adqls
1210
+ assert_equal('cm', Unit.from_xml(@doc.root).to_adqls)
1211
+ end
1212
+ end
1213
+
1214
+ class AllowTest < Test::Unit::TestCase
1215
+ def setup
1216
+ @doc = REXML::Document.new('<Allow xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="selectionOptionType" Option="DISTINCT"/>')
1217
+ end
1218
+
1219
+ def test_from_xml
1220
+ assert_nothing_raised {
1221
+ allow = Allow.from_xml(@doc.root)
1222
+ }
1223
+ end
1224
+
1225
+ def test_to_adqls
1226
+ assert_equal('DISTINCT', Allow.from_xml(@doc.root).to_adqls)
1227
+ end
1228
+ end
1229
+
1230
+ class ExpressionTest < Test::Unit::TestCase
1231
+ def setup
1232
+ @doc = REXML::Document.new('<Expression xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Table="opt" Name="R" xsi:type="columnReferenceType"/>')
1233
+ end
1234
+
1235
+ def test_from_xml
1236
+ assert_nothing_raised {
1237
+ expr = Expression.from_xml(@doc.root)
1238
+ }
1239
+ end
1240
+
1241
+ def test_to_adqls
1242
+ assert_equal('opt.R', Expression.from_xml(@doc.root).to_adqls)
1243
+ end
1244
+ end
1245
+
1246
+ class ConditionTest < Test::Unit::TestCase
1247
+ def setup
1248
+ @xml1 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="likePredType">' +
1249
+ '<Arg xsi:type="columnReferenceType" Table="opt" Name="org" />' +
1250
+ '<Pattern>' +
1251
+ '<Literal xsi:type="stringType" Value="%esa%" />' +
1252
+ '</Pattern>' +
1253
+ '</Condition>'
1254
+ @doc1 = REXML::Document.new(@xml1)
1255
+
1256
+ @xml2 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="notLikePredType">' +
1257
+ '<Arg xsi:type="columnReferenceType" Table="opt" Name="org" />' +
1258
+ '<Pattern>' +
1259
+ '<Literal xsi:type="stringType" Value="%esa%" />' +
1260
+ '</Pattern>' +
1261
+ '</Condition>'
1262
+ @doc2 = REXML::Document.new(@xml2)
1263
+
1264
+ @xml3 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="closedSearchType">' +
1265
+ @xml1 +
1266
+ '</Condition>'
1267
+ @doc3 = REXML::Document.new(@xml3)
1268
+
1269
+ @xml4 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="comparisonPredType" Comparison="&lt;&gt;">' +
1270
+ '<Arg xsi:type="columnReferenceType" Table="opt" Name="publisher" />' +
1271
+ '<Arg xsi:type="atomType">' +
1272
+ '<Literal xsi:type="stringType" Value="CDS" />' +
1273
+ '</Arg>' +
1274
+ '</Condition>'
1275
+ @doc4 = REXML::Document.new(@xml4)
1276
+
1277
+ @xml5 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="betweenPredType">' +
1278
+ '<Arg xsi:type="columnReferenceType" Table="opt" Name="R" />' +
1279
+ '<Arg xsi:type="atomType">' +
1280
+ '<Literal xsi:type="realType" Value="1.2" />' +
1281
+ '</Arg>' +
1282
+ '<Arg xsi:type="atomType">' +
1283
+ '<Literal xsi:type="realType" Value="1.6" />' +
1284
+ '</Arg>' +
1285
+ '</Condition>'
1286
+ @doc5 = REXML::Document.new(@xml5)
1287
+
1288
+ @xml6 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="notBetweenPredType">' +
1289
+ '<Arg xsi:type="columnReferenceType" Table="opt" Name="R" />' +
1290
+ '<Arg xsi:type="atomType">' +
1291
+ '<Literal xsi:type="realType" Value="1.2" />' +
1292
+ '</Arg>' +
1293
+ '<Arg xsi:type="atomType">' +
1294
+ '<Literal xsi:type="realType" Value="1.6" />' +
1295
+ '</Arg>' +
1296
+ '</Condition>'
1297
+ @doc6 = REXML::Document.new(@xml6)
1298
+
1299
+ @xml7 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="intersectionSearchType">' +
1300
+ @xml4 +
1301
+ @xml5 +
1302
+ '</Condition>'
1303
+ @doc7 = REXML::Document.new(@xml7)
1304
+
1305
+ @xml8 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="unionSearchType">' +
1306
+ @xml4 +
1307
+ @xml5 +
1308
+ '</Condition>'
1309
+ @doc8 = REXML::Document.new(@xml8)
1310
+
1311
+ @xml9 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xMatchType">' +
1312
+ '<Table xsi:type="includeTableType" Name="opt"/>' +
1313
+ '<Table xsi:type="includeTableType" Name="apt"/>' +
1314
+ '<Table xsi:type="dropTableType" Name="drop_me"/>' +
1315
+ '<Nature xsi:type="comparisonType" Comparison="&lt;"/>' +
1316
+ '<Sigma xsi:type="realType" Value="0.5"/>' +
1317
+ '</Condition>'
1318
+ @doc9 = REXML::Document.new(@xml9)
1319
+
1320
+ @xml10 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="regionSearchType">' +
1321
+ '<Region xmlns:q1="http://www.ivoa.net/xml/STC/STCregion/v1.10" xsi:type="q1:circleType" unit="deg">' +
1322
+ '<q1:Center>181.3 -0.76</q1:Center>' +
1323
+ '<q1:Radius>6.5</q1:Radius>' +
1324
+ '</Region>' +
1325
+ '</Condition>'
1326
+ @doc10 = REXML::Document.new(@xml10)
1327
+
1328
+ @xml11 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="inverseSearchType">' +
1329
+ @xml4 +
1330
+ '</Condition>'
1331
+ @doc11 = REXML::Document.new(@xml11)
1332
+
1333
+ @xml12 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="inclusiveSearchType">' +
1334
+ '<Expression xsi:type="columnReferenceType" Table="opt" Name="R" />' +
1335
+ '<Set xsi:type="subQuerySetType">' +
1336
+ '<Select>' +
1337
+ '<SelectionList>' +
1338
+ '<Item xsi:type="columnReferenceType" Table="opt" Name="R" />' +
1339
+ '<Item xsi:type="columnReferenceType" Table="opt" Name="V" />' +
1340
+ '<Item xsi:type="columnReferenceType" Table="opt" Name="ra" />' +
1341
+ '<Item xsi:type="columnReferenceType" Table="opt" Name="dec" />' +
1342
+ '</SelectionList>' +
1343
+ '</Select>' +
1344
+ '</Set>' +
1345
+ '</Condition>'
1346
+ @doc12 = REXML::Document.new(@xml12)
1347
+
1348
+ @xml13 = '<Condition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="exclusiveSearchType">' +
1349
+ '<Expression xsi:type="columnReferenceType" Table="opt" Name="R" />' +
1350
+ '<Set xsi:type="subQuerySetType">' +
1351
+ '<Select>' +
1352
+ '<SelectionList>' +
1353
+ '<Item xsi:type="columnReferenceType" Table="opt" Name="R" />' +
1354
+ '<Item xsi:type="columnReferenceType" Table="opt" Name="V" />' +
1355
+ '<Item xsi:type="columnReferenceType" Table="opt" Name="ra" />' +
1356
+ '<Item xsi:type="columnReferenceType" Table="opt" Name="dec" />' +
1357
+ '</SelectionList>' +
1358
+ '</Select>' +
1359
+ '</Set>' +
1360
+ '</Condition>'
1361
+ @doc13 = REXML::Document.new(@xml13)
1362
+ end
1363
+
1364
+ def test_from_xml
1365
+ assert_nothing_raised {
1366
+ cond = Condition.from_xml(@doc1.root)
1367
+ cond = Condition.from_xml(@doc2.root)
1368
+ cond = Condition.from_xml(@doc3.root)
1369
+ cond = Condition.from_xml(@doc4.root)
1370
+ cond = Condition.from_xml(@doc5.root)
1371
+ cond = Condition.from_xml(@doc6.root)
1372
+ cond = Condition.from_xml(@doc7.root)
1373
+ cond = Condition.from_xml(@doc8.root)
1374
+ cond = Condition.from_xml(@doc9.root)
1375
+ cond = Condition.from_xml(@doc10.root)
1376
+ cond = Condition.from_xml(@doc11.root)
1377
+ cond = Condition.from_xml(@doc12.root)
1378
+ cond = Condition.from_xml(@doc13.root)
1379
+ }
1380
+ end
1381
+
1382
+ def test_to_adqls
1383
+ assert_equal("opt.org LIKE '%esa%'",
1384
+ Condition.from_xml(@doc1.root).to_adqls)
1385
+ assert_equal("opt.org NOT LIKE '%esa%'",
1386
+ Condition.from_xml(@doc2.root).to_adqls)
1387
+ assert_equal("(opt.org LIKE '%esa%')",
1388
+ Condition.from_xml(@doc3.root).to_adqls)
1389
+ assert_equal("opt.publisher <> 'CDS'",
1390
+ Condition.from_xml(@doc4.root).to_adqls)
1391
+ assert_equal("opt.R BETWEEN 1.2 AND 1.6",
1392
+ Condition.from_xml(@doc5.root).to_adqls)
1393
+ assert_equal("opt.R NOT BETWEEN 1.2 AND 1.6",
1394
+ Condition.from_xml(@doc6.root).to_adqls)
1395
+ assert_equal("opt.publisher <> 'CDS' AND opt.R BETWEEN 1.2 AND 1.6",
1396
+ Condition.from_xml(@doc7.root).to_adqls)
1397
+ assert_equal("opt.publisher <> 'CDS' OR opt.R BETWEEN 1.2 AND 1.6",
1398
+ Condition.from_xml(@doc8.root).to_adqls)
1399
+ assert_equal('XMATCH(opt, apt, !drop_me) < 0.5',
1400
+ Condition.from_xml(@doc9.root).to_adqls)
1401
+ assert_equal("Region('CIRCLE J2000 181.3 -0.76 6.5')",
1402
+ Condition.from_xml(@doc10.root).to_adqls)
1403
+ assert_equal("NOT opt.publisher <> 'CDS'",
1404
+ Condition.from_xml(@doc11.root).to_adqls)
1405
+ assert_equal('opt.R IN (SELECT opt.R, opt.V, opt.ra, opt.dec)',
1406
+ Condition.from_xml(@doc12.root).to_adqls)
1407
+ assert_equal('opt.R NOT IN (SELECT opt.R, opt.V, opt.ra, opt.dec)',
1408
+ Condition.from_xml(@doc13.root).to_adqls)
1409
+ end
1410
+ end
1411
+
1412
+ class TableTest < Test::Unit::TestCase
1413
+ def setup
1414
+ @xml1 = '<Table Name="my_table" xsi:type="includeTableType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'
1415
+ @doc1 = REXML::Document.new(@xml1)
1416
+
1417
+ @xml2 = '<Table Name="my_table" xsi:type="dropTableType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'
1418
+ @doc2 = REXML::Document.new(@xml2)
1419
+
1420
+ @xml3 = '<Table Archive="SDSS" Name="PhotoPrimary" Alias="o" xsi:type="archiveTableType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>'
1421
+ @doc3 = REXML::Document.new(@xml3)
1422
+
1423
+ @xml4 = '<Table xsi:type="joinTableType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
1424
+ '<Qualifier xsi:type="jointTableQualifierType">INNER</Qualifier>' +
1425
+ '<Tables xsi:type="arrayOfFromTableType">' +
1426
+ '<Table Archive="SDSS" Name="PhotoPrimary" Alias="o" xsi:type="archiveTableType"/>' +
1427
+ '<Table Archive="TWOMASS" Name="PhotoPrimary" Alias="t" xsi:type="archiveTableType"/>' +
1428
+ '</Tables>' +
1429
+ '<Condition xsi:type="comparisonPredType" Comparison="=">' +
1430
+ '<Arg xsi:type="columnReferenceType" Table="o" Name="publisher" />' +
1431
+ '<Arg xsi:type="atomType">' +
1432
+ '<Literal xsi:type="stringType" Value="CDS" />' +
1433
+ '</Arg>' +
1434
+ '</Condition>' +
1435
+ '</Table>'
1436
+ @doc4 = REXML::Document.new(@xml4)
1437
+
1438
+ @table1 = Table.new('PhotoPrimary', 'o')
1439
+ @table2 = Table.new('PhotoPrimary')
1440
+ end
1441
+
1442
+ def test_from_xml
1443
+ assert_nothing_raised {
1444
+ tbl = Table.from_xml(@doc1.root)
1445
+ tbl = Table.from_xml(@doc2.root)
1446
+ tbl = Table.from_xml(@doc3.root)
1447
+ tbl = Table.from_xml(@doc4.root)
1448
+ }
1449
+ end
1450
+
1451
+ def test_to_adqls
1452
+ assert_equal('my_table', Table.from_xml(@doc1.root).to_adqls)
1453
+ assert_equal('!my_table', Table.from_xml(@doc2.root).to_adqls)
1454
+ assert_equal('SDSS:PhotoPrimary o', Table.from_xml(@doc3.root).to_adqls)
1455
+ assert_equal("INNER SDSS:PhotoPrimary o, TWOMASS:PhotoPrimary t ON o.publisher = 'CDS'",
1456
+ Table.from_xml(@doc4.root).to_adqls)
1457
+ assert_equal('PhotoPrimary o', @table1.to_adqls)
1458
+ assert_equal('PhotoPrimary', @table2.to_adqls)
1459
+ end
1460
+ end
1461
+
1462
+ class ConstantListSetTest < Test::Unit::TestCase
1463
+ def setup
1464
+ @xml = '<Set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="constantListSetType">' +
1465
+ '<Item xsi:type="realType" Value="10.1" />' +
1466
+ '<Item xsi:type="stringType" Value="hello" />' +
1467
+ '<Item xsi:type="integerType" Value="5" />' +
1468
+ '</Set>'
1469
+ @doc = REXML::Document.new(@xml)
1470
+ end
1471
+
1472
+ def test_from_xml
1473
+ assert_nothing_raised {
1474
+ set = ConstantListSet.from_xml(@doc.root)
1475
+ }
1476
+ end
1477
+
1478
+ def test_to_adqls
1479
+ assert_equal('10.1, "hello", 5',
1480
+ ConstantListSet.from_xml(@doc.root).to_adqls)
1481
+ end
1482
+ end
1483
+
1484
+ class ColumnTest < Test::Unit::TestCase
1485
+ def setup
1486
+ @xml = '<Column xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="columnReferenceType" Table="o" Name="publisher" />'
1487
+ @doc = REXML::Document.new(@xml)
1488
+ end
1489
+
1490
+ def test_from_xml
1491
+ assert_nothing_raised {
1492
+ col = Column.from_xml(@doc.root)
1493
+ }
1494
+ end
1495
+
1496
+ def test_to_adqls
1497
+ assert_equal('o.publisher', Column.from_xml(@doc.root).to_adqls)
1498
+
1499
+ xml = '<Column Table="o" Name="ra"/>'
1500
+ doc = REXML::Document.new(xml)
1501
+ assert_equal('o.ra', Column.from_xml(doc.root).to_adqls)
1502
+ end
1503
+ end
1504
+
1505
+ class ItemTest < Test::Unit::TestCase
1506
+ def setup
1507
+ @xml1 = '<Item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="orderType">' +
1508
+ '<Expression xsi:type="columnReferenceType" Table="o" Name="ra" />' +
1509
+ '<Order Direction="ASC"/>' +
1510
+ '</Item>'
1511
+ @doc1 = REXML::Document.new(@xml1)
1512
+ end
1513
+
1514
+ def test_from_xml
1515
+ assert_nothing_raised {
1516
+ item = Item.from_xml(@doc1.root)
1517
+ }
1518
+ end
1519
+
1520
+ def test_from_adqls
1521
+ assert_equal('o.ra ASC', Item.from_xml(@doc1.root).to_adqls)
1522
+ end
1523
+ end
1524
+
1525
+ class OrderByTest < Test::Unit::TestCase
1526
+ def setup
1527
+ xml = '<OrderBy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
1528
+ '<Item xsi:type="orderType">' +
1529
+ '<Expression xsi:type="columnReferenceType" Table="o" Name="ra" />' +
1530
+ '<Order Direction="ASC"/>' +
1531
+ '</Item>' +
1532
+ '<Item xsi:type="orderType">' +
1533
+ '<Expression xsi:type="columnReferenceType" Table="o" Name="dec" />' +
1534
+ '<Order Direction="DESC"/>' +
1535
+ '</Item>' +
1536
+ '</OrderBy>'
1537
+ @doc = REXML::Document.new(xml)
1538
+ end
1539
+
1540
+ def test_from_xml
1541
+ assert_equal('ORDER BY o.ra ASC, o.dec DESC',
1542
+ OrderBy.from_xml(@doc.root).to_adqls)
1543
+ end
1544
+ end
1545
+
1546
+ class ParamsTest < Test::Unit::TestCase
1547
+ def setup
1548
+ xml = '<Params xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Oper="-" xsi:type="binaryExprType">' +
1549
+ '<Arg Table="o" Name="R" xsi:type="columnReferenceType"/>' +
1550
+ '<Arg Table="o" Name="B" xsi:type="columnReferenceType"/>' +
1551
+ '</Params>'
1552
+ @doc = REXML::Document.new(xml)
1553
+ end
1554
+
1555
+ def test_from_xml
1556
+ assert_equal('o.R - o.B',
1557
+ Params.from_xml(@doc.root).to_adqls)
1558
+ end
1559
+ end
1560
+
1561
+ class QualifierTest < Test::Unit::TestCase
1562
+ def setup
1563
+ xml = '<Qualifier>INNER</Qualifier>'
1564
+ @doc = REXML::Document.new(xml)
1565
+ end
1566
+
1567
+ def test_from_xml
1568
+ assert_equal('INNER', Qualifier.from_xml(@doc.root).to_adqls)
1569
+ end
1570
+ end
1571
+
1572
+ class TablesTest < Test::Unit::TestCase
1573
+ def setup
1574
+ xml = '<Tables xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
1575
+ '<Table Archive="SDSS" Name="PhotoPrimary" Alias="o" xsi:type="archiveTableType"/>' +
1576
+ '<Table Archive="TWOMASS" Name="PhotoPrimary" Alias="t" xsi:type="archiveTableType"/>' +
1577
+ '</Tables>'
1578
+ @doc = REXML::Document.new(xml)
1579
+ end
1580
+
1581
+ def test_from_xml
1582
+ assert_equal('SDSS:PhotoPrimary o, TWOMASS:PhotoPrimary t',
1583
+ Tables.from_xml(@doc.root).to_adqls)
1584
+ end
1585
+ end
1586
+
1587
+ class RealWorldTests < Test::Unit::TestCase
1588
+ def setup
1589
+ @test1_doc = REXML::Document.new(File.new('test/adql/test1.adql'))
1590
+ @test2_doc = REXML::Document.new(File.new('test/adql/test2.adql'))
1591
+ @test3_doc = REXML::Document.new(File.new('test/adql/test3.adql'))
1592
+ @test4_doc = REXML::Document.new(File.new('test/adql/test4.adql'))
1593
+ @test5_doc = REXML::Document.new(File.new('test/adql/test5.adql'))
1594
+ @test6_doc = REXML::Document.new(File.new('test/adql/test6.adql'))
1595
+ @test7_doc = REXML::Document.new(File.new('test/adql/test7.adql'))
1596
+ end
1597
+
1598
+ def test_test1
1599
+ assert_equal('SELECT o.objid, o.ra, o.dec, o.type, t.objid, t.ra, t.dec, t.j_m, o.i ' +
1600
+ 'FROM SDSS:PhotoPrimary o, TWOMASS:PhotoPrimary t, ' +
1601
+ 'INNER SDSS:PhotoPrimary o, TWOMASS:PhotoPrimary t ON o.objid = t.objid ' +
1602
+ "WHERE Region('CIRCLE J2000 182.5 -0.89 8.0')",
1603
+ Select.from_xml(@test1_doc.root).to_adqls)
1604
+ end
1605
+
1606
+ def test_test2
1607
+ assert_equal('SELECT o.objid, o.ra, o.dec, o.r, o.type, t.objid, t.ra, t.dec ' +
1608
+ 'FROM SDSS:PhotoPrimary o, TWOMASS:PhotoPrimary t ' +
1609
+ 'WHERE ' +
1610
+ 'XMATCH(o, t) < 3.5 AND ' +
1611
+ "Region('CIRCLE J2000 181.3 -0.76 6.5') AND " +
1612
+ 'o.type = 3',
1613
+ Select.from_xml(@test2_doc.root).to_adqls)
1614
+ end
1615
+
1616
+ def test_test3
1617
+ assert_equal('SELECT o.objid, o.ra, o.dec, o.type, t.objid, t.ra, t.dec, t.j_m, o.i ' +
1618
+ 'FROM SDSS:PhotoPrimary o, TWOMASS:PhotoPrimary t ' +
1619
+ 'WHERE ' +
1620
+ 'XMATCH(o, t) < 3.5 AND ' +
1621
+ "Region('CIRCLE J2000 182.5 -0.89 8.0') AND " +
1622
+ 'o.type = 3 AND ' +
1623
+ 'o.i < 21 AND ' +
1624
+ 't.j_m < 18 AND ' +
1625
+ '(o.i - t.j_m) > 2',
1626
+ Select.from_xml(@test3_doc.root).to_adqls)
1627
+ end
1628
+
1629
+ def test_test4
1630
+ assert_equal('SELECT o.objid, o.ra, o.dec, t.ra, t.dec, t.objid, o.type ' +
1631
+ 'FROM SDSS:PhotoPrimary o, TWOMASS:PhotoPrimary t, USNOB:PhotoPrimary p ' +
1632
+ 'WHERE ' +
1633
+ 'XMATCH(o, t, !p) < 3.5 AND ' +
1634
+ "Region('CIRCLE J2000 182.5 -0.89 8.0') AND " +
1635
+ 'o.type = 3',
1636
+ Select.from_xml(@test4_doc.root).to_adqls)
1637
+ end
1638
+
1639
+ def test_test5
1640
+ assert_equal('SELECT o.objid, o.ra, o.dec, o.type, t.objid, t.j_m, o.z ' +
1641
+ 'FROM SDSSDR2:PhotoPrimary o, TWOMASS:PhotoPrimary t ' +
1642
+ 'WHERE ' +
1643
+ 'XMATCH(o, t) < 2.5 AND ' +
1644
+ "Region('CIRCLE J2000 16.031 -0.891 30.0') AND " +
1645
+ '(o.z - t.j_m) > 2',
1646
+ Select.from_xml(@test5_doc.root).to_adqls)
1647
+ end
1648
+
1649
+ def test_test6
1650
+ assert_equal('SELECT TOP 10 s.* FROM sdss:photoobjall s',
1651
+ Select.from_xml(@test6_doc.root).to_adqls)
1652
+ end
1653
+
1654
+ def test_test7
1655
+ assert_equal('SELECT b.objid, b.ra, b.dec, b.u, s.z AS sdssRS ' +
1656
+ 'FROM sdss:photoprimary b, sdss:specobjall s ' +
1657
+ 'WHERE ' +
1658
+ 's.specobjid = b.specobjid AND ' +
1659
+ 's.z > 1.8 AND ' +
1660
+ "Region('CIRCLE J2000 181.3 -0.76 30.0')",
1661
+ Select.from_xml(@test7_doc.root).to_adqls)
1662
+ end
1663
+ end
1664
+
1665
+ class ParserTest < Test::Unit::TestCase
1666
+ def test_construct
1667
+ assert_nothing_raised {
1668
+ select = Parser.new(File.new('test/adql/test3.adql')).parse
1669
+ select_s = Parser.convert_to_adqls(File.new('test/adql/test3.adql'))
1670
+ }
1671
+ end
1672
+ end