1
2
3
4
5 package com.eviware.soapui.impl.wsdl.teststeps.actions;
6
7 import com.eviware.soapui.impl.wsdl.WsdlInterface;
8 import com.eviware.soapui.impl.wsdl.WsdlProject;
9 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
10 import com.eviware.soapui.impl.wsdl.teststeps.WsdlMockResponseTestStep;
11 import com.eviware.soapui.model.iface.Interface;
12 import com.eviware.soapui.model.iface.Operation;
13 import com.eviware.soapui.model.util.ModelItemNames;
14 import com.eviware.soapui.support.UISupport;
15 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
16 import com.eviware.x.form.XFormDialog;
17 import com.eviware.x.form.XFormField;
18 import com.eviware.x.form.XFormFieldListener;
19 import com.eviware.x.form.support.ADialogBuilder;
20 import com.eviware.x.form.support.AField;
21 import com.eviware.x.form.support.AField.AFieldType;
22 import com.eviware.x.form.support.AForm;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 public class SetMockOperationAction extends AbstractSoapUIAction<WsdlMockResponseTestStep>
28 {
29 private XFormDialog dialog;
30 private WsdlProject project;
31
32 public SetMockOperationAction()
33 {
34 super( "Set MockOperation", "Sets which Operation to Mock" );
35 }
36
37 public void perform( WsdlMockResponseTestStep mockResponseTestStep, Object param )
38 {
39 if( dialog == null )
40 {
41 dialog = ADialogBuilder.buildDialog( CreateForm.class );
42 dialog.getFormField( CreateForm.INTERFACE ).addFormFieldListener( new XFormFieldListener() {
43
44 public void valueChanged( XFormField sourceField, String newValue, String oldValue )
45 {
46 updateOperations( newValue );
47 }} );
48 }
49
50 project = mockResponseTestStep.getTestCase().getTestSuite().getProject();
51 List<Interface> interfaces = new ArrayList<Interface>();
52 for( int c = 0; c < project.getInterfaceCount(); c++ )
53 {
54 if( project.getInterfaceAt( c ).getOperationCount() > 0 )
55 interfaces.add( project.getInterfaceAt( c ));
56 }
57
58
59 dialog.setOptions( CreateForm.INTERFACE, new ModelItemNames<Interface>( interfaces ).getNames() );
60 String ifaceName = mockResponseTestStep.getOperation().getInterface().getName();
61 updateOperations( ifaceName );
62
63 dialog.setValue( CreateForm.INTERFACE, ifaceName );
64 dialog.setValue( CreateForm.OPERATION, mockResponseTestStep.getOperation().getName() );
65
66 if( dialog.show() )
67 {
68 mockResponseTestStep.setInterface( dialog.getValue( CreateForm.INTERFACE ) );
69 mockResponseTestStep.setOperation( dialog.getValue( CreateForm.OPERATION ) );
70 }
71 }
72
73 private void updateOperations( String interfaceName )
74 {
75 WsdlInterface iface = (WsdlInterface) project.getInterfaceByName( interfaceName );
76 dialog.setOptions( CreateForm.OPERATION,
77 new ModelItemNames<Operation>( iface.getOperationList() ).getNames() );
78 }
79
80 @AForm(description = "Set the Operation to mock (required for dispatch and validations)", name = "Set MockOperation",
81 helpUrl= HelpUrls.SETMOCKOPERATION_HELP_URL, icon=UISupport.TOOL_ICON_PATH)
82 private interface CreateForm
83 {
84 @AField(description = "Specifies the operation to be mocked", name = "Operation", type = AFieldType.ENUMERATION)
85 public final static String OPERATION = "Operation";
86
87 @AField(description = "Specifies the interface containing the operation to be mocked", name = "Interface", type = AFieldType.ENUMERATION)
88 public final static String INTERFACE = "Interface";
89 }
90 }