| 1 | # $Id: 621-output-get-schema-create-many-to-many-uml.t,v 1.1 2011/02/15 20:15:54 aff Exp $ |
| 2 | |
| 3 | use warningsscip-perl cpan Parse-Dia-SQL 0.31 warnings/; |
| 4 | use strictscip-perl cpan Parse-Dia-SQL 0.31 strict/; |
| 5 | |
| 6 | use Data::Dumperscip-perl cpan Parse-Dia-SQL 0.31 Data/Dumper/; |
| 7 | use Test::Morescip-perl cpan Parse-Dia-SQL 0.31 Test/More/; |
| 8 | use Test::Exceptionscip-perl cpan Parse-Dia-SQL 0.31 Test/Exception/; |
| 9 | use File::Spec::Functionsscip-perl cpan Parse-Dia-SQL 0.31 File/Spec/Functions/; |
| 10 | use libscip-perl cpan Parse-Dia-SQL 0.31 lib/ catdir qw ( blib lib ); |
| 11 | |
| 12 | planscip-perl cpan Parse-Dia-SQL 0.31 main/plan(). tests => 16; |
| 13 | |
| 14 | use libscip-perl cpan Parse-Dia-SQL 0.31 lib/ q{lib}; |
| 15 | use_okscip-perl cpan Parse-Dia-SQL 0.31 main/use_ok(). ('Parse::Dia::SQL'); |
| 16 | use_okscip-perl cpan Parse-Dia-SQL 0.31 main/use_ok(). ('Parse::Dia::SQL::Output'); |
| 17 | use_okscip-perl cpan Parse-Dia-SQL 0.31 main/use_ok(). ('Parse::Dia::SQL::Output::DB2'); |
| 18 | |
| 19 | # 1. parse input |
| 20 | my $diasql = Parse::Dia::SQL->newscip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/new().( file => catfilescip-perl cpan Parse-Dia-SQL 0.31 main/catfile().(qw(t data many_to_many.dia)), db => 'db2', uml => 1 ); |
| 21 | isa_okscip-perl cpan Parse-Dia-SQL 0.31 main/isa_ok().($diasql, q{Parse::Dia::SQL}, q{Expect a Parse::Dia::SQL object}); |
| 22 | isscip-perl cpan Parse-Dia-SQL 0.31 main/is().($diasql->convertscip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/convert().(), 1, q{Expect convert to return 1}); |
| 23 | |
| 24 | my $classes = $diasql->get_classes_refscip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/get_classes_ref().(); |
| 25 | my $associations = $diasql->get_associations_refscip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/get_associations_ref().(); |
| 26 | my $smallpackages = $diasql->get_smallpackages_refscip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/get_smallpackages_ref().(); |
| 27 | |
| 28 | # check parsed content |
| 29 | okscip-perl cpan Parse-Dia-SQL 0.31 main/ok().(definedscip-perl cpan Parse-Dia-SQL 0.31 main/defined().($classes) && refscip-perl cpan Parse-Dia-SQL 0.31 main/ref().($classes) eq q{ARRAY} && scalarscip-perl cpan Parse-Dia-SQL 0.31 main/scalar().(@$classes), q{Non-empty array ref}); |
| 30 | okscip-perl cpan Parse-Dia-SQL 0.31 main/ok().(definedscip-perl cpan Parse-Dia-SQL 0.31 main/defined().($associations) && refscip-perl cpan Parse-Dia-SQL 0.31 main/ref().($associations) eq q{ARRAY} && scalarscip-perl cpan Parse-Dia-SQL 0.31 main/scalar().(@$associations), q{Non-empty array ref}); |
| 31 | |
| 32 | # 2. get output instance |
| 33 | my $subclass = undef; |
| 34 | lives_okscip-perl cpan Parse-Dia-SQL 0.31 main/lives_ok().(sub { $subclass = $diasql->get_output_instancescip-perl cpan Parse-Dia-SQL 0.31 Parse/Dia/SQL/get_output_instance().(); }, |
| 35 | q{get_output_instance (db2) should not die}); |
| 36 | |
| 37 | isa_okscip-perl cpan Parse-Dia-SQL 0.31 main/isa_ok().($subclass, 'Parse::Dia::SQL::Output') |
| 38 | or diagscip-perl cpan Parse-Dia-SQL 0.31 main/diag().(Dumperscip-perl cpan Parse-Dia-SQL 0.31 main/Dumper().($subclass)); |
| 39 | isa_okscip-perl cpan Parse-Dia-SQL 0.31 main/isa_ok().($subclass, 'Parse::Dia::SQL::Output::DB2') |
| 40 | or diagscip-perl cpan Parse-Dia-SQL 0.31 main/diag().(Dumperscip-perl cpan Parse-Dia-SQL 0.31 main/Dumper().($subclass)); |
| 41 | can_okscip-perl cpan Parse-Dia-SQL 0.31 main/can_ok().($subclass, 'get_schema_create'); |
| 42 | |
| 43 | # 3. schema |
| 44 | my $schema = $subclass->get_schema_createscip-perl cpan Parse-Dia-SQL 0.31 main/get_schema_create().(); |
| 45 | |
| 46 | likescip-perl cpan Parse-Dia-SQL 0.31 main/like().($schema, qr|.* |
| 47 | create \s+ table \s+ student \s* |
| 48 | .*|six, q{Check syntax for sql create table student}); |
| 49 | likescip-perl cpan Parse-Dia-SQL 0.31 main/like().($schema, qr|.* |
| 50 | create \s+ table \s+ course \s* |
| 51 | .*|six, q{Check syntax for sql create table course}); |
| 52 | likescip-perl cpan Parse-Dia-SQL 0.31 main/like().($schema, qr|.* |
| 53 | create \s+ table \s+ student_course \s* |
| 54 | .*|six, q{Check syntax for sql create table student_course}); |
| 55 | |
| 56 | # 4. associations |
| 57 | my $assoc = $subclass->get_associations_createscip-perl cpan Parse-Dia-SQL 0.31 main/get_associations_create().(); |
| 58 | |
| 59 | likescip-perl cpan Parse-Dia-SQL 0.31 main/like().($assoc, qr|.* |
| 60 | alter \s+ table \s+ student_course \s+ add \s+ constraint \s+ \w+ \s+ |
| 61 | foreign \s+ key \s+ \(ssn\) \s+ |
| 62 | references \s+ student \s+ \(ssn\) \s+ on \s+ delete \s+ cascade; \s* |
| 63 | .*|six, q{Check syntax for sql alter table add constraint rel1}); |
| 64 | likescip-perl cpan Parse-Dia-SQL 0.31 main/like().($assoc, qr|.* |
| 65 | alter \s+ table \s+ student_course \s+ add \s+ constraint \s+ \w+ \s+ |
| 66 | foreign \s+ key \s+ \(course_id\) \s+ |
| 67 | references \s+ course \s+ \(course_id\) \s+ on \s+ delete \s+ cascade; \s* |
| 68 | .*|six, q{Check syntax for sql alter table add constraint rel2}); |
| 69 | |
| 70 | __END__ |