dor-workflow-service 2.4.0 → 2.5.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.
- checksums.yaml +4 -4
 - data/.rubocop.yml +6 -0
 - data/.rubocop_todo.yml +26 -135
 - data/Gemfile +4 -2
 - data/Rakefile +7 -4
 - data/bin/console +1 -0
 - data/dor-workflow-service.gemspec +11 -8
 - data/lib/dor-workflow-service.rb +2 -0
 - data/lib/dor/models/response/workflow.rb +26 -0
 - data/lib/dor/services/workflow_service.rb +59 -40
 - data/lib/dor/workflow_exception.rb +2 -0
 - data/lib/dor/workflow_version.rb +3 -1
 - data/spec/models/response/workflow_spec.rb +36 -0
 - data/spec/plumbing_spec.rb +3 -1
 - data/spec/spec_helper.rb +3 -1
 - data/spec/workflow_service_spec.rb +94 -72
 - metadata +72 -41
 
    
        data/lib/dor/workflow_version.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,36 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            RSpec.describe Dor::Workflow::Response::Workflow do
         
     | 
| 
      
 6 
     | 
    
         
            +
              subject(:instance) { described_class.new(xml: xml) }
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              describe '#active?' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                subject { instance.active_for?(version: 2) }
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                context 'when the workflow has not been instantiated for the given version' do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  let(:xml) do
         
     | 
| 
      
 13 
     | 
    
         
            +
                    <<~XML
         
     | 
| 
      
 14 
     | 
    
         
            +
                      <workflow repository="dor" objectId="druid:mw971zk1113" id="assemblyWF">
         
     | 
| 
      
 15 
     | 
    
         
            +
                        <process version="1" laneId="default" elapsed="0.0" attempts="1" datetime="2013-02-18T14:40:25-0800" status="completed" name="start-assembly"/>
         
     | 
| 
      
 16 
     | 
    
         
            +
                        <process version="1" laneId="default" elapsed="0.509" attempts="1" datetime="2013-02-18T14:42:24-0800" status="completed" name="jp2-create"/>
         
     | 
| 
      
 17 
     | 
    
         
            +
                      </workflow>
         
     | 
| 
      
 18 
     | 
    
         
            +
                    XML
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
                  it { is_expected.to be false }
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                context 'when the workflow has been instantiated for the given version' do
         
     | 
| 
      
 24 
     | 
    
         
            +
                  let(:xml) do
         
     | 
| 
      
 25 
     | 
    
         
            +
                    <<~XML
         
     | 
| 
      
 26 
     | 
    
         
            +
                      <workflow repository="dor" objectId="druid:mw971zk1113" id="assemblyWF">
         
     | 
| 
      
 27 
     | 
    
         
            +
                        <process version="1" laneId="default" elapsed="0.0" attempts="1" datetime="2013-02-18T14:40:25-0800" status="completed" name="start-assembly"/>
         
     | 
| 
      
 28 
     | 
    
         
            +
                        <process version="1" laneId="default" elapsed="0.509" attempts="1" datetime="2013-02-18T14:42:24-0800" status="completed" name="jp2-create"/>
         
     | 
| 
      
 29 
     | 
    
         
            +
                        <process version="2" laneId="default" elapsed="0.509" attempts="1" datetime="2013-02-18T14:42:24-0800" status="waiting" name="jp2-create"/>
         
     | 
| 
      
 30 
     | 
    
         
            +
                      </workflow>
         
     | 
| 
      
 31 
     | 
    
         
            +
                    XML
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
                  it { is_expected.to be true }
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/plumbing_spec.rb
    CHANGED
    
    | 
         @@ -1,3 +1,5 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            describe Dor::WorkflowService do
         
     | 
| 
         @@ -12,7 +14,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       12 
14 
     | 
    
         
             
                end
         
     | 
| 
       13 
15 
     | 
    
         
             
                it 'accepts :logger if specified' do
         
     | 
| 
       14 
16 
     | 
    
         
             
                  expect(Dor::WorkflowService).not_to receive(:default_logger)
         
     | 
