Source Code Cross Referenced for JTextComponentTest.java in  » Testing » jacareto » jacareto » test » 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 » jacareto » jacareto.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jacareto Copyright (c) 2002-2005
003:         * Applied Computer Science Research Group, Darmstadt University of
004:         * Technology, Institute of Mathematics & Computer Science,
005:         * Ludwigsburg University of Education, and Computer Based
006:         * Learning Research Group, Aachen University. All rights reserved.
007:         *
008:         * Jacareto is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2 of the License, or (at your option) any later version.
012:         *
013:         * Jacareto is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         * General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public
019:         * License along with Jacareto; if not, write to the Free
020:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         *
022:         */
023:
024:        package jacareto.test;
025:
026:        import jacareto.comp.Components;
027:        import jacareto.system.Environment;
028:
029:        import org.apache.regexp.RE;
030:        import org.apache.regexp.RESyntaxException;
031:
032:        import java.awt.Component;
033:
034:        import java.util.Iterator;
035:
036:        import javax.swing.text.JTextComponent;
037:
038:        /**
039:         * Test class for testing <code>java.swing.JTextComponent</code> components.  The following
040:         * criteria are tested by this class:
041:         * 
042:         * <ul>
043:         * <li>
044:         * <b>target text</b> - testes if the text in the tested text component is correct
045:         * </li>
046:         * <li>
047:         * <b>regular expression</b> - testes if the text in the tested text component matches a regular
048:         * expression
049:         * </li>
050:         * </ul>
051:         * 
052:         *
053:         * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
054:         * @version 1.0
055:         */
056:        public class JTextComponentTest extends JComponentTest {
057:            /** Contains the expected text of the tested text component */
058:            private String targetText;
059:
060:            /** Contains whether or not the target text is a regular expression. */
061:            private boolean isRegExp;
062:
063:            /**
064:             * Creates a new test with the specified values.
065:             *
066:             * @param env env the environment
067:             * @param componentName the name of the component
068:             * @param isIgnoring if the test result should be ignored
069:             * @param isCorrecting if the values of the component should be corrected when the test has
070:             *        failed
071:             * @param hasFocus if the component has the focus
072:             * @param isEnabled if the component is set enabled
073:             * @param targetText the text which should be contained in the text component
074:             * @param isRegExp whether or not the target text is a regular expression
075:             */
076:            public JTextComponentTest(Environment env, String componentName,
077:                    boolean isIgnoring, boolean isCorrecting, boolean hasFocus,
078:                    boolean isEnabled, String targetText, boolean isRegExp) {
079:                super (env, componentName, isIgnoring, isCorrecting, hasFocus,
080:                        isEnabled);
081:                setTargetText(targetText);
082:                setRegExp(isRegExp);
083:            }
084:
085:            /**
086:             * Creates a new test with the values of the given component and default values. The target
087:             * text is not a regular expression
088:             *
089:             * @param env the environment.
090:             * @param components the components instance
091:             * @param component the component to test. Must be of type
092:             *        <code>javax.swing.JTextComponent</code>.
093:             */
094:            public JTextComponentTest(Environment env, Components components,
095:                    Component component) {
096:                super (env, components, component);
097:                setTargetText(((JTextComponent) component).getText());
098:                setRegExp(false);
099:            }
100:
101:            /**
102:             * Creates a new test with default values and no environment. The environment should be defined
103:             * with the method {@link jacareto.system.EnvironmentMember#setEnvironment(Environment)}
104:             * before environment instances will be accessed.
105:             */
106:            public JTextComponentTest() {
107:                this (null, "", false, false, false, true, "", false);
108:            }
109:
110:            /**
111:             * DOCUMENT ME!
112:             *
113:             * @param isRegExp whether or not the target text is a regular expression
114:             */
115:            public void setRegExp(boolean isRegExp) {
116:                this .isRegExp = isRegExp;
117:            }
118:
119:            /**
120:             * DOCUMENT ME!
121:             *
122:             * @return <code>true</code> if the target text is a regular expression, if not
123:             *         <code>false</code>.
124:             */
125:            public boolean isRegExp() {
126:                return isRegExp;
127:            }
128:
129:            /**
130:             * DOCUMENT ME!
131:             *
132:             * @param targetText the expected text of the tested text component
133:             */
134:            public void setTargetText(String targetText) {
135:                this .targetText = targetText;
136:            }
137:
138:            /**
139:             * DOCUMENT ME!
140:             *
141:             * @return The expected text of the tested text component
142:             */
143:            public String getTargetText() {
144:                return targetText;
145:            }
146:
147:            /**
148:             * @see jacareto.struct.StructureElement#getElementName()
149:             */
150:            public String getElementName() {
151:                return language.getString("Tests.JTextComponentTest.Name");
152:            }
153:
154:            /**
155:             * @see jacareto.struct.StructureElement#getElementDescription()
156:             */
157:            public String getElementDescription() {
158:                return language
159:                        .getString("Tests.JTextComponentTest.Description");
160:            }
161:
162:            /**
163:             * @see jacareto.struct.StructureElement#toShortString()
164:             */
165:            public String toShortString() {
166:                return getElementName();
167:            }
168:
169:            /**
170:             * @see jacareto.test.Test#evaluate(jacareto.comp.Components)
171:             */
172:            public boolean evaluate(Components components) {
173:                setLastIgnored(isIgnoring());
174:                setLastResult(false);
175:                setLastCorrected(false);
176:
177:                JTextComponent textComp = null;
178:
179:                // get the text component with the componentName
180:                Component component = components
181:                        .getComponent(getComponentName());
182:
183:                if (component == null) {
184:                    setEvaluationMessage(language
185:                            .getString("Tests.Test.Failure.NoComponent"));
186:
187:                    return false;
188:                }
189:
190:                if (!(component instanceof  JTextComponent)) {
191:                    setEvaluationMessage(language
192:                            .getString("Tests.Test.Failure.WrongComponentType"));
193:
194:                    return false;
195:                }
196:
197:                textComp = (JTextComponent) component;
198:
199:                if (doTest(textComp)) {
200:                    boolean result = true;
201:                    Iterator childIter = childrenIterator();
202:
203:                    while (childIter.hasNext() && result) {
204:                        result &= evaluateChild((Test) childIter.next(),
205:                                components);
206:                    }
207:
208:                    setLastResult(result);
209:
210:                    return result;
211:                }
212:
213:                if (isCorrecting()) {
214:                    //appendToEvaluationMessage("\n" + language.getString("Test.Correct"));
215:                    correct(textComp);
216:                    setLastCorrected(true);
217:                }
218:
219:                //if(isIgnoring()) appendToEvaluationMessage("\n" + language.getString("Test.Ignored"));
220:                return false;
221:            }
222:
223:            /**
224:             * @see jacareto.test.JComponentTest#doTest(java.awt.Component)
225:             */
226:            protected boolean doTest(Component component) {
227:                if (super .doTest(component)) {
228:                    JTextComponent textComp = (JTextComponent) component;
229:                    String currentText = textComp.getText();
230:                    String targetText = getTargetText();
231:
232:                    if (!isRegExp) {
233:                        if (!currentText.equals(targetText)) {
234:                            setEvaluationMessage(language
235:                                    .getString("Tests.JTextComponentTest.Failure.WrongText")
236:                                    + "\n"
237:                                    + language
238:                                            .getString("Tests.Test.Failure.Expected")
239:                                    + ": "
240:                                    + targetText
241:                                    + "\n"
242:                                    + language
243:                                            .getString("Tests.Test.Failure.Detected")
244:                                    + ": " + currentText);
245:
246:                            return false;
247:                        }
248:                    } else {
249:                        try {
250:                            if (!(new RE(targetText).match(currentText))) {
251:                                setEvaluationMessage(language
252:                                        .getString("Tests.JTextComponentTest.Failure.RegExpMismatch")
253:                                        + "\n"
254:                                        + language
255:                                                .getString("Tests.JTextComponentTest.RegExp")
256:                                        + ": "
257:                                        + targetText
258:                                        + "\n"
259:                                        + language
260:                                                .getString("Tests.Test.Failure.Detected")
261:                                        + ": " + currentText);
262:
263:                                return false;
264:                            }
265:                        } catch (RESyntaxException ex) {
266:                            setEvaluationMessage(language
267:                                    .getString("Tests.JTextComponentTest.Failure.RegExpSyntax")
268:                                    + "\n"
269:                                    + language
270:                                            .getString("Tests.JTextComponentTest.RegExp")
271:                                    + ": " + targetText);
272:                        }
273:                    }
274:                } else {
275:                    return false;
276:                }
277:
278:                return true;
279:            }
280:
281:            /**
282:             * @see jacareto.test.JComponentTest#correct(java.awt.Component)
283:             */
284:            protected void correct(Component component) {
285:                super .correct(component);
286:
287:                JTextComponent textComp = (JTextComponent) component;
288:
289:                if (!isRegExp()) {
290:                    textComp.setText(targetText);
291:                    appendToEvaluationMessage("\n"
292:                            + getElementName()
293:                            + ": "
294:                            + language
295:                                    .getString("Tests.JTextComponentTest.Correct.Text"));
296:                } else {
297:                    appendToEvaluationMessage("\n"
298:                            + getElementName()
299:                            + ": "
300:                            + language
301:                                    .getString("Tests.JTextComponentTest.Correct.TextFailure"));
302:                }
303:            }
304:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.