Marc Kupietz | 3e3e326 | 2022-04-12 23:11:45 +0200 | [diff] [blame^] | 1 | use strict; |
| 2 | use warnings; |
| 3 | use Test::More tests=>5; |
| 4 | use Mojo::JSON qw(decode_json encode_json to_json); |
| 5 | use REST::Client; |
| 6 | use Data::Dump qw(dump); |
| 7 | |
| 8 | my $pid = fork(); |
| 9 | my $res; |
| 10 | unless ($pid) { |
| 11 | unless (fork) { |
| 12 | exec "MOJO_CONFIG=../example.conf morbo script/derekovecs-server"; |
| 13 | die "exec failed!"; |
| 14 | } |
| 15 | exit(0); |
| 16 | } |
| 17 | sleep(20); |
| 18 | |
| 19 | my $client = REST::Client->new(); |
| 20 | $client->GET('http://localhost:3000/?word=Grund&json=1'); |
| 21 | $res = decode_json($client->responseContent()); |
| 22 | is( $res->{list}->[0]->[1]->{word}, "Reaktion", "primary paradigmatic neighbour of Grund" ); |
| 23 | is( $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()); |
| 28 | is( $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()); |
| 32 | is( $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()); |
| 36 | is($res->{f1}, 29, "collocation association"); |
| 37 | |
| 38 | for (my $i=0; $i<4; $i++) { |
| 39 | $pid++; |
| 40 | print STDERR "killing PID $pid\n"; |
| 41 | system("kill -9 $pid"); |
| 42 | } |
| 43 | done_testing; |