Source Code Cross Referenced for HTMLDocument_Reader_FormActionTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » text » html » 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 » Apache Harmony Java SE » javax package » javax.swing.text.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Alexander T. Simbirtsev
019:         * @version $Revision$
020:         */package javax.swing.text.html;
021:
022:        import javax.swing.DefaultButtonModel;
023:        import javax.swing.DefaultComboBoxModel;
024:        import javax.swing.DefaultListModel;
025:        import javax.swing.JToggleButton;
026:        import javax.swing.text.AttributeSet;
027:        import javax.swing.text.PlainDocument;
028:        import javax.swing.text.SimpleAttributeSet;
029:        import javax.swing.text.StyleConstants;
030:        import javax.swing.text.DefaultStyledDocument.ElementSpec;
031:        import javax.swing.text.html.HTML.Tag;
032:
033:        import org.apache.harmony.x.swing.text.html.form.FormFieldsetModel;
034:        import org.apache.harmony.x.swing.text.html.form.FormOption;
035:
036:        public class HTMLDocument_Reader_FormActionTest extends
037:                HTMLDocumentTestCase {
038:
039:            protected HTMLDocument.HTMLReader reader;
040:            protected HTMLDocument doc;
041:            protected HTMLDocument.HTMLReader.TagAction action;
042:
043:            protected void setUp() throws Exception {
044:                super .setUp();
045:                doc = new HTMLDocument();
046:                reader = (HTMLDocument.HTMLReader) doc.getReader(0);
047:            }
048:
049:            protected void tearDown() throws Exception {
050:                action = null;
051:                doc = null;
052:                reader = null;
053:                super .tearDown();
054:            }
055:
056:            public void testFormStart_InputButton() throws Exception {
057:                if (isHarmony()) {
058:                    checkStandardInputStart("button", DefaultButtonModel.class);
059:                }
060:            }
061:
062:            public void testFormEnd_InputButton() throws Exception {
063:                checkEmptyFormEnd(Tag.INPUT, "button");
064:            }
065:
066:            public void testFormStart_InputCheckBox() throws Exception {
067:                checkStandardInputStart("checkbox",
068:                        JToggleButton.ToggleButtonModel.class);
069:            }
070:
071:            public void testFormEnd_InputCheckBox() throws Exception {
072:                checkEmptyFormEnd(Tag.INPUT, "checkbox");
073:            }
074:
075:            public void testFormStart_InputImage() throws Exception {
076:                checkStandardInputStart("image", DefaultButtonModel.class);
077:            }
078:
079:            public void testFormEnd_InputImage() throws Exception {
080:                checkEmptyFormEnd(Tag.INPUT, "image");
081:            }
082:
083:            public void testFormStart_InputRadio() throws Exception {
084:                checkStandardInputStart("radio",
085:                        JToggleButton.ToggleButtonModel.class);
086:            }
087:
088:            public void testFormEnd_InputRadio() throws Exception {
089:                checkEmptyFormEnd(Tag.INPUT, "radio");
090:            }
091:
092:            public void testForm_InputRadioGroups() throws Exception {
093:                String name1 = "name1";
094:                String name2 = "name2";
095:                String name3 = "";
096:                action = reader.new FormAction();
097:
098:                reader.handleStartTag(Tag.FORM, new SimpleAttributeSet(), 0);
099:                reader.handleStartTag(Tag.INPUT,
100:                        createInputNamedAttributes(name1), 0);
101:                reader.handleStartTag(Tag.INPUT,
102:                        createInputNamedAttributes(name2), 0);
103:                reader.handleStartTag(Tag.INPUT,
104:                        createInputNamedAttributes(name3), 0);
105:                reader.handleStartTag(Tag.INPUT,
106:                        createInputNamedAttributes(name1), 0);
107:                reader.handleStartTag(Tag.INPUT,
108:                        createInputNamedAttributes(null), 0);
109:                reader.handleStartTag(Tag.INPUT,
110:                        createInputNamedAttributes(name2), 0);
111:                reader.handleStartTag(Tag.INPUT,
112:                        createInputNamedAttributes(name3), 0);
113:                reader.handleStartTag(Tag.INPUT,
114:                        createInputNamedAttributes(null), 0);
115:                reader.handleEndTag(Tag.FORM, 0);
116:                assertEquals(0, reader.charAttr.getAttributeCount());
117:                assertEquals(13, reader.parseBuffer.size());
118:
119:                DefaultButtonModel model1 = (DefaultButtonModel) getModel((ElementSpec) reader.parseBuffer
120:                        .get(2));
121:                DefaultButtonModel model2 = (DefaultButtonModel) getModel((ElementSpec) reader.parseBuffer
122:                        .get(3));
123:                DefaultButtonModel model3 = (DefaultButtonModel) getModel((ElementSpec) reader.parseBuffer
124:                        .get(4));
125:                DefaultButtonModel model4 = (DefaultButtonModel) getModel((ElementSpec) reader.parseBuffer
126:                        .get(5));
127:                DefaultButtonModel model5 = (DefaultButtonModel) getModel((ElementSpec) reader.parseBuffer
128:                        .get(6));
129:                DefaultButtonModel model6 = (DefaultButtonModel) getModel((ElementSpec) reader.parseBuffer
130:                        .get(7));
131:                DefaultButtonModel model7 = (DefaultButtonModel) getModel((ElementSpec) reader.parseBuffer
132:                        .get(8));
133:                DefaultButtonModel model8 = (DefaultButtonModel) getModel((ElementSpec) reader.parseBuffer
134:                        .get(9));
135:                assertNotNull(model1.getGroup());
136:                assertNotNull(model2.getGroup());
137:                assertNotNull(model3.getGroup());
138:                assertNotNull(model4.getGroup());
139:                assertNotNull(model5.getGroup());
140:                assertNotNull(model6.getGroup());
141:                assertNotNull(model7.getGroup());
142:                assertNotNull(model8.getGroup());
143:                assertSame(model1.getGroup(), model4.getGroup());
144:                assertSame(model2.getGroup(), model6.getGroup());
145:                assertSame(model3.getGroup(), model7.getGroup());
146:                assertSame(model5.getGroup(), model8.getGroup());
147:                assertNotSame(model1.getGroup(), model2.getGroup());
148:                assertNotSame(model3.getGroup(), model5.getGroup());
149:
150:                reader.handleStartTag(Tag.FORM, new SimpleAttributeSet(), 0);
151:                reader.handleStartTag(Tag.INPUT,
152:                        createInputNamedAttributes(name1), 0);
153:                reader.handleStartTag(Tag.INPUT,
154:                        createInputNamedAttributes(null), 0);
155:                reader.handleStartTag(Tag.INPUT,
156:                        createInputNamedAttributes(name1), 0);
157:                assertEquals(18, reader.parseBuffer.size());
158:                DefaultButtonModel model9 = (DefaultButtonModel) getModel((ElementSpec) reader.parseBuffer
159:                        .get(15));
160:                DefaultButtonModel model10 = (DefaultButtonModel) getModel((ElementSpec) reader.parseBuffer
161:                        .get(16));
162:                DefaultButtonModel model11 = (DefaultButtonModel) getModel((ElementSpec) reader.parseBuffer
163:                        .get(17));
164:                assertNotNull(model9.getGroup());
165:                assertNotNull(model11.getGroup());
166:                if (!isHarmony()) {
167:                    assertNotNull(model10.getGroup());
168:                } else {
169:                    assertNull(model10.getGroup());
170:                }
171:                assertNotSame(model9.getGroup(), model1.getGroup());
172:                assertNotSame(model11.getGroup(), model1.getGroup());
173:
174:            }
175:
176:            private SimpleAttributeSet createInputNamedAttributes(String name) {
177:                SimpleAttributeSet attr = new SimpleAttributeSet();
178:                attr.addAttribute(HTML.Attribute.TYPE, "radio");
179:                if (name != null) {
180:                    attr.addAttribute(HTML.Attribute.NAME, name);
181:                }
182:                return attr;
183:            }
184:
185:            public void testFormStart_InputReset() throws Exception {
186:                checkStandardInputStart("reset", DefaultButtonModel.class);
187:            }
188:
189:            public void testFormEnd_InputReset() throws Exception {
190:                checkEmptyFormEnd(Tag.INPUT, "reset");
191:            }
192:
193:            public void testFormStart_InputSubmit() throws Exception {
194:                checkStandardInputStart("submit", DefaultButtonModel.class);
195:            }
196:
197:            public void testFormEnd_InputSubmit() throws Exception {
198:                checkEmptyFormEnd(Tag.INPUT, "submit");
199:            }
200:
201:            public void testFormStart_InputText() throws Exception {
202:                checkStandardInputStart("text", PlainDocument.class);
203:            }
204:
205:            public void testFormEnd_InputText() throws Exception {
206:                checkEmptyFormEnd(Tag.INPUT, "text");
207:            }
208:
209:            public void testFormStart_InputPassword() throws Exception {
210:                checkStandardInputStart("password", PlainDocument.class);
211:            }
212:
213:            public void testFormEnd_InputPassword() throws Exception {
214:                checkEmptyFormEnd(Tag.INPUT, "password");
215:            }
216:
217:            public void testFormStart_InputFile() throws Exception {
218:                checkStandardInputStart("file", PlainDocument.class);
219:            }
220:
221:            public void testFormEnd_InputFile() throws Exception {
222:                checkEmptyFormEnd(Tag.INPUT, "file");
223:            }
224:
225:            public void testFormStart_InputHidden() throws Exception {
226:                checkStandardInputStart("hidden", null);
227:            }
228:
229:            public void testFormEnd_InputHidden() throws Exception {
230:                checkEmptyFormEnd(Tag.INPUT, "hidden");
231:            }
232:
233:            public void testFormStart_InputNull() throws Exception {
234:                checkStandardInputStart(null, PlainDocument.class);
235:            }
236:
237:            public void testFormEnd_InputNull() throws Exception {
238:                checkEmptyFormEnd(Tag.INPUT, null);
239:            }
240:
241:            public void testFormStart_Button() throws Exception {
242:                if (isHarmony()) {
243:                    checkStandardFormStart(Tag.BUTTON, DefaultButtonModel.class);
244:                }
245:            }
246:
247:            public void testFormEnd_Button() throws Exception {
248:                if (isHarmony()) {
249:                    checkEmptyFormEnd(Tag.BUTTON, null);
250:                }
251:            }
252:
253:            public void testFormStart_SelectCombo1() throws Exception {
254:                checkStandardFormStart(Tag.SELECT, DefaultComboBoxModel.class);
255:            }
256:
257:            public void testFormStart_SelectCombo2() throws Exception {
258:                SimpleAttributeSet attr = new SimpleAttributeSet();
259:                attr.addAttribute(HTML.Attribute.SIZE, "1");
260:                checkStandardFormStart(Tag.SELECT, DefaultComboBoxModel.class,
261:                        attr);
262:            }
263:
264:            public void testFormStart_SelectList1() throws Exception {
265:                SimpleAttributeSet attr = new SimpleAttributeSet();
266:                attr.addAttribute(HTML.Attribute.MULTIPLE, "multiple");
267:                checkStandardFormStart(Tag.SELECT, DefaultListModel.class, attr);
268:            }
269:
270:            public void testFormStart_SelectList2() throws Exception {
271:                SimpleAttributeSet attr = new SimpleAttributeSet();
272:                attr.addAttribute(HTML.Attribute.SIZE, "2");
273:                checkStandardFormStart(Tag.SELECT, DefaultListModel.class, attr);
274:            }
275:
276:            public void testFormStart_SelectList3() throws Exception {
277:                SimpleAttributeSet attr = new SimpleAttributeSet();
278:                attr.addAttribute(HTML.Attribute.MULTIPLE, "multiple");
279:                attr.addAttribute(HTML.Attribute.SIZE, "1");
280:                checkStandardFormStart(Tag.SELECT, DefaultListModel.class, attr);
281:            }
282:
283:            public void testFormStart_SelectList4() throws Exception {
284:                SimpleAttributeSet attr = new SimpleAttributeSet();
285:                attr.addAttribute(HTML.Attribute.SIZE, "kva");
286:                checkStandardFormStart(Tag.SELECT, DefaultComboBoxModel.class,
287:                        attr);
288:            }
289:
290:            public void testFormEnd_Select() throws Exception {
291:                checkEmptyFormEnd(Tag.SELECT, null);
292:            }
293:
294:            public void testFormStart_Option() throws Exception {
295:                String text = "text";
296:                SimpleAttributeSet attr = new SimpleAttributeSet();
297:                attr.addAttribute("aaaa", "bbbb");
298:                action = reader.new FormAction();
299:                action.start(Tag.OPTION, attr);
300:                assertEquals(0, reader.parseBuffer.size());
301:            }
302:
303:            public void testForm_OptionCombo() throws Exception {
304:                String text = "text";
305:                SimpleAttributeSet attr = new SimpleAttributeSet();
306:                attr.addAttribute("aaaa", "bbbb");
307:                action = reader.new FormAction();
308:                action.start(Tag.SELECT, attr);
309:                action.start(Tag.OPTION, attr);
310:
311:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(1);
312:                final AttributeSet specAttr = spec.getAttributes();
313:                assertEquals(3, specAttr.getAttributeCount());
314:                assertSpec(spec, ElementSpec.ContentType,
315:                        ElementSpec.OriginateDirection, 0, new char[] { ' ' });
316:                Object contentModel = specAttr
317:                        .getAttribute(StyleConstants.ModelAttribute);
318:                assertNotNull(contentModel);
319:                assertTrue(contentModel instanceof  DefaultComboBoxModel);
320:                DefaultComboBoxModel model = (DefaultComboBoxModel) contentModel;
321:                assertEquals(1, model.getSize());
322:                assertNotNull(model.getElementAt(0));
323:                reader.handleText(text.toCharArray(), 0);
324:                assertEquals(1, model.getSize());
325:                assertNotNull(model.getElementAt(0));
326:                action.end(Tag.OPTION);
327:
328:                action.start(Tag.OPTION, attr);
329:                assertEquals(2, model.getSize());
330:                assertNotNull(model.getElementAt(1));
331:                reader.handleText(text.toCharArray(), 0);
332:                assertEquals(2, model.getSize());
333:                assertNotNull(model.getElementAt(1));
334:                action.end(Tag.OPTION);
335:                action.end(Tag.SELECT);
336:                assertEquals(3, specAttr.getAttributeCount());
337:            }
338:
339:            public void testForm_OptionList() throws Exception {
340:                String text = "text";
341:                SimpleAttributeSet attr = new SimpleAttributeSet();
342:                attr.addAttribute(HTML.Attribute.MULTIPLE, "multiple");
343:                attr.addAttribute("aaaa", "bbbb");
344:                action = reader.new FormAction();
345:                action.start(Tag.SELECT, attr);
346:                action.start(Tag.OPTION, attr);
347:
348:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(1);
349:                final AttributeSet specAttr = spec.getAttributes();
350:                assertEquals(4, specAttr.getAttributeCount());
351:                assertSpec(spec, ElementSpec.ContentType,
352:                        ElementSpec.OriginateDirection, 0, new char[] { ' ' });
353:                Object contentModel = specAttr
354:                        .getAttribute(StyleConstants.ModelAttribute);
355:                assertNotNull(contentModel);
356:                assertTrue(contentModel instanceof  DefaultListModel);
357:                DefaultListModel model = (DefaultListModel) contentModel;
358:                assertEquals(1, model.getSize());
359:                assertNotNull(model.getElementAt(0));
360:                reader.handleText(text.toCharArray(), 0);
361:                assertEquals(1, model.getSize());
362:                assertNotNull(model.getElementAt(0));
363:                action.end(Tag.OPTION);
364:
365:                action.start(Tag.OPTION, attr);
366:                assertEquals(2, model.getSize());
367:                assertNotNull(model.getElementAt(1));
368:                reader.handleText(text.toCharArray(), 0);
369:                assertEquals(2, model.getSize());
370:                assertNotNull(model.getElementAt(1));
371:                action.end(Tag.OPTION);
372:                action.end(Tag.SELECT);
373:                assertEquals(4, specAttr.getAttributeCount());
374:            }
375:
376:            public void testForm_SelectOption() throws Exception {
377:                SimpleAttributeSet attr = new SimpleAttributeSet();
378:                attr.addAttribute("aaaa", "bbbb");
379:                action = reader.new FormAction();
380:                action.start(Tag.SELECT, attr);
381:                assertEquals(2, reader.parseBuffer.size());
382:                action.start(Tag.OPTION, attr);
383:                action.end(Tag.OPTION);
384:                action.start(Tag.OPTION, attr);
385:                action.end(Tag.OPTION);
386:                action.end(Tag.SELECT);
387:                assertEquals(2, reader.parseBuffer.size());
388:            }
389:
390:            public void testForm_Attributes() throws Exception {
391:                String text = "text";
392:                SimpleAttributeSet attr = new SimpleAttributeSet();
393:                attr.addAttribute("aaaa", "bbbb");
394:                action = reader.new FormAction();
395:                action.start(Tag.SELECT, attr);
396:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(1);
397:                final AttributeSet specAttr = spec.getAttributes();
398:                assertNotSame(specAttr, attr);
399:            }
400:
401:            public void testForm_OptionAttributes() throws Exception {
402:                String text = "text";
403:                SimpleAttributeSet attr = new SimpleAttributeSet();
404:                attr.addAttribute("aaaa", "bbbb");
405:                action = reader.new FormAction();
406:                action.start(Tag.SELECT, attr);
407:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(1);
408:                final AttributeSet specAttr = spec.getAttributes();
409:                assertEquals(3, specAttr.getAttributeCount());
410:                assertSpec(spec, ElementSpec.ContentType,
411:                        ElementSpec.OriginateDirection, 0, new char[] { ' ' });
412:                Object contentModel = specAttr
413:                        .getAttribute(StyleConstants.ModelAttribute);
414:                assertNotNull(contentModel);
415:                assertTrue(contentModel instanceof  DefaultComboBoxModel);
416:                DefaultComboBoxModel model = (DefaultComboBoxModel) contentModel;
417:
418:                action.start(Tag.OPTION, attr);
419:                assertEquals(1, model.getSize());
420:                assertNotNull(model.getElementAt(0));
421:                Option option = (Option) model.getElementAt(0);
422:                assertFalse(option.isSelected());
423:                assertNull(option.getLabel());
424:                assertNull(option.getValue());
425:                reader.handleText(text.toCharArray(), 0);
426:                assertEquals(1, model.getSize());
427:                assertNotNull(model.getElementAt(0));
428:                option = (Option) model.getElementAt(0);
429:                assertFalse(option.isSelected());
430:                assertEquals(text, option.getLabel());
431:                assertEquals(text, option.getValue());
432:                action.end(Tag.OPTION);
433:
434:                final String value = "value";
435:                final String label = "label";
436:                attr.addAttribute(HTML.Attribute.SELECTED, "true");
437:                attr.addAttribute(HTML.Attribute.VALUE, value);
438:                if (isHarmony()) {
439:                    attr.addAttribute(HTML.Attribute.LABEL, label);
440:                } else {
441:                    attr.addAttribute("label", label);
442:                }
443:                action.start(Tag.OPTION, attr);
444:                assertEquals(2, model.getSize());
445:                assertNotNull(model.getElementAt(1));
446:                option = (Option) model.getElementAt(1);
447:                assertTrue(option.isSelected());
448:                if (isHarmony()) {
449:                    assertEquals(label, option.getLabel());
450:                    assertEquals(0, ((FormOption) option).getDepth());
451:                } else {
452:                    assertNull(option.getLabel());
453:                }
454:                assertEquals(value, option.getValue());
455:                reader.handleText(text.toCharArray(), 0);
456:                assertEquals(2, model.getSize());
457:                assertNotNull(model.getElementAt(1));
458:                option = (Option) model.getElementAt(1);
459:                assertTrue(option.isSelected());
460:                assertEquals(value, option.getValue());
461:                if (isHarmony()) {
462:                    assertEquals(0, ((FormOption) option).getDepth());
463:                }
464:                assertEquals(text, option.getLabel());
465:                action.end(Tag.OPTION);
466:                action.end(Tag.SELECT);
467:                assertEquals(3, specAttr.getAttributeCount());
468:            }
469:
470:            public void testForm_OptionGroupAttributes() throws Exception {
471:                if (!isHarmony()) {
472:                    return;
473:                }
474:                String text = "text";
475:                SimpleAttributeSet attr = new SimpleAttributeSet();
476:                attr.addAttribute("aaaa", "bbbb");
477:                action = reader.new FormAction();
478:                action.start(Tag.SELECT, attr);
479:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(1);
480:                final AttributeSet specAttr = spec.getAttributes();
481:                assertEquals(3, specAttr.getAttributeCount());
482:                assertSpec(spec, ElementSpec.ContentType,
483:                        ElementSpec.OriginateDirection, 0, new char[] { ' ' });
484:                Object contentModel = specAttr
485:                        .getAttribute(StyleConstants.ModelAttribute);
486:                assertNotNull(contentModel);
487:                assertTrue(contentModel instanceof  DefaultComboBoxModel);
488:                DefaultComboBoxModel model = (DefaultComboBoxModel) contentModel;
489:
490:                final String value = "value";
491:                final String label = "label";
492:                attr.addAttribute(HTML.Attribute.SELECTED, "true");
493:                attr.addAttribute(HTML.Attribute.LABEL, label);
494:                action.start(Tag.OPTGROUP, attr);
495:                assertEquals(1, model.getSize());
496:                assertNotNull(model.getElementAt(0));
497:                FormOption option = (FormOption) model.getElementAt(0);
498:                assertFalse(option.isSelected());
499:                assertEquals(label, option.getLabel());
500:                assertNull(option.getValue());
501:                reader.handleText(text.toCharArray(), 0);
502:                assertEquals(1, model.getSize());
503:                assertNotNull(model.getElementAt(0));
504:                option = (FormOption) model.getElementAt(0);
505:                assertFalse(option.isSelected());
506:                assertEquals(label, option.getLabel());
507:                assertNull(option.getValue());
508:                assertEquals(0, option.getDepth());
509:
510:                attr.addAttribute(HTML.Attribute.SELECTED, "true");
511:                attr.addAttribute(HTML.Attribute.VALUE, value);
512:                attr.addAttribute(HTML.Attribute.LABEL, label);
513:                action.start(Tag.OPTGROUP, attr);
514:                assertEquals(2, model.getSize());
515:                assertNotNull(model.getElementAt(1));
516:                option = (FormOption) model.getElementAt(1);
517:                assertFalse(option.isSelected());
518:                assertEquals(label, option.getLabel());
519:                assertNull(option.getValue());
520:                reader.handleText(text.toCharArray(), 0);
521:                assertEquals(2, model.getSize());
522:                assertNotNull(model.getElementAt(1));
523:                option = (FormOption) model.getElementAt(1);
524:                assertFalse(option.isSelected());
525:                assertEquals(label, option.getLabel());
526:                assertNull(option.getValue());
527:                assertEquals(1, option.getDepth());
528:                action.end(Tag.OPTGROUP);
529:                action.end(Tag.OPTGROUP);
530:                action.end(Tag.SELECT);
531:                assertEquals(3, specAttr.getAttributeCount());
532:            }
533:
534:            public void testFormEnd_Option() throws Exception {
535:                checkEmptyFormEnd(Tag.OPTION, null);
536:            }
537:
538:            public void testFormEnd_Optgroup() throws Exception {
539:                if (isHarmony()) {
540:                    checkEmptyFormEnd(Tag.OPTGROUP, null);
541:                }
542:            }
543:
544:            public void testFormStart_TextArea() throws Exception {
545:                checkStandardFormStart(Tag.TEXTAREA, PlainDocument.class);
546:            }
547:
548:            public void testFormEnd_TextArea() throws Exception {
549:                checkEmptyFormEnd(Tag.TEXTAREA, null);
550:            }
551:
552:            public void testFormStart_FieldSet() throws Exception {
553:                if (!isHarmony()) {
554:                    return;
555:                }
556:                String text = "text";
557:                SimpleAttributeSet attr = new SimpleAttributeSet();
558:                attr.addAttribute("aaaa", "bbbb");
559:                action = reader.new FormAction();
560:                action.start(Tag.FIELDSET, attr);
561:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(1);
562:                final AttributeSet specAttr = spec.getAttributes();
563:                assertEquals(3, specAttr.getAttributeCount());
564:                assertSpec(spec, ElementSpec.ContentType,
565:                        ElementSpec.OriginateDirection, 0, new char[] { ' ' });
566:                Object contentModel = specAttr
567:                        .getAttribute(StyleConstants.ModelAttribute);
568:                assertNotNull(contentModel);
569:                assertTrue(contentModel instanceof  FormFieldsetModel);
570:            }
571:
572:            public void testFormEnd_FieldSet() throws Exception {
573:                if (isHarmony()) {
574:                    checkEmptyFormEnd(Tag.FIELDSET, null);
575:                }
576:            }
577:
578:            public void testFormStartEnd_Legend_InsideFieldSet()
579:                    throws Exception {
580:                if (!isHarmony()) {
581:                    return;
582:                }
583:                String text1 = "text1";
584:                String text2 = "text2";
585:                SimpleAttributeSet attr = new SimpleAttributeSet();
586:                attr.addAttribute("aaaa", "bbbb");
587:                SimpleAttributeSet legendAttr1 = new SimpleAttributeSet();
588:                legendAttr1.addAttribute("bbbb", "aaaa");
589:                SimpleAttributeSet legendAttr2 = new SimpleAttributeSet();
590:                legendAttr2.addAttribute("bb", "aa");
591:                action = reader.new FormAction();
592:                action.start(Tag.FIELDSET, attr);
593:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(1);
594:                final AttributeSet specAttr = spec.getAttributes();
595:                assertEquals(3, specAttr.getAttributeCount());
596:                assertSpec(spec, ElementSpec.ContentType,
597:                        ElementSpec.OriginateDirection, 0, new char[] { ' ' });
598:                Object contentModel = specAttr
599:                        .getAttribute(StyleConstants.ModelAttribute);
600:                assertNotNull(contentModel);
601:                assertTrue(contentModel instanceof  FormFieldsetModel);
602:                FormFieldsetModel fieldSet = (FormFieldsetModel) contentModel;
603:                assertNull(fieldSet.getLegend());
604:                assertNull(fieldSet.getLegendAttributes());
605:
606:                action.start(Tag.LEGEND, legendAttr1);
607:                reader.handleText(text1.toCharArray(), 0);
608:                action.end(Tag.LEGEND);
609:                assertEquals(text1, fieldSet.getLegend());
610:                assertNotNull(fieldSet.getLegendAttributes());
611:                assertEquals(2, fieldSet.getLegendAttributes()
612:                        .getAttributeCount());
613:                checkAttributes(fieldSet.getLegendAttributes(), "bbbb", "aaaa");
614:                checkAttributes(fieldSet.getLegendAttributes(),
615:                        StyleConstants.NameAttribute, Tag.LEGEND);
616:                assertNotSame(legendAttr1, fieldSet.getLegendAttributes());
617:
618:                action.start(Tag.LEGEND, legendAttr2);
619:                reader.handleText(text2.toCharArray(), 0);
620:                action.end(Tag.LEGEND);
621:                assertEquals(text1, fieldSet.getLegend());
622:                assertNotNull(fieldSet.getLegendAttributes());
623:                assertEquals(2, fieldSet.getLegendAttributes()
624:                        .getAttributeCount());
625:                checkAttributes(fieldSet.getLegendAttributes(),
626:                        StyleConstants.NameAttribute, Tag.LEGEND);
627:                checkAttributes(fieldSet.getLegendAttributes(), "bbbb", "aaaa");
628:            }
629:
630:            public void testFormStartEnd_Legend_OutsideFieldSet()
631:                    throws Exception {
632:                if (!isHarmony()) {
633:                    return;
634:                }
635:                String text1 = "text1";
636:                String text2 = "text2";
637:                SimpleAttributeSet attr = new SimpleAttributeSet();
638:                attr.addAttribute("aaaa", "bbbb");
639:                action = reader.new FormAction();
640:                action.start(Tag.FIELDSET, attr);
641:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(1);
642:                final AttributeSet specAttr = spec.getAttributes();
643:                assertEquals(3, specAttr.getAttributeCount());
644:                assertSpec(spec, ElementSpec.ContentType,
645:                        ElementSpec.OriginateDirection, 0, new char[] { ' ' });
646:                Object contentModel = specAttr
647:                        .getAttribute(StyleConstants.ModelAttribute);
648:                assertNotNull(contentModel);
649:                assertTrue(contentModel instanceof  FormFieldsetModel);
650:                FormFieldsetModel fieldSet = (FormFieldsetModel) contentModel;
651:                assertNull(fieldSet.getLegend());
652:                assertNull(fieldSet.getLegendAttributes());
653:                action.end(Tag.FIELDSET);
654:
655:                action.start(Tag.LEGEND, attr);
656:                reader.handleText(text1.toCharArray(), 0);
657:                action.end(Tag.LEGEND);
658:                assertNull(fieldSet.getLegend());
659:                assertNull(fieldSet.getLegendAttributes());
660:            }
661:
662:            public void testFormEnd_Legend() throws Exception {
663:                if (isHarmony()) {
664:                    checkEmptyFormEnd(Tag.LEGEND, null);
665:                }
666:            }
667:
668:            private void checkStandardInputStart(final String type,
669:                    final Class modelClass) throws Exception {
670:                checkStandardFormStart(Tag.INPUT, modelClass, type, null);
671:            }
672:
673:            private void checkStandardFormStart(final Tag tag,
674:                    final Class modelClass) throws Exception {
675:                checkStandardFormStart(tag, modelClass, null, null);
676:            }
677:
678:            private void checkStandardFormStart(final Tag tag,
679:                    final Class modelClass, final AttributeSet attr)
680:                    throws Exception {
681:                checkStandardFormStart(tag, modelClass, null, attr);
682:            }
683:
684:            private void checkStandardFormStart(final Tag tag,
685:                    final Class modelClass, final String type,
686:                    final AttributeSet additionalAttr) throws Exception {
687:                doFormStart(tag, type, additionalAttr);
688:
689:                ElementSpec spec = (ElementSpec) reader.parseBuffer.get(0);
690:                checkOpenImpliedSpec(spec);
691:
692:                spec = (ElementSpec) reader.parseBuffer.get(1);
693:                AttributeSet specAttr = spec.getAttributes();
694:
695:                int addendum = additionalAttr != null ? additionalAttr
696:                        .getAttributeCount() : 0;
697:                int attrNum = 2;
698:                if (modelClass != null) {
699:                    attrNum++;
700:                }
701:                if (Tag.INPUT.equals(tag)) {
702:                    attrNum++;
703:                }
704:                assertEquals(attrNum + addendum, specAttr.getAttributeCount());
705:
706:                if (additionalAttr != null) {
707:                    assertTrue(specAttr.containsAttributes(additionalAttr));
708:                }
709:                checkAttributes(specAttr, StyleConstants.NameAttribute, tag);
710:                if (type != null) {
711:                    checkAttributes(specAttr, HTML.Attribute.TYPE, type);
712:                }
713:                checkAttributes(specAttr, "aaaa", "bbbb");
714:                if (modelClass != null) {
715:                    assertSpec(spec, ElementSpec.ContentType,
716:                            ElementSpec.OriginateDirection, 0,
717:                            new char[] { ' ' });
718:                    Object contentModel = getModel(spec);
719:                    assertNotNull(contentModel);
720:                    assertTrue(modelClass.isAssignableFrom(contentModel
721:                            .getClass()));
722:                }
723:            }
724:
725:            private Object getModel(final ElementSpec spec) {
726:                return spec.getAttributes().getAttribute(
727:                        StyleConstants.ModelAttribute);
728:            }
729:
730:            private void doFormStart(final Tag tag, final String type,
731:                    final AttributeSet additionalAttr) {
732:                SimpleAttributeSet attr = new SimpleAttributeSet();
733:                if (additionalAttr != null) {
734:                    attr.addAttributes(additionalAttr);
735:                }
736:                if (type != null) {
737:                    attr.addAttribute(HTML.Attribute.TYPE, type);
738:                }
739:                attr.addAttribute("aaaa", "bbbb");
740:                action = reader.new FormAction();
741:
742:                action.start(tag, attr);
743:                assertEquals(0, reader.charAttr.getAttributeCount());
744:                assertEquals(2, reader.parseBuffer.size());
745:            }
746:
747:            private void checkEmptyFormEnd(final Tag tag, final String type)
748:                    throws Exception {
749:                SimpleAttributeSet attr = new SimpleAttributeSet();
750:                attr.addAttribute("aaaa", "bbbb");
751:                if (type != null) {
752:                    attr.addAttribute(HTML.Attribute.TYPE, type);
753:                }
754:
755:                action = reader.new FormAction();
756:                action.start(tag, attr);
757:                assertEquals(0, reader.charAttr.getAttributeCount());
758:                int numSpecs = reader.parseBuffer.size();
759:                action.end(tag);
760:                assertEquals(0, reader.charAttr.getAttributeCount());
761:                assertEquals(numSpecs, reader.parseBuffer.size());
762:            }
763:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.