dor-workflow-service 1.7.6 → 1.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.rubocop_todo.yml +5 -54
- data/.travis.yml +2 -0
- data/Gemfile +1 -1
- data/Rakefile +1 -1
- data/dor-workflow-service.gemspec +18 -17
- data/lib/dor-workflow-service.rb +1 -1
- data/lib/dor/services/workflow_service.rb +134 -94
- data/lib/dor/workflow_version.rb +1 -1
- data/spec/plumbing_spec.rb +18 -0
- data/spec/spec_helper.rb +0 -3
- data/spec/workflow_service_spec.rb +162 -153
- metadata +48 -32
data/lib/dor/workflow_version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dor::WorkflowService do
|
4
|
+
before :each do
|
5
|
+
@logger1 = double('Logger')
|
6
|
+
allow(Dor::WorkflowService).to receive(:default_logger).and_return(@logger1)
|
7
|
+
end
|
8
|
+
describe '#configure' do
|
9
|
+
it 'pulls default_logger if not specified' do
|
10
|
+
expect(Dor::WorkflowService).to receive(:default_logger).and_return(@logger1)
|
11
|
+
Dor::WorkflowService.configure('https://dortest.stanford.edu/workflow')
|
12
|
+
end
|
13
|
+
it 'accepts :logger if specified' do
|
14
|
+
expect(Dor::WorkflowService).not_to receive(:default_logger)
|
15
|
+
Dor::WorkflowService.configure('https://dortest.stanford.edu/workflow', {:logger => @logger1})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Dor::WorkflowService do
|
4
|
-
|
5
4
|
let(:wf_xml) { <<-EOXML
|
6
5
|
<workflow id="etdSubmitWF">
|
7
6
|
<process name="register-object" status="completed" attempts="1" />
|
@@ -26,131 +25,130 @@ describe Dor::WorkflowService do
|
|
26
25
|
}
|
27
26
|
|
28
27
|
before(:each) do
|
29
|
-
@repo
|
28
|
+
@repo = 'dor'
|
30
29
|
@druid = 'druid:123'
|
31
|
-
|
32
|
-
@mock_logger = double('logger').as_null_object
|
33
|
-
allow(Rails).to receive(:logger).and_return(@mock_logger)
|
34
|
-
|
35
30
|
@mock_resource = double('mock_rest_client_resource')
|
31
|
+
@mock_logger = double('Logger')
|
36
32
|
allow(@mock_resource).to receive(:[]).and_return(@mock_resource)
|
37
33
|
allow(@mock_resource).to receive(:options).and_return( {} )
|
34
|
+
allow(@mock_resource).to receive(:url).and_return( 'https://dortest.stanford.edu/workflow' )
|
35
|
+
allow(@mock_logger).to receive(:info)
|
38
36
|
allow(RestClient::Resource).to receive(:new).and_return(@mock_resource)
|
37
|
+
allow(Dor::WorkflowService).to receive(:default_logger).and_return(@mock_logger)
|
39
38
|
Dor::WorkflowService.configure 'https://dortest.stanford.edu/workflow'
|
40
39
|
end
|
41
40
|
|
42
|
-
describe
|
43
|
-
it
|
44
|
-
expect(@mock_resource).to receive(:put).with(wf_xml_label, anything
|
41
|
+
describe '#create_workflow' do
|
42
|
+
it 'should pass workflow xml to the DOR workflow service and return the URL to the workflow' do
|
43
|
+
expect(@mock_resource).to receive(:put).with(wf_xml_label, anything).and_return('')
|
45
44
|
Dor::WorkflowService.create_workflow(@repo, @druid, 'etdSubmitWF', wf_xml)
|
46
45
|
end
|
47
46
|
|
48
|
-
it
|
49
|
-
ex = Exception.new(
|
50
|
-
|
51
|
-
|
47
|
+
it 'should log an error and retry upon a targetted RestClient exception, raise on an unexpected Exception' do
|
48
|
+
ex = RestClient::Exception.new(nil, 418)
|
49
|
+
ex.message = "I'm A Teapot"
|
50
|
+
runs = 0
|
51
|
+
expect(@mock_resource).to receive(:put).twice {
|
52
|
+
runs += 1
|
53
|
+
raise ex if runs == 1
|
54
|
+
raise Exception.new('Something Else Happened') if runs == 2
|
55
|
+
}
|
56
|
+
expect(@mock_logger).to receive(:warn).with(/\[Attempt 1\] RestClient::Exception: #{ex.message}/)
|
57
|
+
expect{ Dor::WorkflowService.create_workflow(@repo, @druid, 'etdSubmitWF', wf_xml) }.to raise_error(Exception, 'Something Else Happened')
|
52
58
|
end
|
53
59
|
|
54
|
-
it
|
60
|
+
it 'sets the create-ds param to the value of the passed in options hash' do
|
55
61
|
expect(@mock_resource).to receive(:put).with(wf_xml_label, :content_type => 'application/xml',
|
56
62
|
:params => {'create-ds' => false}).and_return('')
|
57
63
|
Dor::WorkflowService.create_workflow(@repo, @druid, 'etdSubmitWF', wf_xml, :create_ds => false)
|
58
64
|
end
|
59
65
|
|
60
|
-
it
|
61
|
-
|
66
|
+
it 'adds lane_id attributes to all steps if passed in as an option' do
|
67
|
+
skip 'test not implemented'
|
62
68
|
end
|
63
|
-
|
64
69
|
end
|
65
70
|
|
66
|
-
describe
|
67
|
-
|
68
|
-
it "adds laneId attributes to all process elements" do
|
71
|
+
describe '#add_lane_id_to_workflow_xml' do
|
72
|
+
it 'adds laneId attributes to all process elements' do
|
69
73
|
expected = <<-XML
|
70
74
|
<workflow id="etdSubmitWF">
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
<process name="register-object" status="completed" attempts="1" laneId="lane1"/>
|
76
|
+
<process name="submit" status="waiting" laneId="lane1"/>
|
77
|
+
<process name="reader-approval" status="waiting" laneId="lane1"/>
|
78
|
+
<process name="registrar-approval" status="waiting" laneId="lane1"/>
|
79
|
+
<process name="start-accession" status="waiting" laneId="lane1"/>
|
76
80
|
</workflow>
|
77
81
|
XML
|
78
|
-
|
79
82
|
expect(Dor::WorkflowService.send(:add_lane_id_to_workflow_xml, 'lane1', wf_xml)).to be_equivalent_to(expected)
|
80
83
|
end
|
81
84
|
end
|
82
85
|
|
83
|
-
describe
|
84
|
-
before
|
86
|
+
describe '#update_workflow_status' do
|
87
|
+
before :each do
|
85
88
|
@xml_re = /name="reader-approval"/
|
86
89
|
end
|
87
90
|
|
88
|
-
it
|
91
|
+
it 'should update workflow status and return true if successful' do
|
89
92
|
built_xml = "<?xml version=\"1.0\"?>\n<process name=\"reader-approval\" status=\"completed\" elapsed=\"0\" note=\"annotation\" version=\"2\" laneId=\"lane2\"/>\n"
|
90
93
|
expect(@mock_resource).to receive(:put).with(built_xml, { :content_type => 'application/xml' }).and_return('')
|
91
|
-
expect(Dor::WorkflowService.update_workflow_status(@repo, @druid,
|
94
|
+
expect(Dor::WorkflowService.update_workflow_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'completed', :version => 2, :note => 'annotation', :lane_id => 'lane2')).to be true
|
92
95
|
end
|
93
96
|
|
94
|
-
it
|
95
|
-
ex = Exception.new(
|
97
|
+
it 'should return false if the PUT to the DOR workflow service throws an exception' do
|
98
|
+
ex = Exception.new('exception thrown')
|
96
99
|
expect(@mock_resource).to receive(:put).with(@xml_re, { :content_type => 'application/xml' }).and_raise(ex)
|
97
|
-
expect{ Dor::WorkflowService.update_workflow_status(@repo, @druid,
|
100
|
+
expect{ Dor::WorkflowService.update_workflow_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'completed') }.to raise_error(Exception, 'exception thrown')
|
98
101
|
end
|
99
102
|
|
100
|
-
it
|
101
|
-
expect(@mock_resource).to receive(:[]).with(
|
103
|
+
it 'performs a conditional update when current-status is passed as a parameter' do
|
104
|
+
expect(@mock_resource).to receive(:[]).with('dor/objects/druid:123/workflows/etdSubmitWF/reader-approval?current-status=queued')
|
102
105
|
expect(@mock_resource).to receive(:put).with(@xml_re, { :content_type => 'application/xml' }).and_return('')
|
103
|
-
expect(Dor::WorkflowService.update_workflow_status(@repo, @druid,
|
106
|
+
expect(Dor::WorkflowService.update_workflow_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'completed', :version => 2, :note => 'annotation', :lane_id => 'lane1', :current_status => 'queued')).to be true
|
104
107
|
end
|
105
108
|
end
|
106
109
|
|
107
|
-
describe
|
108
|
-
it
|
110
|
+
describe '#update_workflow_error_status' do
|
111
|
+
it 'should update workflow status to error and return true if successful' do
|
109
112
|
expect(@mock_resource).to receive(:put).with(/status="error" errorMessage="Some exception" errorText="The optional stacktrace"/, { :content_type => 'application/xml' }).and_return('')
|
110
|
-
Dor::WorkflowService.update_workflow_error_status(@repo, @druid,
|
113
|
+
Dor::WorkflowService.update_workflow_error_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'Some exception', :error_text =>'The optional stacktrace')
|
111
114
|
end
|
112
|
-
|
113
|
-
|
114
|
-
ex = Exception.new("exception thrown")
|
115
|
+
it 'should return false if the PUT to the DOR workflow service throws an exception' do
|
116
|
+
ex = Exception.new('exception thrown')
|
115
117
|
expect(@mock_resource).to receive(:put).with(/status="completed"/, { :content_type => 'application/xml' }).and_raise(ex)
|
116
|
-
expect{ Dor::WorkflowService.update_workflow_status(@repo, @druid,
|
118
|
+
expect{ Dor::WorkflowService.update_workflow_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'completed') }.to raise_error(Exception, 'exception thrown')
|
117
119
|
end
|
118
120
|
end
|
119
121
|
|
120
|
-
describe
|
121
|
-
it
|
122
|
+
describe '#get_workflow_status' do
|
123
|
+
it 'parses workflow xml and returns status as a string' do
|
122
124
|
expect(@mock_resource).to receive(:get).and_return('<process name="registrar-approval" status="completed" />')
|
123
125
|
expect(Dor::WorkflowService.get_workflow_status('dor', 'druid:123', 'etdSubmitWF', 'registrar-approval')).to eq('completed')
|
124
126
|
end
|
125
|
-
|
126
|
-
|
127
|
-
ex = Exception.new("exception thrown")
|
127
|
+
it 'should throw an exception if it fails for any reason' do
|
128
|
+
ex = Exception.new('exception thrown')
|
128
129
|
expect(@mock_resource).to receive(:get).and_raise(ex)
|
129
|
-
|
130
|
-
expect{ Dor::WorkflowService.get_workflow_status('dor', 'druid:123', 'etdSubmitWF', 'registrar-approval') }.to raise_error(Exception, "exception thrown")
|
130
|
+
expect{ Dor::WorkflowService.get_workflow_status('dor', 'druid:123', 'etdSubmitWF', 'registrar-approval') }.to raise_error(Exception, 'exception thrown')
|
131
131
|
end
|
132
|
-
|
133
|
-
it "should throw an exception if it cannot parse the response" do
|
132
|
+
it 'should throw an exception if it cannot parse the response' do
|
134
133
|
expect(@mock_resource).to receive(:get).and_return('something not xml')
|
135
134
|
expect{ Dor::WorkflowService.get_workflow_status('dor', 'druid:123', 'etdSubmitWF', 'registrar-approval') }.to raise_error(Exception, "Unable to parse response:\nsomething not xml")
|
136
135
|
end
|
137
|
-
it
|
136
|
+
it 'should return nil if the workflow/process combination doesnt exist' do
|
138
137
|
expect(@mock_resource).to receive(:get).and_return('<process name="registrar-approval" status="completed" />')
|
139
|
-
expect(Dor::WorkflowService.get_workflow_status('dor', 'druid:123', 'accessionWF', 'publish')).to
|
138
|
+
expect(Dor::WorkflowService.get_workflow_status('dor', 'druid:123', 'accessionWF', 'publish')).to be_nil
|
140
139
|
end
|
141
|
-
|
142
140
|
end
|
143
141
|
|
144
|
-
describe
|
145
|
-
it
|
142
|
+
describe '#get_workflow_xml' do
|
143
|
+
it 'returns the xml for a given repository, druid, and workflow' do
|
146
144
|
xml = '<workflow id="etdSubmitWF"><process name="registrar-approval" status="completed" /></workflow>'
|
147
145
|
expect(@mock_resource).to receive(:get).and_return(xml)
|
148
146
|
expect(Dor::WorkflowService.get_workflow_xml('dor', 'druid:123', 'etdSubmitWF')).to eq(xml)
|
149
147
|
end
|
150
148
|
end
|
151
149
|
|
152
|
-
describe
|
153
|
-
it
|
150
|
+
describe '#get_lifecycle' do
|
151
|
+
it 'returns a Time object reprenting when the milestone was reached' do
|
154
152
|
xml = <<-EOXML
|
155
153
|
<lifecycle objectId="druid:ct011cv6501">
|
156
154
|
<milestone date="2010-04-27T11:34:17-0700">registered</milestone>
|
@@ -166,104 +164,96 @@ describe Dor::WorkflowService do
|
|
166
164
|
expect(@mock_resource).to receive(:get).and_return('<lifecycle/>')
|
167
165
|
expect(Dor::WorkflowService.get_lifecycle('dor', 'druid:abc', 'inprocess')).to be_nil
|
168
166
|
end
|
169
|
-
|
170
167
|
end
|
171
168
|
|
172
|
-
describe
|
169
|
+
describe '#get_objects_for_workstep' do
|
173
170
|
before :each do
|
174
|
-
@repository =
|
175
|
-
@workflow
|
176
|
-
@completed
|
177
|
-
@waiting
|
171
|
+
@repository = 'dor'
|
172
|
+
@workflow = 'googleScannedBookWF'
|
173
|
+
@completed = 'google-download'
|
174
|
+
@waiting = 'process-content'
|
178
175
|
end
|
179
176
|
|
180
|
-
context
|
181
|
-
it
|
177
|
+
context 'a query with one step completed and one waiting' do
|
178
|
+
it 'creates the URI string with only the one completed step' do
|
182
179
|
expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&lane-id=default")
|
183
180
|
expect(@mock_resource).to receive(:get).and_return(%{<objects count="1"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>})
|
184
|
-
expect(Dor::WorkflowService.get_objects_for_workstep(@completed, @waiting, 'default', :default_repository => @repository, :default_workflow => @workflow)).to eq(['druid:ab123de4567','druid:ab123de9012'])
|
181
|
+
expect(Dor::WorkflowService.get_objects_for_workstep(@completed, @waiting, 'default', :default_repository => @repository, :default_workflow => @workflow)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
|
185
182
|
end
|
186
183
|
end
|
187
184
|
|
188
|
-
context
|
189
|
-
it
|
190
|
-
second_completed=
|
185
|
+
context 'a query with TWO steps completed and one waiting' do
|
186
|
+
it 'creates the URI string with the two completed steps correctly' do
|
187
|
+
second_completed = 'google-convert'
|
191
188
|
expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&completed=#{@repository}:#{@workflow}:#{second_completed}&lane-id=default")
|
192
189
|
expect(@mock_resource).to receive(:get).and_return(%{<objects count="1"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>})
|
193
|
-
expect(Dor::WorkflowService.get_objects_for_workstep([@completed,second_completed], @waiting, 'default', :default_repository => @repository, :default_workflow => @workflow)).to eq(['druid:ab123de4567','druid:ab123de9012'])
|
190
|
+
expect(Dor::WorkflowService.get_objects_for_workstep([@completed, second_completed], @waiting, 'default', :default_repository => @repository, :default_workflow => @workflow)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
|
194
191
|
end
|
195
192
|
end
|
196
193
|
|
197
|
-
context
|
198
|
-
|
199
|
-
qualified_waiting
|
200
|
-
qualified_completed = "#{@repository}:#{@workflow}:#{@completed}"
|
201
|
-
repo2 = "sdr"
|
202
|
-
workflow2 = "sdrIngestWF"
|
203
|
-
completed2="complete-deposit"
|
204
|
-
completed3="ingest-transfer"
|
205
|
-
qualified_completed2 = "#{repo2}:#{workflow2}:#{completed2}"
|
206
|
-
qualified_completed3 = "#{repo2}:#{workflow2}:#{completed3}"
|
207
|
-
expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{qualified_waiting}&completed=#{qualified_completed}&completed=#{qualified_completed2}&completed=#{qualified_completed3}&lane-id=default")
|
208
|
-
expect(@mock_resource).to receive(:get).and_return(%{<objects count="2"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>})
|
209
|
-
expect(Dor::WorkflowService.get_objects_for_workstep([qualified_completed, qualified_completed2, qualified_completed3], qualified_waiting)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
|
194
|
+
context 'a query using qualified workflow names for completed and waiting' do
|
195
|
+
before :each do
|
196
|
+
@qualified_waiting = "#{@repository}:#{@workflow}:#{@waiting}"
|
197
|
+
@qualified_completed = "#{@repository}:#{@workflow}:#{@completed}"
|
210
198
|
end
|
211
199
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
expect(@mock_resource).to receive(:get).and_return(%{<objects count="2"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>})
|
223
|
-
expect(Dor::WorkflowService.get_objects_for_workstep([qualified_completed, qualified_completed2, qualified_completed3], qualified_waiting, "lane1")).to eq([ 'druid:ab123de4567', 'druid:ab123de9012'])
|
200
|
+
RSpec.shared_examples 'lane-aware' do
|
201
|
+
it 'creates the URI string with the two completed steps across repositories correctly' do
|
202
|
+
qualified_completed2 = "sdr:sdrIngestWF:complete-deposit"
|
203
|
+
qualified_completed3 = "sdr:sdrIngestWF:ingest-transfer"
|
204
|
+
expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{@qualified_waiting}&completed=#{@qualified_completed}&completed=#{qualified_completed2}&completed=#{qualified_completed3}&lane-id=#{laneid}")
|
205
|
+
expect(@mock_resource).to receive(:get).and_return(%{<objects count="2"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>})
|
206
|
+
args = [[@qualified_completed, qualified_completed2, qualified_completed3], @qualified_waiting]
|
207
|
+
args << laneid if laneid != 'default'
|
208
|
+
expect(Dor::WorkflowService.get_objects_for_workstep(*args)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
|
209
|
+
end
|
224
210
|
end
|
225
211
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{qualified_waiting}&completed=#{qualified_completed}&lane-id=default")
|
231
|
-
expect(@mock_resource).to receive(:get).and_return(%{<objects count="1"><object id="druid:ab123de4567"/></objects>})
|
232
|
-
expect(Dor::WorkflowService.get_objects_for_workstep(qualified_completed, qualified_waiting)).to eq(['druid:ab123de4567'])
|
212
|
+
describe 'default lane_id' do
|
213
|
+
it_behaves_like 'lane-aware' do
|
214
|
+
let(:laneid) { 'default' }
|
215
|
+
end
|
233
216
|
end
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{qualified_waiting}&lane-id=default")
|
239
|
-
expect(@mock_resource).to receive(:get).and_return(%{<objects count="1"><object id="druid:ab123de4567"/></objects>})
|
240
|
-
expect(Dor::WorkflowService.get_objects_for_workstep(nil, qualified_waiting)).to eq(['druid:ab123de4567'])
|
217
|
+
describe 'explicit lane_id' do
|
218
|
+
it_behaves_like 'lane-aware' do
|
219
|
+
let(:laneid) { 'lane1' }
|
220
|
+
end
|
241
221
|
end
|
242
222
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
223
|
+
describe 'URI string creation' do
|
224
|
+
before :each do
|
225
|
+
expect(@mock_resource).to receive(:get).and_return(%{<objects count="1"><object id="druid:ab123de4567"/></objects>})
|
226
|
+
end
|
227
|
+
it 'with only one completed step passed in as a String' do
|
228
|
+
expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{@qualified_waiting}&completed=#{@qualified_completed}&lane-id=default")
|
229
|
+
expect(Dor::WorkflowService.get_objects_for_workstep(@qualified_completed, @qualified_waiting)).to eq(['druid:ab123de4567'])
|
230
|
+
end
|
231
|
+
it 'without any completed steps, only waiting' do
|
232
|
+
expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{@qualified_waiting}&lane-id=default")
|
233
|
+
expect(Dor::WorkflowService.get_objects_for_workstep(nil, @qualified_waiting)).to eq(['druid:ab123de4567'])
|
234
|
+
end
|
235
|
+
it 'same but with lane_id' do
|
236
|
+
expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{@qualified_waiting}&lane-id=lane1")
|
237
|
+
expect(Dor::WorkflowService.get_objects_for_workstep(nil, @qualified_waiting, 'lane1')).to eq([ 'druid:ab123de4567' ])
|
238
|
+
end
|
249
239
|
end
|
250
240
|
end
|
251
241
|
end
|
252
242
|
|
253
|
-
context
|
254
|
-
it
|
255
|
-
repository =
|
256
|
-
workflow
|
257
|
-
completed
|
258
|
-
waiting
|
243
|
+
context 'get empty workflow queue' do
|
244
|
+
it 'returns an empty list if it encounters an empty workflow queue' do
|
245
|
+
repository = 'dor'
|
246
|
+
workflow = 'googleScannedBookWF'
|
247
|
+
completed = 'google-download'
|
248
|
+
waiting = 'process-content'
|
259
249
|
expect(@mock_resource).to receive(:[]).with("workflow_queue?waiting=#{repository}:#{workflow}:#{waiting}&completed=#{repository}:#{workflow}:#{completed}&lane-id=default")
|
260
250
|
expect(@mock_resource).to receive(:get).and_return(%{<objects count="0"/>})
|
261
251
|
expect(Dor::WorkflowService.get_objects_for_workstep(completed, waiting, 'default', :default_repository => repository, :default_workflow => workflow)).to eq([])
|
262
252
|
end
|
263
253
|
end
|
264
254
|
|
265
|
-
describe
|
266
|
-
it
|
255
|
+
describe '#delete_workflow' do
|
256
|
+
it 'sends a delete request to the workflow service' do
|
267
257
|
expect(@mock_resource).to receive(:[]).with("#{@repo}/objects/#{@druid}/workflows/accessionWF")
|
268
258
|
expect(@mock_resource).to receive(:delete)
|
269
259
|
Dor::WorkflowService.delete_workflow(@repo, @druid, 'accessionWF')
|
@@ -271,17 +261,17 @@ describe Dor::WorkflowService do
|
|
271
261
|
end
|
272
262
|
describe 'get_milestones' do
|
273
263
|
it 'should include the version in with the milestones' do
|
274
|
-
xml='<?xml version="1.0" encoding="UTF-8"?><lifecycle objectId="druid:gv054hp4128"><milestone date="2012-01-26T21:06:54-0800" version="2">published</milestone></lifecycle>'
|
275
|
-
xml=Nokogiri::XML(xml)
|
264
|
+
xml = '<?xml version="1.0" encoding="UTF-8"?><lifecycle objectId="druid:gv054hp4128"><milestone date="2012-01-26T21:06:54-0800" version="2">published</milestone></lifecycle>'
|
265
|
+
xml = Nokogiri::XML(xml)
|
276
266
|
allow(Dor::WorkflowService).to receive(:query_lifecycle).and_return(xml)
|
277
|
-
milestones=Dor::WorkflowService.get_milestones(@repo, @druid)
|
278
|
-
expect(milestones.first[:milestone]).to eq(
|
279
|
-
expect(milestones.first[:version]).to eq(
|
267
|
+
milestones = Dor::WorkflowService.get_milestones(@repo, @druid)
|
268
|
+
expect(milestones.first[:milestone]).to eq('published')
|
269
|
+
expect(milestones.first[:version]).to eq('2')
|
280
270
|
end
|
281
271
|
end
|
282
272
|
|
283
|
-
describe
|
284
|
-
it
|
273
|
+
describe '.get_active_workflows' do
|
274
|
+
it 'it returns an array of active workflows only' do
|
285
275
|
xml = <<-XML
|
286
276
|
<workflows objectId="druid:mw971zk1113">
|
287
277
|
<workflow repository="dor" objectId="druid:mw971zk1113" id="accessionWF">
|
@@ -293,67 +283,86 @@ describe Dor::WorkflowService do
|
|
293
283
|
</workflow>
|
294
284
|
</workflows>
|
295
285
|
XML
|
296
|
-
|
297
286
|
allow(Dor::WorkflowService).to receive(:get_workflow_xml) { xml }
|
298
287
|
expect(Dor::WorkflowService.get_active_workflows('dor', 'druid:mw971zk1113')).to eq(['accessionWF'])
|
299
288
|
end
|
300
289
|
end
|
301
290
|
|
302
|
-
describe
|
303
|
-
it
|
304
|
-
expect(@mock_resource).to receive(:[]).with(
|
291
|
+
describe '#close_version' do
|
292
|
+
it 'calls the versionClose endpoint with druid' do
|
293
|
+
expect(@mock_resource).to receive(:[]).with('dor/objects/druid:123/versionClose').and_return(@mock_resource)
|
305
294
|
expect(@mock_resource).to receive(:post).with('').and_return('')
|
306
295
|
Dor::WorkflowService.close_version(@repo, @druid)
|
307
296
|
end
|
308
297
|
|
309
|
-
it
|
310
|
-
expect(@mock_resource).to receive(:[]).with(
|
298
|
+
it 'optionally prevents creation of accessionWF' do
|
299
|
+
expect(@mock_resource).to receive(:[]).with('dor/objects/druid:123/versionClose?create-accession=false').and_return(@mock_resource)
|
311
300
|
expect(@mock_resource).to receive(:post).with('').and_return('')
|
312
301
|
Dor::WorkflowService.close_version(@repo, @druid, false)
|
313
302
|
end
|
314
303
|
end
|
315
304
|
|
316
|
-
describe
|
317
|
-
it
|
305
|
+
describe '.get_stale_queued_workflows' do
|
306
|
+
it 'returns an Array of Hashes containing each workflow step' do
|
318
307
|
xml = <<-XML
|
319
308
|
<workflows>
|
320
309
|
<workflow laneId="lane1" note="annotation" lifecycle="in-process" errorText="stacktrace" errorMessage="NullPointerException" elapsed="1.173" repository="dor" attempts="0" datetime="2008-11-15T13:30:00-0800" status="waiting" process="content-metadata" name="accessionWF" druid="dr:123"/>
|
321
310
|
<workflow laneId="lane2" note="annotation" lifecycle="in-process" errorText="stacktrace" errorMessage="NullPointerException" elapsed="1.173" repository="dor" attempts="0" datetime="2008-11-15T13:30:00-0800" status="waiting" process="jp2-create" name="assemblyWF" druid="dr:456"/>
|
322
311
|
</workflows>
|
323
312
|
XML
|
324
|
-
expect(@mock_resource).to receive(:[]).with(
|
313
|
+
expect(@mock_resource).to receive(:[]).with('workflow_queue/all_queued?repository=dor&hours-ago=24&limit=100')
|
325
314
|
expect(@mock_resource).to receive(:get).and_return(xml)
|
326
|
-
|
327
315
|
ah = Dor::WorkflowService.get_stale_queued_workflows 'dor', :hours_ago => 24, :limit => 100
|
328
|
-
expected = [
|
329
|
-
|
316
|
+
expected = [
|
317
|
+
{ :workflow => 'accessionWF', :step => 'content-metadata', :druid => 'dr:123', :lane_id => 'lane1' },
|
318
|
+
{ :workflow => 'assemblyWF', :step => 'jp2-create', :druid => 'dr:456', :lane_id => 'lane2' }
|
319
|
+
]
|
330
320
|
expect(ah).to eql(expected)
|
331
321
|
end
|
332
322
|
end
|
333
323
|
|
334
|
-
describe
|
335
|
-
it
|
336
|
-
expect(@mock_resource).to receive(:[]).with(
|
324
|
+
describe '.count_stale_queued_workflows' do
|
325
|
+
it 'returns the number of queued workflow steps' do
|
326
|
+
expect(@mock_resource).to receive(:[]).with('workflow_queue/all_queued?repository=dor&hours-ago=48&count-only=true')
|
337
327
|
expect(@mock_resource).to receive(:get).and_return(%{<objects count="10"/>})
|
338
|
-
|
339
328
|
expect(Dor::WorkflowService.count_stale_queued_workflows('dor', :hours_ago => 48)).to eq(10)
|
340
329
|
end
|
341
330
|
end
|
342
331
|
|
343
|
-
describe
|
344
|
-
it
|
332
|
+
describe '.get_lane_ids' do
|
333
|
+
it 'returns the lane ids for a given workflow step' do
|
345
334
|
xml = <<-XML
|
346
335
|
<lanes>
|
347
336
|
<lane id="lane1"/>
|
348
337
|
<lane id="lane2"/>
|
349
338
|
</lanes>
|
350
339
|
XML
|
351
|
-
|
352
|
-
expect(@mock_resource).to receive(:[]).with("workflow_queue/lane_ids?step=dor:accessionWF:shelve")
|
340
|
+
expect(@mock_resource).to receive(:[]).with('workflow_queue/lane_ids?step=dor:accessionWF:shelve')
|
353
341
|
expect(@mock_resource).to receive(:get).and_return(xml)
|
354
|
-
|
355
342
|
expect(Dor::WorkflowService.get_lane_ids('dor', 'accessionWF', 'shelve')).to eq(%w(lane1 lane2))
|
356
343
|
end
|
357
344
|
end
|
358
345
|
|
346
|
+
describe 'protected method' do
|
347
|
+
describe '#build_queued_uri' do
|
348
|
+
it 'does something' do
|
349
|
+
skip 'test unimplemented'
|
350
|
+
end
|
351
|
+
end
|
352
|
+
describe '#parse_queued_workflows_response' do
|
353
|
+
it 'does something' do
|
354
|
+
skip 'test unimplemented'
|
355
|
+
end
|
356
|
+
end
|
357
|
+
describe '#add_lane_id_to_workflow_xml' do
|
358
|
+
it 'does something' do
|
359
|
+
skip 'test unimplemented'
|
360
|
+
end
|
361
|
+
end
|
362
|
+
describe '#count_objects_in_step' do
|
363
|
+
it 'does something' do
|
364
|
+
skip 'test unimplemented'
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
359
368
|
end
|