1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.request;
14
15 import com.eviware.soapui.SoapUI;
16 import com.eviware.soapui.impl.wsdl.WsdlProject;
17 import com.eviware.soapui.impl.wsdl.WsdlRequest;
18 import com.eviware.soapui.impl.wsdl.actions.support.AbstractAddToTestCaseAction;
19 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
20 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
21 import com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.SchemaComplianceAssertion;
22 import com.eviware.soapui.impl.wsdl.teststeps.assertions.soap.NotSoapFaultAssertion;
23 import com.eviware.soapui.impl.wsdl.teststeps.assertions.soap.SoapResponseAssertion;
24 import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory;
25 import com.eviware.soapui.support.UISupport;
26 import com.eviware.soapui.support.types.StringToStringMap;
27 import com.eviware.soapui.ui.desktop.SoapUIDesktop;
28 import com.eviware.x.form.XForm;
29 import com.eviware.x.form.XFormDialog;
30 import com.eviware.x.form.XFormDialogBuilder;
31 import com.eviware.x.form.XFormFactory;
32 import com.eviware.x.form.XFormField;
33
34 /***
35 * Adds a WsdlRequest to a WsdlTestCase as a WsdlTestRequestStep
36 *
37 * @author Ole.Matzura
38 */
39
40 public class AddRequestToTestCaseAction extends AbstractAddToTestCaseAction<WsdlRequest>
41 {
42 public static final String SOAPUI_ACTION_ID = "AddRequestToTestCaseAction";
43
44 private static final String STEP_NAME = "Name";
45 private static final String ADD_SOAP_FAULT_ASSERTION = "Add Not SOAP Fault Assertion";
46 private static final String ADD_SOAP_RESPONSE_ASSERTION = "Add SOAP Response Assertion";
47 private static final String ADD_SCHEMA_ASSERTION = "Add Schema Assertion";
48 private static final String CLOSE_REQUEST = "Close Request Window";
49 private static final String SHOW_TESTCASE = "Shows TestCase Editor";
50 private static final String COPY_ATTACHMENTS = "Copy Attachments";
51 private static final String COPY_HTTPHEADERS = "Copy HTTP Headers";
52
53 private XFormDialog dialog;
54 private StringToStringMap dialogValues = new StringToStringMap();
55 private XFormField closeRequestCheckBox;
56
57 public AddRequestToTestCaseAction()
58 {
59 super( "Add to TestCase", "Adds this request to a TestCase" );
60 }
61
62 public void perform( WsdlRequest request, Object param )
63 {
64 WsdlProject project = request.getOperation().getInterface().getProject();
65
66 WsdlTestCase testCase = getTargetTestCase( project );
67 if( testCase != null )
68 addRequest( testCase, request, -1 );
69 }
70
71 public WsdlTestRequestStep addRequest(WsdlTestCase testCase, WsdlRequest request, int position)
72 {
73 if( dialog == null )
74 buildDialog();
75
76 dialogValues.put( STEP_NAME, request.getOperation().getName() + " - " + request.getName() );
77 dialogValues.put( CLOSE_REQUEST, "true" );
78 dialogValues.put( SHOW_TESTCASE, "true" );
79 dialog.getFormField( COPY_ATTACHMENTS ).setEnabled( request.getAttachmentCount() > 0 );
80 dialog.setBooleanValue( COPY_ATTACHMENTS, true );
81
82 dialog.getFormField( COPY_HTTPHEADERS ).setEnabled( request.getRequestHeaders().size() > 0 );
83 dialog.setBooleanValue( COPY_HTTPHEADERS, false );
84
85 SoapUIDesktop desktop = SoapUI.getDesktop();
86 closeRequestCheckBox.setEnabled( desktop != null && desktop.hasDesktopPanel( request ));
87
88 boolean bidirectional = request.getOperation().isBidirectional();
89 dialog.getFormField( ADD_SCHEMA_ASSERTION ).setEnabled(bidirectional);
90 dialog.getFormField( ADD_SOAP_FAULT_ASSERTION ).setEnabled(bidirectional);
91 dialog.getFormField( ADD_SOAP_RESPONSE_ASSERTION ).setEnabled(bidirectional);
92
93 dialogValues = dialog.show( dialogValues );
94 if( dialog.getReturnValue() != XFormDialog.OK_OPTION )
95 return null;;
96
97 String name = dialogValues.get( STEP_NAME );
98
99 WsdlTestRequestStep testStep = (WsdlTestRequestStep) testCase.insertTestStep(
100 WsdlTestRequestStepFactory.createConfig( request, name ), position );
101
102 if( testStep == null )
103 return null;
104
105 if( dialogValues.getBoolean( COPY_ATTACHMENTS ))
106 request.copyAttachmentsTo( testStep.getTestRequest() );
107
108 if( dialogValues.getBoolean( COPY_HTTPHEADERS ))
109 testStep.getTestRequest().setRequestHeaders( request.getRequestHeaders() );
110
111 if( bidirectional )
112 {
113 if( dialogValues.getBoolean( ADD_SOAP_RESPONSE_ASSERTION ))
114 testStep.getTestRequest().addAssertion( SoapResponseAssertion.ID );
115
116 if( dialogValues.getBoolean( ADD_SCHEMA_ASSERTION ))
117 testStep.getTestRequest().addAssertion( SchemaComplianceAssertion.ID );
118
119 if( dialogValues.getBoolean( ADD_SOAP_FAULT_ASSERTION ))
120 testStep.getTestRequest().addAssertion( NotSoapFaultAssertion.LABEL );
121 }
122
123 UISupport.selectAndShow( testStep );
124
125 if( dialogValues.getBoolean( CLOSE_REQUEST ) && desktop != null )
126 {
127 desktop.closeDesktopPanel( request );
128 }
129
130 if( dialogValues.getBoolean( SHOW_TESTCASE ) )
131 {
132 UISupport.selectAndShow( testCase );
133 }
134
135 return testStep;
136 }
137
138 private void buildDialog()
139 {
140 XFormDialogBuilder builder = XFormFactory.createDialogBuilder("Add Request to TestCase");
141 XForm mainForm = builder.createForm( "Basic" );
142
143 mainForm.addTextField( STEP_NAME, "Name of TestStep", XForm.FieldType.URL ).setWidth( 30 );
144
145 mainForm.addCheckBox( ADD_SOAP_RESPONSE_ASSERTION, "(adds validation that response is a SOAP message)" );
146 mainForm.addCheckBox( ADD_SCHEMA_ASSERTION, "(adds validation that response complies with its schema)" );
147 mainForm.addCheckBox( ADD_SOAP_FAULT_ASSERTION, "(adds validation that response is not a SOAP Fault)" );
148 closeRequestCheckBox = mainForm.addCheckBox( CLOSE_REQUEST, "(closes the current window for this request)" );
149 mainForm.addCheckBox( SHOW_TESTCASE, "(opens the TestCase editor for the target TestCase)" );
150 mainForm.addCheckBox( COPY_ATTACHMENTS, "(copies the requests attachments to the TestRequest)" );
151 mainForm.addCheckBox( COPY_HTTPHEADERS, "(copies the requests HTTP-Headers to the TestRequest)" );
152
153 dialog = builder.buildDialog( builder.buildOkCancelActions(),
154 "Specify options for adding the request to a TestCase", UISupport.OPTIONS_ICON );
155
156 dialogValues.put( ADD_SOAP_RESPONSE_ASSERTION, Boolean.TRUE.toString() );
157 }
158 }