rews 0.1.0 → 0.2.0

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/lib/rews.rb CHANGED
@@ -19,37 +19,5 @@ require 'rews/sort_order'
19
19
  require 'rews/view'
20
20
  require 'rews/folder'
21
21
  require 'rews/item'
22
+ require 'rews/client'
22
23
 
23
- module Rews
24
- class Client
25
- attr_reader :client
26
- attr_accessor :logdev
27
-
28
- # Rews::Client.new('https://exchange.foo.com/EWS/Exchange.asmx', :ntlm, 'DOMAIN\\user', 'password')
29
- # Rews::Client.new('https://exchange.foo.com/EWS/Exchange.asmx', :basic, 'DOMAIN\\user', 'password')
30
- def initialize(endpoint, auth_type, user, password)
31
- @client = Savon::Client.new do
32
- wsdl.endpoint = endpoint
33
- wsdl.namespace = SCHEMA_MESSAGES
34
-
35
- http.auth.ssl.verify_mode = :none
36
- http.auth.send(auth_type, user, password)
37
- end
38
- end
39
-
40
- # client.distinguished_folder_id('inbox')
41
- # client.distinguished_folder_id('inbox', 'foo@bar.com') # to get a folder from another mailbox
42
- def distinguished_folder_id(id, mailbox_email=nil)
43
- Folder::DistinguishedFolderId.new(client, id, mailbox_email)
44
- end
45
-
46
- def log
47
- yield logger if @logdev
48
- end
49
-
50
- def logger
51
- return @logger if @logger
52
- @logger = Logger.new(@logdev) if @logdev
53
- end
54
- end
55
- end
@@ -0,0 +1,18 @@
1
+ # a stand-in for a Savon Client, which does instance_eval with delegation
2
+ # like the Savon Client
3
+ class RequestProxy
4
+ attr_accessor :soap
5
+ def initialize
6
+ @soap=Object.new
7
+ end
8
+
9
+ def eval_with_delegation(&block)
10
+ @self_before_instance_eval = eval "self", block.binding
11
+ instance_eval &block
12
+ end
13
+
14
+ def method_missing(method, *args, &block)
15
+ @self_before_instance_eval.send method, *args, &block
16
+ end
17
+ end
18
+
@@ -0,0 +1,21 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+ module Rews
4
+ describe Client do
5
+ it "should create new DistinguishedFolderIds for arbitrary mailboxes" do
6
+ client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
7
+
8
+ mock(Folder::DistinguishedFolderId).new(client.client, 'inbox', 'foo@bar.com')
9
+
10
+ client.distinguished_folder_id('inbox', 'foo@bar.com')
11
+ end
12
+
13
+ it "should create new DistinguishedFolderIds for the default mailbox" do
14
+ client = Client.new("https://foo/EWS/Exchange.asmx", :ntlm, "EXCHDOM\\foo", "password")
15
+
16
+ mock(Folder::DistinguishedFolderId).new(client.client, 'inbox', nil)
17
+
18
+ client.distinguished_folder_id('inbox')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,402 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+ module Rews
4
+ describe Folder do
5
+ describe Folder::Folder do
6
+ it "should parse the folder_id and attributes from the XML hash" do
7
+ client = Object.new
8
+
9
+ i = Folder::Folder.new(client, {:folder_id=>{:id=>"abc", :change_key=>'def'}, :foo=>100})
10
+ i.client.should == client
11
+ i.folder_id.should == Folder::VanillaFolderId.new(client, {:id=>'abc', :change_key=>"def"})
12
+ i[:foo].should == 100
13
+ end
14
+ end
15
+
16
+ describe Folder::DistinguishedFolderId do
17
+ it "should generate DistinguishedFolderId xml for the default mailbox" do
18
+ client = Object.new
19
+ xml = Folder::DistinguishedFolderId.new(client, 'inbox').to_xml
20
+ doc = Nokogiri::XML(xml)
21
+ dfid=doc.children.first
22
+ dfid.name.should == "DistinguishedFolderId"
23
+ dfid[:Id].should == 'inbox'
24
+ dfid.children.size.should == 0
25
+ end
26
+
27
+ it "should generate DistinguishedFolderId xml for a specified mailbox" do
28
+ client = Object.new
29
+ xml = Folder::DistinguishedFolderId.new(client, 'inbox', 'foo@bar.com').to_xml
30
+ doc = Nokogiri::XML(xml)
31
+ dfid=doc.children.first
32
+ dfid.name.should == "DistinguishedFolderId"
33
+ dfid[:Id].should == 'inbox'
34
+ dfid.children.size.should == 1
35
+
36
+ mb = dfid.children.first
37
+ mb.name.should == "Mailbox"
38
+ mb.children.size.should == 1
39
+
40
+ ea = mb.children.first
41
+ ea.name.should == "EmailAddress"
42
+ ea.content.should == 'foo@bar.com'
43
+ ea.children.size.should == 1 # the content
44
+ end
45
+ end
46
+
47
+ describe Folder::VanillaFolderId do
48
+ it "should generate FolderId xml with a change_key" do
49
+ client = Object.new
50
+ xml = Folder::VanillaFolderId.new(client, {:id=>"abc", :change_key=>"def"}).to_xml
51
+ doc = Nokogiri::XML(xml)
52
+ fid=doc.children.first
53
+ fid.name.should=="FolderId"
54
+ fid[:Id].should == "abc"
55
+ fid[:ChangeKey].should == "def"
56
+ end
57
+
58
+ it "should generate FolderId without a change_key" do
59
+ client = Object.new
60
+ xml = Folder::VanillaFolderId.new(client, {:id=>"abc"}).to_xml
61
+ doc = Nokogiri::XML(xml)
62
+ fid=doc.children.first
63
+ fid.name.should=="FolderId"
64
+ fid[:Id].should == "abc"
65
+ fid[:ChangeKey].should == nil
66
+ end
67
+ end
68
+
69
+ describe Folder::BaseFolderId do
70
+ def mock_request(client, action, attrs, response)
71
+ # deal with different call arity
72
+ mock(client).request(*[:wsdl, action, attrs].compact) do |*args|
73
+ block = args.last # block is the last arg
74
+
75
+ ctx = RequestProxy.new()
76
+ ns = Object.new
77
+ mock(ctx.soap).namespaces{ns}
78
+ mock(ns)["xmlns:t"]=Rews::SCHEMA_TYPES
79
+ mock(ctx.soap).body=(anything)
80
+
81
+ ctx.eval_with_delegation(&block)
82
+ response
83
+ end
84
+ end
85
+
86
+ describe "find_folder" do
87
+ def test_find_folder(client, folder_shape, indexed_page_folder_view, restriction, result)
88
+ shape = Object.new
89
+ mock(Shape::FolderShape).new(folder_shape||{}){shape}
90
+ mock(shape).to_xml{""}
91
+
92
+ if indexed_page_folder_view
93
+ view = Object.new
94
+ mock(View::IndexedPageFolderView).new(indexed_page_folder_view){view}
95
+ mock(view).to_xml{""}
96
+ end
97
+
98
+ if restriction
99
+ r = Object.new
100
+ mock(Restriction).new(restriction){r}
101
+ mock(r).to_xml{""}
102
+ end
103
+
104
+ fid = Folder::DistinguishedFolderId.new(client, 'blah')
105
+ mock.proxy(fid).to_xml
106
+
107
+ response = Object.new
108
+ mock(response).to_hash{{:find_folder_response=>{:response_messages=>{:find_folder_response_message=>{:response_class=>"Success", :root_folder=>result}}}}}
109
+
110
+ mock_request(client, "FindFolder", {"Traversal"=>"Shallow"}, response)
111
+
112
+ opts = {}
113
+ opts[:folder_shape] = folder_shape if folder_shape
114
+ opts[:indexed_page_folder_view] = indexed_page_folder_view if indexed_page_folder_view
115
+ opts[:restriction] = restriction if restriction
116
+ fid.find_folder(opts)
117
+ end
118
+
119
+ it "should generate minimal xml and parse a response with one folder" do
120
+ client = Object.new
121
+ folders = test_find_folder(client,
122
+ {:base_shape=>:IdOnly},
123
+ nil,
124
+ nil,
125
+ {:includes_last_item_in_range=>false,
126
+ :indexed_paging_offset=>0,
127
+ :total_items_in_view=>1,
128
+ :folders=>{:folder=>{:folder_id=>{:id=>"abc", :change_key=>"def"}}}})
129
+ folders.includes_last_item_in_range.should == false
130
+ folders.indexed_paging_offset.should == 0
131
+ folders.total_items_in_view.should == 1
132
+ folders.result.first.should == Folder::Folder.new(client, :folder_id=>{:id=>"abc", :change_key=>"def"})
133
+
134
+ end
135
+
136
+ it "should generate xml with indexed_page_folder_view and parse a response with multiple folders" do
137
+ client = Object.new
138
+ folders = test_find_folder(client,
139
+ {:base_shape=>:Default},
140
+ {:max_entries_returned=>10, :offset=>10, :base_point=>:Beginning},
141
+ [[:== , "item:DateTimeReceived", DateTime.now]],
142
+ {:includes_last_item_in_range=>true,
143
+ :indexed_paging_offset=>10,
144
+ :total_items_in_view=>5,
145
+ :folders=>{:folder=>[{:folder_id=>{:id=>"abc", :change_key=>"def"}},
146
+ {:folder_id=>{:id=>"ghi", :change_key=>"jkl"}}]}})
147
+ folders.includes_last_item_in_range.should == true
148
+ folders.indexed_paging_offset.should == 10
149
+ folders.total_items_in_view.should == 5
150
+ folders.result.first.should == Folder::Folder.new(client, :folder_id=>{:id=>"abc", :change_key=>"def"})
151
+ folders.result[1].should == Folder::Folder.new(client, :folder_id=>{:id=>"ghi", :change_key=>"jkl"})
152
+ end
153
+ end
154
+
155
+ describe "find_folder_id" do
156
+ it "should call find_folder with a default BaseShape of IdOnly" do
157
+ client=Object.new
158
+
159
+ fid = Folder::DistinguishedFolderId.new(client, 'blah')
160
+
161
+ opts = {:indexed_page_folder_view=>{:max_entries_returned=>10, :offset=>10, :base_point=>:Beginning},
162
+ :restriction=>[[:==, "item:DateTimeReceived", DateTime.now]]}
163
+ mock(fid).find_folder(opts){Folder::FindResult.new(:includes_last_item_in_range=>true, :indexed_paging_offset=>10, :total_items_in_view=>3){[Folder::Folder.new(client, {:folder_id=>{:id=>"abc", :change_key=>"def"}})]}}
164
+
165
+ fres = fid.find_folder_id(opts)
166
+ fres.includes_last_item_in_range.should == true
167
+ fres.indexed_paging_offset.should == 10
168
+ fres.total_items_in_view.should == 3
169
+ end
170
+ end
171
+
172
+ def test_find_item(client, item_shape, indexed_page_item_view, restriction, result)
173
+ shape = Object.new
174
+ mock(Shape::ItemShape).new(item_shape||{}){shape}
175
+ mock(shape).to_xml{""}
176
+
177
+ if indexed_page_item_view
178
+ view = Object.new
179
+ mock(View::IndexedPageItemView).new(indexed_page_item_view){view}
180
+ mock(view).to_xml{""}
181
+ end
182
+
183
+ if restriction
184
+ r = Object.new
185
+ mock(Restriction).new(restriction){r}
186
+ mock(r).to_xml{""}
187
+ end
188
+
189
+ fid = Folder::DistinguishedFolderId.new(client, 'blah')
190
+ mock.proxy(fid).to_xml
191
+
192
+ response = Object.new
193
+ mock(response).to_hash{{:find_item_response=>{:response_messages=>{:find_item_response_message=>{:response_class=>"Success", :root_folder=>result}}}}}
194
+
195
+ mock_request(client, "FindItem", {"Traversal"=>"Shallow"}, response)
196
+
197
+ opts = {}
198
+ opts[:item_shape] = item_shape if item_shape
199
+ opts[:indexed_page_item_view] = indexed_page_item_view if indexed_page_item_view
200
+ opts[:restriction] = restriction if restriction
201
+ fid.find_item(opts)
202
+ end
203
+
204
+ describe "find_item" do
205
+ it "should generate minimal xml and parse a response with one item" do
206
+ client = Object.new
207
+ items = test_find_item(client,
208
+ {:base_shape=>:IdOnly},
209
+ nil,
210
+ nil,
211
+ {:includes_last_item_in_range=>false,
212
+ :indexed_paging_offset=>0,
213
+ :total_items_in_view=>1,
214
+ :items=>{:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}}})
215
+ items.includes_last_item_in_range.should == false
216
+ items.indexed_paging_offset.should == 0
217
+ items.total_items_in_view.should == 1
218
+ items.result.size.should == 1
219
+ items.result.first.should == Item::Item.new(client, :message, :item_id=>{:id=>"abc", :change_key=>"def"})
220
+ end
221
+
222
+ it "should generate xml with indexed_page_folder_view and parse a response with multiple folders" do
223
+ client = Object.new
224
+ items = test_find_item(client,
225
+ {:base_shape=>:IdOnly},
226
+ {:max_entries_returned=>10, :offset=>10, :base_point=>:Beginning},
227
+ [[:== , "item:DateTimeReceived", DateTime.now]],
228
+ {:includes_last_item_in_range=>false,
229
+ :indexed_paging_offset=>0,
230
+ :total_items_in_view=>1,
231
+ :items=>{:message=>[{:item_id=>{:id=>"abc", :change_key=>"def"}},
232
+ {:item_id=>{:id=>"ghi", :change_key=>"jkl"}}]}})
233
+ items.includes_last_item_in_range.should == false
234
+ items.indexed_paging_offset.should == 0
235
+ items.total_items_in_view.should == 1
236
+ items.result.size.should == 2
237
+ items.result.first.should == Item::Item.new(client, :message, :item_id=>{:id=>"abc", :change_key=>"def"})
238
+ items.result[1].should == Item::Item.new(client, :message, :item_id=>{:id=>"ghi", :change_key=>"jkl"})
239
+ end
240
+ end
241
+
242
+ describe "find_item_id" do
243
+ it "should call find_folder with a default BaseShape of IdOnly" do
244
+ client=Object.new
245
+
246
+ fid = Folder::DistinguishedFolderId.new(client, 'blah')
247
+
248
+ opts = {
249
+ :indexed_page_item_view=>{:max_entries_returned=>10, :offset=>10, :base_point=>:Beginning}
250
+ }
251
+
252
+ mock(fid).find_item(opts.merge(:item_shape=>{:base_shape=>:IdOnly})) do
253
+ Folder::FindResult.new(:includes_last_item_in_range=>false,
254
+ :indexed_paging_offset=>10,
255
+ :total_items_in_view=>10) do
256
+ [Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}})]
257
+ end
258
+ end
259
+
260
+ res = fid.find_item_id(opts)
261
+ res.includes_last_item_in_range.should == false
262
+ res.indexed_paging_offset.should == 10
263
+ res.total_items_in_view.should == 10
264
+ end
265
+ end
266
+
267
+ describe "get_item" do
268
+ def test_get_item(client, item_shape, ignore_change_keys, message_ids, result)
269
+ shape = Object.new
270
+ mock(Shape::ItemShape).new(item_shape||{}){shape}
271
+ mock(shape).to_xml{""}
272
+
273
+ fid = Folder::DistinguishedFolderId.new(client, 'blah')
274
+
275
+ message_ids = message_ids.result if message_ids.is_a?(Folder::FindResult)
276
+ message_ids.each do |mid|
277
+ if mid.is_a?(Item::Item)
278
+ mock(mid.item_id).to_xml(ignore_change_keys){""}
279
+ else
280
+ mock(mid).to_xml(ignore_change_keys){""}
281
+ end
282
+ end
283
+
284
+ response = Object.new
285
+ mock(response).to_hash{{:get_item_response=>{:response_messages=>{:get_item_response_message=>{:response_class=>"Success", :items=>result}}}}}
286
+
287
+ mock_request(client, "GetItem", nil, response)
288
+
289
+ opts = {}
290
+ opts[:item_shape]=item_shape if item_shape
291
+ opts[:ignore_change_keys]=ignore_change_keys if ignore_change_keys
292
+ fid.get_item(message_ids, opts)
293
+ end
294
+
295
+ it "should generate xml including all provided ItemIds and parse response" do
296
+ client = Object.new
297
+ items = test_get_item(client,
298
+ {:base_shape=>:IdOnly},
299
+ nil,
300
+ [Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"})],
301
+ {:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
302
+ items.size.should == 1
303
+ msg=items.first
304
+ msg.item_id.should == Item::ItemId.new(client, :id=>"abc", :change_key=>"def")
305
+ end
306
+
307
+ it "should generate xml ignoring change keys if requested and parsing a response with multiple items" do
308
+ client = Object.new
309
+ items = test_get_item(client,
310
+ {:base_shape=>:Default},
311
+ true,
312
+ [Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"}),
313
+ Item::ItemId.new(client, {:id=>"ghi", :change_key=>"jkl"})],
314
+ {:message=>[{:item_id=>{:id=>"abc", :change_key=>"def"}},
315
+ {:item_id=>{:id=>"ghi", :change_key=>"jkl"}}]})
316
+ items.size.should == 2
317
+ items.first.item_id.should == Item::ItemId.new(client, :id=>"abc", :change_key=>"def")
318
+ items[1].item_id.should == Item::ItemId.new(client, :id=>"ghi", :change_key=>"jkl")
319
+ end
320
+
321
+ it "should extract ItemIds from Items if items are provided as identifiers" do
322
+ client = Object.new
323
+ items = test_get_item(client,
324
+ {:base_shape=>:Default},
325
+ true,
326
+ [Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}}),
327
+ Item::Item.new(client, :message, {:item_id=>{:id=>"ghi", :change_key=>"jkl"}})],
328
+ {:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
329
+ end
330
+
331
+ it "should extract results from a FindResult if a FindResult is provided for identifiers" do
332
+ client = Object.new
333
+ items = test_get_item(client,
334
+ {:base_shape=>:Default},
335
+ true,
336
+ Folder::FindResult.new({}) {
337
+ [Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}}),
338
+ Item::Item.new(client, :message, {:item_id=>{:id=>"ghi", :change_key=>"jkl"}})]},
339
+ {:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
340
+ end
341
+ end
342
+
343
+ describe "delete_item" do
344
+ def test_delete_item(client, delete_type, ignore_change_keys, message_ids)
345
+
346
+ fid = Folder::DistinguishedFolderId.new(client, 'blah')
347
+
348
+ message_ids = message_ids.result if message_ids.is_a?(Folder::FindResult)
349
+ message_ids.each do |mid|
350
+ if mid.is_a?(Item::Item)
351
+ mock(mid.item_id).to_xml(ignore_change_keys){""}
352
+ else
353
+ mock(mid).to_xml(ignore_change_keys){""}
354
+ end
355
+ end
356
+
357
+ response = Object.new
358
+ mock(response).to_hash{{:delete_item_response=>{:response_messages=>{:delete_item_response_message=>{:response_class=>"Success"}}}}}
359
+
360
+ mock_request(client, "DeleteItem", {:DeleteType=>delete_type}, response)
361
+
362
+ opts = {}
363
+ opts[:delete_type]=delete_type if delete_type
364
+ opts[:ignore_change_keys]=ignore_change_keys if ignore_change_keys
365
+ fid.delete_item(message_ids, opts)
366
+ end
367
+
368
+ it "should generate xml including a single ItemId" do
369
+ client = Object.new
370
+ test_delete_item(client, :HardDelete, nil, [Item::ItemId.new(client, :id=>"abc", :change_key=>"def")])
371
+ end
372
+
373
+ it "should generate xml ignoring change keys and including multiple ItemIds" do
374
+ client = Object.new
375
+ test_delete_item(client,
376
+ :HardDelete,
377
+ true,
378
+ [Item::ItemId.new(client, :id=>"abc", :change_key=>"def"),
379
+ Item::ItemId.new(client, :id=>"ghi", :change_key=>"jkl")])
380
+ end
381
+
382
+ it "should extract ItemIds from Items if Items are provided as identifiers" do
383
+ client = Object.new
384
+ test_delete_item(client,
385
+ :HardDelete,
386
+ true,
387
+ [Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}}),
388
+ Item::Item.new(client, :message, {:item_id=>{:id=>"ghi", :change_key=>"jkl"}})])
389
+ end
390
+
391
+ it "should extract ItemIds from a FindResult if a FindResult is provided as identifiers" do
392
+ client = Object.new
393
+ test_delete_item(client,
394
+ :HardDelete,
395
+ true,
396
+ Folder::FindResult.new({}) {[Item::Item.new(client, :message, {:item_id=>{:id=>"abc", :change_key=>"def"}}),
397
+ Item::Item.new(client, :message, {:item_id=>{:id=>"ghi", :change_key=>"jkl"}})]})
398
+ end
399
+ end
400
+ end
401
+ end
402
+ end
@@ -0,0 +1,124 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+ module Rews
4
+ describe Item do
5
+ describe Item::Item do
6
+ it "should parse the item_id and attributes from the XML hash" do
7
+ client = Object.new
8
+
9
+ i = Item::Item.new(client, 'Message', {:item_id=>{:id=>'1234', :change_key=>'abcd'}, :foo=>100})
10
+
11
+ i.client.should == client
12
+ i.item_class.should == 'Message'
13
+ i.item_id.should == Item::ItemId.new(client, {:id=>'1234', :change_key=>'abcd'})
14
+
15
+ i[:foo].should == 100
16
+ end
17
+ end
18
+
19
+ describe Item::ItemId do
20
+
21
+ describe "to_xml" do
22
+ it "should generate an ItemId with change_key by default" do
23
+ client = Object.new
24
+ xml = Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"}).to_xml
25
+ doc = Nokogiri::XML(xml)
26
+ id=doc.children.first
27
+ id.name.should == "ItemId"
28
+ id[:Id].should == "abc"
29
+ id[:ChangeKey].should == "def"
30
+ end
31
+
32
+ it "should generate an ItemId without change_key if requested" do
33
+ client = Object.new
34
+ xml = Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"}).to_xml(true)
35
+ doc = Nokogiri::XML(xml)
36
+ id=doc.children.first
37
+ id.name.should == "ItemId"
38
+ id[:Id].should == "abc"
39
+ id[:ChangeKey].should == nil
40
+ end
41
+ end
42
+
43
+ def mock_request(client, action, attrs, response)
44
+ # deal with different call arity
45
+ mock(client).request(*[:wsdl, action, attrs].compact) do |*args|
46
+ block = args.last # block is the last arg
47
+
48
+ ctx = RequestProxy.new()
49
+ ns = Object.new
50
+ mock(ctx.soap).namespaces{ns}
51
+ mock(ns)["xmlns:t"]=Rews::SCHEMA_TYPES
52
+ mock(ctx.soap).body=(anything)
53
+
54
+ ctx.eval_with_delegation(&block)
55
+ response
56
+ end
57
+ end
58
+
59
+ describe "get_item" do
60
+ def test_get_item(client, item_shape, ignore_change_keys, result)
61
+ shape = Object.new
62
+ mock(Shape::ItemShape).new(item_shape||{}){shape}
63
+ mock(shape).to_xml{""}
64
+
65
+ iid = Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"})
66
+ mock.proxy(iid).to_xml(ignore_change_keys){""}
67
+
68
+ response = Object.new
69
+ mock(response).to_hash{{:get_item_response=>{:response_messages=>{:get_item_response_message=>{:response_class=>"Success", :items=>result}}}}}
70
+
71
+ mock_request(client, "GetItem", nil, response)
72
+
73
+ opts={}
74
+ opts[:item_shape]=item_shape if item_shape
75
+ opts[:ignore_change_keys]=ignore_change_keys if ignore_change_keys
76
+ iid.get_item(opts)
77
+ end
78
+
79
+ it "should generate the BaseShape and ItemId xml and parse the response" do
80
+ client = Object.new
81
+ msg = test_get_item(client,
82
+ {:base_shape=>:IdOnly},
83
+ nil,
84
+ {:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
85
+ msg.item_class.should == :message
86
+ msg.item_id.should == Item::ItemId.new(client, :id=>"abc", :change_key=>"def")
87
+ end
88
+
89
+ it "should generate a request with no change_key if specified" do
90
+ client = Object.new
91
+ msg = test_get_item(client,
92
+ {:base_shape=>:Default},
93
+ true,
94
+ {:message=>{:item_id=>{:id=>"abc", :change_key=>"def"}}})
95
+ msg.item_class.should == :message
96
+ msg.item_id.should == Item::ItemId.new(client, :id=>"abc", :change_key=>"def")
97
+ end
98
+
99
+ end
100
+
101
+ describe "delete_item" do
102
+ def test_delete_item(client, ignore_change_keys, delete_type)
103
+ iid = Item::ItemId.new(client, {:id=>"abc", :change_key=>"def"})
104
+ mock.proxy(iid).to_xml(ignore_change_keys){""}
105
+
106
+ response = Object.new
107
+ mock(response).to_hash{{:delete_item_response=>{:response_messages=>{:delete_item_response_message=>{:response_class=>"Success"}}}}}
108
+
109
+ mock_request(client, "DeleteItem", {:DeleteType=>delete_type}, response)
110
+
111
+ opts={}
112
+ opts[:ignore_change_keys]=ignore_change_keys if ignore_change_keys
113
+ opts[:delete_type] = delete_type
114
+ iid.delete_item(opts)
115
+ end
116
+
117
+ it "should generate the ItemId xml and parse the response" do
118
+ client = Object.new
119
+ msg = test_delete_item(client, true, :HardDelete)
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,53 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+ module Rews
4
+ describe Restriction do
5
+ it "should write Restriction xml" do
6
+ xml = Restriction.new([:and,
7
+ [:<= , "item:DateTimeReceived", DateTime.parse("2011-03-14T17:02:17+00:00")],
8
+ [:> , "item:DateTimeReceived", DateTime.parse("2010-03-14T17:02:17+00:00")]]).to_xml
9
+
10
+ doc = Nokogiri::XML(xml)
11
+ r = doc.children.first
12
+ r.name.should == "Restriction"
13
+ r.children.size.should == 1
14
+
15
+ join = r.children.first
16
+ join.name.should == "And"
17
+ join.children.size.should == 2
18
+
19
+ le = join.children.first
20
+ le.name.should == "IsLessThanOrEqualTo"
21
+ le.children.size.should == 2
22
+
23
+ furi = le.children.first
24
+ furi.name.should == "FieldURI"
25
+ furi[:FieldURI].should == "item:DateTimeReceived"
26
+
27
+ foc = le.children[1]
28
+ foc.name.should == "FieldURIOrConstant"
29
+ foc.children.size.should == 1
30
+
31
+ furi2 = foc.children.first
32
+ furi2.name.should == "Constant"
33
+ furi2[:Value].should == DateTime.parse("2011-03-14T17:02:17+00:00").to_s
34
+
35
+
36
+ gt = join.children[1]
37
+ gt.name.should == "IsGreaterThan"
38
+ gt.children.size.should == 2
39
+
40
+ furi3 = gt.children.first
41
+ furi3.name.should == "FieldURI"
42
+ furi3[:FieldURI].should == "item:DateTimeReceived"
43
+
44
+ foc2 = gt.children[1]
45
+ foc2.name.should == "FieldURIOrConstant"
46
+ foc2.children.size.should == 1
47
+
48
+ furi4 = foc2.children.first
49
+ furi4.name.should == "Constant"
50
+ furi4[:Value].should == DateTime.parse("2010-03-14T17:02:17+00:00").to_s
51
+ end
52
+ end
53
+ end