Dancer2-Plugin-RPC

 view release on metacpan or  search on metacpan

t/100-xmlrpc.t  view on Meta::CPAN

        [ 'Content-Type' => 'text/xml' ],
        <<'        EOXML',
<?xml version="1.0"?>
<methodCall>
<methodName>ping</methodName>
<params/>
</methodCall>
        EOXML
    );
    my $response = $tester->request($request);
    my $value = $p->parse($response->decoded_content)->value->value;
    is_deeply(
        $value,
        'pong',
        "ping"
    ) or diag(explain($value));
};

subtest "XMLRPC ping (GET)" => sub {
    my $request = HTTP::Request->new(
        GET => '/endpoint',

t/100-xmlrpc.t  view on Meta::CPAN

          </member>
        </struct>
      </param>
    </params>
</methodCall>
        EOXML
    );
    my $response = $tester->request($request);
    is($response->status_line, '200 OK', "OK response");

    my $methods = $p->parse($response->decoded_content)->value->value;
    is_deeply(
        $methods,
        {
            '/endpoint' => [qw/
                methodList
                ping
                version
            /]
        },
        "methodList(plugin => 'xmlrpc')"

t/110-xmlrpc-callbackfail.t  view on Meta::CPAN

        [ 'Content-Type' => 'text/xml' ],
        <<'        EOXML',
<?xml version="1.0"?>
<methodCall>
<methodName>ping</methodName>
<params/>
</methodCall>
        EOXML
    );
    my $response = $tester->request($request);
    my $response_data = $p->parse($response->decoded_content)->value->value;
    is_deeply(
        $response_data,
        {
            'faultCode'   => '-32760',
            'faultString' => 'Callback failed'
        },
        "CallbackFail"
    ) or diag(explain($response_data));
};

t/115-xmlrpc-callback-die.t  view on Meta::CPAN

        [ 'Content-Type' => 'text/xml' ],
        <<'        EOXML',
<?xml version="1.0"?>
<methodCall>
<methodName>ping</methodName>
<params/>
</methodCall>
        EOXML
    );
    my $response = $tester->request($request);
    my $response_data = $p->parse($response->decoded_content)->value->value;
    is_deeply(
        $response_data,
        {
            'faultCode'   => 500,
            'faultString' => "Callback die()s\n",
        },
        "CallbackFail"
    ) or diag(explain($response_data));
};

t/120-xmlrpc-codewrapper-die.t  view on Meta::CPAN

        [ 'Content-Type' => 'text/xml' ],
        <<'        EOXML',
<?xml version="1.0"?>
<methodCall>
<methodName>ping</methodName>
<params/>
</methodCall>
        EOXML
    );
    my $response = $tester->request($request);
    my $response_data = $p->parse($response->decoded_content)->value->value;
    is_deeply(
        $response_data,
        {
            'faultCode'   => -32500,
            'faultString' => "Codewrapper die()s\n",
        },
        "CodeWrapper die()s"
    ) or diag(explain($response_data));
};

t/125-xmlrpc-myapp.t  view on Meta::CPAN

<methodCall>
    <methodName>ping</methodName>
    <params/>
</methodCall>
        EOXML
    );
    my $response = $tester->request($request);
    is($response->status_line, '200 OK', "OK response");

    is_deeply(
        $p->parse($response->decoded_content)->value->value,
        'pong',
        "ping"
    );
};

subtest "XMLRPC version" => sub {
    local $Data::Dumper::Purity = 0;
    my $request = HTTP::Request->new(
        POST => '/endpoint',
        [ 'Content-Type' => 'text/xml' ],

t/125-xmlrpc-myapp.t  view on Meta::CPAN

<methodCall>
    <methodName>version</methodName>
    <params/>
</methodCall>
        EOXML
    );
    my $response = $tester->request($request);
    is($response->status_line, '200 OK', "OK response");

    is_deeply(
        $p->parse($response->decoded_content)->value->value,
        {software => $MyAppCode::VERSION},
        "version"
    );
};

