1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.operation;
14
15 import com.eviware.soapui.config.MockResponseStepConfig;
16 import com.eviware.soapui.config.TestStepConfig;
17 import com.eviware.soapui.impl.wsdl.WsdlOperation;
18 import com.eviware.soapui.impl.wsdl.actions.support.AbstractAddToTestCaseAction;
19 import com.eviware.soapui.impl.wsdl.support.CompressedStringSupport;
20 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
21 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
22 import com.eviware.soapui.impl.wsdl.teststeps.WsdlMockResponseTestStep;
23 import com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.SchemaComplianceAssertion;
24 import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlMockResponseStepFactory;
25 import com.eviware.soapui.settings.WsdlSettings;
26 import com.eviware.soapui.support.UISupport;
27 import com.eviware.x.form.XFormDialog;
28 import com.eviware.x.form.support.ADialogBuilder;
29 import com.eviware.x.form.support.AField;
30 import com.eviware.x.form.support.AForm;
31 import com.eviware.x.form.support.AField.AFieldType;
32
33 public class AddOperationAsMockResponseStepAction extends AbstractAddToTestCaseAction<WsdlOperation>
34 {
35 private XFormDialog dialog;
36
37 public AddOperationAsMockResponseStepAction()
38 {
39 super( "Add as MockResponse Step", "Creates a MockResponseStep for this Operation" );
40 }
41
42 public void perform( WsdlOperation operation, Object param )
43 {
44 WsdlTestCase testCase = getTargetTestCase( operation.getInterface().getProject() );
45 if( testCase != null )
46 addMockResponse( testCase, operation );
47 }
48
49 protected boolean addMockResponse( WsdlTestCase testCase, WsdlOperation operation )
50 {
51 if( dialog == null )
52 {
53 dialog = ADialogBuilder.buildDialog( Form.class );
54 dialog.setWidth( 450 );
55 }
56
57 dialog.setValue( Form.STEP_NAME, operation.getName() );
58 dialog.setBooleanValue( Form.SHOW_TESTCASE, true );
59 dialog.setIntValue( Form.PORT, 8181 );
60 dialog.setValue( Form.PATH, "/" + operation.getName() );
61
62 if( !dialog.show() )
63 return false;
64
65 TestStepConfig config = WsdlMockResponseStepFactory.createConfig( operation, false );
66 MockResponseStepConfig mockResponseStepConfig = ( ( MockResponseStepConfig )config.getConfig() );
67
68 config.setName( dialog.getValue( Form.STEP_NAME ) );
69 mockResponseStepConfig.setPath( dialog.getValue( Form.PATH ) );
70 mockResponseStepConfig.setPort( dialog.getIntValue( Form.PORT, 8181 ) );
71
72 String response = operation.createResponse( operation.getSettings().getBoolean(
73 WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS ) );
74 CompressedStringSupport.setString( mockResponseStepConfig.addNewResponse().addNewResponseContent(), response );
75
76 WsdlMockResponseTestStep testStep = ( WsdlMockResponseTestStep )testCase.addTestStep( config );
77
78 if( dialog.getBooleanValue( Form.ADD_SCHEMA_ASSERTION ) )
79 testStep.addAssertion( SchemaComplianceAssertion.ID );
80
81 UISupport.selectAndShow( testStep );
82
83 if( dialog.getBooleanValue( Form.SHOW_TESTCASE ) )
84 {
85 UISupport.selectAndShow( testCase );
86 }
87
88 return true;
89 }
90
91 @AForm( name = "Add MockResponse to TestCase", description = "Options for adding this Operations Response to a "
92 + "TestCase using a default response message generated from the schema.", helpUrl = HelpUrls.ADDMOCKOPERATIONASMOCKRESPONSESTEP_HELP_URL, icon = UISupport.TOOL_ICON_PATH )
93 private interface Form
94 {
95 @AField( name = "Name", description = "Unique name of MockResponse Step" )
96 public final static String STEP_NAME = "Name";
97
98 @AField( name = "Path", description = "Path to listen on" )
99 public final static String PATH = "Path";
100
101 @AField( name = "Port", description = "Port to listen on", type = AFieldType.INT )
102 public final static String PORT = "Port";
103
104 @AField( name = "Add Schema Assertion", description = "Adds SchemaCompliance Assertion for request", type = AFieldType.BOOLEAN )
105 public final static String ADD_SCHEMA_ASSERTION = "Add Schema Assertion";
106
107 @AField( name = "Shows TestCase Editor", description = "Shows the target steps TestCase editor", type = AFieldType.BOOLEAN )
108 public final static String SHOW_TESTCASE = "Shows TestCase Editor";
109 }
110 }