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