subtest "XMLRPC methodList()" => sub {
    my $request = HTTP::Request->new(
        POST => '/endpoint',
        ['Content-Type' => 'text/xml'],
        <<'        EOXML',
<?xml version="1.0"?>
<methodCall>
    <methodName>methodList</methodName>
    <params/>
</methodCall>
        EOXML
    );
    my $response = $tester->request($request);
    is($response->status_line, '200 OK', "OK response");

    my $methods = $p->parse($response->decoded_content)->value->value;
    is_deeply(
        $methods,
        {
            'jsonrpc' => {'/endpoint' => ['method.list', 'ping', 'version']},
            'restrpc' => {'/endpoint' => ['method_list', 'ping', 'version']},
            'xmlrpc'  => {'/endpoint' => ['methodList',  'ping', 'version']}
        },
        "methodList(plugin => 'xmlrpc')"
    ) or diag(explain($methods // $response));
};

t/125-xmlrpc-myapp.t  view on Meta::CPAN

          </member>
        </struct>
      </param>
    </params>
</methodCall>
        EOXML
    );
    my $response = $tester->request($request);
    is($response->status_line, '200 OK', "OK response");

    my $methods = $p->parse($response->decoded_content)->value->value;
    is_deeply(
        $methods,
        {
            '/endpoint' => [qw/
                methodList
                ping
                version
            /]
        },
        "methodList(plugin => 'xmlrpc')"

t/200-jsonrpc.t  view on Meta::CPAN

                jsonrpc => '2.0',
                method  => 'method.list',
                id      => 42,
                params  => {plugin => 'jsonrpc'}
            }
        ),
    );

    my $response = $tester->request($request);
    is_deeply(
        from_json($response->decoded_content)->{result},
        {
            '/endpoint' => [qw/
                method.list
                ping
                version
            /]
        },
        "method.list(plugin => 'jsonrpc')"
    ) or diag(explain($response));
};

t/200-jsonrpc.t  view on Meta::CPAN

                method  => 'methodList',
                id      => 42,
                params  => {plugin => 'any'}
            }
        ),
    );

    my $response = $tester->request($request);
    is($response->status_line, "200 OK", "Transport OK");
    is_deeply(
        from_json($response->decoded_content)->{error},
        {
            code    => -32601,
            message => "Method 'methodList' not found at '/endpoint' (skipped)"
        },
        "Unknown jsonrpc-method"
    );
};

subtest "JSONRPC wrong content-type => 404" => sub {
    my $request = HTTP::Request->new(

t/225-jsonrpc-myapp.t  view on Meta::CPAN

            {
                jsonrpc => '2.0',
                method  => 'ping',
                id      => 42,
            }
        ),
    );

    my $response = $tester->request($request);
    is_deeply(
        from_json($response->decoded_content)->{result},
        'pong',
        "ping"
    ) or diag(explain($response));
};

subtest "JSONRPC version" => sub {
    my $request = HTTP::Request->new(
        POST => '/endpoint',
        [
            'Content-Type' => 'application/json',

t/225-jsonrpc-myapp.t  view on Meta::CPAN

            {
                jsonrpc => '2.0',
                method  => 'version',
                id      => 42,
            }
        ),
    );

    my $response = $tester->request($request);
    is_deeply(
        from_json($response->decoded_content)->{result},
        { software => $MyAppCode::VERSION },
        "version"
    ) or diag(explain($response));
};

subtest "JSONRPC method.list()" => sub {
    my $request = HTTP::Request->new(
        POST => '/endpoint',
        [
            'Content-Type' => 'application/json',

t/225-jsonrpc-myapp.t  view on Meta::CPAN

            {
                jsonrpc => '2.0',
                method  => 'method.list',
                id      => 42,
            }
        ),
    );

    my $response = $tester->request($request);
    is_deeply(
        from_json($response->decoded_content)->{result},
        {
            'jsonrpc' => {'/endpoint' => ['method.list', 'ping', 'version']},
            'restrpc' => {'/endpoint' => ['method_list', 'ping', 'version']},
            'xmlrpc'  => {'/endpoint' => ['methodList',  'ping', 'version']}
        },
        "method.list()"
    ) or diag(explain($response));
};

