Improve error handling
Change-Id: I1f54cf9cd4770d6602f70036cf0e27c9ede8c893
diff --git a/t/corpus_info.t b/t/corpus_info.t
index 1d8290b..502ffd2 100644
--- a/t/corpus_info.t
+++ b/t/corpus_info.t
@@ -25,37 +25,37 @@
$fake_backend->pattern->defaults->{app}->log($t->app->log);
# Query passed
-$t->get_ok('/corpus2')
+$t->get_ok('/corpus')
->status_is(200)
->json_is('/documents', 11)
->json_is('/tokens', 665842)
->json_is('/sentences', 25074)
->json_is('/paragraphs', 772)
- ->json_is('/X-cached', undef)
+ ->header_isnt('X-Kalamar-Cache', 'true')
;
-$t->get_ok('/corpus2?cq=docSigle+%3D+\"GOE/AGA\"')
+$t->get_ok('/corpus?cq=docSigle+%3D+\"GOE/AGA\"')
->status_is(200)
->json_is('/documents', 5)
->json_is('/tokens', 108557)
->json_is('/sentences', 3835)
->json_is('/paragraphs', 124)
- ->json_is('/X-cached', undef)
+ ->header_isnt('X-Kalamar-Cache', 'true')
;
-$t->get_ok('/corpus2?cq=4')
+$t->get_ok('/corpus?cq=4')
->status_is(400)
->json_is('/notifications/0/1', "302: Could not parse query >>> (4) <<<.")
;
# Query passed
-$t->get_ok('/corpus2')
+$t->get_ok('/corpus')
->status_is(200)
->json_is('/documents', 11)
->json_is('/tokens', 665842)
->json_is('/sentences', 25074)
->json_is('/paragraphs', 772)
- ->json_is('/X-cached', 1)
+ ->header_is('X-Kalamar-Cache', 'true')
;
diff --git a/t/fixtures.t b/t/fixtures.t
index ba795f7..ea0047c 100644
--- a/t/fixtures.t
+++ b/t/fixtures.t
@@ -24,16 +24,18 @@
->content_like(qr!Oooops!)
;
-$t->get_ok('/search?q=[orth=das&ql=poliqarp')
+$t->get_ok('/search?q=[orth=das&ql=poliqarp&offset=0&count=25')
->status_is(400)
+ ->text_is('#error', '')
->json_is('/errors/0/0',302)
->json_is('/errors/0/1','Parantheses/brackets unbalanced.')
->json_is('/errors/1/0',302)
->json_is('/errors/1/1','Could not parse query >>> [orth=das <<<.')
;
-$t->get_ok('/search?q=baum&ql=poliqarp')
+$t->get_ok('/search?q=baum&ql=poliqarp&offset=0&count=25')
->status_is(200)
+ ->text_is('#error', '')
->json_is('/meta/count', 25)
->json_is('/meta/serialQuery', "tokens:s:Baum")
->json_is('/matches/0/docSigle', "GOE/AGI")
diff --git a/t/fixtures/fake_backend.pl b/t/fixtures/fake_backend.pl
index 89ad3c3..9f06697 100644
--- a/t/fixtures/fake_backend.pl
+++ b/t/fixtures/fake_backend.pl
@@ -36,6 +36,8 @@
my $c = shift;
my $q_name = shift;
my $file = $fixture_path->child("response_$q_name.json");
+ $c->app->log->debug("Load response from $file");
+
unless (-f $file) {
return {
status => 500,
@@ -44,6 +46,7 @@
}
}
};
+
my $response = $file->slurp;
return decode_json($response);
};
@@ -64,6 +67,8 @@
$v->optional('ql');
$v->optional('count');
$v->optional('context');
+ $v->optional('offset');
+ $v->optional('cutoff')->in(qw/true false/);
$c->app->log->debug('Receive request');
@@ -78,11 +83,16 @@
};
if (!$v->param('q')) {
- return $c->render(%{$c->load_response('no_query')});
+ return $c->render(%{$c->load_response('query_no_query')});
};
+ my @slug_base = ($v->param('q'));
+ push @slug_base, 'o' . $v->param('offset') if defined $v->param('offset');
+ push @slug_base, 'c' . $v->param('count') if defined $v->param('count');
+ push @slug_base, 'co' . $v->param('cutoff') if defined $v->param('cutoff');
+
# Get response based on query parameter
- my $response = $c->load_response(slugify($v->param('q')));
+ my $response = $c->load_response('query_' . slugify(join('_', @slug_base)));
# Check authentification
if (my $auth = $c->req->headers->header('Authorization')) {
diff --git a/t/fixtures/response_query_baum_o0_c25_cotrue.json b/t/fixtures/response_query_baum_o0_c25_cotrue.json
new file mode 100644
index 0000000..6e0921e
--- /dev/null
+++ b/t/fixtures/response_query_baum_o0_c25_cotrue.json
@@ -0,0 +1,77 @@
+{
+ "status" : 200,
+ "json" : {
+ "@context" : "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
+ "meta" : {
+ "count" : 25,
+ "startIndex" : 0,
+ "cutOff": true,
+ "authorized" : null,
+ "timeout" : 120000,
+ "context" : {
+ "left" : ["token",40],
+ "right" : ["token",40]
+ },
+ "fields" : ["pubDate","subTitle","author","pubPlace","title","textSigle","UID","ID","layerInfos","corpusSigle","docSigle","corpusID","textClass"],
+ "version" : "0.55.7",
+ "benchmark" : "0.120577834 s",
+ "totalResults" : -1,
+ "serialQuery" : "tokens:s:Baum",
+ "itemsPerPage" : 25
+ },
+ "query" : {
+ "@type" : "koral:token",
+ "wrap" : {
+ "@type" : "koral:term",
+ "layer" : "orth",
+ "key" : "Baum",
+ "match" : "match:eq",
+ "foundry" : "opennlp",
+ "rewrites" : [
+ {
+ "@type" : "koral:rewrite",
+ "src" : "Kustvakt",
+ "operation" : "operation:injection",
+ "scope" : "foundry"
+ }
+ ]
+ }
+ },
+ "matches" : [
+ {
+ "field" : "tokens",
+ "pubPlace" : "München",
+ "textSigle" : "GOE/AGI/00000",
+ "docSigle" : "GOE/AGI",
+ "corpusSigle" : "GOE",
+ "title" : "Italienische Reise",
+ "subTitle" : "Auch ich in Arkadien!",
+ "author" : "Goethe, Johann Wolfgang von",
+ "layerInfos" : "base/s=spans corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels mdp/d=rels opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans",
+ "startMore" : true,
+ "endMore" : true,
+ "snippet" : "<span class=\"context-left\"><span class=\"more\"></span>sie etwas bedeuten zu wollen und machte mit der Oberlippe eine fatale Miene. ich sprach sehr viel mit ihr durch, sie war überall zu Hause und merkte gut auf die Gegenstände. so fragte sie mich einmal, was das für ein </span><span class=\"match\"><mark>Baum</mark></span><span class=\"context-right\"> sei. es war ein schöner großer Ahorn, der erste, der mir auf der ganzen Reise zu Gesichte kam. den hatte sie doch gleich bemerkt und freute sich, da mehrere nach und nach erschienen, daß sie auch diesen Baum unterscheiden könne<span class=\"more\"></span></span>",
+ "matchID" : "match-GOE/AGI/00000-p2030-2031",
+ "UID" : 0,
+ "pubDate" : "1982"
+ },
+ {
+ "field" : "tokens",
+ "pubPlace" : "München",
+ "textSigle" : "GOE/AGI/00001",
+ "docSigle" : "GOE/AGI",
+ "corpusSigle" : "GOE",
+ "title" : "Italienische Reise",
+ "subTitle" : "Auch ich in Arkadien!",
+ "author" : "Goethe, Johann Wolfgang von",
+ "layerInfos" : "base/s=spans corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels mdp/d=rels opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans",
+ "startMore" : true,
+ "endMore" : true,
+ "snippet" : "<span class=\"context-left\"><span class=\"more\"></span>für ein Baum sei. es war ein schöner großer Ahorn, der erste, der mir auf der ganzen Reise zu Gesichte kam. den hatte sie doch gleich bemerkt und freute sich, da mehrere nach und nach erschienen, daß sie auch diesen </span><span class=\"match\"><mark>Baum</mark></span><span class=\"context-right\"> unterscheiden könne. sie gehe, sagte sie, nach Bozen auf die Messe, wo ich doch wahrscheinlich auch hinzöge. wenn sie mich dort anträfe, müsse ich ihr einen Jahrmarkt kaufen, welches ich ihr denn auch versprach. dort wollte sie auch ihre neue<span class=\"more\"></span></span>",
+ "matchID" : "match-GOE/AGI/00000-p2068-2069",
+ "UID" : 0,
+ "pubDate" : "1982"
+ }
+ ]
+ }
+}
diff --git a/t/fixtures/response_query_der_o0_c2.json b/t/fixtures/response_query_der_o0_c2.json
new file mode 100644
index 0000000..f712139
--- /dev/null
+++ b/t/fixtures/response_query_der_o0_c2.json
@@ -0,0 +1,4 @@
+{
+ "status" : 200,
+ "json" : {"@context":"http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld","meta":{"count":2,"startIndex":0,"timeout":120000,"context":{"left":["token",6],"right":["token",6]},"fields":["textSigle","author","docSigle","availability","title","pubDate","UID","corpusID","textClass","subTitle","layerInfos","ID","pubPlace","corpusSigle"],"version":"0.58.0","benchmark":"22.347006999999998 ms","totalResults":14581,"serialQuery":"tokens:s:der","itemsPerPage":2},"query":{"@type":"koral:token","wrap":{"@type":"koral:term","match":"match:eq","layer":"orth","key":"der","foundry":"opennlp","rewrites":[{"@type":"koral:rewrite","src":"Kustvakt","operation":"operation:injection","scope":"foundry"}]}},"matches":[{"field":"tokens","pubPlace":"München","textSigle":"GOE/AGI/00000","docSigle":"GOE/AGI","corpusSigle":"GOE","title":"Italienische Reise","subTitle":"Auch ich in Arkadien!","author":"Goethe, Johann Wolfgang von","availability":"ACA-NC","layerInfos":"corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels marmot/m=tokens marmot/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens","startMore":true,"endMore":true,"license":"ACA-NC","snippet":"<span class=\"context-left\"><span class=\"more\"></span>das Stift Waldsassen entgegen - köstliche Besitztümer </span><span class=\"match\"><mark>der</mark></span><span class=\"context-right\"> geistlichen Herren, die früher als andere<span class=\"more\"></span></span>","matchID":"match-GOE/AGI/00000-p161-162","pubDate":"1982","UID":0},{"field":"tokens","pubPlace":"München","textSigle":"GOE/AGI/00000","docSigle":"GOE/AGI","corpusSigle":"GOE","title":"Italienische Reise","subTitle":"Auch ich in Arkadien!","author":"Goethe, Johann Wolfgang von","availability":"ACA-NC","layerInfos":"corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels marmot/m=tokens marmot/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens","startMore":true,"endMore":true,"license":"ACA-NC","snippet":"<span class=\"context-left\"><span class=\"more\"></span>Kloster im Lande weit umher Besitzungen. </span><span class=\"match\"><mark>der</mark></span><span class=\"context-right\"> Boden ist aufgelöster Tonschiefer. der Quarz<span class=\"more\"></span></span>","matchID":"match-GOE/AGI/00000-p200-201","pubDate":"1982","UID":0}]}
+}
diff --git a/t/fixtures/response_query_der_o0_c2_cotrue.json b/t/fixtures/response_query_der_o0_c2_cotrue.json
new file mode 100644
index 0000000..a683805
--- /dev/null
+++ b/t/fixtures/response_query_der_o0_c2_cotrue.json
@@ -0,0 +1,4 @@
+{
+ "status" : 200,
+ "json" : {"@context":"http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld","meta":{"cutOff":true,"count":2,"startIndex":0,"timeout":120000,"context":{"left":["token",6],"right":["token",6]},"fields":["textSigle","author","docSigle","availability","title","pubDate","UID","corpusID","textClass","subTitle","layerInfos","ID","pubPlace","corpusSigle"],"version":"0.58.0","benchmark":"29.377798 ms","totalResults":-1,"serialQuery":"tokens:s:der","itemsPerPage":2},"query":{"@type":"koral:token","wrap":{"@type":"koral:term","match":"match:eq","layer":"orth","key":"der","foundry":"opennlp","rewrites":[{"@type":"koral:rewrite","src":"Kustvakt","operation":"operation:injection","scope":"foundry"}]}},"matches":[{"field":"tokens","pubPlace":"München","textSigle":"GOE/AGI/00000","docSigle":"GOE/AGI","corpusSigle":"GOE","title":"Italienische Reise","subTitle":"Auch ich in Arkadien!","author":"Goethe, Johann Wolfgang von","availability":"ACA-NC","layerInfos":"corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels marmot/m=tokens marmot/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens","startMore":true,"endMore":true,"license":"ACA-NC","snippet":"<span class=\"context-left\"><span class=\"more\"></span>das Stift Waldsassen entgegen - köstliche Besitztümer </span><span class=\"match\"><mark>der</mark></span><span class=\"context-right\"> geistlichen Herren, die früher als andere<span class=\"more\"></span></span>","matchID":"match-GOE/AGI/00000-p161-162","pubDate":"1982","UID":0},{"field":"tokens","pubPlace":"München","textSigle":"GOE/AGI/00000","docSigle":"GOE/AGI","corpusSigle":"GOE","title":"Italienische Reise","subTitle":"Auch ich in Arkadien!","author":"Goethe, Johann Wolfgang von","availability":"ACA-NC","layerInfos":"corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels marmot/m=tokens marmot/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens","startMore":true,"endMore":true,"license":"ACA-NC","snippet":"<span class=\"context-left\"><span class=\"more\"></span>Kloster im Lande weit umher Besitzungen. </span><span class=\"match\"><mark>der</mark></span><span class=\"context-right\"> Boden ist aufgelöster Tonschiefer. der Quarz<span class=\"more\"></span></span>","matchID":"match-GOE/AGI/00000-p200-201","pubDate":"1982","UID":0}]}
+}
diff --git a/t/fixtures/response_query_der_o2_c2.json b/t/fixtures/response_query_der_o2_c2.json
new file mode 100644
index 0000000..ae77282
--- /dev/null
+++ b/t/fixtures/response_query_der_o2_c2.json
@@ -0,0 +1,4 @@
+{
+ "status" : 200,
+ "json" : {"@context":"http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld","meta":{"count":2,"startIndex":2,"timeout":120000,"context":{"left":["token",6],"right":["token",6]},"fields":["textSigle","author","docSigle","availability","title","pubDate","UID","corpusID","textClass","subTitle","layerInfos","ID","pubPlace","corpusSigle"],"version":"0.58.0","benchmark":"31.207413 ms","totalResults":14581,"serialQuery":"tokens:s:der","itemsPerPage":2},"query":{"@type":"koral:token","wrap":{"@type":"koral:term","match":"match:eq","layer":"orth","key":"der","foundry":"opennlp","rewrites":[{"@type":"koral:rewrite","src":"Kustvakt","operation":"operation:injection","scope":"foundry"}]}},"matches":[{"field":"tokens","pubPlace":"München","textSigle":"GOE/AGI/00000","docSigle":"GOE/AGI","corpusSigle":"GOE","title":"Italienische Reise","subTitle":"Auch ich in Arkadien!","author":"Goethe, Johann Wolfgang von","availability":"ACA-NC","layerInfos":"corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels marmot/m=tokens marmot/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens","startMore":true,"endMore":true,"license":"ACA-NC","snippet":"<span class=\"context-left\"><span class=\"more\"></span>Besitzungen. der Boden ist aufgelöster Tonschiefer. </span><span class=\"match\"><mark>der</mark></span><span class=\"context-right\"> Quarz, der sich in dieser Gebirgsart<span class=\"more\"></span></span>","matchID":"match-GOE/AGI/00000-p205-206","pubDate":"1982","UID":0},{"field":"tokens","pubPlace":"München","textSigle":"GOE/AGI/00000","docSigle":"GOE/AGI","corpusSigle":"GOE","title":"Italienische Reise","subTitle":"Auch ich in Arkadien!","author":"Goethe, Johann Wolfgang von","availability":"ACA-NC","layerInfos":"corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels marmot/m=tokens marmot/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens","startMore":true,"endMore":true,"license":"ACA-NC","snippet":"<span class=\"context-left\"><span class=\"more\"></span>Boden ist aufgelöster Tonschiefer. der Quarz, </span><span class=\"match\"><mark>der</mark></span><span class=\"context-right\"> sich in dieser Gebirgsart befindet und<span class=\"more\"></span></span>","matchID":"match-GOE/AGI/00000-p207-208","pubDate":"1982","UID":0}]}
+}
diff --git a/t/fixtures/response_query_der_o2_c2_cotrue.json b/t/fixtures/response_query_der_o2_c2_cotrue.json
new file mode 100644
index 0000000..c0ef128
--- /dev/null
+++ b/t/fixtures/response_query_der_o2_c2_cotrue.json
@@ -0,0 +1,4 @@
+{
+ "status" : 200,
+ "json" : {"@context":"http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld","meta":{"cutOff":true,"count":2,"startIndex":2,"timeout":120000,"context":{"left":["token",6],"right":["token",6]},"fields":["textSigle","author","docSigle","availability","title","pubDate","UID","corpusID","textClass","subTitle","layerInfos","ID","pubPlace","corpusSigle"],"version":"0.58.0","benchmark":"21.959009 ms","totalResults":-1,"serialQuery":"tokens:s:der","itemsPerPage":2},"query":{"@type":"koral:token","wrap":{"@type":"koral:term","match":"match:eq","layer":"orth","key":"der","foundry":"opennlp","rewrites":[{"@type":"koral:rewrite","src":"Kustvakt","operation":"operation:injection","scope":"foundry"}]}},"matches":[{"field":"tokens","pubPlace":"München","textSigle":"GOE/AGI/00000","docSigle":"GOE/AGI","corpusSigle":"GOE","title":"Italienische Reise","subTitle":"Auch ich in Arkadien!","author":"Goethe, Johann Wolfgang von","availability":"ACA-NC","layerInfos":"corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels marmot/m=tokens marmot/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens","startMore":true,"endMore":true,"license":"ACA-NC","snippet":"<span class=\"context-left\"><span class=\"more\"></span>Besitzungen. der Boden ist aufgelöster Tonschiefer. </span><span class=\"match\"><mark>der</mark></span><span class=\"context-right\"> Quarz, der sich in dieser Gebirgsart<span class=\"more\"></span></span>","matchID":"match-GOE/AGI/00000-p205-206","pubDate":"1982","UID":0},{"field":"tokens","pubPlace":"München","textSigle":"GOE/AGI/00000","docSigle":"GOE/AGI","corpusSigle":"GOE","title":"Italienische Reise","subTitle":"Auch ich in Arkadien!","author":"Goethe, Johann Wolfgang von","availability":"ACA-NC","layerInfos":"corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels marmot/m=tokens marmot/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens","startMore":true,"endMore":true,"license":"ACA-NC","snippet":"<span class=\"context-left\"><span class=\"more\"></span>Boden ist aufgelöster Tonschiefer. der Quarz, </span><span class=\"match\"><mark>der</mark></span><span class=\"context-right\"> sich in dieser Gebirgsart befindet und<span class=\"more\"></span></span>","matchID":"match-GOE/AGI/00000-p207-208","pubDate":"1982","UID":0}]}
+}
diff --git a/t/match_info.t b/t/match_info.t
index c07e7aa..bd9afe9 100644
--- a/t/match_info.t
+++ b/t/match_info.t
@@ -25,14 +25,14 @@
$fake_backend->pattern->defaults->{app}->log($t->app->log);
# Query passed
-$t->get_ok('/corpus2/WPD15/232/39681/p2133-2134?spans=false&foundry=*')
+$t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=false&foundry=*')
->status_is(200)
->json_is('/textSigle', 'WPD15/232/39681')
->json_like('/snippet', qr!<span class=\"context-left\">!)
- ->json_is('/X-cached', undef)
+ ->header_isnt('X-Kalamar-Cache', 'true')
;
-$t->get_ok('/corpus2/GOE/AGF/02286/p75682-75683')
+$t->get_ok('/corpus/GOE/AGF/02286/p75682-75683')
->status_is(200)
->json_is('/textSigle', 'GOE/AGF/02286')
->json_is('/title','Materialien zur Geschichte der Farbenlehre')
@@ -40,7 +40,7 @@
# TODO:
# It's surprising, that it doesn't return a 404!
-$t->get_ok('/corpus2/notfound/X/X/p0-1')
+$t->get_ok('/corpus/notfound/X/X/p0-1')
->status_is(200)
->json_is('/textSigle', 'NOTFOUND/X/X')
->json_is('/corpusID', undef)
@@ -48,7 +48,7 @@
# TODO:
# Should probably return a 500!
-$t->get_ok('/corpus2/fail/x/x/p0-0')
+$t->get_ok('/corpus/fail/x/x/p0-0')
->status_is(200)
->json_is('/notifications/0/0', 'error')
->json_is('/notifications/0/1', 'Unable to load query response from /home/ndiewald/Repositories/korap-git/Kalamar/t/fixtures/response_matchinfo_fail_x_x_p0-0.json')
@@ -56,7 +56,7 @@
# TODO:
# Should probably return a 4xx!
-$t->get_ok('/corpus2/GOE/AGF/02286/p-2-0')
+$t->get_ok('/corpus/GOE/AGF/02286/p-2-0')
->status_is(200)
->json_is('/notifications/0/0', 'error')
->json_is('/notifications/0/1', '730: Invalid match identifier')
@@ -64,19 +64,19 @@
# TODO:
# It's surprising, that it doesn't return a 404!
-$t->get_ok('/corpus2/notfound2/X/X/p0-1')
+$t->get_ok('/corpus/notfound2/X/X/p0-1')
->status_is(404)
->json_is('/notifications/0/0', 'error')
->json_is('/notifications/0/1', '404: Not Found')
;
-$t->get_ok('/corpus2/brokenerr/X/X/p0-1')
+$t->get_ok('/corpus/brokenerr/X/X/p0-1')
->status_is(409)
->json_is('/notifications/0/0', 'error')
->json_is('/notifications/0/1', 'Message structure failed')
;
-$t->get_ok('/corpus2/brokenwarn/X/X/p0-1')
+$t->get_ok('/corpus/brokenwarn/X/X/p0-1')
->status_is(200)
->json_is('/notifications/0/0', 'warning')
->json_is('/notifications/0/1', '1: Warning 1')
@@ -84,18 +84,18 @@
->json_is('/notifications/1/1', 'Message structure failed')
;
-$t->get_ok('/corpus2/brokenerr2/X/X/p0-1')
+$t->get_ok('/corpus/brokenerr2/X/X/p0-1')
->status_is(417)
->json_is('/notifications/0/0', 'error')
->json_is('/notifications/0/1', 'Message structure failed')
;
# Get from cache
-$t->get_ok('/corpus2/WPD15/232/39681/p2133-2134?spans=false&foundry=*')
+$t->get_ok('/corpus/WPD15/232/39681/p2133-2134?spans=false&foundry=*')
->status_is(200)
->json_is('/textSigle', 'WPD15/232/39681')
->json_like('/snippet', qr!<span class=\"context-left\">!)
- ->json_is('/X-cached', 1)
+ ->header_is('X-Kalamar-Cache', 'true')
;
diff --git a/t/query.t b/t/query.t
index 4bc97dc..97f4997 100644
--- a/t/query.t
+++ b/t/query.t
@@ -25,9 +25,10 @@
$fake_backend->pattern->defaults->{app}->log($t->app->log);
# Query passed
-$t->get_ok('/q2?q=baum')
+$t->get_ok('/?q=baum')
->status_is(200)
->text_is('#error','')
+
->text_is('title', 'KorAP: Find »baum« with Poliqarp')
->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
@@ -42,6 +43,9 @@
->content_like(qr/\"authorized\":null/)
->content_like(qr/\"pubDate\",\"subTitle\",\"author\"/)
+ # No cutOff
+ ->content_unlike(qr!\"cutOff":true!)
+
->element_exists('li[data-text-sigle=GOE/AGI/00000]')
->element_exists('li:nth-of-type(1) div.flop')
->element_exists('li[data-text-sigle=GOE/AGI/00001]')
@@ -65,13 +69,87 @@
->text_like('li:nth-of-type(1) p.ref', qr!by Goethe, Johann Wolfgang!)
->text_is('li:nth-of-type(1) p.ref time[datetime=1982]', 1982)
->text_is('li:nth-of-type(1) p.ref span.sigle', '[GOE/AGI/00000]')
+ ->header_isnt('X-Kalamar-Cache', 'true')
;
-$t->get_ok('/q2?q=[orth=das')
+$t->get_ok('/?q=[orth=das')
->status_is(400)
->text_is('div.notify-error:nth-of-type(1)', '302: Parantheses/brackets unbalanced.')
->text_like('div.notify-error:nth-of-type(2)', qr!302: Could not parse query .+? \[orth=das.+?!)
;
+# Query with partial cache (for total results)
+$t->get_ok('/?q=baum')
+ ->status_is(200)
+ ->text_is('#error','')
+ ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
+ ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
+ ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
+ ->header_isnt('X-Kalamar-Cache', 'true')
+ ->content_like(qr!\"cutOff":true!)
+ ->text_is('#total-results', 51)
+ ;
+
+# Query with full cache
+$t->get_ok('/?q=baum')
+ ->status_is(200)
+ ->text_is('#error','')
+ ->text_is('title', 'KorAP: Find »baum« with Poliqarp')
+ ->element_exists('meta[name="DC.title"][content="KorAP: Find »baum« with Poliqarp"]')
+ ->element_exists('body[itemscope][itemtype="http://schema.org/SearchResultsPage"]')
+ ->header_is('X-Kalamar-Cache', 'true')
+ ->content_like(qr!\"cutOff":true!)
+ ->text_is('#total-results', 51)
+ ;
+
+
+# Query with page information
+$t->get_ok('/?q=der&p=1&count=2')
+ ->status_is(200)
+ ->text_is('#error','')
+ ->text_is('title', 'KorAP: Find »der« with Poliqarp')
+
+ # Total results
+ ->text_is('#total-results', '14,581')
+
+ # Total pages
+ ->element_count_is('#pagination a', 7)
+ ->text_is('#pagination a:nth-of-type(6) span', 7291)
+ ->content_like(qr!\"count":2!)
+ ->content_like(qr!\"startIndex":0!)
+ ->content_like(qr!\"itemsPerPage":2!)
+
+ # No caching
+ ->header_isnt('X-Kalamar-Cache', 'true')
+
+ # Not searched for "der" before
+ ->content_unlike(qr!\"cutOff":true!)
+ ;
+
+# Query with page information - next page
+$t->get_ok('/?q=der&p=2&count=2')
+ ->status_is(200)
+ ->text_is('#error','')
+ ->text_is('title', 'KorAP: Find »der« with Poliqarp')
+
+ # Total results
+ ->text_is('#total-results', '14,581')
+
+ # Total pages
+ ->element_count_is('#pagination a', 7)
+ ->text_is('#pagination a:nth-of-type(6) span', 7291)
+ ->content_like(qr!\"count":2!)
+ ->content_like(qr!\"itemsPerPage":2!)
+ ->content_like(qr!\"startIndex":2!)
+
+ # No caching
+ ->header_isnt('X-Kalamar-Cache', 'true')
+ ->content_like(qr!\"cutOff":true!)
+ ;
+
+
+
+
done_testing;
+__END__
diff --git a/t/remote.t b/t/remote.t
index 328b4ef..a04ca5c 100644
--- a/t/remote.t
+++ b/t/remote.t
@@ -23,13 +23,9 @@
$fake_backend->pattern->defaults->{app}->log($t->app->log);
+
if (0) {
-$t->get_ok('/')
- ->status_is(200)
- ->text_is('title', 'KorAP - Corpus Analysis Platform')
- ->text_like('h1 span', qr/KorAP - Corpus Analysis Platform/i)
- ;
# Check paging
$t->get_ok('/?q=Baum')
@@ -75,13 +71,12 @@
};
-
-
# Check for query error
$t->get_ok('/?q=[orth=das&ql=poliqarp')
->element_exists('.notify-error')
->text_is('.notify-error', '302: Parantheses/brackets unbalanced.')
->content_like(qr!KorAP\.koralQuery =!)
+ ->text_is('.no-results:nth-of-type(1)', 'Unable to perform the search.')
;
done_testing;