request-processor-procs.tcl

Tests for procs defined in request-processor-procs

Location:
packages/acs-tcl/tcl/test/request-processor-procs.tcl

Procedures in this file

Detailed information

_acs-tcl__test_ad_register_proc (private)

 _acs-tcl__test_ad_register_proc

Partial Call Graph (max 5 caller/called nodes):
%3 _ _ (public) aa_equals aa_equals (public) aa_log aa_log (public) aa_log_result aa_log_result (public) acs::test::url acs::test::url (public) _acs-tcl__test_ad_register_proc _acs-tcl__test_ad_register_proc _acs-tcl__test_ad_register_proc->_ _acs-tcl__test_ad_register_proc->aa_equals _acs-tcl__test_ad_register_proc->aa_log _acs-tcl__test_ad_register_proc->aa_log_result _acs-tcl__test_ad_register_proc->acs::test::url

Testcases:
No testcase defined.

request_processor::test::a_proc_with_any_args (private)

 request_processor::test::a_proc_with_any_args [ args... ]

A proc with arbitrary args

Partial Call Graph (max 5 caller/called nodes):
%3 request_processor::test::require_registered_procs request_processor::test::require_registered_procs (private) request_processor::test::a_proc_with_any_args request_processor::test::a_proc_with_any_args request_processor::test::require_registered_procs->request_processor::test::a_proc_with_any_args

Testcases:
No testcase defined.

request_processor::test::a_proc_with_flags_and_args (private)

 request_processor::test::a_proc_with_flags_and_args [ -a_flag a_flag ] \
    [ -another_flag another_flag ] [ args... ]

A proc with two flags and arbitrary args

Switches:
-a_flag (optional, defaults to "DEFAULT1")
-another_flag (optional, defaults to "DEFAULT2")

Partial Call Graph (max 5 caller/called nodes):
%3 request_processor::test::require_registered_procs request_processor::test::require_registered_procs (private) request_processor::test::a_proc_with_flags_and_args request_processor::test::a_proc_with_flags_and_args request_processor::test::require_registered_procs->request_processor::test::a_proc_with_flags_and_args

Testcases:
No testcase defined.

request_processor::test::a_proc_with_no_args (private)

 request_processor::test::a_proc_with_no_args

A proc with no arguments

Partial Call Graph (max 5 caller/called nodes):
%3 request_processor::test::require_registered_procs request_processor::test::require_registered_procs (private) request_processor::test::a_proc_with_no_args request_processor::test::a_proc_with_no_args request_processor::test::require_registered_procs->request_processor::test::a_proc_with_no_args

Testcases:
No testcase defined.

request_processor::test::a_proc_with_some_flags (private)

 request_processor::test::a_proc_with_some_flags [ -a_flag a_flag ] \
    [ -another_flag another_flag ]

A proc with two flags

Switches:
-a_flag (optional, defaults to "DEFAULT1")
-another_flag (optional, defaults to "DEFAULT2")

Partial Call Graph (max 5 caller/called nodes):
%3 request_processor::test::require_registered_procs request_processor::test::require_registered_procs (private) request_processor::test::a_proc_with_some_flags request_processor::test::a_proc_with_some_flags request_processor::test::require_registered_procs->request_processor::test::a_proc_with_some_flags

Testcases:
No testcase defined.

request_processor::test::require_registered_procs (private)

 request_processor::test::require_registered_procs

Requires that the test procs are registered under the test URLs

Partial Call Graph (max 5 caller/called nodes):
%3 _ _ (public) ad_register_proc ad_register_proc (public) request_processor::test::a_proc_with_any_args request_processor::test::a_proc_with_any_args (private) request_processor::test::a_proc_with_flags_and_args request_processor::test::a_proc_with_flags_and_args (private) request_processor::test::a_proc_with_no_args request_processor::test::a_proc_with_no_args (private) request_processor::test::require_registered_procs request_processor::test::require_registered_procs request_processor::test::require_registered_procs->_ request_processor::test::require_registered_procs->ad_register_proc request_processor::test::require_registered_procs->request_processor::test::a_proc_with_any_args request_processor::test::require_registered_procs->request_processor::test::a_proc_with_flags_and_args request_processor::test::require_registered_procs->request_processor::test::a_proc_with_no_args

Testcases:
No testcase defined.
[ hide source ] | [ make this the default ]

Content File Source

ad_library {

    Tests for procs defined in request-processor-procs

}

namespace eval request_processor::test {}

ad_proc -private request_processor::test::a_proc_with_no_args {} {
    A proc with no arguments
} {
    ns_return 200 text/plain OK
}

