Source Code Cross Referenced for TestStepMaxAssertion.java in  » Web-Services » soapui-1.7.5 » com » eviware » soapui » impl » wsdl » loadtest » assertions » 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.assertions 
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.assertions;
014:
015:        import java.util.List;
016:
017:        import org.apache.log4j.Logger;
018:        import org.apache.xmlbeans.XmlObject;
019:
020:        import com.eviware.soapui.config.LoadTestAssertionConfig;
021:        import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
022:        import com.eviware.soapui.impl.wsdl.loadtest.data.LoadTestStatistics;
023:        import com.eviware.soapui.impl.wsdl.loadtest.data.LoadTestStatistics.Statistic;
024:        import com.eviware.soapui.impl.wsdl.support.Configurable;
025:        import com.eviware.soapui.impl.wsdl.support.HelpUrls;
026:        import com.eviware.soapui.model.testsuite.LoadTestRunContext;
027:        import com.eviware.soapui.model.testsuite.LoadTestRunner;
028:        import com.eviware.soapui.model.testsuite.TestRunContext;
029:        import com.eviware.soapui.model.testsuite.TestRunner;
030:        import com.eviware.soapui.model.testsuite.TestStep;
031:        import com.eviware.soapui.model.testsuite.TestStepResult;
032:        import com.eviware.soapui.support.UISupport;
033:        import com.eviware.soapui.support.types.StringToStringMap;
034:        import com.eviware.soapui.support.xml.XmlObjectConfigurationBuilder;
035:        import com.eviware.soapui.support.xml.XmlObjectConfigurationReader;
036:        import com.eviware.x.form.XForm;
037:        import com.eviware.x.form.XFormDialog;
038:        import com.eviware.x.form.XFormDialogBuilder;
039:        import com.eviware.x.form.XFormFactory;
040:        import com.eviware.x.form.XForm.FieldType;
041:
042:        /**
043:         * LoadTestAssertion for asserting the maximum step time
044:         * 
045:         * @author Ole.Matzura
046:         */
047:
048:        public class TestStepMaxAssertion extends AbstractLoadTestAssertion
049:                implements  Configurable {
050:            private static final String NAME_FIELD = "Name";
051:            private static final String NAME_ELEMENT = "name";
052:            private static final String MAX_VALUE_ELEMENT = "max-value";
053:            private static final String MIN_REQUESTS_ELEMENT = "min-requests";
054:            private static final String MAX_VALUE_FIELD = "Max Time";
055:            private static final String MINIMUM_REQUESTS_FIELD = "Minimum Requests";
056:            private static final String MAX_ERRORS_ELEMENT = "max-errors";
057:            private static final String MAX_ERRORS_FIELD = "Max Errors";
058:
059:            private int minRequests;
060:            private int maxValue;
061:            private int maxErrors;
062:            private XFormDialog dialog;
063:            public static final String STEP_MAXIMUM_TYPE = "Step Maximum";
064:            private final static Logger log = Logger
065:                    .getLogger(TestStepMaxAssertion.class);
066:
067:            public TestStepMaxAssertion(
068:                    LoadTestAssertionConfig assertionConfig,
069:                    WsdlLoadTest loadTest) {
070:                super (assertionConfig, loadTest);
071:
072:                init(assertionConfig);
073:                initIcon("/max_loadtest_assertion.gif");
074:            }
075:
076:            private void init(LoadTestAssertionConfig assertionConfig) {
077:                XmlObject configuration = assertionConfig.getConfiguration();
078:
079:                XmlObjectConfigurationReader reader = new XmlObjectConfigurationReader(
080:                        configuration);
081:                setName(reader.readString(TestStepMaxAssertion.NAME_ELEMENT,
082:                        "Step Maximum"));
083:                minRequests = reader.readInt(
084:                        TestStepMaxAssertion.MIN_REQUESTS_ELEMENT, 100);
085:                maxValue = reader.readInt(
086:                        TestStepMaxAssertion.MAX_VALUE_ELEMENT, 1000);
087:                setTargetStep(reader.readString(
088:                        TestStepMaxAssertion.TEST_STEP_ELEMENT,
089:                        TestStepMaxAssertion.ANY_TEST_STEP));
090:                maxErrors = reader.readInt(MAX_ERRORS_ELEMENT, -1);
091:            }
092:
093:            public String assertResult(LoadTestRunner loadTestRunner,
094:                    LoadTestRunContext context, TestStepResult result,
095:                    TestRunner testRunner, TestRunContext runContext) {
096:                TestStep step = result.getTestStep();
097:                if (targetStepMatches(step)) {
098:                    WsdlLoadTest loadTest = (WsdlLoadTest) loadTestRunner
099:                            .getLoadTest();
100:                    LoadTestStatistics statisticsModel = loadTest
101:                            .getStatisticsModel();
102:
103:                    int index = step.getTestCase().getIndexOfTestStep(step);
104:
105:                    long maximum = result.getTimeTaken();
106:                    if (statisticsModel.getStatistic(index, Statistic.COUNT) > minRequests
107:                            && maximum >= maxValue) {
108:                        return returnErrorOrFail("Time [" + maximum
109:                                + "] exceeds limit [" + maxValue + "]",
110:                                maxErrors, loadTestRunner, context);
111:                    }
112:                }
113:
114:                return null;
115:            }
116:
117:            public String assertResults(LoadTestRunner loadTestRunner,
118:                    LoadTestRunContext context, TestRunner testRunner,
119:                    TestRunContext runContext) {
120:                if (ALL_TEST_STEPS.equals(getTargetStep())) {
121:                    WsdlLoadTest loadTest = (WsdlLoadTest) loadTestRunner
122:                            .getLoadTest();
123:                    LoadTestStatistics statisticsModel = loadTest
124:                            .getStatisticsModel();
125:
126:                    long sum = 0;
127:                    List<TestStepResult> results = testRunner.getResults();
128:                    for (int c = 0; c < results.size(); c++) {
129:                        TestStepResult result = results.get(c);
130:                        if (result == null) {
131:                            log.warn("Result [" + c + "] is null in TestCase ["
132:                                    + testRunner.getTestCase().getName() + "]");
133:                            continue;
134:                        }
135:
136:                        sum += result.getTimeTaken();
137:                    }
138:
139:                    if (statisticsModel.getStatistic(LoadTestStatistics.TOTAL,
140:                            Statistic.COUNT) >= minRequests
141:                            && sum >= maxValue) {
142:                        return returnErrorOrFail("Time [" + sum
143:                                + "] exceeds limit [" + maxValue + "]",
144:                                maxErrors, loadTestRunner, context);
145:                    }
146:                }
147:
148:                return null;
149:            }
150:
151:            public String getDescription() {
152:                return "testStep: " + getTargetStep() + ", minRequests: "
153:                        + minRequests + ", maxValue: " + maxValue
154:                        + ", maxErrors: " + maxErrors;
155:            }
156:
157:            public boolean configure() {
158:                if (dialog == null) {
159:                    buildDialog();
160:                }
161:
162:                StringToStringMap values = new StringToStringMap();
163:
164:                values.put(TestStepMaxAssertion.NAME_FIELD, getName());
165:                values.put(TestStepMaxAssertion.MINIMUM_REQUESTS_FIELD, String
166:                        .valueOf(minRequests));
167:                values.put(TestStepMaxAssertion.MAX_VALUE_FIELD, String
168:                        .valueOf(maxValue));
169:                values.put(TestStepMaxAssertion.TEST_STEP_FIELD,
170:                        getTargetStep());
171:                values.put(TestStepMaxAssertion.MAX_ERRORS_FIELD, String
172:                        .valueOf(maxErrors));
173:
174:                dialog.setOptions(TestStepMaxAssertion.TEST_STEP_FIELD,
175:                        getTargetStepOptions(true));
176:                values = dialog.show(values);
177:
178:                if (dialog.getReturnValue() == XFormDialog.OK_OPTION) {
179:                    try {
180:                        minRequests = Integer
181:                                .parseInt(values
182:                                        .get(TestStepMaxAssertion.MINIMUM_REQUESTS_FIELD));
183:                        maxValue = Integer.parseInt(values
184:                                .get(TestStepMaxAssertion.MAX_VALUE_FIELD));
185:                        maxErrors = Integer.parseInt(values
186:                                .get(TestStepMaxAssertion.MAX_ERRORS_FIELD));
187:                        setTargetStep(values
188:                                .get(TestStepMaxAssertion.TEST_STEP_FIELD));
189:                        setName(values.get(TestStepMaxAssertion.NAME_FIELD));
190:                    } catch (Exception e) {
191:                        UISupport.showErrorMessage(e.getMessage());
192:                    }
193:
194:                    updateConfiguration();
195:
196:                    return true;
197:                }
198:
199:                return false;
200:            }
201:
202:            protected void updateConfiguration() {
203:                XmlObjectConfigurationBuilder builder = new XmlObjectConfigurationBuilder();
204:
205:                builder.add(TestStepMaxAssertion.NAME_ELEMENT, getName());
206:                builder.add(TestStepMaxAssertion.MIN_REQUESTS_ELEMENT,
207:                        minRequests);
208:                builder.add(TestStepMaxAssertion.MAX_VALUE_ELEMENT, maxValue);
209:                builder.add(TestStepMaxAssertion.TEST_STEP_ELEMENT,
210:                        getTargetStep());
211:                builder.add(TestStepMaxAssertion.MAX_ERRORS_ELEMENT, maxErrors);
212:
213:                setConfiguration(builder.finish());
214:            }
215:
216:            private void buildDialog() {
217:                XFormDialogBuilder builder = XFormFactory
218:                        .createDialogBuilder("TestStep Max Assertion");
219:                XForm form = builder.createForm("Basic");
220:
221:                form.addTextField(TestStepMaxAssertion.NAME_FIELD,
222:                        "Name of this assertion", FieldType.TEXT);
223:                form.addTextField(TestStepMaxAssertion.MINIMUM_REQUESTS_FIELD,
224:                        "Minimum steps before asserting", FieldType.TEXT);
225:                form.addTextField(TestStepMaxAssertion.MAX_VALUE_FIELD,
226:                        "Maximum allowed step time", FieldType.TEXT);
227:                form.addTextField(TestStepMaxAssertion.MAX_ERRORS_FIELD,
228:                        "Maximum number of errors before failing",
229:                        FieldType.TEXT);
230:                form.addComboBox(TestStepMaxAssertion.TEST_STEP_FIELD,
231:                        new String[0], "TestStep to assert");
232:
233:                dialog = builder
234:                        .buildDialog(
235:                                builder
236:                                        .buildOkCancelHelpActions(HelpUrls.STEP_MAXIMUM_LOAD_TEST_ASSERTION_HELP_URL),
237:                                "Specify options for this TestStep Max Assertion",
238:                                UISupport.OPTIONS_ICON);
239:            }
240:        }
w_w_w__.___j_ava__2__s__.__com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.