| 1 | package SADI::Simple::UnitTest; | ||
| 2 | { | ||
| 3 | $SADI::Simple::UnitTest::VERSION = '0.15'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use base ("SADI::Simple::Base"); | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | SADI::Simple::UnitTest - A module that encapsulates unit test information for sadi services. | ||
| 12 | |||
| 13 | =head1 SYNOPSIS | ||
| 14 | |||
| 15 | use SADI::Simple::UnitTest; | ||
| 16 | |||
| 17 | # create a new blank SADI UnitTest object | ||
| 18 | my $data = SADI::Simple::UnitTest->new (); | ||
| 19 | |||
| 20 | # create a new primed SADI UnitTest object | ||
| 21 | $data = SADI::Simple::UnitTest->new ( | ||
| 22 | regex => '(\w+)+', | ||
| 23 | xpath => '/xml/text()', | ||
| 24 | input => '<xml/>', | ||
| 25 | output => '<xml/>', | ||
| 26 | ); | ||
| 27 | |||
| 28 | # get the unit test regex | ||
| 29 | my $regex = $data->regex; | ||
| 30 | # set the regex statement for this test | ||
| 31 | $data->regex($regex); | ||
| 32 | |||
| 33 | # get the unit test xpath statement | ||
| 34 | my $xpath = $data->xpath; | ||
| 35 | # set the xpath statement for this test | ||
| 36 | $data->regex($xpath); | ||
| 37 | |||
| 38 | # get input for this test | ||
| 39 | my $input = $data->input; | ||
| 40 | # set the input for this test | ||
| 41 | $data->input($input); | ||
| 42 | |||
| 43 | # get expected output for this test | ||
| 44 | my $output = $data->output; | ||
| 45 | # set the expected output for this test | ||
| 46 | $data->output($output); | ||
| 47 | |||
| 48 | =head1 DESCRIPTION | ||
| 49 | |||
| 50 | An object representing a SADI service unit test. | ||
| 51 | |||
| 52 | =head1 AUTHORS | ||
| 53 | |||
| 54 | Edward Kawas (edward.kawas [at] gmail [dot] com) | ||
| 55 | |||
| 56 | =cut | ||
| 57 | |||
| 58 | #----------------------------------------------------------------- | ||
| 59 | # A list of allowed attribute names. See SADI::Base for details. | ||
| 60 | #----------------------------------------------------------------- | ||
| 61 | |||
| 62 | =head1 ACCESSIBLE ATTRIBUTES | ||
| 63 | |||
| 64 | Details are in L<SADI::Base>. Here just a list of them (additionally | ||
| 65 | to the attributes from the parent classes) | ||
| 66 | |||
| 67 | =over | ||
| 68 | |||
| 69 | =item B<input> | ||
| 70 | |||
| 71 | The input for this unit test. Input is required, because without it, there can be no test | ||
| 72 | |||
| 73 | =item B<output> | ||
| 74 | |||
| 75 | The expected output of this service given the specified input. | ||
| 76 | |||
| 77 | =item B<regex> | ||
| 78 | |||
| 79 | A regular expression that should match the output of the service given the specified input. | ||
| 80 | |||
| 81 | =item B<xpath> | ||
| 82 | |||
| 83 | An xpath expression that should yield return results given the specified input. | ||
| 84 | |||
| 85 | =back | ||
| 86 | |||
| 87 | =cut | ||
| 88 | |||
| 89 | { | ||
| 90 | my %_allowed = ( | ||
| 91 | input => { type => SADI::Base->STRING }, | ||
| 92 | output => { type => SADI::Base->STRING }, | ||
| 93 | regex => { type => SADI::Base->STRING }, | ||
| 94 | xpath => { type => SADI::Base->STRING }, | ||
| 95 | ); | ||
| 96 | |||
| 97 | sub _accessible { | ||
| 98 | my ( $self, $attr ) = @_; | ||
| 99 | exists $_allowed{$attr} or $self->SUPER::_accessible($attr); | ||
| 100 | } | ||
| 101 | |||
| 102 | sub _attr_prop { | ||
| 103 | my ( $self, $attr_name, $prop_name ) = @_; | ||
| 104 | my $attr = $_allowed{$attr_name}; | ||
| 105 | return ref($attr) ? $attr->{$prop_name} : $attr if $attr; | ||
| 106 | return $self->SUPER::_attr_prop( $attr_name, $prop_name ); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | #----------------------------------------------------------------- | ||
| 111 | # init | ||
| 112 | #----------------------------------------------------------------- | ||
| 113 | sub init { | ||
| 114 | my ($self) = shift; | ||
| 115 | $self->SUPER::init(); | ||
| 116 | |||
| 117 | # set any defaults here | ||
| 118 | |||
| 119 | } | ||
| 120 | |||
| 121 | 1; | ||
| 122 | |||
| 123 | __END__ |