#-- # ============================================================================= # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu) # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # * The names of its contributors may not be used to endorse or promote # products derived from this software without specific prior written # permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # ============================================================================= #++ $:.unshift "../.." $:.unshift "../../../lib" require 'test/unit' require 'copland/configuration/yaml/implementor' require 'copland/instantiator' require 'mock' require 'yaml' class TC_ImplementorProcessor < Test::Unit::TestCase def setup @processor = Copland::Configuration::YAML::ImplementorProcessor.new end def test_process_bad_type point = MockServicePoint.new assert_raise( Copland::Configuration::ParserError ) do @processor.process( point, 15 ) end end def test_process_simple point = MockServicePoint.new assert_nothing_raised do @processor.process( point, "something" ) end assert_instance_of Copland::Instantiator::Simple, point.instantiator end def test_process_complex point = MockServicePoint.new assert_nothing_raised do @processor.process( point, "factory" => "something" ) end assert_instance_of Copland::Instantiator::Complex, point.instantiator end def test_process_complex_deyamlize_good point = MockServicePoint.new parms = { "factory" => "something", "class" => YAML::Syck::PrivateType.new( "real", 3.1415 ), "items" => [ "a string", YAML::Syck::PrivateType.new( "service", "copland.Registry" ) ], "map" => { "key1" => "a string", "key2" => YAML::Syck::PrivateType.new( "configuration", "copland.Registry" ) } } assert_nothing_raised do @processor.process( point, parms ) end assert_instance_of Copland::Instantiator::Complex, point.instantiator assert_equal "a string", point.instantiator.construction_parms['map'].value['key1'].value assert_equal "service", point.instantiator.construction_parms['items'].value[1].type_id assert_equal "hash", point.instantiator.construction_parms['map'].type_id assert_equal "array", point.instantiator.construction_parms['items'].type_id assert_equal "copland.Registry", point.instantiator.construction_parms['items'].value[1].value end end