Source Code Cross Referenced for TestLinkMessage.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » links » 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 » com.sun.midp.links 
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 com.sun.midp.links;
028:
029:        import com.sun.cldc.isolate.Isolate;
030:        import com.sun.midp.i3test.TestCase;
031:
032:        /**
033:         * Tests basic operations on the LinkMessage class.
034:         */
035:        public class TestLinkMessage extends TestCase {
036:
037:            /**
038:             * Checks the creation of a data message with subrange arguments to 
039:             * determine whether it throws IndexOutOfBoundsException. Returns a 
040:             * boolean indicating whether IOOBE was thrown.
041:             */
042:            boolean checkRange(byte[] data, int offset, int length) {
043:                boolean thrown = false;
044:
045:                try {
046:                    LinkMessage.newDataMessage(data, offset, length);
047:                } catch (IndexOutOfBoundsException ioobe) {
048:                    thrown = true;
049:                }
050:
051:                return thrown;
052:            }
053:
054:            /**
055:             * Tests a LinkMessage containing a basic byte array (that is, not a 
056:             * subrange).
057:             */
058:            void testData() {
059:                byte[] data = Utils.extractBytes("this is a test string");
060:                LinkMessage lm = LinkMessage.newDataMessage(data);
061:
062:                assertTrue("containsData must return true", lm.containsData());
063:                assertFalse("containsLink must return false", lm.containsLink());
064:                assertFalse("containsString must return false", lm
065:                        .containsString());
066:                assertSame("extract must return same object", data, lm
067:                        .extract());
068:
069:                boolean thrown;
070:                byte[] retData = null;
071:
072:                thrown = false;
073:                try {
074:                    retData = lm.extractData();
075:                } catch (IllegalStateException ise) {
076:                    thrown = true;
077:                }
078:                assertFalse("extractData must not throw exception", thrown);
079:                assertTrue("extractData must return equal data", Utils
080:                        .bytesEqual(data, retData));
081:
082:                thrown = false;
083:                Object obj;
084:                try {
085:                    obj = lm.extractLink();
086:                } catch (IllegalStateException ise) {
087:                    thrown = true;
088:                }
089:                assertTrue("extractLink must throw exception", thrown);
090:
091:                thrown = false;
092:                try {
093:                    obj = lm.extractString();
094:                } catch (IllegalStateException ise) {
095:                    thrown = true;
096:                }
097:                assertTrue("extractString must throw exception", thrown);
098:            }
099:
100:            /**
101:             * Tests a LinkMessage that contains a byte array subrange.
102:             */
103:            void testDataSubrange() {
104:                byte[] data = Utils.extractBytes("this is test data fodder");
105:
106:                assertTrue("offset -7 must throw ioobe", checkRange(data, -7,
107:                        10));
108:                assertTrue("offset 9853 must throw ioobe", checkRange(data,
109:                        9853, 3));
110:                assertTrue("length 2387 must throw ioobe", checkRange(data, 0,
111:                        2387));
112:                assertTrue("length -2 must throw ioobe",
113:                        checkRange(data, 5, -2));
114:                assertTrue("20, 20 must throw ioobe", checkRange(data, 20, 20));
115:
116:                assertFalse("0,0 ok", checkRange(data, 0, 0));
117:                assertFalse("0,len ok", checkRange(data, 0, data.length));
118:                assertFalse("len,0 ok", checkRange(data, data.length, 0));
119:                assertFalse("3,6 ok", checkRange(data, 3, 6));
120:
121:                LinkMessage lm;
122:                byte[] retData;
123:
124:                lm = LinkMessage.newDataMessage(data, 0, data.length);
125:                retData = lm.extractData();
126:                assertTrue("full data", Utils.bytesEqual(data, retData));
127:
128:                byte[] nullData = new byte[0];
129:
130:                lm = LinkMessage.newDataMessage(data, 0, 0);
131:                retData = lm.extractData();
132:                assertTrue("zero null", Utils.bytesEqual(nullData, retData));
133:
134:                lm = LinkMessage.newDataMessage(data, data.length, 0);
135:                retData = lm.extractData();
136:                assertTrue("end null", Utils.bytesEqual(nullData, retData));
137:
138:                lm = LinkMessage.newDataMessage(data, 5, 9);
139:                retData = lm.extractData();
140:                assertTrue("subrange", Utils.bytesEqual(data, 5, 9, retData));
141:            }
142:
143:            /**
144:             * Tests a LinkMessage containing a Link.
145:             */
146:            void testLink() {
147:                Isolate isolate = Isolate.currentIsolate();
148:                Link link = Link.newLink(isolate, isolate);
149:                LinkMessage lm = LinkMessage.newLinkMessage(link);
150:
151:                assertFalse("containsData must return false", lm.containsData());
152:                assertTrue("containsLink must return true", lm.containsLink());
153:                assertFalse("containsString must return false", lm
154:                        .containsString());
155:                assertSame("extract must return same object", link, lm
156:                        .extract());
157:
158:                boolean thrown;
159:                Object obj;
160:
161:                thrown = false;
162:                try {
163:                    obj = lm.extractData();
164:                } catch (IllegalStateException ise) {
165:                    thrown = true;
166:                }
167:                assertTrue("extractData must throw exception", thrown);
168:
169:                thrown = false;
170:                Link retLink = null;
171:                try {
172:                    retLink = lm.extractLink();
173:                } catch (IllegalStateException ise) {
174:                    thrown = true;
175:                }
176:                assertFalse("extractLink must not throw exception", thrown);
177:                assertSame("extractLink must return same link", link, retLink);
178:
179:                thrown = false;
180:                try {
181:                    obj = lm.extractString();
182:                } catch (IllegalStateException ise) {
183:                    thrown = true;
184:                }
185:                assertTrue("extractString must throw exception", thrown);
186:            }
187:
188:            /**
189:             * Tests a LinkMessage containing a String.
190:             */
191:            void testString() {
192:                String msg = "this is a string message";
193:                LinkMessage lm = LinkMessage.newStringMessage(msg);
194:
195:                assertFalse("containsData must return false", lm.containsData());
196:                assertFalse("containsLink must return false", lm.containsLink());
197:                assertTrue("containsString must return true", lm
198:                        .containsString());
199:                assertSame("extract must return same object", msg, lm.extract());
200:
201:                boolean thrown;
202:                Object obj;
203:
204:                thrown = false;
205:                try {
206:                    obj = lm.extractData();
207:                } catch (IllegalStateException ise) {
208:                    thrown = true;
209:                }
210:                assertTrue("extractData must throw exception", thrown);
211:
212:                thrown = false;
213:                try {
214:                    obj = lm.extractLink();
215:                } catch (IllegalStateException ise) {
216:                    thrown = true;
217:                }
218:                assertTrue("extractLink must throw exception", thrown);
219:
220:                thrown = false;
221:                String str = null;
222:                try {
223:                    str = lm.extractString();
224:                } catch (IllegalStateException ise) {
225:                    thrown = true;
226:                }
227:                assertFalse("extractString must not thrown exception", thrown);
228:                assertTrue("strings must match", msg.equals(str));
229:            }
230:
231:            /**
232:             * Runs all tests.
233:             */
234:            public void runTests() {
235:                declare("data");
236:                testData();
237:                declare("data subrange");
238:                testDataSubrange();
239:                declare("link");
240:                testLink();
241:                declare("string");
242:                testString();
243:            }
244:
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.