ASNMTAP

 view release on metacpan or  search on metacpan

plugins/templates/check_template-WebTransact-XML-Cactus-parser.pl  view on Meta::CPAN

#!/usr/bin/env perl
# ----------------------------------------------------------------------------------------------------------
# © Copyright 2003-2011 by Alex Peeters [alex.peeters@citap.be]
# ----------------------------------------------------------------------------------------------------------
# 2011/mm/dd, v3.002.003, check_template-WebTransact-XML-Cactus-parser.pl
# ----------------------------------------------------------------------------------------------------------

use strict;
use warnings;           # Must be used in test mode only. This reduces a little process speed
#use diagnostics;       # Must be used in test mode only. This reduces a lot of process speed

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

BEGIN { if ( $ENV{ASNMTAP_PERL5LIB} ) { eval 'use lib ( "$ENV{ASNMTAP_PERL5LIB}" )'; } }

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

use ASNMTAP::Asnmtap::Plugins v3.002.003;
use ASNMTAP::Asnmtap::Plugins qw(:PLUGINS);

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

my $objectPlugins = ASNMTAP::Asnmtap::Plugins->new (
  _programName        => 'check_template-WebTransact-XML-Cactus-parser.pl',
  _programDescription => "WebTransact XML Cactus parser HTTP/HTTPS plugin template for testing the '$APPLICATION'",
  _programVersion     => '3.002.003',
  _programGetOptions  => ['filename|f:s', 'environment|e:s', 'proxy:s', 'timeout|t:i', 'trendline|T:i'],
  _timeout            => 300,
  _debug              => 0);

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

use ASNMTAP::Asnmtap::Plugins::XML qw(&extract_XML);

my $filename = $objectPlugins->getOptionsArgv ('filename') ? $objectPlugins->getOptionsArgv ('filename') : undef;

my $httpNotByFile = ( defined $filename ) ? 0 : 1;

# Modify Cactus XML testcontainer data  - - - - - - - - - - - - - - - - -

use constant HEADER       => '<?xml version="1.0" encoding="UTF-8" ?>';
use constant FOOTER       => '</testsuites>';

use constant TESTSUITE    => 'be.asnmtap.common.businessservices.service.TestAsnmtapServiceRemote';
use constant URL          => 'http://asnmtap:7205/ripservice.1.4.2.cactus/ServletTestRunner';
use constant EXP          => '.';
use constant EXP_FAULT    => '>>>NIHIL<<<';
use constant MSG          => '.';
use constant MSG_FAULT    => '.';

# Parameters for the example: ServletTestRunner.xml, modify them!!!

my $timeTestsuiteWarning  = 30;
my $timeTestsuiteCritical = 45;

# - - - - - - - - - - - - -  [TESTCASE, WARNING, CRITICAL],
my @testcase              = (['testHeavyLoad1', 10, 20],
                             ['testHeavyLoad2', 10, 20]);
						
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

use constant TESTCASE => 0;
use constant WARNING  => 1;
use constant CRITICAL => 2;

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Start plugin  - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

my ($returnCode, $result, $xml);

my $debug = $objectPlugins->getOptionsValue ('debug');

if ($httpNotByFile) {
  use ASNMTAP::Asnmtap::Plugins::WebTransact;

  my @URLS = (
    { Method => 'GET',  Url => URL, Qs_var => [], Qs_fixed => [suite => TESTSUITE], Exp => EXP, Exp_Fault => EXP_FAULT, Msg => MSG, Msg_Fault => MSG_FAULT },
  );

  my $objectWebTransact = ASNMTAP::Asnmtap::Plugins::WebTransact->new ( \$objectPlugins, \@URLS );

  $returnCode = $objectWebTransact->check ( { } );
  undef $objectWebTransact;
  $objectPlugins->exit (7) if ( $returnCode );

  $result = $objectPlugins->pluginValue ('result');
  $filename = undef;
} else { # for testing, you can use the file 'ServletTestRunner.xml' instead of using HTTP/HTTPS access
  $result = undef;
}

if ( $debug >= 2 ) {
  print "\n<header>\n" . HEADER . "\n</header>\n";
  print "<in>\n$result\n</in>\n" if (defined $result);
}

if ( defined $result )  {
  ($returnCode, $xml) = extract_XML ( asnmtapInherited => \$objectPlugins, resultXML => $result, headerXML => HEADER, footerXML => FOOTER );
} elsif ( defined $filename ) {
  ($returnCode, $xml) = extract_XML ( asnmtapInherited => \$objectPlugins, filenameXML => $filename, headerXML => HEADER, footerXML => FOOTER );



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