blob: 69e4d3f060f7b2dd85e09fe3fb4a4de79f351dff [file] [log] [blame]
Nils Diewald034ea702015-01-16 19:41:52 +00001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Test::More;
5use Test::Mojo;
6use Mojo::JSON;
7use Mojo::ByteStream 'b';
8use utf8;
9
10my $t = Test::Mojo->new;
11
12my $url = Mojo::URL->new('http://10.0.10.13:8888/api/v0.1/');
13
14# Get resources - corpus
15$t->get_ok($url->clone->path('corpus'))
16 ->status_is(200)
17 ->header_is('Content-Type', 'application/json; charset=utf-8')
18 ->json_is('/0/id', 'WPD')
19 ->json_is('/0/name', 'WPD')
20 ->json_is('/0/path', 'WPD')
21 ->json_is('/0/managed', Mojo::JSON->true)
22 ->json_is('/0/statistics/documents', 196510)
23 ->json_is('/0/statistics/tokens', 51545081)
24 ->json_is('/0/statistics/sentences', 4116282)
25 ->json_is('/0/statistics/paragraphs', 2034752);
26
27# Get resources - collection
28$t->get_ok($url->clone->path('collection'))
29 ->status_is(200)
30 ->json_is('/0/managed', Mojo::JSON->true)
31 ->json_is('/0/name', 'Wikipedia')
32 ->json_is('/0/description', 'Die freie Enzyklopädie');
33
34# Get resources - query
35$t->get_ok($url->clone->path('query'))
36 ->status_is(200)
37 ->json_is([]);
38
39# Get resources - foundry
40$t->get_ok($url->clone->path('foundry'))
41 ->status_is(200);
42
43# Get resources - layer
44$t->get_ok($url->clone->path('layer'))
45 ->status_is(200);
46
47# Stats
48$t->get_ok($url->clone->path('corpus/WPD/stats'))
49 ->json_is('/documents', 196510)
50 ->json_is('/tokens', 51545081)
51 ->json_is('/sentences', 4116282)
52 ->json_is('/paragraphs', 2034752)
53 ->status_is(200);
54
55# Matchinfo
56$t->get_ok($url->clone->path('corpus/WPD/SSS.04897/p29-30/matchInfo'))
57 ->json_is('/author', 'Darkone,Dramburg,Fusslkopp')
58 ->json_is('/textClass', 'freizeit-unterhaltung reisen')
59 ->json_is('/corpusID', 'WPD')
60 ->json_is('/title', 'Schloss Hohenzieritz')
61 ->json_is('/docID', 'WPD_SSS.04897')
62 ->json_is('/ID', 'match-WPD!WPD_SSS.04897-p29-30')
63 ->json_is('/snippet', "<span class=\"context-left\"><span class=\"more\"></span></span><span class=\"match\">Haus</span><span class=\"context-right\"><span class=\"more\"></span></span>")
64 ->status_is(200);
65
66# Matchinfo
67$t->get_ok($url->clone->path('corpus/WPD/SSS.04897/p29-30/matchInfo')->query({ foundry => '*'}))
68 ->json_is('/author', 'Darkone,Dramburg,Fusslkopp')
69 ->json_is('/textClass', 'freizeit-unterhaltung reisen')
70 ->json_is('/corpusID', 'WPD')
71 ->json_is('/title', 'Schloss Hohenzieritz')
72 ->json_is('/docID', 'WPD_SSS.04897')
73 ->json_is('/ID', 'match-WPD!WPD_SSS.04897-p23-45')
74 ->json_has('/snippet')
75 ->status_is(200);
76
77# Search
78# Check serialization
79$t->get_ok($url->clone->path('search')->query({ q => 'contains(<s>, [orth=Test])', ql => 'poliqarp'}))
80 ->json_is('/startIndex', 0)
81 ->json_like('/totalResults', qr/\d+/)
82 ->json_is('/itemsPerPage', 25)
83 ->status_is(200);
84
85my $tx = $t->ua->build_tx('TRACE', $url->clone->path('search')->query({ q => 'contains(<s>, [orth=Test])', ql => 'poliqarp'}));
86$tx = $t->ua->start($tx);
87
88#{"@context":"http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld","query":{"@type":"korap:group","operation":"operation:position","frame":"frame:contains","operands":[{"@type":"korap:span","key":"s"},{"@type":"korap:token","wrap":{"@type":"korap:term","layer":"orth","key":"Test","match":"match:eq"}}]},"collections":[{"@type":"korap:meta-filter","@value":{"@type":"korap:term","@field":"korap:field#corpusID","@value":"WPD"}}],"meta":{}}
89$t->tx($tx)
90 ->json_is('/@context', 'http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld')
91 ->json_is('/query/@type', 'korap:group')
92 ->json_is('/query/operation', 'operation:position')
93 ->json_is('/query/operands/0/@type', 'korap:span')
94 ->json_is('/query/operands/0/key', 's')
95 ->status_is(200);
96
97#$t->get_ok()
98# ->content_is('')
99# ->status_is(200);
100
101
102
103done_testing;