Applied patch sent in by Daniel Westermann-Clark on Oct 11 2006.
[dbsrgits/SQL-Translator.git] / t / 21xml-xmi-parser.t
index c0bdab2..558252e 100644 (file)
@@ -5,23 +5,23 @@
 # `make test'. After `make install' it should work as `perl test.pl'
 
 #
-# basic.t
-# -------
-# Tests that;
+# Tests basic functionality and the default xmi2schema
 #
 
 use strict;
-use Test::More;
-use Test::Exception;
-
-use strict;
+use FindBin qw/$Bin/;
 use Data::Dumper;
+
+# run test with -d for debug
 my %opt;
 BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
 use constant DEBUG => (exists $opt{d} ? 1 : 0);
-local $SIG{__WARN__} = sub { diag "[warn] ", @_; };
 
-use FindBin qw/$Bin/;
+use Test::More;
+use Test::Exception;
+use Test::SQL::Translator qw(maybe_plan);
+use SQL::Translator;
+use SQL::Translator::Schema::Constants;
 
 # Usefull test subs for the schema objs
 #=============================================================================
@@ -79,55 +79,66 @@ sub test_table {
 # Testing 1,2,3,..
 #=============================================================================
 
-plan tests => 85;
-
-use SQL::Translator;
-use SQL::Translator::Schema::Constants;
+maybe_plan(103,
+    'SQL::Translator::Parser::XML::XMI',
+    'SQL::Translator::Producer::MySQL');
 
 my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi";
-# Parse the test XML schema
+die "Can't find test schema $testschema" unless -e $testschema;
+
 my $obj;
 $obj = SQL::Translator->new(
-    debug          => DEBUG,
-    show_warnings  => 1,
-    add_drop_table => 1,
-);
-die "Can't find test schema $testschema" unless -e $testschema;
-my $sql = $obj->translate(
+    filename => $testschema,
     from     => 'XML-XMI',
     to       => 'MySQL',
-    filename => $testschema,
+    debug          => DEBUG,
+    show_warnings  => 1,
 );
+my $sql = $obj->translate;
 print $sql if DEBUG;
-#print "Debug: translator", Dumper($obj) if DEBUG;
-#print "Debug: schema", Dumper($obj->schema) if DEBUG;
 
 #
-# Test the schema objs generted from the XML
+# Test the schema
 #
 my $scma = $obj->schema;
 my @tblnames = map {$_->name} $scma->get_tables;
-is_deeply( \@tblnames, [qw/Foo PrivateFoo Recording Track/], "tables");
+is_deeply( \@tblnames, [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/]
+    ,"tables");
+
+#
+# Tables
 #
 # Foo
 #
 test_table( $scma->get_table("Foo"),
     name => "Foo",
     fields => [
-    {
-        name => "fooid",
-        data_type => "int",
-        default_value => undef,
-        is_nullable => 1,
-        is_primary_key => 1,
-    },
-    {
-        name => "name",
-        data_type => "varchar",
-        default_value => "",
-        is_nullable => 1,
-    } ],
+        {
+            name => "fooid",
+            data_type => "int",
+            default_value => undef,
+            is_nullable => 1,
+            is_primary_key => 1,
+        },
+        {
+            name => "name",
+            data_type => "varchar",
+            default_value => "",
+            is_nullable => 1,
+        },
+        {
+            name => "protectedname",
+            data_type => "varchar",
+            default_value => undef,
+            is_nullable => 1,
+        },
+        {
+            name => "privatename",
+            data_type => "varchar",
+            default_value => undef,
+            is_nullable => 1,
+        },
+    ],
 );
 
 #