subtest "JSONRPC method.list(plugin => 'jsonrpc')" => sub {

t/225-jsonrpc-myapp.t  view on Meta::CPAN

                jsonrpc => '2.0',
                method  => 'method.list',
                id      => 42,
                params  => {plugin => 'jsonrpc'}
            }
        ),
    );

    my $response = $tester->request($request);
    is_deeply(
        from_json($response->decoded_content)->{result},
        {
            '/endpoint' => [ qw/ method.list ping version / ]
        },
        "method.list(plugin => 'jsonrpc')"
    ) or diag(explain($response));
};

abeltje_done_testing();

BEGIN {

t/300-restrpc.t  view on Meta::CPAN

            'Content-Type' => 'application/json',
            'Accept'       => 'application/json',
        ],
        encode_json(
            { plugin => 'restrpc'}
        ),
    );

    my $response = $tester->request($request);
    is_deeply(
        from_json($response->decoded_content),
        {
            '/endpoint' => [qw/
                method_list
                ping
                version
            /]
        },
        "method_list(plugin => 'restrpc')"
    ) or diag(explain($response));
};

t/300-restrpc.t  view on Meta::CPAN

    my $request = HTTP::Request->new(
        POST => '/endpoint/ping',
        [
            'Content-Type' => 'application/json',
            'Accept'       => 'application/json',
        ],
    );

    my $response = $tester->request($request);
    is_deeply(
        from_json($response->decoded_content),
        { RESULT => 'pong' },
        "simple-scalar-result becomes hashref with key RESPONSE"
    ) or diag(explain($response));
};

subtest "RESTRPC methodList(plugin => 'restrpc') /wrong_endpoint" => sub {
    my $request = HTTP::Request->new(
        POST => '/wrong_endpoint',
        [
            'Content-Type' => 'application/json',

t/325-restrpc-myapp.t  view on Meta::CPAN

    my $request = HTTP::Request->new(
        POST => '/endpoint/ping',
        [
            'Content-Type' => 'application/json',
            'Accept'       => 'application/json',
        ],
    );

    my $response = $tester->request($request);
    is_deeply(
        from_json($response->decoded_content),
        { RESULT => 'pong' },
        "simple-scalar-result becomes hashref with key RESPONSE"
    ) or diag(explain($response));
};

subtest "RESTRPC version" => sub {
    my $request = HTTP::Request->new(
        POST => '/endpoint/version',
        [
            'Content-Type' => 'application/json',
            'Accept'       => 'application/json',
        ],
    );

    my $response = $tester->request($request);
    is_deeply(
        from_json($response->decoded_content),
        { software => $MyAppCode::VERSION },
        "version"
    ) or diag(explain($response));
};

subtest "RESTRPC method_list()" => sub {
    my $request = HTTP::Request->new(
        POST => '/endpoint/method_list',
        [
            'Content-Type' => 'application/json',
            'Accept'       => 'application/json',
        ],
    );

    my $response = $tester->request($request);
    is_deeply(
        from_json($response->decoded_content),
        {
            'jsonrpc' => {'/endpoint' => ['method.list', 'ping', 'version']},
            'restrpc' => {'/endpoint' => ['method_list', 'ping', 'version']},
            'xmlrpc'  => {'/endpoint' => ['methodList',  'ping', 'version']}
        },
        "method_list()"
    ) or diag(explain($response));
};

subtest "RESTRPC method_list(plugin => 'restrpc')" => sub {

t/325-restrpc-myapp.t  view on Meta::CPAN

            'Content-Type' => 'application/json',
            'Accept'       => 'application/json',
        ],
        encode_json(
            { plugin => 'restrpc'}
        ),
    );

    my $response = $tester->request($request);
    is_deeply(
        from_json($response->decoded_content),
        {
            '/endpoint' => [qw/
                method_list
                ping
                version
            /]
        },
        "method_list(plugin => 'restrpc')"
    ) or diag(explain($response));
};



( run in 0.454 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )