Class: MobyBase::SutController
- Defined in:
- lib/tdriver/base/sut/controller.rb
Instance Attribute Summary collapse
-
#execution_order ⇒ Object
, :test_object_adapter, :test_object_factory.
-
#sut_controllers ⇒ Object
, :test_object_adapter, :test_object_factory.
Instance Method Summary collapse
-
#execute_command(command_data) ⇒ Object
Function to execute a command on a SutController This method is not meant to be overwritten in descendants.
-
#initialize(sut_controllers, sut_adapter) ⇒ SutController
constructor
- Creating new SutController associates SutAdapter to the controller == params sut_adapter
-
MobyController::SutAdapter descendant, e.g.
Constructor Details
#initialize(sut_controllers, sut_adapter) ⇒ SutController
Creating new SutController associates SutAdapter to the controller
params
- sut_adapter
-
MobyController::SutAdapter descendant, e.g. MobyController::QT::SutAdapter
raises
- TypeError
-
Wrong argument type $1 for SUT controller (expected $2)
- NameError
-
No SUT controller found for <type> (<class>)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/tdriver/base/sut/controller.rb', line 32 def initialize( sut_controllers, sut_adapter ) sut_controllers.check_type String, 'Wrong argument type $1 for SUT controller (expected $2)' @sut_adapter = sut_adapter # empty sut controllers hash @sut_controllers = {} # empty sut controller execution order, this will be used when multiple sut controllers given @execution_order = [] sut_controllers.split( ';' ).each{ | sut_type | begin # add sut_controller to execution order list @execution_order << sut_type # store sut controller @sut_controllers[ sut_type ] = "MobyController::#{ sut_type }" # extend controller module extend( eval( "#{ @sut_controllers[ sut_type ] }::SutController" ) ) rescue NameError raise MobyBase::ControllerNotFoundError, "No SUT controller found for #{ sut_type } (#{ @sut_controllers[ sut_type ] }::SutController)" end } end |
Instance Attribute Details
#execution_order ⇒ Object
, :test_object_adapter, :test_object_factory
24 25 26 |
# File 'lib/tdriver/base/sut/controller.rb', line 24 def execution_order @execution_order end |
#sut_controllers ⇒ Object
, :test_object_adapter, :test_object_factory
24 25 26 |
# File 'lib/tdriver/base/sut/controller.rb', line 24 def sut_controllers @sut_controllers end |
Instance Method Details
#execute_command(command_data) ⇒ Object
Function to execute a command on a SutController This method is not meant to be overwritten in descendants.
Associates MobyCommand::CommandData implementation based on the MobyCommand class name, by finding implementation from the same module as the SutController instance.
example: MobyController::QT::SutController instance associates MobyController::QT::Application (module) implementation to MobyCommand::Application command_data object
params
- command_data
-
MobyCommand::CommandData descendant
returns
command_data implementation specific return value
raises
- TypeError
-
Wrong argument type $1 for command_data (expected $2)
- MobyBase::CommandNotFoundError
-
if no implementation is found for the CommandData object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/tdriver/base/sut/controller.rb', line 83 def execute_command( command_data ) command_data.check_type MobyCommand::CommandData, 'Wrong argument type $1 for command_data (expected $2)' _command_class_suffix = command_data.class.name.gsub(/^MobyCommand::/, '') _execution_order_count = @execution_order.count # retrieve controller for command; iterate through each sut controller @execution_order.each_with_index do | controller, index | begin # extend command_data with combinination of corresponding sut specific controller command_data.extend eval( "#{ @sut_controllers[ controller ] }::#{ _command_class_suffix }" ) # controller found break rescue NameError # raise exception only if none controller found if ( index + 1 ) == _execution_order_count raise MobyBase::ControllerNotFoundError, "No controller found for command data object #{ command_data.inspect }" end end end # pass sut_adapter for command_data command_data.set_adapter( @sut_adapter ) retries = 0 begin # execute the command command_data.execute # retry in case of IO/connection error rescue Errno::EPIPE, IOError raise if retries == 1 retries += 1 if TDriver::SUTFactory.connected_suts.include?( @sut_adapter.sut_id.to_sym ) @sut_adapter.disconnect @sut_adapter.connect( @sut_adapter.sut_id ) end retry end end |