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.actions.loadtest;
014:
015: import java.awt.event.ActionEvent;
016:
017: import javax.swing.AbstractAction;
018: import javax.swing.Action;
019:
020: import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
021: import com.eviware.soapui.impl.wsdl.support.HelpUrls;
022: import com.eviware.soapui.model.settings.Settings;
023: import com.eviware.soapui.settings.HttpSettings;
024: import com.eviware.soapui.support.UISupport;
025: import com.eviware.x.form.XFormDialog;
026: import com.eviware.x.form.XFormField;
027: import com.eviware.x.form.XFormFieldListener;
028: import com.eviware.x.form.support.ADialogBuilder;
029: import com.eviware.x.form.support.AField;
030: import com.eviware.x.form.support.AForm;
031: import com.eviware.x.form.support.AField.AFieldType;
032:
033: /**
034: * Displays the LoadTest Options dialog
035: *
036: * @author Ole.Matzura
037: */
038:
039: public class LoadTestOptionsAction extends AbstractAction {
040: private final WsdlLoadTest loadTest;
041: private XFormDialog dialog;
042:
043: public LoadTestOptionsAction(WsdlLoadTest loadTest) {
044: this .loadTest = loadTest;
045:
046: putValue(Action.SMALL_ICON, UISupport
047: .createImageIcon("/options.gif"));
048: putValue(Action.SHORT_DESCRIPTION,
049: "Sets options for this LoadTest");
050: }
051:
052: public void actionPerformed(ActionEvent e) {
053: if (dialog == null)
054: buildDialog();
055:
056: dialog.setIntValue(Form.THREAD_STARTUP_DELAY, loadTest
057: .getStartDelay());
058: dialog.setBooleanValue(Form.RESET_STATISTICS, loadTest
059: .getResetStatisticsOnThreadCountChange());
060: dialog.setBooleanValue(Form.CALC_TPS, loadTest
061: .getCalculateTPSOnTimePassed());
062: dialog.setIntValue(Form.SAMPLE_INTERVAL, (int) loadTest
063: .getSampleInterval());
064: dialog.setBooleanValue(Form.DISABLE_HISTORY, loadTest
065: .getHistoryLimit() == 0);
066:
067: Settings settings = loadTest.getSettings();
068:
069: dialog
070: .setBooleanValue(
071: Form.INCLUDE_REQUEST,
072: settings
073: .getBoolean(HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN));
074: dialog
075: .setBooleanValue(
076: Form.INCLUDE_RESPONSE,
077: settings
078: .getBoolean(HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN));
079: dialog.setBooleanValue(Form.CLOSE_CONNECTIONS, settings
080: .getBoolean(HttpSettings.CLOSE_CONNECTIONS));
081:
082: if (dialog.show()) {
083: try {
084: loadTest.setStartDelay(dialog.getIntValue(
085: Form.THREAD_STARTUP_DELAY, loadTest
086: .getStartDelay()));
087: loadTest.setResetStatisticsOnThreadCountChange(dialog
088: .getBooleanValue(Form.RESET_STATISTICS));
089: loadTest.setCalculateTPSOnTimePassed(dialog
090: .getBooleanValue(Form.CALC_TPS));
091: loadTest.setSampleInterval(dialog.getIntValue(
092: Form.SAMPLE_INTERVAL, (int) loadTest
093: .getSampleInterval()));
094: loadTest
095: .setHistoryLimit(dialog
096: .getBooleanValue(Form.DISABLE_HISTORY) ? 0
097: : -1);
098: settings.setBoolean(
099: HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN,
100: dialog.getBooleanValue(Form.INCLUDE_REQUEST));
101: settings.setBoolean(
102: HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN,
103: dialog.getBooleanValue(Form.INCLUDE_RESPONSE));
104: settings.setBoolean(HttpSettings.CLOSE_CONNECTIONS,
105: dialog.getBooleanValue(Form.CLOSE_CONNECTIONS));
106: } catch (NumberFormatException ex) {
107: }
108: }
109: }
110:
111: private void buildDialog() {
112: dialog = ADialogBuilder.buildDialog(Form.class);
113: dialog.getFormField(Form.DISABLE_HISTORY).addFormFieldListener(
114: new XFormFieldListener() {
115:
116: public void valueChanged(XFormField sourceField,
117: String newValue, String oldValue) {
118: dialog
119: .getFormField(Form.SAMPLE_INTERVAL)
120: .setEnabled(
121: !Boolean.parseBoolean(newValue));
122: }
123: });
124: }
125:
126: @AForm(name="LoadTest Options",description="Set options for this LoadTest",helpUrl=HelpUrls.LOADTESTOPTIONS_HELP_URL,icon="/preferences-system.png")
127: private interface Form {
128: @AField(name="Thread startup delay",description="The delay before starting a thread in ms",type=AFieldType.INT)
129: public final static String THREAD_STARTUP_DELAY = "Thread startup delay";
130:
131: @AField(name="Reset statistics",description="when the number of threads changes",type=AFieldType.BOOLEAN)
132: public final static String RESET_STATISTICS = "Reset statistics";
133:
134: @AField(name="Calculate TPS/BPS",description="based on actual time passed",type=AFieldType.BOOLEAN)
135: public final static String CALC_TPS = "Calculate TPS/BPS";
136:
137: @AField(name="Include request write",description="in calculated time",type=AFieldType.BOOLEAN)
138: public final static String INCLUDE_REQUEST = "Include request write";
139:
140: @AField(name="Include response read",description="in calculated time",type=AFieldType.BOOLEAN)
141: public final static String INCLUDE_RESPONSE = "Include response read";
142:
143: @AField(name="Close connections",description="between each request",type=AFieldType.BOOLEAN)
144: public final static String CLOSE_CONNECTIONS = "Close connections";
145:
146: @AField(name="Sample interval",description="in calculated time",type=AFieldType.INT)
147: public final static String SAMPLE_INTERVAL = "Sample interval";
148:
149: @AField(name="Disable History",description="to preserve memory (will disable diagrams)",type=AFieldType.BOOLEAN)
150: public final static String DISABLE_HISTORY = "Disable History";
151: }
152: }
|