AtteanX-Endpoint

 view release on metacpan or  search on metacpan

t/gsp.t  view on Meta::CPAN

use Test::More;
use Test::Exception;

use v5.14;
use warnings;
no warnings 'redefine';

use Attean::RDF;
use AtteanX::Endpoint;
use Test::WWW::Mechanize::PSGI;

sub mech_for_nquads {
	my $allow_update	= shift;
	my $nquads			= shift;
	my $config			= {
		endpoint	=> {
			service_description => {},
			html				=> {},
			load_data			=> 0,
			update				=> $allow_update,
		}
	};

	my $store	= Attean->get_store('Memory')->new();
	my $model	= Attean::MutableQuadModel->new( store => $store );
	my $graph	= iri('http://example.org/graph');
	$model->load_triples('nquads', $graph => $nquads);


	my $end		= AtteanX::Endpoint->new( model => $model, conf => $config, graph => $graph );
	my $app	= sub {
		my $env 	= shift;
		my $req 	= Plack::Request->new($env);
		my $resp	= $end->run( $req );
		return $resp->finalize;
	};

	my $mech	= Test::WWW::Mechanize::PSGI->new(app => $app);
	return $mech;
}


my $mech	= mech_for_nquads(1, <<"END");
_:b <num> "000" .
_:b <num> "123" <http://example.org/graph1> .
_:b <num> "787" <http://example.org/graph2> .
<doc> <name> "My Document" <http://example.org/graph3> .
END

subtest 'HEAD default graph' => sub {
	$mech->head_ok('/gsp?default', {Accept => 'text/turtle'});
	ok( $mech->success );
	is( $mech->ct, 'text/turtle', 'Is text/turtle' );
	is(length($mech->content(raw => 1)), 0, 'empty body');
};

subtest 'GET default graph' => sub {
	$mech->get('/gsp?default', Accept => 'text/turtle');
	ok( $mech->success );
	is( $mech->ct, 'text/turtle', 'Is text/turtle' );
	$mech->content_like(qr#"000"#);
	$mech->content_unlike(qr#"123"#);
	$mech->content_unlike(qr#"My Document"#);
};

subtest 'GET named graph' => sub {
	$mech->get('/gsp?graph=http%3A%2F%2Fexample.org%2Fgraph2', Accept => 'text/turtle');
	ok( $mech->success );
	is( $mech->ct, 'text/turtle', 'Is text/turtle' );
	$mech->content_like(qr#"787"#);
	$mech->content_unlike(qr#"123"#);
	$mech->content_unlike(qr#"My Document"#);
};

subtest 'PUT named graph' => sub {
	$mech->put('/gsp?graph=http%3A%2F%2Fexample.org%2Fgraph2', 'Content-Type' => 'text/turtle', content => '<s> <p> "new content" .');



( run in 0.917 second using v1.01-cache-2.11-cpan-5a3173703d6 )