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.soapui.support.types.StringToStringMap;
26 import com.eviware.x.form.XForm;
27 import com.eviware.x.form.XFormDialog;
28 import com.eviware.x.form.XFormDialogBuilder;
29 import com.eviware.x.form.XFormFactory;
30 import com.eviware.x.form.XForm.FieldType;
31
32 /***
33 * Displays the LoadTest Options dialog
34 *
35 * @author Ole.Matzura
36 */
37
38 public class LoadTestOptionsAction extends AbstractAction
39 {
40 private static final String THREAD_STARTUP_DELAY = "Thread startup delay";
41 private static final String RESET_STATISTICS = "Reset statistics";
42 private static final String CALC_TPS = "Calculate TPS/BPS";
43 private static final String INCLUDE_REQUEST = "Include request write";
44 private static final String INCLUDE_RESPONSE = "Include response read";
45 private static final String CLOSE_CONNECTIONS = "Close connections";
46 private static final String SAMPLE_INTERVAL = "Sample interval";
47 private final WsdlLoadTest loadTest;
48 private XFormDialog dialog;
49
50 public LoadTestOptionsAction( WsdlLoadTest loadTest )
51 {
52 this.loadTest = loadTest;
53
54 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/options.gif"));
55 putValue( Action.SHORT_DESCRIPTION, "Sets options for this LoadTest" );
56 }
57
58 public void actionPerformed(ActionEvent e)
59 {
60 if( dialog == null )
61 buildDialog();
62
63 StringToStringMap values = new StringToStringMap();
64
65 values.put( THREAD_STARTUP_DELAY, String.valueOf( loadTest.getStartDelay()) );
66 values.put( RESET_STATISTICS, String.valueOf( loadTest.getResetStatisticsOnThreadCountChange()) );
67 values.put( CALC_TPS, String.valueOf( loadTest.getCalculateTPSOnTimePassed()) );
68 values.put( SAMPLE_INTERVAL, String.valueOf( loadTest.getSampleInterval()) );
69
70 Settings settings = loadTest.getSettings();
71 values.put( INCLUDE_REQUEST, String.valueOf( settings.getBoolean( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN )));
72 values.put( INCLUDE_RESPONSE, String.valueOf( settings.getBoolean( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN )));
73 values.put( CLOSE_CONNECTIONS, String.valueOf( settings.getBoolean( HttpSettings.CLOSE_CONNECTIONS )));
74
75 values = dialog.show( values );
76
77 if( dialog.getReturnValue() == XFormDialog.OK_OPTION )
78 {
79 try
80 {
81 loadTest.setStartDelay(Integer.parseInt(values.get(THREAD_STARTUP_DELAY)));
82 loadTest.setResetStatisticsOnThreadCountChange( Boolean.parseBoolean( values.get( RESET_STATISTICS )));
83 loadTest.setCalculateTPSOnTimePassed( Boolean.parseBoolean( values.get( CALC_TPS )));
84 loadTest.setSampleInterval( Integer.parseInt(values.get(SAMPLE_INTERVAL)));
85 settings.setBoolean( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN,
86 Boolean.parseBoolean( values.get( INCLUDE_REQUEST )));
87 settings.setBoolean( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN,
88 Boolean.parseBoolean( values.get( INCLUDE_RESPONSE )));
89 settings.setBoolean( HttpSettings.CLOSE_CONNECTIONS,
90 Boolean.parseBoolean( values.get( CLOSE_CONNECTIONS )));
91 }
92 catch (NumberFormatException ex)
93 {
94 }
95 }
96 }
97
98 private void buildDialog()
99 {
100 XFormDialogBuilder builder = XFormFactory.createDialogBuilder( "LoadTest Options" );
101 XForm form = builder.createForm( "Basic" );
102
103 form.addTextField( THREAD_STARTUP_DELAY, "The delay before starting a thread in ms", FieldType.TEXT ).setWidth( 10 );
104 form.addCheckBox( RESET_STATISTICS, "when the number of threads changes" );
105 form.addCheckBox( CALC_TPS, "based on actual time passed" );
106 form.addCheckBox( INCLUDE_REQUEST, "in calculated time" );
107 form.addCheckBox( INCLUDE_RESPONSE, "in calculated time" );
108 form.addCheckBox( CLOSE_CONNECTIONS, "after each request" );
109 form.addTextField( SAMPLE_INTERVAL, "the frequency of statistics updates in ms", FieldType.TEXT ).setWidth( 10 );
110
111 dialog = builder.buildDialog( builder.buildOkCancelHelpActions( HelpUrls.LOADTESTOPTIONS_HELP_URL ),
112 "Specify general options for this LoadTest", UISupport.TOOL_ICON );
113 }
114 }