NoSQL-PL2SQL-Simple
view release on metacpan or search on metacpan
t/NoSQL-PL2SQL-Simple.t view on Meta::CPAN
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl NoSQL-PL2SQL-Simple.t'
#########################
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 56;
BEGIN { use_ok('XML::Parser::Nodes') };
BEGIN { use_ok('NoSQL::PL2SQL::DBI::SQLite') };
BEGIN { use_ok('NoSQL::PL2SQL::DBI') };
BEGIN { use_ok('NoSQL::PL2SQL') };
BEGIN { use_ok('NoSQL::PL2SQL::Simple') };
#########################
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.
sub testpath {
my @path = split m|/|, ":$0" ;
pop @path ;
$path[0] =~ s/^:// ;
return join '/', @path, @_ ;
}
sub XML::Parser::Nodes::asobject {
my $node = shift ;
my %data = map { $_->[0], $_->[1]->gettext } $node->childnodes ;
return \%data ;
}
do {
package TQIS::DataSource ;
use base qw( NoSQL::PL2SQL::Simple ) ;
my @dsn = () ;
sub dsn {
return @dsn if @dsn ;
push @dsn, NoSQL::PL2SQL::DBI::SQLite->new('objectdata') ;
push @dsn, $dsn[0]->table('querydata') ;
$dsn[1]->connect( 'dbi:SQLite:dbname=:memory:', '', '') ;
return @dsn ;
}
package TQIS::Employees ;
use base qw( TQIS::DataSource ) ;
package TQIS::Contacts ;
use base qw( TQIS::DataSource ) ;
} ;
## Test data source subclass TQIS::Datasource
my @dsn = TQIS::Employees->dsn ;
is( scalar @dsn => 2 ) ;
is( $dsn[0]->table => 'objectdata' ) ;
@dsn = TQIS::Employees->dsn ;
TQIS::DataSource->loadschema ;
## Test loadschema(). Ensure it's called independently on separate
## data sources. Throws an error, otherwise.
my $testdsn = new NoSQL::PL2SQL::DBI::SQLite 'objecttest' ;
$testdsn->connect( 'dbi:SQLite:dbname=:memory:', '', '') ;
NoSQL::PL2SQL::Simple->loadschema( $testdsn, 'querytest' ) ;
## I wanted to test this at a reasonable scale. So around 17K records
## are loaded from a MySQL test data set.
my $testdatafn = testpath( 'employees.xml' ) ;
exit unless -f $testdatafn ;
my $nodes = new XML::Parser::Nodes $testdatafn ;
my @staff = map { $_->asobject }
$nodes->childnode('testdata')->childnode('employees') ;
my @cent = splice @staff, -100, 100 ;
## Data definitions
( run in 1.290 second using v1.01-cache-2.11-cpan-71847e10f99 )