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

TestShortHeaderNames

public class TestShortHeaderNames extends SipHeaderBaseTest
Test for support of short forms of headers names.

Fields Summary
private static String[]
shortNames
Compact forms of headers names
private static String[]
fullNames
Full headers names
private static String[]
headerValues
Headers values to set
Constructors Summary
Methods Summary
voidTest1()
Body of the test 1: creating SipHeader with short header's name test.

        SipHeader sh;

        for (int i = 0; i < shortNames.length; i++) {
            sh = createSipHeader(shortNames[i], headerValues[i]);

            if (sh == null) {
                return;
            }

            assertEquals("Invalid header name: " + sh.getName(),
                shortNames[i], sh.getName());

            assertEquals("Invalid header value!",
                headerValues[i], sh.getValue());
        } // end for
    
voidTest2()
Body of the test 2: SipClientConnection methods test.

        SipClientConnection scc = openClientConnection();
        testGetSetHeader(scc);

        try {
            if (scc != null) {
                scc.close();
            }
        } catch (Exception ex) {
        }
    
voidTest3()
Body of the test 3: SipServerConnection methods test.

        SipServerConnection ssc = null;
        SipClientConnection scc = openClientConnection();

        // Open SipServerConnection.
        try {
            SipConnectionNotifier scn =
                (SipConnectionNotifier)Connector.open("sip:5090");
            scc.send();

            ssc = scn.acceptAndOpen();
            ssc.initResponse(200);
        } catch (Exception ex) {
            fail("Exception during ssc open: " + ex);
        }

        testGetSetHeader(ssc);
    
private javax.microedition.sip.SipClientConnectionopenClientConnection()
Opens a new SIP client connection and initializes Init request.

return
newly opened SipClientConnection


                       
       
        // Open SipClientConnection.
        SipClientConnection scc = null;

        try {
            scc = (SipClientConnection)
                Connector.open("sip:sippy.tester@localhost:5090");
        } catch (Exception ex) {
            fail("Exception during Connector.open(): " + ex);
        }

        assertNotNull("scc is null", scc);

        try {
            // Put the connection into the appropriate state
            // to call setHeader().
            scc.initRequest("INVITE", null);
        } catch (Exception ex) {
            fail("Exception during scc.initRequest(): " + ex);
        }

        return scc;
    
public voidrunTests()
Run the tests.

        declare("Creating SipHeader with short header's name test");
        Test1();

        declare("SipClientConnection methods test");
        Test2();

        // Disabled until SipServerConnection.get/setHeader() will be modified.

        // declare("SipServerConnection methods test");
        // Test3();
    
private voidtestGetSetHeader(SipConnection sc)
Tests get/set/removeHeader() methods of SipConnection.

param
sc SIP commection to test

        assertNotNull("sc is null", sc);

        try {
            String[] headerNamesToAdd, headerNamesToRemove;

            for (int j = 0; j < 2; j++) {
                if (j == 0) {
                    // Trying to add a header using its short name
                    // and then trying to remove it using its full name.
                    headerNamesToAdd = shortNames;
                    headerNamesToRemove = fullNames;
                } else {
                    // Use full header's name to add the header,
                    // then use its short name to remove the header.
                    headerNamesToAdd = fullNames;
                    headerNamesToRemove = shortNames;
                }

                // Test set/getHeader().
                for (int i = 0; i < headerNamesToAdd.length; i++) {
                    sc.setHeader(headerNamesToAdd[i], headerValues[i]);

                    // Check that getHeader() returns correct values
                    // both for short and long form of header's name.
                    String val = sc.getHeader(headerNamesToAdd[i]);
                    assertTrue("Invalid '" + headerNamesToAdd[i] +
                        "' header's value: '" + val + "'",
                        headerValues[i].equalsIgnoreCase(val));

                    String name = sc.getHeader(headerNamesToRemove[i]);
                    assertTrue("Invalid '" + headerNamesToRemove[i] +
                        "' header's value: '" + val + "'",
                        headerValues[i].equalsIgnoreCase(val));

                    // Remove the header and check that getHeader()
                    // will return null.
                    sc.removeHeader(headerNamesToRemove[i]);

                    val = sc.getHeader(headerNamesToAdd[i]);
                    assertNull("getHeader(\"" + headerNamesToAdd[i] +
                        "\") returned non-null value!", val);

                    val = sc.getHeader(headerNamesToRemove[i]);
                    assertNull("getHeader(\"" + headerNamesToRemove[i] +
                        "\") returned non-null value!", val);
                } // end for i
            } // end for j
        } catch (Exception ex) {
            fail("Exception during set/getHeader(): " + ex);
        }