View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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.config.WsrmVersionTypeConfig;
16  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
17  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
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.soapui.support.types.StringToStringMap;
22  import com.eviware.x.form.XForm;
23  import com.eviware.x.form.XFormDialog;
24  import com.eviware.x.form.XFormDialogBuilder;
25  import com.eviware.x.form.XFormFactory;
26  import com.eviware.x.form.XFormField;
27  import com.eviware.x.form.XFormFieldListener;
28  import com.eviware.x.form.XForm.FieldType;
29  
30  /***
31   * Options dialog for testcases
32   * 
33   * @author Ole.Matzura
34   */
35  
36  public class TestCaseOptionsAction extends AbstractSoapUIAction<WsdlTestCase>
37  {
38  	private static final String KEEP_SESSION = "Session";
39  	private static final String FAIL_ON_ERROR = "Abort on Error";
40  	private static final String FAIL_TESTCASE_ON_ERROR = "Fail TestCase on Error";
41  	private static final String DISCARD_OK_RESULTS = "Discard OK Results";
42  	private static final String SOCKET_TIMEOUT = "Socket timeout";
43  	private static final String SEARCH_PROPERTIES = "Search Properties";
44  	public static final String SOAPUI_ACTION_ID = "TestCaseOptionsAction";
45  	private static final String TESTCASE_TIMEOUT = "TestCase timeout";
46  	private static final String MAXRESULTS = "Max Results";
47  	private static final String WS_RM_ENABLED = "WS-RM Enabled";
48  	private static final String WS_RM_VERSION = "WS-RM Version";
49  	private static final String WS_RM_ACK_TO = "WS-RM Ack To";
50  	private static final String WS_RM_EXPIRES = "WS-RM Expires";
51  
52  	private XFormDialog dialog;
53  	private XForm form;
54  
55  	public TestCaseOptionsAction()
56  	{
57  		super( "Options", "Sets options for this TestCase" );
58  	}
59  
60  	public void perform( WsdlTestCase testCase, Object param )
61  	{
62  		if( dialog == null )
63  		{
64  			XFormDialogBuilder builder = XFormFactory.createDialogBuilder( "TestCase Options" );
65  			form = builder.createForm( "Basic" );
66  			form.addCheckBox( SEARCH_PROPERTIES, "Search preceding TestSteps for property values" );
67  			form.addCheckBox( KEEP_SESSION, "Maintain HTTP session" );
68  			form.addCheckBox( FAIL_ON_ERROR, "Fail on error" ).addFormFieldListener( new XFormFieldListener()
69  			{
70  
71  				public void valueChanged( XFormField sourceField, String newValue, String oldValue )
72  				{
73  					form.getFormField( FAIL_TESTCASE_ON_ERROR ).setEnabled( !Boolean.parseBoolean( newValue ) );
74  				}
75  			} );
76  
77  			form.addCheckBox( FAIL_TESTCASE_ON_ERROR, "Fail TestCase if it has failed TestSteps" );
78  			form.addCheckBox( DISCARD_OK_RESULTS, "Discards successful TestStep results to preserve memory" );
79  			form.addTextField( SOCKET_TIMEOUT, "Socket timeout in milliseconds", FieldType.TEXT );
80  			form.addTextField( TESTCASE_TIMEOUT, "Timeout in milliseconds for entire TestCase", FieldType.TEXT );
81  			form.addTextField( MAXRESULTS, "Maximum number of TestStep results to keep in memory during a run",
82  					FieldType.TEXT );
83  
84  			form.addCheckBox( WS_RM_ENABLED, "Use WS-Reliable Messaging" );
85  			form.addComboBox( WS_RM_VERSION, new String[] { WsrmVersionTypeConfig.X_1_0.toString(),
86  					WsrmVersionTypeConfig.X_1_1.toString(), WsrmVersionTypeConfig.X_1_2.toString() },
87  					"The  property for managing WS-RM version" );
88  			form.addTextField( WS_RM_ACK_TO, "Acknowledgments To", FieldType.TEXT );
89  			form.addTextField( WS_RM_EXPIRES, "Expires after", FieldType.TEXT );
90  
91  			dialog = builder.buildDialog( builder.buildOkCancelHelpActions( HelpUrls.TESTCASEOPTIONS_HELP_URL ),
92  					"Specify general options for this TestCase", UISupport.OPTIONS_ICON );
93  		}
94  
95  		StringToStringMap values = new StringToStringMap();
96  
97  		values.put( SEARCH_PROPERTIES, String.valueOf( testCase.getSearchProperties() ) );
98  		values.put( KEEP_SESSION, String.valueOf( testCase.getKeepSession() ) );
99  		values.put( FAIL_ON_ERROR, String.valueOf( testCase.getFailOnError() ) );
100 		values.put( FAIL_TESTCASE_ON_ERROR, String.valueOf( testCase.getFailTestCaseOnErrors() ) );
101 		values.put( DISCARD_OK_RESULTS, String.valueOf( testCase.getDiscardOkResults() ) );
102 		values
103 				.put( SOCKET_TIMEOUT, String.valueOf( testCase.getSettings().getString( HttpSettings.SOCKET_TIMEOUT, "" ) ) );
104 		values.put( TESTCASE_TIMEOUT, String.valueOf( testCase.getTimeout() ) );
105 		values.put( MAXRESULTS, String.valueOf( testCase.getMaxResults() ) );
106 
107 		values.put( WS_RM_ENABLED, String.valueOf( testCase.getWsrmEnabled() ) );
108 		values.put( WS_RM_VERSION, String.valueOf( testCase.getWsrmVersion() ) );
109 		if( testCase.getWsrmAckTo() != null )
110 			values.put( WS_RM_ACK_TO, String.valueOf( testCase.getWsrmAckTo() ) );
111 		if( testCase.getWsrmExpires() != 0 )
112 			values.put( WS_RM_EXPIRES, String.valueOf( testCase.getWsrmExpires() ) );
113 
114 		dialog.getFormField( FAIL_TESTCASE_ON_ERROR ).setEnabled(
115 				!Boolean.parseBoolean( String.valueOf( testCase.getFailOnError() ) ) );
116 
117 		values = dialog.show( values );
118 
119 		if( dialog.getReturnValue() == XFormDialog.OK_OPTION )
120 		{
121 			try
122 			{
123 				testCase.setSearchProperties( Boolean.parseBoolean( values.get( SEARCH_PROPERTIES ) ) );
124 				testCase.setKeepSession( Boolean.parseBoolean( values.get( KEEP_SESSION ) ) );
125 				testCase.setDiscardOkResults( Boolean.parseBoolean( values.get( DISCARD_OK_RESULTS ) ) );
126 				testCase.setFailOnError( Boolean.parseBoolean( values.get( FAIL_ON_ERROR ) ) );
127 				testCase.setFailTestCaseOnErrors( Boolean.parseBoolean( values.get( FAIL_TESTCASE_ON_ERROR ) ) );
128 				testCase.setTimeout( Long.parseLong( values.get( TESTCASE_TIMEOUT ) ) );
129 				testCase.setMaxResults( Integer.parseInt( values.get( MAXRESULTS ) ) );
130 				testCase.setWsrmEnabled( Boolean.parseBoolean( values.get( WS_RM_ENABLED ) ) );
131 				testCase.setWsrmVersion( values.get( WS_RM_VERSION ) );
132 				testCase.setWsrmAckTo( values.get( WS_RM_ACK_TO ) );
133 				if( values.get( WS_RM_EXPIRES ) != null && values.get( WS_RM_EXPIRES ).length() > 0 )
134 					testCase.setWsrmExpires( Long.parseLong( values.get( WS_RM_EXPIRES ) ) );
135 
136 				String timeout = values.get( SOCKET_TIMEOUT );
137 				if( timeout.trim().length() == 0 )
138 					testCase.getSettings().clearSetting( HttpSettings.SOCKET_TIMEOUT );
139 				else
140 					testCase.getSettings().setString( HttpSettings.SOCKET_TIMEOUT, timeout );
141 			}
142 			catch( Exception e1 )
143 			{
144 				UISupport.showErrorMessage( e1.getMessage() );
145 			}
146 		}
147 	}
148 }