salesforcebulk 1.4.0 → 4.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 (46) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +92 -117
  3. data/lib/salesforce_bulk.rb +2 -10
  4. data/lib/salesforce_bulk/batch.rb +1 -1
  5. data/lib/salesforce_bulk/batch_result.rb +11 -11
  6. data/lib/salesforce_bulk/client.rb +91 -70
  7. data/lib/salesforce_bulk/job.rb +8 -8
  8. data/lib/salesforce_bulk/query_result_collection.rb +11 -11
  9. data/lib/salesforce_bulk/version.rb +1 -1
  10. metadata +21 -115
  11. data/.gitignore +0 -4
  12. data/.travis.yml +0 -10
  13. data/Gemfile +0 -3
  14. data/LICENSE +0 -20
  15. data/Rakefile +0 -22
  16. data/lib/salesforce_bulk/core_extensions/string.rb +0 -14
  17. data/salesforcebulk.gemspec +0 -30
  18. data/test/fixtures/batch_create_request.csv +0 -3
  19. data/test/fixtures/batch_create_response.xml +0 -13
  20. data/test/fixtures/batch_info_list_response.xml +0 -27
  21. data/test/fixtures/batch_info_response.xml +0 -14
  22. data/test/fixtures/batch_result_list_response.csv +0 -3
  23. data/test/fixtures/config.yml +0 -5
  24. data/test/fixtures/invalid_batch_error.xml +0 -5
  25. data/test/fixtures/invalid_error.xml +0 -5
  26. data/test/fixtures/invalid_job_error.xml +0 -5
  27. data/test/fixtures/invalid_session_error.xml +0 -5
  28. data/test/fixtures/job_abort_request.xml +0 -1
  29. data/test/fixtures/job_abort_response.xml +0 -25
  30. data/test/fixtures/job_close_request.xml +0 -1
  31. data/test/fixtures/job_close_response.xml +0 -25
  32. data/test/fixtures/job_create_request.xml +0 -1
  33. data/test/fixtures/job_create_response.xml +0 -25
  34. data/test/fixtures/job_info_response.xml +0 -25
  35. data/test/fixtures/login_error.xml +0 -1
  36. data/test/fixtures/login_request.xml +0 -1
  37. data/test/fixtures/login_response.xml +0 -39
  38. data/test/fixtures/query_result_list_response.xml +0 -1
  39. data/test/fixtures/query_result_response.csv +0 -5
  40. data/test/lib/test_batch.rb +0 -252
  41. data/test/lib/test_batch_result.rb +0 -36
  42. data/test/lib/test_core_extensions.rb +0 -15
  43. data/test/lib/test_initialization.rb +0 -80
  44. data/test/lib/test_job.rb +0 -247
  45. data/test/lib/test_query_result_collection.rb +0 -86
  46. data/test/test_helper.rb +0 -32
