Attean

 view release on metacpan or  search on metacpan

t/simple-eval.t  view on Meta::CPAN

			q(a a),
			q(a b),
			q(a c),
			q(b b),
			q(b c),
			q(c c),
		);
		my @got;
		foreach my $r (@rows) {
			my $str	= join(' ', map { $r->value($_)->value } qw(X Y));
			$str	=~ s#http://example.org/##g;
			push(@got, $str);
		}
		is_deeply([sort @got], \@expected);
# 		while (my $q = $iter->next) { say $q->as_string }
	}
	
# 	{
# 		# pp12
# 		my $p1	= Attean::Algebra::PredicatePath->new( predicate => iri('http://www.example.org/schema#p1') );
# 		my $p2	= Attean::Algebra::PredicatePath->new( predicate => iri('http://www.example.org/schema#p2') );
# 		my $seq	= Attean::Algebra::SequencePath->new( children => [$p1, $p2] );
# 		my $pp	= Attean::Algebra::OneOrMorePath->new( children => [$seq] );
# 		my $path	= Attean::Algebra::Path->new( subject => iri('http://www.example.org/instance#a'), path => $pp, object => variable('x') );
# 		my $e		= Attean::SimpleQueryEvaluator->new( model => $model, default_graph => iri('pp11') );
# 		my $iter	= $e->evaluate($path, iri('pp11'));
# 		while (my $q = $iter->next) { say $q->as_string }
# 	}

	{
		note('Service');
		my $ua		= Test::LWP::UserAgent->new();
		$ua->map_response(qr{example.org/sparql}, HTTP::Response->new('200', 'OK', ['Content-Type' => 'application/sparql-results+xml'], <<'XML'));
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
  <head>
	<variable name="s"/>
	<variable name="p"/>
	<variable name="o"/>
  </head>
  <results>
	<result>
		<binding name="s"><uri>http://example.org/s4</uri></binding>
		<binding name="p"><uri>http://example.org/p</uri></binding>
		<binding name="o"><literal datatype="http://www.w3.org/2001/XMLSchema#integer">4</literal></binding>
	</result>
	<result>
		<binding name="s"><uri>http://example.org/s3</uri></binding>
		<binding name="p"><uri>http://example.org/p</uri></binding>
		<binding name="o"><literal datatype="http://www.w3.org/2001/XMLSchema#integer">3</literal></binding>
	</result>
  </results>
</sparql>
XML
		my $g		= iri('g');
		my $ep		= iri('http://example.org/sparql');
		my $e		= Attean::SimpleQueryEvaluator->new( model => $model, default_graph => $g, user_agent => $ua );
		my $t		= triplepattern(variable('s'), variable('p'), variable('o'));
		my $bgp		= Attean::Algebra::BGP->new( triples => [$t] );
		my $algebra	= Attean::Algebra::Service->new(
			endpoint => $ep,
			children => [$bgp],
		);
		my $iter	= $e->evaluate($algebra, $g);
		my @results	= $iter->elements;
		is(scalar(@results), 2, 'expected result count');
		my @objects	= sort { $a <=> $b } map { $_->value('o')->value } @results;
		is_deeply(\@objects, [3,4], 'expected values');
	}
}

{
	my $store	= Attean->get_store('Memory')->new();
	my $model	= Attean::MutableQuadModel->new( store => $store );
	
	my $graph	= Attean::IRI->new('http://example.org/graph');
	{
		my $data	= <<'END';
@prefix test: <http://ontologi.es/doap-tests#> .
@prefix deps: <http://ontologi.es/doap-deps#>.
@prefix httph:<http://www.w3.org/2007/ont/httph#> .
@prefix http: <http://www.w3.org/2007/ont/http#> .
@prefix nfo:  <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#> .
@prefix :     <http://example.org/test#> .


:test_list a test:FixtureTable ;
    test:fixtures :public_writeread_unauthn_alt .


:public_writeread_unauthn_alt a test:AutomatedTest ;
    test:purpose "More elaborate HTTP vocab for PUT then GET test"@en ;
    test:test_script <http://example.org/httplist#http_req_res_list_unauthenticated> ;
    test:params [
        test:steps (
            [
                test:request :public_writeread_unauthn_alt_put_req ;
                test:response_assertion :public_writeread_unauthn_alt_put_res
            ]
            [
                test:request :public_writeread_unauthn_alt_get_req ;
                test:response_assertion :public_writeread_unauthn_alt_get_res
            ]
        )
    ] .
END
		$model->load_triples('turtle', $graph, $data);
	}
	
	my $active_graph	= $graph;
	my $test	= URI::Namespace->new('http://ontologi.es/doap-tests#');
	my $b	= $model->objects(undef, iri('http://www.w3.org/1999/02/22-rdf-syntax-ns#first'))->next();
	my $t1	= triplepattern($b, iri($test->request->as_string), variable('request'));
	my $t2	= triplepattern($b, iri($test->response_assertion->as_string), variable('response_assertion'));
	my $bgp	= bgp($t1, $t2);

	{
		my $e	= Attean::SimpleQueryEvaluator->new(
			model => $model,
			default_graph => $graph,
			ground_blanks => 0



( run in 0.532 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )