Source Code Cross Referenced for TestCallIdHeader.java in  » 6.0-JDK-Modules » j2me » javax » microedition » sip » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » javax.microedition.sip 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:         * RFC3261, p. 37; BNF: p. 228
036:         *
037:         * Call-ID = ( "Call-ID" / "i" ) HCOLON callid
038:         * callid  = word [ "@" word ]
039:         *
040:         * The Call-ID header field acts as a unique identifier to group
041:         * together a series of messages.  It MUST be the same for all requests
042:         * and responses sent by either UA in a dialog.  It SHOULD be the same
043:         * in each registration from a UA.
044:         *
045:         * In a new request created by a UAC outside of any dialog, the Call-ID
046:         * header field MUST be selected by the UAC as a globally unique
047:         * identifier over space and time unless overridden by method-specific
048:         * behavior.  All SIP UAs must have a means to guarantee that the Call-
049:         * ID header fields they produce will not be inadvertently generated by
050:         * any other UA.  Note that when requests are retried after certain
051:         * failure responses that solicit an amendment to a request (for
052:         * example, a challenge for authentication), these retried requests are
053:         * not considered new requests, and therefore do not need new Call-ID
054:         * header fields; see Section 8.1.3.5.
055:         *
056:         * Use of cryptographically random identifiers (RFC 1750 [12]) in the
057:         * generation of Call-IDs is RECOMMENDED.  Implementations MAY use the
058:         * form "localid@host".  Call-IDs are case-sensitive and are simply
059:         * compared byte-by-byte.
060:         *
061:         *    Using cryptographically random identifiers provides some
062:         *    protection against session hijacking and reduces the likelihood of
063:         *    unintentional Call-ID collisions.
064:         *
065:         * No provisioning or human interface is required for the selection of
066:         * the Call-ID header field value for a request.
067:         *
068:         * For further information on the Call-ID header field, see Section 20.8.
069:         *
070:         * Example:
071:         *
072:         *    Call-ID: f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com
073:         *
074:         */
075:
076:        public class TestCallIdHeader extends SipHeaderBaseTest {
077:
078:            /** A name of the header that will be tested */
079:            private final String headerName = "Call-ID";
080:
081:            /**
082:             * Body of the test 1.
083:             *
084:             * Test for Call-ID header field: setName()/getName().
085:             */
086:            void Test1() {
087:                // DEBUG:        System.out.println("");
088:                // DEBUG:        System.out.println("*** Test1 started ***");
089:
090:                SipHeader sh;
091:
092:                sh = createSipHeader(headerName,
093:                        "f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com");
094:
095:                if (sh == null) {
096:                    return;
097:                }
098:
099:                // Testing getName()...
100:                String ret_name = sh.getName();
101:                assertTrue("Invalid header value: " + ret_name, ret_name
102:                        .equals(headerName));
103:
104:                // Testing setName()...
105:                try {
106:                    sh.setName(headerName);
107:                } catch (java.lang.IllegalArgumentException e) {
108:                    fail("setName(" + headerName + ") failed (IAE): " + e);
109:                } catch (Throwable e) {
110:                    fail("setName(" + headerName + ") failed: " + e);
111:                }
112:            }
113:
114:            /**
115:             * Body of the test 2.
116:             *
117:             * Test for Call-ID header field: getValue()/getHeaderValue().
118:             */
119:            void Test2() {
120:                String val;
121:                String headerValue = "f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com";
122:
123:                // DEBUG:        System.out.println("");
124:                // DEBUG:        System.out.println("*** Test2 started ***");
125:
126:                SipHeader sh = createSipHeader(headerName, headerValue);
127:
128:                if (sh != null) {
129:                    val = sh.getValue();
130:                    assertTrue("getValue() returned invalid value: '" + val
131:                            + "'", val.equals(headerValue));
132:
133:                    val = sh.getHeaderValue();
134:                    assertTrue("(1) getHeaderValue() returned invalid "
135:                            + "value: '" + val + "'", val.equals(headerValue));
136:
137:                    // Test if the value can be changed.
138:                    headerValue = "test";
139:                    sh.setValue(headerValue);
140:
141:                    val = sh.getHeaderValue();
142:                    assertTrue("(2) getHeaderValue() returned invalid "
143:                            + "value: '" + val + "'", val.equals(headerValue));
144:                }
145:            }
146:
147:            /**
148:             * Body of the test 4.
149:             *
150:             * Test for Call-ID header field: getParameterNames()/getParameter().
151:             */
152:            void Test4() {
153:                // DEBUG:        System.out.println("");
154:                // DEBUG:        System.out.println("*** Test4 started ***");
155:
156:                SipHeader sh = createSipHeader(headerName,
157:                        "f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com");
158:
159:                if (sh == null) {
160:                    return;
161:                }
162:
163:                // Testing getParameterNames()...
164:                String[] paramList = sh.getParameterNames();
165:
166:                if (paramList != null) {
167:                    fail("getParameterNames() should return null!");
168:                }
169:
170:                // Testing getParameter()...
171:                String paramVal = sh.getParameter("ttl");
172:                assertTrue("getParameter() returned '" + paramVal
173:                        + "' for the parameter 'ttl' that doesn't exist.",
174:                        paramVal == null);
175:            }
176:
177:            /**
178:             * Body of the test 5.
179:             *
180:             * Test for Call-ID header field: setParameter()/removeParameter().
181:             */
182:            void Test5() {
183:                // DEBUG:        System.out.println("");
184:                // DEBUG:        System.out.println("*** Test5 started ***");
185:
186:                SipHeader sh = createSipHeader(headerName,
187:                        "f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com");
188:
189:                if (sh == null) {
190:                    return;
191:                }
192:
193:                // Testing setParameter()...
194:                try {
195:                    sh.setParameter("test", "1");
196:                } catch (Exception e) {
197:                    fail(e + " was thrown.");
198:                }
199:
200:                try {
201:                    sh.removeParameter("test");
202:                } catch (Exception e) {
203:                    fail("removeParameter(): " + e + " was thrown!");
204:                }
205:
206:                assertTrue(true); // to avoid error message from the test framework
207:            }
208:
209:            /**
210:             * Run the tests
211:             */
212:            public void runTests() {
213:                declare("setName()/getName()");
214:                Test1();
215:
216:                declare("getValue()/getHeaderValue()");
217:                Test2();
218:
219:                declare("setValue()");
220:                testSetValue(headerName,
221:                        "f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com");
222:
223:                declare("getParameterNames()/getParameter()");
224:                Test4();
225:
226:                declare("setParameter()/removeParameter()");
227:                Test5();
228:
229:                declare("toString()");
230:                testToString(headerName,
231:                        "f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com");
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.