View Javadoc

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