salesforcebulk 1.4.0 → 2.0.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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -15
  3. data/lib/salesforce_bulk.rb +1 -5
  4. data/lib/salesforce_bulk/client.rb +56 -59
  5. data/lib/salesforce_bulk/version.rb +1 -1
  6. metadata +46 -76
  7. data/.gitignore +0 -4
  8. data/.travis.yml +0 -10
  9. data/Gemfile +0 -3
  10. data/LICENSE +0 -20
  11. data/Rakefile +0 -22
  12. data/salesforcebulk.gemspec +0 -30
  13. data/test/fixtures/batch_create_request.csv +0 -3
  14. data/test/fixtures/batch_create_response.xml +0 -13
  15. data/test/fixtures/batch_info_list_response.xml +0 -27
  16. data/test/fixtures/batch_info_response.xml +0 -14
  17. data/test/fixtures/batch_result_list_response.csv +0 -3
  18. data/test/fixtures/config.yml +0 -5
  19. data/test/fixtures/invalid_batch_error.xml +0 -5
  20. data/test/fixtures/invalid_error.xml +0 -5
  21. data/test/fixtures/invalid_job_error.xml +0 -5
  22. data/test/fixtures/invalid_session_error.xml +0 -5
  23. data/test/fixtures/job_abort_request.xml +0 -1
  24. data/test/fixtures/job_abort_response.xml +0 -25
  25. data/test/fixtures/job_close_request.xml +0 -1
  26. data/test/fixtures/job_close_response.xml +0 -25
  27. data/test/fixtures/job_create_request.xml +0 -1
  28. data/test/fixtures/job_create_response.xml +0 -25
  29. data/test/fixtures/job_info_response.xml +0 -25
  30. data/test/fixtures/login_error.xml +0 -1
  31. data/test/fixtures/login_request.xml +0 -1
  32. data/test/fixtures/login_response.xml +0 -39
  33. data/test/fixtures/query_result_list_response.xml +0 -1
  34. data/test/fixtures/query_result_response.csv +0 -5
  35. data/test/lib/test_batch.rb +0 -252
  36. data/test/lib/test_batch_result.rb +0 -36
  37. data/test/lib/test_core_extensions.rb +0 -15
  38. data/test/lib/test_initialization.rb +0 -80
  39. data/test/lib/test_job.rb +0 -247
  40. data/test/lib/test_query_result_collection.rb +0 -86
  41. data/test/test_helper.rb +0 -32
