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