Source Code Cross Referenced for TestSipClientSetHeader.java in  » 6.0-JDK-Modules » j2me » gov » nist » 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 » gov.nist.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 gov.nist.microedition.sip;
028:
029:        import javax.microedition.sip.*;
030:        import javax.microedition.io.Connector;
031:        import gov.nist.microedition.sip.SipConnectionNotifierImpl;
032:        import gov.nist.microedition.sip.SipClientConnectionImpl;
033:        import gov.nist.siplite.message.Request;
034:        import gov.nist.siplite.header.*;
035:        import gov.nist.siplite.address.*;
036:        import gov.nist.core.*;
037:        import com.sun.midp.i3test.TestCase;
038:
039:        /**
040:         * Tests for SetHeader method of SipClientConnection class.
041:         *
042:         */
043:        public class TestSipClientSetHeader extends TestCase {
044:
045:            /**
046:             * Body of the test 1.
047:             * Checks that on "send" method the "tag" parameter is added
048:             * to "From" header and the "contact" header contains the
049:             * correct port value.
050:             * 
051:             * @param method string representation of the requests method
052:             */
053:            void Test1(String method) {
054:                /** Client connection. */
055:                SipClientConnection sc = null;
056:                SipConnectionNotifier scn = null;
057:                try {
058:                    // Open SIP client connection to the local SIP server
059:                    sc = (SipClientConnection) Connector
060:                            .open("sip:sippy.tester@localhost:5060");
061:                } catch (Exception ex) {
062:                    assertNull("Exception during sc open", sc);
063:                    ex.printStackTrace();
064:                }
065:                assertNotNull("sc is null", sc);
066:
067:                // State of client connection must be "Created"
068:                assertEquals("State is not CREATED",
069:                        ((SipClientConnectionImpl) sc).getState(),
070:                        SipClientConnectionImpl.CREATED);
071:
072:                // Move to INITIALIZED state
073:                try {
074:                    sc.initRequest(method, null);
075:                    sc.setHeader("Content-Type", "text/plain");
076:                } catch (Throwable e) {
077:                    fail("" + e + " was caused");
078:                }
079:
080:                assertEquals("State is not INITIALIZED",
081:                        ((SipClientConnectionImpl) sc).getState(),
082:                        SipClientConnectionImpl.INITIALIZED);
083:
084:                try {
085:                    scn = (SipConnectionNotifier) Connector.open("sip:5090");
086:                    sc.setHeader("From", "sip:sippy.tester@localhost"); // no tag
087:                    sc.setHeader("Subject", "Hello...");
088:                    sc.setHeader("Contact", "sip:user@" + scn.getLocalAddress()
089:                            + ":" + scn.getLocalPort());
090:                    sc.send();
091:                } catch (Throwable e) {
092:                    fail("" + e + " was caused");
093:                }
094:
095:                Request request = ((SipClientConnectionImpl) sc).getRequest();
096:
097:                try {
098:                    // On "send" method "tag" parameter must be added
099:                    FromHeader fromHeader = request.getFromHeader();
100:                    assertNotNull("No \"From\" header in request", fromHeader);
101:                    assertNotNull("No \"Tag\" parameter in \"From\" header",
102:                            fromHeader.getTag());
103:                    // "Contact" header must be correct
104:                    ContactList contacts = request.getContactHeaders();
105:                    assertEquals("Wrong number of contacts", contacts.size(), 1);
106:                    // port number must be 5090
107:                    ContactHeader contact = (ContactHeader) contacts
108:                            .elementAt(0);
109:                    assertEquals("Wrong port number", contact.getHostPort()
110:                            .getPort(), 5090);
111:                } catch (Throwable e) {
112:                    fail("" + e + " was caused");
113:                }
114:
115:                // close connection
116:                try {
117:                    sc.close();
118:                    scn.close();
119:                } catch (Throwable e) {
120:                    fail("" + e + " was caused");
121:                }
122:            }
123:
124:            /**
125:             * Body of the test 2.
126:             *
127:             * Check the transforming TEL URI to SIP URI.
128:             * @param method string representation of the requests method
129:             */
130:            void Test2(String method) {
131:                /** Client connection. */
132:                SipClientConnection sc = null;
133:                try {
134:                    // Open SIP client connection to the local SIP server
135:                    sc = (SipClientConnection) Connector
136:                            .open("sip:sippy.tester@localhost:5060");
137:                } catch (Exception ex) {
138:                    assertNull("Exception during sc open", sc);
139:                    ex.printStackTrace();
140:                }
141:                assertNotNull("sc is null", sc);
142:
143:                // State of client connection must be "Created"
144:                assertEquals("State is not CREATED",
145:                        ((SipClientConnectionImpl) sc).getState(),
146:                        SipClientConnectionImpl.CREATED);
147:
148:                // Move to INITIALIZED state
149:                try {
150:                    sc.initRequest(method, null);
151:                } catch (Throwable e) {
152:                    fail("" + e + " was caused");
153:                }
154:
155:                assertEquals("State is not INITIALIZED",
156:                        ((SipClientConnectionImpl) sc).getState(),
157:                        SipClientConnectionImpl.INITIALIZED);
158:
159:                // Set header with the "tel" scheme
160:                try {
161:                    sc.setHeader("From", "tel:+1234567;postd=9876;isub=3746");
162:                    assertTrue("OK", true);
163:                } catch (Throwable e) {
164:                    fail("" + e + " was caused");
165:                    e.printStackTrace();
166:                }
167:
168:                Request request = ((SipClientConnectionImpl) sc).getRequest();
169:
170:                try {
171:                    // On "send" method "tag" parameter must be added
172:                    FromHeader fromHeader = request.getFromHeader();
173:                    assertNotNull("No \"From\" header in request", fromHeader);
174:                    Address telAddress = fromHeader.getAddress();
175:                    TelURL telURL = (TelURL) (telAddress.getURI());
176:                    assertTrue("Wrong scheme", telURL.getScheme().equals("tel"));
177:                    assertTrue("Wrong isub", telURL.getIsdnSubAddress().equals(
178:                            "3746"));
179:
180:                } catch (Throwable e) {
181:                    fail("" + e + " was caused");
182:                    e.printStackTrace();
183:                }
184:
185:                // Set header with the "tel" scheme with correct isdn-subaddress
186:                // RFC 2806, 2.2
187:                // isdn-subaddress       = ";isub=" 1*phonedigit
188:                // phonedigit            = DIGIT / visual-separator
189:                // visual-separator      = "-" / "." / "(" / ")"
190:                try {
191:                    sc.setHeader("From", "tel:+1234567;isub=01234567890-.()");
192:                    assertTrue("OK", true);
193:                } catch (Throwable e) {
194:                    fail("" + e + " was caused");
195:                    e.printStackTrace();
196:                }
197:                // Set header with the "tel" scheme with wrong isdn-subaddress
198:                try {
199:                    sc.setHeader("From", "tel:+1234567;isub=3A46");
200:                    System.err.println("Test: 1");
201:                    fail("IllegalArgumentException weren't be caused");
202:                } catch (IllegalArgumentException e) {
203:                    assertTrue("OK", true);
204:                } catch (Throwable e) {
205:                    fail("" + e + " was caused");
206:                    e.printStackTrace();
207:                }
208:
209:                // Set header with the "tel" scheme with correct post-dial
210:                // RFC 2806, 2.2
211:                // post-dial             = ";postd=" 1*(phonedigit /
212:                //                         dtmf-digit / pause-character)
213:                // dtmf-digit            = "*" / "#" / "A" / "B" / "C" / "D"
214:                // pause-character       = one-second-pause / wait-for-dial-tone
215:                // one-second-pause      = "p"
216:                // wait-for-dial-tone    = "w"
217:                try {
218:                    sc.setHeader("From",
219:                            "tel:+1234567;postd=01234567890-.()pw*#ABCD");
220:                    assertTrue("OK", true);
221:                } catch (Throwable e) {
222:                    fail("" + e + " was caused");
223:                    e.printStackTrace();
224:                }
225:
226:                // Set header with the "tel" scheme with wrong post-dial
227:                try {
228:                    sc.setHeader("From", "tel:+1234567;postd=9e8w76;isub=3746");
229:                    System.err.println("Test: 2");
230:                    fail("IllegalArgumentException weren't be caused");
231:                } catch (IllegalArgumentException e) {
232:                    assertTrue("OK", true);
233:                } catch (Throwable e) {
234:                    fail("" + e + " was caused");
235:                    e.printStackTrace();
236:                }
237:
238:                // close connection
239:                try {
240:                    sc.close();
241:                } catch (Throwable e) {
242:                    fail("" + e + " was caused");
243:                }
244:
245:            }
246:
247:            /**
248:             * Tests execute
249:             *
250:             */
251:            public void runTests() {
252:                declare("Test1");
253:                Test1("INVITE");
254:                declare("Test2");
255:                Test2("INVITE");
256:            }
257:
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.