FileDocCategorySizeDatePackage
TestCSeqHeader.javaAPI DocphoneME MR2 API (J2ME)6383Wed May 02 18:00:40 BST 2007javax.microedition.sip

TestCSeqHeader

public class TestCSeqHeader extends SipHeaderBaseTest
RFC3261, p. 38; BNF: p. 229 CSeq = "CSeq" HCOLON 1*DIGIT LWS Method The CSeq header field serves as a way to identify and order transactions. It consists of a sequence number and a method. The method MUST match that of the request. For non-REGISTER requests outside of a dialog, the sequence number value is arbitrary. The sequence number value MUST be expressible as a 32-bit unsigned integer and MUST be less than 2**31. As long as it follows the above guidelines, a client may use any mechanism it would like to select CSeq header field values. Section 12.2.1.1 discusses construction of the CSeq for requests within a dialog. Example: CSeq: 4711 INVITE

Fields Summary
private final String
headerName
A name of the header that will be tested
Constructors Summary
Methods Summary
voidTest1()
Body of the test 1. Test for CSeq header field: setName()/getName().


                    
      
        // DEBUG:        System.out.println("");
        // DEBUG:        System.out.println("*** Test1 started ***");

        SipHeader sh;

        // Test the constructor.
        /*
        try {
            sh = new SipHeader(headerName, "Invalid INVITE");
            fail("Constructor: IAE was not thrown!");
        } catch (IllegalArgumentException iae) {
        }
        */

        sh = createSipHeader(headerName, "4711 INVITE");

        if (sh == null) {
            return;
        }

        // Testing getName()...
        String ret_name = sh.getName();
        assertTrue("Invalid header value: " + ret_name,
            ret_name.equals(headerName));

        // Testing setName()...
        try {
           sh.setName(headerName);
        } catch (java.lang.IllegalArgumentException e) {
            fail("setName(" + headerName + ") failed (IAE): " + e);
        } catch (Throwable e) {
            fail("setName(" + headerName + ") failed: " + e);
        }
    
voidTest2()
Body of the test 2. Test for CSeq header field: getValue()/getHeaderValue().

        String val;
        String headerValue = "4711 INVITE";

        // DEBUG:        System.out.println("");
        // DEBUG:        System.out.println("*** Test2 started ***");

        SipHeader sh = createSipHeader(headerName, headerValue);

        if (sh != null) {
            val = sh.getValue();
            assertTrue("getValue() returned invalid value: '" +
                       val + "'", val.equals(headerValue));

            val = sh.getHeaderValue();
            assertTrue("(1) getHeaderValue() returned invalid " +
                "value: '" + val + "'", val.equals(headerValue));

            // Test if the value can be changed.
            headerValue = "12345 REGISTER";
            sh.setValue(headerValue);

            val = sh.getHeaderValue();
            assertTrue("(2) getHeaderValue() returned invalid " +
                "value: '" + val + "'", val.equals(headerValue));
        }
    
voidTest4()
Body of the test 4. Test for CSeq header field: getParameterNames()/getParameter().

        // DEBUG:        System.out.println("");
        // DEBUG:        System.out.println("*** Test4 started ***");

        SipHeader sh = createSipHeader(headerName, "4711 INVITE");

        if (sh == null) {
            return;
        }

        // Testing getParameterNames()...
        String[] paramList = sh.getParameterNames();

        if (paramList != null) {
            fail("getParameterNames() should return null!");
        }

        // Testing getParameter()...
        String paramVal = sh.getParameter("ttl");
        assertTrue("getParameter() returned '" + paramVal +
            "' for the parameter 'ttl' that doesn't exist.", paramVal == null);
    
voidTest5()
Body of the test 5. Test for CSeq header field: setParameter()/removeParameter().

        // DEBUG:        System.out.println("");
        // DEBUG:        System.out.println("*** Test5 started ***");

        SipHeader sh = createSipHeader(headerName, "4711 INVITE");

        if (sh == null) {
            return;
        }

        // Testing setParameter()...
        try {
            sh.setParameter("test", "192.0.0.1");
        } catch (Exception e) {
            fail(e + " was thrown.");
        }

        try {
            sh.removeParameter("test");
        } catch (Exception e) {
            fail("removeParameter(): " + e + " was thrown!");
        }

        assertTrue(true); // to avoid error message from the test framework
    
public voidrunTests()
Run the tests

        declare("setName()/getName()");
        Test1();

        declare("getValue()/getHeaderValue()");
        Test2();

        declare("setValue()");
        testSetValue(headerName, "4711 INVITE");

        declare("getParameterNames()/getParameter()");
        Test4();

        declare("setParameter()/removeParameter()");
        Test5();

        declare("toString()");
        testToString(headerName, "4711 INVITE");