1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.teststeps;
14
15 import java.util.HashSet;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.Set;
19
20 import javax.swing.ImageIcon;
21
22 import org.apache.log4j.Logger;
23
24 import com.eviware.soapui.SoapUI;
25 import com.eviware.soapui.config.JdbcRequestTestStepConfig;
26 import com.eviware.soapui.config.ModelItemConfig;
27 import com.eviware.soapui.impl.wsdl.support.ModelItemIconAnimator;
28 import com.eviware.soapui.impl.wsdl.teststeps.JdbcRequestTestStep;
29 import com.eviware.soapui.impl.wsdl.teststeps.TestRequest;
30 import com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion;
31 import com.eviware.soapui.impl.wsdl.teststeps.assertions.TestAssertionRegistry.AssertableType;
32 import com.eviware.soapui.model.ModelItem;
33 import com.eviware.soapui.model.iface.Attachment;
34 import com.eviware.soapui.model.iface.Interface;
35 import com.eviware.soapui.model.iface.MessagePart;
36 import com.eviware.soapui.model.iface.Operation;
37 import com.eviware.soapui.model.iface.Submit;
38 import com.eviware.soapui.model.iface.SubmitContext;
39 import com.eviware.soapui.model.iface.SubmitListener;
40 import com.eviware.soapui.model.settings.Settings;
41 import com.eviware.soapui.model.support.AbstractAnimatableModelItem;
42 import com.eviware.soapui.model.support.ModelSupport;
43 import com.eviware.soapui.model.testsuite.Assertable;
44 import com.eviware.soapui.model.testsuite.AssertionsListener;
45 import com.eviware.soapui.model.testsuite.TestAssertion;
46 import com.eviware.soapui.monitor.TestMonitor;
47 import com.eviware.soapui.support.UISupport;
48
49 public class JdbcRequest extends AbstractAnimatableModelItem<ModelItemConfig> implements Assertable, TestRequest
50 {
51 private final JdbcRequestTestStep testStep;
52 private Set<SubmitListener> submitListeners = new HashSet<SubmitListener>();
53 private JdbcResponse response;
54 final static Logger logger = Logger.getLogger( JdbcRequest.class );
55 private ImageIcon validRequestIcon;
56 private ImageIcon failedRequestIcon;
57 private ImageIcon disabledRequestIcon;
58 private ImageIcon unknownRequestIcon;
59 private RequestIconAnimator<?> iconAnimator;
60 private boolean forLoadTest;
61 private AssertionStatus currentStatus;
62
63 public JdbcRequest( JdbcRequestTestStep testStep )
64 {
65 this.testStep = testStep;
66 initIcons();
67 }
68
69 public void addSubmitListener( SubmitListener listener )
70 {
71 submitListeners.add( listener );
72 }
73
74 public boolean dependsOn( ModelItem modelItem )
75 {
76 return ModelSupport.dependsOn( testStep, modelItem );
77 }
78
79 public Attachment[] getAttachments()
80 {
81 return null;
82 }
83
84 public String getEncoding()
85 {
86 return null;
87 }
88
89 public String getEndpoint()
90 {
91 return null;
92 }
93
94 public Operation getOperation()
95 {
96 return null;
97 }
98
99 public String getRequestContent()
100 {
101 return ( ( JdbcRequestTestStepConfig )testStep.getConfig() ).getQuery();
102 }
103
104 public MessagePart[] getRequestParts()
105 {
106 return null;
107 }
108
109 public MessagePart[] getResponseParts()
110 {
111 return null;
112 }
113
114 public String getTimeout()
115 {
116 return testStep.getQueryTimeout();
117 }
118
119 public void removeSubmitListener( SubmitListener listener )
120 {
121 submitListeners.remove( listener );
122 }
123
124 public void setEncoding( String string )
125 {
126 }
127
128 public void setEndpoint( String string )
129 {
130 }
131
132 public JdbcSubmit submit( SubmitContext submitContext, boolean async ) throws SubmitException
133 {
134 return new JdbcSubmit( this, submitContext, async );
135 }
136
137 public List<? extends ModelItem> getChildren()
138 {
139 return null;
140 }
141
142 public String getDescription()
143 {
144 return testStep.getDescription();
145 }
146
147
148
149
150
151
152 public String getId()
153 {
154 return testStep.getId();
155 }
156
157 public String getName()
158 {
159 return testStep.getName();
160 }
161
162 public ModelItem getParent()
163 {
164 return testStep.getParent();
165 }
166
167 public Settings getSettings()
168 {
169 return testStep.getSettings();
170 }
171
172 public SubmitListener[] getSubmitListeners()
173 {
174 return submitListeners.toArray( new SubmitListener[submitListeners.size()] );
175 }
176
177 public JdbcRequestTestStep getTestStep()
178 {
179 return testStep;
180 }
181
182 public WsdlMessageAssertion importAssertion( WsdlMessageAssertion source, boolean overwrite, boolean createCopy )
183 {
184 return testStep.importAssertion( source, overwrite, createCopy );
185 }
186
187 public TestAssertion addAssertion( String selection )
188 {
189 return testStep.addAssertion( selection );
190 }
191
192 public void addAssertionsListener( AssertionsListener listener )
193 {
194 testStep.addAssertionsListener( listener );
195 }
196
197 public TestAssertion cloneAssertion( TestAssertion source, String name )
198 {
199 return testStep.cloneAssertion( source, name );
200 }
201
202 public String getAssertableContent()
203 {
204 return testStep.getAssertableContent();
205 }
206
207 public AssertableType getAssertableType()
208 {
209 return testStep.getAssertableType();
210 }
211
212 public TestAssertion getAssertionAt( int c )
213 {
214 return testStep.getAssertionAt( c );
215 }
216
217 public TestAssertion getAssertionByName( String name )
218 {
219 return testStep.getAssertionByName( name );
220 }
221
222 public int getAssertionCount()
223 {
224 return testStep.getAssertionCount();
225 }
226
227 public List<TestAssertion> getAssertionList()
228 {
229 return testStep.getAssertionList();
230 }
231
232 public AssertionStatus getAssertionStatus()
233 {
234 currentStatus = AssertionStatus.UNKNOWN;
235
236 if( getResponse() == null )
237 return currentStatus;
238
239 int cnt = getAssertionCount();
240 if( cnt == 0 )
241 return currentStatus;
242
243 boolean hasEnabled = false;
244
245 for( int c = 0; c < cnt; c++ )
246 {
247 if( !getAssertionAt( c ).isDisabled() )
248 hasEnabled = true;
249
250 if( getAssertionAt( c ).getStatus() == AssertionStatus.FAILED )
251 {
252 currentStatus = AssertionStatus.FAILED;
253 break;
254 }
255 }
256
257 if( currentStatus == AssertionStatus.UNKNOWN && hasEnabled )
258 currentStatus = AssertionStatus.VALID;
259
260 return currentStatus;
261 }
262
263 public Map<String, TestAssertion> getAssertions()
264 {
265 return testStep.getAssertions();
266 }
267
268 public String getDefaultAssertableContent()
269 {
270 return testStep.getDefaultAssertableContent();
271 }
272
273 public Interface getInterface()
274 {
275 return testStep.getInterface();
276 }
277
278 public ModelItem getModelItem()
279 {
280 return testStep.getModelItem();
281 }
282
283 public TestAssertion moveAssertion( int ix, int offset )
284 {
285 return testStep.moveAssertion( ix, offset );
286 }
287
288 public void removeAssertion( TestAssertion assertion )
289 {
290 testStep.removeAssertion( assertion );
291 }
292
293 public void removeAssertionsListener( AssertionsListener listener )
294 {
295 testStep.removeAssertionsListener( listener );
296 }
297
298 public void setResponse( JdbcResponse response )
299 {
300 this.response = response;
301 }
302
303 public JdbcResponse getResponse()
304 {
305 return response;
306 }
307
308 public void initIcons()
309 {
310 if( validRequestIcon == null )
311 validRequestIcon = UISupport.createImageIcon( "/valid_jdbc_request.gif" );
312
313 if( failedRequestIcon == null )
314 failedRequestIcon = UISupport.createImageIcon( "/invalid_jdbc_request.gif" );
315
316 if( unknownRequestIcon == null )
317 unknownRequestIcon = UISupport.createImageIcon( "/unknown_jdbc_request.gif" );
318
319 if( disabledRequestIcon == null )
320 disabledRequestIcon = UISupport.createImageIcon( "/disabled_jdbc_request.gif" );
321
322 setIconAnimator( new RequestIconAnimator<JdbcRequest>( this, "/jdbc_request.gif", "/exec_jdbc_request", 4, "gif" ) );
323 }
324
325 protected RequestIconAnimator<?> initIconAnimator()
326 {
327 return new RequestIconAnimator<JdbcRequest>( this, "/jdbc_request.gif", "/exec_jdbc_request", 4, "gif" );
328 }
329
330 public static class RequestIconAnimator<T extends JdbcRequest> extends ModelItemIconAnimator<T> implements
331 SubmitListener
332 {
333 public RequestIconAnimator( T modelItem, String baseIcon, String animIconRoot, int iconCount, String iconExtension )
334 {
335 super( modelItem, baseIcon, animIconRoot, iconCount, iconExtension );
336 }
337
338 public boolean beforeSubmit( Submit submit, SubmitContext context )
339 {
340 if( isEnabled() && submit.getRequest() == getTarget() )
341 start();
342 return true;
343 }
344
345 public void afterSubmit( Submit submit, SubmitContext context )
346 {
347 if( submit.getRequest() == getTarget() )
348 stop();
349 }
350 }
351
352 public RequestIconAnimator<?> getIconAnimator()
353 {
354 return iconAnimator;
355 }
356
357 public void setIconAnimator( RequestIconAnimator<?> iconAnimator )
358 {
359 if( this.iconAnimator != null )
360 removeSubmitListener( this.iconAnimator );
361
362 this.iconAnimator = iconAnimator;
363 addSubmitListener( this.iconAnimator );
364 }
365
366 public ImageIcon getIcon()
367 {
368 if( forLoadTest || UISupport.isHeadless() )
369 return null;
370
371 TestMonitor testMonitor = SoapUI.getTestMonitor();
372 if( testMonitor != null && testMonitor.hasRunningLoadTest( getTestStep().getTestCase() ) )
373 return disabledRequestIcon;
374
375 ImageIcon icon = getIconAnimator().getIcon();
376 if( icon == getIconAnimator().getBaseIcon() )
377 {
378 AssertionStatus status = getAssertionStatus();
379 if( status == AssertionStatus.VALID )
380 return validRequestIcon;
381 else if( status == AssertionStatus.FAILED )
382 return failedRequestIcon;
383 else if( status == AssertionStatus.UNKNOWN )
384 return unknownRequestIcon;
385 }
386
387 return icon;
388 }
389
390 @Override
391 public void setIcon( ImageIcon icon )
392 {
393 getTestStep().setIcon( icon );
394 }
395
396 public String getPassword()
397 {
398
399 return null;
400 }
401
402 public String getUsername()
403 {
404
405 return null;
406 }
407
408 }