use Test::More 'no_plan'; use Test::Exception; use Data::Dumper; use constant DONE => 1; my $AG_SERVER = $ENV{AG3_SERVER}; unless ($AG_SERVER) { ok (1, 'Tests skipped. Use "export AG3_SERVER=http://my.server:port" before running the test suite. See README for details.'); exit; } use RDF::AllegroGraph::Server3; my $server = new RDF::AllegroGraph::Server (ADDRESS => $AG_SERVER); use RDF::AllegroGraph::Catalog3; my $vienna = new RDF::AllegroGraph::Catalog3 (NAME => '/scratch', SERVER => $server); if (DONE) { use Fcntl; my $model = $server->model ('/scratch/catlitter', mode => O_CREAT); is ($model->size, 0, 'empty model'); $model->add (); is ($model->size, 0, 'still empty model'); $model->add (['', '', '']); is ($model->size, 1, 'added: model of 1'); $model->add (['', '', '']); is ($model->size, 2, 'added: model of 2'); $model->replace (['', '', '']); is ($model->size, 1, 'replaced: model of 1'); $model->add (['', '', ''], ['', '', ''], ['', '', ''], ); is ($model->size, 4, 'replaced/added: model of 4'); $model->delete (['', '', '']); is ($model->size, 3, 'deleted (fact): model of 3'); $model->delete ([undef, '', undef]); is ($model->size, 1, 'deleted (wildcard): model of 1'); $model->delete (['', undef, undef]); is ($model->size, 1, 'deleted (wildcard): model of 1'); $model->add (['', '', ''], ['', '', ''], ['', '', ''], ['', '', ''], ); $model->delete ([undef, '', undef ], [undef, undef, '' ] ); is ($model->size, 1, 'deleted (wildcard): model of 1'); $model->replace (['', '', ''], ['', '', ''], ['', '', ''], ['', '', ''], ); $model->delete ([undef, '', undef ], ['', '', '' ] ); is ($model->size, 2, 'deleted (wildcard): model of 2'); $model->disband; } if (DONE) { my $model = $server->model ('/scratch/catlitter', mode => O_CREAT); $model->replace (['', '', ''], ['', '', ''], ['', '', ''], ['', '', ''], ); my @ss = $model->match ([undef, undef, '']); is (scalar @ss, 2, 'match found kitty'); map { is ($_->[2], '', 'kitty!') } @ss; @ss = $model->match (['', undef, undef]); is (scalar @ss, 4, 'match found sacklpicker'); map { is ($_->[0], '', 'sacklpicker!') } @ss; @ss = $model->match (['', '', '']); is (scalar @ss, 2, 'match found exactly two identical'); @ss = $model->match ([undef, '', undef], [undef, '', undef]); is (scalar @ss, 4, 'match found love and hate'); $model->disband; } if (DONE) { my $model = $server->model ('/scratch/catlitter', mode => O_CREAT); $model->add (' .'); is (scalar $model->match (['', undef, undef]), 1, 'added N3: 1'); $model->add (' . .'); is (scalar $model->match (['', undef, undef]), 3, 'added N3: 3'); $model->replace (' . .'); is (scalar $model->match (['', undef, undef]), 2, 'replaced N3: 2'); $model->disband; } my $file; END { $AG_SERVER && unlink $file; } if (DONE) { use POSIX qw(tmpnam); use IO::File; do { $file = tmpnam().".n3"; } until IO::File->new ($file, O_RDWR|O_CREAT|O_EXCL); my $fh = IO::File->new ("> $file") || die "so what?"; print $fh " . . "; $fh->close; my $model = $server->model ('/scratch/catlitter', mode => O_CREAT); $model->add ('file://'. $file); is (scalar $model->match (['', undef, undef]), 2, 'added N3 file: 2'); $model->replace (('file://'. $file ) x 3); is (scalar $model->match (['', undef, undef]), 2*3, 'added N3 file: 2*3'); $model->disband; } if (DONE) { my $model = $server->model ('/scratch/catlitter', mode => O_CREAT); $model->add (['', '', ''], ['', '', ''], ['', '', ''], ['', '', ''], ); my @ss = $model->sparql ('SELECT ?s ?p ?o WHERE {?s ?p ?o .}' ); # warn Dumper \@ss; is (scalar @ss, 4, 'query: all triples'); map { is ($_->[0], '', 'sackelpicker everywhere') } @ss; map { is (scalar @$_, 3, 'triple everywhere') } @ss; @ss = $model->sparql ('SELECT ?thing WHERE { ?cat ?thing . }' ); is (scalar @ss, 2, 'query: all that hate'); map { like ($_->[0], qr//, 'tomcat/litty everywhere') } @ss; map { is (scalar @$_, 1, 'singleton everywhere') } @ss; $model->disband; } # TODO with and w/o authentication __END__