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.request;
014:
015: import com.eviware.soapui.SoapUI;
016: import com.eviware.soapui.impl.wsdl.WsdlProject;
017: import com.eviware.soapui.impl.wsdl.WsdlRequest;
018: import com.eviware.soapui.impl.wsdl.actions.support.AbstractAddToTestCaseAction;
019: import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
020: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
021: import com.eviware.soapui.impl.wsdl.teststeps.assertions.NotSoapFaultAssertion;
022: import com.eviware.soapui.impl.wsdl.teststeps.assertions.SchemaComplianceAssertion;
023: import com.eviware.soapui.impl.wsdl.teststeps.assertions.SoapResponseAssertion;
024: import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory;
025: import com.eviware.soapui.support.UISupport;
026: import com.eviware.soapui.support.types.StringToStringMap;
027: import com.eviware.soapui.ui.desktop.SoapUIDesktop;
028: import com.eviware.x.form.XForm;
029: import com.eviware.x.form.XFormDialog;
030: import com.eviware.x.form.XFormDialogBuilder;
031: import com.eviware.x.form.XFormFactory;
032: import com.eviware.x.form.XFormField;
033:
034: /**
035: * Adds a WsdlRequest to a WsdlTestCase as a WsdlTestRequestStep
036: *
037: * @author Ole.Matzura
038: */
039:
040: public class AddRequestToTestCaseAction extends
041: AbstractAddToTestCaseAction<WsdlRequest> {
042: public static final String SOAPUI_ACTION_ID = "AddRequestToTestCaseAction";
043:
044: private static final String STEP_NAME = "Name";
045: private static final String ADD_SOAP_FAULT_ASSERTION = "Add Not SOAP Fault Assertion";
046: private static final String ADD_SOAP_RESPONSE_ASSERTION = "Add SOAP Response Assertion";
047: private static final String ADD_SCHEMA_ASSERTION = "Add Schema Assertion";
048: private static final String CLOSE_REQUEST = "Close Request Window";
049: private static final String SHOW_TESTCASE = "Shows TestCase Editor";
050: private static final String COPY_ATTACHMENTS = "Copy Attachments";
051: private static final String COPY_HTTPHEADERS = "Copy HTTP Headers";
052:
053: private XFormDialog dialog;
054: private StringToStringMap dialogValues = new StringToStringMap();
055: private XFormField closeRequestCheckBox;
056:
057: public AddRequestToTestCaseAction() {
058: super ("Add to TestCase", "Adds this request to a TestCase");
059: }
060:
061: public void perform(WsdlRequest request, Object param) {
062: WsdlProject project = request.getOperation().getInterface()
063: .getProject();
064:
065: WsdlTestCase testCase = getTargetTestCase(project);
066: if (testCase != null)
067: addRequest(testCase, request, -1);
068: }
069:
070: public WsdlTestRequestStep addRequest(WsdlTestCase testCase,
071: WsdlRequest request, int position) {
072: if (dialog == null)
073: buildDialog();
074:
075: dialogValues.put(STEP_NAME, request.getOperation().getName()
076: + " - " + request.getName());
077: dialogValues.put(CLOSE_REQUEST, "true");
078: dialogValues.put(SHOW_TESTCASE, "true");
079: dialog.getFormField(COPY_ATTACHMENTS).setEnabled(
080: request.getAttachmentCount() > 0);
081: dialog.setBooleanValue(COPY_ATTACHMENTS, true);
082:
083: dialog.getFormField(COPY_HTTPHEADERS).setEnabled(
084: request.getRequestHeaders().size() > 0);
085: dialog.setBooleanValue(COPY_HTTPHEADERS, true);
086:
087: SoapUIDesktop desktop = SoapUI.getDesktop();
088: closeRequestCheckBox.setEnabled(desktop != null
089: && desktop.hasDesktopPanel(request));
090:
091: dialogValues = dialog.show(dialogValues);
092: if (dialog.getReturnValue() != XFormDialog.OK_OPTION)
093: return null;
094: ;
095:
096: String name = dialogValues.get(STEP_NAME);
097:
098: WsdlTestRequestStep test = (WsdlTestRequestStep) testCase
099: .insertTestStep(WsdlTestRequestStepFactory
100: .createConfig(request, name), position);
101:
102: if (dialogValues.getBoolean(COPY_ATTACHMENTS))
103: request.copyAttachmentsTo(test.getTestRequest());
104:
105: if (dialogValues.getBoolean(COPY_HTTPHEADERS))
106: test.getTestRequest().setRequestHeaders(
107: request.getRequestHeaders());
108:
109: if (dialogValues.getBoolean(ADD_SOAP_RESPONSE_ASSERTION))
110: test.getTestRequest()
111: .addAssertion(SoapResponseAssertion.ID);
112:
113: if (dialogValues.getBoolean(ADD_SCHEMA_ASSERTION))
114: test.getTestRequest().addAssertion(
115: SchemaComplianceAssertion.ID);
116:
117: if (dialogValues.getBoolean(ADD_SOAP_FAULT_ASSERTION))
118: test.getTestRequest().addAssertion(
119: NotSoapFaultAssertion.LABEL);
120:
121: UISupport.selectAndShow(test);
122:
123: if (dialogValues.getBoolean(CLOSE_REQUEST) && desktop != null) {
124: desktop.closeDesktopPanel(request);
125: }
126:
127: if (dialogValues.getBoolean(SHOW_TESTCASE)) {
128: UISupport.selectAndShow(testCase);
129: }
130:
131: return test;
132: }
133:
134: private void buildDialog() {
135: XFormDialogBuilder builder = XFormFactory
136: .createDialogBuilder("Add Request to TestCase");
137: XForm mainForm = builder.createForm("Basic");
138:
139: mainForm.addTextField(STEP_NAME, "Name of TestStep",
140: XForm.FieldType.URL).setWidth(30);
141:
142: mainForm.addCheckBox(ADD_SOAP_RESPONSE_ASSERTION,
143: "(adds validation that response is a SOAP message)");
144: mainForm
145: .addCheckBox(ADD_SCHEMA_ASSERTION,
146: "(adds validation that response complies with its schema)");
147: mainForm.addCheckBox(ADD_SOAP_FAULT_ASSERTION,
148: "(adds validation that response is not a SOAP Fault)");
149: closeRequestCheckBox = mainForm.addCheckBox(CLOSE_REQUEST,
150: "(closes the current window for this request)");
151: mainForm.addCheckBox(SHOW_TESTCASE,
152: "(opens the TestCase editor for the target TestCase)");
153: mainForm.addCheckBox(COPY_ATTACHMENTS,
154: "(copies the requests attachments to the TestRequest)");
155: mainForm
156: .addCheckBox(COPY_HTTPHEADERS,
157: "(copies the requests HTTP-Headers to the TestRequest)");
158:
159: dialog = builder.buildDialog(builder.buildOkCancelActions(),
160: "Specify options for adding the request to a TestCase",
161: UISupport.OPTIONS_ICON);
162:
163: dialogValues.put(ADD_SOAP_RESPONSE_ASSERTION, Boolean.TRUE
164: .toString());
165: }
166: }
|