$:.unshift(File.dirname(__FILE__)) require 'abstract_unit' class JudeApiLoaderForLockedProjectTest < Test::Unit::TestCase test_jude_model_dir :class_diagram TEST_TMP_DIR = File.join File.dirname(__FILE__), '..', 'tmp' def setup super Luruju::Configuration.install do |config| config.use_jude_cache = false end FileUtils.remove_entry(TEST_TMP_DIR, :force => true) @test_loader = Luruju::JudeApiLoader.dup return if am_i_cruby? @test_loader.instance_eval do class << self alias_method :hoge, :original_load def original_load jude_file, options={} raise Luruju::ProjectLockedException.new if FileTest.exist? "#{jude_file}.test" hoge jude_file, options end end end end def teardown FileUtils.remove_entry TEST_TMP_DIR, :force => true end def test_load_file_not_found_exception assert_raise Luruju::ProjectNotFoundException do @test_loader.load("#{jude_dir}/hoge.jude") end end def test_unexpected_exception assert_raise UnexpectedNativeException do @test_loader.load "#{jude_dir}/dummy.jude" end end def test_load_locked_exception return if am_i_cruby? assert_raise Luruju::ProjectLockedException do @test_loader.load("#{jude_dir}/locked.jude", :copy => :never) end end def test_load project = @test_loader.load "#{jude_dir}/locked.jude" assert_equal "locked", project.name end def test_load_copy_if_locked project = @test_loader.load "#{jude_dir}/locked.jude", :copy => :if_locked assert_equal "locked", project.name end def test_load_copy_first project = @test_loader.load "#{jude_dir}/locked.jude", :copy => :first assert_equal "locked", project.name end def test_load_tmpdir project = @test_loader.load "#{jude_dir}/locked.jude", :tmpdir => TEST_TMP_DIR assert_equal "locked", project.name end def test_load_tmpdir_already_mkdir FileUtils.makedirs TEST_TMP_DIR project = @test_loader.load "#{jude_dir}/locked.jude", :tmpdir => TEST_TMP_DIR assert_equal "locked", project.name end def test_load_copy_first_and_tmpdir project = @test_loader.load "#{jude_dir}/locked.jude", :copy => :first, :tmpdir => TEST_TMP_DIR assert_equal "locked", project.name end def test_load_not_overflow_when_retry_failed return if am_i_cruby? @test_loader.instance_eval do class << self def original_load jude_file, options={} raise Luruju::ProjectLockedException.new end end end assert_raise Luruju::ProjectLockedException do @test_loader.load "#{jude_dir}/locked.jude", :copy => :if_locked end end end