@@ -1,3 +0,0 @@
1
- Id__c,Title__c,IsPreview__c
2
- 12345,This is a test video,
3
- 23456,A second test!,true
@@ -1,13 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><batchInfo
2
- xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <id>751E00000004ZmUIAU</id>
4
- <jobId>750E00000004NRfIAM</jobId>
5
- <state>Queued</state>
6
- <createdDate>2012-06-02T21:03:56.000Z</createdDate>
7
- <systemModstamp>2012-06-02T21:03:56.000Z</systemModstamp>
8
- <numberRecordsProcessed>0</numberRecordsProcessed>
9
- <numberRecordsFailed>0</numberRecordsFailed>
10
- <totalProcessingTime>0</totalProcessingTime>
11
- <apiActiveProcessingTime>0</apiActiveProcessingTime>
12
- <apexProcessingTime>0</apexProcessingTime>
13
- </batchInfo>
@@ -1,27 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><batchInfoList
2
- xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <batchInfo>
4
- <id>751E00000004ZRbIAM</id>
5
- <jobId>750E00000004N97IAE</jobId>
6
- <state>Completed</state>
7
- <createdDate>2012-05-31T01:22:47.000Z</createdDate>
8
- <systemModstamp>2012-05-31T01:22:47.000Z</systemModstamp>
9
- <numberRecordsProcessed>2</numberRecordsProcessed>
10
- <numberRecordsFailed>0</numberRecordsFailed>
11
- <totalProcessingTime>72</totalProcessingTime>
12
- <apiActiveProcessingTime>28</apiActiveProcessingTime>
13
- <apexProcessingTime>0</apexProcessingTime>
14
- </batchInfo>
15
- <batchInfo>
16
- <id>751E00000004ZQsIAM</id>
17
- <jobId>750E00000004N97IAE</jobId>
18
- <state>Completed</state>
19
- <createdDate>2012-05-31T01:23:20.000Z</createdDate>
20
- <systemModstamp>2012-05-31T01:23:20.000Z</systemModstamp>
21
- <numberRecordsProcessed>2</numberRecordsProcessed>
22
- <numberRecordsFailed>0</numberRecordsFailed>
23
- <totalProcessingTime>72</totalProcessingTime>
24
- <apiActiveProcessingTime>28</apiActiveProcessingTime>
25
- <apexProcessingTime>0</apexProcessingTime>
26
- </batchInfo>
27
- </batchInfoList>
@@ -1,14 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><batchInfo
2
- xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <id>751E00000004ZRbIAM</id>
4
- <jobId>750E00000004N97IAE</jobId>
5
- <state>Completed</state>
6
- <stateMessage>Success</stateMessage>
7
- <createdDate>2012-05-31T01:22:47.000Z</createdDate>
8
- <systemModstamp>2012-05-31T01:22:47.000Z</systemModstamp>
9
- <numberRecordsProcessed>2</numberRecordsProcessed>
10
- <numberRecordsFailed>0</numberRecordsFailed>
11
- <totalProcessingTime>72</totalProcessingTime>
12
- <apiActiveProcessingTime>28</apiActiveProcessingTime>
13
- <apexProcessingTime>0</apexProcessingTime>
14
- </batchInfo>
@@ -1,3 +0,0 @@
1
- "Id","Success","Created","Error"
2
- "a00E0000002V30LIAS","true","false",""
3
- "a00E0000002V30MIAS","true","false",""
@@ -1,5 +0,0 @@
1
- ---
2
- username: MyUsername
3
- password: MyPassword
4
- login_host: myhost.mydomain.com
5
- version: 88.0
@@ -1,5 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <error xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <exceptionCode>InvalidBatch</exceptionCode>
4
- <exceptionMessage>Records not processed</exceptionMessage>
5
- </error>
@@ -1,5 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><error
2
- xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <exceptionCode>UnsupportedContentType</exceptionCode>
4
- <exceptionMessage>Unsupported content type: text/cs; charset=UTF-8</exceptionMessage>
5
- </error>
@@ -1,5 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><error
2
- xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <exceptionCode>InvalidJob</exceptionCode>
4
- <exceptionMessage>Unable to find object: Video__c</exceptionMessage>
5
- </error>
@@ -1,5 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><error
2
- xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <exceptionCode>InvalidSessionId</exceptionCode>
4
- <exceptionMessage>Invalid session id</exceptionMessage>
5
- </error>
@@ -1 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?><jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload"><state>Aborted</state></jobInfo>
@@ -1,25 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><jobInfo
2
- xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <id>750E00000004N1NIAU</id>
4
- <operation>upsert</operation>
5
- <object>VideoEvent__c</object>
6
- <createdById>005E00000017spfIAA</createdById>
7
- <createdDate>2012-05-30T00:16:04.000Z</createdDate>
8
- <systemModstamp>2012-05-30T00:16:04.000Z</systemModstamp>
9
- <state>Aborted</state>
10
- <externalIdFieldName>Id__c</externalIdFieldName>
11
- <concurrencyMode>Parallel</concurrencyMode>
12
- <contentType>CSV</contentType>
13
- <numberBatchesQueued>0</numberBatchesQueued>
14
- <numberBatchesInProgress>0</numberBatchesInProgress>
15
- <numberBatchesCompleted>0</numberBatchesCompleted>
16
- <numberBatchesFailed>0</numberBatchesFailed>
17
- <numberBatchesTotal>0</numberBatchesTotal>
18
- <numberRecordsProcessed>0</numberRecordsProcessed>
19
- <numberRetries>0</numberRetries>
20
- <apiVersion>24.0</apiVersion>
21
- <numberRecordsFailed>0</numberRecordsFailed>
22
- <totalProcessingTime>0</totalProcessingTime>
23
- <apiActiveProcessingTime>0</apiActiveProcessingTime>
24
- <apexProcessingTime>0</apexProcessingTime>
25
- </jobInfo>
@@ -1 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?><jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload"><state>Closed</state></jobInfo>
@@ -1,25 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><jobInfo
2
- xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <id>750E00000004MzbIAE</id>
4
- <operation>upsert</operation>
5
- <object>VideoEvent__c</object>
6
- <createdById>005E00000017spfIAA</createdById>
7
- <createdDate>2012-05-29T23:51:53.000Z</createdDate>
8
- <systemModstamp>2012-05-29T23:51:53.000Z</systemModstamp>
9
- <state>Closed</state>
10
- <externalIdFieldName>Id__c</externalIdFieldName>
11
- <concurrencyMode>Parallel</concurrencyMode>
12
- <contentType>CSV</contentType>
13
- <numberBatchesQueued>0</numberBatchesQueued>
14
- <numberBatchesInProgress>0</numberBatchesInProgress>
15
- <numberBatchesCompleted>0</numberBatchesCompleted>
16
- <numberBatchesFailed>0</numberBatchesFailed>
17
- <numberBatchesTotal>0</numberBatchesTotal>
18
- <numberRecordsProcessed>0</numberRecordsProcessed>
19
- <numberRetries>0</numberRetries>
20
- <apiVersion>24.0</apiVersion>
21
- <numberRecordsFailed>0</numberRecordsFailed>
22
- <totalProcessingTime>0</totalProcessingTime>
23
- <apiActiveProcessingTime>0</apiActiveProcessingTime>
24
- <apexProcessingTime>0</apexProcessingTime>
25
- </jobInfo>
@@ -1 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?><jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload"><operation>upsert</operation><object>VideoEvent__c</object><externalIdFieldName>Id__c</externalIdFieldName><contentType>CSV</contentType></jobInfo>
@@ -1,25 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <id>750E00000004MzbIAE</id>
4
- <operation>upsert</operation>
5
- <object>VideoEvent__c</object>
6
- <createdById>005E00000017spfIAA</createdById>
7
- <createdDate>2012-05-29T21:50:47.000Z</createdDate>
8
- <systemModstamp>2012-05-29T21:50:47.000Z</systemModstamp>
9
- <state>Open</state>
10
- <externalIdFieldName>Id__c</externalIdFieldName>
11
- <concurrencyMode>Parallel</concurrencyMode>
12
- <contentType>CSV</contentType>
13
- <numberBatchesQueued>0</numberBatchesQueued>
14
- <numberBatchesInProgress>0</numberBatchesInProgress>
15
- <numberBatchesCompleted>0</numberBatchesCompleted>
16
- <numberBatchesFailed>0</numberBatchesFailed>
17
- <numberBatchesTotal>0</numberBatchesTotal>
18
- <numberRecordsProcessed>0</numberRecordsProcessed>
19
- <numberRetries>0</numberRetries>
20
- <apiVersion>24.0</apiVersion>
21
- <numberRecordsFailed>0</numberRecordsFailed>
22
- <totalProcessingTime>0</totalProcessingTime>
23
- <apiActiveProcessingTime>0</apiActiveProcessingTime>
24
- <apexProcessingTime>0</apexProcessingTime>
25
- </jobInfo>
@@ -1,25 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><jobInfo
2
- xmlns="http://www.force.com/2009/06/asyncapi/dataload">
3
- <id>750E00000004N1mIAE</id>
4
- <operation>upsert</operation>
5
- <object>VideoEvent__c</object>
6
- <createdById>005E00000017spfIAA</createdById>
7
- <createdDate>2012-05-30T04:08:30.000Z</createdDate>
8
- <systemModstamp>2012-05-30T04:08:30.000Z</systemModstamp>
9
- <state>Open</state>
10
- <externalIdFieldName>Id__c</externalIdFieldName>
11
- <concurrencyMode>Parallel</concurrencyMode>
12
- <contentType>CSV</contentType>
13
- <numberBatchesQueued>0</numberBatchesQueued>
14
- <numberBatchesInProgress>0</numberBatchesInProgress>
15
- <numberBatchesCompleted>0</numberBatchesCompleted>
16
- <numberBatchesFailed>0</numberBatchesFailed>
17
- <numberBatchesTotal>0</numberBatchesTotal>
18
- <numberRecordsProcessed>0</numberRecordsProcessed>
19
- <numberRetries>0</numberRetries>
20
- <apiVersion>24.0</apiVersion>
21
- <numberRecordsFailed>0</numberRecordsFailed>
22
- <totalProcessingTime>0</totalProcessingTime>
23
- <apiActiveProcessingTime>0</apiActiveProcessingTime>
24
- <apexProcessingTime>0</apexProcessingTime>
25
- </jobInfo>
@@ -1 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>sf:INVALID_LOGIN</faultcode><faultstring>INVALID_LOGIN: Invalid username, password, security token; or user locked out.</faultstring><detail><sf:LoginFault xsi:type="sf:LoginFault"><sf:exceptionCode>INVALID_LOGIN</sf:exceptionCode><sf:exceptionMessage>Invalid username, password, security token; or user locked out.</sf:exceptionMessage></sf:LoginFault></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope>
@@ -1 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><n1:login xmlns:n1="urn:partner.soap.sforce.com"><n1:username>MyUsername</n1:username><n1:password>MyPassword</n1:password></n1:login></env:Body></env:Envelope>
@@ -1,39 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
- <soapenv:Body>
4
- <loginResponse>
5
- <result>
6
- <metadataServerUrl>https://na9-api.salesforce.com/services/Soap/m/24.0/00DE0000000YSKp</metadataServerUrl>
7
- <passwordExpired>false</passwordExpired>
8
- <sandbox>false</sandbox>
9
- <serverUrl>https://na9-api.salesforce.com/services/Soap/u/24.0/00DE0000000YSKp</serverUrl>
10
- <sessionId>00DE0000000YSKp!AQ4AQNQhDKLMORZx2NwZppuKfure.ChCmdI3S35PPxpNA5MHb3ZVxhYd5STM3euVJTI5.39s.jOBT.3mKdZ3BWFDdIrddS8O</sessionId>
11
- <userId>005E00000017spfIAA</userId>
12
- <userInfo>
13
- <accessibilityMode>false</accessibilityMode>
14
- <currencySymbol>$</currencySymbol>
15
- <orgAttachmentFileSizeLimit>5242880</orgAttachmentFileSizeLimit>
16
- <orgDefaultCurrencyIsoCode>USD</orgDefaultCurrencyIsoCode>
17
- <orgDisallowHtmlAttachments>false</orgDisallowHtmlAttachments>
18
- <orgHasPersonAccounts>false</orgHasPersonAccounts>
19
- <organizationId>00DE0000000YSKpMAO</organizationId>
20
- <organizationMultiCurrency>false</organizationMultiCurrency>
21
- <organizationName>Gmail</organizationName>
22
- <profileId>00eE0000000oANhIAM</profileId>
23
- <roleId xsi:nil="true" />
24
- <sessionSecondsValid>7200</sessionSecondsValid>
25
- <userDefaultCurrencyIsoCode xsi:nil="true" />
26
- <userEmail>jjfutbol@gmail.com</userEmail>
27
- <userFullName>Javier Julio</userFullName>
28
- <userId>005E00000017spfIAA</userId>
29
- <userLanguage>en_US</userLanguage>
30
- <userLocale>en_US</userLocale>
31
- <userName>jjfutbol@gmail.com</userName>
32
- <userTimeZone>America/Panama</userTimeZone>
33
- <userType>Standard</userType>
34
- <userUiSkin>Theme3</userUiSkin>
35
- </userInfo>
36
- </result>
37
- </loginResponse>
38
- </soapenv:Body>
39
- </soapenv:Envelope>
@@ -1 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?><result-list xmlns="http://www.force.com/2009/06/asyncapi/dataload"><result>752E0000000TNaq</result></result-list>
@@ -1,5 +0,0 @@
1
- "Id__c","Title__c","IsPreview__c"
2
- "23456.0","A second test!","true"
3
- "12345.0","This is a test video","false"
4
- "3456.0","Some long title","false"
5
- "4567.0","Another test title for testing","true"
@@ -1,252 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestBatch < Test::Unit::TestCase
4
-
5
- def setup
6
- options = {
7
- :username => 'myusername',
8
- :password => 'mypassword'
9
- }
10
-
11
- @client = SalesforceBulk::Client.new(options)
12
- bypass_authentication(@client)
13
- @batch = SalesforceBulk::Batch.new
14
- @headers = {"Content-Type" => "text/csv; charset=UTF-8", 'X-Sfdc-Session' => '123456789'}
15
- @headersWithXml = {'Content-Type' => 'application/xml', 'X-Sfdc-Session' => '123456789'}
16
- end
17
-
18
- test "initialize from XML" do
19
- xml = fixture("batch_info_response.xml")
20
- batch = SalesforceBulk::Batch.new_from_xml(XmlSimple.xml_in(xml, 'ForceArray' => false))
21
-
22
- assert_equal batch.id, '751E00000004ZRbIAM'
23
- assert_equal batch.job_id, '750E00000004N97IAE'
24
- assert_equal batch.state, 'Completed'
25
- assert_equal batch.state_message, 'Success'
26
- assert_equal batch.created_at, DateTime.parse('2012-05-31T01:22:47.000Z')
27
- assert_equal batch.completed_at, DateTime.parse('2012-05-31T01:22:47.000Z')
28
- assert_equal batch.processed_records, 2
29
- assert_equal batch.failed_records, 0
30
- assert_equal batch.total_processing_time, 72
31
- assert_equal batch.api_active_processing_time, 28
32
- assert_equal batch.apex_processing_time, 0
33
- end
34
-
35
- test "state?" do
36
- @batch.state = "Completed"
37
- assert @batch.state?('Completed')
38
-
39
- @batch.state = "COMPLETED"
40
- assert @batch.state?('completed')
41
-
42
- @batch.state = "Failed"
43
- assert !@batch.state?('Queued')
44
- end
45
-
46
- test "state is marked queued" do
47
- @batch.state = "Queued"
48
- assert @batch.queued?
49
-
50
- @batch.state = nil
51
- assert !@batch.queued?
52
- end
53
-
54
- test "state is marked in progress" do
55
- @batch.state = "InProgress"
56
- assert @batch.in_progress?
57
-
58
- @batch.state = nil
59
- assert !@batch.in_progress?
60
- end
61
-
62
- test "state is marked completed" do
63
- @batch.state = "Completed"
64
- assert @batch.completed?
65
-
66
- @batch.state = nil
67
- assert !@batch.completed?
68
- end
69
-
70
- test "state is marked failed" do
71
- @batch.state = "Failed"
72
- assert @batch.failed?
73
-
74
- @batch.state = nil
75
- assert !@batch.failed?
76
- end
77
-
78
- test "should add a batch to a job and return a successful response" do
79
- request = fixture("batch_create_request.csv")
80
- response = fixture("batch_create_response.xml")
81
- job_id = "750E00000004NRfIAM"
82
- batch_id = "751E00000004ZmUIAU"
83
- data = [
84
- {:Id__c => '12345', :Title__c => "This is a test video", :IsPreview__c => nil},
85
- {:Id__c => '23456', :Title__c => "A second test!", :IsPreview__c => true}
86
- ]
87
-
88
- if RUBY_VERSION < '1.9'
89
- data.first.stubs(:keys).returns([:Id__c, :Title__c, :IsPreview__c])
90
- end
91
-
92
- stub_request(:post, "#{api_url(@client)}job/#{job_id}/batch").with(:body => request, :headers => @headers).to_return(:body => response, :status => 200)
93
-
94
- batch = @client.add_batch(job_id, data)
95
-
96
- assert_requested :post, "#{api_url(@client)}job/#{job_id}/batch", :body => request, :headers => @headers, :times => 1
97
-
98
- assert_equal batch.id, batch_id
99
- assert_equal batch.job_id, job_id
100
- assert_equal batch.state, 'Queued'
101
- assert_equal batch.created_at, DateTime.parse('2012-06-02T21:03:56.000Z')
102
- assert_equal batch.completed_at, DateTime.parse('2012-06-02T21:03:56.000Z')
103
- assert_equal batch.processed_records, 0
104
- assert_equal batch.failed_records, 0
105
- assert_equal batch.total_processing_time, 0
106
- assert_equal batch.api_active_processing_time, 0
107
- assert_equal batch.apex_processing_time, 0
108
- end
109
-
110
- test "should raise ArgumentError when given data array length exceeding 10000" do
111
- data = (1..10100).map { |index| {:Id => index} }
112
-
113
- assert_raise ArgumentError do
114
- @client.add_batch("750E00000004NRfIAM", data)
115
- end
116
- end
117
-
118
- test "should retrieve info for all batches in a job in a single request" do
119
- response = fixture("batch_info_list_response.xml")
120
- job_id = "750E00000004N97IAE"
121
-
122
- stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch").with(:headers => @headersWithXml).to_return(:body => response, :status => 200)
123
-
124
- batches = @client.batch_info_list(job_id)
125
-
126
- assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch", :headers => @headersWithXml, :times => 1
127
-
128
- assert_kind_of Array, batches
129
- assert_kind_of SalesforceBulk::Batch, batches.first
130
- assert_equal batches.length, 2
131
-
132
- batch = batches.first
133
- assert_equal batch.id, "751E00000004ZRbIAM"
134
- assert_equal batch.job_id, job_id
135
- assert_equal batch.state, 'Completed'
136
- assert_equal batch.created_at, DateTime.parse('2012-05-31T01:22:47.000Z')
137
- assert_equal batch.completed_at, DateTime.parse('2012-05-31T01:22:47.000Z')
138
- assert_equal batch.processed_records, 2
139
- assert_equal batch.failed_records, 0
140
- assert_equal batch.total_processing_time, 72
141
- assert_equal batch.api_active_processing_time, 28
142
- assert_equal batch.apex_processing_time, 0
143
-
144
- batch = batches.last
145
- assert_equal batch.id, "751E00000004ZQsIAM"
146
- assert_equal batch.job_id, job_id
147
- assert_equal batch.state, 'Completed'
148
- assert_equal batch.created_at, DateTime.parse('2012-05-31T01:23:20.000Z')
149
- assert_equal batch.completed_at, DateTime.parse('2012-05-31T01:23:20.000Z')
150
- assert_equal batch.processed_records, 2
151
- assert_equal batch.failed_records, 0
152
- assert_equal batch.total_processing_time, 72
153
- assert_equal batch.api_active_processing_time, 28
154
- assert_equal batch.apex_processing_time, 0
155
- end
156
-
157
- test "should retrieve batch info" do
158
- response = fixture("batch_info_response.xml")
159
- job_id = "750E00000004N97IAE"
160
- batch_id = "751E00000004ZRbIAM"
161
-
162
- stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}").with(:headers => @headersWithXml).to_return(:body => response, :status => 200)
163
-
164
- batch = @client.batch_info(job_id, batch_id)
165
-
166
- assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}", :headers => @headersWithXml, :times => 1
167
-
168
- assert_equal batch.id, batch_id
169
- assert_equal batch.job_id, job_id
170
- assert_equal batch.state, 'Completed'
171
- assert_equal batch.created_at, DateTime.parse('2012-05-31T01:22:47.000Z')
172
- assert_equal batch.completed_at, DateTime.parse('2012-05-31T01:22:47.000Z')
173
- assert_equal batch.processed_records, 2
174
- assert_equal batch.failed_records, 0
175
- assert_equal batch.total_processing_time, 72
176
- assert_equal batch.api_active_processing_time, 28
177
- assert_equal batch.apex_processing_time, 0
178
- end
179
-
180
- test "should return batch result for a non-querying job" do
181
- response = fixture("batch_result_list_response.csv")
182
- job_id = "750E00000004NRa"
183
- batch_id = "751E00000004ZmK"
184
-
185
- # Batches that are created using CSV will always return
186
- # results in CSV format despite requesting with XML content type.
187
- # Thus the content type header is ignored.
188
-
189
- stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result").to_return(:body => response, :status => 200)
190
-
191
- results = @client.batch_result(job_id, batch_id)
192
-
193
- assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result", :times => 1
194
-
195
- assert_kind_of SalesforceBulk::BatchResultCollection, results
196
- assert_kind_of Array, results
197
- assert_equal results.length, 2
198
- assert_equal results.job_id, job_id
199
- assert_equal results.batch_id, batch_id
200
- assert_equal results.first.success, true
201
- assert_equal results.first.created, false
202
- assert_equal results.first.error?, false
203
- assert_equal results.first.error, ''
204
- end
205
-
206
- test "retrieve result id for a query operation" do
207
- response = fixture("query_result_list_response.xml")
208
- job_id = "750E00000004NnR"
209
- batch_id = "751E00000004aEY"
210
- result_id = "752E0000000TNaq"
211
-
212
- stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result").with(:headers => @headersWithXml).to_return(:body => response, :status => 200)
213
-
214
- @client.expects(:query_result).with(job_id, batch_id, result_id).returns([])
215
-
216
- result = @client.batch_result(job_id, batch_id)
217
-
218
- assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result", :headers => @headersWithXml, :times => 1
219
- assert_kind_of SalesforceBulk::QueryResultCollection, result
220
- assert_equal result.job_id, job_id
221
- assert_equal result.batch_id, batch_id
222
- assert_equal result.result_id, result_id
223
- end
224
-
225
- test "retrieve and parse a query result successfully" do
226
- response = fixture("query_result_response.csv")
227
- job_id = "750E00000004NnR"
228
- batch_id = "751E00000004aEY"
229
- result_id = "752E0000000TNaq"
230
-
231
- stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result/#{result_id}").with(:headers => @headers).to_return(:body => response, :status => 200)
232
-
233
- result = @client.query_result(job_id, batch_id, result_id)
234
-
235
- assert_requested :get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result/#{result_id}", :headers => @headers, :times => 1
236
- assert_kind_of Array, result
237
- assert result.length == 4
238
- end
239
-
240
- test "should raise SalesforceError on invalid batch response" do
241
- response = fixture("invalid_batch_error.xml")
242
- job_id = "750E00000004NnR"
243
- batch_id = "751E00000004aEY"
244
-
245
- stub_request(:get, "#{api_url(@client)}job/#{job_id}/batch/#{batch_id}/result").with(:headers => @headersWithXml).to_return(:body => response, :status => 400)
246
-
247
- assert_raise SalesforceBulk::SalesforceError do
248
- @client.batch_result(job_id, batch_id)
249
- end
250
- end
251
-
252
- end