01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package javax.microedition.sip;
28:
29: import java.util.Enumeration;
30: import gov.nist.siplite.message.*;
31: import com.sun.midp.i3test.TestCase;
32: import gov.nist.siplite.header.*;
33:
34: /**
35: * Test for Message.attachHeader() method.
36: */
37: public class TestMessageAttachHeader extends TestCase {
38:
39: /**
40: * Body of the test 1: test for attachHeader().
41: */
42: void Test1() {
43: Request request = null;
44: String[] strContacts = {
45: "Contact: <sip:UserB@192.168.200.201>;expires=3600\n",
46: "Contact: <mailto:UserB@biloxi.com>;expires=4294967295\n" };
47:
48: try {
49: request = new Request();
50:
51: request.addHeader(strContacts[0]);
52: request.addHeader(strContacts[1]);
53: } catch (Exception ex) {
54: fail("Exception was thrown: " + ex);
55: }
56:
57: ContactList contacts = request.getContactHeaders();
58: assertNotNull("contacts is null!", contacts);
59: assertEquals("Wrong number of contacts", strContacts.length,
60: contacts.size());
61:
62: Enumeration en = contacts.getElements();
63: int i = 0;
64:
65: while (en.hasMoreElements()) {
66: String hdr = ((Header) en.nextElement()).toString();
67:
68: // Remove trailing '\n' and/or '\r'.
69: int idx1 = hdr.indexOf('\n');
70: int idx2 = hdr.indexOf('\r');
71:
72: if (idx1 >= 0 && idx1 < idx2) {
73: hdr = hdr.substring(0, idx1);
74: } else {
75: if (idx2 >= 0) {
76: hdr = hdr.substring(0, idx2);
77: }
78: }
79:
80: assertEquals("Invalid Contact header value!",
81: strContacts[i], hdr + "\n");
82: i++;
83: }
84:
85: /** TODO: add more test cases. */
86: }
87:
88: /**
89: * Run the tests.
90: */
91: public void runTests() {
92: declare("attachHeader() test");
93: Test1();
94: }
95: }
|