orchestrate 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/README.md +28 -20
- data/lib/orchestrate/api/errors.rb +114 -52
- data/lib/orchestrate/api/helpers.rb +48 -0
- data/lib/orchestrate/api/response.rb +111 -0
- data/lib/orchestrate/api.rb +4 -6
- data/lib/orchestrate/client.rb +290 -302
- data/lib/orchestrate/version.rb +1 -1
- data/lib/orchestrate.rb +0 -37
- data/test/orchestrate/api/collections_test.rb +28 -6
- data/test/orchestrate/api/event_test.rb +85 -20
- data/test/orchestrate/api/exceptions_test.rb +172 -0
- data/test/orchestrate/api/graph_test.rb +4 -0
- data/test/orchestrate/api/key_value_test.rb +52 -7
- data/test/orchestrate/api/response_test.rb +36 -0
- data/test/orchestrate/client_test.rb +15 -16
- data/test/test_helper.rb +4 -9
- metadata +10 -6
- data/lib/orchestrate/configuration.rb +0 -53
- data/lib/orchestrate/helpers.rb +0 -22
- data/test/orchestrate/configuration_test.rb +0 -67
data/lib/orchestrate/version.rb
CHANGED
data/lib/orchestrate.rb
CHANGED
@@ -1,46 +1,9 @@
|
|
1
1
|
require "orchestrate/api"
|
2
2
|
require "orchestrate/client"
|
3
|
-
require "orchestrate/configuration"
|
4
|
-
require "orchestrate/helpers"
|
5
3
|
require "orchestrate/version"
|
6
4
|
|
7
5
|
#
|
8
6
|
# A library for supporting connections to the \Orchestrate API.
|
9
7
|
#
|
10
8
|
module Orchestrate
|
11
|
-
|
12
|
-
# Configuration ------------------------------------------------------------
|
13
|
-
|
14
|
-
class << self
|
15
|
-
|
16
|
-
#
|
17
|
-
# An instance of Configuration containing the current library
|
18
|
-
# configuration options.
|
19
|
-
#
|
20
|
-
attr_accessor :config
|
21
|
-
|
22
|
-
#
|
23
|
-
# Lazily initialize and return the Configuration instance.
|
24
|
-
#
|
25
|
-
def config # :nodoc:
|
26
|
-
@config ||= Configuration.new
|
27
|
-
end
|
28
|
-
|
29
|
-
#
|
30
|
-
# Configure the Orchestrate library. This method should be called during
|
31
|
-
# application or script initialization. At a bare minimum, the Orchestrate
|
32
|
-
# library will require that an API key is provided.
|
33
|
-
#
|
34
|
-
# ==== Example
|
35
|
-
#
|
36
|
-
# Orchestrate.configure do |config|
|
37
|
-
# config.api_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
38
|
-
# end
|
39
|
-
#
|
40
|
-
def configure
|
41
|
-
yield config
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
9
|
end
|
@@ -18,10 +18,13 @@ class CollectionTest < MiniTest::Unit::TestCase
|
|
18
18
|
response = @client.delete_collection(@collection)
|
19
19
|
assert_equal 204, response.status
|
20
20
|
assert_equal '', response.body
|
21
|
+
assert_equal response.headers['X-Orchestrate-Req-Id'], response.request_id
|
21
22
|
end
|
22
23
|
|
23
24
|
def test_lists_collection_without_params
|
24
|
-
body = {"count" =>
|
25
|
+
body = {"count" => 1, "results" => [
|
26
|
+
{ "value" => {"value" => "one"}, "path" => {}, "reftime" => "" }
|
27
|
+
], "next" => "/v0/#{@collection}?afterKey=one"}
|
25
28
|
|
26
29
|
@stubs.get("/v0/#{@collection}") do |env|
|
27
30
|
assert_authorization @basic_auth, env
|
@@ -32,10 +35,14 @@ class CollectionTest < MiniTest::Unit::TestCase
|
|
32
35
|
response = @client.list(@collection)
|
33
36
|
assert_equal 200, response.status
|
34
37
|
assert_equal body, response.body
|
38
|
+
assert_equal response.headers['X-Orchestrate-Req-Id'], response.request_id
|
39
|
+
assert_equal body['count'], response.count
|
40
|
+
assert_equal body['results'], response.results
|
41
|
+
assert_equal body['next'], response.next_link
|
35
42
|
end
|
36
43
|
|
37
44
|
def test_lists_collections_with_params_passes_them
|
38
|
-
body = {"count" => 0, "results" => []
|
45
|
+
body = {"count" => 0, "results" => []}
|
39
46
|
@stubs.get("/v0/#{@collection}") do |env|
|
40
47
|
assert_authorization @basic_auth, env
|
41
48
|
assert_accepts_json env
|
@@ -48,11 +55,13 @@ class CollectionTest < MiniTest::Unit::TestCase
|
|
48
55
|
response = @client.list(@collection, {limit:1, start: 'foo'})
|
49
56
|
assert_equal 200, response.status
|
50
57
|
assert_equal body, response.body
|
58
|
+
assert_nil response.next_link
|
51
59
|
end
|
52
60
|
|
53
61
|
def test_search_with_simple_query
|
54
62
|
query = 'text:"The Right Way" and go'
|
55
|
-
body = {
|
63
|
+
body = { "count" => 1, "total_count" => 1,
|
64
|
+
"results" => [{"path" => {}, "score" => 0.5 }] }
|
56
65
|
|
57
66
|
@stubs.get("/v0/#{@collection}") do |env|
|
58
67
|
assert_authorization @basic_auth, env
|
@@ -64,24 +73,37 @@ class CollectionTest < MiniTest::Unit::TestCase
|
|
64
73
|
response = @client.search(@collection, query)
|
65
74
|
assert_equal 200, response.status
|
66
75
|
assert_equal body, response.body
|
76
|
+
assert_equal body['count'], response.count
|
77
|
+
assert_equal body['total_count'], response.total_count
|
78
|
+
assert_equal body['results'], response.results
|
79
|
+
assert_nil response.next_link
|
80
|
+
assert_nil response.prev_link
|
67
81
|
end
|
68
82
|
|
69
83
|
def test_search_with_extra_params
|
70
84
|
query = 'text:"The Right Way" and go'
|
71
|
-
body = { "results" => [
|
85
|
+
body = { "results" => [{"value" => {}, "path" => {}, "score" => 0.5}],
|
86
|
+
"count" => 1, "total_count" => 10,
|
87
|
+
"next" => "/v0/#{@collection}?limit=1&offset=4&query=__query__",
|
88
|
+
"prev" => "/v0/#{@collection}?limit=1&offset=2&query=__query__" }
|
72
89
|
|
73
90
|
@stubs.get("/v0/#{@collection}") do |env|
|
74
91
|
assert_authorization @basic_auth, env
|
75
92
|
assert_accepts_json env
|
76
93
|
assert_equal query, env.params['query']
|
77
94
|
assert_equal '3', env.params['offset']
|
78
|
-
assert_equal '
|
95
|
+
assert_equal '1', env.params['limit']
|
79
96
|
[ 200, response_headers, body.to_json]
|
80
97
|
end
|
81
98
|
|
82
|
-
response = @client.search(@collection, query, {offset: 3, limit:
|
99
|
+
response = @client.search(@collection, query, {offset: 3, limit: 1})
|
83
100
|
assert_equal 200, response.status
|
84
101
|
assert_equal body, response.body
|
102
|
+
assert_equal body['results'], response.results
|
103
|
+
assert_equal body['count'], response.count
|
104
|
+
assert_equal body['total_count'], response.total_count
|
105
|
+
assert_equal body['next'], response.next_link
|
106
|
+
assert_equal body['prev'], response.prev_link
|
85
107
|
end
|
86
108
|
|
87
109
|
end
|
@@ -7,70 +7,125 @@ class EventTest < MiniTest::Unit::TestCase
|
|
7
7
|
@key = 'instance'
|
8
8
|
@client, @stubs, @basic_auth = make_client_and_artifacts
|
9
9
|
@event_type = "commits"
|
10
|
-
@
|
10
|
+
@time = Time.now
|
11
|
+
@timestamp = (@time.to_f * 1000).to_i
|
11
12
|
@ordinal = 5
|
12
13
|
end
|
13
14
|
|
14
15
|
def test_get_event
|
15
|
-
|
16
|
-
|
16
|
+
ref = "12345"
|
17
|
+
value = {"msg" => "hello"}
|
18
|
+
path = { "collection" => @collection, "key" => @key, "type" => @event_type,
|
19
|
+
"ref" => "\"#{ref}\"", "timestamp" => @timestamp, "ordinal" => @ordinal }
|
20
|
+
body = { "path" => path, "value" => value, "timestamp" => @timestamp, "ordinal" => @ordinal }
|
21
|
+
location = ["/v0", @collection, @key, "events", @event_type, @timestamp, @ordinal].join('/')
|
22
|
+
@stubs.get(location) do |env|
|
17
23
|
assert_authorization @basic_auth, env
|
18
24
|
assert_accepts_json env
|
19
|
-
|
25
|
+
headers = { "Etag" => "\"#{ref}\"" }
|
26
|
+
[200, response_headers(headers), body.to_json]
|
20
27
|
end
|
21
28
|
|
22
29
|
response = @client.get_event(@collection, @key, @event_type, @timestamp, @ordinal)
|
23
30
|
assert_equal 200, response.status
|
24
31
|
assert_equal body, response.body
|
32
|
+
assert_equal ref, response.ref
|
33
|
+
# assert_equal location, response.location
|
34
|
+
assert_equal Time.parse(response.headers['Date']), response.request_time
|
35
|
+
assert_equal response.headers['X-Orchestrate-Req-Id'], response.request_id
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_get_event_with_time
|
39
|
+
time = Time.now
|
40
|
+
ts = (time.getutc.to_f * 1000).to_i
|
41
|
+
@stubs.get("/v0/#{@collection}/#{@key}/events/#{@event_type}/#{ts}/#{@ordinal}") do |env|
|
42
|
+
assert_authorization @basic_auth, env
|
43
|
+
assert_accepts_json env
|
44
|
+
[ 200, response_headers, {}.to_json ]
|
45
|
+
end
|
46
|
+
|
47
|
+
response = @client.get_event(@collection, @key, @event_type, time, @ordinal)
|
48
|
+
assert_equal 200, response.status
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_get_event_with_datetime
|
52
|
+
time = DateTime.now
|
53
|
+
ts = (time.to_time.getutc.to_f * 1000).to_i
|
54
|
+
@stubs.get("/v0/#{@collection}/#{@key}/events/#{@event_type}/#{ts}/#{@ordinal}") do |env|
|
55
|
+
assert_authorization @basic_auth, env
|
56
|
+
assert_accepts_json env
|
57
|
+
[ 200, response_headers, {}.to_json ]
|
58
|
+
end
|
59
|
+
response = @client.get_event(@collection, @key, @event_type, time, @ordinal)
|
60
|
+
assert_equal 200, response.status
|
25
61
|
end
|
26
62
|
|
27
63
|
def test_post_event_without_timestamp
|
28
64
|
event = {"msg" => "hello"}
|
65
|
+
ref = "12345"
|
66
|
+
location = ["/v0",@collection,@key,'events',@event_type,@timestamp,@ordinal].join('/')
|
29
67
|
@stubs.post("/v0/#{@collection}/#{@key}/events/#{@event_type}") do |env|
|
30
68
|
assert_authorization @basic_auth, env
|
31
69
|
assert_equal event.to_json, env.body
|
32
|
-
|
70
|
+
headers = { "Etag" => "\"#{ref}\"", "Location" => location }
|
71
|
+
[204, response_headers(headers), '']
|
33
72
|
end
|
34
73
|
|
35
74
|
response = @client.post_event(@collection, @key, @event_type, event)
|
36
75
|
assert_equal 204, response.status
|
76
|
+
assert_equal location, response.location
|
77
|
+
assert_equal ref, response.ref
|
37
78
|
end
|
38
79
|
|
39
80
|
def test_post_event_with_timestamp
|
40
81
|
event = {"msg" => "hello"}
|
82
|
+
ref = "12345"
|
83
|
+
location = ["/v0",@collection,@key,'events',@event_type,@timestamp,@ordinal].join('/')
|
41
84
|
@stubs.post("/v0/#{@collection}/#{@key}/events/#{@event_type}/#{@timestamp}") do |env|
|
42
85
|
assert_authorization @basic_auth, env
|
43
86
|
assert_equal event.to_json, env.body
|
44
|
-
|
87
|
+
headers = { "Etag" => "\"#{ref}\"", "Location" => location }
|
88
|
+
[204, response_headers(headers), '']
|
45
89
|
end
|
46
90
|
|
47
|
-
response = @client.post_event(@collection, @key, @event_type, event, @
|
91
|
+
response = @client.post_event(@collection, @key, @event_type, event, @time)
|
48
92
|
assert_equal 204, response.status
|
93
|
+
assert_equal location, response.location
|
94
|
+
assert_equal ref, response.ref
|
49
95
|
end
|
50
96
|
|
51
97
|
def test_put_event_without_ref
|
52
98
|
event = {"msg" => "hello"}
|
99
|
+
ref = "12345"
|
100
|
+
location = ["/v0",@collection,@key,'events',@event_type,@timestamp,@ordinal].join('/')
|
53
101
|
@stubs.put("/v0/#{@collection}/#{@key}/events/#{@event_type}/#{@timestamp}/#{@ordinal}") do |env|
|
54
102
|
assert_authorization @basic_auth, env
|
55
103
|
assert_equal event.to_json, env.body
|
56
|
-
|
104
|
+
headers = { "Etag" => "\"#{ref}\"", "Location" => location }
|
105
|
+
[204, response_headers(headers), '']
|
57
106
|
end
|
58
|
-
response = @client.put_event(@collection, @key, @event_type, @
|
107
|
+
response = @client.put_event(@collection, @key, @event_type, @time, @ordinal, event)
|
59
108
|
assert_equal 204, response.status
|
109
|
+
assert_equal location, response.location
|
110
|
+
assert_equal ref, response.ref
|
60
111
|
end
|
61
112
|
|
62
113
|
def test_put_event_with_ref
|
63
114
|
event = {"msg" => "hello"}
|
64
115
|
ref = "12345"
|
65
|
-
|
116
|
+
new_ref = "abcde"
|
117
|
+
path = ['/v0', @collection, @key, 'events', @event_type, @timestamp, @ordinal]
|
66
118
|
@stubs.put(path.join("/")) do |env|
|
67
119
|
assert_authorization @basic_auth, env
|
68
120
|
assert_header 'If-Match', "\"#{ref}\"", env
|
69
121
|
assert_equal event.to_json, env.body
|
70
|
-
|
122
|
+
headers = { "Etag" => "\"#{new_ref}\"", "Location" => path.join('/') }
|
123
|
+
[204, response_headers(headers), '']
|
71
124
|
end
|
72
|
-
response = @client.put_event(@collection, @key, @event_type, @
|
125
|
+
response = @client.put_event(@collection, @key, @event_type, @time, @ordinal, event, ref)
|
73
126
|
assert_equal 204, response.status
|
127
|
+
assert_equal new_ref, response.ref
|
128
|
+
assert_equal path.join('/'), response.location
|
74
129
|
end
|
75
130
|
|
76
131
|
def test_purge_event_without_ref
|
@@ -80,8 +135,9 @@ class EventTest < MiniTest::Unit::TestCase
|
|
80
135
|
assert_equal 'true', env.params['purge']
|
81
136
|
[204, response_headers, '']
|
82
137
|
end
|
83
|
-
response = @client.purge_event(@collection, @key, @event_type, @
|
138
|
+
response = @client.purge_event(@collection, @key, @event_type, @time, @ordinal)
|
84
139
|
assert_equal 204, response.status
|
140
|
+
assert_equal response.headers['X-Orchestrate-Req-Id'], response.request_id
|
85
141
|
end
|
86
142
|
|
87
143
|
def test_purge_event_with_ref
|
@@ -93,12 +149,14 @@ class EventTest < MiniTest::Unit::TestCase
|
|
93
149
|
assert_equal 'true', env.params['purge']
|
94
150
|
[204, response_headers, '']
|
95
151
|
end
|
96
|
-
response = @client.purge_event(@collection, @key, @event_type, @
|
152
|
+
response = @client.purge_event(@collection, @key, @event_type, @time, @ordinal, ref)
|
97
153
|
assert_equal 204, response.status
|
154
|
+
assert_equal response.headers['X-Orchestrate-Req-Id'], response.request_id
|
98
155
|
end
|
99
156
|
|
100
157
|
def test_list_events_without_timestamp
|
101
|
-
body = { "results" => [
|
158
|
+
body = { "results" => [{"path"=>{}, "value"=>{}, "timestamp"=>"", "ordinal"=>0}],
|
159
|
+
"count" => 0, "next" => "__NEXT__" }
|
102
160
|
@stubs.get("/v0/#{@collection}/#{@key}/events/#{@event_type}") do |env|
|
103
161
|
assert_authorization @basic_auth, env
|
104
162
|
assert_accepts_json env
|
@@ -108,26 +166,33 @@ class EventTest < MiniTest::Unit::TestCase
|
|
108
166
|
response = @client.list_events(@collection, @key, @event_type)
|
109
167
|
assert_equal 200, response.status
|
110
168
|
assert_equal body, response.body
|
169
|
+
assert_equal body['count'], response.count
|
170
|
+
assert_equal body['results'], response.results
|
171
|
+
assert_equal body['next'], response.next_link
|
111
172
|
end
|
112
173
|
|
113
174
|
def test_list_events_with_timestamp
|
114
175
|
end_time = Time.now
|
115
176
|
start_time = end_time - (24 * 3600)
|
116
|
-
body = { "results" => [
|
177
|
+
body = { "results" => [{"path"=>{}, "value"=>{}, "timestamp"=>"", "ordinal"=>0}],
|
178
|
+
"count" => 1, "next" => "__NEXT__" }
|
117
179
|
|
118
180
|
@stubs.get("/v0/#{@collection}/#{@key}/events/#{@event_type}") do |env|
|
119
181
|
assert_authorization @basic_auth, env
|
120
182
|
assert_accepts_json env
|
121
|
-
assert_equal start_time.to_i.to_s, env.params['startEvent']
|
122
|
-
assert_equal end_time.to_i.to_s, env.params['endEvent']
|
183
|
+
assert_equal (start_time.to_f * 1000).to_i.to_s, env.params['startEvent']
|
184
|
+
assert_equal (end_time.to_f * 1000).to_i.to_s, env.params['endEvent']
|
123
185
|
assert_equal ['startEvent', 'endEvent'].sort, env.params.keys.sort
|
124
186
|
[200, response_headers, body.to_json]
|
125
187
|
end
|
126
188
|
response = @client.list_events(@collection, @key, @event_type,
|
127
|
-
|
128
|
-
)
|
189
|
+
{ start: start_time, end: end_time })
|
129
190
|
assert_equal 200, response.status
|
130
191
|
assert_equal body, response.body
|
192
|
+
assert_equal body['results'], response.results
|
193
|
+
assert_equal body['count'], response.count
|
194
|
+
assert_equal body['next'], response.next_link
|
195
|
+
assert_nil response.prev_link
|
131
196
|
end
|
132
197
|
|
133
198
|
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
class ExceptionsTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@client, @stubs, @basic_auth = make_client_and_artifacts
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_raises_on_unauthroized
|
9
|
+
@stubs.get("/v0/foo") do |env|
|
10
|
+
assert_authorization @basic_auth, env
|
11
|
+
[ 401, response_headers, {
|
12
|
+
"message" => "Valid credentials are required.",
|
13
|
+
"code" => "security_unauthorized"
|
14
|
+
}.to_json ]
|
15
|
+
end
|
16
|
+
assert_raises Orchestrate::API::Unauthorized do
|
17
|
+
@client.list(:foo)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_raises_on_bad_request
|
22
|
+
message = "Invalid value for header 'If-Match'."
|
23
|
+
@stubs.put("/v0/foo/bar") do |env|
|
24
|
+
[400, response_headers, {
|
25
|
+
message: message,
|
26
|
+
code: "api_bad_request"
|
27
|
+
}.to_json ]
|
28
|
+
end
|
29
|
+
err = assert_raises Orchestrate::API::BadRequest do
|
30
|
+
@client.put(:foo, "bar", {}, "'foo'")
|
31
|
+
end
|
32
|
+
assert_equal message, err.message
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_raises_on_malformed_search_query
|
36
|
+
@stubs.get("/v0/foo") do |env|
|
37
|
+
[ 400, response_headers, {
|
38
|
+
message: "The search query provided is invalid.",
|
39
|
+
code: "search_query_malformed"
|
40
|
+
}.to_json ]
|
41
|
+
end
|
42
|
+
assert_raises Orchestrate::API::MalformedSearch do
|
43
|
+
@client.search(:foo, "foo=\"no")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_raises_on_invalid_search_param
|
48
|
+
@stubs.get("/v0/foo") do |env|
|
49
|
+
[ 400, response_headers, {
|
50
|
+
message: "A provided search query param is invalid.",
|
51
|
+
details: { query: "Query is empty." },
|
52
|
+
code: "search_param_invalid"
|
53
|
+
}.to_json ]
|
54
|
+
end
|
55
|
+
assert_raises Orchestrate::API::InvalidSearchParam do
|
56
|
+
@client.search(:foo, '')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_raises_on_malformed_ref
|
61
|
+
@stubs.put("/v0/foo/bar") do |env|
|
62
|
+
[ 400, response_headers, {
|
63
|
+
message: "The provided Item Ref is malformed.",
|
64
|
+
details: { ref: "blerg" },
|
65
|
+
code: "item_ref_malformed"
|
66
|
+
}.to_json ]
|
67
|
+
end
|
68
|
+
assert_raises Orchestrate::API::MalformedRef do
|
69
|
+
@client.put(:foo, "bar", {:blerg => 'blerg'}, "blerg")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_raises_on_indexing_conflict
|
74
|
+
@stubs.put("/v0/foo/bar") do |env|
|
75
|
+
[ 409, response_headers, {
|
76
|
+
message: "The item has been stored but conflicts were detected when indexing. Conflicting fields have not been indexed.",
|
77
|
+
details: {
|
78
|
+
conflicts: { name: { type: "string", expected: "long" } },
|
79
|
+
conflicts_uri: "/v0/test/one/refs/f8a86a25029a907b/conflicts"
|
80
|
+
},
|
81
|
+
code: "indexing_conflict"
|
82
|
+
}.to_json ]
|
83
|
+
end
|
84
|
+
assert_raises Orchestrate::API::IndexingConflict do
|
85
|
+
@client.put(:foo, 'bar', {count: "foo"})
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_raises_on_version_mismatch
|
90
|
+
@stubs.put("/v0/foo/bar") do |env|
|
91
|
+
[ 412, response_headers, {
|
92
|
+
message: "The version of the item does not match.",
|
93
|
+
code: "item_version_mismatch"
|
94
|
+
}.to_json ]
|
95
|
+
end
|
96
|
+
assert_raises Orchestrate::API::VersionMismatch do
|
97
|
+
@client.put(:foo, 'bar', {foo:'bar'}, "7ae8635207acbb2f")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_raises_on_item_already_present
|
102
|
+
@stubs.put("/v0/foo/bar") do |env|
|
103
|
+
[ 412, response_headers, {
|
104
|
+
message: "The item is already present.",
|
105
|
+
code: "item_already_present"
|
106
|
+
}.to_json ]
|
107
|
+
end
|
108
|
+
assert_raises Orchestrate::API::AlreadyPresent do
|
109
|
+
@client.put_if_absent(:foo, 'bar', {foo:'bar'})
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_raises_on_unexpected_response_error
|
114
|
+
@stubs.get("/v0/teapot/spout") do |env|
|
115
|
+
[ 418, response_headers, {
|
116
|
+
message: "I'm a little teapot",
|
117
|
+
code: "teapot"
|
118
|
+
}.to_json ]
|
119
|
+
end
|
120
|
+
assert_raises Orchestrate::API::RequestError do
|
121
|
+
@client.get(:teapot, "spout")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_raises_on_security_authentication
|
126
|
+
@stubs.get("/v0/test/123") do |env|
|
127
|
+
[ 500, response_headers, {
|
128
|
+
message: "An error occurred while trying to authenticate.",
|
129
|
+
code: "security_authentication"
|
130
|
+
}.to_json ]
|
131
|
+
end
|
132
|
+
assert_raises Orchestrate::API::SecurityAuthentication do
|
133
|
+
@client.get(:test, '123')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_raises_on_search_index_not_found
|
138
|
+
@stubs.get("/v0/test") do |env|
|
139
|
+
[ 500, response_headers, {
|
140
|
+
message: "Index could not be queried for this application.",
|
141
|
+
code: "search_index_not_found"
|
142
|
+
}.to_json ]
|
143
|
+
end
|
144
|
+
assert_raises Orchestrate::API::SearchIndexNotFound do
|
145
|
+
@client.search(:test, '123')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_raises_on_internal_error
|
150
|
+
@stubs.get("/v0/test/123") do |env|
|
151
|
+
[ 500, response_headers, {
|
152
|
+
message: "Internal Error.",
|
153
|
+
code: "internal_error"
|
154
|
+
}.to_json ]
|
155
|
+
end
|
156
|
+
assert_raises Orchestrate::API::InternalError do
|
157
|
+
@client.get(:test, '123')
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_raises_on_generic_500_error
|
162
|
+
body = "The bees, they're in my eyes"
|
163
|
+
@stubs.get("/v0/test/123") do |env|
|
164
|
+
[ 500, {}, body ]
|
165
|
+
end
|
166
|
+
err = assert_raises Orchestrate::API::ServiceError do
|
167
|
+
@client.get(:test, '123')
|
168
|
+
end
|
169
|
+
assert_equal body, err.message
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
@@ -21,6 +21,8 @@ class GraphTest < MiniTest::Unit::TestCase
|
|
21
21
|
response = @client.get_relations(@collection, @key, @kind, @kind)
|
22
22
|
assert_equal 200, response.status
|
23
23
|
assert_equal body, response.body
|
24
|
+
assert_equal body['count'], response.count
|
25
|
+
assert_equal body['results'], response.results
|
24
26
|
end
|
25
27
|
|
26
28
|
def test_put_graph
|
@@ -30,6 +32,7 @@ class GraphTest < MiniTest::Unit::TestCase
|
|
30
32
|
end
|
31
33
|
response = @client.put_relation(@collection, @key, @kind, @target_collection, @target_key)
|
32
34
|
assert_equal 204, response.status
|
35
|
+
assert_equal response.headers['X-Orchestrate-Req-Id'], response.request_id
|
33
36
|
end
|
34
37
|
|
35
38
|
def test_delete_graph
|
@@ -40,5 +43,6 @@ class GraphTest < MiniTest::Unit::TestCase
|
|
40
43
|
end
|
41
44
|
response = @client.delete_relation(@collection, @key, @kind, @target_collection, @target_key)
|
42
45
|
assert_equal 204, response.status
|
46
|
+
assert_equal response.headers['X-Orchestrate-Req-Id'], response.request_id
|
43
47
|
end
|
44
48
|
end
|
@@ -27,6 +27,11 @@ class KeyValueTest < MiniTest::Unit::TestCase
|
|
27
27
|
|
28
28
|
assert_equal "\"#{ref}\"", response.headers['Etag']
|
29
29
|
assert_equal ref_url, response.headers['Content-Location']
|
30
|
+
|
31
|
+
assert_equal ref_url, response.location
|
32
|
+
assert_equal ref, response.ref
|
33
|
+
assert_equal Time.parse(response.headers['Date']), response.request_time
|
34
|
+
assert_equal response.headers['X-Orchestrate-Req-Id'], response.request_id
|
30
35
|
end
|
31
36
|
|
32
37
|
def test_gets_key_value_is_404_when_does_not_exist
|
@@ -36,22 +41,28 @@ class KeyValueTest < MiniTest::Unit::TestCase
|
|
36
41
|
[ 404, response_headers(), response_not_found({collection:@collection, key:@key}) ]
|
37
42
|
end
|
38
43
|
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
assert_raises Orchestrate::API::NotFound do
|
45
|
+
@client.get(@collection, @key)
|
46
|
+
end
|
42
47
|
end
|
43
48
|
|
44
49
|
def test_puts_key_value_without_ref
|
45
50
|
body={"foo" => "bar"}
|
46
|
-
|
51
|
+
ref = "12345"
|
52
|
+
base_location = "/v0/#{@collection}/#{@key}"
|
53
|
+
@stubs.put(base_location) do |env|
|
47
54
|
assert_authorization @basic_auth, env
|
48
55
|
assert_header 'Content-Type', 'application/json', env
|
49
56
|
assert_equal body.to_json, env.body
|
50
|
-
|
57
|
+
headers = { "Location" => "#{base_location}/refs/#{ref}",
|
58
|
+
"Etag" => "\"#{ref}\"" }
|
59
|
+
[ 201, response_headers(headers), '' ]
|
51
60
|
end
|
52
61
|
|
53
62
|
response = @client.put(@collection, @key, body)
|
54
63
|
assert_equal 201, response.status
|
64
|
+
assert_equal ref, response.ref
|
65
|
+
assert_equal "#{base_location}/refs/#{ref}", response.location
|
55
66
|
end
|
56
67
|
|
57
68
|
def test_puts_key_value_with_specific_ref
|
@@ -122,6 +133,7 @@ class KeyValueTest < MiniTest::Unit::TestCase
|
|
122
133
|
end
|
123
134
|
response = @client.delete(@collection, @key)
|
124
135
|
assert_equal 204, response.status
|
136
|
+
assert_equal response.headers['X-Orchestrate-Req-Id'], response.request_id
|
125
137
|
end
|
126
138
|
|
127
139
|
def test_delete_key_value_with_condition
|
@@ -154,20 +166,53 @@ class KeyValueTest < MiniTest::Unit::TestCase
|
|
154
166
|
end
|
155
167
|
response = @client.purge(@collection, @key)
|
156
168
|
assert_equal 204, response.status
|
169
|
+
assert_equal response.headers['X-Orchestrate-Req-Id'], response.request_id
|
157
170
|
end
|
158
171
|
|
159
172
|
def test_gets_ref
|
160
173
|
body = {"key" => "value"}
|
161
174
|
ref = '123456'
|
162
|
-
|
175
|
+
ref_url = "/v0/#{@collection}/#{@key}/refs/#{ref}"
|
176
|
+
@stubs.get(ref_url) do |env|
|
163
177
|
assert_authorization @basic_auth, env
|
164
178
|
assert_accepts_json env
|
165
|
-
|
179
|
+
headers = {
|
180
|
+
'Content-Location' => ref_url,
|
181
|
+
'Etag' => "\"#{ref}\""
|
182
|
+
}
|
183
|
+
[ 200, response_headers(headers), body.to_json ]
|
166
184
|
end
|
167
185
|
|
168
186
|
response = @client.get(@collection, @key, ref)
|
169
187
|
assert_equal 200, response.status
|
170
188
|
assert_equal body, response.body
|
189
|
+
|
190
|
+
assert_equal ref_url, response.location
|
191
|
+
assert_equal ref, response.ref
|
192
|
+
assert_equal Time.parse(response.headers['Date']), response.request_time
|
193
|
+
assert_equal response.headers['X-Orchestrate-Req-Id'], response.request_id
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_list_refs
|
197
|
+
reflist = (1..3).map do |i|
|
198
|
+
{ "path" => {}, "reftime" => Time.now.to_i - (-2 * i * 3600 * 1000) }
|
199
|
+
end
|
200
|
+
body = { "results" => reflist, "count" => 3, "prev" => "__PREV__" }
|
201
|
+
|
202
|
+
@stubs.get("/v0/#{@collection}/#{@key}/refs") do |env|
|
203
|
+
assert_authorization @basic_auth, env
|
204
|
+
assert_accepts_json env
|
205
|
+
assert_equal "10", env.params['offset']
|
206
|
+
[ 200, response_headers, body.to_json ]
|
207
|
+
end
|
208
|
+
|
209
|
+
response = @client.list_refs(@collection, @key, {offset: 10})
|
210
|
+
assert_equal 200, response.status
|
211
|
+
assert_equal body, response.body
|
212
|
+
assert_equal body['count'], response.count
|
213
|
+
assert_equal body['results'], response.results
|
214
|
+
assert_equal body['prev'], response.prev_link
|
215
|
+
assert_nil response.next_link
|
171
216
|
end
|
172
217
|
|
173
218
|
end
|