1#!/usr/bin/env perl 2 3use strict; 4use lib qw(../lib lib ../t t); 5use TestUtil; 6use Test::More tests => 50; 7use Test::Exception; 8 9my ($parser); 10 11#testing load 12require_ok( 'Workflow::Config' ); 13 14#testing bad config language,SCAML it is a disgrace to mark-up 15dies_ok { Workflow::Config->new( 'SCAML' ) }; 16 17#testing good config language XML 18ok($parser = Workflow::Config->new( 'xml' )); 19 20ok(my @validtypes = $parser->get_valid_config_types()); 21is( $validtypes[0], 'action', 'Got array with valid types and action is first.'); 22 23isa_ok($parser, 'Workflow::Config'); 24 25my %config_xml = ( 26 'workflow' => ['workflow.xml', 'workflow_type.xml'], 27 'action' => ['workflow_action.xml', 'workflow_action_type.xml'], 28 'condition' => ['workflow_condition.xml', 'workflow_condition_type.xml'], 29 'validator' => ['workflow_validator.xml'], 30 'persister' => ['workflow_persister.xml'], 31 ); 32 33for my $type ( sort keys %config_xml ){ 34 for my $source ( @{$config_xml{$type}} ){ 35 36 my @config = $parser->parse( $type, $source ); 37 ok( $config[0], "Parsed a config from $source for $type."); 38 is( (ref $config[0]), 'HASH', 'Got a hashref.'); 39 } 40} 41 42$parser = Workflow::Config->new( 'xml' ); 43ok($parser->parse( 'workflow', 'workflow.xml', 'workflow_type.xml', 'workflow_action.xml', 'workflow_action_type.xml', 'workflow_condition.xml', 'workflow_condition_type.xml', 'workflow_validator.xml' )); 44 45#testing good config language Perl 46ok($parser = Workflow::Config->new( 'perl' )); 47isa_ok($parser, 'Workflow::Config'); 48 49dies_ok { $parser->parse( 'workflow', 'workflow_errorprone.perl' ) }; 50dies_ok { $parser->parse( 'workflow', 'no_such_file.perl' ) }; 51dies_ok { $parser->parse( '123_NOSUCHTYPE', 'workflow_errorprone.perl' ) }; 52 53dies_ok { Workflow::Config->parse() }; 54 55my @config = $parser->parse( 'workflow' ); 56is(scalar(@config), 0, 'forgotten file, asserting length of array returned'); 57 58my %config_perl = ( 59 'workflow' => ['workflow.perl', 'workflow_type.perl', 'workflow_type_alternate_initial.perl'], 60 'action' => ['workflow_action.perl'], 61 'condition' => ['workflow_condition.perl', 'workflow_condition_type.perl'], 62 'validator' => ['workflow_validator.perl'], 63 'persister' => ['workflow_persister.perl'], 64 ); 65 66for my $type ( sort keys %config_perl ){ 67 for my $source ( @{$config_perl{$type}} ){ 68 69 my @config = $parser->parse( $type, $source ); 70 ok( $config[0], "Parsed a config from $source for $type."); 71 is( (ref $config[0]), 'HASH', 'Got a hashref.'); 72 } 73} 74 75$parser = Workflow::Config->new( 'perl' ); 76ok($parser->parse( 'workflow', 'workflow.perl', 'workflow_action.perl', 'workflow_condition.perl', 'workflow_validator.perl' )); 77 78#testing class method parse_all_files 79my @array = Workflow::Config->parse_all_files(); 80is(scalar @array, 0, 'asserting return value'); 81 82dies_ok { Workflow::Config->parse_all_files( '123_NOSUCHTYPE', 'workflow_condition.prl' ) }; 83 84ok(Workflow::Config->parse_all_files( 'workflow', 'workflow_condition.perl', 'workflow_validator.perl' )); 85