@@ -1,247 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestJob < Test::Unit::TestCase
4
-
5
- def setup
6
- options = {
7
- :username => 'myusername',
8
- :password => 'mypassword'
9
- }
10
-
11
- @client = SalesforceBulk::Client.new(options)
12
- @job = SalesforceBulk::Job.new
13
- @headers = {'Content-Type' => 'application/xml', 'X-Sfdc-Session' => '123456789'}
14
-
15
- bypass_authentication(@client)
16
- end
17
-
18
- test "initialization from XML" do
19
- xml = fixture("job_info_response.xml")
20
- job = SalesforceBulk::Job.new_from_xml(XmlSimple.xml_in(xml, 'ForceArray' => false))
21
-
22
- assert_equal job.id, '750E00000004N1mIAE'
23
- assert_equal job.operation, 'upsert'
24
- assert_equal job.sobject, 'VideoEvent__c'
25
- assert_equal job.created_by, '005E00000017spfIAA'
26
- assert_equal job.created_at, DateTime.parse('2012-05-30T04:08:30.000Z')
27
- assert_equal job.completed_at, DateTime.parse('2012-05-30T04:08:30.000Z')
28
- assert_equal job.state, 'Open'
29
- assert_equal job.external_id_field_name, 'Id__c'
30
- assert_equal job.concurrency_mode, 'Parallel'
31
- assert_equal job.content_type, 'CSV'
32
- assert_equal job.queued_batches, 0
33
- assert_equal job.in_progress_batches, 0
34
- assert_equal job.completed_batches, 0
35
- assert_equal job.failed_batches, 0
36
- assert_equal job.total_batches, 0
37
- assert_equal job.processed_records, 0
38
- assert_equal job.failed_records, 0
39
- assert_equal job.retries, 0
40
- assert_equal job.api_active_processing_time, 0
41
- assert_equal job.apex_processing_time, 0
42
- assert_equal job.total_processing_time, 0
43
- assert_equal job.api_version, 24.0
44
- end
45
-
46
- test "state?" do
47
- @job.state = 'Closed'
48
- assert @job.state?('closed')
49
-
50
- @job.state = 'Closed'
51
- assert @job.state?('CLOSED')
52
-
53
- @job.state = nil
54
- assert !@job.state?('closed')
55
- end
56
-
57
- test "aborted?" do
58
- @job.state = 'Aborted'
59
- assert @job.aborted?
60
-
61
- @job.state = nil
62
- assert !@job.aborted?
63
- end
64
-
65
- test "closed?" do
66
- @job.state = 'Closed'
67
- assert @job.closed?
68
-
69
- @job.state = nil
70
- assert !@job.closed?
71
- end
72
-
73
- test "open?" do
74
- @job.state = 'Open'
75
- assert @job.open?
76
-
77
- @job.state = nil
78
- assert !@job.open?
79
- end
80
-
81
- test "add_job returns successful response" do
82
- request = fixture("job_create_request.xml")
83
- response = fixture("job_create_response.xml")
84
-
85
- stub_request(:post, "#{api_url(@client)}job").with(:body => request, :headers => @headers).to_return(:body => response, :status => 200)
86
-
87
- job = @client.add_job(:upsert, :VideoEvent__c, :external_id_field_name => :Id__c)
88
-
89
- assert_requested :post, "#{api_url(@client)}job", :body => request, :headers => @headers, :times => 1
90
-
91
- assert_equal job.id, '750E00000004MzbIAE'
92
- assert_equal job.operation, 'upsert'
93
- assert_equal job.sobject, 'VideoEvent__c'
94
- assert_equal job.created_by, '005E00000017spfIAA'
95
- assert_equal job.created_at, DateTime.parse('2012-05-29T21:50:47.000Z')
96
- assert_equal job.completed_at, DateTime.parse('2012-05-29T21:50:47.000Z')
97
- assert_equal job.state, 'Open'
98
- assert_equal job.external_id_field_name, 'Id__c'
99
- assert_equal job.concurrency_mode, 'Parallel'
100
- assert_equal job.content_type, 'CSV'
101
- assert_equal job.queued_batches, 0
102
- assert_equal job.in_progress_batches, 0
103
- assert_equal job.completed_batches, 0
104
- assert_equal job.failed_batches, 0
105
- assert_equal job.total_batches, 0
106
- assert_equal job.processed_records, 0
107
- assert_equal job.failed_records, 0
108
- assert_equal job.retries, 0
109
- assert_equal job.api_active_processing_time, 0
110
- assert_equal job.apex_processing_time, 0
111
- assert_equal job.total_processing_time, 0
112
- assert_equal job.api_version, 24.0
113
- end
114
-
115
- test "add_job raises ArgumentError if provided with invalid operation" do
116
- assert_raise ArgumentError do
117
- job = @client.add_job(:SomeOtherOperation, nil)
118
- end
119
- end
120
-
121
- test "add_job raises ArgumentError if provided with invalid key for options" do
122
- assert_raise ArgumentError do
123
- job = @client.add_job(:upsert, :VideoEvent__c, :non_existing_key => '')
124
- end
125
- end
126
-
127
- test "add_job raises ArgumentError if provided with invalid concurrency mode" do
128
- assert_raise ArgumentError do
129
- job = @client.add_job(:upsert, :VideoEvent__c, :concurrency_mode => 'SomeMode')
130
- end
131
- end
132
-
133
- test "should close job and return successful response" do
134
- request = fixture("job_close_request.xml")
135
- response = fixture("job_close_response.xml")
136
- job_id = "750E00000004MzbIAE"
137
-
138
- stub_request(:post, "#{api_url(@client)}job/#{job_id}").with(:body => request, :headers => @headers).to_return(:body => response, :status => 200)
139
-
140
- job = @client.close_job(job_id)
141
-
142
- assert_requested :post, "#{api_url(@client)}job/#{job_id}", :body => request, :headers => @headers, :times => 1
143
-
144
- assert_equal job.id, job_id
145
- assert_equal job.operation, 'upsert'
146
- assert_equal job.sobject, 'VideoEvent__c'
147
- assert_equal job.created_by, '005E00000017spfIAA'
148
- assert_equal job.created_at, DateTime.parse('2012-05-29T23:51:53.000Z')
149
- assert_equal job.completed_at, DateTime.parse('2012-05-29T23:51:53.000Z')
150
- assert_equal job.state, 'Closed'
151
- assert_equal job.external_id_field_name, 'Id__c'
152
- assert_equal job.concurrency_mode, 'Parallel'
153
- assert_equal job.content_type, 'CSV'
154
- assert_equal job.queued_batches, 0
155
- assert_equal job.in_progress_batches, 0
156
- assert_equal job.completed_batches, 0
157
- assert_equal job.failed_batches, 0
158
- assert_equal job.total_batches, 0
159
- assert_equal job.processed_records, 0
160
- assert_equal job.failed_records, 0
161
- assert_equal job.retries, 0
162
- assert_equal job.api_active_processing_time, 0
163
- assert_equal job.apex_processing_time, 0
164
- assert_equal job.total_processing_time, 0
165
- assert_equal job.api_version, 24.0
166
- end
167
-
168
- test "should abort job and return successful response" do
169
- request = fixture("job_abort_request.xml")
170
- response = fixture("job_abort_response.xml")
171
- job_id = "750E00000004N1NIAU"
172
-
173
- stub_request(:post, "#{api_url(@client)}job/#{job_id}").with(:body => request, :headers => @headers).to_return(:body => response, :status => 200)
174
-
175
- job = @client.abort_job(job_id)
176
-
177
- assert_requested :post, "#{api_url(@client)}job/#{job_id}", :body => request, :headers => @headers, :times => 1
178
-
179
- assert_equal job.id, job_id
180
- assert_equal job.operation, 'upsert'
181
- assert_equal job.sobject, 'VideoEvent__c'
182
- assert_equal job.created_by, '005E00000017spfIAA'
183
- assert_equal job.created_at, DateTime.parse('2012-05-30T00:16:04.000Z')
184
- assert_equal job.completed_at, DateTime.parse('2012-05-30T00:16:04.000Z')
185
- assert_equal job.state, 'Aborted'
186
- assert_equal job.external_id_field_name, 'Id__c'
187
- assert_equal job.concurrency_mode, 'Parallel'
188
- assert_equal job.content_type, 'CSV'
189
- assert_equal job.queued_batches, 0
190
- assert_equal job.in_progress_batches, 0
191
- assert_equal job.completed_batches, 0
192
- assert_equal job.failed_batches, 0
193
- assert_equal job.total_batches, 0
194
- assert_equal job.processed_records, 0
195
- assert_equal job.failed_records, 0
196
- assert_equal job.retries, 0
197
- assert_equal job.api_active_processing_time, 0
198
- assert_equal job.apex_processing_time, 0
199
- assert_equal job.total_processing_time, 0
200
- assert_equal job.api_version, 24.0
201
- end
202
-
203
- test "should return job info" do
204
- response = fixture("job_info_response.xml")
205
- job_id = "750E00000004N1mIAE"
206
-
207
- stub_request(:get, "#{api_url(@client)}job/#{job_id}").with(:body => '', :headers => @headers).to_return(:body => response, :status => 200)
208
-
209
- job = @client.job_info(job_id)
210
-
211
- assert_requested :get, "#{api_url(@client)}job/#{job_id}", :body => '', :headers => @headers, :times => 1
212
-
213
- assert_equal job.id, job_id
214
- assert_equal job.operation, 'upsert'
215
- assert_equal job.sobject, 'VideoEvent__c'
216
- assert_equal job.created_by, '005E00000017spfIAA'
217
- assert_equal job.created_at, DateTime.parse('2012-05-30T04:08:30.000Z')
218
- assert_equal job.completed_at, DateTime.parse('2012-05-30T04:08:30.000Z')
219
- assert_equal job.state, 'Open'
220
- assert_equal job.external_id_field_name, 'Id__c'
221
- assert_equal job.concurrency_mode, 'Parallel'
222
- assert_equal job.content_type, 'CSV'
223
- assert_equal job.queued_batches, 0
224
- assert_equal job.in_progress_batches, 0
225
- assert_equal job.completed_batches, 0
226
- assert_equal job.failed_batches, 0
227
- assert_equal job.total_batches, 0
228
- assert_equal job.processed_records, 0
229
- assert_equal job.failed_records, 0
230
- assert_equal job.retries, 0
231
- assert_equal job.api_active_processing_time, 0
232
- assert_equal job.apex_processing_time, 0
233
- assert_equal job.total_processing_time, 0
234
- assert_equal job.api_version, 24.0
235
- end
236
-
237
- test "should raise SalesforceError on invalid job" do
238
- response = fixture("invalid_job_error.xml")
239
-
240
- stub_request(:post, "#{api_url(@client)}job").to_return(:body => response, :status => 500)
241
-
242
- assert_raise SalesforceBulk::SalesforceError do
243
- job = @client.add_job(:upsert, :SomeNonExistingObject__c, :external_id_field_name => :Id__c)
244
- end
245
- end
246
-
247
- end
@@ -1,86 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestQueryResultCollection < Test::Unit::TestCase
4
-
5
- def setup
6
- options = {
7
- :username => 'myusername',
8
- :password => 'mypassword'
9
- }
10
-
11
- @client = SalesforceBulk::Client.new(options)
12
- @job_id = "123"
13
- @batch_id = "234"
14
- @result_ids = ["12","23","34"]
15
- @result_id = @result_ids[1]
16
- @collection = SalesforceBulk::QueryResultCollection.new(@client, @job_id, @batch_id, @result_id, @result_ids)
17
- end
18
-
19
- test "initilize using defaults" do
20
- collection = SalesforceBulk::QueryResultCollection.new(@client, @job_id, @batch_id)
21
-
22
- assert_equal collection.client, @client
23
- assert_equal collection.job_id, @job_id
24
- assert_equal collection.batch_id, @batch_id
25
- assert_nil collection.result_id
26
- assert_equal collection.result_ids, []
27
- assert_equal collection.instance_variable_get('@current_index'), 0
28
- end
29
-
30
- test "initilize with all values" do
31
- assert_equal @collection.client, @client
32
- assert_equal @collection.job_id, @job_id
33
- assert_equal @collection.batch_id, @batch_id
34
- assert_equal @collection.result_id, @result_id
35
- assert_equal @collection.result_ids, @result_ids
36
- end
37
-
38
- test "next?" do
39
- assert @collection.next?
40
-
41
- @collection.instance_variable_set('@current_index', @result_ids.length - 1)
42
- assert !@collection.next?
43
-
44
- @collection.instance_variable_set('@result_ids', [])
45
- assert !@collection.next?
46
-
47
- @collection.instance_variable_set('@result_ids', nil)
48
- assert !@collection.next?
49
- end
50
-
51
- test "next" do
52
- @client.expects(:query_result).once.with(@job_id, @batch_id, @result_ids.last).returns([])
53
-
54
- @collection.next
55
-
56
- assert_kind_of SalesforceBulk::QueryResultCollection, @collection
57
- assert @collection.previous?
58
- assert !@collection.next?
59
- assert !@collection.next.any?
60
- end
61
-
62
- test "previous?" do
63
- assert @collection.previous?
64
-
65
- @collection.instance_variable_set('@current_index', 0)
66
- assert !@collection.previous?
67
-
68
- @collection.instance_variable_set('@result_ids', [])
69
- assert !@collection.previous?
70
-
71
- @collection.instance_variable_set('@result_ids', nil)
72
- assert !@collection.previous?
73
- end
74
-
75
- test "previous" do
76
- @client.expects(:query_result).once.with(@job_id, @batch_id, @result_ids.first).returns([])
77
-
78
- @collection.previous
79
-
80
- assert_kind_of SalesforceBulk::QueryResultCollection, @collection
81
- assert @collection.next?
82
- assert !@collection.previous?
83
- assert !@collection.previous.any?
84
- end
85
-
86
- end
@@ -1,32 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
- require 'mocha/setup'
5
- require 'webmock/test_unit'
6
- require 'salesforce_bulk'
7
-
8
- class Test::Unit::TestCase
9
-
10
- def self.test(name, &block)
11
- define_method("test #{name.inspect}", &block)
12
- end
13
-
14
- def api_url(client)
15
- "https://#{client.login_host}/services/async/#{client.version}/"
16
- end
17
-
18
- def bypass_authentication(client)
19
- client.instance_variable_set('@session_id', '123456789')
20
- client.instance_variable_set('@login_host', 'na9.salesforce.com')
21
- client.instance_variable_set('@instance_host', 'na9.salesforce.com')
22
- end
23
-
24
- def fixture_path(file)
25
- File.expand_path("../fixtures/#{file}", __FILE__)
26
- end
27
-
28
- def fixture(file)
29
- File.new(fixture_path(file)).read
30
- end
31
-
32
- end