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