1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.teststeps;
14
15 import com.eviware.soapui.impl.wsdl.WsdlOperation;
16 import com.eviware.soapui.impl.wsdl.submit.WsdlMessageExchange;
17 import com.eviware.soapui.impl.wsdl.submit.transports.http.WsdlResponse;
18 import com.eviware.soapui.impl.wsdl.support.assertions.AssertedXPathsContainer;
19 import com.eviware.soapui.impl.wsdl.support.soap.SoapVersion;
20 import com.eviware.soapui.impl.wsdl.teststeps.actions.ShowMessageExchangeAction;
21 import com.eviware.soapui.model.ModelItem;
22 import com.eviware.soapui.model.iface.Attachment;
23 import com.eviware.soapui.model.iface.MessageExchange;
24 import com.eviware.soapui.model.testsuite.AssertedXPath;
25 import com.eviware.soapui.model.testsuite.MessageExchangeTestStepResult;
26 import com.eviware.soapui.model.testsuite.ResponseAssertedMessageExchange;
27 import com.eviware.soapui.support.action.swing.ActionList;
28 import com.eviware.soapui.support.types.StringToStringMap;
29 import com.eviware.soapui.support.xml.XmlUtils;
30
31 import java.io.PrintWriter;
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.Vector;
35
36 /***
37 * TestStepResult for a WsdlTestRequestStep
38 *
39 * @author ole.matzura
40 */
41
42 public class WsdlTestRequestStepResult extends WsdlTestStepResult implements
43 ResponseAssertedMessageExchange, AssertedXPathsContainer, MessageExchangeTestStepResult, WsdlMessageExchange
44 {
45 private String requestContent;
46 private WsdlResponse response;
47 private String domain;
48 private String username;
49 private String endpoint;
50 private String encoding;
51 private String password;
52 private StringToStringMap properties;
53 private boolean addedAction;
54 private List<AssertedXPath> assertedXPaths;
55
56 public WsdlTestRequestStepResult( WsdlTestRequestStep step )
57 {
58 super( step );
59 }
60
61 public WsdlOperation getOperation()
62 {
63 WsdlTestRequestStep testStep = (WsdlTestRequestStep) getTestStep();
64 return testStep.getOperation();
65 }
66
67 public SoapVersion getSoapVersion()
68 {
69 return ((WsdlOperation) getOperation()).getInterface().getSoapVersion();
70 }
71
72 public ModelItem getModelItem()
73 {
74 if( response != null )
75 return response.getRequest();
76 else
77 return null;
78 }
79
80 public String getRequestContent()
81 {
82 if( isDiscarded() )
83 return "<discarded>";
84
85 return requestContent;
86 }
87
88 public void setRequestContent( String requestContent )
89 {
90 this.requestContent = requestContent;
91 }
92
93 public WsdlResponse getResponse()
94 {
95 return response;
96 }
97
98 @Override
99 public ActionList getActions()
100 {
101 if( !addedAction )
102 {
103 addAction( new ShowMessageExchangeAction( this, "TestStep" ), true );
104 addedAction = true;
105 }
106
107 return super.getActions();
108 }
109
110 public void setResponse( WsdlResponse response )
111 {
112 this.response = response;
113 }
114
115 public String getDomain()
116 {
117 return domain;
118 }
119
120 public void setDomain( String domain )
121 {
122 this.domain = domain;
123 addProperty( "domain", domain );
124 }
125
126 private void addProperty( String key, String value )
127 {
128 if( properties == null )
129 properties = new StringToStringMap();
130
131 properties.put( key, value );
132 }
133
134 public String getEncoding()
135 {
136 return encoding;
137 }
138
139 public void setEncoding( String encoding )
140 {
141 this.encoding = encoding;
142 addProperty( "encoding", encoding );
143 }
144
145 public String getEndpoint()
146 {
147 return endpoint;
148 }
149
150 public void setEndpoint( String endpoint )
151 {
152 this.endpoint = endpoint;
153 addProperty( "endpoint", endpoint );
154 }
155
156 public String getPassword()
157 {
158 return password;
159 }
160
161 public void setPassword( String password )
162 {
163 this.password = password;
164 addProperty( "password", password );
165 }
166
167 public String getUsername()
168 {
169 return username;
170 }
171
172 public void setUsername( String username )
173 {
174 this.username = username;
175 addProperty( "username", username );
176 }
177
178 public void discard()
179 {
180 super.discard();
181
182 requestContent = null;
183 response = null;
184 properties = null;
185 assertedXPaths = null;
186 }
187
188 public void writeTo( PrintWriter writer )
189 {
190 super.writeTo( writer );
191
192 writer.println( "----------------------------------------------------" );
193 writer.println( "Encoding: " + getEncoding() );
194 writer.println( "Endpoint: " + getEndpoint() );
195 writer.println( "Username: " + getUsername() );
196 writer.println( "Password: " + getPassword() );
197 writer.println( "Domain: " + getDomain() );
198
199 writer.println( "---------------- Request ---------------------------" );
200 if( requestContent != null )
201 writer.println( XmlUtils.prettyPrintXml( requestContent ) );
202 else
203 writer.println( "- missing request / garbage collected -" );
204
205 if( response != null )
206 {
207 writer.println( "Request Headers: " + response.getRequestHeaders().toString() );
208 }
209
210 writer.println( "---------------- Response --------------------------" );
211 if( response != null )
212 {
213 String respContent = response.getContentAsString();
214 if( respContent != null )
215 writer.println( XmlUtils.prettyPrintXml( respContent ) );
216
217 writer.println( "Response Headers: " + response.getResponseHeaders().toString() );
218 }
219 else
220 writer.println( "- missing response / garbage collected -" );
221 }
222
223 public StringToStringMap getProperties()
224 {
225 return properties;
226 }
227
228 public String getProperty( String name )
229 {
230 return properties.get( name );
231 }
232
233 public Attachment[] getRequestAttachments()
234 {
235 if( response == null || response.getRequest() == null )
236 return new Attachment[0];
237
238 return response.getRequest().getAttachments();
239 }
240
241 public StringToStringMap getRequestHeaders()
242 {
243 if( response == null )
244 return null;
245
246 return response.getRequestHeaders();
247 }
248
249 public Attachment[] getResponseAttachments()
250 {
251 if( response == null )
252 return new Attachment[0];
253
254 return response.getAttachments();
255 }
256
257 public String getResponseContent()
258 {
259 if( isDiscarded() )
260 return "<discarded>";
261
262 if( response == null )
263 return "<missing response>";
264
265 return response.getContentAsString();
266 }
267
268 public String getRequestContentAsXml()
269 {
270 return XmlUtils.seemsToBeXml( requestContent ) ? requestContent : "<not-xml/>";
271 }
272
273 public String getResponseContentAsXml()
274 {
275 String responseContent = getResponseContent();
276 return XmlUtils.seemsToBeXml( responseContent ) ? responseContent : null;
277 }
278
279 public StringToStringMap getResponseHeaders()
280 {
281 if( response == null )
282 return null;
283
284 return response.getResponseHeaders();
285 }
286
287 public long getTimestamp()
288 {
289 if( isDiscarded() || response == null )
290 return -1;
291
292 return response.getTimestamp();
293 }
294
295 public AssertedXPath[] getAssertedXPathsForResponse()
296 {
297 return assertedXPaths == null ? new AssertedXPath[0] :
298 assertedXPaths.toArray( new AssertedXPath[assertedXPaths.size()] );
299 }
300
301 public void addAssertedXPath( AssertedXPath assertedXPath )
302 {
303 if( assertedXPaths == null )
304 assertedXPaths = new ArrayList<AssertedXPath>();
305
306 assertedXPaths.add( assertedXPath );
307 }
308
309 public MessageExchange[] getMessageExchanges()
310 {
311 return new MessageExchange[] { this };
312 }
313
314 public byte[] getRawRequestData()
315 {
316 return response == null ? null : response.getRawRequestData();
317 }
318
319 public byte[] getRawResponseData()
320 {
321 return response == null ? null : response.getRawResponseData();
322 }
323
324 public Attachment[] getRequestAttachmentsForPart( String partName )
325 {
326 return null;
327 }
328
329 public Attachment[] getResponseAttachmentsForPart( String partName )
330 {
331 return null;
332 }
333
334 public boolean hasRawData()
335 {
336 return false;
337 }
338
339 public boolean hasRequest( boolean b )
340 {
341 return true;
342 }
343
344 public boolean hasResponse()
345 {
346 return response != null;
347 }
348
349 public Vector<?> getRequestWssResult()
350 {
351 return null;
352 }
353
354 public Vector<?> getResponseWssResult()
355 {
356 return response == null ? null : response.getWssResult();
357 }
358
359 public int getResponseStatusCode()
360 {
361 return response == null ? 0 : response.getStatusCode();
362 }
363
364 public String getResponseContentType()
365 {
366 return response == null ? null : response.getContentType();
367 }
368 }