ASNMTAP

 view release on metacpan or  search on metacpan

lib/ASNMTAP/Asnmtap/Plugins/WebTransact.pod  view on Meta::CPAN

Get the urls

  foreach ( @{ $objectWebTransact->get_urls() } ) {
    while ( my ($key, $value) = each %{ $_ } ) { print "$key => $value\n"; }
  };

=item $objectWebTransact->set_urls()

Set the urls used by the next call from $objectWebTransact->check ( { } )

  my @URLS = (
    { Method => 'GET',  Url => 'http://www.citap.be/', Qs_var => [], Qs_fixed => [], Exp => "Consulting Internet Technology Alex Peeters", Exp_Fault => ">>>NIHIL<<<", Msg => "Consulting Internet Technology Alex Peeters", Msg_Fault => "Consulting Inte...
  );

  $objectWebTransact->urls( \@URLS );

  $returnCode = $objectWebTransact->check ( { } );

=back

=head1 EXAMPLES

This example performs a primitive content check of the ADDS service, getting the page
specified by the Url field, and if there is a response from the web server, comparing
the response to the fields Exp and Exp_Fault and returns Exp_Return.

If the response matches the Exp field the check succeeds; if the response matches the
Exp_Fault field the check fails.

  use ASNMTAP::Asnmtap::Plugins::WebTransact;

  my $ar = [ { Method         => 'GET',
               Url            => "http://Pericles.IPAustralia.Gov.AU/adds2/ADDS.ADDS_START.intro",
               Qs_var         => [],
               Qs_fixed       => [],
               Exp            => 'Designs Data Searching - Introduction',
               Exp_Fault      => 'We were unable to process your request at this time',
               Exp_Return     => {},
               Msg            => 'Status error when not all Exp found',
               Msg_Fault      => 'Status error when Exp_Fault found',
               Timeout        => 30,
               Perfdata_Label => 'Label x' } ];

  my $objectWebTransact = ASNMTAP::Asnmtap::Plugins::WebTransact->new ( \$objectPlugins, $ar);
  my $returnCode = $objectWebTransact->check ( { tmno => $tmno } );

  foreach ( @{ $objectWebTransact->get_matches() } ) { print $_, "\n"; }

  undef $objectWebTransact;

This example checks if a complete ATMOSS transaction is successfull by getting a sequence
of URLs, checking the content where the Qs_fixed and Qs_var fields are non null generating
a query string for the request.

For example, the POST request for 'http://external/atmoss/Falcon.Result' is accompanied by
the query string p_tmno1 = <current_value_of_arg_hash{tmno}>

  use ASNMTAP::Asnmtap::Plugins::WebTransact;

  use constant Intro              => 'http://Pericles.IPAustralia.Gov.AU/atmoss/falcon.application_start';
  use constant ConnectToSearch    => 'http://Pericles.IPAustralia.Gov.AU/atmoss/Falcon_Users_Cookies.Define_User';
  use constant MultiSessConn      => 'http://Pericles.IPAustralia.Gov.AU/atmoss/Falcon_Users_Cookies.Run_Create';
  use constant Search             => 'http://Pericles.IPAustralia.Gov.AU/atmoss/Falcon.Result';
  use constant ResultAbstract     => 'http://Pericles.IPAustralia.Gov.AU/atmoss/falcon_details.show_tm_details';
  use constant ResultDetails      => 'http://Pericles.IPAustralia.Gov.AU/atmoss/Falcon_Details.Show_TM_Details';
  use constant DeleteSearches     => 'http://Pericles.IPAustralia.Gov.AU/atmoss/Falcon_Searches.Delete_All_Searches';

  use constant Int                => 'Welcome to ATMOSS';
  use constant ConnSrch           => 'Connect to Trade Mark Search';
  use constant MltiSess           => 'Fill in one or more of the fields below';
  use constant Srch               => 'Your search request retrieved\s+\d+\s+match(es)?';
  use constant ResAbs             => 'Trade Mark\s+:\s+\d+';
  use constant ResDet             => ResAbs;
  use constant DelSrch            => MltiSess;

  use constant MSC_f              => [p_Anon => 'REGISTERED', p_user_type => 'Connect to Existing Extract List', p_extID => 'Foo', p_password => 'Bar'];
  use constant Srch_v             => [p_tmno1 => 'tmno'];
  use constant RA_v               => [p_tm_number => 'tmno'];
  use constant RA_f               => [p_detail => 'QUICK', p_rec_all => 1, p_rec_no => 1, p_search_no => 1, p_ExtDisp => 'D'];
  use constant RD_v               => RA_v;
  use constant RD_f               => [p_Detail => 'DETAILED', p_rec_no => 1, p_search_no => 1,  p_ExtDisp => 'D'];

  use constant OraFault           => 'We were unable to process your request at this time';

  use constant URLS               => [
    {Method => 'GET',  Url => Intro,           Qs_var => [],     Qs_fixed => [], Exp => Int,        Exp_Fault => OraFault, Msg => '', Msg_Fault => ''},
    {Method => 'GET',  Url => ConnectToSearch, Qs_var => [],     Qs_fixed => [], Exp => ConnSrch,   Exp_Fault => OraFault, Msg => '', Msg_Fault => ''},
    {Method => 'POST', Url => MultiSessConn,   Qs_var => [],     Qs_fixed => MSC_f,Exp => MltiSess, Exp_Fault => OraFault, Msg => '', Msg_Fault => ''},
    {Method => 'POST', Url => Search,          Qs_var => Srch_v, Qs_fixed => [], Exp => Srch,       Exp_Fault => OraFault, Msg => '', Msg_Fault => ''},
    {Method => 'GET',  Url => ResultAbstract,  Qs_var => RA_v,   Qs_fixed => RA_f, Exp => ResAbs,   Exp_Fault => OraFault, Msg => '', Msg_Fault => ''},
    {Method => 'POST', Url => ResultDetails,   Qs_var => RD_v,   Qs_fixed => RD_f, Exp => ResDet,   Exp_Fault => OraFault, Msg => '', Msg_Fault => ''},
    {Method => 'POST', Url => DeleteSearches,  Qs_var => [],     Qs_fixed => [], Exp => DelSrch,    Exp_Fault => OraFault, Msg => '', Msg_Fault => ''},
  ];

  @tmarks = @ARGV ? @ARGV : (3, 100092, 200099, 300006, 400075, 500067, 600076, 700066, 800061);
  $i = @ARGV == 1 ? 0 : int( rand($#tmarks) + 0.5 );
  $tmno = $tmarks[$i];

  $objectWebTransact = ASNMTAP::Asnmtap::Plugins::WebTransact->new ( \$objectPlugins, URLS );
  $returnCode = $objectWebTransact->check ( {tmno => $tmno} )

  foreach ( @{ $objectWebTransact->get_matches() } ) { print $_, "\n"; }

  undef $objectWebTransact;

More examples:

=over 4

=item Example 1

  use constant EXP_NAVIGATION_TOKEN => '<input\s+type="hidden"\s+name="NAVIGATION_TOKEN"\s+value="(-{0,1}\d+)"\s+/>';
  use constant VAL_NAVIGATION_TOKEN => [0, sub { $_[0] }];

  use constant EXP_TICKETNUMBER     => '<b>N°\s+de\s+ticket\s*:</b>\s*\n*\s*&nbsp;(\w{3}-\w{7}-\w{2}-\w)';
  use constant VAL_TICKETNUMBER     => [1, sub { $_[0] }];

  @URLS = (
    { Method => 'GET',  Url => "...", Qs_var => [], Qs_fixed => [], Exp => [EXP_NAVIGATION_TOKEN, EXP_TICKETNUMBER], ... },
    { Method => 'POST', Url => "...", Qs_var => [NAVIGATION_TOKEN => VAL_NAVIGATION_TOKEN, TICKETNUMBER => VAL_TICKETNUMBER], Qs_fixed => [], Exp => [EXP_NAVIGATION_TOKEN, EXP_TICKETNUMBER], ... },
  );



( run in 0.976 second using v1.01-cache-2.11-cpan-39bf76dae61 )