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.teststeps.actions;
014:
015: import com.eviware.soapui.impl.wsdl.WsdlOperation;
016: import com.eviware.soapui.impl.wsdl.WsdlProject;
017: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
018: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
019: import com.eviware.soapui.model.support.ModelSupport;
020: import com.eviware.soapui.support.UISupport;
021: import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
022: import com.eviware.soapui.support.xml.XmlUtils;
023: import com.eviware.x.form.XFormDialog;
024: import com.eviware.x.form.XFormField;
025: import com.eviware.x.form.XFormFieldListener;
026: import com.eviware.x.form.support.ADialogBuilder;
027: import com.eviware.x.form.support.AField;
028: import com.eviware.x.form.support.AForm;
029: import com.eviware.x.form.support.AField.AFieldType;
030:
031: /**
032: * Prompts to change the WsdlOperation of a WsdlTestRequestStep
033: *
034: * @author Ole.Matzura
035: */
036:
037: public class ChangeOperationAction extends
038: AbstractSoapUIAction<WsdlTestRequestStep> {
039: private XFormDialog dialog;
040: private WsdlTestRequestStep testStep;
041:
042: public ChangeOperationAction() {
043: super ("Change Operation",
044: "Changes the Interface Operation for this Test Request");
045: }
046:
047: public void perform(WsdlTestRequestStep target, Object param) {
048: this .testStep = target;
049:
050: if (dialog == null) {
051: dialog = ADialogBuilder.buildDialog(Form.class);
052: dialog.getFormField(Form.INTERFACE).addFormFieldListener(
053: new XFormFieldListener() {
054:
055: public void valueChanged(
056: XFormField sourceField,
057: String newValue, String oldValue) {
058: WsdlProject project = testStep
059: .getTestCase().getTestSuite()
060: .getProject();
061: dialog.setOptions(Form.OPERATION,
062: ModelSupport.getNames(project
063: .getInterfaceByName(
064: newValue)
065: .getOperations()));
066: dialog.setValue(Form.OPERATION, testStep
067: .getOperationName());
068: }
069: });
070:
071: dialog.getFormField(Form.RECREATE_REQUEST)
072: .addFormFieldListener(new XFormFieldListener() {
073:
074: public void valueChanged(
075: XFormField sourceField,
076: String newValue, String oldValue) {
077: boolean enabled = Boolean
078: .parseBoolean(newValue);
079:
080: dialog.getFormField(Form.CREATE_OPTIONAL)
081: .setEnabled(enabled);
082: dialog.getFormField(Form.KEEP_EXISTING)
083: .setEnabled(enabled);
084: }
085: });
086:
087: dialog.getFormField(Form.CREATE_OPTIONAL).setEnabled(false);
088: dialog.getFormField(Form.KEEP_EXISTING).setEnabled(false);
089: }
090:
091: WsdlProject project = target.getTestCase().getTestSuite()
092: .getProject();
093: dialog.setOptions(Form.INTERFACE, ModelSupport.getNames(project
094: .getInterfaces()));
095: dialog.setValue(Form.INTERFACE, target.getInterfaceName());
096:
097: dialog.setOptions(Form.OPERATION, ModelSupport.getNames(project
098: .getInterfaceByName(target.getInterfaceName())
099: .getOperations()));
100: dialog.setValue(Form.OPERATION, target.getOperationName());
101: dialog.setValue(Form.NAME, target.getName());
102:
103: if (dialog.show()) {
104: String ifaceName = dialog.getValue(Form.INTERFACE);
105: String operationName = dialog.getValue(Form.OPERATION);
106:
107: WsdlOperation operation = project.getInterfaceByName(
108: ifaceName).getOperationByName(operationName);
109: target.setOperation(operation);
110:
111: String name = dialog.getValue(Form.NAME).trim();
112: if (name.length() > 0 && !target.getName().equals(name))
113: target.setName(name);
114:
115: if (dialog.getBooleanValue(Form.RECREATE_REQUEST)) {
116: String req = operation.createRequest(dialog
117: .getBooleanValue(Form.CREATE_OPTIONAL));
118: if (req == null) {
119: UISupport
120: .showErrorMessage("Request creation failed");
121: return;
122: }
123:
124: WsdlTestRequest request = target.getTestRequest();
125: if (dialog.getBooleanValue(Form.KEEP_EXISTING)) {
126: req = XmlUtils.transferValues(request
127: .getRequestContent(), req);
128: }
129:
130: request.setRequestContent(req);
131: }
132: }
133: }
134:
135: @AForm(description="Specify Interface/Operation for TestRequest",name="Change Operation")
136: protected interface Form {
137: @AField(name="Name",description="The Name of the TestRequests",type=AFieldType.STRING)
138: public final static String NAME = "Name";
139:
140: @AField(name="Interface",description="The TestRequests' Interface",type=AFieldType.ENUMERATION)
141: public final static String INTERFACE = "Interface";
142:
143: @AField(name="Operation",description="The TestRequests' Operation",type=AFieldType.ENUMERATION)
144: public final static String OPERATION = "Operation";
145:
146: @AField(name="Recreate Request",description="Recreates the request content from the new Operations Definition",type=AFieldType.BOOLEAN)
147: public final static String RECREATE_REQUEST = "Recreate Request";
148:
149: @AField(name="Create Optional",description="Creates optional content when recreating the request",type=AFieldType.BOOLEAN)
150: public final static String CREATE_OPTIONAL = "Create Optional";
151:
152: @AField(name="Keep Existing",description="Tries to keep existing values when recreating the request",type=AFieldType.BOOLEAN)
153: public final static String KEEP_EXISTING = "Keep Existing";
154: }
155: }
|