Source Code Cross Referenced for TestWhileController.java in  » Testing » jakarta-jmeter » org » apache » jmeter » control » 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 » jakarta jmeter » org.apache.jmeter.control 
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:
019:        package org.apache.jmeter.control;
020:
021:        import org.apache.jmeter.junit.JMeterTestCase;
022:        import org.apache.jmeter.junit.stubs.TestSampler;
023:        import org.apache.jmeter.samplers.Sampler;
024:        import org.apache.jmeter.testelement.TestElement;
025:
026:        /**
027:         * @version $Revision: 595966 $
028:         */
029:        public class TestWhileController extends JMeterTestCase {
030:            static {
031:                // LoggingManager.setPriority("DEBUG","jmeter");
032:                // LoggingManager.setTarget(new java.io.PrintWriter(System.out));
033:            }
034:
035:            public TestWhileController(String name) {
036:                super (name);
037:            }
038:
039:            // Get next sample and its name
040:            private String nextName(GenericController c) {
041:                Sampler s = c.next();
042:                if (s == null) {
043:                    return null;
044:                } else {
045:                    return s.getPropertyAsString(TestElement.NAME);
046:                }
047:            }
048:
049:            // While (blank), previous sample OK - should loop until false
050:            public void testBlankPrevOK() throws Exception {
051:                //			log.info("testBlankPrevOK");
052:                runtestPrevOK("");
053:            }
054:
055:            // While (LAST), previous sample OK - should loop until false
056:            public void testLastPrevOK() throws Exception {
057:                //			log.info("testLASTPrevOK");
058:                runtestPrevOK("LAST");
059:            }
060:
061:            private static final String OTHER = "X"; // Dummy for testing
062:
063:            // functions
064:
065:            // While (LAST), previous sample OK - should loop until false
066:            public void testOtherPrevOK() throws Exception {
067:                //			log.info("testOtherPrevOK");
068:                runtestPrevOK(OTHER);
069:            }
070:
071:            public void runtestPrevOK(String type) throws Exception {
072:                GenericController controller = new GenericController();
073:                WhileController while_cont = new WhileController();
074:                while_cont.testMode = true;
075:                while_cont.testModeResult = true;
076:                while_cont.setCondition(type);
077:                while_cont.addTestElement(new TestSampler("one"));
078:                while_cont.addTestElement(new TestSampler("two"));
079:                while_cont.addTestElement(new TestSampler("three"));
080:                controller.addTestElement(while_cont);
081:                controller.addTestElement(new TestSampler("four"));
082:                controller.initialize();
083:                assertEquals("one", nextName(controller));
084:                assertEquals("two", nextName(controller));
085:                assertEquals("three", nextName(controller));
086:                assertEquals("one", nextName(controller));
087:                assertEquals("two", nextName(controller));
088:                assertEquals("three", nextName(controller));
089:                assertEquals("one", nextName(controller));
090:                while_cont.testModeResult = false;// one and two fail
091:                if (type.equals(OTHER))
092:                    while_cont.setCondition("false");
093:                assertEquals("two", nextName(controller));
094:                assertEquals("three", nextName(controller));
095:                while_cont.testModeResult = true;// but three OK, so does not exit
096:                if (type.equals(OTHER))
097:                    while_cont.setCondition(OTHER);
098:                assertEquals("one", nextName(controller));
099:                assertEquals("two", nextName(controller));
100:                assertEquals("three", nextName(controller));
101:                while_cont.testModeResult = false;// three fails, so exits while
102:                if (type.equals(OTHER))
103:                    while_cont.setCondition("false");
104:                assertEquals("four", nextName(controller));
105:                assertNull(nextName(controller));
106:                while_cont.testModeResult = true;
107:                if (type.equals(OTHER))
108:                    while_cont.setCondition(OTHER);
109:                assertEquals("one", nextName(controller));
110:            }
111:
112:            // While (blank), previous sample failed - should run once
113:            public void testBlankPrevFailed() throws Exception {
114:                //			log.info("testBlankPrevFailed");
115:                GenericController controller = new GenericController();
116:                WhileController while_cont = new WhileController();
117:                while_cont.testMode = true;
118:                while_cont.testModeResult = false;
119:                while_cont.setCondition("");
120:                while_cont.addTestElement(new TestSampler("one"));
121:                while_cont.addTestElement(new TestSampler("two"));
122:                controller.addTestElement(while_cont);
123:                controller.addTestElement(new TestSampler("three"));
124:                controller.initialize();
125:                assertEquals("one", nextName(controller));
126:                assertEquals("two", nextName(controller));
127:                assertEquals("three", nextName(controller));
128:                assertNull(nextName(controller));
129:                assertEquals("one", nextName(controller));
130:                assertEquals("two", nextName(controller));
131:                assertEquals("three", nextName(controller));
132:                assertNull(nextName(controller));
133:            }
134:
135:            // While LAST, previous sample failed - should not run
136:            public void testLASTPrevFailed() throws Exception {
137:                //			log.info("testLastPrevFailed");
138:                runTestPrevFailed("LAST");
139:            }
140:
141:            // While False, previous sample failed - should not run
142:            public void testfalsePrevFailed() throws Exception {
143:                //			log.info("testFalsePrevFailed");
144:                runTestPrevFailed("False");
145:            }
146:
147:            public void runTestPrevFailed(String s) throws Exception {
148:                GenericController controller = new GenericController();
149:                WhileController while_cont = new WhileController();
150:                while_cont.testMode = true;
151:                while_cont.testModeResult = false;
152:                while_cont.setCondition(s);
153:                while_cont.addTestElement(new TestSampler("one"));
154:                while_cont.addTestElement(new TestSampler("two"));
155:                controller.addTestElement(while_cont);
156:                controller.addTestElement(new TestSampler("three"));
157:                controller.initialize();
158:                assertEquals("three", nextName(controller));
159:                assertNull(nextName(controller));
160:                assertEquals("three", nextName(controller));
161:                assertNull(nextName(controller));
162:            }
163:
164:            // Tests for Stack Overflow (bug 33954)
165:            public void testAlwaysFailOK() throws Exception {
166:                runTestAlwaysFail(true); // Should be OK
167:            }
168:
169:            public void testAlwaysFailBAD() throws Exception {
170:                runTestAlwaysFail(false); // Currently fails
171:            }
172:
173:            public void runTestAlwaysFail(boolean other) {
174:                LoopController controller = new LoopController();
175:                controller.setContinueForever(true);
176:                controller.setLoops(-1);
177:                WhileController while_cont = new WhileController();
178:                while_cont.testMode = true;
179:                while_cont.testModeResult = false;
180:                while_cont.setCondition("false");
181:                while_cont.addTestElement(new TestSampler("one"));
182:                while_cont.addTestElement(new TestSampler("two"));
183:                controller.addTestElement(while_cont);
184:                if (other)
185:                    controller.addTestElement(new TestSampler("three"));
186:                controller.initialize();
187:                try {
188:                    if (other) {
189:                        assertEquals("three", nextName(controller));
190:                    } else {
191:                        assertNull(nextName(controller));
192:                    }
193:                } catch (StackOverflowError e) {
194:                    // e.printStackTrace();
195:                    fail(e.toString());
196:                }
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.