blob: 3146511e8829f5ea4a284e75ca49c20308abe130 [file] [log] [blame]
Marc Kupietz3e3e3262022-04-12 23:11:45 +02001use strict;
2use warnings;
Marc Kupietzaf708c22023-11-05 11:20:20 +01003use Test::More tests=>6;
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();
40like($res, qr/\d+\.?\d*\.?\d*/, "version ok");
41
Marc Kupietz3e3e3262022-04-12 23:11:45 +020042for (my $i=0; $i<4; $i++) {
43 $pid++;
44 print STDERR "killing PID $pid\n";
45 system("kill -9 $pid");
46}
47done_testing;