blob: 4d8a560318f76fd5ee0085c5c6056dd5bb19b993 [file] [log] [blame]
Nils Diewald034ea702015-01-16 19:41:52 +00001#!/usr/bin/env perl
2use strict;
3use warnings;
Nils Diewalda748b0e2015-05-19 22:54:06 +00004use Test::More skip_all => 'No remote tests';
Nils Diewald034ea702015-01-16 19:41:52 +00005use 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')
Nils Diewalda748b0e2015-05-19 22:54:06 +000032# ->json_is('/0/description', 'Die freie Enzyklopädie')
33 ;
Nils Diewald034ea702015-01-16 19:41:52 +000034
35# Get resources - query
36$t->get_ok($url->clone->path('query'))
37 ->status_is(200)
38 ->json_is([]);
39
40# Get resources - foundry
41$t->get_ok($url->clone->path('foundry'))
42 ->status_is(200);
43
44# Get resources - layer
45$t->get_ok($url->clone->path('layer'))
46 ->status_is(200);
47
48# Stats
49$t->get_ok($url->clone->path('corpus/WPD/stats'))
50 ->json_is('/documents', 196510)
51 ->json_is('/tokens', 51545081)
52 ->json_is('/sentences', 4116282)
53 ->json_is('/paragraphs', 2034752)
54 ->status_is(200);
55
56# Matchinfo
57$t->get_ok($url->clone->path('corpus/WPD/SSS.04897/p29-30/matchInfo'))
58 ->json_is('/author', 'Darkone,Dramburg,Fusslkopp')
59 ->json_is('/textClass', 'freizeit-unterhaltung reisen')
60 ->json_is('/corpusID', 'WPD')
61 ->json_is('/title', 'Schloss Hohenzieritz')
62 ->json_is('/docID', 'WPD_SSS.04897')
63 ->json_is('/ID', 'match-WPD!WPD_SSS.04897-p29-30')
64 ->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>")
65 ->status_is(200);
66
67# Matchinfo
68$t->get_ok($url->clone->path('corpus/WPD/SSS.04897/p29-30/matchInfo')->query({ foundry => '*'}))
69 ->json_is('/author', 'Darkone,Dramburg,Fusslkopp')
70 ->json_is('/textClass', 'freizeit-unterhaltung reisen')
71 ->json_is('/corpusID', 'WPD')
72 ->json_is('/title', 'Schloss Hohenzieritz')
73 ->json_is('/docID', 'WPD_SSS.04897')
74 ->json_is('/ID', 'match-WPD!WPD_SSS.04897-p23-45')
75 ->json_has('/snippet')
76 ->status_is(200);
77
78# Search
79# Check serialization
80$t->get_ok($url->clone->path('search')->query({ q => 'contains(<s>, [orth=Test])', ql => 'poliqarp'}))
81 ->json_is('/startIndex', 0)
82 ->json_like('/totalResults', qr/\d+/)
83 ->json_is('/itemsPerPage', 25)
84 ->status_is(200);
85
86my $tx = $t->ua->build_tx('TRACE', $url->clone->path('search')->query({ q => 'contains(<s>, [orth=Test])', ql => 'poliqarp'}));
87$tx = $t->ua->start($tx);
88
Nils Diewald034ea702015-01-16 19:41:52 +000089$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
Nils Diewald034ea702015-01-16 19:41:52 +000097done_testing;