1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.teststeps.actions;
14
15 import com.eviware.soapui.impl.wsdl.WsdlOperation;
16 import com.eviware.soapui.impl.wsdl.WsdlProject;
17 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
18 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
19 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
20 import com.eviware.soapui.model.support.ModelSupport;
21 import com.eviware.soapui.support.UISupport;
22 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
23 import com.eviware.soapui.support.xml.XmlUtils;
24 import com.eviware.x.form.XFormDialog;
25 import com.eviware.x.form.XFormField;
26 import com.eviware.x.form.XFormFieldListener;
27 import com.eviware.x.form.support.ADialogBuilder;
28 import com.eviware.x.form.support.AField;
29 import com.eviware.x.form.support.AForm;
30 import com.eviware.x.form.support.AField.AFieldType;
31
32 /***
33 * Prompts to change the WsdlOperation of a WsdlTestRequestStep
34 *
35 * @author Ole.Matzura
36 */
37
38 public class ChangeOperationAction extends AbstractSoapUIAction<WsdlTestRequestStep>
39 {
40 private XFormDialog dialog;
41 private WsdlTestRequestStep testStep;
42
43 public ChangeOperationAction()
44 {
45 super( "Change Operation", "Changes the Interface Operation for this Test Request" );
46 }
47
48 public void perform( WsdlTestRequestStep target, Object param )
49 {
50 this.testStep = target;
51
52 if( dialog == null )
53 {
54 dialog = ADialogBuilder.buildDialog( Form.class );
55 dialog.getFormField( Form.INTERFACE ).addFormFieldListener( new XFormFieldListener() {
56
57 public void valueChanged( XFormField sourceField, String newValue, String oldValue )
58 {
59 WsdlProject project = testStep.getTestCase().getTestSuite().getProject();
60 dialog.setOptions( Form.OPERATION,
61 ModelSupport.getNames( project.getInterfaceByName( newValue ).getOperationList() ));
62 dialog.setValue( Form.OPERATION, testStep.getOperationName() );
63 }} );
64
65 dialog.getFormField( Form.RECREATE_REQUEST ).addFormFieldListener( new XFormFieldListener() {
66
67 public void valueChanged( XFormField sourceField, String newValue, String oldValue )
68 {
69 boolean enabled = Boolean.parseBoolean( newValue );
70
71 dialog.getFormField( Form.CREATE_OPTIONAL ).setEnabled( enabled );
72 dialog.getFormField( Form.KEEP_EXISTING ).setEnabled( enabled );
73 }} );
74
75 dialog.getFormField( Form.CREATE_OPTIONAL ).setEnabled( false );
76 dialog.getFormField( Form.KEEP_EXISTING ).setEnabled( false );
77 }
78
79 WsdlProject project = target.getTestCase().getTestSuite().getProject();
80 dialog.setOptions( Form.INTERFACE, ModelSupport.getNames( project.getInterfaceList() ));
81 dialog.setValue( Form.INTERFACE, target.getInterfaceName() );
82
83 dialog.setOptions( Form.OPERATION,
84 ModelSupport.getNames( project.getInterfaceByName( target.getInterfaceName() ).getOperationList() ));
85 dialog.setValue( Form.OPERATION, target.getOperationName() );
86 dialog.setValue( Form.NAME, target.getName() );
87
88 if( dialog.show() )
89 {
90 String ifaceName = dialog.getValue( Form.INTERFACE );
91 String operationName = dialog.getValue( Form.OPERATION );
92
93 WsdlOperation operation = project.getInterfaceByName( ifaceName ).getOperationByName( operationName );
94 target.setOperation( operation );
95
96 String name = dialog.getValue( Form.NAME ).trim();
97 if( name.length() > 0 && !target.getName().equals( name ) )
98 target.setName( name );
99
100 if( dialog.getBooleanValue( Form.RECREATE_REQUEST ))
101 {
102 String req = operation.createRequest( dialog.getBooleanValue( Form.CREATE_OPTIONAL ) );
103 if( req == null )
104 {
105 UISupport.showErrorMessage( "Request creation failed" );
106 return;
107 }
108
109 WsdlTestRequest request = target.getTestRequest();
110 if( dialog.getBooleanValue( Form.KEEP_EXISTING ))
111 {
112 req = XmlUtils.transferValues( request.getRequestContent(), req );
113 }
114
115 request.setRequestContent( req );
116 }
117 }
118 }
119
120 @AForm( description = "Specify Interface/Operation for TestRequest", name = "Change Operation",
121 helpUrl=HelpUrls.CHANGEOPERATION_HELP_URL, icon=UISupport.TOOL_ICON_PATH)
122 protected interface Form
123 {
124 @AField( name = "Name", description = "The Name of the TestRequests", type = AFieldType.STRING )
125 public final static String NAME = "Name";
126
127 @AField( name = "Interface", description = "The TestRequests' Interface", type = AFieldType.ENUMERATION )
128 public final static String INTERFACE = "Interface";
129
130 @AField( name = "Operation", description = "The TestRequests' Operation", type = AFieldType.ENUMERATION )
131 public final static String OPERATION = "Operation";
132
133 @AField( name = "Recreate Request", description = "Recreates the request content from the new Operations Definition", type = AFieldType.BOOLEAN )
134 public final static String RECREATE_REQUEST = "Recreate Request";
135
136 @AField( name = "Create Optional", description = "Creates optional content when recreating the request", type = AFieldType.BOOLEAN )
137 public final static String CREATE_OPTIONAL = "Create Optional";
138
139 @AField( name = "Keep Existing", description = "Tries to keep existing values when recreating the request", type = AFieldType.BOOLEAN )
140 public final static String KEEP_EXISTING = "Keep Existing";
141 }
142 }