[yast-commit] <rest-service> backgroud_patches_bnc550934 : added BackgroundStatus test suite
ref: refs/heads/backgroud_patches_bnc550934 commit 50b3749636edaddde03ac59c4da2ef140dc03752 Author: Ladislav Slezak <lslezak@novell.com> Date: Fri Dec 18 09:44:39 2009 +0100 added BackgroundStatus test suite --- webservice/test/unit/background_status_test.rb | 81 ++++++++++++++++++++++++ 1 files changed, 81 insertions(+), 0 deletions(-) diff --git a/webservice/test/unit/background_status_test.rb b/webservice/test/unit/background_status_test.rb new file mode 100644 index 0000000..2131fa7 --- /dev/null +++ b/webservice/test/unit/background_status_test.rb @@ -0,0 +1,81 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ObserverTest + def initialize(observable) + observable.add_observer(self) + reset + end + + def update(observable) + @changed = true + end + + def changed? + @changed + end + + def reset + @changed = false + end +end + +class BackgroundStatusTest < ActiveSupport::TestCase + def setup + @bs = BackgroundStatus.new + end + + def test_assignemnt + s = 'status' + p = 10 + sp = 5 + @bs.status = s + @bs.progress = p + @bs.subprogress = sp + + assert_equal s, @bs.status + assert_equal p, @bs.progress + assert_equal sp, @bs.subprogress + end + + def test_observing + ot = ObserverTest.new(@bs, changed_flag) + s = 'dummy status' + p = 10 + sp = 5 + + # test progress change + ot.reset + @bs.progress = p + assert ot.changed? + + ot.reset + @bs.subprogress = sp + assert ot.changed? + + ot.reset + @bs.status = s + assert ot.changed? + + # no change must not emit change event + ot.reset + @bs.progress = p + assert !ot.changed? + + ot.reset + @bs.subprogress = sp + assert !ot.changed? + + ot.reset + @bs.status = s + assert !ot.changed? + end + + def test_serialization + assert @bs.to_xml + + expected_ret = {"subprogress" => @bs.subprogress, "progress" => @bs.progress, "status" => @bs.status } + + assert_equal expected_ret, Hash.from_xml(@bs.to_xml)["background_status"] + end + +end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
Ladislav Slezak