Source Code Cross Referenced for MenuItemTestCase.java in  » Testing » UISpec4J » org » uispec4j » 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 » Testing » UISpec4J » org.uispec4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.uispec4j;
002:
003:        import junit.framework.AssertionFailedError;
004:        import org.uispec4j.interception.WindowHandler;
005:        import org.uispec4j.interception.WindowInterceptor;
006:        import org.uispec4j.utils.AssertionFailureNotDetectedError;
007:        import org.uispec4j.xml.EventLogger;
008:        import org.uispec4j.xml.XmlAssert;
009:
010:        import javax.swing.*;
011:        import java.awt.event.ActionEvent;
012:
013:        public abstract class MenuItemTestCase extends UIComponentTestCase {
014:
015:            public void testGetComponentTypeName() throws Exception {
016:                MenuItem item = getBuilder("menuTest").getMenuItem();
017:                assertEquals("menu", item.getDescriptionTypeName());
018:            }
019:
020:            public void testGetDescription() throws Exception {
021:                MenuItem item = getBuilder("menuTest").setName("myMenu")
022:                        .getMenuItem();
023:                XmlAssert.assertEquivalent("<menu name='myMenu'/>", item
024:                        .getDescription());
025:            }
026:
027:            protected UIComponent createComponent() {
028:                return getBuilder("item").getMenuItem();
029:            }
030:
031:            public void testMenuContent() throws Exception {
032:                MenuBuilder rootBuilder = getBuilder("menuTest");
033:                rootBuilder.add("item1");
034:                MenuBuilder item2Builder = rootBuilder.startSubMenu("item2");
035:                item2Builder.add("subItem1");
036:                item2Builder.add("subItem2");
037:                rootBuilder.add("item3");
038:
039:                MenuItem item = rootBuilder.getMenuItem();
040:                assertTrue(item.contentEquals("<menu name='menuTest'>"
041:                        + "  <menu name='item1'/>" + "  <menu name='item2'>"
042:                        + "    <menu name='subItem1'/>"
043:                        + "    <menu name='subItem2'/>" + "  </menu>"
044:                        + "  <menu name='item3'/>" + "</menu>"));
045:            }
046:
047:            public void testCheckMenu() throws Exception {
048:                MenuBuilder builder = getBuilder("menuTest");
049:                builder.add("item1");
050:                builder.addSeparator();
051:                builder.add("item2");
052:                MenuItem item = builder.getMenuItem();
053:                assertTrue(item.contentEquals("<menu name='menuTest'>"
054:                        + "  <menu name='item1'/>" + "  <separator/>"
055:                        + "  <menu name='item2'/>" + "</menu>"));
056:                assertTrue(item
057:                        .contentEquals(new String[] { "item1", "item2" }));
058:            }
059:
060:            public void testCheckMenuOnMenuItemWithNoError() throws Exception {
061:                MenuBuilder builder = getBuilder("root");
062:                builder.add("item1");
063:                MenuItem item = builder.getMenuItem();
064:                MenuItem subMenu = item.getSubMenu("item1");
065:                assertTrue(subMenu.contentEquals("<menu name='item1'/>"));
066:                assertTrue(item.contentEquals(new String[] { "item1" }));
067:            }
068:
069:            public void testGetSubMenuWorksWithPartOfItsName() throws Exception {
070:                MenuBuilder builder = getBuilder("root");
071:                builder.add("one two three...");
072:                MenuItem item = builder.getMenuItem();
073:                assertNotNull(item.getSubMenu("one two three..."));
074:                assertNotNull(item.getSubMenu("one"));
075:                assertNotNull(item.getSubMenu("two"));
076:            }
077:
078:            public void testClickFailsIfTheMenuItemIsNotEnabled()
079:                    throws Exception {
080:                MenuItem item = getBuilder("").setEnabled(false).getMenuItem();
081:                try {
082:                    item.click();
083:                    throw new AssertionFailureNotDetectedError();
084:                } catch (AssertionFailedError e) {
085:                    assertEquals(
086:                            "The menu item is not enabled, it cannot be activated",
087:                            e.getMessage());
088:                }
089:            }
090:
091:            public void testCheckMenuWithOneLevel() throws Exception {
092:                MenuItem item = getBuilder("").add("item1").add("item2").add(
093:                        "item3").getMenuItem();
094:                assertTrue(item.contentEquals(new String[] { "item1", "item2",
095:                        "item3" }));
096:            }
097:
098:            public void testActivateSimulatesAClickOnTheMenuItem()
099:                    throws Exception {
100:                EventLogger eventLogger = new EventLogger();
101:                MenuItem menuItem = createLoggingMenuItem(eventLogger);
102:                assertTrue(menuItem.contentEquals(new String[] { "item" }));
103:                menuItem.getSubMenu("item").click();
104:
105:                eventLogger.assertEquals("<log>" + "  <action/>" + "</log>");
106:            }
107:
108:            public void testTriggerClickWorksAsClick() throws Exception {
109:                EventLogger eventLogger = new EventLogger();
110:                MenuItem menuItem = createLoggingMenuItem(eventLogger);
111:                menuItem.getSubMenu("item").triggerClick().run();
112:                eventLogger.assertEquals("<log>" + "  <action/>" + "</log>");
113:            }
114:
115:            public void testGetSubmenuError() throws Exception {
116:                checkGetSubmenuError(new String[] { "One", "Two", "Three" },
117:                        "Four",
118:                        "There is no menu item matching 'Four' - actual elements: [One,Two,Three]");
119:            }
120:
121:            public void testGetAmbiguitySubMenu() throws Exception {
122:                checkGetSubmenuError(
123:                        new String[] { "One two three...",
124:                                "One two three four...", "two three" },
125:                        "three",
126:                        "Could not retrieve subMenu item : There are more than one component matching 'three'");
127:            }
128:
129:            private void checkGetSubmenuError(String[] menus,
130:                    String searchedItem, String expectedMessage) {
131:                MenuBuilder builder = getBuilder("");
132:                for (int i = 0; i < menus.length; i++) {
133:                    builder.add(menus[i]);
134:                }
135:                MenuItem item = builder.getMenuItem();
136:                try {
137:                    item.getSubMenu(searchedItem);
138:                    throw new AssertionFailureNotDetectedError();
139:                } catch (AssertionFailedError e) {
140:                    assertEquals(expectedMessage, e.getMessage());
141:                }
142:            }
143:
144:            public void testGetSubMenuWhenSubMenuIsItselfAMenu()
145:                    throws Exception {
146:                MenuBuilder rootBuilder = getBuilder("");
147:                rootBuilder.add("item1");
148:                rootBuilder.startSubMenu("item2").add("subItem1").add(
149:                        "subItem2").setName("subMenuItem2");
150:                rootBuilder.add("item3");
151:                MenuItem subMenuItem = rootBuilder.getMenuItem().getSubMenu(
152:                        "item2");
153:                assertTrue(subMenuItem.contentEquals("<menu name='item2'>"
154:                        + "  <menu name='subItem1'/>"
155:                        + "  <menu name='subItem2'/>" + "</menu>"));
156:            }
157:
158:            public void testHandlingADialogShownByAPopupMenu() throws Exception {
159:                final EventLogger logger = new EventLogger();
160:
161:                final JPanel panel = new JPanel();
162:                WindowInterceptor.run(new Trigger() {
163:                    public void run() throws Exception {
164:                        showDialog(panel);
165:                    }
166:                });
167:
168:                final JButton button = new JButton(new AbstractAction("ok") {
169:                    public void actionPerformed(ActionEvent e) {
170:                        logger.log("ok");
171:                    }
172:                });
173:
174:                MenuItem menuItem = getBuilder("").add(
175:                        new AbstractAction("menu") {
176:                            public void actionPerformed(ActionEvent e) {
177:                                logger.log("dialog");
178:                                showDialog(button);
179:                            }
180:                        }).getMenuItem();
181:                WindowInterceptor.init(
182:                        menuItem.getSubMenu("menu").triggerClick()).process(
183:                        new WindowHandler() {
184:                            public Trigger process(Window window)
185:                                    throws Exception {
186:                                logger.log("handleWindow");
187:                                return window.getButton("ok").triggerClick();
188:                            }
189:                        }).run();
190:
191:                logger.assertEquals("<log>" + "  <dialog/>"
192:                        + "  <handleWindow/>" + "  <ok/>" + "</log>");
193:            }
194:
195:            private void showDialog(final JComponent component) {
196:                JDialog dialog = new JDialog();
197:                dialog.getContentPane().add(component);
198:                dialog.setVisible(true);
199:            }
200:
201:            protected abstract MenuItem createLoggingMenuItem(
202:                    EventLogger eventLogger);
203:
204:            protected abstract MenuBuilder getBuilder(String text);
205:
206:            public interface MenuBuilder {
207:                MenuBuilder add(String item);
208:
209:                MenuBuilder add(Action action);
210:
211:                MenuBuilder addSeparator();
212:
213:                MenuBuilder setEnabled(boolean enabled);
214:
215:                MenuBuilder setName(String s);
216:
217:                MenuBuilder startSubMenu(String item);
218:
219:                MenuItem getMenuItem();
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.