blob: 5a216c696c2809e5b5184cd3e40266c8e2ed3cb2 [file] [log] [blame]
Marc Kupietz3e3e3262022-04-12 23:11:45 +02001use strict;
2use warnings;
Marc Kupietz043db152023-11-05 17:47:53 +01003use Test::More tests=>8;
Marc Kupietz3e3e3262022-04-12 23:11:45 +02004use Mojo::JSON qw(decode_json encode_json to_json);
5use REST::Client;
6use Data::Dump qw(dump);
7
8my $pid = fork();
9my $res;
10unless ($pid) {
11 unless (fork) {
12 exec "MOJO_CONFIG=../example.conf morbo script/derekovecs-server";
13 die "exec failed!";
14 }
15 exit(0);
16}
17sleep(20);
18
19my $client = REST::Client->new();
20$client->GET('http://localhost:3000/?word=Grund&json=1');
21$res = decode_json($client->responseContent());
22is( $res->{list}->[0]->[1]->{word}, "Reaktion", "primary paradigmatic neighbour of Grund" );
23is( $res->{collocators}->[0]->{word}, "Hitchcock", "primary syntagmatic neighbour of Grund" );
24
25$client->GET('http://localhost:3000/getClassicCollocators?w=Grund');
26#print STDERR dump($res);
27$res = decode_json($client->responseContent());
28is( $res->{collocates}->[0]->{word}, "diesem", "primary collocate of Grund" );
29
30$client->GET('http://localhost:3000/getClassicCollocators?w=Grund');
31$res = decode_json($client->responseContent());
32is( $res->{collocates}->[0]->{word}, "diesem", "primary collocate of Grund (cached)" );
33
34$client->GET('http://localhost:3000/getCollocationAssociation?w=Grund&c=diesem');
35$res = decode_json($client->responseContent());
36is($res->{f1}, 29, "collocation association");
37
Marc Kupietzaf708c22023-11-05 11:20:20 +010038$client->GET('http://localhost:3000/getVersion');
39$res = $client->responseContent();
Marc Kupietzb36bc742023-11-05 17:46:11 +010040like($res, qr/^"\d+\.?\d*\.?\d*"$/, "version ok");
Marc Kupietzaf708c22023-11-05 11:20:20 +010041
Marc Kupietzdea505e2023-11-05 11:42:36 +010042$client->GET('http://localhost:3000/getModelName');
43$res = $client->responseContent();
Marc Kupietzb36bc742023-11-05 17:46:11 +010044is($res, '"wpd19_10000"', "model name ok");
45
Marc Kupietz043db152023-11-05 17:47:53 +010046$client->GET('http://localhost:3000/getVocabSize');
47$res = $client->responseContent();
48ok($res > 1000, "vocab size ok");
Marc Kupietzdea505e2023-11-05 11:42:36 +010049
Marc Kupietz3e3e3262022-04-12 23:11:45 +020050for (my $i=0; $i<4; $i++) {
51 $pid++;
52 print STDERR "killing PID $pid\n";
53 system("kill -9 $pid");
54}
55done_testing;