| 1 | 9 | ▶ | use 5.008; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 9 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 9 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | package Data::Conveyor::Test; | ||
| 6 | 9 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 9 | $Data::Conveyor::Test::VERSION = '1.103130'; | |
| 8 | } | ||
| 9 | # ABSTRACT: Stage-based conveyor-belt-like ticket handling system | ||
| 10 | 9 | ▶ | use Test::More; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 9 | ▶ | use Error::Hierarchy::Util 'load_class'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 9 | ▶ | use parent 'Class::Scaffold::Test'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | # e.g., stage_basics_ok($self->delegate, ST_POLICY => 1); | ||
| 15 | sub stage_basics_ok { | ||
| 16 | my ($self, $stage_type_const, $will_shift_ticket, %stage_args) = @_; | ||
| 17 | my $stage_type = $self->delegate->$stage_type_const; | ||
| 18 | my $stage = $self->delegate->make_stage_object($stage_type, %stage_args); | ||
| 19 | is($stage->expected_stage, $stage_type, | ||
| 20 | "expected stage type [$stage_type]"); | ||
| 21 | is($stage->will_shift_ticket, $will_shift_ticket, | ||
| 22 | "$stage_type ticket shift setting"); | ||
| 23 | } | ||
| 24 | |||
| 25 | sub transition_ok { | ||
| 26 | my ($self, $test_storage, $stage, $rc, $next_stage) = @_; | ||
| 27 | $test_storage->transition_ok_bare( | ||
| 28 | $test_storage, | ||
| 29 | $test_storage->delegate->make_obj('value_ticket_stage') | ||
| 30 | ->new_end($stage), | ||
| 31 | $rc, | ||
| 32 | $test_storage->delegate->make_obj('value_ticket_stage') | ||
| 33 | ->new_start($next_stage), | ||
| 34 | ); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub transition_ok_bare { | ||
| 38 | my ($self, $test_storage, $stage, $rc, $next_stage) = @_; | ||
| 39 | is($test_storage->get_next_stage($stage, $rc), | ||
| 40 | $next_stage, sprintf('%s + %s = %s', $stage, $rc, $next_stage)); | ||
| 41 | } | ||
| 42 | |||
| 43 | sub factory_gen_template_handler_ok { | ||
| 44 | my ($self, $factory, $gen_method, $hash_name) = @_; | ||
| 45 | my %hash_spec = $factory->every_hash($hash_name); | ||
| 46 | while (my ($ticket_type, $class) = each %hash_spec) { | ||
| 47 | next if $ticket_type eq '_AUTO'; | ||
| 48 | isa_ok( | ||
| 49 | $factory->$gen_method( | ||
| 50 | ticket => | ||
| 51 | $factory->delegate->make_obj('ticket', type => $ticket_type), | ||
| 52 | ), | ||
| 53 | $class | ||
| 54 | ); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | sub factory_gen_txsel_handler_iterate { | ||
| 59 | my ($self, $factory, $gen_method, $spec, $value) = @_; | ||
| 60 | if (ref $value eq 'HASH') { | ||
| 61 | while (my ($deeper_spec, $deeper_value) = each %$value) { | ||
| 62 | next if $deeper_spec eq '_AUTO'; | ||
| 63 | $self->factory_gen_txsel_handler_iterate($factory, $gen_method, | ||
| 64 | [ @$spec, $deeper_spec ], | ||
| 65 | $deeper_value); | ||
| 66 | } | ||
| 67 | } else { | ||
| 68 | |||
| 69 | # expect it to be a scalar, i.e. a leaf, so call the generator method | ||
| 70 | isa_ok($factory->$gen_method(@$spec), $value); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | sub factory_gen_txsel_handler_ok { | ||
| 75 | my ($self, $factory, $gen_method, $hash_name) = @_; | ||
| 76 | my %hash_spec = $factory->every_hash($hash_name); | ||
| 77 | $self->factory_gen_txsel_handler_iterate($factory, $gen_method, [], | ||
| 78 | \%hash_spec); | ||
| 79 | } | ||
| 80 | |||
| 81 | sub factory_gen_transaction_handler_ok { | ||
| 82 | my ($self, $factory, $gen_method, $hash_name) = @_; | ||
| 83 | my %hash_spec = $factory->every_hash($hash_name); | ||
| 84 | while (my ($object_type, $ot_spec) = each %hash_spec) { | ||
| 85 | next if $object_type eq '_AUTO'; | ||
| 86 | while (my ($command, $class) = each %$ot_spec) { | ||
| 87 | next if $command eq '_AUTO'; | ||
| 88 | my $tx = $factory->delegate->make_obj( | ||
| 89 | 'transaction', | ||
| 90 | object_type => $object_type, | ||
| 91 | command => $command, | ||
| 92 | ); | ||
| 93 | my $payload_tx = $factory->delegate->make_obj('payload_transaction', | ||
| 94 | transaction => $tx); | ||
| 95 | isa_ok($factory->$gen_method(tx => $payload_tx), $class); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | sub apply_rc_ok { | ||
| 101 | my ($self, $from, $via, $to, $should_ask_delegate) = @_; | ||
| 102 | if ($should_ask_delegate) { | ||
| 103 | $_ = $self->delegate->$_ for $from, $via, $to; | ||
| 104 | } | ||
| 105 | $_ = $self->delegate->make_obj('value_ticket_rc', value => $_) | ||
| 106 | for $from, $via, $to; | ||
| 107 | is($from + $via, $to, sprintf("apply_rc: %s x %s = %s", $from, $via, $to)); | ||
| 108 | } | ||
| 109 | |||
| 110 | sub apply_status_ok { | ||
| 111 | my ($self, $from, $via, $to, $should_ask_delegate) = @_; | ||
| 112 | if ($should_ask_delegate) { | ||
| 113 | $_ = $self->delegate->$_ for $from, $via, $to; | ||
| 114 | } | ||
| 115 | $_ = $self->delegate->make_obj('value_ticket_status', value => $_) | ||
| 116 | for $from, $via, $to; | ||
| 117 | is($from + $via, | ||
| 118 | $to, sprintf("apply_status: %s x %s = %s", $from, $via, $to)); | ||
| 119 | } | ||
| 120 | |||
| 121 | sub object_limit_ok { | ||
| 122 | my ($self, $ticket_type_const, $object_type_const, $expected) = @_; | ||
| 123 | my $ticket_type = $self->delegate->$ticket_type_const; | ||
| 124 | my $object_type = $self->delegate->$object_type_const; | ||
| 125 | is( $self->delegate->get_object_limit($ticket_type, $object_type), | ||
| 126 | $expected, sprintf '%s, %s -> %s', | ||
| 127 | $ticket_type, $object_type, $expected | ||
| 128 | ); | ||
| 129 | } | ||
| 130 | |||
| 131 | sub rc_for_exception_class_ok { | ||
| 132 | my ($self, $handler, $exception_class, $payload_item_type, $command_name, | ||
| 133 | $rc_name) | ||
| 134 | = @_; | ||
| 135 | |||
| 136 | # The exception class needs to be loaded so class_map() can determine its | ||
| 137 | # superclasses. | ||
| 138 | load_class $exception_class, 0; | ||
| 139 | my $payload_item = $self->delegate->make_obj($payload_item_type, | ||
| 140 | command => $self->delegate->$command_name); | ||
| 141 | my $rc = $handler->rc_for_exception_class($exception_class, $payload_item); | ||
| 142 | is( $rc, | ||
| 143 | $self->delegate->$rc_name, | ||
| 144 | sprintf 'type [%s], command [%s]: exception [%s] => rc [%s]', | ||
| 145 | $payload_item_type, | ||
| 146 | $command_name, | ||
| 147 | $exception_class, | ||
| 148 | $rc_name | ||
| 149 | ); | ||
| 150 | } | ||
| 151 | 1; | ||
| 152 | |||
| 153 | |||
| 154 | __END__ | ||