| 
       15 
     | 
    
         
            -
                  Dor::WorkflowService.configure('https://dortest.stanford.edu/workflow',  
     | 
| 
      
 17 
     | 
    
         
            +
                  Dor::WorkflowService.configure('https://dortest.stanford.edu/workflow', logger: @logger1)
         
     | 
| 
       16 
18 
     | 
    
         
             
                end
         
     | 
| 
       17 
19 
     | 
    
         
             
              end
         
     | 
| 
       18 
20 
     | 
    
         
             
            end
         
     | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
| 
         @@ -1,7 +1,10 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
       1 
3 
     | 
    
         
             
            require 'spec_helper'
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
5 
     | 
    
         
             
            describe Dor::WorkflowService do
         
     | 
| 
       4 
     | 
    
         
            -
              let(:wf_xml)  
     | 
| 
      
 6 
     | 
    
         
            +
              let(:wf_xml) do
         
     | 
| 
      
 7 
     | 
    
         
            +
                <<-EOXML
         
     | 
| 
       5 
8 
     | 
    
         
             
                <workflow id="etdSubmitWF">
         
     | 
| 
       6 
9 
     | 
    
         
             
                     <process name="register-object" status="completed" attempts="1" />
         
     | 
| 
       7 
10 
     | 
    
         
             
                     <process name="submit" status="waiting" />
         
     | 
| 
         @@ -10,19 +13,20 @@ describe Dor::WorkflowService do 
     | 
|
| 
       10 
13 
     | 
    
         
             
                     <process name="start-accession" status="waiting" />
         
     | 
| 
       11 
14 
     | 
    
         
             
                </workflow>
         
     | 
| 
       12 
15 
     | 
    
         
             
                EOXML
         
     | 
| 
       13 
     | 
    
         
            -
               
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
       14 
17 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
              let(:wf_xml_label)  
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
              let(:wf_xml_label) do
         
     | 
| 
      
 19 
     | 
    
         
            +
                <<~EOXML
         
     | 
| 
      
 20 
     | 
    
         
            +
                  <?xml version="1.0"?>
         
     | 
| 
      
 21 
     | 
    
         
            +
                  <workflow id="etdSubmitWF">
         
     | 
| 
       18 
22 
     | 
    
         
             
                     <process name="register-object" status="completed" attempts="1" laneId="default"/>
         
     | 
| 
       19 
23 
     | 
    
         
             
                     <process name="submit" status="waiting" laneId="default"/>
         
     | 
| 
       20 
24 
     | 
    
         
             
                     <process name="reader-approval" status="waiting" laneId="default"/>
         
     | 
| 
       21 
25 
     | 
    
         
             
                     <process name="registrar-approval" status="waiting" laneId="default"/>
         
     | 
| 
       22 
26 
     | 
    
         
             
                     <process name="start-accession" status="waiting" laneId="default"/>
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
      
 27 
     | 
    
         
            +
                  </workflow>
         
     | 
| 
       24 
28 
     | 
    
         
             
                EOXML
         
     | 
| 
       25 
     | 
    
         
            -
               
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
       26 
30 
     | 
    
         | 
| 
       27 
31 
     | 
    
         
             
              let(:stubs) do
         
     | 
| 
       28 
32 
     | 
    
         
             
                Faraday::Adapter::Test::Stubs.new
         
     | 
| 
         @@ -52,7 +56,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       52 
56 
     | 
    
         | 
| 
       53 
57 
     | 
    
         
             
              describe '#configure' do
         
     | 
| 
       54 
58 
     | 
    
         
             
                it 'should handle a string and timeout' do
         
     | 
| 
       55 
     | 
    
         
            -
                  conn = Dor::WorkflowService.configure 'http://externalhost/', : 
     | 
| 
      
 59 
     | 
    
         
            +
                  conn = Dor::WorkflowService.configure 'http://externalhost/', timeout: 99
         
     | 
| 
       56 
60 
     | 
    
         
             
                  expect(conn).to be_a(Faraday::Connection)
         
     | 
| 
       57 
61 
     | 
    
         
             
                  expect(conn.options.timeout).to eq(99)
         
     | 
| 
       58 
62 
     | 
    
         
             
                  expect(conn.options.open_timeout).to eq(99)
         
     | 
| 
         @@ -62,10 +66,10 @@ describe Dor::WorkflowService do 
     | 
|
| 
       62 
66 
     | 
    
         
             
              describe '#create_workflow' do
         
     | 
| 
       63 
67 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       64 
68 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       65 
     | 
    
         
            -
                    stub.put("#{@repo}/objects/#{@druid}/workflows/etdSubmitWF") { | 
     | 
| 
       66 
     | 
    
         
            -
                    stub.put("#{@repo}/objects/#{@druid}/workflows/noCreateDsWF?create-ds=false") { | 
     | 
| 
       67 
     | 
    
         
            -
                    stub.put("#{@repo}/objects/#{@druid}/workflows/httpException") { | 
     | 
| 
       68 
     | 
    
         
            -
                    stub.put("#{@repo}/objects/#{@druid}/workflows/raiseException") { | 
     | 
| 
      
 69 
     | 
    
         
            +
                    stub.put("#{@repo}/objects/#{@druid}/workflows/etdSubmitWF") { |_env| [201, {}, ''] }
         
     | 
| 
      
 70 
     | 
    
         
            +
                    stub.put("#{@repo}/objects/#{@druid}/workflows/noCreateDsWF?create-ds=false") { |_env| [201, {}, ''] }
         
     | 
| 
      
 71 
     | 
    
         
            +
                    stub.put("#{@repo}/objects/#{@druid}/workflows/httpException") { |_env| [418, {}, "I'm A Teapot"] }
         
     | 
| 
      
 72 
     | 
    
         
            +
                    stub.put("#{@repo}/objects/#{@druid}/workflows/raiseException") { |_env| raise 'broken' }
         
     | 
| 
       69 
73 
     | 
    
         
             
                  end
         
     | 
| 
       70 
74 
     | 
    
         
             
                end
         
     | 
| 
       71 
75 
     | 
    
         | 
| 
         @@ -79,11 +83,11 @@ describe Dor::WorkflowService do 
     | 
|
| 
       79 
83 
     | 
    
         
             
                end
         
     | 
| 
       80 
84 
     | 
    
         | 
| 
       81 
85 
     | 
    
         
             
                it 'should raise on an unexpected Exception' do
         
     | 
| 
       82 
     | 
    
         
            -
                  expect{ Dor::WorkflowService.create_workflow(@repo, @druid, 'raiseException', wf_xml) }.to raise_error(Exception, 'broken')
         
     | 
| 
      
 86 
     | 
    
         
            +
                  expect { Dor::WorkflowService.create_workflow(@repo, @druid, 'raiseException', wf_xml) }.to raise_error(Exception, 'broken')
         
     | 
| 
       83 
87 
     | 
    
         
             
                end
         
     | 
| 
       84 
88 
     | 
    
         | 
| 
       85 
89 
     | 
    
         
             
                it 'sets the create-ds param to the value of the passed in options hash' do
         
     | 
| 
       86 
     | 
    
         
            -
                  Dor::WorkflowService.create_workflow(@repo, @druid, 'noCreateDsWF', wf_xml, : 
     | 
| 
      
 90 
     | 
    
         
            +
                  Dor::WorkflowService.create_workflow(@repo, @druid, 'noCreateDsWF', wf_xml, create_ds: false)
         
     | 
| 
       87 
91 
     | 
    
         
             
                end
         
     | 
| 
       88 
92 
     | 
    
         | 
| 
       89 
93 
     | 
    
         
             
                it 'adds lane_id attributes to all steps if passed in as an option' do
         
     | 
| 
         @@ -109,7 +113,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       109 
113 
     | 
    
         
             
              describe '#update_workflow_status' do
         
     | 
| 
       110 
114 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       111 
115 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       112 
     | 
    
         
            -
                    stub.put("#{@repo}/objects/#{@druid}/workflows/etdSubmitWF/reader-approval?current-status=queued") do | 
     | 
| 
      
 116 
     | 
    
         
            +
                    stub.put("#{@repo}/objects/#{@druid}/workflows/etdSubmitWF/reader-approval?current-status=queued") do |_env|
         
     | 
| 
       113 
117 
     | 
    
         
             
                      [201, {}, '']
         
     | 
| 
       114 
118 
     | 
    
         
             
                    end
         
     | 
| 
       115 
119 
     | 
    
         | 
| 
         @@ -118,24 +122,24 @@ describe Dor::WorkflowService do 
     | 
|
| 
       118 
122 
     | 
    
         
             
                      [201, {}, '']
         
     | 
| 
       119 
123 
     | 
    
         
             
                    end
         
     | 
| 
       120 
124 
     | 
    
         | 
| 
       121 
     | 
    
         
            -
                    stub.put("#{@repo}/objects/#{@druid}/workflows/errorWF/reader-approval") do | 
     | 
| 
      
 125 
     | 
    
         
            +
                    stub.put("#{@repo}/objects/#{@druid}/workflows/errorWF/reader-approval") do |_env|
         
     | 
| 
       122 
126 
     | 
    
         
             
                      [400, {}, '']
         
     | 
| 
       123 
127 
     | 
    
         
             
                    end
         
     | 
| 
       124 
128 
     | 
    
         
             
                  end
         
     | 
| 
       125 
129 
     | 
    
         
             
                end
         
     | 
| 
       126 
130 
     | 
    
         | 
| 
       127 
131 
     | 
    
         
             
                it 'should update workflow status and return true if successful' do
         
     | 
| 
       128 
     | 
    
         
            -
                  expect(Dor::WorkflowService.update_workflow_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'completed', : 
     | 
| 
      
 132 
     | 
    
         
            +
                  expect(Dor::WorkflowService.update_workflow_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'completed', version: 2, note: 'annotation', lane_id: 'lane2')).to be true
         
     | 
| 
       129 
133 
     | 
    
         
             
                end
         
     | 
| 
       130 
134 
     | 
    
         | 
| 
       131 
135 
     | 
    
         
             
                it 'should return false if the PUT to the DOR workflow service throws an exception' do
         
     | 
| 
       132 
     | 
    
         
            -
                  expect{ Dor::WorkflowService.update_workflow_status(@repo, @druid, 'errorWF', 'reader-approval', 'completed') }.to raise_error(Dor::WorkflowException, /status 400/)
         
     | 
| 
      
 136 
     | 
    
         
            +
                  expect { Dor::WorkflowService.update_workflow_status(@repo, @druid, 'errorWF', 'reader-approval', 'completed') }.to raise_error(Dor::WorkflowException, /status 400/)
         
     | 
| 
       133 
137 
     | 
    
         
             
                end
         
     | 
| 
       134 
138 
     | 
    
         | 
| 
       135 
139 
     | 
    
         
             
                it 'performs a conditional update when current-status is passed as a parameter' do
         
     | 
| 
       136 
140 
     | 
    
         
             
                  expect(mock_http_connection).to receive(:put).with("#{@repo}/objects/#{@druid}/workflows/etdSubmitWF/reader-approval?current-status=queued").and_call_original
         
     | 
| 
       137 
141 
     | 
    
         | 
| 
       138 
     | 
    
         
            -
                  expect(Dor::WorkflowService.update_workflow_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'completed', : 
     | 
| 
      
 142 
     | 
    
         
            +
                  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
         
     | 
| 
       139 
143 
     | 
    
         
             
                end
         
     | 
| 
       140 
144 
     | 
    
         | 
| 
       141 
145 
     | 
    
         
             
                it 'should throw exception if invalid status provided' do
         
     | 
| 
         @@ -151,17 +155,17 @@ describe Dor::WorkflowService do 
     | 
|
| 
       151 
155 
     | 
    
         
             
                      [201, {}, '']
         
     | 
| 
       152 
156 
     | 
    
         
             
                    end
         
     | 
| 
       153 
157 
     | 
    
         | 
| 
       154 
     | 
    
         
            -
                    stub.put("#{@repo}/objects/#{@druid}/workflows/errorWF/reader-approval") do | 
     | 
| 
      
 158 
     | 
    
         
            +
                    stub.put("#{@repo}/objects/#{@druid}/workflows/errorWF/reader-approval") do |_env|
         
     | 
| 
       155 
159 
     | 
    
         
             
                      [400, {}, '']
         
     | 
| 
       156 
160 
     | 
    
         
             
                    end
         
     | 
| 
       157 
161 
     | 
    
         
             
                  end
         
     | 
| 
       158 
162 
     | 
    
         
             
                end
         
     | 
| 
       159 
163 
     | 
    
         | 
| 
       160 
164 
     | 
    
         
             
                it 'should update workflow status to error and return true if successful' do
         
     | 
| 
       161 
     | 
    
         
            -
                  Dor::WorkflowService.update_workflow_error_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'Some exception', : 
     | 
| 
      
 165 
     | 
    
         
            +
                  Dor::WorkflowService.update_workflow_error_status(@repo, @druid, 'etdSubmitWF', 'reader-approval', 'Some exception', error_text: 'The optional stacktrace')
         
     | 
| 
       162 
166 
     | 
    
         
             
                end
         
     | 
| 
       163 
167 
     | 
    
         
             
                it 'should return false if the PUT to the DOR workflow service throws an exception' do
         
     | 
| 
       164 
     | 
    
         
            -
                  expect{ Dor::WorkflowService.update_workflow_status(@repo, @druid, 'errorWF', 'reader-approval', 'completed') }.to raise_error(Dor::WorkflowException, /status 400/)
         
     | 
| 
      
 168 
     | 
    
         
            +
                  expect { Dor::WorkflowService.update_workflow_status(@repo, @druid, 'errorWF', 'reader-approval', 'completed') }.to raise_error(Dor::WorkflowException, /status 400/)
         
     | 
| 
       165 
169 
     | 
    
         
             
                end
         
     | 
| 
       166 
170 
     | 
    
         
             
              end
         
     | 
| 
       167 
171 
     | 
    
         | 
| 
         @@ -170,7 +174,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       170 
174 
     | 
    
         
             
                let(:druid) { @druid }
         
     | 
| 
       171 
175 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       172 
176 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       173 
     | 
    
         
            -
                    stub.get("#{repo}/objects/#{druid}/workflows/#{workflow_name}") do | 
     | 
| 
      
 177 
     | 
    
         
            +
                    stub.get("#{repo}/objects/#{druid}/workflows/#{workflow_name}") do |_env|
         
     | 
| 
       174 
178 
     | 
    
         
             
                      response
         
     | 
| 
       175 
179 
     | 
    
         
             
                    end
         
     | 
| 
       176 
180 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -210,7 +214,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       210 
214 
     | 
    
         
             
                  let(:status) { 404 }
         
     | 
| 
       211 
215 
     | 
    
         | 
| 
       212 
216 
     | 
    
         
             
                  it 'throws an exception' do
         
     | 
| 
       213 
     | 
    
         
            -
                    expect{ subject }.to raise_error Dor::WorkflowException
         
     | 
| 
      
 217 
     | 
    
         
            +
                    expect { subject }.to raise_error Dor::WorkflowException
         
     | 
| 
       214 
218 
     | 
    
         
             
                  end
         
     | 
| 
       215 
219 
     | 
    
         
             
                end
         
     | 
| 
       216 
220 
     | 
    
         | 
| 
         @@ -220,7 +224,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       220 
224 
     | 
    
         
             
                  end
         
     | 
| 
       221 
225 
     | 
    
         | 
| 
       222 
226 
     | 
    
         
             
                  it 'throws an exception' do
         
     | 
| 
       223 
     | 
    
         
            -
                    expect{ subject }.to raise_error Dor::WorkflowException, "Unable to parse response:\nsomething not xml"
         
     | 
| 
      
 227 
     | 
    
         
            +
                    expect { subject }.to raise_error Dor::WorkflowException, "Unable to parse response:\nsomething not xml"
         
     | 
| 
       224 
228 
     | 
    
         
             
                  end
         
     | 
| 
       225 
229 
     | 
    
         
             
                end
         
     | 
| 
       226 
230 
     | 
    
         | 
| 
         @@ -240,7 +244,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       240 
244 
     | 
    
         
             
                let(:xml) { '<workflow id="etdSubmitWF"><process name="registrar-approval" status="completed" /></workflow>' }
         
     | 
| 
       241 
245 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       242 
246 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       243 
     | 
    
         
            -
                    stub.get( 
     | 
| 
      
 247 
     | 
    
         
            +
                    stub.get('dor/objects/druid:123/workflows/etdSubmitWF') do |_env|
         
     | 
| 
       244 
248 
     | 
    
         
             
                      [200, {}, xml]
         
     | 
| 
       245 
249 
     | 
    
         
             
                    end
         
     | 
| 
       246 
250 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -255,7 +259,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       255 
259 
     | 
    
         
             
                let(:xml) { '<workflow id="accessionWF"><process name="publish" status="completed" /></workflow>' }
         
     | 
| 
       256 
260 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       257 
261 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       258 
     | 
    
         
            -
                    stub.get("dor/objects/#{@druid}/workflows/") do | 
     | 
| 
      
 262 
     | 
    
         
            +
                    stub.get("dor/objects/#{@druid}/workflows/") do |_env|
         
     | 
| 
       259 
263 
     | 
    
         
             
                      [200, {}, xml]
         
     | 
| 
       260 
264 
     | 
    
         
             
                    end
         
     | 
| 
       261 
265 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -269,7 +273,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       269 
273 
     | 
    
         
             
              describe '#get_lifecycle' do
         
     | 
| 
       270 
274 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       271 
275 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       272 
     | 
    
         
            -
                    stub.get('dor/objects/druid:123/lifecycle') do | 
     | 
| 
      
 276 
     | 
    
         
            +
                    stub.get('dor/objects/druid:123/lifecycle') do |_env|
         
     | 
| 
       273 
277 
     | 
    
         
             
                      [200, {}, <<-EOXML]
         
     | 
| 
       274 
278 
     | 
    
         
             
                        <lifecycle objectId="druid:ct011cv6501">
         
     | 
| 
       275 
279 
     | 
    
         
             
                            <milestone date="2010-04-27T11:34:17-0700">registered</milestone>
         
     | 
| 
         @@ -279,7 +283,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       279 
283 
     | 
    
         
             
                      EOXML
         
     | 
| 
       280 
284 
     | 
    
         
             
                    end
         
     | 
| 
       281 
285 
     | 
    
         | 
| 
       282 
     | 
    
         
            -
                    stub.get('dor/objects/druid:abc/lifecycle') do | 
     | 
| 
      
 286 
     | 
    
         
            +
                    stub.get('dor/objects/druid:abc/lifecycle') do |_env|
         
     | 
| 
       283 
287 
     | 
    
         
             
                      [200, {}, <<-EOXML]
         
     | 
| 
       284 
288 
     | 
    
         
             
                        <lifecycle />
         
     | 
| 
       285 
289 
     | 
    
         
             
                      EOXML
         
     | 
| 
         @@ -299,7 +303,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       299 
303 
     | 
    
         
             
              describe '#get_active_lifecycle' do
         
     | 
| 
       300 
304 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       301 
305 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       302 
     | 
    
         
            -
                    stub.get("dor/objects/#{@druid}/lifecycle") do | 
     | 
| 
      
 306 
     | 
    
         
            +
                    stub.get("dor/objects/#{@druid}/lifecycle") do |_env|
         
     | 
| 
       303 
307 
     | 
    
         
             
                      [200, {}, <<-EOXML]
         
     | 
| 
       304 
308 
     | 
    
         
             
                        <lifecycle objectId="#{@druid}">
         
     | 
| 
       305 
309 
     | 
    
         
             
                            <milestone date="2010-04-27T11:34:17-0700">registered</milestone>
         
     | 
| 
         @@ -309,7 +313,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       309 
313 
     | 
    
         
             
                      EOXML
         
     | 
| 
       310 
314 
     | 
    
         
             
                    end
         
     | 
| 
       311 
315 
     | 
    
         | 
| 
       312 
     | 
    
         
            -
                    stub.get("dor/objects/#{@druid}/lifecycle") do | 
     | 
| 
      
 316 
     | 
    
         
            +
                    stub.get("dor/objects/#{@druid}/lifecycle") do |_env|
         
     | 
| 
       313 
317 
     | 
    
         
             
                      [200, {}, <<-EOXML]
         
     | 
| 
       314 
318 
     | 
    
         
             
                        <lifecycle />
         
     | 
| 
       315 
319 
     | 
    
         
             
                      EOXML
         
     | 
| 
         @@ -336,7 +340,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       336 
340 
     | 
    
         | 
| 
       337 
341 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       338 
342 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       339 
     | 
    
         
            -
                    stub.get("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&lane-id=default") do | 
     | 
| 
      
 343 
     | 
    
         
            +
                    stub.get("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&lane-id=default") do |_env|
         
     | 
| 
       340 
344 
     | 
    
         
             
                      [200, {}, '<objects count="1"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>']
         
     | 
| 
       341 
345 
     | 
    
         
             
                    end
         
     | 
| 
       342 
346 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -344,16 +348,16 @@ describe Dor::WorkflowService do 
     | 
|
| 
       344 
348 
     | 
    
         | 
| 
       345 
349 
     | 
    
         
             
                describe 'a query with one step completed and one waiting' do
         
     | 
| 
       346 
350 
     | 
    
         
             
                  it 'creates the URI string with only the one completed step' do
         
     | 
| 
       347 
     | 
    
         
            -
                    expect(Dor::WorkflowService.get_objects_for_workstep(@completed, @waiting, 'default', : 
     | 
| 
      
 351 
     | 
    
         
            +
                    expect(Dor::WorkflowService.get_objects_for_workstep(@completed, @waiting, 'default', default_repository: @repository, default_workflow: @workflow)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
         
     | 
| 
       348 
352 
     | 
    
         
             
                  end
         
     | 
| 
       349 
353 
     | 
    
         
             
                end
         
     | 
| 
       350 
354 
     | 
    
         | 
| 
       351 
355 
     | 
    
         
             
                describe 'a query with TWO steps completed and one waiting' do
         
     | 
| 
       352 
356 
     | 
    
         
             
                  it 'creates the URI string with the two completed steps correctly' do
         
     | 
| 
       353 
357 
     | 
    
         
             
                    second_completed = 'google-convert'
         
     | 
| 
       354 
     | 
    
         
            -
                    xml = % 
     | 
| 
       355 
     | 
    
         
            -
                    allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&completed=#{@repository}:#{@workflow}:#{second_completed}&lane-id=default").and_return(double 
     | 
| 
       356 
     | 
    
         
            -
                    expect(Dor::WorkflowService.get_objects_for_workstep([@completed, second_completed], @waiting, 'default', : 
     | 
| 
      
 358 
     | 
    
         
            +
                    xml = %(<objects count="1"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>)
         
     | 
| 
      
 359 
     | 
    
         
            +
                    allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&completed=#{@repository}:#{@workflow}:#{second_completed}&lane-id=default").and_return(double(Faraday::Response, body: xml))
         
     | 
| 
      
 360 
     | 
    
         
            +
                    expect(Dor::WorkflowService.get_objects_for_workstep([@completed, second_completed], @waiting, 'default', default_repository: @repository, default_workflow: @workflow)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
         
     | 
| 
       357 
361 
     | 
    
         
             
                  end
         
     | 
| 
       358 
362 
     | 
    
         
             
                end
         
     | 
| 
       359 
363 
     | 
    
         | 
| 
         @@ -365,10 +369,10 @@ describe Dor::WorkflowService do 
     | 
|
| 
       365 
369 
     | 
    
         | 
| 
       366 
370 
     | 
    
         
             
                  RSpec.shared_examples 'lane-aware' do
         
     | 
| 
       367 
371 
     | 
    
         
             
                    it 'creates the URI string with the two completed steps across repositories correctly' do
         
     | 
| 
       368 
     | 
    
         
            -
                      qualified_completed2 =  
     | 
| 
       369 
     | 
    
         
            -
                      qualified_completed3 =  
     | 
| 
       370 
     | 
    
         
            -
                      xml = % 
     | 
| 
       371 
     | 
    
         
            -
                      allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&completed=#{@qualified_completed}&completed=#{qualified_completed2}&completed=#{qualified_completed3}&lane-id=#{laneid}").and_return(double 
     | 
| 
      
 372 
     | 
    
         
            +
                      qualified_completed2 = 'sdr:sdrIngestWF:complete-deposit'
         
     | 
| 
      
 373 
     | 
    
         
            +
                      qualified_completed3 = 'sdr:sdrIngestWF:ingest-transfer'
         
     | 
| 
      
 374 
     | 
    
         
            +
                      xml = %(<objects count="2"><object id="druid:ab123de4567"/><object id="druid:ab123de9012"/></objects>)
         
     | 
| 
      
 375 
     | 
    
         
            +
                      allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&completed=#{@qualified_completed}&completed=#{qualified_completed2}&completed=#{qualified_completed3}&lane-id=#{laneid}").and_return(double(Faraday::Response, body: xml))
         
     | 
| 
       372 
376 
     | 
    
         
             
                      args = [[@qualified_completed, qualified_completed2, qualified_completed3], @qualified_waiting]
         
     | 
| 
       373 
377 
     | 
    
         
             
                      args << laneid if laneid != 'default'
         
     | 
| 
       374 
378 
     | 
    
         
             
                      expect(Dor::WorkflowService.get_objects_for_workstep(*args)).to eq(['druid:ab123de4567', 'druid:ab123de9012'])
         
     | 
| 
         @@ -388,19 +392,19 @@ describe Dor::WorkflowService do 
     | 
|
| 
       388 
392 
     | 
    
         | 
| 
       389 
393 
     | 
    
         
             
                  context 'URI string creation' do
         
     | 
| 
       390 
394 
     | 
    
         
             
                    before :each do
         
     | 
| 
       391 
     | 
    
         
            -
                      @xml = % 
     | 
| 
      
 395 
     | 
    
         
            +
                      @xml = %(<objects count="1"><object id="druid:ab123de4567"/></objects>)
         
     | 
| 
       392 
396 
     | 
    
         
             
                    end
         
     | 
| 
       393 
397 
     | 
    
         
             
                    it 'with only one completed step passed in as a String' do
         
     | 
| 
       394 
     | 
    
         
            -
                      allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&completed=#{@qualified_completed}&lane-id=default").and_return(double 
     | 
| 
      
 398 
     | 
    
         
            +
                      allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&completed=#{@qualified_completed}&lane-id=default").and_return(double(Faraday::Response, body: @xml))
         
     | 
| 
       395 
399 
     | 
    
         
             
                      expect(Dor::WorkflowService.get_objects_for_workstep(@qualified_completed, @qualified_waiting)).to eq(['druid:ab123de4567'])
         
     | 
| 
       396 
400 
     | 
    
         
             
                    end
         
     | 
| 
       397 
401 
     | 
    
         
             
                    it 'without any completed steps, only waiting' do
         
     | 
| 
       398 
     | 
    
         
            -
                      allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&lane-id=default").and_return(double 
     | 
| 
      
 402 
     | 
    
         
            +
                      allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&lane-id=default").and_return(double(Faraday::Response, body: @xml))
         
     | 
| 
       399 
403 
     | 
    
         
             
                      expect(Dor::WorkflowService.get_objects_for_workstep(nil, @qualified_waiting)).to eq(['druid:ab123de4567'])
         
     | 
| 
       400 
404 
     | 
    
         
             
                    end
         
     | 
| 
       401 
405 
     | 
    
         
             
                    it 'same but with lane_id' do
         
     | 
| 
       402 
     | 
    
         
            -
                      allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&lane-id=lane1").and_return(double 
     | 
| 
       403 
     | 
    
         
            -
                      expect(Dor::WorkflowService.get_objects_for_workstep(nil, @qualified_waiting, 'lane1')).to eq([ 
     | 
| 
      
 406 
     | 
    
         
            +
                      allow(mock_http_connection).to receive(:get).with("workflow_queue?waiting=#{@qualified_waiting}&lane-id=lane1").and_return(double(Faraday::Response, body: @xml))
         
     | 
| 
      
 407 
     | 
    
         
            +
                      expect(Dor::WorkflowService.get_objects_for_workstep(nil, @qualified_waiting, 'lane1')).to eq(['druid:ab123de4567'])
         
     | 
| 
       404 
408 
     | 
    
         
             
                    end
         
     | 
| 
       405 
409 
     | 
    
         
             
                  end
         
     | 
| 
       406 
410 
     | 
    
         
             
                end
         
     | 
| 
         @@ -416,14 +420,14 @@ describe Dor::WorkflowService do 
     | 
|
| 
       416 
420 
     | 
    
         | 
| 
       417 
421 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       418 
422 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       419 
     | 
    
         
            -
                    stub.get("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&lane-id=default") do | 
     | 
| 
      
 423 
     | 
    
         
            +
                    stub.get("workflow_queue?waiting=#{@repository}:#{@workflow}:#{@waiting}&completed=#{@repository}:#{@workflow}:#{@completed}&lane-id=default") do |_env|
         
     | 
| 
       420 
424 
     | 
    
         
             
                      [200, {}, '<objects count="0"/>']
         
     | 
| 
       421 
425 
     | 
    
         
             
                    end
         
     | 
| 
       422 
426 
     | 
    
         
             
                  end
         
     | 
| 
       423 
427 
     | 
    
         
             
                end
         
     | 
| 
       424 
428 
     | 
    
         | 
| 
       425 
429 
     | 
    
         
             
                it 'returns an empty list if it encounters an empty workflow queue' do
         
     | 
| 
       426 
     | 
    
         
            -
                  expect(Dor::WorkflowService.get_objects_for_workstep(@completed, @waiting, 'default', : 
     | 
| 
      
 430 
     | 
    
         
            +
                  expect(Dor::WorkflowService.get_objects_for_workstep(@completed, @waiting, 'default', default_repository: @repository, default_workflow: @workflow)).to eq([])
         
     | 
| 
       427 
431 
     | 
    
         
             
                end
         
     | 
| 
       428 
432 
     | 
    
         
             
              end
         
     | 
| 
       429 
433 
     | 
    
         | 
| 
         @@ -436,18 +440,18 @@ describe Dor::WorkflowService do 
     | 
|
| 
       436 
440 
     | 
    
         | 
| 
       437 
441 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       438 
442 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       439 
     | 
    
         
            -
                    stub.get("/workflow_queue?error=#{@step}&repository=#{@repository}&workflow=#{@workflow}") do | 
     | 
| 
       440 
     | 
    
         
            -
                      [200, {}, <<-EOXML 
     | 
| 
      
 443 
     | 
    
         
            +
                    stub.get("/workflow_queue?error=#{@step}&repository=#{@repository}&workflow=#{@workflow}") do |_env|
         
     | 
| 
      
 444 
     | 
    
         
            +
                      [200, {}, <<-EOXML]
         
     | 
| 
       441 
445 
     | 
    
         
             
                        <objects count="1">
         
     | 
| 
       442 
446 
     | 
    
         
             
                           <object id="druid:ab123cd4567" errorMessage="This is an error message"/>
         
     | 
| 
       443 
447 
     | 
    
         
             
                         </objects>
         
     | 
| 
       444 
     | 
    
         
            -
             
     | 
| 
      
 448 
     | 
    
         
            +
                      EOXML
         
     | 
| 
       445 
449 
     | 
    
         
             
                    end
         
     | 
| 
       446 
450 
     | 
    
         
             
                  end
         
     | 
| 
       447 
451 
     | 
    
         
             
                end
         
     | 
| 
       448 
452 
     | 
    
         | 
| 
       449 
453 
     | 
    
         
             
                it 'returns error messages for errored objects' do
         
     | 
| 
       450 
     | 
    
         
            -
                  expect(Dor::WorkflowService.get_errored_objects_for_workstep(@workflow, @step, @repository)).to eq( 
     | 
| 
      
 454 
     | 
    
         
            +
                  expect(Dor::WorkflowService.get_errored_objects_for_workstep(@workflow, @step, @repository)).to eq('druid:ab123cd4567' => 'This is an error message')
         
     | 
| 
       451 
455 
     | 
    
         
             
                end
         
     | 
| 
       452 
456 
     | 
    
         | 
| 
       453 
457 
     | 
    
         
             
                it 'counts how many steps are errored out' do
         
     | 
| 
         @@ -464,12 +468,12 @@ describe Dor::WorkflowService do 
     | 
|
| 
       464 
468 
     | 
    
         | 
| 
       465 
469 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       466 
470 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       467 
     | 
    
         
            -
                    stub.get("/workflow_queue?queued=#{@step}&repository=#{@repository}&workflow=#{@workflow}") do | 
     | 
| 
       468 
     | 
    
         
            -
                      [200, {}, <<-EOXML 
     | 
| 
      
 471 
     | 
    
         
            +
                    stub.get("/workflow_queue?queued=#{@step}&repository=#{@repository}&workflow=#{@workflow}") do |_env|
         
     | 
| 
      
 472 
     | 
    
         
            +
                      [200, {}, <<-EOXML]
         
     | 
| 
       469 
473 
     | 
    
         
             
                        <objects count="1">
         
     | 
| 
       470 
474 
     | 
    
         
             
                           <object id="druid:ab123cd4567"/>
         
     | 
| 
       471 
475 
     | 
    
         
             
                         </objects>
         
     | 
| 
       472 
     | 
    
         
            -
             
     | 
| 
      
 476 
     | 
    
         
            +
                      EOXML
         
     | 
| 
       473 
477 
     | 
    
         
             
                    end
         
     | 
| 
       474 
478 
     | 
    
         
             
                  end
         
     | 
| 
       475 
479 
     | 
    
         
             
                end
         
     | 
| 
         @@ -487,10 +491,10 @@ describe Dor::WorkflowService do 
     | 
|
| 
       487 
491 
     | 
    
         | 
| 
       488 
492 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       489 
493 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       490 
     | 
    
         
            -
                    stub.get("/workflow_archive?repository=#{@repository}&workflow=#{@workflow}&count-only=true") do | 
     | 
| 
       491 
     | 
    
         
            -
                      [200, {}, <<-EOXML 
     | 
| 
      
 494 
     | 
    
         
            +
                    stub.get("/workflow_archive?repository=#{@repository}&workflow=#{@workflow}&count-only=true") do |_env|
         
     | 
| 
      
 495 
     | 
    
         
            +
                      [200, {}, <<-EOXML]
         
     | 
| 
       492 
496 
     | 
    
         
             
                        <objects count="20" />
         
     | 
| 
       493 
     | 
    
         
            -
             
     | 
| 
      
 497 
     | 
    
         
            +
                      EOXML
         
     | 
| 
       494 
498 
     | 
    
         
             
                    end
         
     | 
| 
       495 
499 
     | 
    
         
             
                  end
         
     | 
| 
       496 
500 
     | 
    
         
             
                end
         
     | 
| 
         @@ -510,12 +514,12 @@ describe Dor::WorkflowService do 
     | 
|
| 
       510 
514 
     | 
    
         | 
| 
       511 
515 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       512 
516 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       513 
     | 
    
         
            -
                    stub.get("/workflow_queue?repository=#{@repository}&workflow=#{@workflow}&#{@type}=#{@step}") do | 
     | 
| 
       514 
     | 
    
         
            -
                      [200, {}, <<-EOXML 
     | 
| 
      
 517 
     | 
    
         
            +
                    stub.get("/workflow_queue?repository=#{@repository}&workflow=#{@workflow}&#{@type}=#{@step}") do |_env|
         
     | 
| 
      
 518 
     | 
    
         
            +
                      [200, {}, <<-EOXML]
         
     | 
| 
       515 
519 
     | 
    
         
             
                        <objects count="1">
         
     | 
| 
       516 
520 
     | 
    
         
             
                          <object id="druid:oo000ra0001" url="null/fedora/objects/druid:oo000ra0001"/>
         
     | 
| 
       517 
521 
     | 
    
         
             
                        </objects>
         
     | 
| 
       518 
     | 
    
         
            -
             
     | 
| 
      
 522 
     | 
    
         
            +
                      EOXML
         
     | 
| 
       519 
523 
     | 
    
         
             
                    end
         
     | 
| 
       520 
524 
     | 
    
         
             
                  end
         
     | 
| 
       521 
525 
     | 
    
         
             
                end
         
     | 
| 
         @@ -530,7 +534,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       530 
534 
     | 
    
         | 
| 
       531 
535 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       532 
536 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       533 
     | 
    
         
            -
                    stub.delete(url) { | 
     | 
| 
      
 537 
     | 
    
         
            +
                    stub.delete(url) { |_env| [202, {}, ''] }
         
     | 
| 
       534 
538 
     | 
    
         
             
                  end
         
     | 
| 
       535 
539 
     | 
    
         
             
                end
         
     | 
| 
       536 
540 
     | 
    
         | 
| 
         @@ -564,18 +568,36 @@ describe Dor::WorkflowService do 
     | 
|
| 
       564 
568 
     | 
    
         
             
                  </workflows>
         
     | 
| 
       565 
569 
     | 
    
         
             
                  XML
         
     | 
| 
       566 
570 
     | 
    
         
             
                  allow(Dor::WorkflowService).to receive(:get_workflow_xml) { xml }
         
     | 
| 
      
 571 
     | 
    
         
            +
                  expect(Deprecation).to receive(:warn)
         
     | 
| 
       567 
572 
     | 
    
         
             
                  expect(Dor::WorkflowService.get_active_workflows('dor', 'druid:mw971zk1113')).to eq(['accessionWF'])
         
     | 
| 
       568 
573 
     | 
    
         
             
                end
         
     | 
| 
       569 
574 
     | 
    
         
             
              end
         
     | 
| 
       570 
575 
     | 
    
         | 
| 
      
 576 
     | 
    
         
            +
              describe '.workflow' do
         
     | 
| 
      
 577 
     | 
    
         
            +
                let(:xml) do
         
     | 
| 
      
 578 
     | 
    
         
            +
                  <<~XML
         
     | 
| 
      
 579 
     | 
    
         
            +
                    <workflow repository="dor" objectId="druid:mw971zk1113" id="accessionWF">
         
     | 
| 
      
 580 
     | 
    
         
            +
                      <process laneId="default" lifecycle="submitted" elapsed="0.0" attempts="1" datetime="2013-02-18T15:08:10-0800" status="completed" name="start-accession"/>
         
     | 
| 
      
 581 
     | 
    
         
            +
                    </workflow>
         
     | 
| 
      
 582 
     | 
    
         
            +
                  XML
         
     | 
| 
      
 583 
     | 
    
         
            +
                end
         
     | 
| 
      
 584 
     | 
    
         
            +
                before do
         
     | 
| 
      
 585 
     | 
    
         
            +
                  allow(Dor::WorkflowService).to receive(:get_workflow_xml) { xml }
         
     | 
| 
      
 586 
     | 
    
         
            +
                end
         
     | 
| 
      
 587 
     | 
    
         
            +
             
     | 
| 
      
 588 
     | 
    
         
            +
                it 'it returns a workflow' do
         
     | 
| 
      
 589 
     | 
    
         
            +
                  expect(Dor::WorkflowService.workflow(pid: 'druid:mw971zk1113', workflow_name: 'accessionWF')).to be_kind_of Dor::Workflow::Response::Workflow
         
     | 
| 
      
 590 
     | 
    
         
            +
                end
         
     | 
| 
      
 591 
     | 
    
         
            +
              end
         
     | 
| 
      
 592 
     | 
    
         
            +
             
     | 
| 
       571 
593 
     | 
    
         
             
              describe '#close_version' do
         
     | 
| 
       572 
594 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       573 
595 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       574 
     | 
    
         
            -
                    stub.post('dor/objects/druid:123/versionClose?create-accession=false') do | 
     | 
| 
      
 596 
     | 
    
         
            +
                    stub.post('dor/objects/druid:123/versionClose?create-accession=false') do |_env|
         
     | 
| 
       575 
597 
     | 
    
         
             
                      [202, {}, '']
         
     | 
| 
       576 
598 
     | 
    
         
             
                    end
         
     | 
| 
       577 
599 
     | 
    
         | 
| 
       578 
     | 
    
         
            -
                    stub.post('dor/objects/druid:123/versionClose') do | 
     | 
| 
      
 600 
     | 
    
         
            +
                    stub.post('dor/objects/druid:123/versionClose') do |_env|
         
     | 
| 
       579 
601 
     | 
    
         
             
                      [202, {}, '']
         
     | 
| 
       580 
602 
     | 
    
         
             
                    end
         
     | 
| 
       581 
603 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -595,7 +617,7 @@ describe Dor::WorkflowService do 
     | 
|
| 
       595 
617 
     | 
    
         
             
              describe '.get_stale_queued_workflows' do
         
     | 
| 
       596 
618 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       597 
619 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       598 
     | 
    
         
            -
                    stub.get('workflow_queue/all_queued?repository=dor&hours-ago=24&limit=100') do | 
     | 
| 
      
 620 
     | 
    
         
            +
                    stub.get('workflow_queue/all_queued?repository=dor&hours-ago=24&limit=100') do |_env|
         
     | 
| 
       599 
621 
     | 
    
         
             
                      [200, {}, <<-XML]
         
     | 
| 
       600 
622 
     | 
    
         
             
                      <workflows>
         
     | 
| 
       601 
623 
     | 
    
         
             
                          <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"/>
         
     | 
| 
         @@ -607,10 +629,10 @@ describe Dor::WorkflowService do 
     | 
|
| 
       607 
629 
     | 
    
         
             
                end
         
     | 
| 
       608 
630 
     | 
    
         | 
| 
       609 
631 
     | 
    
         
             
                it 'returns an Array of Hashes containing each workflow step' do
         
     | 
| 
       610 
     | 
    
         
            -
                  ah = Dor::WorkflowService.get_stale_queued_workflows 'dor', : 
     | 
| 
      
 632 
     | 
    
         
            +
                  ah = Dor::WorkflowService.get_stale_queued_workflows 'dor', hours_ago: 24, limit: 100
         
     | 
| 
       611 
633 
     | 
    
         
             
                  expected = [
         
     | 
| 
       612 
     | 
    
         
            -
                    { : 
     | 
| 
       613 
     | 
    
         
            -
                    { : 
     | 
| 
      
 634 
     | 
    
         
            +
                    { workflow: 'accessionWF', step: 'content-metadata', druid: 'dr:123', lane_id: 'lane1' },
         
     | 
| 
      
 635 
     | 
    
         
            +
                    { workflow: 'assemblyWF',  step: 'jp2-create',       druid: 'dr:456', lane_id: 'lane2' }
         
     | 
| 
       614 
636 
     | 
    
         
             
                  ]
         
     | 
| 
       615 
637 
     | 
    
         
             
                  expect(ah).to eql(expected)
         
     | 
| 
       616 
638 
     | 
    
         
             
                end
         
     | 
| 
         @@ -619,21 +641,21 @@ describe Dor::WorkflowService do 
     | 
|
| 
       619 
641 
     | 
    
         
             
              describe '.count_stale_queued_workflows' do
         
     | 
| 
       620 
642 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       621 
643 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       622 
     | 
    
         
            -
                    stub.get('workflow_queue/all_queued?repository=dor&hours-ago=48&count-only=true') do | 
     | 
| 
      
 644 
     | 
    
         
            +
                    stub.get('workflow_queue/all_queued?repository=dor&hours-ago=48&count-only=true') do |_env|
         
     | 
| 
       623 
645 
     | 
    
         
             
                      [200, {}, '<objects count="10"/>']
         
     | 
| 
       624 
646 
     | 
    
         
             
                    end
         
     | 
| 
       625 
647 
     | 
    
         
             
                  end
         
     | 
| 
       626 
648 
     | 
    
         
             
                end
         
     | 
| 
       627 
649 
     | 
    
         | 
| 
       628 
650 
     | 
    
         
             
                it 'returns the number of queued workflow steps' do
         
     | 
| 
       629 
     | 
    
         
            -
                  expect(Dor::WorkflowService.count_stale_queued_workflows('dor', : 
     | 
| 
      
 651 
     | 
    
         
            +
                  expect(Dor::WorkflowService.count_stale_queued_workflows('dor', hours_ago: 48)).to eq(10)
         
     | 
| 
       630 
652 
     | 
    
         
             
                end
         
     | 
| 
       631 
653 
     | 
    
         
             
              end
         
     | 
| 
       632 
654 
     | 
    
         | 
| 
       633 
655 
     | 
    
         
             
              describe '.get_lane_ids' do
         
     | 
| 
       634 
656 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       635 
657 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       636 
     | 
    
         
            -
                    stub.get('workflow_queue/lane_ids?lane_ids?step=dor:accessionWF:shelve') do | 
     | 
| 
      
 658 
     | 
    
         
            +
                    stub.get('workflow_queue/lane_ids?lane_ids?step=dor:accessionWF:shelve') do |_env|
         
     | 
| 
       637 
659 
     | 
    
         
             
                      [200, {}, <<-XML]
         
     | 
| 
       638 
660 
     | 
    
         
             
                      <lanes>
         
     | 
| 
       639 
661 
     | 
    
         
             
                        <lane id="lane1"/>
         
     | 
| 
         @@ -645,14 +667,14 @@ describe Dor::WorkflowService do 
     | 
|
| 
       645 
667 
     | 
    
         
             
                end
         
     | 
| 
       646 
668 
     | 
    
         | 
| 
       647 
669 
     | 
    
         
             
                it 'returns the lane ids for a given workflow step' do
         
     | 
| 
       648 
     | 
    
         
            -
                  expect(Dor::WorkflowService.get_lane_ids('dor', 'accessionWF', 'shelve')).to eq(%w 
     | 
| 
      
 670 
     | 
    
         
            +
                  expect(Dor::WorkflowService.get_lane_ids('dor', 'accessionWF', 'shelve')).to eq(%w[lane1 lane2])
         
     | 
| 
       649 
671 
     | 
    
         
             
                end
         
     | 
| 
       650 
672 
     | 
    
         
             
              end
         
     | 
| 
       651 
673 
     | 
    
         | 
| 
       652 
674 
     | 
    
         
             
              describe '.workflow_resource_method' do
         
     | 
| 
       653 
675 
     | 
    
         
             
                let(:stubs) do
         
     | 
| 
       654 
676 
     | 
    
         
             
                  Faraday::Adapter::Test::Stubs.new do |stub|
         
     | 
| 
       655 
     | 
    
         
            -
                    stub.get('x?complete=a&complete=b') do | 
     | 
| 
      
 677 
     | 
    
         
            +
                    stub.get('x?complete=a&complete=b') do |_env|
         
     | 
| 
       656 
678 
     | 
    
         
             
                      [200, {}, 'ab']
         
     | 
| 
       657 
679 
     | 
    
         
             
                    end
         
     | 
| 
       658 
680 
     | 
    
         
             
                  end
         
     |