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