Source Code Cross Referenced for TestToHeader.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. 178
036:         *
037:         * The To header field specifies the logical recipient of the request.
038:         *
039:         * The optional "display-name" is meant to be rendered by a human-user
040:         * interface.  The "tag" parameter serves as a general mechanism for
041:         * dialog identification.
042:         *
043:         * See Section 19.3 for details of the "tag" parameter.
044:         *
045:         * Comparison of To header fields for equality is identical to
046:         * comparison of From header fields.  See Section 20.10 for the rules
047:         * for parsing a display name, URI and URI parameters, and header field
048:         * parameters.
049:         *
050:         * The compact form of the To header field is t.
051:         *
052:         * The following are examples of valid To header fields:
053:         *
054:         *    To: The Operator <sip:operator@cs.columbia.edu>;tag=287447
055:         *    t: sip:+12125551212@server.phone2net.com
056:         *
057:         */
058:
059:        public class TestToHeader extends SipHeaderBaseTest {
060:
061:            /** A name of the header that will be tested */
062:            private final String headerName = "To";
063:
064:            /**
065:             * Body of the test 1.
066:             *
067:             * Test for To header field: setName()/getName().
068:             */
069:            void Test1() {
070:                // DEBUG:        System.out.println("");
071:                // DEBUG:        System.out.println("*** Test1 started ***");
072:
073:                // Testing the constructor...
074:                // testConstructorNegative(headerName, "Invalid Value");
075:
076:                SipHeader sh = createSipHeader(headerName, "The Operator"
077:                        + " <sip:operator@cs.columbia.edu>;tag=287447");
078:
079:                if (sh == null) {
080:                    return;
081:                }
082:
083:                // Testing getName()...
084:                String ret_name = sh.getName();
085:                assertTrue("Invalid header value: " + ret_name, ret_name
086:                        .equals(headerName));
087:
088:                // Testing setName()...
089:                try {
090:                    sh.setName(headerName);
091:                } catch (java.lang.IllegalArgumentException e) {
092:                    fail("setName(" + headerName + ") failed (IAE): " + e);
093:                } catch (Throwable e) {
094:                    fail("setName(" + headerName + ") failed: " + e);
095:                }
096:            }
097:
098:            /**
099:             * Body of the test 2.
100:             *
101:             * Test for To header field: getValue()/getHeaderValue().
102:             */
103:            void Test2() {
104:                SipHeader sh;
105:                String val;
106:                String headerValue1 = "The Operator <sip:operator@cs.columbia.edu>";
107:                String headerValue2 = "<sip:+12125551212@server.phone2net.com>";
108:                String headerParam1 = headerValue1;
109:                String headerParam2 = headerValue2;
110:                String[] paramList = { "tag=287447", "generic=sample_value" };
111:
112:                // DEBUG:        System.out.println("");
113:                // DEBUG:        System.out.println("*** Test2 started ***");
114:
115:                for (int i = 0; i < paramList.length + 1; i++) {
116:                    sh = createSipHeader(headerName, headerParam1);
117:
118:                    if (sh != null) {
119:                        val = sh.getValue();
120:                        assertTrue(
121:                                "getValue() returned invalid parameter value: '"
122:                                        + val + "'", val.equals(headerValue1));
123:
124:                        val = sh.getHeaderValue();
125:                        assertTrue("(1) getHeaderValue() returned invalid "
126:                                + "parameter value: '" + val + "'", val
127:                                .equals(headerParam1));
128:
129:                        // Test if the value can be changed.
130:                        sh.setValue(headerValue2);
131:
132:                        val = sh.getHeaderValue();
133:                        assertTrue("(2) getHeaderValue() returned invalid "
134:                                + "parameter value: '" + val + "'", val
135:                                .equals(headerParam2));
136:                    }
137:
138:                    headerParam1 += ";";
139:                    headerParam2 += ";";
140:
141:                    if (i < paramList.length) {
142:                        headerParam1 += paramList[i];
143:                        headerParam2 += paramList[i];
144:                    }
145:                } // end for
146:            }
147:
148:            /**
149:             * Body of the test 4.
150:             *
151:             * Test for To header field: getParameterNames()/getParameter().
152:             */
153:            void Test4() {
154:                // DEBUG:        System.out.println("");
155:                // DEBUG:        System.out.println("*** Test4 started ***");
156:
157:                SipHeader sh = createSipHeader(headerName, "The Operator"
158:                        + " <sip:operator@cs.columbia.edu>;tag=287447");
159:
160:                if (sh == null) {
161:                    return;
162:                }
163:
164:                // Testing getParameterNames()...
165:                String[] paramList = sh.getParameterNames();
166:                if (paramList == null) {
167:                    fail("getParameterNames() returned null!");
168:                } else {
169:                    assertTrue("getParameterNames() returned "
170:                            + paramList.length + " parameters instead of 1.",
171:                            paramList.length == 1);
172:
173:                    assertTrue("Invalid parameter name: " + paramList[0],
174:                            paramList[0].equals("tag"));
175:                }
176:
177:                // Testing getParameter()...
178:                String paramVal = sh.getParameter("q");
179:                assertTrue("getParameter() returned '" + paramVal
180:                        + "' for the parameter 'q' that doesn't exist.",
181:                        paramVal == null);
182:
183:                paramVal = sh.getParameter("tag");
184:                assertTrue("getParameter() returned '" + paramVal
185:                        + "' for 'tag' instead of 287447.", paramVal
186:                        .equals("287447"));
187:            }
188:
189:            /**
190:             * Body of the test 5.
191:             *
192:             * Test for To header field: setParameter()/removeParameter().
193:             */
194:            void Test5() {
195:                // DEBUG:        System.out.println("");
196:                // DEBUG:        System.out.println("*** Test5 started ***");
197:
198:                SipHeader sh = createSipHeader(headerName, "The Operator"
199:                        + " <sip:operator@cs.columbia.edu>;tag=287447");
200:
201:                if (sh == null) {
202:                    return;
203:                }
204:
205:                // Testing setParameter()...
206:                sh.setParameter("tag", "12345");
207:
208:                String paramVal = sh.getParameter("tag");
209:                assertTrue("getParameter() returned '" + paramVal
210:                        + "' instead of 12345.", paramVal.equals("12345"));
211:
212:                sh.setParameter("q", "10"); // parameter doesn't exist
213:
214:                paramVal = sh.getParameter("q");
215:                assertTrue("getParameter() returned '" + paramVal
216:                        + "' instead of 10.", paramVal.equals("10"));
217:            }
218:
219:            /**
220:             * Run the tests
221:             */
222:            public void runTests() {
223:                String headerParam = "The Operator "
224:                        + "<sip:operator@cs.columbia.edu>;tag=287447";
225:
226:                declare("setName()/getName()");
227:                Test1();
228:
229:                declare("getValue()/getHeaderValue()");
230:                Test2();
231:
232:                declare("setValue()");
233:                testSetValue(headerName, headerParam);
234:
235:                declare("getParameterNames()/getParameter()");
236:                Test4();
237:
238:                declare("setParameter()/removeParameter()");
239:                Test5();
240:
241:                declare("toString()");
242:                testToString(headerName, headerParam);
243:            }
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.