Mercurial > repos > greg > greg_sparql
comparison sparql-7785ad38967f/sparql/spec/executor_spec.rb @ 0:46996d3b1cfb default tip
Uploaded
author | greg |
---|---|
date | Tue, 13 Mar 2012 16:29:09 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:46996d3b1cfb |
---|---|
1 # -*- coding: utf-8 -*- | |
2 require File.expand_path('../executor', File.dirname(__FILE__)) | |
3 | |
4 describe SPARQLExecutor, "は" do | |
5 include GalaxyTool::Matcher | |
6 | |
7 before do | |
8 @tool = SPARQLExecutor.new | |
9 end | |
10 | |
11 it "SPARQLエンドポイント指定として '-e' オプションを受けつける" do | |
12 @tool.should accept_option_with_argument(:endpoint, '-e') | |
13 end | |
14 it "SPARQLエンドポイント指定として '--endpoint' オプションを受けつける" do | |
15 @tool.should accept_option_with_argument(:endpoint, '--endpoint') | |
16 end | |
17 it "'--endpoint' オプションを、前後空白を無視して受けつける" do | |
18 @tool.should evaluate_option('--endpoint', " http://example.com/endpoint\n", "http://example.com/endpoint") | |
19 end | |
20 it "クエリ指定は必須である" do | |
21 @tool.should require_option(:endpoint) | |
22 end | |
23 | |
24 it "クエリ指定として '-q' オプションを受けつける" do | |
25 @tool.should accept_option_with_argument(:query, '-q') | |
26 end | |
27 it "クエリ指定として '--query' オプションを受けつける" do | |
28 @tool.should accept_option_with_argument(:query, '--query') | |
29 end | |
30 it "クエリ指定として '--query-file' オプションを受けつける" do | |
31 @tool.should accept_option_with_argument(:query, '--query-file') | |
32 end | |
33 it "'--query-file' オプションを、クエリが書かれたファイルのパスとして受けつける" do | |
34 @tool.should evaluate_option('--query-file', stub_file("p53\n").path, 'p53') | |
35 end | |
36 it "クエリ指定は必須である" do | |
37 @tool.should require_option(:query) | |
38 end | |
39 | |
40 it "出力先指定として '-o' オプションを受けつける" do | |
41 @tool.should accept_option_with_argument(:output, '-o') | |
42 end | |
43 it "出力先指定として '--output' オプションを受けつける" do | |
44 @tool.should accept_option_with_argument(:output, '--output') | |
45 end | |
46 it "出力先指定は必須である" do | |
47 @tool.should require_option(:output) | |
48 end | |
49 | |
50 it "Info出力先指定として '--info' オプションを受けつける" do | |
51 @tool.should accept_option_with_argument(:info, '--info') | |
52 end | |
53 it "Info出力先の規定値は標準出力である" do | |
54 @tool.should set_default_option_value(:info, '/dev/stdout') | |
55 end | |
56 | |
57 describe "エンドポイント、クエリ、出力先を指定して実行すると" do | |
58 before do | |
59 @tool.should_receive(:search).and_return do |client, query| | |
60 client.should_receive(:parsed_xml) do |parse| | |
61 REXML::Document.new(<<-EOT).root | |
62 <?xml version="1.0" ?> | |
63 <sparql xmlns="http://www.w3.org/2005/sparql-results#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/sw/DataAccess/rf1/result2.xsd"> | |
64 <head> | |
65 <variable name="s"/> | |
66 <variable name="p"/> | |
67 <variable name="o"/> | |
68 </head> | |
69 <results distinct="false" ordered="true"> | |
70 <result> | |
71 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-uri-fn</uri></binding> | |
72 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfLongTmpl</uri></binding> | |
73 <binding name="o"><literal> ^{custom-verbatim-1}^_INVERSE (__id2in (^{tree}^))</literal></binding> | |
74 </result> | |
75 <result> | |
76 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-uri-fn</uri></binding> | |
77 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfUriTmpl</uri></binding> | |
78 <binding name="o"><literal> ^{custom-verbatim-1}^_INVERSE (^{tree}^)</literal></binding> | |
79 </result> | |
80 <result> | |
81 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-literal-fn</uri></binding> | |
82 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfUriTmpl</uri></binding> | |
83 <binding name="o"><literal> ^{custom-verbatim-1}^_INVERSE (^{tree}^)</literal></binding> | |
84 </result> | |
85 <result> | |
86 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-literal-fn</uri></binding> | |
87 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfLongTmpl</uri></binding> | |
88 <binding name="o"><literal> ^{custom-verbatim-1}^_INVERSE (__ro2sq /*l*/ (^{tree}^))</literal></binding> | |
89 </result> | |
90 <result> | |
91 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-dt</uri></binding> | |
92 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfSqlvalTmpl</uri></binding> | |
93 <binding name="o"><literal> ^{sqlval-of-tree}^^{as-name-0}^^{comma-cut}^NULL^{as-name-1}^</literal></binding> | |
94 </result> | |
95 </results> | |
96 </sparql> | |
97 EOT | |
98 end | |
99 | |
100 client.query(query) | |
101 end | |
102 | |
103 @url = "http://www.semantic-systems-biology.org/biogateway/endpoint" | |
104 @query = "select * where { ?s ?p ?o . } limit 5" | |
105 @info = stub_stdout | |
106 @output = stub_file | |
107 @tool.run ["-q", @query, "-e", @url, "-o", @output.path] | |
108 end | |
109 | |
110 it "SPARQL検索を行い、ID、URL、タイトル、ランクをタブ区切りで表示する" do | |
111 @output.should be_output(<<-EOT) | |
112 ?s ?p ?o | |
113 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-uri-fn> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfLongTmpl> " ^{custom-verbatim-1}^_INVERSE (__id2in (^{tree}^))" | |
114 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-uri-fn> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfUriTmpl> " ^{custom-verbatim-1}^_INVERSE (^{tree}^)" | |
115 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-literal-fn> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfUriTmpl> " ^{custom-verbatim-1}^_INVERSE (^{tree}^)" | |
116 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-literal-fn> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfLongTmpl> " ^{custom-verbatim-1}^_INVERSE (__ro2sq /*l*/ (^{tree}^))" | |
117 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-dt> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfSqlvalTmpl> " ^{sqlval-of-tree}^^{as-name-0}^^{comma-cut}^NULL^{as-name-1}^" | |
118 EOT | |
119 end | |
120 end | |
121 | |
122 describe "結果の途中に改行のテキストノードを含むレスポンスを得るようなエンドポイントに対するクエリだったとしても" do | |
123 before do | |
124 @tool.should_receive(:search).and_return do |client, query| | |
125 client.should_receive(:parsed_xml) do |parse| | |
126 REXML::Document.new(<<-EOT).root | |
127 <?xml version="1.0" ?> | |
128 <sparql xmlns="http://www.w3.org/2005/sparql-results#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/sw/DataAccess/rf1/result2.xsd"> | |
129 <head> | |
130 <variable name="s"/> | |
131 <variable name="p"/> | |
132 <variable name="o"/> | |
133 </head> | |
134 <results distinct="false" ordered="true"> | |
135 <result> | |
136 <binding name="s"> | |
137 <uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-uri-fn</uri> | |
138 </binding> | |
139 <binding name="p"> | |
140 <uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfLongTmpl</uri> | |
141 </binding> | |
142 <binding name="o"> | |
143 <literal> ^{custom-verbatim-1}^_INVERSE (__id2in (^{tree}^))</literal> | |
144 </binding> | |
145 </result> | |
146 <result> | |
147 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-uri-fn</uri></binding> | |
148 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfUriTmpl</uri></binding> | |
149 <binding name="o"><literal> ^{custom-verbatim-1}^_INVERSE (^{tree}^)</literal></binding> | |
150 </result> | |
151 <result> | |
152 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-literal-fn</uri></binding> | |
153 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfUriTmpl</uri></binding> | |
154 <binding name="o"><literal> ^{custom-verbatim-1}^_INVERSE (^{tree}^)</literal></binding> | |
155 </result> | |
156 <result> | |
157 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-literal-fn</uri></binding> | |
158 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfLongTmpl</uri></binding> | |
159 <binding name="o"><literal> ^{custom-verbatim-1}^_INVERSE (__ro2sq /*l*/ (^{tree}^))</literal></binding> | |
160 </result> | |
161 <result> | |
162 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-dt</uri></binding> | |
163 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfSqlvalTmpl</uri></binding> | |
164 <binding name="o"><literal> ^{sqlval-of-tree}^^{as-name-0}^^{comma-cut}^NULL^{as-name-1}^</literal></binding> | |
165 </result> | |
166 </results> | |
167 </sparql> | |
168 EOT | |
169 end | |
170 | |
171 client.query(query) | |
172 end | |
173 | |
174 @url = "http://www.semantic-systems-biology.org/biogateway/endpoint" | |
175 @query = "select * where { ?s ?p ?o . } limit 5" | |
176 @info = stub_stdout | |
177 @output = stub_file | |
178 @tool.run ["-q", @query, "-e", @url, "-o", @output.path] | |
179 end | |
180 | |
181 it "SPARQL検索を行い、ID、URL、タイトル、ランクをタブ区切りで表示する" do | |
182 @output.should be_output(<<-EOT) | |
183 ?s ?p ?o | |
184 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-uri-fn> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfLongTmpl> " ^{custom-verbatim-1}^_INVERSE (__id2in (^{tree}^))" | |
185 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-uri-fn> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfUriTmpl> " ^{custom-verbatim-1}^_INVERSE (^{tree}^)" | |
186 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-literal-fn> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfUriTmpl> " ^{custom-verbatim-1}^_INVERSE (^{tree}^)" | |
187 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-literal-fn> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfLongTmpl> " ^{custom-verbatim-1}^_INVERSE (__ro2sq /*l*/ (^{tree}^))" | |
188 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-dt> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfSqlvalTmpl> " ^{sqlval-of-tree}^^{as-name-0}^^{comma-cut}^NULL^{as-name-1}^" | |
189 EOT | |
190 end | |
191 end | |
192 | |
193 describe "Blank Nodeを含むレスポンスとなるクエリだったとしても" do | |
194 before do | |
195 @tool.should_receive(:search).and_return do |client, query| | |
196 client.should_receive(:parsed_xml) do |parse| | |
197 REXML::Document.new(<<-EOT).root | |
198 <?xml version="1.0" ?> | |
199 <sparql xmlns="http://www.w3.org/2005/sparql-results#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/2001/sw/DataAccess/rf1/result2.xsd"> | |
200 <head> | |
201 <variable name="s"/> | |
202 <variable name="p"/> | |
203 <variable name="o"/> | |
204 </head> | |
205 <results distinct="false" ordered="true"> | |
206 <result> | |
207 <binding name="s"> | |
208 <bnode>nodeID://b196899188</bnode> | |
209 </binding> | |
210 <binding name="p"> | |
211 <uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfLongTmpl</uri> | |
212 </binding> | |
213 <binding name="o"> | |
214 <literal> ^{custom-verbatim-1}^_INVERSE (__id2in (^{tree}^))</literal> | |
215 </binding> | |
216 </result> | |
217 <result> | |
218 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-uri-fn</uri></binding> | |
219 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfUriTmpl</uri></binding> | |
220 <binding name="o"><literal> ^{custom-verbatim-1}^_INVERSE (^{tree}^)</literal></binding> | |
221 </result> | |
222 <result> | |
223 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-literal-fn</uri></binding> | |
224 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfUriTmpl</uri></binding> | |
225 <binding name="o"><literal> ^{custom-verbatim-1}^_INVERSE (^{tree}^)</literal></binding> | |
226 </result> | |
227 <result> | |
228 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-literal-fn</uri></binding> | |
229 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfLongTmpl</uri></binding> | |
230 <binding name="o"><literal> ^{custom-verbatim-1}^_INVERSE (__ro2sq /*l*/ (^{tree}^))</literal></binding> | |
231 </result> | |
232 <result> | |
233 <binding name="s"><uri>http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-dt</uri></binding> | |
234 <binding name="p"><uri>http://www.openlinksw.com/schemas/virtrdf#qmfShortOfSqlvalTmpl</uri></binding> | |
235 <binding name="o"><literal> ^{sqlval-of-tree}^^{as-name-0}^^{comma-cut}^NULL^{as-name-1}^</literal></binding> | |
236 </result> | |
237 </results> | |
238 </sparql> | |
239 EOT | |
240 end | |
241 | |
242 client.query(query) | |
243 end | |
244 | |
245 @url = "http://www.semantic-systems-biology.org/biogateway/endpoint" | |
246 @query = "select * where { ?s ?p ?o . } limit 5" | |
247 @info = stub_stdout | |
248 @output = stub_file | |
249 @tool.run ["-q", @query, "-e", @url, "-o", @output.path] | |
250 end | |
251 | |
252 it "SPARQL検索を行い、ID、URL、タイトル、ランクをタブ区切りで表示する" do | |
253 @output.should be_output(<<-EOT) | |
254 ?s ?p ?o | |
255 _:nodeID://b196899188 <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfLongTmpl> " ^{custom-verbatim-1}^_INVERSE (__id2in (^{tree}^))" | |
256 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-uri-fn> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfUriTmpl> " ^{custom-verbatim-1}^_INVERSE (^{tree}^)" | |
257 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-literal-fn> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfUriTmpl> " ^{custom-verbatim-1}^_INVERSE (^{tree}^)" | |
258 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-literal-fn> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfLongTmpl> " ^{custom-verbatim-1}^_INVERSE (__ro2sq /*l*/ (^{tree}^))" | |
259 <http://www.openlinksw.com/virtrdf-data-formats#sql-varchar-dt> <http://www.openlinksw.com/schemas/virtrdf#qmfShortOfSqlvalTmpl> " ^{sqlval-of-tree}^^{as-name-0}^^{comma-cut}^NULL^{as-name-1}^" | |
260 EOT | |
261 end | |
262 end | |
263 | |
264 end |