PageRenderTime 29ms CodeModel.GetById 1ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/t/020_interface/poe-uri.t

http://github.com/http-engine/HTTP-Engine
Unknown | 63 lines | 53 code | 10 blank | 0 comment | 0 complexity | 0e0685244737fcaec7f8fba5fe35ed7d MD5 | raw file
 1use strict;
 2use warnings;
 3use Test::More;
 4use Test::TCP;
 5use HTTP::Engine;
 6use Encode;
 7
 8eval "use POE;use POE::Session;";
 9plan skip_all => "this test requires POE" if $@;
10eval "use POE::Component::Client::HTTP;";
11plan skip_all => "this test requires POE::Component::Client::HTTP" if $@;
12
13plan tests => 2;
14
15use_ok 'HTTP::Engine::Interface::POE';
16
17# my $port = empty_port;
18my $port = decode_utf8(empty_port);
19
20HTTP::Engine::Interface::POE->new(
21    request_handler => sub {
22        my $req = shift;
23        HTTP::Engine::Response->new(
24            status => 200,
25            body   => $req->param('channel'),
26        );
27    },
28    alias => 'he',
29    port => $port,
30)->run;
31
32POE::Component::Client::HTTP->spawn(
33    Alias => 'ua',
34);
35
36POE::Session->create(
37    inline_states => {
38        _start => sub {
39            my ($kernel, ) = @_[POE::Session::KERNEL()];
40            my $req = HTTP::Request->new(
41                'GET',
42                "http://localhost:$port/?channel=%23%E3%81%BB%E3%81%92",
43            );
44            $kernel->post(
45                'ua',
46                'request',
47                'response',
48                $req,
49            );
50        },
51        'response' => sub {
52            my ($kernel, ) = @_[POE::Session::KERNEL()];
53            my $req = @_[POE::Session::ARG0()]->[0];
54            my $res = @_[POE::Session::ARG1()]->[0];
55
56            is($res->content, '#ほげ');
57            $kernel->stop;
58        },
59    },
60);
61
62POE::Kernel->run;
63