001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package javax.microedition.sip;
028:
029: import com.sun.midp.i3test.TestCase;
030:
031: import javax.microedition.io.Connector;
032: import java.io.IOException;
033:
034: /**
035: * This class is used to test TestParameterLessHeader class.
036: */
037: public class TestParameterLessHeader extends SipHeaderBaseTest {
038:
039: /**
040: * Array of the headers that can not have any parameters.
041: * See Header.java.
042: */
043: private static final String[] parameterLessHeaders = {
044: "Authentication-Info",
045: "Allow",
046: "In-Reply-To",
047: "Priority",
048: "Mime-Version",
049: "Server",
050: "Timestamp",
051: "User-Agent",
052: "Min-Expires",
053: "Subject",
054: // This header has the corresponding class and parser.
055: // It should not be tested as "parameterless", pl. refer
056: // to the comments in Header.java.
057: // "Content-Length",
058: "Content-Language", "Warning", "Content-Encoding",
059: "Organization", "Unsupported", "Require", "Supported",
060: "Proxy-Require" };
061:
062: /**
063: * Body of the test 1.
064: *
065: * Test for "parameter-less" headers.
066: */
067: void Test1() {
068: SipHeader sh;
069: String headerName;
070:
071: for (int i = 0; i < parameterLessHeaders.length; i++) {
072: headerName = parameterLessHeaders[i];
073:
074: sh = createSipHeader(headerName, "INVITE;test=10");
075: assertTrue("Cannot create '" + headerName + "' header!",
076: sh != null);
077:
078: // Ensure that the header was not parsed
079: assertTrue("Header '" + headerName + "' was parsed!", sh
080: .getValue().equals(sh.getHeaderValue()));
081:
082: String[] paramNames = sh.getParameterNames();
083: assertTrue("'" + headerName + "' header must not have "
084: + "any parameters!", paramNames == null);
085:
086: String param = sh.getParameter("test");
087: assertTrue("'" + headerName
088: + "' header has not parameter 'test'!",
089: param == null);
090:
091: try {
092: sh.setParameter("test", "1");
093: fail("IAE was not thrown!");
094: } catch (IllegalArgumentException iae) {
095: // System.out.println(headerName + " OK!");
096: } catch (Exception e) {
097: fail("Exception was caught: " + e);
098: }
099: } // end for()
100: }
101:
102: /**
103: * Run the tests
104: */
105: public void runTests() {
106: declare("ParameterLessHeader class test");
107: Test1();
108: }
109:
110: }
|