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