OpenTTCN/Knowledge base/Creating NETCONF Over SOAP XML Codec/CodecTest.ttcn

From OpenTTCN

Jump to: navigation, search

  OpenTTCN DocZone

  Home | Developer's corner | Knowledge base | Working documents | Documentation | OpenTTCN IDE | Tutorials | Training | How do I | Frequently asked questions | Technical support


CodecTest.ttcn


Back to main article >>

module CodecTest
{

import from urn_ietf_params_xml_ns_netconf_base_1_0 all;

import from http_schemas_xmlsoap_org_soap_envelope_ all;
import from http_schemas_xmlsoap_org_soap_encoding_ all;

import from UsefulTypes all;
import from XSD all;

type component ComponentType
{
}

testcase TC_CodecTest()
    runs on ComponentType
{
    log("****************** Group 1 ******************");

    var template Envelope v_soapenv :=
    {
        header := omit,
        body :=
        {
            elem_list :=
            {
                {
                    urn_ietf_params_xml_ns_netconf_base_1_0 :=
                    {
                        Hello :=
                        {
                            capabilities :=
                            {
                                capability_list := { "urn:ietf:params:netconf:base:1.0" }
                            },
                            session_id := omit
                        }
                    }
                }
            },

            attr := { }
        },
        elem_list := { },
        attr :=
        {
            "xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"""
        }
    }

    log("Type : http_schemas_xmlsoap_org_soap_envelope_.Envelope", v_soapenv);

    var bitstring bs := encvalue(v_soapenv);
    var charstring cs := oct2char(bit2oct(bs));

    log("encoded:", cs);

    var Envelope v_soapenv_2;
    var integer rv := decvalue(bs, v_soapenv_2);

    log("decoded:", v_soapenv_2);

    if (v_soapenv_2 == valueof(v_soapenv))
    { setverdict(pass); } else { setverdict(fail, "decoded value mismatch"); stop; }

    log("****************** Group 2 ******************");

    v_soapenv :=
    {
        header := omit,
        body :=
        {
            elem_list :=
            {
                {
                    Hello :=
                    {
                        capabilities :=
                        {
                            capability_list :=
                            {
                                "urn:ietf:params:netconf:base:1.0",
                                "urn:ietf:params:netconf:capability:startup:1.0",
                                "http:/example.net/router/2.3/myfeature"
                            }
                        },
                        session_id := 4
                    }
                }
            },

            attr := { }
        },
        elem_list := { },
        attr :=
        {
            "xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"""
        }
    }

    // This step is optional and is made only to make original and decoded values
    // identical to each other:
    v_soapenv.body.elem_list[0].urn_ietf_params_xml_ns_netconf_base_1_0.Hello :=
        v_soapenv.body.elem_list[0].Hello;

    log("Type : http_schemas_xmlsoap_org_soap_envelope_.Envelope", v_soapenv);

    bs := encvalue(v_soapenv);
    cs := oct2char(bit2oct(bs));

    log("encoded:", cs);

    rv := decvalue(bs, v_soapenv_2);

    log("decoded:", v_soapenv_2);

    if (v_soapenv_2 == valueof(v_soapenv))
    { setverdict(pass); } else { setverdict(fail, "decoded value mismatch"); stop; }
}

}
Views
Personal tools