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.NotSoapFaultAssertion;
22 import com.eviware.soapui.impl.wsdl.teststeps.assertions.SchemaComplianceAssertion;
23 import com.eviware.soapui.impl.wsdl.teststeps.assertions.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, true );
84
85
86 SoapUIDesktop desktop = SoapUI.getDesktop();
87 closeRequestCheckBox.setEnabled( desktop != null && desktop.hasDesktopPanel( request ));
88
89 dialogValues = dialog.show( dialogValues );
90 if( dialog.getReturnValue() != XFormDialog.OK_OPTION )
91 return null;;
92
93 String name = dialogValues.get( STEP_NAME );
94
95 WsdlTestRequestStep test = (WsdlTestRequestStep) testCase.insertTestStep(
96 WsdlTestRequestStepFactory.createConfig( request, name ), position );
97
98 if( dialogValues.getBoolean( COPY_ATTACHMENTS ))
99 request.copyAttachmentsTo( test.getTestRequest() );
100
101 if( dialogValues.getBoolean( COPY_HTTPHEADERS ))
102 test.getTestRequest().setRequestHeaders( request.getRequestHeaders() );
103
104 if( dialogValues.getBoolean( ADD_SOAP_RESPONSE_ASSERTION ))
105 test.getTestRequest().addAssertion( SoapResponseAssertion.ID );
106
107 if( dialogValues.getBoolean( ADD_SCHEMA_ASSERTION ))
108 test.getTestRequest().addAssertion( SchemaComplianceAssertion.ID );
109
110 if( dialogValues.getBoolean( ADD_SOAP_FAULT_ASSERTION ))
111 test.getTestRequest().addAssertion( NotSoapFaultAssertion.LABEL );
112
113 UISupport.selectAndShow( test );
114
115 if( dialogValues.getBoolean( CLOSE_REQUEST ) && desktop != null )
116 {
117 desktop.closeDesktopPanel( request );
118 }
119
120 if( dialogValues.getBoolean( SHOW_TESTCASE ) )
121 {
122 UISupport.selectAndShow( testCase );
123 }
124
125 return test;
126 }
127
128 private void buildDialog()
129 {
130 XFormDialogBuilder builder = XFormFactory.createDialogBuilder("Add Request to TestCase");
131 XForm mainForm = builder.createForm( "Basic" );
132
133 mainForm.addTextField( STEP_NAME, "Name of TestStep", XForm.FieldType.URL ).setWidth( 30 );
134
135 mainForm.addCheckBox( ADD_SOAP_RESPONSE_ASSERTION, "(adds validation that response is a SOAP message)" );
136 mainForm.addCheckBox( ADD_SCHEMA_ASSERTION, "(adds validation that response complies with its schema)" );
137 mainForm.addCheckBox( ADD_SOAP_FAULT_ASSERTION, "(adds validation that response is not a SOAP Fault)" );
138 closeRequestCheckBox = mainForm.addCheckBox( CLOSE_REQUEST, "(closes the current window for this request)" );
139 mainForm.addCheckBox( SHOW_TESTCASE, "(opens the TestCase editor for the target TestCase)" );
140 mainForm.addCheckBox( COPY_ATTACHMENTS, "(copies the requests attachments to the TestRequest)" );
141 mainForm.addCheckBox( COPY_HTTPHEADERS, "(copies the requests HTTP-Headers to the TestRequest)" );
142
143 dialog = builder.buildDialog( builder.buildOkCancelActions(),
144 "Specify options for adding the request to a TestCase", UISupport.OPTIONS_ICON );
145
146 dialogValues.put( ADD_SOAP_RESPONSE_ASSERTION, Boolean.TRUE.toString() );
147 }
148 }