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.testcase;
14  
15  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
16  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
17  import com.eviware.soapui.settings.HttpSettings;
18  import com.eviware.soapui.support.UISupport;
19  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
20  import com.eviware.soapui.support.types.StringToStringMap;
21  import com.eviware.x.form.XForm;
22  import com.eviware.x.form.XFormDialog;
23  import com.eviware.x.form.XFormDialogBuilder;
24  import com.eviware.x.form.XFormFactory;
25  import com.eviware.x.form.XFormField;
26  import com.eviware.x.form.XFormFieldListener;
27  import com.eviware.x.form.XForm.FieldType;
28  
29  /***
30   * Options dialog for testcases
31   * 
32   * @author Ole.Matzura
33   */
34  
35  public class TestCaseOptionsAction extends AbstractSoapUIAction<WsdlTestCase>
36  {
37  	private static final String KEEP_SESSION = "Session";
38  	private static final String FAIL_ON_ERROR = "Abort on Error";
39  	private static final String FAIL_TESTCASE_ON_ERROR = "Fail TestCase on Error";
40  	private static final String DISCARD_OK_RESULTS = "Discard OK Results";
41  	private static final String SOCKET_TIMEOUT = "Socket timeout";
42  	private static final String SEARCH_PROPERTIES = "Search Properties";
43  	public static final String SOAPUI_ACTION_ID = "TestCaseOptionsAction";
44  	
45  	private XFormDialog dialog;
46  	private XForm form;
47  
48  	public TestCaseOptionsAction()
49     {
50  		super( "Options", "Sets options for this TestCase" );
51     }
52  
53  	public void perform( WsdlTestCase testCase, Object param )
54  	{
55  		if( dialog == null )
56  		{
57  			XFormDialogBuilder builder = XFormFactory.createDialogBuilder( "TestCase Options" );
58  		   form = builder.createForm( "Basic" );
59  			form.addCheckBox( SEARCH_PROPERTIES, "Search preceding teststeps for property values" );
60  			form.addCheckBox( KEEP_SESSION, "Maintain HTTP session" );
61  			form.addCheckBox( FAIL_ON_ERROR, "Fail on error" ).addFormFieldListener( new XFormFieldListener() {
62  
63  				public void valueChanged( XFormField sourceField, String newValue, String oldValue )
64  				{
65  					form.getFormField( FAIL_TESTCASE_ON_ERROR ).setEnabled( !Boolean.parseBoolean( newValue ) );
66  				}} );
67  			
68  			form.addCheckBox( FAIL_TESTCASE_ON_ERROR, "Fail TestCase if it has failed TestSteps" );
69  			form.addCheckBox( DISCARD_OK_RESULTS, "Discards successfull testresults to preserve memory" );
70  			form.addTextField( SOCKET_TIMEOUT, "Socket timeout in milliseconds", FieldType.TEXT );
71  			
72  			dialog = builder.buildDialog( builder.buildOkCancelHelpActions( HelpUrls.TESTCASEOPTIONS_HELP_URL ), 
73  					"Specify general options for this TestCase", UISupport.OPTIONS_ICON );
74  		}
75  		
76  		StringToStringMap values = new StringToStringMap();
77  		
78  		values.put( SEARCH_PROPERTIES, String.valueOf( testCase.getSearchProperties() ));
79  		values.put( KEEP_SESSION, String.valueOf( testCase.getKeepSession() ));
80  		values.put( FAIL_ON_ERROR, String.valueOf( testCase.getFailOnError() ));
81  		values.put( FAIL_TESTCASE_ON_ERROR, String.valueOf( testCase.getFailTestCaseOnErrors() ));
82  		values.put( DISCARD_OK_RESULTS, String.valueOf( testCase.getDiscardOkResults() ));
83  		values.put( SOCKET_TIMEOUT, String.valueOf( testCase.getSettings().getString( HttpSettings.SOCKET_TIMEOUT, "" )));
84  		
85  		dialog.getFormField( FAIL_TESTCASE_ON_ERROR ).
86  			setEnabled( !Boolean.parseBoolean( String.valueOf( testCase.getFailOnError() ) ) );
87  		
88  		values = dialog.show( values );
89  		
90  		if( dialog.getReturnValue() == XFormDialog.OK_OPTION )
91  		{
92  			try
93  			{
94  				testCase.setSearchProperties( Boolean.parseBoolean( values.get( SEARCH_PROPERTIES )));
95  				testCase.setKeepSession( Boolean.parseBoolean( values.get( KEEP_SESSION )));
96  				testCase.setDiscardOkResults( Boolean.parseBoolean( values.get( DISCARD_OK_RESULTS )));
97  				testCase.setFailOnError( Boolean.parseBoolean( values.get( FAIL_ON_ERROR )));
98  				testCase.setFailTestCaseOnErrors( Boolean.parseBoolean( values.get( FAIL_TESTCASE_ON_ERROR )));
99  				String timeout = values.get( SOCKET_TIMEOUT );
100 				if( timeout.trim().length() == 0 )
101 					testCase.getSettings().clearSetting( HttpSettings.SOCKET_TIMEOUT );
102 				else
103 					testCase.getSettings().setString( HttpSettings.SOCKET_TIMEOUT, timeout);
104 			}
105 			catch( Exception e1 )
106 			{
107 				UISupport.showErrorMessage( e1.getMessage() );
108 			}
109 		}
110 	}
111 }