restful-capabilities 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Rakefile +111 -0
- data/bin/razorrisk-microservice-capabilities +57 -0
- data/lib/razor_risk/cassini/applications/microservices/restful/capabilities/app.rb +306 -0
- data/lib/razor_risk/cassini/applications/microservices/restful/capabilities/version.rb +43 -0
- data/lib/razor_risk/cassini/applications/microservices/restful/capabilities.rb +17 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/capabilities/data_subject_get.rb +65 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/capabilities/data_subjects_get.rb +59 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/capabilities/get_handler_mixin.rb +159 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/capabilities/group_get.rb +65 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/capabilities/group_users_get.rb +65 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/capabilities/groups_get.rb +59 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/capabilities/subject_get.rb +65 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/capabilities/subjects_get.rb +59 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/capabilities/user_get.rb +65 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/capabilities/users_get.rb +59 -0
- data/lib/razor_risk/cassini/applications/route_verb_adaptors/capabilities.rb +24 -0
- data/test/unit/adapters/tc_get_handler_mixin.rb +342 -0
- data/test/unit/microservice/tc_app.rb +765 -0
- metadata +254 -0
@@ -0,0 +1,765 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
#############################################################################
|
5
|
+
#
|
6
|
+
# Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
|
7
|
+
#
|
8
|
+
#############################################################################
|
9
|
+
|
10
|
+
$:.unshift File.join(File.dirname(__FILE__), *(['..'] * 3), 'lib')
|
11
|
+
|
12
|
+
ENV['APP_ENV'] = 'test'
|
13
|
+
ENV['RZ_EXPOSE_MICROSERVICE_EXCEPTIONS'] = 'true'
|
14
|
+
|
15
|
+
# ##########################################################
|
16
|
+
# requires
|
17
|
+
|
18
|
+
require 'razor_risk/cassini/testing/suppress_pantheios_logging' unless $DEBUG
|
19
|
+
|
20
|
+
require 'razor_risk/cassini/applications/microservices/restful/capabilities/app'
|
21
|
+
require 'razor_risk/razor/connectivity/test_doubles/razor_requester/raises_on_send'
|
22
|
+
require 'razor_risk/razor/connectivity/test_doubles/razor_requester/returns_given_response'
|
23
|
+
require 'razor_risk/razor/connectivity/razor_3/response'
|
24
|
+
|
25
|
+
require 'rack/test'
|
26
|
+
require 'test/unit'
|
27
|
+
|
28
|
+
# ##########################################################
|
29
|
+
# Tests
|
30
|
+
|
31
|
+
class TestCapabilitiesApp < Test::Unit::TestCase
|
32
|
+
|
33
|
+
include ::Rack::Test::Methods
|
34
|
+
|
35
|
+
include ::RazorRisk::Cassini::Applications::Microservices::RESTful
|
36
|
+
include ::RazorRisk::Razor::Connectivity::TestDoubles::RazorRequester
|
37
|
+
include ::RazorRisk::Razor::Connectivity::Razor3
|
38
|
+
include ::RazorRisk::Razor::Connectivity::EntityConnectors::Exceptions
|
39
|
+
|
40
|
+
RazorEnv = 'env'
|
41
|
+
|
42
|
+
def app
|
43
|
+
Capabilities::CapabilitiesApp
|
44
|
+
end
|
45
|
+
|
46
|
+
def set_razor_response body, **options
|
47
|
+
|
48
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
49
|
+
xml.razorOutbound(
|
50
|
+
environment: RazorEnv,
|
51
|
+
request: 'select',
|
52
|
+
server: 'DataServer',
|
53
|
+
) do
|
54
|
+
xml.requestReceivedTime '2020-09-09 14:20:33.844'
|
55
|
+
xml.responseSentTime '2019-09-09 14:20:33.911'
|
56
|
+
xml.responseReceivedTime '2019-09-09 14:20:33.917'
|
57
|
+
xml.returnCode (options[:failed] ? 'nack' : 'ack')
|
58
|
+
xml.parent << ::Nokogiri.XML(body).root
|
59
|
+
end
|
60
|
+
end.doc
|
61
|
+
|
62
|
+
rsp = Response.new(doc)
|
63
|
+
rr = ReturnsGivenResponse.new('conf', RazorEnv, given_response: rsp)
|
64
|
+
|
65
|
+
app.on_init_service(
|
66
|
+
razor_requester: rr,
|
67
|
+
request_options: options[:request_options],
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def configure_app **opts
|
72
|
+
opts = {
|
73
|
+
host: 'localhost',
|
74
|
+
port: 5679,
|
75
|
+
authentication_scheme: 'none',
|
76
|
+
executable: 'abc',
|
77
|
+
razor_requester: nil,
|
78
|
+
}.merge(opts)
|
79
|
+
|
80
|
+
app.init_service(**opts)
|
81
|
+
end
|
82
|
+
|
83
|
+
def setup
|
84
|
+
configure_app
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class TestCommon < TestCapabilitiesApp
|
89
|
+
|
90
|
+
# TODO: HEAD does the full razor request as if it is a GET, but returns
|
91
|
+
# empty. This is not ok and it must be changed not do the razor request.
|
92
|
+
|
93
|
+
# TODO: Currently cannot mock raising UnexpectedServerResponseException
|
94
|
+
# as due to restrictuions in RaisesOnSend exception must be a class.
|
95
|
+
|
96
|
+
Routes = {
|
97
|
+
'groups' => [ '/groups' ],
|
98
|
+
'group' => [ '/groups/id' ],
|
99
|
+
'users' => [ '/users' ],
|
100
|
+
'user' => [ '/users/-/id' ],
|
101
|
+
'group_users' => [ '/users/group_id' ],
|
102
|
+
'subjects' => [ '/subjects' ],
|
103
|
+
'subject' => [ '/subjects/id' ],
|
104
|
+
'data_subjects' => [ '/data-subjects' ],
|
105
|
+
'data_subject' => [ '/data-subjects/id' ],
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
class TestInvalidVerbs < TestCommon
|
110
|
+
|
111
|
+
InvalidVerbs = [ :post, :put, :delete, :options ]
|
112
|
+
|
113
|
+
InvalidVerbs.each do |verb|
|
114
|
+
Routes.each do |name, args|
|
115
|
+
define_method "test_#{verb}_#{name}" do
|
116
|
+
self.send(verb, *args)
|
117
|
+
assert_false last_response.ok?
|
118
|
+
assert_equal 404, last_response.status
|
119
|
+
assert_equal(
|
120
|
+
"'#{args.first}' [#{verb.to_s.upcase}] not found",
|
121
|
+
last_response.body
|
122
|
+
)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
class TestHeaders < TestCommon
|
129
|
+
|
130
|
+
Routes.each do |name, args|
|
131
|
+
define_method "test_#{name}_invalid_accept_type" do
|
132
|
+
set_razor_response('<body/>')
|
133
|
+
|
134
|
+
header 'Accept', 'image/png'
|
135
|
+
get(*args)
|
136
|
+
|
137
|
+
assert_false last_response.ok?, last_response.body
|
138
|
+
assert_equal 406, last_response.status
|
139
|
+
assert_match(/invalid accept type/, last_response.body)
|
140
|
+
end
|
141
|
+
|
142
|
+
define_method "test_#{name}_invalid_accept_types" do
|
143
|
+
set_razor_response('<body/>')
|
144
|
+
|
145
|
+
header 'Accept', [ 'image/png', 'application/pdf' ]
|
146
|
+
get(*args)
|
147
|
+
|
148
|
+
assert_false last_response.ok?, last_response.body
|
149
|
+
assert_equal 406, last_response.status
|
150
|
+
assert_match(/invalid accept type/, last_response.body)
|
151
|
+
end
|
152
|
+
|
153
|
+
define_method "test_#{name}_valid_accept_type" do
|
154
|
+
|
155
|
+
set_razor_response(
|
156
|
+
'<body/>',
|
157
|
+
request_options: { validate: false }
|
158
|
+
)
|
159
|
+
|
160
|
+
header 'Accept', 'application/xml'
|
161
|
+
get(*args)
|
162
|
+
|
163
|
+
assert last_response.ok?, last_response.body
|
164
|
+
assert_equal 200, last_response.status
|
165
|
+
assert_match(
|
166
|
+
/application\/xml/,
|
167
|
+
last_response.headers['Content-Type']
|
168
|
+
)
|
169
|
+
end
|
170
|
+
|
171
|
+
define_method "test_#{name}_valid_accept_types" do
|
172
|
+
|
173
|
+
set_razor_response(
|
174
|
+
'<body/>',
|
175
|
+
request_options: { validate: false }
|
176
|
+
)
|
177
|
+
|
178
|
+
header 'Accept', [ 'application/json', 'application/xml' ]
|
179
|
+
get(*args)
|
180
|
+
|
181
|
+
assert last_response.ok?, last_response.body
|
182
|
+
assert_equal 200, last_response.status
|
183
|
+
assert_match(
|
184
|
+
/application\/xml/,
|
185
|
+
last_response.headers['Content-Type']
|
186
|
+
)
|
187
|
+
end
|
188
|
+
|
189
|
+
define_method "test_#{name}_mixed_accept_types" do
|
190
|
+
|
191
|
+
set_razor_response(
|
192
|
+
'<body/>',
|
193
|
+
request_options: { validate: false }
|
194
|
+
)
|
195
|
+
|
196
|
+
header 'Accept', [ 'application/pdf', 'application/xml' ]
|
197
|
+
get(*args)
|
198
|
+
|
199
|
+
assert last_response.ok?, last_response.body
|
200
|
+
assert_equal 200, last_response.status
|
201
|
+
assert_match(
|
202
|
+
/application\/xml/,
|
203
|
+
last_response.headers['Content-Type']
|
204
|
+
)
|
205
|
+
end
|
206
|
+
|
207
|
+
define_method "test_#{name}_application_xml_accept_types" do
|
208
|
+
|
209
|
+
set_razor_response(
|
210
|
+
'<body/>',
|
211
|
+
request_options: { validate: false }
|
212
|
+
)
|
213
|
+
|
214
|
+
header 'Accept', 'application/xml'
|
215
|
+
get(*args)
|
216
|
+
|
217
|
+
assert last_response.ok?, last_response.body
|
218
|
+
assert_equal 200, last_response.status
|
219
|
+
assert_match(
|
220
|
+
/application\/xml/,
|
221
|
+
last_response.headers['Content-Type']
|
222
|
+
)
|
223
|
+
assert_equal '<body/>', last_response.body
|
224
|
+
end
|
225
|
+
|
226
|
+
define_method "test_#{name}_text_xml_accept_types" do
|
227
|
+
|
228
|
+
set_razor_response(
|
229
|
+
'<body/>',
|
230
|
+
request_options: { validate: false }
|
231
|
+
)
|
232
|
+
|
233
|
+
header 'Accept', 'text/xml'
|
234
|
+
get(*args)
|
235
|
+
|
236
|
+
assert last_response.ok?, last_response.body
|
237
|
+
assert_equal 200, last_response.status
|
238
|
+
assert_match(
|
239
|
+
/text\/xml/,
|
240
|
+
last_response.headers['Content-Type']
|
241
|
+
)
|
242
|
+
assert_equal '<body/>', last_response.body
|
243
|
+
end
|
244
|
+
|
245
|
+
define_method "test_#{name}_application_json_accept_types" do
|
246
|
+
|
247
|
+
set_razor_response(
|
248
|
+
'<body/>',
|
249
|
+
request_options: { validate: false }
|
250
|
+
)
|
251
|
+
|
252
|
+
header 'Accept', 'application/json'
|
253
|
+
get(*args)
|
254
|
+
|
255
|
+
assert last_response.ok?, last_response.body
|
256
|
+
assert_equal 200, last_response.status
|
257
|
+
assert_match(
|
258
|
+
/application\/json/,
|
259
|
+
last_response.headers['Content-Type']
|
260
|
+
)
|
261
|
+
assert_equal '{"body":[]}', last_response.body
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
class TestJSONConversion < TestCommon
|
267
|
+
|
268
|
+
Routes.each do |name, args|
|
269
|
+
|
270
|
+
define_method "test_#{name}_json_uses_gdata_scheme" do
|
271
|
+
|
272
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
273
|
+
xml.body do
|
274
|
+
xml.group 'value', id: 'group 1'
|
275
|
+
xml.group id: 'group 2'
|
276
|
+
end
|
277
|
+
end.doc.root.to_xml
|
278
|
+
set_razor_response(doc, request_options: { validate: false })
|
279
|
+
|
280
|
+
exp_doc = {
|
281
|
+
'body' => {
|
282
|
+
'group' => [
|
283
|
+
{ '$t' => 'value', 'id' => 'group 1' },
|
284
|
+
{ 'id' => 'group 2' }
|
285
|
+
]
|
286
|
+
}
|
287
|
+
}.to_json
|
288
|
+
|
289
|
+
header 'Accept', 'application/json'
|
290
|
+
get(*args)
|
291
|
+
|
292
|
+
assert last_response.ok?, last_response.body
|
293
|
+
assert_equal 200, last_response.status
|
294
|
+
assert_match(
|
295
|
+
/application\/json/,
|
296
|
+
last_response.headers['Content-Type']
|
297
|
+
)
|
298
|
+
assert_equal(
|
299
|
+
exp_doc,
|
300
|
+
last_response.body
|
301
|
+
)
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
class TestErrorHandling < TestCommon
|
307
|
+
|
308
|
+
Routes.each do |name, args|
|
309
|
+
|
310
|
+
define_method "test_#{name}_RZ0011_error" do
|
311
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
312
|
+
xml.errors do
|
313
|
+
xml.error do
|
314
|
+
xml.code 'RZ0011'
|
315
|
+
xml.message 'This failed'
|
316
|
+
xml.details 'This failed'
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end.doc.root.to_xml
|
320
|
+
set_razor_response doc, failed: true
|
321
|
+
|
322
|
+
get(*args)
|
323
|
+
|
324
|
+
assert_false last_response.ok?
|
325
|
+
assert_equal 404, last_response.status
|
326
|
+
assert_equal('This failed: This failed', last_response.body)
|
327
|
+
end
|
328
|
+
|
329
|
+
define_method "test_#{name}_razor_error" do
|
330
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
331
|
+
xml.body
|
332
|
+
end.doc.root.to_xml
|
333
|
+
set_razor_response doc, failed: true
|
334
|
+
|
335
|
+
get(*args)
|
336
|
+
|
337
|
+
assert_false last_response.ok?
|
338
|
+
assert_equal 500, last_response.status
|
339
|
+
assert_equal('Server Error', last_response.body)
|
340
|
+
end
|
341
|
+
|
342
|
+
define_method "test_#{name}_unknown_error" do
|
343
|
+
|
344
|
+
doc = '<body/>'
|
345
|
+
set_razor_response doc, failed: true
|
346
|
+
|
347
|
+
get(*args)
|
348
|
+
|
349
|
+
assert_false last_response.ok?
|
350
|
+
assert_equal 500, last_response.status
|
351
|
+
assert_equal('Server Error', last_response.body)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
class TestGroups < TestCapabilitiesApp
|
357
|
+
|
358
|
+
def test_validates_xml
|
359
|
+
|
360
|
+
doc = '<body/>'
|
361
|
+
set_razor_response(doc)
|
362
|
+
|
363
|
+
get '/groups'
|
364
|
+
|
365
|
+
assert_false last_response.ok?, last_response.body
|
366
|
+
assert_equal 404, last_response.status
|
367
|
+
assert_equal('Capabilities not found', last_response.body)
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_get
|
371
|
+
|
372
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
373
|
+
xml.body do
|
374
|
+
xml.group id: 'group 1'
|
375
|
+
xml.group id: 'group 2'
|
376
|
+
end
|
377
|
+
end.doc.root.to_xml
|
378
|
+
set_razor_response(doc)
|
379
|
+
|
380
|
+
get '/groups'
|
381
|
+
assert last_response.ok?
|
382
|
+
assert_equal 200, last_response.status
|
383
|
+
assert_equal doc, last_response.body
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
class TestGroup < TestCapabilitiesApp
|
388
|
+
|
389
|
+
def test_validates_xml
|
390
|
+
|
391
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
392
|
+
xml.body do
|
393
|
+
xml.capability id: 'cap 1'
|
394
|
+
xml.capability id: 'cap 2'
|
395
|
+
end
|
396
|
+
end.doc.root.to_xml
|
397
|
+
set_razor_response(doc)
|
398
|
+
|
399
|
+
get '/groups/id'
|
400
|
+
|
401
|
+
assert_false last_response.ok?, last_response.body
|
402
|
+
assert_equal 404, last_response.status
|
403
|
+
assert_equal('Capabilities not found', last_response.body)
|
404
|
+
end
|
405
|
+
|
406
|
+
def test_get
|
407
|
+
|
408
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
409
|
+
xml.body(id: 'id') do
|
410
|
+
xml.capability id: 'cap 1'
|
411
|
+
xml.capability id: 'cap 2'
|
412
|
+
end
|
413
|
+
end.doc.root.to_xml
|
414
|
+
set_razor_response(doc)
|
415
|
+
|
416
|
+
get '/groups/id'
|
417
|
+
|
418
|
+
assert last_response.ok?, last_response.body
|
419
|
+
assert_equal 200, last_response.status
|
420
|
+
assert_equal doc, last_response.body
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
class TestUsers < TestCapabilitiesApp
|
425
|
+
|
426
|
+
def test_validates_xml
|
427
|
+
|
428
|
+
doc = '<body/>'
|
429
|
+
set_razor_response(doc)
|
430
|
+
|
431
|
+
get '/users'
|
432
|
+
|
433
|
+
assert_false last_response.ok?, last_response.body
|
434
|
+
assert_equal 404, last_response.status
|
435
|
+
assert_equal('Capabilities not found', last_response.body)
|
436
|
+
end
|
437
|
+
|
438
|
+
def test_get
|
439
|
+
|
440
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
441
|
+
xml.body do
|
442
|
+
xml.user id: 'user 1' do
|
443
|
+
xml.groups do
|
444
|
+
xml.group id: 'group 1'
|
445
|
+
end
|
446
|
+
end
|
447
|
+
xml.user id: 'user 2' do
|
448
|
+
xml.groups do
|
449
|
+
xml.group id: 'group 2'
|
450
|
+
end
|
451
|
+
end
|
452
|
+
end
|
453
|
+
end.doc.root.to_xml
|
454
|
+
set_razor_response(doc)
|
455
|
+
|
456
|
+
get '/users'
|
457
|
+
assert last_response.ok?, last_response.body
|
458
|
+
assert_equal 200, last_response.status
|
459
|
+
assert_equal doc, last_response.body
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
class TestGroupUsers < TestCapabilitiesApp
|
464
|
+
|
465
|
+
def test_validates_xml
|
466
|
+
|
467
|
+
doc = '<body/>'
|
468
|
+
set_razor_response(doc)
|
469
|
+
|
470
|
+
get '/users/group_id'
|
471
|
+
|
472
|
+
assert_false last_response.ok?, last_response.body
|
473
|
+
assert_equal 404, last_response.status
|
474
|
+
assert_equal('Capabilities not found', last_response.body)
|
475
|
+
end
|
476
|
+
|
477
|
+
def test_validates_group_id
|
478
|
+
|
479
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
480
|
+
xml.body do
|
481
|
+
xml.user id: 'user 1' do
|
482
|
+
xml.groups do
|
483
|
+
xml.group id: 'group 1'
|
484
|
+
end
|
485
|
+
end
|
486
|
+
xml.user id: 'user 2' do
|
487
|
+
xml.groups do
|
488
|
+
xml.group id: 'group 2'
|
489
|
+
end
|
490
|
+
end
|
491
|
+
end
|
492
|
+
end.doc.root.to_xml
|
493
|
+
set_razor_response(doc)
|
494
|
+
|
495
|
+
get '/users/group%201'
|
496
|
+
|
497
|
+
assert_false last_response.ok?, last_response.body
|
498
|
+
assert_equal 500, last_response.status
|
499
|
+
assert_equal 'Server Error', last_response.body
|
500
|
+
end
|
501
|
+
|
502
|
+
def test_get
|
503
|
+
|
504
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
505
|
+
xml.body do
|
506
|
+
xml.user id: 'user 1' do
|
507
|
+
xml.groups do
|
508
|
+
xml.group id: 'group 1'
|
509
|
+
end
|
510
|
+
end
|
511
|
+
xml.user id: 'user 2' do
|
512
|
+
xml.groups do
|
513
|
+
xml.group id: 'group 1'
|
514
|
+
end
|
515
|
+
end
|
516
|
+
end
|
517
|
+
end.doc.root.to_xml
|
518
|
+
set_razor_response(doc)
|
519
|
+
|
520
|
+
get '/users/group%201'
|
521
|
+
|
522
|
+
assert last_response.ok?, last_response.body
|
523
|
+
assert_equal 200, last_response.status
|
524
|
+
assert_equal doc, last_response.body
|
525
|
+
end
|
526
|
+
|
527
|
+
def test_validates_multiple_group_ids
|
528
|
+
|
529
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
530
|
+
xml.body do
|
531
|
+
xml.user id: 'user 1' do
|
532
|
+
xml.groups do
|
533
|
+
xml.group id: 'group 2'
|
534
|
+
end
|
535
|
+
end
|
536
|
+
xml.user id: 'user 2' do
|
537
|
+
xml.groups do
|
538
|
+
xml.group id: 'group 1'
|
539
|
+
xml.group id: 'group 2'
|
540
|
+
end
|
541
|
+
end
|
542
|
+
end
|
543
|
+
end.doc.root.to_xml
|
544
|
+
set_razor_response(doc)
|
545
|
+
|
546
|
+
get '/users/group%202'
|
547
|
+
|
548
|
+
assert last_response.ok?, last_response.body
|
549
|
+
assert_equal 200, last_response.status
|
550
|
+
assert_equal doc, last_response.body
|
551
|
+
end
|
552
|
+
|
553
|
+
def test_case_sensitive_validation
|
554
|
+
|
555
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
556
|
+
xml.body do
|
557
|
+
xml.user id: 'user 1' do
|
558
|
+
xml.groups do
|
559
|
+
xml.group id: 'Group 1'
|
560
|
+
end
|
561
|
+
end
|
562
|
+
xml.user id: 'user 2' do
|
563
|
+
xml.groups do
|
564
|
+
xml.group id: 'group 1'
|
565
|
+
end
|
566
|
+
end
|
567
|
+
end
|
568
|
+
end.doc.root.to_xml
|
569
|
+
set_razor_response(doc)
|
570
|
+
|
571
|
+
get '/users/group%201'
|
572
|
+
|
573
|
+
assert_false last_response.ok?, last_response.body
|
574
|
+
assert_equal 500, last_response.status
|
575
|
+
assert_equal 'Server Error', last_response.body
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
class TestUser < TestCapabilitiesApp
|
580
|
+
|
581
|
+
def test_validates_xml
|
582
|
+
|
583
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
584
|
+
xml.body id: 'id1' do
|
585
|
+
xml.groups do
|
586
|
+
xml.group id: 'group 2'
|
587
|
+
end
|
588
|
+
end
|
589
|
+
end.doc.root.to_xml
|
590
|
+
set_razor_response(doc)
|
591
|
+
|
592
|
+
get '/users/-/id'
|
593
|
+
|
594
|
+
assert_false last_response.ok?, last_response.body
|
595
|
+
assert_equal 404, last_response.status
|
596
|
+
assert_equal('Capabilities not found', last_response.body)
|
597
|
+
end
|
598
|
+
|
599
|
+
def test_get
|
600
|
+
|
601
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
602
|
+
xml.body id: 'id' do
|
603
|
+
xml.groups do
|
604
|
+
xml.group id: 'group 2'
|
605
|
+
end
|
606
|
+
end
|
607
|
+
end.doc.root.to_xml
|
608
|
+
set_razor_response(doc)
|
609
|
+
|
610
|
+
get '/users/-/id'
|
611
|
+
|
612
|
+
assert last_response.ok?, last_response.body
|
613
|
+
assert_equal 200, last_response.status
|
614
|
+
assert_equal doc, last_response.body
|
615
|
+
end
|
616
|
+
end
|
617
|
+
|
618
|
+
class TestSubjects < TestCapabilitiesApp
|
619
|
+
|
620
|
+
def test_validates_xml
|
621
|
+
|
622
|
+
doc = '<body/>'
|
623
|
+
set_razor_response(doc)
|
624
|
+
|
625
|
+
get '/subjects'
|
626
|
+
|
627
|
+
assert_false last_response.ok?, last_response.body
|
628
|
+
assert_equal 404, last_response.status
|
629
|
+
assert_equal('Capabilities not found', last_response.body)
|
630
|
+
end
|
631
|
+
|
632
|
+
def test_get
|
633
|
+
|
634
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
635
|
+
xml.body do
|
636
|
+
xml.subject name: 'subject1' do
|
637
|
+
xml.action name: 'action1', code: 'a1'
|
638
|
+
end
|
639
|
+
xml.subject name: 'subject2' do
|
640
|
+
xml.action name: 'action2', code: 'a2'
|
641
|
+
end
|
642
|
+
end
|
643
|
+
end.doc.root.to_xml
|
644
|
+
set_razor_response(doc)
|
645
|
+
|
646
|
+
get '/subjects'
|
647
|
+
assert last_response.ok?, last_response.body
|
648
|
+
assert_equal 200, last_response.status
|
649
|
+
assert_equal doc, last_response.body
|
650
|
+
end
|
651
|
+
end
|
652
|
+
|
653
|
+
class TestSubject < TestCapabilitiesApp
|
654
|
+
|
655
|
+
def test_validates_xml
|
656
|
+
|
657
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
658
|
+
xml.body name: 'name1' do
|
659
|
+
xml.action name: 'action1', code: 'a1'
|
660
|
+
xml.action name: 'action2', code: 'a2'
|
661
|
+
end
|
662
|
+
end.doc.root.to_xml
|
663
|
+
set_razor_response(doc)
|
664
|
+
|
665
|
+
get '/subjects/name'
|
666
|
+
|
667
|
+
assert_false last_response.ok?, last_response.body
|
668
|
+
assert_equal 404, last_response.status
|
669
|
+
assert_equal('Capabilities not found', last_response.body)
|
670
|
+
end
|
671
|
+
|
672
|
+
def test_get
|
673
|
+
|
674
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
675
|
+
xml.body name: 'name' do
|
676
|
+
xml.action name: 'action1', code: 'a1'
|
677
|
+
xml.action name: 'action2', code: 'a2'
|
678
|
+
end
|
679
|
+
end.doc.root.to_xml
|
680
|
+
set_razor_response(doc)
|
681
|
+
|
682
|
+
get '/subjects/name'
|
683
|
+
|
684
|
+
assert last_response.ok?, last_response.body
|
685
|
+
assert_equal 200, last_response.status
|
686
|
+
assert_equal doc, last_response.body
|
687
|
+
end
|
688
|
+
end
|
689
|
+
|
690
|
+
class TestDataSubjects < TestCapabilitiesApp
|
691
|
+
|
692
|
+
def test_validates_xml
|
693
|
+
|
694
|
+
doc = '<body/>'
|
695
|
+
set_razor_response(doc)
|
696
|
+
|
697
|
+
get '/data-subjects'
|
698
|
+
|
699
|
+
assert_false last_response.ok?, last_response.body
|
700
|
+
assert_equal 404, last_response.status
|
701
|
+
assert_equal('Capabilities not found', last_response.body)
|
702
|
+
end
|
703
|
+
|
704
|
+
def test_get
|
705
|
+
|
706
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
707
|
+
xml.body do
|
708
|
+
xml.dataSubject name: 'subject1' do
|
709
|
+
xml.dataAction name: 'action1', code: 'a1'
|
710
|
+
end
|
711
|
+
xml.dataSubject name: 'subject2' do
|
712
|
+
xml.dataAction name: 'action2', code: 'a2'
|
713
|
+
end
|
714
|
+
end
|
715
|
+
end.doc.root.to_xml
|
716
|
+
set_razor_response(doc)
|
717
|
+
|
718
|
+
get '/data-subjects'
|
719
|
+
|
720
|
+
assert last_response.ok?, last_response.body
|
721
|
+
assert_equal 200, last_response.status
|
722
|
+
assert_equal doc, last_response.body
|
723
|
+
end
|
724
|
+
end
|
725
|
+
|
726
|
+
class TestDataSubject < TestCapabilitiesApp
|
727
|
+
|
728
|
+
def test_validates_xml
|
729
|
+
|
730
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
731
|
+
xml.body name: 'name1' do
|
732
|
+
xml.dataAction name: 'action1', code: 'a1'
|
733
|
+
xml.dataAction name: 'action2', code: 'a2'
|
734
|
+
end
|
735
|
+
end.doc.root.to_xml
|
736
|
+
set_razor_response(doc)
|
737
|
+
|
738
|
+
get '/data-subjects/name'
|
739
|
+
|
740
|
+
assert_false last_response.ok?, last_response.body
|
741
|
+
assert_equal 404, last_response.status
|
742
|
+
assert_equal('Capabilities not found', last_response.body)
|
743
|
+
end
|
744
|
+
|
745
|
+
def test_get
|
746
|
+
|
747
|
+
doc = ::Nokogiri::XML::Builder.new do |xml|
|
748
|
+
xml.body name: 'name' do
|
749
|
+
xml.dataAction name: 'action1', code: 'a1'
|
750
|
+
xml.dataAction name: 'action2', code: 'a2'
|
751
|
+
end
|
752
|
+
end.doc.root.to_xml
|
753
|
+
set_razor_response(doc)
|
754
|
+
|
755
|
+
get '/data-subjects/name'
|
756
|
+
|
757
|
+
assert last_response.ok?, last_response.body
|
758
|
+
assert_equal 200, last_response.status
|
759
|
+
assert_equal doc, last_response.body
|
760
|
+
end
|
761
|
+
end
|
762
|
+
|
763
|
+
# ############################## end of file ############################# #
|
764
|
+
|
765
|
+
|