Skip to content
Snippets Groups Projects
Commit b2d50053 authored by Graham McVicker's avatar Graham McVicker
Browse files

added tests for new AttributeAdaptor

parent 16231d85
No related branches found
No related tags found
No related merge requests found
use strict;
use lib 't';
use TestUtils qw(test_getter_setter debug);
BEGIN { $| = 1;
use Test;
plan tests => 11;
}
use MultiTestDB;
use Bio::EnsEMBL::Attribute;
our $verbose = 0;
my $multi = MultiTestDB->new;
# get a core DBAdaptor
my $db = $multi->get_DBAdaptor("core");
my $slice_adaptor = $db->get_SliceAdaptor();
my $mfa = $db->get_MiscFeatureAdaptor();
#
# Test get_AttributeAdaptor works
#
my $aa = $db->get_AttributeAdaptor();
ok($aa && ref($aa) && $aa->isa('Bio::EnsEMBL::DBSQL::AttributeAdaptor'));
# hide the contents of the attrib_type, misc_attrib, seq_region_attrib tables
# so we can test storing etc. with a clean slate
$multi->hide('core', 'misc_attrib', 'seq_region_attrib', 'attrib_type');
##############
# MiscFeature functionality tests
#
my $attrib = Bio::EnsEMBL::Attribute->new(-NAME => 'test_name',
-CODE => 'test_code',
-DESC => 'test_desc',
-VALUE => 'test_value');
my $mf = $mfa->fetch_by_dbID(1);
$aa->store_on_MiscFeature($mf, [$attrib]);
#
# make sure the misc_attrib table was updated
#
my $count = $db->db_handle->selectall_arrayref
("SELECT count(*) FROM misc_attrib " .
"WHERE misc_feature_id = 1")->[0]->[0];
ok($count == 1);
#
# make sure the attrib_type table was updated
#
$count = $db->db_handle->selectall_arrayref
("SELECT count(*) FROM attrib_type " .
"WHERE code = 'test_code'")->[0]->[0];
ok($count == 1);
#
# test that we can now retrieve this attribute
#
my @attribs = @{$aa->fetch_all_by_MiscFeature($mf)};
ok(@attribs == 1);
$attrib = $attribs[0];
ok($attrib->name eq 'test_name');
ok($attrib->code eq 'test_code');
ok($attrib->desc eq 'test_desc');
ok($attrib->value eq 'test_value');
#
# test the removal of this attribute
#
$aa->remove_from_MiscFeature($mf);
#
# make sure the misc_attrib table was updated
#
my $count = $db->db_handle->selectall_arrayref
("SELECT count(*) FROM misc_attrib " .
"WHERE misc_feature_id = 1")->[0]->[0];
ok($count == 0);
#
# make sure the attribute is no longer retrievable
#
my @attribs = @{$aa->fetch_all_by_MiscFeature($mf)};
ok(@attribs == 0);
#################
# Slice functionality tests
#
my $attrib = Bio::EnsEMBL::Attribute->new(-NAME => 'test_name2',
-CODE => 'test_code2',
-DESC => 'test_desc2',
-VALUE => 'test_value2');
my $slice = $slice_adaptor->fetch_by_region('chromosome', '20');
$aa->store_on_Slice($slice, [$attrib]);
#
# make sure the seq_region_attrib table was updated
#
my $count = $db->db_handle->selectall_arrayref
("SELECT count(*) FROM seq_region_attrib " .
"WHERE seq_region_id = ".$slice->get_seq_region_id())->[0]->[0];
ok($count == 1);
#
# make sure the attrib_type table was updated
#
$count = $db->db_handle->selectall_arrayref
("SELECT count(*) FROM attrib_type " .
"WHERE code = 'test_code2'")->[0]->[0];
ok($count == 1);
#
# test that we can now retrieve this attribute
#
my @attribs = @{$aa->fetch_all_by_Slice($slice)};
ok(@attribs == 1);
$attrib = $attribs[0];
ok($attrib->name eq 'test_name2');
ok($attrib->code eq 'test_code2');
ok($attrib->desc eq 'test_desc2');
ok($attrib->value eq 'test_value2');
#
# test the removal of this attribute
#
$aa->remove_from_Slice($slice);
#
# make sure the seq_region_attrib table was updated
#
my $count = $db->db_handle->selectall_arrayref
("SELECT count(*) FROM seq_region_attrib " .
"WHERE seq_region_id = " . $slice->get_seq_region_id())->[0]->[0];
ok($count == 0);
#
# make sure the attribute is no longer retrievable
#
my @attribs = @{$aa->fetch_all_by_Slice($slice)};
ok(@attribs == 0);
#
# try to add an attribute with an already existing code
#
$aa->store_on_Slice($slice, [$attrib]);
#
# make sure the seq_region_attrib table was updated
#
my $count = $db->db_handle->selectall_arrayref
("SELECT count(*) FROM seq_region_attrib " .
"WHERE seq_region_id = ".$slice->get_seq_region_id())->[0]->[0];
ok($count == 1);
#
# make sure the attrib_type table was updated
#
$count = $db->db_handle->selectall_arrayref
("SELECT count(*) FROM attrib_type " .
"WHERE code = 'test_code2'")->[0]->[0];
ok($count == 1);
my @attribs = @{$aa->fetch_all_by_Slice($slice)};
ok(@attribs == 1);
$multi->restore('core', 'misc_attrib', 'seq_region_attrib', 'attrib_type');
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment