7 test_begin(-tests => 23);
9 use_ok('Bio::DB::BioSQL::DBAdaptor');
10 use_ok('Bio::BioEntry');
11 use_ok('Bio::DB::Persistent::BioNamespace');
14 my $biosql = DBTestHarness->new("biosql");
17 my $dbc = $biosql->get_DBContext();
20 my $db = $dbc->dbadaptor();
21 isa_ok $db,"Bio::DB::DBAdaptorI";
22 isa_ok $db,"Bio::DB::BioSQL::DBAdaptor";
25 my $dbh = $dbc->dbi()->new_connection($dbc);
27 my $rc = $dbh->ping();
28 ok ($rc && ($rc ne '0 but true'));
30 # test that the -dsn option works as advertised
31 my $dsn = $dbc->dbi()->build_dsn($dbc); # that's what's used for connecting
32 my $db2 = Bio::DB::BioDB->new(-database => "biosql", -dsn => $dsn);
33 my $dbc2 = $db2->dbcontext;
34 is ($dbc2->dbi->build_dsn($dbc2), $dsn);
35 $dbc2->host("i.dont.exist.com");
37 is ($dbc2->dbi->build_dsn($dbc2), $dsn); # dsn is to be taken verbatim
39 # test the dsn parsing results
40 $dbc2 = Bio::DB::SimpleDBContext->new(-dsn => $dsn);
41 is ($dbc2->driver, $dbc->driver);
42 is ($dbc2->dbname, $dbc->dbname);
43 is ($dbc2->host, $dbc->host);
44 is ($dbc2->port, $dbc->port);
46 # test that transaction control is active by trying to roll back
47 my $ns = Bio::BioEntry->new(-namespace => "__dummy__", -authority => "nobody");
48 my $adp = $db->get_object_adaptor("BioNamespace");
49 # we need to disable caching, or otherwise it will bite us
50 $adp->caching_mode(0);
51 my $pns = Bio::DB::Persistent::BioNamespace->new(-identifiable => $ns,
53 is ($pns->namespace, $ns->namespace);
54 is ($pns->authority, $ns->authority);
55 # try to find it - this should fail
56 my $dbns = $adp->find_by_unique_key($pns);
58 warn("found __dummy__ namespace - leftover from previously aborted test?");
61 # we need to commit here or otherwise we can't safely test for rollback
65 # now we should find it - sanity check
66 $dbns = Bio::DB::Persistent::BioNamespace->new(-identifiable => $ns);
67 $dbns = $adp->find_by_unique_key($dbns);
69 is ($dbns->primary_key, $pns->primary_key);
70 is ($dbns->namespace, $pns->namespace);
73 $dbns = $adp->find_by_unique_key($pns);
76 warn("your RDBMS does not have transactions enabled - please fix this\n");
79 # and the namespace should be gone