| 1 |
# Licensed to the Apache Software Foundation (ASF) under one |
| 2 |
# or more contributor license agreements. See the NOTICE file |
| 3 |
# distributed with this work for additional information |
| 4 |
# regarding copyright ownership. The ASF licenses this file |
| 5 |
# to you under the Apache License, Version 2.0 (the |
| 6 |
# "License"); you may not use this file except in compliance |
| 7 |
# with the License. You may obtain a copy of the License at |
| 8 |
# |
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
# |
| 11 |
# Unless required by applicable law or agreed to in writing, |
| 12 |
# software distributed under the License is distributed on an |
| 13 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 |
# KIND, either express or implied. See the License for the |
| 15 |
# specific language governing permissions and limitations |
| 16 |
# under the License. |
| 17 |
|
| 18 |
|
| 19 |
require "spec_helper" |
| 20 |
|
| 21 |
module Qpid |
| 22 |
|
| 23 |
module Proton |
| 24 |
|
| 25 |
class ExceptionHandlingClass |
| 26 |
include Qpid::Proton::Util::ErrorHandler |
| 27 |
|
| 28 |
def error |
| 29 |
"This is a test error: #{Time.new}" |
| 30 |
end |
| 31 |
end |
| 32 |
|
| 33 |
describe "The exception handling mixin" do |
| 34 |
|
| 35 |
before (:each) do |
| 36 |
@handler = Qpid::Proton::ExceptionHandlingClass.new |
| 37 |
end |
| 38 |
|
| 39 |
it "does not raise an error on a zero code" do |
| 40 |
@handler.check_for_error(0) |
| 41 |
end |
| 42 |
|
| 43 |
it "raises EOS on PN_EOS" do |
| 44 |
proc { |
| 45 |
@handler.check_for_error(Qpid::Proton::Error::EOS) |
| 46 |
}.must_raise(Qpid::Proton::EOSError) |
| 47 |
end |
| 48 |
|
| 49 |
it "raises Error on PN_ERR" do |
| 50 |
proc { |
| 51 |
@handler.check_for_error(Qpid::Proton::Error::ERROR) |
| 52 |
}.must_raise(Qpid::Proton::ProtonError) |
| 53 |
end |
| 54 |
|
| 55 |
it "raises Overflow on PN_OVERFLOW" do |
| 56 |
proc { |
| 57 |
@handler.check_for_error(Qpid::Proton::Error::OVERFLOW) |
| 58 |
}.must_raise(Qpid::Proton::OverflowError) |
| 59 |
end |
| 60 |
|
| 61 |
it "raises Underflow on PN_UNDERFLOW" do |
| 62 |
proc { |
| 63 |
@handler.check_for_error(Qpid::Proton::Error::UNDERFLOW) |
| 64 |
}.must_raise(Qpid::Proton::UnderflowError) |
| 65 |
end |
| 66 |
|
| 67 |
it "raises Argument on PN_ARG_ERR" do |
| 68 |
proc { |
| 69 |
@handler.check_for_error(Qpid::Proton::Error::ARGUMENT) |
| 70 |
}.must_raise(Qpid::Proton::ArgumentError) |
| 71 |
end |
| 72 |
|
| 73 |
it "raises TimeoutError on PN_TIMEOUT" do |
| 74 |
proc { |
| 75 |
@handler.check_for_error(Qpid::Proton::Error::TIMEOUT) |
| 76 |
}.must_raise(Qpid::Proton::TimeoutError) |
| 77 |
end |
| 78 |
|
| 79 |
it "raises an Ruby ArgumentError on a nil code" do |
| 80 |
proc { |
| 81 |
@handler.check_for_error(nil) |
| 82 |
}.must_raise(::ArgumentError) |
| 83 |
end |
| 84 |
|
| 85 |
it "raises a Ruby ArgumentError on an unknown value" do |
| 86 |
proc { |
| 87 |
@handler.check_for_error("farkle") |
| 88 |
}.must_raise(::ArgumentError) |
| 89 |
end |
| 90 |
|
| 91 |
end |
| 92 |
|
| 93 |
end |
| 94 |
|
| 95 |
end |