Source Code Cross Referenced for TestBasicTokenIterator.java in  » Net » httpcomponents-core-4.0-beta1 » org » apache » http » message » 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 » Net » httpcomponents core 4.0 beta1 » org.apache.http.message 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-main/src/test/java/org/apache/http/message/TestBasicTokenIterator.java $
003:         * $Revision: 601000 $
004:         * $Date: 2007-12-04 18:03:49 +0100 (Tue, 04 Dec 2007) $
005:         * ====================================================================
006:         * Licensed to the Apache Software Foundation (ASF) under one
007:         * or more contributor license agreements.  See the NOTICE file
008:         * distributed with this work for additional information
009:         * regarding copyright ownership.  The ASF licenses this file
010:         * to you under the Apache License, Version 2.0 (the
011:         * "License"); you may not use this file except in compliance
012:         * with the License.  You may obtain a copy of the License at
013:         *
014:         *   http://www.apache.org/licenses/LICENSE-2.0
015:         *
016:         * Unless required by applicable law or agreed to in writing,
017:         * software distributed under the License is distributed on an
018:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
019:         * KIND, either express or implied.  See the License for the
020:         * specific language governing permissions and limitations
021:         * under the License.
022:         * ====================================================================
023:         *
024:         * This software consists of voluntary contributions made by many
025:         * individuals on behalf of the Apache Software Foundation.  For more
026:         * information on the Apache Software Foundation, please see
027:         * <http://www.apache.org/>.
028:         *
029:         */
030:
031:        package org.apache.http.message;
032:
033:        import java.util.NoSuchElementException;
034:
035:        import junit.framework.Test;
036:        import junit.framework.TestCase;
037:        import junit.framework.TestSuite;
038:
039:        import org.apache.http.Header;
040:        import org.apache.http.HeaderIterator;
041:        import org.apache.http.TokenIterator;
042:        import org.apache.http.ParseException;
043:
044:        /**
045:         * Tests for {@link BasicTokenIterator}.
046:         *
047:         * @version $Revision: 601000 $
048:         */
049:        public class TestBasicTokenIterator extends TestCase {
050:
051:            // ------------------------------------------------------------ Constructor
052:            public TestBasicTokenIterator(String testName) {
053:                super (testName);
054:            }
055:
056:            // ------------------------------------------------------------------- Main
057:            public static void main(String args[]) {
058:                String[] testCaseName = { TestBasicTokenIterator.class
059:                        .getName() };
060:                junit.textui.TestRunner.main(testCaseName);
061:            }
062:
063:            // ------------------------------------------------------- TestCase Methods
064:
065:            public static Test suite() {
066:                return new TestSuite(TestBasicTokenIterator.class);
067:            }
068:
069:            public void testSingleHeader() {
070:                Header[] headers = new Header[] { new BasicHeader("Name",
071:                        "token0,token1, token2 , token3") };
072:                HeaderIterator hit = new BasicHeaderIterator(headers, null);
073:                TokenIterator ti = new BasicTokenIterator(hit);
074:
075:                assertTrue(ti.hasNext());
076:                assertEquals("token0", "token0", ti.nextToken());
077:                assertTrue(ti.hasNext());
078:                assertEquals("token1", "token1", ti.nextToken());
079:                assertTrue(ti.hasNext());
080:                assertEquals("token2", "token2", ti.nextToken());
081:                assertTrue(ti.hasNext());
082:                assertEquals("token3", "token3", ti.nextToken());
083:                assertFalse(ti.hasNext());
084:
085:                headers = new Header[] { new BasicHeader("Name", "token0") };
086:                hit = new BasicHeaderIterator(headers, null);
087:                ti = new BasicTokenIterator(hit);
088:
089:                assertTrue(ti.hasNext());
090:                assertEquals("token0", "token0", ti.nextToken());
091:                assertFalse(ti.hasNext());
092:            }
093:
094:            public void testMultiHeader() {
095:                Header[] headers = new Header[] {
096:                        new BasicHeader("Name", "token0,token1"),
097:                        new BasicHeader("Name", ""),
098:                        new BasicHeader("Name", "token2"),
099:                        new BasicHeader("Name", " "),
100:                        new BasicHeader("Name", "token3 "),
101:                        new BasicHeader("Name", ","),
102:                        new BasicHeader("Name", "token4"), };
103:                HeaderIterator hit = new BasicHeaderIterator(headers, null);
104:                TokenIterator ti = new BasicTokenIterator(hit);
105:
106:                assertTrue(ti.hasNext());
107:                assertEquals("token0", "token0", ti.nextToken());
108:                assertTrue(ti.hasNext());
109:                assertEquals("token1", "token1", ti.nextToken());
110:                assertTrue(ti.hasNext());
111:                assertEquals("token2", "token2", ti.nextToken());
112:                assertTrue(ti.hasNext());
113:                assertEquals("token3", "token3", ti.nextToken());
114:                assertTrue(ti.hasNext());
115:                assertEquals("token4", "token4", ti.nextToken());
116:                assertFalse(ti.hasNext());
117:            }
118:
119:            public void testEmpty() {
120:                Header[] headers = new Header[] { new BasicHeader("Name", " "),
121:                        new BasicHeader("Name", ""),
122:                        new BasicHeader("Name", ","),
123:                        new BasicHeader("Name", " ,, "), };
124:                HeaderIterator hit = new BasicHeaderIterator(headers, null);
125:                TokenIterator ti = new BasicTokenIterator(hit);
126:
127:                assertFalse(ti.hasNext());
128:
129:                hit = new BasicHeaderIterator(headers, "empty");
130:                ti = new BasicTokenIterator(hit);
131:
132:                assertFalse(ti.hasNext());
133:            }
134:
135:            public void testValueStart() {
136:                Header[] headers = new Header[] {
137:                        new BasicHeader("Name", "token0"),
138:                        new BasicHeader("Name", " token1"),
139:                        new BasicHeader("Name", ",token2"),
140:                        new BasicHeader("Name", " ,token3"),
141:                        new BasicHeader("Name", ", token4"),
142:                        new BasicHeader("Name", " , token5"), };
143:                HeaderIterator hit = new BasicHeaderIterator(headers, null);
144:                TokenIterator ti = new BasicTokenIterator(hit);
145:
146:                assertTrue(ti.hasNext());
147:                assertEquals("token0", "token0", ti.nextToken());
148:                assertTrue(ti.hasNext());
149:                assertEquals("token1", "token1", ti.nextToken());
150:                assertTrue(ti.hasNext());
151:                assertEquals("token2", "token2", ti.nextToken());
152:                assertTrue(ti.hasNext());
153:                assertEquals("token3", "token3", ti.nextToken());
154:                assertTrue(ti.hasNext());
155:                assertEquals("token4", "token4", ti.nextToken());
156:                assertTrue(ti.hasNext());
157:                assertEquals("token5", "token5", ti.nextToken());
158:                assertFalse(ti.hasNext());
159:            }
160:
161:            public void testValueEnd() {
162:                Header[] headers = new Header[] {
163:                        new BasicHeader("Name", "token0"),
164:                        new BasicHeader("Name", "token1 "),
165:                        new BasicHeader("Name", "token2,"),
166:                        new BasicHeader("Name", "token3 ,"),
167:                        new BasicHeader("Name", "token4, "),
168:                        new BasicHeader("Name", "token5 , "), };
169:                HeaderIterator hit = new BasicHeaderIterator(headers, null);
170:                TokenIterator ti = new BasicTokenIterator(hit);
171:
172:                assertTrue(ti.hasNext());
173:                assertEquals("token0", "token0", ti.nextToken());
174:                assertTrue(ti.hasNext());
175:                assertEquals("token1", "token1", ti.nextToken());
176:                assertTrue(ti.hasNext());
177:                assertEquals("token2", "token2", ti.nextToken());
178:                assertTrue(ti.hasNext());
179:                assertEquals("token3", "token3", ti.nextToken());
180:                assertTrue(ti.hasNext());
181:                assertEquals("token4", "token4", ti.nextToken());
182:                assertTrue(ti.hasNext());
183:                assertEquals("token5", "token5", ti.nextToken());
184:                assertFalse(ti.hasNext());
185:            }
186:
187:            public void testTokenChar() {
188:                Header[] headers = new Header[] { new BasicHeader("Name",
189:                        "token0") };
190:                HeaderIterator hit = new BasicHeaderIterator(headers, null);
191:                BasicTokenIterator bti = new BasicTokenIterator(hit);
192:
193:                assertTrue("letter", bti.isTokenChar('j'));
194:                assertFalse("control", bti.isTokenChar('\b'));
195:                assertFalse("separator", bti.isTokenChar('?'));
196:                assertTrue("other", bti.isTokenChar('-'));
197:            }
198:
199:            public void testInvalid() {
200:                Header[] headers = new Header[] {
201:                        new BasicHeader("in", "token0=token1"),
202:                        new BasicHeader("no", "token0 token1"),
203:                        new BasicHeader("pre", "<token0,token1"),
204:                        new BasicHeader("post", "token0,token1="), };
205:                HeaderIterator hit = new BasicHeaderIterator(headers, "in");
206:                TokenIterator ti = new BasicTokenIterator(hit);
207:
208:                // constructor located token0
209:                assertTrue(ti.hasNext());
210:                try {
211:                    ti.nextToken();
212:                    fail("invalid infix character not detected");
213:                } catch (ParseException px) {
214:                    // expected
215:                }
216:
217:                // constructor located token0
218:                hit = new BasicHeaderIterator(headers, "no");
219:                ti = new BasicTokenIterator(hit);
220:                assertTrue(ti.hasNext());
221:                try {
222:                    ti.nextToken();
223:                    fail("missing token separator not detected");
224:                } catch (ParseException px) {
225:                    // expected
226:                }
227:
228:                // constructor seeks for the first token
229:                hit = new BasicHeaderIterator(headers, "pre");
230:                try {
231:                    new BasicTokenIterator(hit);
232:                    fail("invalid prefix character not detected");
233:                } catch (ParseException px) {
234:                    // expected
235:                }
236:
237:                hit = new BasicHeaderIterator(headers, "post");
238:                ti = new BasicTokenIterator(hit);
239:
240:                assertTrue(ti.hasNext());
241:                assertEquals("token0", "token0", ti.nextToken());
242:                assertTrue(ti.hasNext());
243:                // failure after the last must not go unpunished
244:                try {
245:                    ti.nextToken();
246:                    fail("invalid postfix character not detected");
247:                } catch (ParseException px) {
248:                    // expected
249:                }
250:            }
251:
252:            public void testWrongPublic() {
253:
254:                try {
255:                    new BasicTokenIterator(null);
256:                    fail("null argument not detected");
257:                } catch (IllegalArgumentException iax) {
258:                    // expected
259:                }
260:
261:                Header[] headers = new Header[] { new BasicHeader("Name", " "),
262:                        new BasicHeader("Name", ""),
263:                        new BasicHeader("Name", ","),
264:                        new BasicHeader("Name", " ,, "), };
265:                HeaderIterator hit = new BasicHeaderIterator(headers, null);
266:                TokenIterator ti = new BasicTokenIterator(hit);
267:
268:                try {
269:                    // call next() instead of nextToken() to get that covered, too
270:                    ti.next();
271:                    fail("next after end not detected");
272:                } catch (NoSuchElementException nsx) {
273:                    // expected
274:                }
275:
276:                try {
277:                    ti.remove();
278:                    fail("unsupported remove not detected");
279:                } catch (UnsupportedOperationException uox) {
280:                    // expected
281:                }
282:            }
283:
284:            public void testWrongProtected() {
285:
286:                Header[] headers = new Header[] { new BasicHeader("Name",
287:                        "token1,token2") };
288:                HeaderIterator hit = new BasicHeaderIterator(headers, null);
289:                BasicTokenIterator bti = new BasicTokenIterator(hit);
290:
291:                try {
292:                    bti.findTokenStart(-1);
293:                    fail("tokenStart: negative index not detected");
294:                } catch (IllegalArgumentException iax) {
295:                    // expected
296:                }
297:
298:                try {
299:                    bti.findTokenSeparator(-1);
300:                    fail("tokenSeparator: negative index not detected");
301:                } catch (IllegalArgumentException iax) {
302:                    // expected
303:                }
304:
305:                try {
306:                    bti.findTokenEnd(-1);
307:                    fail("tokenEnd: negative index not detected");
308:                } catch (IllegalArgumentException iax) {
309:                    // expected
310:                }
311:            }
312:
313:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.