View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.actions.loadtest;
14  
15  import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
16  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
17  import com.eviware.soapui.model.settings.Settings;
18  import com.eviware.soapui.settings.HttpSettings;
19  import com.eviware.soapui.support.UISupport;
20  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
21  import com.eviware.x.form.XFormDialog;
22  import com.eviware.x.form.XFormField;
23  import com.eviware.x.form.XFormFieldListener;
24  import com.eviware.x.form.support.ADialogBuilder;
25  import com.eviware.x.form.support.AField;
26  import com.eviware.x.form.support.AForm;
27  import com.eviware.x.form.support.AField.AFieldType;
28  
29  /***
30   * Displays the LoadTest Options dialog
31   * 
32   * @author Ole.Matzura
33   */
34  
35  public class LoadTestOptionsAction extends AbstractSoapUIAction<WsdlLoadTest>
36  {
37  	public static final String SOAPUI_ACTION_ID = "LoadTestOptionsAction";
38  	private XFormDialog dialog;
39  
40  	public LoadTestOptionsAction()
41     {
42  		super( "Options","Sets options for this LoadTest" );
43     }
44  	
45  	public void perform( WsdlLoadTest loadTest, Object param )
46  	{
47  		if( dialog == null )
48  			buildDialog();
49  		
50  		dialog.setIntValue( Form.THREAD_STARTUP_DELAY, loadTest.getStartDelay() );
51  		dialog.setBooleanValue( Form.RESET_STATISTICS, loadTest.getResetStatisticsOnThreadCountChange() );
52  		dialog.setBooleanValue( Form.CALC_TPS, loadTest.getCalculateTPSOnTimePassed() );
53  		dialog.setIntValue( Form.SAMPLE_INTERVAL, ( int ) loadTest.getSampleInterval() );
54  		dialog.setBooleanValue( Form.DISABLE_HISTORY, loadTest.getHistoryLimit() == 0 );
55  		dialog.setIntValue( Form.MAX_ASSERTIONS, ( int ) loadTest.getMaxAssertionErrors() );
56  		
57  		Settings settings = loadTest.getSettings();
58  		
59  		dialog.setBooleanValue( Form.INCLUDE_REQUEST, settings.getBoolean( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN ));
60  		dialog.setBooleanValue( Form.INCLUDE_RESPONSE, settings.getBoolean( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN ));
61  		dialog.setBooleanValue( Form.CLOSE_CONNECTIONS, settings.getBoolean( HttpSettings.CLOSE_CONNECTIONS ));
62  	
63  		if( dialog.show() )
64  		{
65  			try
66  			{
67  				loadTest.setStartDelay( dialog.getIntValue( Form.THREAD_STARTUP_DELAY, loadTest.getStartDelay() ));
68  				loadTest.setResetStatisticsOnThreadCountChange( dialog.getBooleanValue( Form.RESET_STATISTICS ));
69  				loadTest.setCalculateTPSOnTimePassed( dialog.getBooleanValue( Form.CALC_TPS ));
70  				loadTest.setSampleInterval( dialog.getIntValue( Form.SAMPLE_INTERVAL, ( int ) loadTest.getSampleInterval() ));
71  				loadTest.setHistoryLimit( dialog.getBooleanValue( Form.DISABLE_HISTORY ) ? 0 : -1 );
72  				loadTest.setMaxAssertionErrors( dialog.getIntValue( Form.MAX_ASSERTIONS, 1000 ));
73  				
74  				
75  				settings.setBoolean( HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN, 
76  							dialog.getBooleanValue( Form.INCLUDE_REQUEST ));
77  				settings.setBoolean( HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN, 
78  							dialog.getBooleanValue( Form.INCLUDE_RESPONSE ));
79  				settings.setBoolean( HttpSettings.CLOSE_CONNECTIONS, 
80  							dialog.getBooleanValue( Form.CLOSE_CONNECTIONS ));
81  			}
82  			catch (NumberFormatException ex)
83  			{
84  			}			
85  		}
86  	}
87  
88  	private void buildDialog()
89  	{
90  	   dialog = ADialogBuilder.buildDialog( Form.class );
91  	   dialog.getFormField( Form.DISABLE_HISTORY ).addFormFieldListener( new XFormFieldListener() {
92  
93  			public void valueChanged( XFormField sourceField, String newValue, String oldValue )
94  			{
95  				dialog.getFormField( Form.SAMPLE_INTERVAL ).setEnabled( !Boolean.parseBoolean( newValue ) );
96  			}} );
97  	}
98  	
99  	@AForm( name="LoadTest Options", description = "Set options for this LoadTest", 
100 				helpUrl=HelpUrls.LOADTESTOPTIONS_HELP_URL, icon=UISupport.OPTIONS_ICON_PATH )
101 	private interface Form 
102 	{
103 		@AField(name = "Thread startup delay", description = "The delay before starting a thread in ms", type = AFieldType.INT )
104 		public final static String THREAD_STARTUP_DELAY = "Thread startup delay";
105 		
106 		@AField(name = "Reset statistics", description = "when the number of threads changes", type = AFieldType.BOOLEAN )
107 		public final static String RESET_STATISTICS = "Reset statistics";
108 
109 		@AField(name = "Calculate TPS/BPS", description = "based on actual time passed", type = AFieldType.BOOLEAN )
110 		public final static String CALC_TPS = "Calculate TPS/BPS";
111 		
112 		@AField(name = "Include request write", description = "in calculated time", type = AFieldType.BOOLEAN )
113 		public final static String INCLUDE_REQUEST = "Include request write";
114 		
115 		@AField(name = "Include response read", description = "in calculated time", type = AFieldType.BOOLEAN )
116 		public final static String INCLUDE_RESPONSE = "Include response read";
117 		
118 		@AField(name = "Close connections", description = "between each request", type = AFieldType.BOOLEAN )
119 		public final static String CLOSE_CONNECTIONS = "Close connections";
120 		
121 		@AField(name = "Sample interval", description = "in calculated time", type = AFieldType.INT )
122 		public final static String SAMPLE_INTERVAL = "Sample interval";
123 		
124 		@AField(name = "Disable History", description = "to preserve memory (will disable diagrams)", type = AFieldType.BOOLEAN )
125 		public final static String DISABLE_HISTORY = "Disable History";
126 		
127 		@AField(name = "Max Assertions in Log", description = "the maximum number of assertion errors to keep in log (to preserve memory)", type = AFieldType.INT )
128 		public final static String MAX_ASSERTIONS = "Max Assertions in Log";
129 	}
130 }