1
2
3
4
5
6
7
8
9
10
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 private static final String AMF_LOGIN = "login";
52 private static final String AMF_PASSWORD = "password";
53 private static final String AMF_AUTHORISATION_ENABLE = "AMF Session";
54 private static final String AMF_ENDPOINT = "endpoint";
55
56 private XFormDialog dialog;
57 private XForm form;
58 private XForm amfForm;
59 private XForm wsrmForm;
60
61 public TestCaseOptionsAction()
62 {
63 super( "Options", "Sets options for this TestCase" );
64 }
65
66 public void perform( WsdlTestCase testCase, Object param )
67 {
68 if( dialog == null )
69 {
70 XFormDialogBuilder builder = XFormFactory.createDialogBuilder( "TestCase Options" );
71 form = builder.createForm( "Basic" );
72 form.addCheckBox( SEARCH_PROPERTIES, "Search preceding TestSteps for property values" );
73 form.addCheckBox( KEEP_SESSION, "Maintain HTTP session" );
74 form.addCheckBox( FAIL_ON_ERROR, "Fail on error" ).addFormFieldListener( new XFormFieldListener()
75 {
76
77 public void valueChanged( XFormField sourceField, String newValue, String oldValue )
78 {
79 form.getFormField( FAIL_TESTCASE_ON_ERROR ).setEnabled( !Boolean.parseBoolean( newValue ) );
80 }
81 } );
82
83 form.addCheckBox( FAIL_TESTCASE_ON_ERROR, "Fail TestCase if it has failed TestSteps" );
84 form.addCheckBox( DISCARD_OK_RESULTS, "Discards successful TestStep results to preserve memory" );
85 form.addTextField( SOCKET_TIMEOUT, "Socket timeout in milliseconds", FieldType.TEXT );
86 form.addTextField( TESTCASE_TIMEOUT, "Timeout in milliseconds for entire TestCase", FieldType.TEXT );
87 form.addTextField( MAXRESULTS, "Maximum number of TestStep results to keep in memory during a run",
88 FieldType.TEXT );
89
90 wsrmForm = builder.createForm( "WS-RM" );
91 wsrmForm.addCheckBox( WS_RM_ENABLED, "Use WS-Reliable Messaging" );
92 wsrmForm.addComboBox( WS_RM_VERSION, new String[] { WsrmVersionTypeConfig.X_1_0.toString(),
93 WsrmVersionTypeConfig.X_1_1.toString(), WsrmVersionTypeConfig.X_1_2.toString() },
94 "The property for managing WS-RM version" );
95 wsrmForm.addTextField( WS_RM_ACK_TO, "Acknowledgments To", FieldType.TEXT );
96 wsrmForm.addTextField( WS_RM_EXPIRES, "Expires after", FieldType.TEXT );
97
98 amfForm = builder.createForm( "AMF" );
99 amfForm.addCheckBox( AMF_AUTHORISATION_ENABLE, "Enable AMF Session" ).addFormFieldListener(
100 new AMFXFormFieldListener() );
101 amfForm.addTextField( AMF_ENDPOINT, "AMF Authorization endpoint", FieldType.TEXT );
102 amfForm.addTextField( AMF_LOGIN, "AMF Authorization usernmae", FieldType.TEXT );
103 amfForm.addTextField( AMF_PASSWORD, "AMF Authorization password", FieldType.TEXT );
104
105 dialog = builder.buildDialog( builder.buildOkCancelHelpActions( HelpUrls.TESTCASEOPTIONS_HELP_URL ),
106 "Specify general options for this TestCase", UISupport.OPTIONS_ICON );
107 }
108
109 StringToStringMap values = new StringToStringMap();
110
111 values.put( SEARCH_PROPERTIES, String.valueOf( testCase.getSearchProperties() ) );
112 values.put( KEEP_SESSION, String.valueOf( testCase.getKeepSession() ) );
113 values.put( FAIL_ON_ERROR, String.valueOf( testCase.getFailOnError() ) );
114 values.put( FAIL_TESTCASE_ON_ERROR, String.valueOf( testCase.getFailTestCaseOnErrors() ) );
115 values.put( DISCARD_OK_RESULTS, String.valueOf( testCase.getDiscardOkResults() ) );
116 values
117 .put( SOCKET_TIMEOUT, String.valueOf( testCase.getSettings().getString( HttpSettings.SOCKET_TIMEOUT, "" ) ) );
118 values.put( TESTCASE_TIMEOUT, String.valueOf( testCase.getTimeout() ) );
119 values.put( MAXRESULTS, String.valueOf( testCase.getMaxResults() ) );
120
121 values.put( WS_RM_ENABLED, String.valueOf( testCase.getWsrmEnabled() ) );
122 values.put( WS_RM_VERSION, String.valueOf( testCase.getWsrmVersion() ) );
123 if( testCase.getWsrmAckTo() != null )
124 values.put( WS_RM_ACK_TO, String.valueOf( testCase.getWsrmAckTo() ) );
125 if( testCase.getWsrmExpires() != 0 )
126 values.put( WS_RM_EXPIRES, String.valueOf( testCase.getWsrmExpires() ) );
127
128 values.put( AMF_AUTHORISATION_ENABLE, String.valueOf( testCase.getAmfAuthorisation() ) );
129 values.put( AMF_ENDPOINT, String.valueOf( testCase.getAmfEndpoint() ) );
130 values.put( AMF_LOGIN, String.valueOf( testCase.getAmfLogin() ) );
131 values.put( AMF_PASSWORD, String.valueOf( testCase.getAmfPassword() ) );
132
133 dialog.getFormField( FAIL_TESTCASE_ON_ERROR ).setEnabled(
134 !Boolean.parseBoolean( String.valueOf( testCase.getFailOnError() ) ) );
135
136 values = dialog.show( values );
137
138 if( dialog.getReturnValue() == XFormDialog.OK_OPTION )
139 {
140 try
141 {
142 testCase.setSearchProperties( Boolean.parseBoolean( values.get( SEARCH_PROPERTIES ) ) );
143 testCase.setKeepSession( Boolean.parseBoolean( values.get( KEEP_SESSION ) ) );
144 testCase.setDiscardOkResults( Boolean.parseBoolean( values.get( DISCARD_OK_RESULTS ) ) );
145 testCase.setFailOnError( Boolean.parseBoolean( values.get( FAIL_ON_ERROR ) ) );
146 testCase.setFailTestCaseOnErrors( Boolean.parseBoolean( values.get( FAIL_TESTCASE_ON_ERROR ) ) );
147 testCase.setTimeout( Long.parseLong( values.get( TESTCASE_TIMEOUT ) ) );
148 testCase.setMaxResults( Integer.parseInt( values.get( MAXRESULTS ) ) );
149 testCase.setWsrmEnabled( Boolean.parseBoolean( values.get( WS_RM_ENABLED ) ) );
150 testCase.setWsrmVersion( values.get( WS_RM_VERSION ) );
151 testCase.setWsrmAckTo( values.get( WS_RM_ACK_TO ) );
152 if( values.get( WS_RM_EXPIRES ) != null && values.get( WS_RM_EXPIRES ).length() > 0 )
153 testCase.setWsrmExpires( Long.parseLong( values.get( WS_RM_EXPIRES ) ) );
154
155 String timeout = values.get( SOCKET_TIMEOUT );
156 if( timeout.trim().length() == 0 )
157 testCase.getSettings().clearSetting( HttpSettings.SOCKET_TIMEOUT );
158 else
159 testCase.getSettings().setString( HttpSettings.SOCKET_TIMEOUT, timeout );
160
161 testCase.setAmfAuthorisation( Boolean.parseBoolean( values.get( AMF_AUTHORISATION_ENABLE ) ) );
162 testCase.setAmfEndpoint( values.get( AMF_ENDPOINT ) );
163 testCase.setAmfLogin( values.get( AMF_LOGIN ) );
164 testCase.setAmfPassword( values.get( AMF_PASSWORD ) );
165 }
166 catch( Exception e1 )
167 {
168 UISupport.showErrorMessage( e1.getMessage() );
169 }
170 }
171 }
172
173 private class AMFXFormFieldListener implements XFormFieldListener
174 {
175
176 public void valueChanged( XFormField sourceField, String newValue, String oldValue )
177 {
178 amfForm.getFormField( AMF_ENDPOINT ).setEnabled( Boolean.parseBoolean( newValue ) );
179 amfForm.getFormField( AMF_LOGIN ).setEnabled( Boolean.parseBoolean( newValue ) );
180 amfForm.getFormField( AMF_PASSWORD ).setEnabled( Boolean.parseBoolean( newValue ) );
181 }
182
183 }
184 }