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

TestMessageAttachHeader

public class TestMessageAttachHeader extends com.sun.midp.i3test.TestCase
Test for Message.attachHeader() method.

Fields Summary
Constructors Summary
Methods Summary
voidTest1()
Body of the test 1: test for attachHeader().

        Request request = null;
        String[] strContacts = {
            "Contact: <sip:UserB@192.168.200.201>;expires=3600\n",
            "Contact: <mailto:UserB@biloxi.com>;expires=4294967295\n"
        };

        try {
            request = new Request();

            request.addHeader(strContacts[0]);
            request.addHeader(strContacts[1]);
        } catch (Exception ex) {
            fail("Exception was thrown: " + ex);
        }

        ContactList contacts = request.getContactHeaders();
        assertNotNull("contacts is null!", contacts);
        assertEquals("Wrong number of contacts",
            strContacts.length, contacts.size());

        Enumeration en = contacts.getElements();
        int i = 0;

        while (en.hasMoreElements()) {
            String hdr = ((Header)en.nextElement()).toString();

            // Remove trailing '\n' and/or '\r'.
            int idx1 = hdr.indexOf('\n");
            int idx2 = hdr.indexOf('\r");

            if (idx1 >= 0  && idx1 < idx2) {
                hdr = hdr.substring(0, idx1);
            } else {
                if (idx2 >= 0) {
                    hdr = hdr.substring(0, idx2);
                }
            }

            assertEquals("Invalid Contact header value!",
                strContacts[i], hdr + "\n");
            i++;
        }

        /** TODO: add more test cases. */
    
public voidrunTests()
Run the tests.

        declare("attachHeader() test");
        Test1();