001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.actions.testcase;
014:
015: import com.eviware.soapui.impl.wsdl.support.HelpUrls;
016: import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
017: import com.eviware.soapui.settings.HttpSettings;
018: import com.eviware.soapui.support.UISupport;
019: import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
020: import com.eviware.soapui.support.types.StringToStringMap;
021: import com.eviware.x.form.XForm;
022: import com.eviware.x.form.XFormDialog;
023: import com.eviware.x.form.XFormDialogBuilder;
024: import com.eviware.x.form.XFormFactory;
025: import com.eviware.x.form.XFormField;
026: import com.eviware.x.form.XFormFieldListener;
027: import com.eviware.x.form.XForm.FieldType;
028:
029: /**
030: * Options dialog for testcases
031: *
032: * @author Ole.Matzura
033: */
034:
035: public class TestCaseOptionsAction extends
036: AbstractSoapUIAction<WsdlTestCase> {
037: private static final String KEEP_SESSION = "Session";
038: private static final String FAIL_ON_ERROR = "Abort on Error";
039: private static final String FAIL_TESTCASE_ON_ERROR = "Fail TestCase on Error";
040: private static final String DISCARD_OK_RESULTS = "Discard OK Results";
041: private static final String SOCKET_TIMEOUT = "Socket timeout";
042: private static final String SEARCH_PROPERTIES = "Search Properties";
043: public static final String SOAPUI_ACTION_ID = "TestCaseOptionsAction";
044:
045: private XFormDialog dialog;
046: private XForm form;
047:
048: public TestCaseOptionsAction() {
049: super ("Options", "Sets options for this TestCase");
050: }
051:
052: public void perform(WsdlTestCase testCase, Object param) {
053: if (dialog == null) {
054: XFormDialogBuilder builder = XFormFactory
055: .createDialogBuilder("TestCase Options");
056: form = builder.createForm("Basic");
057: form.addCheckBox(SEARCH_PROPERTIES,
058: "Search preceding teststeps for property values");
059: form.addCheckBox(KEEP_SESSION, "Maintain HTTP session");
060: form.addCheckBox(FAIL_ON_ERROR, "Fail on error")
061: .addFormFieldListener(new XFormFieldListener() {
062:
063: public void valueChanged(
064: XFormField sourceField,
065: String newValue, String oldValue) {
066: form
067: .getFormField(
068: FAIL_TESTCASE_ON_ERROR)
069: .setEnabled(
070: !Boolean
071: .parseBoolean(newValue));
072: }
073: });
074:
075: form.addCheckBox(FAIL_TESTCASE_ON_ERROR,
076: "Fail TestCase if it has failed TestSteps");
077: form
078: .addCheckBox(DISCARD_OK_RESULTS,
079: "Discards successfull testresults to preserve memory");
080: form.addTextField(SOCKET_TIMEOUT,
081: "Socket timeout in milliseconds", FieldType.TEXT);
082:
083: dialog = builder
084: .buildDialog(
085: builder
086: .buildOkCancelHelpActions(HelpUrls.TESTCASEOPTIONS_HELP_URL),
087: "Specify general options for this TestCase",
088: UISupport.OPTIONS_ICON);
089: }
090:
091: StringToStringMap values = new StringToStringMap();
092:
093: values.put(SEARCH_PROPERTIES, String.valueOf(testCase
094: .getSearchProperties()));
095: values.put(KEEP_SESSION, String.valueOf(testCase
096: .getKeepSession()));
097: values.put(FAIL_ON_ERROR, String.valueOf(testCase
098: .getFailOnError()));
099: values.put(FAIL_TESTCASE_ON_ERROR, String.valueOf(testCase
100: .getFailTestCaseOnErrors()));
101: values.put(DISCARD_OK_RESULTS, String.valueOf(testCase
102: .getDiscardOkResults()));
103: values.put(SOCKET_TIMEOUT, String.valueOf(testCase
104: .getSettings().getString(HttpSettings.SOCKET_TIMEOUT,
105: "")));
106:
107: dialog.getFormField(FAIL_TESTCASE_ON_ERROR).setEnabled(
108: !Boolean.parseBoolean(String.valueOf(testCase
109: .getFailOnError())));
110:
111: values = dialog.show(values);
112:
113: if (dialog.getReturnValue() == XFormDialog.OK_OPTION) {
114: try {
115: testCase.setSearchProperties(Boolean
116: .parseBoolean(values.get(SEARCH_PROPERTIES)));
117: testCase.setKeepSession(Boolean.parseBoolean(values
118: .get(KEEP_SESSION)));
119: testCase.setDiscardOkResults(Boolean
120: .parseBoolean(values.get(DISCARD_OK_RESULTS)));
121: testCase.setFailOnError(Boolean.parseBoolean(values
122: .get(FAIL_ON_ERROR)));
123: testCase.setFailTestCaseOnErrors(Boolean
124: .parseBoolean(values
125: .get(FAIL_TESTCASE_ON_ERROR)));
126: String timeout = values.get(SOCKET_TIMEOUT);
127: if (timeout.trim().length() == 0)
128: testCase.getSettings().clearSetting(
129: HttpSettings.SOCKET_TIMEOUT);
130: else
131: testCase.getSettings().setString(
132: HttpSettings.SOCKET_TIMEOUT, timeout);
133: } catch (Exception e1) {
134: UISupport.showErrorMessage(e1.getMessage());
135: }
136: }
137: }
138: }
|