orientdb4r 0.2.7 → 0.2.8
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.
- data/changelog.txt +5 -1
- data/fstudy/design_v1.dia +0 -0
- data/fstudy/design_v1.png +0 -0
- data/fstudy/domain_model.dia +0 -0
- data/fstudy/domain_model.png +0 -0
- data/fstudy/flat_class_perf.rb +46 -0
- data/fstudy/sample1_object_diagram.dia +0 -0
- data/fstudy/sample1_object_diagram.png +0 -0
- data/fstudy/study_case.rb +87 -0
- data/fstudy/technical_feasibility.rb +251 -0
- data/lib/orientdb4r/client.rb +15 -2
- data/lib/orientdb4r/node.rb +6 -0
- data/lib/orientdb4r/rest/client.rb +71 -70
- data/lib/orientdb4r/rest/excon_node.rb +80 -0
- data/lib/orientdb4r/rest/node.rb +1 -19
- data/lib/orientdb4r/rest/restclient_node.rb +28 -13
- data/lib/orientdb4r/version.rb +1 -0
- data/lib/orientdb4r.rb +13 -3
- data/test/test_database.rb +11 -4
- data/test/test_ddo.rb +43 -5
- data/test/test_dmo.rb +7 -5
- data/test/test_document_crud.rb +17 -1
- metadata +12 -4
- data/test/graphs.rb +0 -114
@@ -17,7 +17,9 @@ module Orientdb4r
|
|
17
17
|
options_pattern = { :host => 'localhost', :port => 2480, :ssl => false }
|
18
18
|
verify_and_sanitize_options(options, options_pattern)
|
19
19
|
|
20
|
-
|
20
|
+
raise ArgumentError, 'no node type defined in context' unless Orientdb4r::context.include? :node_type
|
21
|
+
@nodes << Orientdb4r::context[:node_type].new(options[:host], options[:port], options[:ssl])
|
22
|
+
Orientdb4r::logger.debug "client with communication driver: #{a_node.identification}"
|
21
23
|
end
|
22
24
|
|
23
25
|
|
@@ -89,12 +91,9 @@ module Orientdb4r
|
|
89
91
|
|
90
92
|
u = options.include?(:user) ? options[:user] : user
|
91
93
|
p = options.include?(:password) ? options[:password] : password
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
rescue
|
96
|
-
raise OrientdbError
|
97
|
-
end
|
94
|
+
|
95
|
+
# uses one-off request because of additional authentication to the server
|
96
|
+
response = a_node.oo_request :method => :get, :user => u, :password => p, :uri => 'server'
|
98
97
|
process_response(response)
|
99
98
|
end
|
100
99
|
|
@@ -110,13 +109,10 @@ module Orientdb4r
|
|
110
109
|
|
111
110
|
u = options.include?(:user) ? options[:user] : user
|
112
111
|
p = options.include?(:password) ? options[:password] : password
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
rescue
|
118
|
-
raise OrientdbError
|
119
|
-
end
|
112
|
+
|
113
|
+
# uses one-off request because of additional authentication to the server
|
114
|
+
response = a_node.oo_request :method => :post, :user => u, :password => p, \
|
115
|
+
:uri => "database/#{options[:database]}/#{options[:type]}"
|
120
116
|
process_response(response)
|
121
117
|
end
|
122
118
|
|
@@ -135,13 +131,12 @@ module Orientdb4r
|
|
135
131
|
|
136
132
|
u = options.include?(:user) ? options[:user] : user
|
137
133
|
p = options.include?(:password) ? options[:password] : password
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
134
|
+
|
135
|
+
# uses one-off request because of additional authentication to the server
|
136
|
+
response = a_node.oo_request :method => :get, :user => u, :password => p, \
|
137
|
+
:uri => "database/#{options[:database]}"
|
138
|
+
|
139
|
+
# NotFoundError cannot be raised - no way how to recognize from 401 bad auth
|
145
140
|
process_response(response)
|
146
141
|
end
|
147
142
|
|
@@ -156,12 +151,12 @@ module Orientdb4r
|
|
156
151
|
|
157
152
|
limit = ''
|
158
153
|
limit = "/#{options[:limit]}" if !options.nil? and options.include?(:limit)
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
raise NotFoundError
|
154
|
+
|
155
|
+
response = a_node.request(:method => :get, :uri => "query/#{@database}/sql/#{CGI::escape(sql)}#{limit}")
|
156
|
+
entries = process_response(response) do
|
157
|
+
raise NotFoundError, 'record not found' if response.body =~ /ORecordNotFoundException/
|
163
158
|
end
|
164
|
-
|
159
|
+
|
165
160
|
rslt = entries['result']
|
166
161
|
# mixin all document entries (they have '@class' attribute)
|
167
162
|
rslt.each { |doc| doc.extend Orientdb4r::DocumentMetadata unless doc['@class'].nil? }
|
@@ -171,11 +166,7 @@ module Orientdb4r
|
|
171
166
|
|
172
167
|
def command(sql) #:nodoc:
|
173
168
|
raise ArgumentError, 'command is blank' if blank? sql
|
174
|
-
|
175
|
-
response = a_node.request(:method => :post, :uri => "command/#{@database}/sql/#{CGI::escape(sql)}")
|
176
|
-
rescue
|
177
|
-
raise OrientdbError
|
178
|
-
end
|
169
|
+
response = a_node.request(:method => :post, :uri => "command/#{@database}/sql/#{CGI::escape(sql)}")
|
179
170
|
process_response(response)
|
180
171
|
end
|
181
172
|
|
@@ -186,22 +177,19 @@ module Orientdb4r
|
|
186
177
|
raise ArgumentError, "class name is blank" if blank?(name)
|
187
178
|
|
188
179
|
if compare_versions(server_version, '1.1.0') >= 0
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
raise NotFoundError
|
180
|
+
response = a_node.request(:method => :get, :uri => "class/#{@database}/#{name}")
|
181
|
+
rslt = process_response(response) do
|
182
|
+
raise NotFoundError, 'class not found' if response.body =~ /Invalid class/
|
193
183
|
end
|
194
|
-
|
184
|
+
|
195
185
|
classes = [rslt]
|
196
186
|
else
|
197
187
|
# there is bug in REST API [v1.0.0, fixed in r5902], only data are returned
|
198
188
|
# workaround - use metadate delivered by 'connect'
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
raise NotFoundError
|
189
|
+
response = a_node.request(:method => :get, :uri => "connect/#{@database}")
|
190
|
+
connect_info = process_response(response) do
|
191
|
+
raise NotFoundError, 'class not found' if response.body =~ /Invalid class/
|
203
192
|
end
|
204
|
-
connect_info = process_response response
|
205
193
|
|
206
194
|
classes = connect_info['classes'].select { |i| i['name'] == name }
|
207
195
|
raise NotFoundError, "class not found, name=#{name}" unless 1 == classes.size
|
@@ -225,13 +213,12 @@ module Orientdb4r
|
|
225
213
|
# ----------------------------------------------------------------- DOCUMENT
|
226
214
|
|
227
215
|
def create_document(doc)
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
raise DataError
|
216
|
+
response = a_node.request(:method => :post, :uri => "document/#{@database}", \
|
217
|
+
:content_type => 'application/json', :data => doc.to_json)
|
218
|
+
rid = process_response(response) do
|
219
|
+
raise DataError, 'validation problem' if response.body =~ /OValidationException/
|
233
220
|
end
|
234
|
-
|
221
|
+
|
235
222
|
raise ArgumentError, "invalid RID format, RID=#{rid}" unless rid =~ /^#[0-9]+:[0-9]+/
|
236
223
|
rid
|
237
224
|
end
|
@@ -242,12 +229,12 @@ module Orientdb4r
|
|
242
229
|
# remove the '#' prefix
|
243
230
|
rid = rid[1..-1] if rid.start_with? '#'
|
244
231
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
raise NotFoundError
|
232
|
+
response = a_node.request(:method => :get, :uri => "document/#{@database}/#{rid}")
|
233
|
+
rslt = process_response(response) do
|
234
|
+
raise NotFoundError, 'record not found' if response.body =~ /ORecordNotFoundException/
|
235
|
+
raise NotFoundError, 'record not found' if response.body =~ /Record with id .* was not found/ # why after delete?
|
249
236
|
end
|
250
|
-
|
237
|
+
|
251
238
|
rslt.extend Orientdb4r::DocumentMetadata
|
252
239
|
rslt
|
253
240
|
end
|
@@ -261,11 +248,11 @@ module Orientdb4r
|
|
261
248
|
rid = doc.delete '@rid'
|
262
249
|
rid = rid[1..-1] if rid.start_with? '#'
|
263
250
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
raise DataError
|
251
|
+
response = a_node.request(:method => :put, :uri => "document/#{@database}/#{rid}", \
|
252
|
+
:content_type => 'application/json', :data => doc.to_json)
|
253
|
+
process_response(response) do
|
254
|
+
raise DataError, 'concurrent modification' if response.body =~ /OConcurrentModificationException/
|
255
|
+
raise DataError, 'validation problem' if response.body =~ /OValidationException/
|
269
256
|
end
|
270
257
|
# empty http response
|
271
258
|
end
|
@@ -276,10 +263,9 @@ module Orientdb4r
|
|
276
263
|
# remove the '#' prefix
|
277
264
|
rid = rid[1..-1] if rid.start_with? '#'
|
278
265
|
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
raise DataError
|
266
|
+
response = a_node.request(:method => :delete, :uri => "document/#{@database}/#{rid}")
|
267
|
+
process_response(response) do
|
268
|
+
raise NotFoundError, 'record not found' if response.body =~ /ORecordNotFoundException/
|
283
269
|
end
|
284
270
|
# empty http response
|
285
271
|
end
|
@@ -293,18 +279,22 @@ module Orientdb4r
|
|
293
279
|
def process_response(response)
|
294
280
|
raise ArgumentError, 'response is null' if response.nil?
|
295
281
|
|
282
|
+
if block_given?
|
283
|
+
yield
|
284
|
+
end
|
285
|
+
|
286
|
+
|
296
287
|
# return code
|
297
|
-
if
|
298
|
-
|
299
|
-
elsif
|
300
|
-
raise
|
301
|
-
elsif
|
302
|
-
|
303
|
-
msg = "#{msg[0..100]} ..." if msg.size > 100
|
304
|
-
raise OrientdbError, "unexpected return code, code=#{response.code}, body=#{msg}"
|
288
|
+
if 401 == response.code
|
289
|
+
raise UnauthorizedError, compose_error_message(response)
|
290
|
+
elsif 500 == response.code
|
291
|
+
raise ServerError, compose_error_message(response)
|
292
|
+
elsif 2 != (response.code / 100)
|
293
|
+
raise OrientdbError, "unexpected return code, code=#{response.code}, body=#{compose_error_message(response)}"
|
305
294
|
end
|
306
295
|
|
307
|
-
content_type = response.headers[:content_type]
|
296
|
+
content_type = response.headers[:content_type] if Orientdb4r::context[:node_type] == RestClientNode
|
297
|
+
content_type = response.headers['Content-Type'] if Orientdb4r::context[:node_type] == ExconNode
|
308
298
|
content_type ||= 'text/plain'
|
309
299
|
|
310
300
|
rslt = case
|
@@ -319,6 +309,17 @@ module Orientdb4r
|
|
319
309
|
rslt
|
320
310
|
end
|
321
311
|
|
312
|
+
|
313
|
+
###
|
314
|
+
# Composes message of an error raised if the HTTP response doesn't
|
315
|
+
# correspond with expectation.
|
316
|
+
def compose_error_message(http_response, max_len=200)
|
317
|
+
msg = http_response.body.gsub("\n", ' ')
|
318
|
+
msg = "#{msg[0..max_len]} ..." if msg.size > max_len
|
319
|
+
msg
|
320
|
+
end
|
321
|
+
|
322
|
+
|
322
323
|
# @deprecated
|
323
324
|
def process_restclient_response(response, options={})
|
324
325
|
raise ArgumentError, 'response is null' if response.nil?
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'excon'
|
2
|
+
|
3
|
+
module Orientdb4r
|
4
|
+
|
5
|
+
###
|
6
|
+
# This class represents a single sever/node in the Distributed Multi-Master Architecture
|
7
|
+
# accessible view REST API and 'excon' library on the client side.
|
8
|
+
class ExconNode < RestNode
|
9
|
+
|
10
|
+
|
11
|
+
def identification #:nodoc:
|
12
|
+
'excon'
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def oo_request(options) #:nodoc:
|
17
|
+
address = "#{url}/#{options[:uri]}"
|
18
|
+
headers = {}
|
19
|
+
headers['Authorization'] = basic_auth_header(options[:user], options[:password]) if options.include?(:user)
|
20
|
+
headers['Cookie'] = "#{SESSION_COOKIE_NAME}=#{session_id}" unless session_id.nil?
|
21
|
+
response = ::Excon.send options[:method].to_sym, address, :headers => headers
|
22
|
+
|
23
|
+
def response.code
|
24
|
+
status
|
25
|
+
end
|
26
|
+
|
27
|
+
response
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def request(options) #:nodoc:
|
32
|
+
raise OrientdbError, 'long life connection not initialized' if @connection.nil?
|
33
|
+
|
34
|
+
head = headers
|
35
|
+
head['Content-Type'] = options[:content_type] if options.include? :content_type
|
36
|
+
options[:headers] = head
|
37
|
+
|
38
|
+
options[:body] = options[:data] if options.include? :data # just other naming convention
|
39
|
+
options.delete :data
|
40
|
+
options[:path] = options[:uri] if options.include? :uri # just other naming convention
|
41
|
+
options.delete :uri
|
42
|
+
|
43
|
+
response = @connection.request options
|
44
|
+
|
45
|
+
def response.code
|
46
|
+
status
|
47
|
+
end
|
48
|
+
|
49
|
+
response
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def post_connect(user, password, http_response) #:nodoc:
|
54
|
+
@basic_auth = basic_auth_header(user, password)
|
55
|
+
|
56
|
+
cookies = CGI::Cookie::parse(http_response.headers['Set-Cookie'])
|
57
|
+
@session_id = cookies[SESSION_COOKIE_NAME][0]
|
58
|
+
|
59
|
+
@connection = Excon.new(url) if @connection.nil?
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def cleanup #:nodoc:
|
64
|
+
@session_id = nil
|
65
|
+
@basic_auth = nil
|
66
|
+
@connection = nil
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
###
|
73
|
+
# Get request headers prepared with session ID and Basic Auth.
|
74
|
+
def headers
|
75
|
+
{'Authorization' => @basic_auth, 'Cookie' => "#{SESSION_COOKIE_NAME}=#{session_id}"}
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
data/lib/orientdb4r/rest/node.rb
CHANGED
@@ -8,7 +8,7 @@ module Orientdb4r
|
|
8
8
|
# Name of cookie that represents a session.
|
9
9
|
SESSION_COOKIE_NAME = 'OSESSIONID'
|
10
10
|
|
11
|
-
attr_reader :ssl
|
11
|
+
attr_reader :ssl, :session_id
|
12
12
|
|
13
13
|
###
|
14
14
|
# Constructor.
|
@@ -31,10 +31,6 @@ module Orientdb4r
|
|
31
31
|
# after successful connect.
|
32
32
|
def post_connect(user, password, http_response)
|
33
33
|
raise NotImplementedError, 'this should be overridden by subclass'
|
34
|
-
|
35
|
-
# excon
|
36
|
-
# cookies = CGI::Cookie::parse(http_response.headers['Set-Cookie'])
|
37
|
-
# @session_id = cookies[SESSION_COOKIE_NAME][0]
|
38
34
|
end
|
39
35
|
|
40
36
|
|
@@ -60,20 +56,6 @@ module Orientdb4r
|
|
60
56
|
"Basic #{b64}"
|
61
57
|
end
|
62
58
|
|
63
|
-
|
64
|
-
# excon ###
|
65
|
-
# # Get request headers prepared with session ID and Basic Auth.
|
66
|
-
# def headers
|
67
|
-
# {'Authorization' => @basic_auth, 'Cookie' => "#{SESSION_COOKIE_NAME}=#{session_id}"}
|
68
|
-
# end
|
69
|
-
|
70
|
-
# excon ###
|
71
|
-
# # Gets a connection object which is reusable across multiple requests.
|
72
|
-
# def connection
|
73
|
-
# @connection = Excon.new(url) if @connection.nil?
|
74
|
-
# @connection
|
75
|
-
# end
|
76
|
-
|
77
59
|
end
|
78
60
|
|
79
61
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
|
1
3
|
module Orientdb4r
|
2
4
|
|
3
5
|
###
|
@@ -5,7 +7,10 @@ module Orientdb4r
|
|
5
7
|
# accessible view REST API and 'rest-client' library on the client side.
|
6
8
|
class RestClientNode < RestNode
|
7
9
|
|
8
|
-
|
10
|
+
|
11
|
+
def identification #:nodoc:
|
12
|
+
'rest-client'
|
13
|
+
end
|
9
14
|
|
10
15
|
|
11
16
|
def oo_request(options) #:nodoc:
|
@@ -13,13 +18,10 @@ module Orientdb4r
|
|
13
18
|
options[:url] = "#{url}/#{options[:uri]}"
|
14
19
|
options.delete :uri
|
15
20
|
response = ::RestClient::Request.new(options).execute
|
16
|
-
rescue ::RestClient::
|
17
|
-
|
18
|
-
response = "401 Unauthorized"
|
19
|
-
def response.code
|
20
|
-
401
|
21
|
-
end
|
21
|
+
rescue ::RestClient::Exception => e
|
22
|
+
response = transform_error2_response(e)
|
22
23
|
end
|
24
|
+
|
23
25
|
response
|
24
26
|
end
|
25
27
|
|
@@ -37,12 +39,8 @@ module Orientdb4r
|
|
37
39
|
else
|
38
40
|
response = @resource[options[:uri]].send options[:method].to_sym, data
|
39
41
|
end
|
40
|
-
rescue ::RestClient::
|
41
|
-
|
42
|
-
response = "401 Unauthorized"
|
43
|
-
def response.code
|
44
|
-
401
|
45
|
-
end
|
42
|
+
rescue ::RestClient::Exception => e
|
43
|
+
response = transform_error2_response(e)
|
46
44
|
end
|
47
45
|
|
48
46
|
response
|
@@ -65,6 +63,23 @@ module Orientdb4r
|
|
65
63
|
@resource = nil
|
66
64
|
end
|
67
65
|
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
###
|
70
|
+
# Fakes an error thrown by the library into a response object with methods
|
71
|
+
# 'code' and 'body'.
|
72
|
+
def transform_error2_response(error)
|
73
|
+
response = ["#{error.message}: #{error.http_body}", error.http_code]
|
74
|
+
def response.body
|
75
|
+
self[0]
|
76
|
+
end
|
77
|
+
def response.code
|
78
|
+
self[1]
|
79
|
+
end
|
80
|
+
response
|
81
|
+
end
|
82
|
+
|
68
83
|
end
|
69
84
|
|
70
85
|
end
|
data/lib/orientdb4r/version.rb
CHANGED
@@ -2,6 +2,7 @@ module Orientdb4r
|
|
2
2
|
|
3
3
|
# Version history.
|
4
4
|
VERSION_HISTORY = [
|
5
|
+
['0.2.8', '2012-07-16', "New exception handling, added feature Client#create_class(:properties)"],
|
5
6
|
['0.2.7', '2012-07-07', "Added method Client#class_exists?"],
|
6
7
|
['0.2.6', '2012-07-03', "BF #8, BF #6"],
|
7
8
|
['0.2.5', '2012-07-01', "Added 'get_database' into database CRUD"],
|
data/lib/orientdb4r.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'base64'
|
3
3
|
require 'logger'
|
4
|
-
require 'rest_client'
|
5
4
|
require 'orientdb4r/version'
|
6
5
|
|
7
6
|
|
@@ -18,6 +17,7 @@ module Orientdb4r
|
|
18
17
|
autoload :Node, 'orientdb4r/node'
|
19
18
|
autoload :RestNode, 'orientdb4r/rest/node'
|
20
19
|
autoload :RestClientNode, 'orientdb4r/rest/restclient_node'
|
20
|
+
autoload :ExconNode, 'orientdb4r/rest/excon_node'
|
21
21
|
|
22
22
|
|
23
23
|
class << self
|
@@ -43,7 +43,7 @@ module Orientdb4r
|
|
43
43
|
RestClient.proxy = url
|
44
44
|
end
|
45
45
|
|
46
|
-
attr_accessor :logger
|
46
|
+
attr_accessor :logger, :context
|
47
47
|
|
48
48
|
end
|
49
49
|
|
@@ -58,6 +58,10 @@ module Orientdb4r
|
|
58
58
|
# Error indicating that access to the resource requires user authentication.
|
59
59
|
class UnauthorizedError < OrientdbError; end
|
60
60
|
|
61
|
+
###
|
62
|
+
# Error indicating that the server encountered an unexpected condition which prevented it from fulfilling the request.
|
63
|
+
class ServerError < OrientdbError; end
|
64
|
+
|
61
65
|
###
|
62
66
|
# Error indicating problems with communicating with the database.
|
63
67
|
class ConnectionError < OrientdbError; end
|
@@ -79,7 +83,13 @@ Orientdb4r::logger = Logger.new(STDOUT)
|
|
79
83
|
Orientdb4r::logger.level = Logger::INFO
|
80
84
|
|
81
85
|
Orientdb4r::logger.info \
|
82
|
-
|
86
|
+
"Orientdb4r #{Orientdb4r::VERSION}, running on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
87
|
+
|
88
|
+
|
89
|
+
# Configuration of context.
|
90
|
+
Orientdb4r::context = {}
|
91
|
+
Orientdb4r::context[:node_type] = Orientdb4r::RestClientNode
|
92
|
+
#Orientdb4r::context[:node_type] = Orientdb4r::ExconNode
|
83
93
|
|
84
94
|
|
85
95
|
#Orientdb4r::logger.level = Logger::DEBUG
|
data/test/test_database.rb
CHANGED
@@ -42,6 +42,10 @@ class TestDatabase < Test::Unit::TestCase
|
|
42
42
|
assert_raise Orientdb4r::UnauthorizedError do
|
43
43
|
@client.connect :database => 'unknown_db', :user => 'admin', :password => 'admin'
|
44
44
|
end
|
45
|
+
# bad DB name with '/' => wrong REST resource
|
46
|
+
assert_raise Orientdb4r::ServerError do
|
47
|
+
@client.connect :database => 'temp/temp', :user => 'admin', :password => 'admin'
|
48
|
+
end
|
45
49
|
# bad credentials
|
46
50
|
assert_raise Orientdb4r::UnauthorizedError do
|
47
51
|
@client.connect :database => 'temp', :user => 'admin1', :password => 'admin'
|
@@ -97,7 +101,7 @@ class TestDatabase < Test::Unit::TestCase
|
|
97
101
|
###
|
98
102
|
# GET DATABASE
|
99
103
|
def test_get_database
|
100
|
-
# not connected
|
104
|
+
# not connected - allowed with additional authentication
|
101
105
|
assert_nothing_thrown do @client.get_database :database => 'temp', :user => 'admin', :password => 'admin' ; end
|
102
106
|
assert_raise Orientdb4r::ConnectionError do @client.get_database; end
|
103
107
|
# connected
|
@@ -108,12 +112,15 @@ class TestDatabase < Test::Unit::TestCase
|
|
108
112
|
assert_not_nil rslt
|
109
113
|
assert_instance_of Hash, rslt
|
110
114
|
assert rslt.include? 'classes'
|
111
|
-
assert @client.database_exists?(:database => 'temp', :user => 'admin', :password => 'admin')
|
112
|
-
assert @client.database_exists?(:database => 'temp') # use credentials of logged in user
|
113
115
|
|
114
116
|
# bad databases
|
115
117
|
assert_raise Orientdb4r::UnauthorizedError do @client.get_database :database => 'UnknownDB'; end
|
116
|
-
assert_raise Orientdb4r::
|
118
|
+
assert_raise Orientdb4r::ServerError do @client.get_database :database => 'temp/admin'; end # bad REST resource
|
119
|
+
|
120
|
+
|
121
|
+
# database_exists?
|
122
|
+
assert @client.database_exists?(:database => 'temp', :user => 'admin', :password => 'admin')
|
123
|
+
assert @client.database_exists?(:database => 'temp') # use credentials of logged in user
|
117
124
|
assert !@client.database_exists?(:database => 'UnknownDB')
|
118
125
|
assert !@client.database_exists?(:database => 'temp/admin')
|
119
126
|
end
|
data/test/test_ddo.rb
CHANGED
@@ -68,7 +68,7 @@ class TestDdo < Test::Unit::TestCase
|
|
68
68
|
assert @client.class_exists?(CLASS)
|
69
69
|
assert_nothing_thrown do @client.get_class(CLASS); end # raises an Error if no class found
|
70
70
|
# already exist
|
71
|
-
assert_raise Orientdb4r::
|
71
|
+
assert_raise Orientdb4r::ServerError do @client.create_class(CLASS); end
|
72
72
|
|
73
73
|
# create with :force=>true
|
74
74
|
assert_nothing_thrown do @client.create_class(CLASS, :force => true); end
|
@@ -85,7 +85,7 @@ class TestDdo < Test::Unit::TestCase
|
|
85
85
|
assert_equal 'OUser', clazz.super_class
|
86
86
|
|
87
87
|
# bad super class
|
88
|
-
assert_raise Orientdb4r::
|
88
|
+
assert_raise Orientdb4r::ServerError do @client.create_class(CLASS, :extends => 'nonExistingSuperClass'); end
|
89
89
|
end
|
90
90
|
|
91
91
|
|
@@ -121,7 +121,7 @@ class TestDdo < Test::Unit::TestCase
|
|
121
121
|
assert_nil clazz.property(:prop1).linked_class
|
122
122
|
|
123
123
|
# already exist
|
124
|
-
assert_raise Orientdb4r::
|
124
|
+
assert_raise Orientdb4r::ServerError do @client.create_property(CLASS, 'prop1', :integer); end
|
125
125
|
end
|
126
126
|
|
127
127
|
|
@@ -135,12 +135,12 @@ class TestDdo < Test::Unit::TestCase
|
|
135
135
|
assert_equal 'OUser', clazz.property(:friends).linked_class
|
136
136
|
|
137
137
|
# unknow linked-class
|
138
|
-
assert_raise Orientdb4r::
|
138
|
+
assert_raise Orientdb4r::ServerError do
|
139
139
|
@client.create_property(CLASS, 'friends2', :linkset, :linked_class => 'UnknownClass')
|
140
140
|
end
|
141
141
|
|
142
142
|
# already exist
|
143
|
-
assert_raise Orientdb4r::
|
143
|
+
assert_raise Orientdb4r::ServerError do
|
144
144
|
@client.create_property(CLASS, 'friends', :linkset, :linked_class => 'OUser');
|
145
145
|
end
|
146
146
|
end
|
@@ -183,6 +183,44 @@ class TestDdo < Test::Unit::TestCase
|
|
183
183
|
assert_nil user.min
|
184
184
|
assert_nil user.max
|
185
185
|
assert_equal 'OUser', user.linked_class
|
186
|
+
|
187
|
+
|
188
|
+
# properties direct as parametr
|
189
|
+
@client.drop_class CLASS
|
190
|
+
assert_nothing_thrown do
|
191
|
+
@client.create_class(CLASS, :properties => [
|
192
|
+
{ :property => 'prop1_q', :type => :integer },
|
193
|
+
{ :property => 'prop2_q', :type => :string, :mandatory => true, :notnull => true, :min => 1, :max => 99 },
|
194
|
+
{ :property => 'user_q', :type => :linkset, :linked_class => 'OUser', :mandatory => true }
|
195
|
+
])
|
196
|
+
end
|
197
|
+
|
198
|
+
clazz = @client.get_class(CLASS)
|
199
|
+
assert_equal 3, clazz.properties.size
|
200
|
+
|
201
|
+
prop1 = clazz.property(:prop1_q)
|
202
|
+
assert_equal 'INTEGER', prop1.type
|
203
|
+
assert !prop1.mandatory
|
204
|
+
assert !prop1.not_null
|
205
|
+
assert_nil prop1.min
|
206
|
+
assert_nil prop1.max
|
207
|
+
assert_nil prop1.linked_class
|
208
|
+
|
209
|
+
prop2 = clazz.property(:prop2_q)
|
210
|
+
assert_equal 'STRING', prop2.type
|
211
|
+
assert prop2.mandatory
|
212
|
+
assert prop2.not_null
|
213
|
+
assert_equal '1', prop2.min
|
214
|
+
assert_equal '99', prop2.max
|
215
|
+
assert_nil prop2.linked_class
|
216
|
+
|
217
|
+
user = clazz.property(:user_q)
|
218
|
+
assert_equal 'LINKSET', user.type
|
219
|
+
assert user.mandatory
|
220
|
+
assert !user.not_null
|
221
|
+
assert_nil user.min
|
222
|
+
assert_nil user.max
|
223
|
+
assert_equal 'OUser', user.linked_class
|
186
224
|
end
|
187
225
|
|
188
226
|
end
|
data/test/test_dmo.rb
CHANGED
@@ -52,11 +52,11 @@ class TestDmo < Test::Unit::TestCase
|
|
52
52
|
assert_equal urids.size, @client.query("SELECT FROM #{CLASS} WHERE prop2 = 'linkset'")[0]['friends'].size
|
53
53
|
|
54
54
|
# table doesn't exist
|
55
|
-
assert_raise Orientdb4r::
|
55
|
+
assert_raise Orientdb4r::ServerError do
|
56
56
|
@client.command "INSERT INTO #{CLASS}x (prop1, prop2, friends) VALUES (1, 'linkset', [#{urids.join(',')}])"
|
57
57
|
end
|
58
58
|
# bad syntax
|
59
|
-
assert_raise Orientdb4r::
|
59
|
+
assert_raise Orientdb4r::ServerError do
|
60
60
|
@client.command 'xxx'
|
61
61
|
end
|
62
62
|
|
@@ -94,15 +94,17 @@ class TestDmo < Test::Unit::TestCase
|
|
94
94
|
assert_equal 1, gr.select { |e| e if e['@class'] == 'ORole' }.size
|
95
95
|
|
96
96
|
# table doesn't exist
|
97
|
-
assert_raise Orientdb4r::
|
97
|
+
assert_raise Orientdb4r::ServerError do
|
98
98
|
@client.query 'SELECT FROM OUserX'
|
99
99
|
end
|
100
100
|
# bad syntax
|
101
|
-
assert_raise Orientdb4r::
|
101
|
+
assert_raise Orientdb4r::ServerError do
|
102
102
|
@client.query 'xxx'
|
103
103
|
end
|
104
|
+
# record not found
|
105
|
+
assert_raise Orientdb4r::NotFoundError do @client.query 'SELECT FROM #4:1111'; end
|
104
106
|
# used for INSERT
|
105
|
-
assert_raise Orientdb4r::
|
107
|
+
assert_raise Orientdb4r::ServerError do
|
106
108
|
@client.query "INSERT INTO #{CLASS} (prop1, prop2, friends) VALUES (0, 'string0', [])"
|
107
109
|
end
|
108
110
|
end
|