Source Code Cross Referenced for TestMaxForwardsHeader.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. 39; BNF: p. 230
036:         *
037:         * Max-Forwards = "Max-Forwards" HCOLON 1*DIGIT
038:         *
039:         * The Max-Forwards header field serves to limit the number of hops a
040:         * request can transit on the way to its destination.  It consists of an
041:         * integer that is decremented by one at each hop.  If the Max-Forwards
042:         * value reaches 0 before the request reaches its destination, it will
043:         * be rejected with a 483(Too Many Hops) error response.
044:         *
045:         * A UAC MUST insert a Max-Forwards header field into each request it
046:         * originates with a value that SHOULD be 70.  This number was chosen to
047:         * be sufficiently large to guarantee that a request would not be
048:         * dropped in any SIP network when there were no loops, but not so large
049:         * as to consume proxy resources when a loop does occur.  Lower values
050:         * should be used with caution and only in networks where topologies are
051:         * known by the UA.
052:         */
053:
054:        public class TestMaxForwardsHeader extends SipHeaderBaseTest {
055:
056:            /** A name of the header that will be tested */
057:            private final String headerName = "Max-Forwards";
058:
059:            /**
060:             * Body of the test 1.
061:             *
062:             * Test for Max-Forwards header field: setName()/getName().
063:             */
064:            void Test1() {
065:                // DEBUG:        System.out.println("");
066:                // DEBUG:        System.out.println("*** Test1 started ***");
067:
068:                // Testing the constructor...
069:                // testConstructorNegative(headerName, "Invalid Value");
070:
071:                SipHeader sh = createSipHeader(headerName, "100");
072:
073:                if (sh == null) {
074:                    return;
075:                }
076:
077:                // Testing getName()...
078:                String ret_name = sh.getName();
079:                assertTrue("Invalid header value: " + ret_name, ret_name
080:                        .equals(headerName));
081:
082:                // Testing setName()...
083:                try {
084:                    sh.setName(headerName);
085:                } catch (java.lang.IllegalArgumentException e) {
086:                    fail("setName(" + headerName + ") failed (IAE): " + e);
087:                } catch (Throwable e) {
088:                    fail("setName(" + headerName + ") failed: " + e);
089:                }
090:            }
091:
092:            /**
093:             * Body of the test 2.
094:             *
095:             * Test for Max-Forwards header field: getValue()/getHeaderValue().
096:             */
097:            void Test2() {
098:                String val;
099:                String headerValue = "10";
100:
101:                // DEBUG:        System.out.println("");
102:                // DEBUG:        System.out.println("*** Test2 started ***");
103:
104:                SipHeader sh = createSipHeader(headerName, headerValue);
105:
106:                if (sh != null) {
107:                    val = sh.getValue();
108:                    assertTrue("getValue() returned invalid value: '" + val
109:                            + "'", val.equals(headerValue));
110:
111:                    val = sh.getHeaderValue();
112:                    assertTrue("(1) getHeaderValue() returned invalid "
113:                            + "value: '" + val + "'", val.equals(headerValue));
114:
115:                    // Test if the value can be changed.
116:                    headerValue = "70";
117:                    sh.setValue(headerValue);
118:
119:                    val = sh.getHeaderValue();
120:                    assertTrue("(2) getHeaderValue() returned invalid "
121:                            + "value: '" + val + "'", val.equals(headerValue));
122:                }
123:            }
124:
125:            /**
126:             * Body of the test 4.
127:             *
128:             * Test for Max-Forwards header field: getParameterNames()/getParameter().
129:             */
130:            void Test4() {
131:                // DEBUG:        System.out.println("");
132:                // DEBUG:        System.out.println("*** Test4 started ***");
133:
134:                SipHeader sh = createSipHeader(headerName, "70");
135:
136:                if (sh == null) {
137:                    return;
138:                }
139:
140:                // Testing getParameterNames()...
141:                String[] paramList = sh.getParameterNames();
142:
143:                if (paramList != null) {
144:                    fail("getParameterNames() should return null!");
145:                }
146:
147:                // Testing getParameter()...
148:                String paramVal = sh.getParameter("ttl");
149:                assertTrue("getParameter() returned '" + paramVal
150:                        + "' for the parameter 'ttl' that doesn't exist.",
151:                        paramVal == null);
152:            }
153:
154:            /**
155:             * Body of the test 5.
156:             *
157:             * Test for Max-Forwards header field: setParameter()/removeParameter().
158:             */
159:            void Test5() {
160:                // DEBUG:        System.out.println("");
161:                // DEBUG:        System.out.println("*** Test5 started ***");
162:
163:                SipHeader sh = createSipHeader(headerName, "70");
164:
165:                if (sh == null) {
166:                    return;
167:                }
168:
169:                // Testing setParameter()...
170:                try {
171:                    sh.setParameter("test", "1");
172:                } catch (Exception e) {
173:                    fail(e + " was thrown.");
174:                }
175:
176:                try {
177:                    sh.removeParameter("test");
178:                } catch (Exception e) {
179:                    fail("removeParameter(): " + e + " was thrown!");
180:                }
181:
182:                assertTrue(true); // to avoid error message from the test framework
183:            }
184:
185:            /**
186:             * Run the tests
187:             */
188:            public void runTests() {
189:                declare("setName()/getName()");
190:                Test1();
191:
192:                declare("getValue()/getHeaderValue()");
193:                Test2();
194:
195:                declare("setValue()");
196:                testSetValue(headerName, "70");
197:
198:                declare("getParameterNames()/getParameter()");
199:                Test4();
200:
201:                declare("setParameter()/removeParameter()");
202:                Test5();
203:
204:                declare("toString()");
205:                testToString(headerName, "70");
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.