Source Code Cross Referenced for TabGroupTest.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.utils.AssertionFailureNotDetectedError;
005:        import org.uispec4j.utils.ColorUtils;
006:        import org.uispec4j.utils.UIComponentFactory;
007:        import org.uispec4j.xml.XmlAssert;
008:
009:        import javax.swing.*;
010:        import java.awt.*;
011:
012:        public class TabGroupTest extends UIComponentTestCase {
013:            private TabGroup tabGroup;
014:            private JTabbedPane jTabbedPane;
015:
016:            protected void setUp() throws Exception {
017:                super .setUp();
018:                jTabbedPane = new JTabbedPane();
019:                jTabbedPane.setName("myTabbedPane");
020:                addTab("1", "tab1");
021:                addTab("2", "tab2");
022:                addTab("3", "tab3");
023:                tabGroup = new TabGroup(jTabbedPane);
024:            }
025:
026:            public void testGetComponentTypeName() throws Exception {
027:                assertEquals("tabGroup", UIComponentFactory.createUIComponent(
028:                        new JTabbedPane()).getDescriptionTypeName());
029:            }
030:
031:            public void testGetDescription() throws Exception {
032:                checkTabDescription("1");
033:                checkTabDescription("2");
034:                checkTabDescription("3");
035:            }
036:
037:            protected UIComponent createComponent() {
038:                return tabGroup;
039:            }
040:
041:            public void testCheckCurrentTab() throws Exception {
042:                assertTrue(tabGroup.selectedTabEquals("1"));
043:                try {
044:                    assertTrue(tabGroup.selectedTabEquals("2"));
045:                    throw new AssertionFailureNotDetectedError();
046:                } catch (AssertionFailedError e) {
047:                }
048:            }
049:
050:            public void testClickOnTabWithPartOfItsKey() throws Exception {
051:                addTab("GrosseTable", "table");
052:                tabGroup.selectTab("grosse");
053:                assertTrue(tabGroup.selectedTabEquals("GrosseTable"));
054:            }
055:
056:            public void testCheckTabs() throws Exception {
057:                assertTrue(tabGroup
058:                        .tabNamesEquals(new String[] { "1", "2", "3" }));
059:                try {
060:                    assertTrue(tabGroup.tabNamesEquals(new String[] { "this",
061:                            "is", "wrong" }));
062:                    throw new AssertionFailureNotDetectedError();
063:                } catch (AssertionFailedError e) {
064:                    // Expected
065:                }
066:            }
067:
068:            public void testSetCurrentTab() throws Exception {
069:                tabGroup.selectTab("2");
070:                assertEquals("2", jTabbedPane.getTitleAt(jTabbedPane
071:                        .getSelectedIndex()));
072:                tabGroup.selectTab("3");
073:                assertEquals("3", jTabbedPane.getTitleAt(jTabbedPane
074:                        .getSelectedIndex()));
075:            }
076:
077:            public void testSetCurrentTabError() throws Exception {
078:                try {
079:                    tabGroup.selectTab("unknown");
080:                    throw new AssertionFailureNotDetectedError();
081:                } catch (AssertionFailedError e) {
082:                    assertEquals(TabGroup.tabNotFound("unknown"), e
083:                            .getMessage());
084:                }
085:            }
086:
087:            public void testGetDescriptionWhenTheTabContainsAPanel()
088:                    throws Exception {
089:                JButton button = new JButton("btn");
090:                JPanel panel = new JPanel();
091:                panel.add(button);
092:                jTabbedPane.addTab("4", panel);
093:                tabGroup.selectTab("4");
094:                XmlAssert.assertEquivalent("<tabGroup name='myTabbedPane'>"
095:                        + "  <button label='btn'/>" + "</tabGroup>", tabGroup
096:                        .getDescription());
097:            }
098:
099:            public void testFactory() throws Exception {
100:                checkFactory(new JTabbedPane(), TabGroup.class);
101:            }
102:
103:            public void testTabLabelColor() throws Exception {
104:                jTabbedPane.setForegroundAt(0, Color.RED);
105:                assertTrue(tabGroup.tabColorEquals(new String[] { "RED",
106:                        "BLACK", "BLACK" }));
107:            }
108:
109:            public void testCheckColorErrors() throws Exception {
110:                try {
111:                    assertTrue(tabGroup.tabColorEquals(new String[] { "BLACK",
112:                            "GREEN" }));
113:                    throw new AssertionFailureNotDetectedError();
114:                } catch (AssertionFailedError e) {
115:                    assertEquals(
116:                            "You specified 2 colors but there are 3 tabs - expected:<2> but was:<3>",
117:                            e.getMessage());
118:                }
119:
120:                try {
121:                    jTabbedPane.setForegroundAt(1, Color.BLACK);
122:                    assertTrue(tabGroup.tabColorEquals(new String[] { "BLACK",
123:                            "BLUE", "GREEN" }));
124:                    throw new AssertionFailureNotDetectedError();
125:                } catch (AssertionFailedError e) {
126:                    assertEquals("Unexpected color for tab '2' (index 1) - "
127:                            + "expected "
128:                            + ColorUtils.getColorDescription("BLUE")
129:                            + " but was "
130:                            + ColorUtils.getColorDescription("000000"), e
131:                            .getMessage());
132:                }
133:            }
134:
135:            public void testSearchComponentsWhenVisibleTabIsAPanel()
136:                    throws Exception {
137:                JButton jButton = new JButton("button");
138:                Component jPanel1WithButton = createPanelWithComponent(jButton);
139:                JTable jtable = new JTable();
140:                Component jPanel2WithTable = createPanelWithComponent(jtable);
141:
142:                jTabbedPane = new JTabbedPane();
143:                jTabbedPane.addTab("panel1WithButton", jPanel1WithButton);
144:                jTabbedPane.addTab("panel2WithTable", jPanel2WithTable);
145:                tabGroup = new TabGroup(jTabbedPane);
146:
147:                assertSame(jPanel1WithButton, tabGroup.getSelectedTab()
148:                        .getAwtComponent());
149:                assertSame(jButton, tabGroup.getSelectedTab().getButton(
150:                        "button").getAwtComponent());
151:
152:                tabGroup.selectTab("panel2WithTable");
153:                assertSame(jPanel2WithTable, tabGroup.getSelectedTab()
154:                        .getAwtComponent());
155:                assertSame(jtable, tabGroup.getSelectedTab().getTable()
156:                        .getAwtComponent());
157:            }
158:
159:            public void testSearchComponentsFailsWhenVisibleTabIsNotAPanel()
160:                    throws Exception {
161:                jTabbedPane = new JTabbedPane();
162:                jTabbedPane.addTab("tree", new JTree());
163:                tabGroup = new TabGroup(jTabbedPane);
164:
165:                try {
166:                    tabGroup.getSelectedTab();
167:                    throw new AssertionFailureNotDetectedError();
168:                } catch (AssertionFailedError e) {
169:                    assertEquals(
170:                            "tabGroup.getSelectedTab() only supports JPanel components inside a JTabbedPane",
171:                            e.getMessage());
172:                }
173:            }
174:
175:            private Component createPanelWithComponent(Component component) {
176:                JPanel panel = new JPanel();
177:                panel.add(component);
178:                return panel;
179:            }
180:
181:            private void checkTabDescription(String tabLabel) throws Exception {
182:                tabGroup.selectTab(tabLabel);
183:                XmlAssert.assertEquivalent("<tabGroup name='myTabbedPane'>"
184:                        + "  <textBox name='tab" + tabLabel + "'/>"
185:                        + "</tabGroup>", tabGroup.getDescription());
186:            }
187:
188:            private void addTab(String index, String tabName) {
189:                JLabel label = new JLabel("");
190:                label.setName(tabName);
191:                jTabbedPane.addTab(index, label);
192:            }
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.