Source Code Cross Referenced for SimpleLoadStrategy.java in  » Web-Services » soapui-1.7.5 » com » eviware » soapui » impl » wsdl » loadtest » strategy » 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 » Web Services » soapui 1.7.5 » com.eviware.soapui.impl.wsdl.loadtest.strategy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  soapUI, copyright (C) 2004-2007 eviware.com 
003:         *
004:         *  soapUI is free software; you can redistribute it and/or modify it under the 
005:         *  terms of version 2.1 of the GNU Lesser General Public License as published by 
006:         *  the Free Software Foundation.
007:         *
008:         *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
009:         *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
010:         *  See the GNU Lesser General Public License for more details at gnu.org.
011:         */
012:
013:        package com.eviware.soapui.impl.wsdl.loadtest.strategy;
014:
015:        import javax.swing.JComponent;
016:        import javax.swing.JLabel;
017:        import javax.swing.JPanel;
018:        import javax.swing.JTextField;
019:        import javax.swing.text.Document;
020:
021:        import org.apache.xmlbeans.XmlObject;
022:
023:        import com.eviware.soapui.SoapUI;
024:        import com.eviware.soapui.model.testsuite.LoadTestRunContext;
025:        import com.eviware.soapui.model.testsuite.LoadTestRunner;
026:        import com.eviware.soapui.model.testsuite.TestRunContext;
027:        import com.eviware.soapui.model.testsuite.TestRunner;
028:        import com.eviware.soapui.support.DocumentListenerAdapter;
029:        import com.eviware.soapui.support.UISupport;
030:        import com.eviware.soapui.support.xml.XmlObjectConfigurationBuilder;
031:        import com.eviware.soapui.support.xml.XmlObjectConfigurationReader;
032:        import com.jgoodies.forms.builder.ButtonBarBuilder;
033:
034:        /**
035:         * LoadStrategy allowing maximum runs and request delays
036:         * 
037:         * @author Ole.Matzura
038:         */
039:
040:        public class SimpleLoadStrategy extends AbstractLoadStrategy {
041:            private static final int DEFAULT_TEST_DELAY = 1000;
042:
043:            private static final float DEFAULT_RANDOM_FACTOR = 0.5F;
044:
045:            public static final String STRATEGY_TYPE = "Simple";
046:
047:            private int testDelay = DEFAULT_TEST_DELAY;
048:            private float randomFactor = DEFAULT_RANDOM_FACTOR;
049:
050:            private JPanel configPanel;
051:            private JTextField testDelayField;
052:            private JTextField randomFactorField;
053:
054:            public SimpleLoadStrategy(XmlObject config) {
055:                super (STRATEGY_TYPE);
056:
057:                if (config != null) {
058:                    XmlObjectConfigurationReader reader = new XmlObjectConfigurationReader(
059:                            config);
060:                    testDelay = reader.readInt("testDelay", DEFAULT_TEST_DELAY);
061:                    randomFactor = reader.readFloat("randomFactor",
062:                            DEFAULT_RANDOM_FACTOR);
063:                }
064:            }
065:
066:            public XmlObject getConfig() {
067:                XmlObjectConfigurationBuilder builder = new XmlObjectConfigurationBuilder();
068:                builder.add("testDelay", testDelay);
069:                builder.add("randomFactor", randomFactor);
070:                return builder.finish();
071:            }
072:
073:            public void beforeTestCase(LoadTestRunner loadTestRunner,
074:                    LoadTestRunContext context, TestRunner testRunner,
075:                    TestRunContext runContext) {
076:                int delay = calculateDelay(testDelay);
077:                if (delay == 0)
078:                    return;
079:                try {
080:                    Thread.sleep(delay);
081:                } catch (InterruptedException e) {
082:                    SoapUI.logError(e);
083:                }
084:            }
085:
086:            public int calculateDelay(int delay) {
087:                if (delay == 0 || randomFactor == 0)
088:                    return delay;
089:
090:                int fixDelay = (int) ((float) delay * (1 - randomFactor));
091:                int randDelay = (int) (randomFactor == 0 ? 0
092:                        : (float) (delay - fixDelay) * Math.random());
093:                return fixDelay + randDelay;
094:            }
095:
096:            public JComponent getConfigurationPanel() {
097:                if (configPanel == null) {
098:                    ButtonBarBuilder builder = new ButtonBarBuilder();
099:
100:                    testDelayField = new JTextField(5);
101:                    UISupport.setPreferredHeight(testDelayField, 18);
102:                    testDelayField.setHorizontalAlignment(JTextField.RIGHT);
103:                    testDelayField.setText(String.valueOf(testDelay));
104:                    testDelayField
105:                            .setToolTipText("Sets the delay between each test run in milliseconds");
106:                    testDelayField.getDocument().addDocumentListener(
107:                            new ConfigDocumentListener());
108:
109:                    builder.addFixed(new JLabel("Test Delay"));
110:                    builder.addRelatedGap();
111:
112:                    builder.addFixed(testDelayField);
113:                    builder.addRelatedGap();
114:
115:                    randomFactorField = new JTextField(4);
116:                    UISupport.setPreferredHeight(randomFactorField, 18);
117:                    randomFactorField.setHorizontalAlignment(JTextField.RIGHT);
118:                    randomFactorField.setText(String.valueOf(randomFactor));
119:                    randomFactorField
120:                            .setToolTipText("Specifies the relativt amount of randomization for delay (0 = no random, 1 = all random)");
121:                    randomFactorField.getDocument().addDocumentListener(
122:                            new ConfigDocumentListener());
123:
124:                    builder.addFixed(new JLabel("Random"));
125:                    builder.addRelatedGap();
126:                    builder.addFixed(randomFactorField);
127:
128:                    configPanel = builder.getPanel();
129:                }
130:
131:                return configPanel;
132:            }
133:
134:            private final class ConfigDocumentListener extends
135:                    DocumentListenerAdapter {
136:                public void update(Document document) {
137:                    try {
138:                        if (document == testDelayField.getDocument())
139:                            testDelay = Integer.parseInt(testDelayField
140:                                    .getText());
141:                        if (document == randomFactorField.getDocument())
142:                            randomFactor = Float.parseFloat(randomFactorField
143:                                    .getText().replace(',', '.'));
144:
145:                        notifyConfigurationChanged();
146:                    } catch (NumberFormatException e) {
147:                    }
148:                }
149:            }
150:
151:            /**
152:             * Factory for SimpleLoadStrategy class
153:             * 
154:             * @author Ole.Matzura
155:             */
156:
157:            public static class Factory implements  LoadStrategyFactory {
158:                public String getType() {
159:                    return STRATEGY_TYPE;
160:                }
161:
162:                public LoadStrategy build(XmlObject config) {
163:                    return new SimpleLoadStrategy(config);
164:                }
165:
166:                public LoadStrategy create() {
167:                    return new SimpleLoadStrategy(null);
168:                }
169:            }
170:        }
w__w__w___.__j_av_a2s.___c___o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.