File: sparql11-federation.t

package info (click to toggle)
librdf-query-perl 2.919-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,580 kB
  • sloc: perl: 30,628; javascript: 131; sh: 13; makefile: 2
file content (97 lines) | stat: -rw-r--r-- 2,733 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;

use lib qw(. t);
BEGIN { require "models.pl"; }

my @files	= map { "data/$_" } qw(foaf.xrdf);
my @models	= test_models( @files );

my $tests	= scalar(@models) * 10;
plan tests => $tests;

use RDF::Query;

################################################################################
# Log::Log4perl::init( \q[
# 	log4perl.category.rdf.query.costmodel          = TRACE, Screen
# 	
# 	log4perl.appender.Screen         = Log::Log4perl::Appender::Screen
# 	log4perl.appender.Screen.stderr  = 0
# 	log4perl.appender.Screen.layout = Log::Log4perl::Layout::SimpleLayout
# ] );
################################################################################

foreach my $model (@models) {
	print "\n#################################\n";
	print "### Using model: $model\n\n";
	
	
	{
		print "# VALUES (one var)\n";
		my $query	= RDF::Query->new( <<"END", { lang => 'sparql11' } );
			PREFIX foaf: <http://xmlns.com/foaf/0.1/>
			SELECT ?p ?name
			WHERE {
				?p a foaf:Person ; foaf:firstName ?name .
			}
			VALUES ?name { "Gregory" "Gary" }
END
		my $count	= 0;
		my $stream	= $query->execute( $model );
		isa_ok( $stream, 'RDF::Trine::Iterator' );
		while (my $d = $stream->next) {
			isa_ok( $d, 'HASH' );
			if ($d->{p}->isa('RDF::Trine::Node::Resource')) {
				is( $d->{p}->uri_value, 'http://kasei.us/about/foaf.xrdf#greg', 'expected (URI) node' );
			} elsif ($d->{p}->isa('RDF::Trine::Node::Blank')) {
				my $name	= $d->{name}->literal_value;
				is( $name, 'Gary', 'expected (blank) node' );
			} else {
				fail();
			}
			$count++;
		}
		is( $count, 2, 'expected result count' );
	}
	
	{
		print "# VALUES (two var)\n";
		my $query	= RDF::Query->new( <<"END", undef, undef, 'sparql11' );
			PREFIX foaf: <http://xmlns.com/foaf/0.1/>
			SELECT ?p
			WHERE {
				?p a foaf:Person ; foaf:name ?name ; foaf:mbox_sha1sum ?email .
			}
			VALUES (?name ?email) { ("Gregory Todd Williams" "2057969209f1dfdad832de387cf13e6ff8c93b12") }
END
		my $count	= 0;
		my $stream	= $query->execute( $model );
		isa_ok( $stream, 'RDF::Trine::Iterator' );
		while (my $d = $stream->next) {
			$count++;
		}
		is( $count, 0, 'expected result count' );
	}

	{
		print "# VALUES with UNDEF\n";
		my $query	= RDF::Query->new( <<"END", undef, undef, 'sparql11' );
			PREFIX foaf: <http://xmlns.com/foaf/0.1/>
			SELECT *
			WHERE {
				?p a foaf:Person ; foaf:name ?name ; foaf:schoolHomepage ?school .
			}
			VALUES (?name ?school) { (UNDEF <http://www.samohi.smmusd.org/>) }
END
		my $count	= 0;
		my $stream	= $query->execute( $model );
		isa_ok( $stream, 'RDF::Trine::Iterator' );
		while (my $d = $stream->next) {
			$count++;
		}
		is( $count, 4, 'expected result count' );
	}
}