|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use Modern::Perl; |
| 4 |
use Test::More tests => 4; |
| 5 |
use Test::Exception; |
| 6 |
use YAML; |
| 7 |
use File::Temp qw/ tempfile /; |
| 8 |
|
| 9 |
use C4::Context; |
| 10 |
|
| 11 |
#Make a temporary configuration file for the triplestore |
| 12 |
my ($fh, $filename) = tempfile(undef, UNLINK => 1); |
| 13 |
my $temp_config = { |
| 14 |
models => { |
| 15 |
test => { |
| 16 |
module => 'RDF::Trine::Store::SPARQL', |
| 17 |
url => 'http://localhost/example/rdf', |
| 18 |
realm => undef, |
| 19 |
username => undef, |
| 20 |
password => undef, |
| 21 |
} |
| 22 |
} |
| 23 |
}; |
| 24 |
|
| 25 |
#Tell C4::Context to use the temporary configuration file as the triplestore_config |
| 26 |
my $context = $C4::Context::context; |
| 27 |
$context->{config}->{triplestore_config} = $filename; |
| 28 |
|
| 29 |
subtest 'success' => sub { |
| 30 |
YAML::DumpFile($filename, $temp_config); |
| 31 |
|
| 32 |
my $context_object = C4::Context->new(); |
| 33 |
my $triplestore = $context_object->triplestore("test"); |
| 34 |
is(ref $triplestore, 'RDF::Trine::Model', 'C4::Context->new()->triplestore returns RDF::Trine::Model if module equals RDF::Trine::Store::SPARQL'); |
| 35 |
}; |
| 36 |
|
| 37 |
subtest 'missing url' => sub { |
| 38 |
#Reset triplestore context |
| 39 |
delete $context->{triplestore}->{test}; |
| 40 |
|
| 41 |
my $url = delete $temp_config->{models}->{test}->{url}; |
| 42 |
YAML::DumpFile($filename, $temp_config); |
| 43 |
|
| 44 |
my $context_object = C4::Context->new(); |
| 45 |
my $triplestore = $context_object->triplestore("test"); |
| 46 |
is($triplestore, undef, 'C4::Context->new()->triplestore returns undef if missing url for SPARQL store'); |
| 47 |
|
| 48 |
#Restore url for other tests |
| 49 |
$temp_config->{url} = $url; |
| 50 |
}; |
| 51 |
|
| 52 |
subtest 'bad module' => sub { |
| 53 |
#Reset triplestore context |
| 54 |
delete $context->{triplestore}->{test}; |
| 55 |
|
| 56 |
$temp_config->{module} = 'Local::RDF::Bad::Module'; |
| 57 |
YAML::DumpFile($filename, $temp_config); |
| 58 |
|
| 59 |
my $context_object = C4::Context->new(); |
| 60 |
my $triplestore = $context_object->triplestore("test"); |
| 61 |
is($triplestore, undef, 'C4::Context->new()->triplestore returns undef if module equals Local::RDF::Bad::Module'); |
| 62 |
}; |
| 63 |
|
| 64 |
subtest 'missing model name' => sub { |
| 65 |
my $context_object = C4::Context->new(); |
| 66 |
dies_ok { $context_object->triplestore } 'C4::Context::triplestore() method dies if no model name provided'; |
| 67 |
}; |