d_proc -private request_processor::test::a_proc_with_some_flags {
    {-a_flag DEFAULT1}
    {-another_flag DEFAULT2}
} {
    A proc with two flags
} {
    ns_return 200 text/plain [list \
                                  a_flag $a_flag \
                                  another_flag $another_flag]
}

ad_proc -private request_processor::test::a_proc_with_any_args args {
    A proc with arbitrary args
} {
    ns_return 200 text/plain $args
}

d_proc -private request_processor::test::a_proc_with_flags_and_args {
    {-a_flag DEFAULT1}
    {-another_flag DEFAULT2}
    args
} {
    A proc with two flags and arbitrary args
} {
    ns_return 200 text/plain [list \
                                  a_flag $a_flag \
                                  another_flag $another_flag \
                                  args $args]
}

ad_proc -private request_processor::test::require_registered_procs {} {
    Requires that the test procs are registered under the test URLs
} {
    set procs [list \
                   request_processor::test::a_proc_with_no_args \
                   request_processor::test::a_proc_with_some_flags \
                   request_processor::test::a_proc_with_any_args \
                   request_processor::test::a_proc_with_flags_and_args]
    # Exit immediately if any of the test procs is already registered.
    if {![nsv_get rp_registered_procs . registered_procs]} {
        set registered_procs [list]
    }
    foreach proc_info $registered_procs {
        set proc_name [lindex $proc_info 2]
        if {$proc_name in $procs} {
            return false
        }
    }

    foreach proc_name $procs {
        switch $proc_name {
            request_processor::test::a_proc_with_no_args {
                set args [list]
            }
            request_processor::test::a_proc_with_some_flags {
                set args [list -a_flag 1 -another_flag 2]
            }
            request_processor::test::a_proc_with_any_args {
                set args [list 1 2 3 4 5]
            }
            request_processor::test::a_proc_with_flags_and_args {
                set args [list -a_flag 1 -another_flag 2 foo bar]
            }
        }
        regsub -all {:} $proc_name {_} path
        ns_log warning "Registered - $path $proc_name {*}$args"
        ad_register_proc * $path $proc_name $args
    }

    set proc_name request_processor::test::a_proc_with_flags_and_args
    regsub -all {:} $proc_name {_} path
    append path __invoked_without_args
    ad_register_proc * $path $proc_name

    set proc_name request_processor::test::a_proc_with_some_flags
    regsub -all {:} $proc_name {_} path
    append path __invoked_without_args
    ad_register_proc * $path $proc_name
}

request_processor::test::require_registered_procs

aa_register_case \
    -cats {api smoke} \
    -procs {
        ad_register_proc
    } test_ad_register_proc {
        Test that ad_register_proc works as expected. We do so by
        registering procs with different signatures and then trying to
        poke them with HTTP requests.
    } {
        set expected_values [list \
                                 OK \
                                 [list \
                                      a_flag 1 \
                                      another_flag 2] \
                                 [list \
                                      1 2 3 4 5] \
                                 [list \
                                      a_flag 1 \
                                      another_flag 2 \
                                      args [list foo bar]] \
                                 [list \
                                      a_flag DEFAULT1 \
                                      another_flag DEFAULT2] \
                                 [list \
                                      a_flag DEFAULT1 \
                                      another_flag DEFAULT2 \
                                      args [list]] \
                                ]
        set procs [list \
                       request_processor::test::a_proc_with_no_args \
                       request_processor::test::a_proc_with_some_flags \
                       request_processor::test::a_proc_with_any_args \
                       request_processor::test::a_proc_with_flags_and_args]
        set i 0
        foreach proc_name $procs {
            regsub -all {:} $proc_name {_} path
            set r [util::http::get -url [acs::test::url]/$path]
            aa_equals "Request for '$proc_name' successful" [dict get $r status] 200
            aa_equals "Request for '$proc_name' returns the expected value" \
                [join [dict get $r page]] [join [lindex $expected_values $i]]
            incr i
        }

        set procs_invoked_without_args [list \
                                            request_processor::test::a_proc_with_some_flags \
                                            request_processor::test::a_proc_with_flags_and_args]
        foreach proc_name $procs_invoked_without_args {
            regsub -all {:} $proc_name {_} path
            append path __invoked_without_args
            set r [util::http::get -url [acs::test::url]/$path]
            aa_equals "Request for '$proc_name' invoked without args successful" [dict get $r status] 200
            aa_equals "Request for '$proc_name' invoked without args returns the expected value" \
                [join [dict get $r page]] [join [lindex $expected_values $i]]
            incr i
        }
    }


# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: