blob: 128707e31498d43bd2bab56204e6625376285fa9 [file] [log] [blame]
Marc Kupietz3e3e3262022-04-12 23:11:45 +02001use strict;
2use warnings;
3use Test::More tests=>5;
4use 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
38for (my $i=0; $i<4; $i++) {
39 $pid++;
40 print STDERR "killing PID $pid\n";
41 system("kill -9 $pid");
42}
43done_testing;