1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.loadtest;
14
15 import java.awt.event.ActionEvent;
16
17 import javax.swing.AbstractAction;
18 import javax.swing.Action;
19
20 import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
21 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
22 import com.eviware.soapui.model.settings.Settings;
23 import com.eviware.soapui.settings.HttpSettings;
24 import com.eviware.soapui.support.UISupport;
25 import com.eviware.x.form.XFormDialog;
26 import com.eviware.x.form.XFormField;
27 import com.eviware.x.form.XFormFieldListener;
28 import com.eviware.x.form.support.ADialogBuilder;
29 import com.eviware.x.form.support.AField;
30 import com.eviware.x.form.support.AForm;
31 import com.eviware.x.form.support.AField.AFieldType;
32
33 /***
34 * Displays the LoadTest Options dialog
35 *
36 * @author Ole.Matzura
37 */
38
39 public class LoadTestOptionsAction extends AbstractAction
40 {
41 private final WsdlLoadTest loadTest;
42 private XFormDialog dialog;
43
44 public LoadTestOptionsAction( WsdlLoadTest loadTest )
45 {
46 this.loadTest = loadTest;
47
48 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/options.gif"));
49 putValue( Action.SHORT_DESCRIPTION, "Sets options for this LoadTest" );
50 }
51
52 public void actionPerformed(ActionEvent e)
53 {
54 if( dialog == null )
55 buildDialog();
56
57 dialog.setIntValue( Form.THREAD_STARTUP_DELAY, loadTest.getStartDelay() );
58 dialog.setBooleanValue( Form.RESET_STATISTICS, loadTest.getResetStatisticsOnThreadCountChange() );
59 dialog.setBooleanValue( Form.CALC_TPS, loadTest.getCalculateTPSOnTimePassed() );
60 dialog.setIntValue( Form.SAMPLE_INTERVAL, ( int ) loadTest.getSampleInterval() );
61 dialog.setBooleanValue( Form.DISABLE_HISTORY, loadTest.getHistoryLimit() == 0 );
62
63 Settings settings = loadTest.getSettings();
64
65 dialog.setBooleanValue( Form.INCLUDE_REQUEST, settings.getBoolean( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN ));
66 dialog.setBooleanValue( Form.INCLUDE_RESPONSE, settings.getBoolean( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN ));
67 dialog.setBooleanValue( Form.CLOSE_CONNECTIONS, settings.getBoolean( HttpSettings.CLOSE_CONNECTIONS ));
68
69 if( dialog.show() )
70 {
71 try
72 {
73 loadTest.setStartDelay( dialog.getIntValue( Form.THREAD_STARTUP_DELAY, loadTest.getStartDelay() ));
74 loadTest.setResetStatisticsOnThreadCountChange( dialog.getBooleanValue( Form.RESET_STATISTICS ));
75 loadTest.setCalculateTPSOnTimePassed( dialog.getBooleanValue( Form.CALC_TPS ));
76 loadTest.setSampleInterval( dialog.getIntValue( Form.SAMPLE_INTERVAL, ( int ) loadTest.getSampleInterval() ));
77 loadTest.setHistoryLimit( dialog.getBooleanValue( Form.DISABLE_HISTORY ) ? 0 : -1 );
78 settings.setBoolean( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN,
79 dialog.getBooleanValue( Form.INCLUDE_REQUEST ));
80 settings.setBoolean( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN,
81 dialog.getBooleanValue( Form.INCLUDE_RESPONSE ));
82 settings.setBoolean( HttpSettings.CLOSE_CONNECTIONS,
83 dialog.getBooleanValue( Form.CLOSE_CONNECTIONS ));
84 }
85 catch (NumberFormatException ex)
86 {
87 }
88 }
89 }
90
91 private void buildDialog()
92 {
93 dialog = ADialogBuilder.buildDialog( Form.class );
94 dialog.getFormField( Form.DISABLE_HISTORY ).addFormFieldListener( new XFormFieldListener() {
95
96 public void valueChanged( XFormField sourceField, String newValue, String oldValue )
97 {
98 dialog.getFormField( Form.SAMPLE_INTERVAL ).setEnabled( !Boolean.parseBoolean( newValue ) );
99 }} );
100 }
101
102 @AForm( name="LoadTest Options", description = "Set options for this LoadTest", helpUrl=HelpUrls.LOADTESTOPTIONS_HELP_URL,
103 icon="/preferences-system.png")
104 private interface Form
105 {
106 @AField(name = "Thread startup delay", description = "The delay before starting a thread in ms", type = AFieldType.INT )
107 public final static String THREAD_STARTUP_DELAY = "Thread startup delay";
108
109 @AField(name = "Reset statistics", description = "when the number of threads changes", type = AFieldType.BOOLEAN )
110 public final static String RESET_STATISTICS = "Reset statistics";
111
112 @AField(name = "Calculate TPS/BPS", description = "based on actual time passed", type = AFieldType.BOOLEAN )
113 public final static String CALC_TPS = "Calculate TPS/BPS";
114
115 @AField(name = "Include request write", description = "in calculated time", type = AFieldType.BOOLEAN )
116 public final static String INCLUDE_REQUEST = "Include request write";
117
118 @AField(name = "Include response read", description = "in calculated time", type = AFieldType.BOOLEAN )
119 public final static String INCLUDE_RESPONSE = "Include response read";
120
121 @AField(name = "Close connections", description = "between each request", type = AFieldType.BOOLEAN )
122 public final static String CLOSE_CONNECTIONS = "Close connections";
123
124 @AField(name = "Sample interval", description = "in calculated time", type = AFieldType.INT )
125 public final static String SAMPLE_INTERVAL = "Sample interval";
126
127 @AField(name = "Disable History", description = "to preserve memory (will disable diagrams)", type = AFieldType.BOOLEAN )
128 public final static String DISABLE_HISTORY = "Disable History";
129 }
130 }