| 1 | =head1 NAME | ||
| 2 | |||
| 3 | Test::AtteanX::Endpoint - Shared code for testing AtteanX::Endpoint | ||
| 4 | |||
| 5 | =head1 VERSION | ||
| 6 | |||
| 7 | This document describes Test::AtteanX::Endpoint version 0.004 | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | use Test::AtteanX::Endpoint; | ||
| 12 | |||
| 13 | =head1 DESCRIPTION | ||
| 14 | |||
| 15 | The Test::AtteanX::Endpoint class provides APIs for use in testing the | ||
| 16 | AtteanX::Endpoint module. | ||
| 17 | |||
| 18 | =head1 METHODS | ||
| 19 | |||
| 20 | =over 4 | ||
| 21 | |||
| 22 | =cut | ||
| 23 | |||
| 24 | |||
| 25 | use v5.14; | ||
| 26 | use warnings; | ||
| 27 | |||
| 28 | package Test::AtteanX::Endpoint { | ||
| 29 | our $VERSION = "0.004"; | ||
| 30 | |||
| 31 | use Attean::RDF; | ||
| 32 | use AtteanX::Endpoint; | ||
| 33 | use Test::WWW::Mechanize::PSGI; | ||
| 34 | use Test::AtteanX::Endpoint; | ||
| 35 | |||
| 36 | sub mech_for_nquads { | ||
| 37 | my $class = shift; | ||
| 38 | my $nquads = pop; | ||
| 39 | my %args = @_; | ||
| 40 | my $allow_update = delete $args{'update'} // 0; | ||
| 41 | my $gsp_path = delete $args{'gsp_path'}; | ||
| 42 | my $graph = delete $args{'graph'} // iri('http://example.org/graph'); | ||
| 43 | my $config = { | ||
| 44 | endpoint => { | ||
| 45 | service_description => {}, | ||
| 46 | gsp_path => $gsp_path, | ||
| 47 | html => {}, | ||
| 48 | load_data => 0, | ||
| 49 | update => $allow_update, | ||
| 50 | } | ||
| 51 | }; | ||
| 52 | |||
| 53 | if (defined($gsp_path)) { | ||
| 54 | $config->{endpoint}{gsp_path} = $gsp_path; | ||
| 55 | } | ||
| 56 | |||
| 57 | my $store = Attean->get_store('Memory')->new(); | ||
| 58 | my $model = Attean::MutableQuadModel->new( store => $store ); | ||
| 59 | $model->load_triples('nquads', $graph => $nquads); | ||
| 60 | |||
| 61 | my $end = AtteanX::Endpoint->new( model => $model, conf => $config, graph => $graph ); | ||
| 62 | my $app = sub { | ||
| 63 | my $env = shift; | ||
| 64 | my $req = Plack::Request->new($env); | ||
| 65 | my $resp = $end->run( $req ); | ||
| 66 | return $resp->finalize; | ||
| 67 | }; | ||
| 68 | |||
| 69 | my $mech = Test::WWW::Mechanize::PSGI->new(app => $app); | ||
| 70 | return $mech; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | 1; | ||
| 75 | |||
| 76 | |||
| 77 | __END__ |