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 javax.microedition.sip.SipClientConnection;
030: import gov.nist.microedition.sip.SipClientConnectionImpl;
031: import javax.microedition.io.Connector;
032: import java.io.OutputStream;
033: import java.io.IOException;
034: import com.sun.midp.i3test.TestCase;
035:
036: /**
037: * Tests for SipConnectionNotifier class.
038: */
039: public class TestSipConnectionNotifier extends TestCase {
040:
041: /**
042: * Body of the test 1.
043: *
044: * Try to establish connection with wrong URI format.
045: */
046: void Test1() {
047: SipConnectionNotifier scn = null;
048: try {
049: // try to create SipConnection object with SCTP transport
050: scn = (SipConnectionNotifier) Connector
051: .open("sip:alice@atlanta.com;transport=sctp");
052: fail("IllegalArgumentException wasn't caused");
053: } catch (SipException e) {
054: if (e.getErrorCode() == SipException.TRANSPORT_NOT_SUPPORTED) {
055: assertTrue("OK", true);
056: } else {
057: fail("SipException was caused with wrong parameter");
058: }
059: } catch (Throwable e) {
060: fail("" + e + " was caused");
061: }
062:
063: try {
064: // try to create SipConnection object with wrong URI
065: // user part is empty when '@' is present
066: scn = (SipConnectionNotifier) Connector
067: .open("sip:@www.sun.com");
068: fail("IllegalArgumentException wasn't caused");
069: } catch (java.lang.IllegalArgumentException e) {
070: assertTrue("IllegalArgumentException was caused", true);
071: } catch (Throwable e) {
072: fail("" + e + " was caused");
073: }
074:
075: try {
076: // try to create SipConnection object with wrong URI
077: // port format is wrong
078: scn = (SipConnectionNotifier) Connector
079: .open("sip:user@www.sun.com:abcd");
080: fail("IllegalArgumentException wasn't caused");
081: } catch (java.lang.IllegalArgumentException e) {
082: assertTrue("IllegalArgumentException was caused", true);
083: } catch (Throwable e) {
084: fail("" + e + " was caused");
085: }
086:
087: try {
088: // try to create SipConnection object with wrong URI
089: // parameter name is not unique
090: scn = (SipConnectionNotifier) Connector
091: .open("sip:user@www.sun.com:1234;par1=val1;par1=val1");
092: fail("IllegalArgumentException wasn't caused");
093: } catch (java.lang.IllegalArgumentException e) {
094: assertTrue("IllegalArgumentException was caused", true);
095: } catch (Throwable e) {
096: fail("" + e + " was caused");
097: }
098: }
099:
100: /**
101: * Create a SipConnectionNotifier and get local port and address
102: */
103: void Test2() {
104: SipConnectionNotifier scn = null;
105: try {
106: // Open SIP server connection and listen to port 8888
107: scn = (SipConnectionNotifier) Connector.open("sip:8888");
108: } catch (Exception ex) {
109: assertNull("Exception during scn open", scn);
110: ex.printStackTrace();
111: }
112: assertNotNull("scn is null", scn);
113:
114: try {
115: assertEquals("Local port is incorrect", scn.getLocalPort(),
116: 8888);
117: } catch (IOException ioe) {
118: fail("IOException in getting local port or address");
119: }
120:
121: try {
122: scn.close();
123: } catch (IOException ioe) {
124: ioe.printStackTrace();
125: }
126: }
127:
128: /**
129: * Create a SipConnectionNotifier with "transport=tcp"
130: */
131: void Test3() {
132: SipConnectionNotifier scn = null;
133: try {
134: // Open SIP server connection and listen to port 9999
135: scn = (SipConnectionNotifier) Connector
136: .open("sip:9999;transport=tcp");
137: assertNotNull("scn is null", scn);
138: scn.close();
139: } catch (Exception ex) {
140: ex.printStackTrace();
141: }
142: }
143:
144: /**
145: * Create a SipConnectionNotifier with explicite "transport=udp"
146: */
147: void Test4() {
148: SipConnectionNotifier scn = null;
149: try {
150: // Open SIP server connection and listen to port 4444
151: scn = (SipConnectionNotifier) Connector.open("sip:8889");
152: assertNotNull("scn is null", scn);
153: scn.close();
154: } catch (Exception ex) {
155: ex.printStackTrace();
156: }
157: }
158:
159: /**
160: * Create a SipConnectionNotifier with explicite "sip:"
161: */
162: void Test5() {
163: SipConnectionNotifier scn = null;
164: try {
165: // Open SIP server connection and listen to port 4444
166: scn = (SipConnectionNotifier) Connector.open("sip:");
167: assertNotNull("scn is null", scn);
168: scn.close();
169: } catch (Exception ex) {
170: ex.printStackTrace();
171: }
172: }
173:
174: /**
175: * Create a SipConnectionNotifier with explicite "sip:;transport=tcp"
176: */
177: void Test6() {
178: SipConnectionNotifier scn = null;
179: try {
180: // Open SIP server connection and listen to port 4444
181: scn = (SipConnectionNotifier) Connector
182: .open("sip:;transport=tcp");
183: assertNotNull("scn is null", scn);
184: scn.close();
185: } catch (Exception ex) {
186: ex.printStackTrace();
187: }
188: }
189:
190: /**
191: * Tests execute
192: *
193: */
194: public void runTests() {
195: declare("Wrong URI format");
196: Test1();
197: declare("SCN Methods");
198: Test2();
199: declare("TCP Transport");
200: Test3();
201: declare("UDP Transport");
202: Test4();
203: declare("sip:");
204: Test5();
205: declare("sip:;transport=tcp");
206: Test6();
207: }
208:
209: }
|