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  	private static final String TESTCASE_TIMEOUT = "TestCase timeout";
45  	
46  	private XFormDialog dialog;
47  	private XForm form;
48  
49  	public TestCaseOptionsAction()
50     {
51  		super( "Options", "Sets options for this TestCase" );
52     }
53  
54  	public void perform( WsdlTestCase testCase, Object param )
55  	{
56  		if( dialog == null )
57  		{
58  			XFormDialogBuilder builder = XFormFactory.createDialogBuilder( "TestCase Options" );
59  		   form = builder.createForm( "Basic" );
60  			form.addCheckBox( SEARCH_PROPERTIES, "Search preceding teststeps for property values" );
61  			form.addCheckBox( KEEP_SESSION, "Maintain HTTP session" );
62  			form.addCheckBox( FAIL_ON_ERROR, "Fail on error" ).addFormFieldListener( new XFormFieldListener() {
63  
64  				public void valueChanged( XFormField sourceField, String newValue, String oldValue )
65  				{
66  					form.getFormField( FAIL_TESTCASE_ON_ERROR ).setEnabled( !Boolean.parseBoolean( newValue ) );
67  				}} );
68  			
69  			form.addCheckBox( FAIL_TESTCASE_ON_ERROR, "Fail TestCase if it has failed TestSteps" );
70  			form.addCheckBox( DISCARD_OK_RESULTS, "Discards successfull testresults to preserve memory" );
71  			form.addTextField( SOCKET_TIMEOUT, "Socket timeout in milliseconds", FieldType.TEXT );
72  			form.addTextField( TESTCASE_TIMEOUT, "Timeout in milliseconds for entire TestCase", FieldType.TEXT );
73  
74  			dialog = builder.buildDialog( builder.buildOkCancelHelpActions( HelpUrls.TESTCASEOPTIONS_HELP_URL ), 
75  					"Specify general options for this TestCase", UISupport.OPTIONS_ICON );
76  		}
77  		
78  		StringToStringMap values = new StringToStringMap();
79  		
80  		values.put( SEARCH_PROPERTIES, String.valueOf( testCase.getSearchProperties() ));
81  		values.put( KEEP_SESSION, String.valueOf( testCase.getKeepSession() ));
82  		values.put( FAIL_ON_ERROR, String.valueOf( testCase.getFailOnError() ));
83  		values.put( FAIL_TESTCASE_ON_ERROR, String.valueOf( testCase.getFailTestCaseOnErrors() ));
84  		values.put( DISCARD_OK_RESULTS, String.valueOf( testCase.getDiscardOkResults() ));
85  		values.put( SOCKET_TIMEOUT, String.valueOf( testCase.getSettings().getString( HttpSettings.SOCKET_TIMEOUT, "" )));
86  		values.put( TESTCASE_TIMEOUT, String.valueOf( testCase.getTimeout() ));
87  		
88  		dialog.getFormField( FAIL_TESTCASE_ON_ERROR ).
89  			setEnabled( !Boolean.parseBoolean( String.valueOf( testCase.getFailOnError() ) ) );
90  		
91  		values = dialog.show( values );
92  		
93  		if( dialog.getReturnValue() == XFormDialog.OK_OPTION )
94  		{
95  			try
96  			{
97  				testCase.setSearchProperties( Boolean.parseBoolean( values.get( SEARCH_PROPERTIES )));
98  				testCase.setKeepSession( Boolean.parseBoolean( values.get( KEEP_SESSION )));
99  				testCase.setDiscardOkResults( Boolean.parseBoolean( values.get( DISCARD_OK_RESULTS )));
100 				testCase.setFailOnError( Boolean.parseBoolean( values.get( FAIL_ON_ERROR )));
101 				testCase.setFailTestCaseOnErrors( Boolean.parseBoolean( values.get( FAIL_TESTCASE_ON_ERROR )));
102 				testCase.setTimeout( Long.parseLong( values.get( TESTCASE_TIMEOUT ) ) );
103 				
104 				String timeout = values.get( SOCKET_TIMEOUT );
105 				if( timeout.trim().length() == 0 )
106 					testCase.getSettings().clearSetting( HttpSettings.SOCKET_TIMEOUT );
107 				else
108 					testCase.getSettings().setString( HttpSettings.SOCKET_TIMEOUT, timeout);
109 			}
110 			catch( Exception e1 )
111 			{
112 				UISupport.showErrorMessage( e1.getMessage() );
113 			}
114 		}
115 	}
116 }