require 'spec_helper' describe Roqua::Healthy::A19::Fetcher do it 'succeeds when upstream returns XML' do stub_mirth_response("") expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.not_to raise_error end it "raises when upstream does not return HTTP 200" do stub_mirth_response "Request not successful", 500 expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception end it 'raises when upstream responds with illegal XML' do stub_mirth_response "Jan & Piet" expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_error(Roqua::Healthy::IllegalMirthResponse) stub_mirth_response "Jan" expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_error(Roqua::Healthy::IllegalMirthResponse) end it "raises upstream is returning 'Timeout waiting for ACK' messages" do stub_mirth_response "Timeout waiting for ACK", 500 expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::Timeout) end it "raises upstream is returning 'connection timeout' messages" do stub_mirth_response "Unable to connect to destination\tSocketTimeoutException\tconnect timed out", 500 expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::Timeout) end it "raises upstream is returning 'connection refuesed' messages" do stub_mirth_response "Unable to connect to destination\tConnectException\tConnection refused", 500 expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::ConnectionRefused) end it "raises when upstream does not accept connections" do stub_mirth.to_raise Errno::ECONNREFUSED expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::ConnectionRefused) end it 'raises when upstream is unreachable' do stub_mirth.to_raise Errno::EHOSTUNREACH expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::HostUnreachable) end it "raises when upstream is timing out" do stub_mirth.to_timeout expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::Timeout) stub_mirth.to_raise Errno::ETIMEDOUT expect { Roqua::Healthy::A19::Fetcher.new("123").fetch }.to raise_exception(Roqua::Healthy::Timeout) end end