4 use Test::More 'no_plan';
14 use_ok 'Text::Tradition::Directory';
16 my $fh = File::Temp->new();
17 my $file = $fh->filename;
19 my $dsn = "dbi:SQLite:dbname=$file";
21 my $t = Text::Tradition->new(
24 'file' => 't/data/simple.txt',
28 my $d = Text::Tradition::Directory->new( 'dsn' => $dsn,
29 'extra_args' => { 'create' => 1 } );
30 is( ref $d, 'Text::Tradition::Directory', "Got directory object" );
32 my $scope = $d->new_scope;
33 $uuid = $d->save( $t );
34 ok( $uuid, "Saved test tradition" );
36 my $s = $t->add_stemma( dotfile => 't/data/simple.dot' );
37 ok( $d->save( $t ), "Updated tradition with stemma" );
38 is( $d->tradition( $uuid ), $t, "Correct tradition returned for id" );
39 is( $d->tradition( $uuid )->stemma(0), $s, "...and it has the correct stemma" );
42 } catch( Text::Tradition::Error $e ) {
43 is( $e->ident, 'database error', "Got exception trying to save stemma directly" );
44 like( $e->message, qr/Cannot directly save non-Tradition object/,
45 "Exception has correct message" );
48 my $nt = Text::Tradition->new(
50 'input' => 'CollateX',
51 'file' => 't/data/Collatex-16.xml',
53 is( ref( $nt ), 'Text::Tradition', "Made new tradition" );
56 my $f = Text::Tradition::Directory->new( 'dsn' => $dsn );
57 my $scope = $f->new_scope;
58 is( scalar $f->tradition_ids, 1, "Directory index has our tradition" );
59 my $nuuid = $f->save( $nt );
60 ok( $nuuid, "Stored second tradition" );
61 is( scalar $f->tradition_ids, 2, "Directory index has both traditions" );
62 my $tf = $f->tradition( $uuid );
63 is( $tf->name, $t->name, "Retrieved the tradition from a new directory" );
64 my $sid = $f->object_to_id( $tf->stemma(0) );
66 $f->tradition( $sid );
67 } catch( Text::Tradition::Error $e ) {
68 is( $e->ident, 'database error', "Got exception trying to fetch stemma directly" );
69 like( $e->message, qr/not a Text::Tradition/, "Exception has correct message" );
73 } catch( Text::Tradition::Error $e ) {
74 is( $e->ident, 'database error', "Got exception trying to delete stemma directly" );
75 like( $e->message, qr/Cannot directly delete non-Tradition object/,
76 "Exception has correct message" );
79 ok( !$f->exists( $uuid ), "Object is deleted from DB" );
80 ok( !$f->exists( $sid ), "Object stemma also deleted from DB" );
81 is( scalar $f->tradition_ids, 1, "Object is deleted from index" );
85 skip 'Have yet to figure out garbage collection', 1;
86 my $g = Text::Tradition::Directory->new( 'dsn' => $dsn );
87 my $scope = $g->new_scope;
88 is( scalar $g->tradition_ids, 1, "Now one object in new directory index" );