Support text information endpoint
Change-Id: I93499d56e235f99dd56189e0174b5c572ae36189
diff --git a/t/fixtures/fake_backend.pl b/t/fixtures/fake_backend.pl
index 9f06697..7506d84 100644
--- a/t/fixtures/fake_backend.pl
+++ b/t/fixtures/fake_backend.pl
@@ -114,6 +114,24 @@
return 1;
};
+# Textinfo fixtures
+get '/corpus/:corpusId/:docId/:textId' => sub {
+ my $c = shift;
+
+ my $file = join('_', (
+ 'textinfo',
+ $c->stash('corpusId'),
+ $c->stash('docId'),
+ $c->stash('textId')
+ ));
+
+ my $slug = slugify($file);
+
+ # Get response based on query parameter
+ my $response = $c->load_response($slug);
+ return $c->render(%$response);
+};
+
# Matchinfo fixtures
get '/corpus/:corpusId/:docId/:textId/:matchId/matchInfo' => sub {
diff --git a/t/fixtures/response_textinfo_goe_agi_00000.json b/t/fixtures/response_textinfo_goe_agi_00000.json
new file mode 100644
index 0000000..384df8d
--- /dev/null
+++ b/t/fixtures/response_textinfo_goe_agi_00000.json
@@ -0,0 +1,4 @@
+{
+ "status" : 200,
+ "json" : {"messages":[["Response format is temporary"]],"@context":"http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld","meta":{},"document":{"@type":"koral:document","fields":[{"@type":"koral:field","type":"type:string","key":"textSigle","value":"GOE/AGI/00000"},{"@type":"koral:field","type":"type:text","key":"author","value":"Goethe, Johann Wolfgang von"},{"@type":"koral:field","type":"type:string","key":"docSigle","value":"GOE/AGI"},{"@type":"koral:field","type":"type:text","key":"docTitle","value":"Goethe: Autobiographische Schriften III, (1813-1816, 1819-1829)"},{"@type":"koral:field","type":"type:string","key":"textType","value":"Autobiographie"},{"@type":"koral:field","type":"type:string","key":"language","value":"de"},{"@type":"koral:field","type":"type:string","key":"availability","value":"ACA-NC"},{"@type":"koral:field","type":"type:text","key":"title","value":"Italienische Reise"},{"@type":"koral:field","type":"type:date","key":"creationDate","value":"1813"},{"@type":"koral:field","type":"type:string","key":"foundries","value":"corenlp corenlp/constituency corenlp/morpho corenlp/sentences dereko dereko/structure dereko/structure/base-sentences-paragraphs-pagebreaks malt malt/dependency marmot marmot/morpho opennlp opennlp/morpho opennlp/sentences treetagger treetagger/morpho"},{"@type":"koral:field","type":"type:date","key":"pubDate","value":"1982"},{"@type":"koral:field","type":"type:store","key":"reference","value":"Goethe, Johann Wolfgang von: Italienische Reise. Auch ich in Arkadien!, (Geschrieben: 1813-1816), In: Goethe, Johann Wolfgang von: Goethes Werke, Bd. 11, Autobiographische Schriften III, Hrsg.: Trunz, Erich. München: Verlag C. H. Beck, 1982, S. 9-349"},{"@type":"koral:field","type":"type:text","key":"subTitle","value":"Auch ich in Arkadien!"},{"@type":"koral:field","type":"type:store","key":"tokenSource","value":"base#tokens"},{"@type":"koral:field","type":"type:store","key":"publisher","value":"Verlag C. H. Beck"},{"@type":"koral:field","type":"type:text","key":"corpusAuthor","value":"Goethe, Johann Wolfgang von"},{"@type":"koral:field","type":"type:store","key":"layerInfos","value":"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"},{"@type":"koral:field","type":"type:string","key":"pubPlace","value":"München"},{"@type":"koral:field","type":"type:text","key":"corpusTitle","value":"Goethes Werke"},{"@type":"koral:field","type":"type:string","key":"corpusSigle","value":"GOE"},{"@type":"koral:field","type":"type:store","key":"corpusEditor","value":"Trunz, Erich"}]}}
+}
diff --git a/t/fixtures/response_textinfo_goe_agy_00000.json b/t/fixtures/response_textinfo_goe_agy_00000.json
new file mode 100644
index 0000000..9182e24
--- /dev/null
+++ b/t/fixtures/response_textinfo_goe_agy_00000.json
@@ -0,0 +1,4 @@
+{
+ "status" : 200,
+ "json" : {"errors":[[630,"Document not found"]],"messages":[["Response format is temporary"]],"@context":"http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld","meta":{},"document":{"@type":"koral:document","fields":[]}}
+}
diff --git a/t/text_info.t b/t/text_info.t
new file mode 100644
index 0000000..7c06bf6
--- /dev/null
+++ b/t/text_info.t
@@ -0,0 +1,42 @@
+use Mojo::Base -strict;
+use Test::Mojo;
+use Test::More;
+use Mojo::File qw/path/;
+
+
+#####################
+# Start Fake server #
+#####################
+my $mount_point = '/api/';
+$ENV{KALAMAR_API} = $mount_point;
+
+my $t = Test::Mojo->new('Kalamar');
+
+# Mount fake backend
+# Get the fixture path
+my $fixtures_path = path(Mojo::File->new(__FILE__)->dirname, 'fixtures');
+my $fake_backend = $t->app->plugin(
+ Mount => {
+ $mount_point =>
+ $fixtures_path->child('fake_backend.pl')
+ }
+);
+# Configure fake backend
+$fake_backend->pattern->defaults->{app}->log($t->app->log);
+
+# Query passed
+$t->get_ok('/corpus/GOE/AGI/00000')
+ ->status_is(200)
+ ->json_is('/document/fields/0/key', 'textSigle')
+ ->json_is('/document/fields/0/value', 'GOE/AGI/00000')
+ ;
+
+# Not found - should probably be 404
+$t->get_ok('/corpus/GOE/AGY/00000')
+ ->status_is(200)
+ ->json_is('/notifications/0/1', '630: Document not found')
+ ;
+
+
+done_testing;
+__END__