1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.testcase;
14
15 import com.eviware.soapui.SoapUI;
16 import com.eviware.soapui.config.LoadTestConfig;
17 import com.eviware.soapui.config.TestCaseConfig;
18 import com.eviware.soapui.config.TestStepConfig;
19 import com.eviware.soapui.impl.wsdl.AbstractTestPropertyHolderWsdlModelItem;
20 import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
21 import com.eviware.soapui.impl.wsdl.loadtest.LoadTestAssertion;
22 import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
23 import com.eviware.soapui.impl.wsdl.loadtest.assertions.TestStepStatusAssertion;
24 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
25 import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestStepFactory;
26 import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestStepRegistry;
27 import com.eviware.soapui.model.ModelItem;
28 import com.eviware.soapui.model.testsuite.*;
29 import com.eviware.soapui.support.StringUtils;
30 import com.eviware.soapui.support.UISupport;
31 import com.eviware.soapui.support.action.swing.ActionList;
32 import com.eviware.soapui.support.action.swing.DefaultActionList;
33 import com.eviware.soapui.support.resolver.ResolveDialog;
34 import com.eviware.soapui.support.scripting.SoapUIScriptEngine;
35 import com.eviware.soapui.support.scripting.SoapUIScriptEngineRegistry;
36 import com.eviware.soapui.support.types.StringToObjectMap;
37 import org.apache.log4j.Logger;
38
39 import java.io.File;
40 import java.io.IOException;
41 import java.util.*;
42
43 /***
44 * TestCase implementation for WSDL projects
45 *
46 * @author Ole.Matzura
47 */
48
49 public class WsdlTestCase extends AbstractTestPropertyHolderWsdlModelItem<TestCaseConfig> implements TestCase
50 {
51 private final static Logger logger = Logger.getLogger( WsdlTestCase.class );
52 public final static String KEEP_SESSION_PROPERTY = WsdlTestCase.class.getName() + "@keepSession";
53 public final static String FAIL_ON_ERROR_PROPERTY = WsdlTestCase.class.getName() + "@failOnError";
54 public final static String FAIL_ON_ERRORS_PROPERTY = WsdlTestCase.class.getName() + "@failOnErrors";
55 public final static String DISCARD_OK_RESULTS = WsdlTestCase.class.getName() + "@discardOkResults";
56 public final static String SETUP_SCRIPT_PROPERTY = WsdlTestCase.class.getName() + "@setupScript";
57 public final static String TEARDOWN_SCRIPT_PROPERTY = WsdlTestCase.class.getName() + "@tearDownScript";
58 public static final String TIMEOUT_PROPERTY = WsdlTestCase.class.getName() + "@timeout";
59 public static final String SEARCH_PROPERTIES_PROPERTY = WsdlTestCase.class.getName() + "@searchProperties";
60
61 private final WsdlTestSuite testSuite;
62 private List<WsdlTestStep> testSteps = new ArrayList<WsdlTestStep>();
63 private List<WsdlLoadTest> loadTests = new ArrayList<WsdlLoadTest>();
64 private Set<TestRunListener> testRunListeners = new HashSet<TestRunListener>();
65 private DefaultActionList createActions;
66 private final boolean forLoadTest;
67 private SoapUIScriptEngine setupScriptEngine;
68 private SoapUIScriptEngine tearDownScriptEngine;
69
70 public WsdlTestCase( WsdlTestSuite testSuite, TestCaseConfig config, boolean forLoadTest )
71 {
72 super( config, testSuite, "/testCase.gif" );
73
74 this.testSuite = testSuite;
75 this.forLoadTest = forLoadTest;
76
77 List<TestStepConfig> testStepConfigs = config.getTestStepList();
78 for( TestStepConfig tsc : testStepConfigs )
79 {
80 WsdlTestStep testStep = createTestStepFromConfig( tsc );
81 if( testStep != null )
82 {
83 ensureUniqueName( testStep );
84 testSteps.add( testStep );
85 }
86 }
87
88 if( !forLoadTest )
89 {
90 List<LoadTestConfig> loadTestConfigs = config.getLoadTestList();
91 for( LoadTestConfig tsc : loadTestConfigs )
92 {
93 WsdlLoadTest loadTest = new WsdlLoadTest( this, tsc );
94 loadTests.add( loadTest );
95 }
96 }
97
98
99 if( !config.isSetFailOnError() )
100 config.setFailOnError( true );
101
102 if( !config.isSetFailTestCaseOnErrors() )
103 config.setFailTestCaseOnErrors( true );
104
105 if( !config.isSetKeepSession() )
106 config.setKeepSession( false );
107
108 if( !config.isSetMaxResults() )
109 config.setMaxResults( 0 );
110
111 for( TestRunListener listener : SoapUI.getListenerRegistry().getListeners( TestRunListener.class ) )
112 {
113 addTestRunListener( listener );
114 }
115
116 if( !getConfig().isSetProperties() )
117 getConfig().addNewProperties();
118
119 setPropertiesConfig( getConfig().getProperties() );
120
121
122
123
124
125
126
127
128
129
130
131
132
133 }
134
135 public boolean getKeepSession()
136 {
137 return getConfig().getKeepSession();
138 }
139
140 public void setKeepSession( boolean keepSession )
141 {
142 boolean old = getKeepSession();
143 if( old != keepSession )
144 {
145 getConfig().setKeepSession( keepSession );
146 notifyPropertyChanged( KEEP_SESSION_PROPERTY, old, keepSession );
147 }
148 }
149
150 public void setSetupScript( String script )
151 {
152 String oldScript = getSetupScript();
153
154 if( !getConfig().isSetSetupScript() )
155 getConfig().addNewSetupScript();
156
157 getConfig().getSetupScript().setStringValue( script );
158 if( setupScriptEngine != null )
159 setupScriptEngine.setScript( script );
160
161 notifyPropertyChanged( SETUP_SCRIPT_PROPERTY, oldScript, script );
162 }
163
164 public String getSetupScript()
165 {
166 return getConfig().isSetSetupScript() ? getConfig().getSetupScript().getStringValue() : null;
167 }
168
169 public void setTearDownScript( String script )
170 {
171 String oldScript = getTearDownScript();
172
173 if( !getConfig().isSetTearDownScript() )
174 getConfig().addNewTearDownScript();
175
176 getConfig().getTearDownScript().setStringValue( script );
177 if( tearDownScriptEngine != null )
178 tearDownScriptEngine.setScript( script );
179
180 notifyPropertyChanged( TEARDOWN_SCRIPT_PROPERTY, oldScript, script );
181 }
182
183 public String getTearDownScript()
184 {
185 return getConfig().isSetTearDownScript() ? getConfig().getTearDownScript().getStringValue() : null;
186 }
187
188 public boolean getFailOnError()
189 {
190 return getConfig().getFailOnError();
191 }
192
193 public boolean getFailTestCaseOnErrors()
194 {
195 return getConfig().getFailTestCaseOnErrors();
196 }
197
198 public void setFailOnError( boolean failOnError )
199 {
200 boolean old = getFailOnError();
201 if( old != failOnError )
202 {
203 getConfig().setFailOnError( failOnError );
204 notifyPropertyChanged( FAIL_ON_ERROR_PROPERTY, old, failOnError );
205 }
206 }
207
208 public void setFailTestCaseOnErrors( boolean failTestCaseOnErrors )
209 {
210 boolean old = getFailTestCaseOnErrors();
211 if( old != failTestCaseOnErrors )
212 {
213 getConfig().setFailTestCaseOnErrors( failTestCaseOnErrors );
214 notifyPropertyChanged( FAIL_ON_ERRORS_PROPERTY, old, failTestCaseOnErrors );
215 }
216 }
217
218 public boolean getSearchProperties()
219 {
220 return getConfig().getSearchProperties();
221 }
222
223 public void setSearchProperties( boolean searchProperties )
224 {
225 boolean old = getSearchProperties();
226 if( old != searchProperties )
227 {
228 getConfig().setSearchProperties( searchProperties );
229 notifyPropertyChanged( SEARCH_PROPERTIES_PROPERTY, old, searchProperties );
230 }
231 }
232
233 public boolean getDiscardOkResults()
234 {
235 return getConfig().getDiscardOkResults();
236 }
237
238 public void setDiscardOkResults( boolean discardOkResults )
239 {
240 boolean old = getDiscardOkResults();
241 if( old != discardOkResults )
242 {
243 getConfig().setDiscardOkResults( discardOkResults );
244 notifyPropertyChanged( DISCARD_OK_RESULTS, old, discardOkResults );
245 }
246 }
247
248 public int getMaxResults()
249 {
250 return getConfig().getMaxResults();
251 }
252
253 public void setMaxResults( int maxResults )
254 {
255 int old = getMaxResults();
256 if( old != maxResults )
257 {
258 getConfig().setMaxResults( maxResults );
259 notifyPropertyChanged( "maxResults", old, maxResults );
260 }
261 }
262
263 private WsdlTestStep createTestStepFromConfig( TestStepConfig tsc )
264 {
265 WsdlTestStepFactory factory = WsdlTestStepRegistry.getInstance().getFactory( tsc.getType() );
266 if( factory != null )
267 {
268 WsdlTestStep testStep = factory.buildTestStep( this, tsc, forLoadTest );
269 return testStep;
270 }
271 else
272 {
273 logger.error( "Failed to create test step for [" + tsc.getName() + "]" );
274 return null;
275 }
276 }
277
278 private boolean ensureUniqueName( WsdlTestStep testStep )
279 {
280 String name = testStep.getName();
281 while( name == null || getTestStepByName( name ) != null )
282 {
283 if( name == null )
284 name = testStep.getName();
285 else
286 {
287 int cnt = 0;
288
289 while( getTestStepByName( name ) != null )
290 {
291 cnt++;
292 name = testStep.getName() + " " + cnt;
293 }
294
295 if( cnt == 0 )
296 break;
297 }
298
299 name = UISupport.prompt( "TestStep name must be unique, please specify new name for step\n" + "["
300 + testStep.getName() + "] in TestCase [" + getTestSuite().getProject().getName() + "->"
301 + getTestSuite().getName() + "->" + getName() + "]", "Change TestStep name", name );
302
303 if( name == null )
304 return false;
305 }
306
307 if( !name.equals( testStep.getName() ) )
308 testStep.setName( name );
309
310 return true;
311 }
312
313 public WsdlLoadTest addNewLoadTest( String name )
314 {
315 WsdlLoadTest loadTest = new WsdlLoadTest( this, getConfig().addNewLoadTest() );
316 loadTest.setStartDelay( 0 );
317 loadTest.setName( name );
318 loadTests.add( loadTest );
319
320 loadTest.addAssertion( TestStepStatusAssertion.STEP_STATUS_TYPE, LoadTestAssertion.ANY_TEST_STEP, false );
321
322 ( getTestSuite() ).fireLoadTestAdded( loadTest );
323
324 return loadTest;
325 }
326
327 public void removeLoadTest( WsdlLoadTest loadTest )
328 {
329 int ix = loadTests.indexOf( loadTest );
330
331 loadTests.remove( ix );
332
333 try
334 {
335 ( getTestSuite() ).fireLoadTestRemoved( loadTest );
336 }
337 finally
338 {
339 loadTest.release();
340 getConfig().removeLoadTest( ix );
341 }
342 }
343
344 public WsdlTestSuite getTestSuite()
345 {
346 return testSuite;
347 }
348
349 public WsdlTestStep cloneStep( WsdlTestStep testStep, String name )
350 {
351 return testStep.clone( this, name );
352 }
353
354 public WsdlTestStep getTestStepAt( int index )
355 {
356 return testSteps.get( index );
357 }
358
359 public int getTestStepCount()
360 {
361 return testSteps.size();
362 }
363
364 public WsdlLoadTest getLoadTestAt( int index )
365 {
366 return loadTests.get( index );
367 }
368
369 public LoadTest getLoadTestByName( String loadTestName )
370 {
371 return (LoadTest) getWsdlModelItemByName( loadTests, loadTestName );
372 }
373
374 public int getLoadTestCount()
375 {
376 return loadTests.size();
377 }
378
379 public WsdlTestStep addTestStep( TestStepConfig stepConfig )
380 {
381 return insertTestStep( stepConfig, -1 );
382 }
383
384 public WsdlTestStep addTestStep( String type, String name )
385 {
386 TestStepConfig newStepConfig = WsdlTestStepRegistry.getInstance().getFactory( type ).createNewTestStep( this,
387 name );
388 if( newStepConfig != null )
389 {
390 return addTestStep( newStepConfig );
391 }
392 else
393 return null;
394 }
395
396 public WsdlTestStep insertTestStep( String type, String name, int index )
397 {
398 TestStepConfig newStepConfig = WsdlTestStepRegistry.getInstance().getFactory( type ).createNewTestStep( this,
399 name );
400 if( newStepConfig != null )
401 {
402 return insertTestStep( newStepConfig, index );
403 }
404 else
405 return null;
406 }
407
408 public WsdlTestStep importTestStep( WsdlTestStep testStep, String name, int index, boolean createCopy )
409 {
410 testStep.beforeSave();
411 TestStepConfig newStepConfig = (TestStepConfig) testStep.getConfig().copy();
412 newStepConfig.setName( name );
413 if( createCopy && newStepConfig.isSetId() )
414 newStepConfig.unsetId();
415
416 WsdlTestStep result = insertTestStep( newStepConfig, index );
417 resolveTestCase();
418 return result;
419 }
420
421 private void resolveTestCase()
422 {
423 ResolveDialog resolver = new ResolveDialog( "Validate TestCase", "Checks TestCase for inconsistencies", null );
424 resolver.setShowOkMessage( false );
425 resolver.resolve( this );
426 }
427
428 public WsdlTestStep[] importTestSteps( WsdlTestStep[] testSteps, int index, boolean createCopies )
429 {
430 TestStepConfig[] newStepConfigs = new TestStepConfig[testSteps.length];
431
432 for( int c = 0; c < testSteps.length; c++ )
433 {
434 testSteps[c].beforeSave();
435 newStepConfigs[c] = (TestStepConfig) testSteps[c].getConfig().copy();
436 if( createCopies && newStepConfigs[c].isSetId() )
437 newStepConfigs[c].unsetId();
438 }
439
440 WsdlTestStep[] result = insertTestSteps( newStepConfigs, index );
441 resolveTestCase();
442 return result;
443 }
444
445 public WsdlTestStep insertTestStep( TestStepConfig stepConfig, int ix )
446 {
447 TestStepConfig newStepConfig = ix == -1 ? getConfig().addNewTestStep() : getConfig().insertNewTestStep( ix );
448 newStepConfig.set( stepConfig );
449 WsdlTestStep testStep = createTestStepFromConfig( newStepConfig );
450
451 if( !ensureUniqueName( testStep ) )
452 return null;
453
454 if( ix == -1 )
455 testSteps.add( testStep );
456 else
457 testSteps.add( ix, testStep );
458
459 testStep.afterLoad();
460
461 if( getTestSuite() != null )
462 ( getTestSuite() ).fireTestStepAdded( testStep, ix == -1 ? testSteps.size() - 1 : ix );
463
464 return testStep;
465 }
466
467 public WsdlTestStep[] insertTestSteps( TestStepConfig[] stepConfig, int ix )
468 {
469 WsdlTestStep[] result = new WsdlTestStep[stepConfig.length];
470
471 for( int c = 0; c < stepConfig.length; c++ )
472 {
473 TestStepConfig newStepConfig = ix == -1 ? getConfig().addNewTestStep() : getConfig()
474 .insertNewTestStep( ix + c );
475 newStepConfig.set( stepConfig[c] );
476 WsdlTestStep testStep = createTestStepFromConfig( newStepConfig );
477
478 if( !ensureUniqueName( testStep ) )
479 return null;
480
481 if( ix == -1 )
482 testSteps.add( testStep );
483 else
484 testSteps.add( ix + c, testStep );
485
486 result[c] = testStep;
487 }
488
489 for( int c = 0; c < result.length; c++ )
490 {
491 result[c].afterLoad();
492
493 if( getTestSuite() != null )
494 ( getTestSuite() ).fireTestStepAdded( result[c], getIndexOfTestStep( result[c] ) );
495 }
496
497 return result;
498 }
499
500 public void removeTestStep( WsdlTestStep testStep )
501 {
502 int ix = testSteps.indexOf( testStep );
503 if( ix == -1 )
504 {
505 logger.error( "TestStep [" + testStep.getName() + "] passed to removeTestStep in testCase [" + getName()
506 + "] not found" );
507 return;
508 }
509
510 testSteps.remove( ix );
511
512 try
513 {
514 ( getTestSuite() ).fireTestStepRemoved( testStep, ix );
515 }
516 finally
517 {
518 testStep.release();
519
520 for( int c = 0; c < getConfig().sizeOfTestStepArray(); c++ )
521 {
522 if( testStep.getConfig() == getConfig().getTestStepArray( c ) )
523 {
524 getConfig().removeTestStep( c );
525 break;
526 }
527 }
528 }
529 }
530
531 public WsdlTestCaseRunner run( StringToObjectMap properties, boolean async )
532 {
533 WsdlTestCaseRunner runner = new WsdlTestCaseRunner( this, properties );
534 runner.start( async );
535 return runner;
536 }
537
538 public void addTestRunListener( TestRunListener listener )
539 {
540 if( listener == null )
541 throw new RuntimeException( "listener must not be null" );
542
543 testRunListeners.add( listener );
544 }
545
546 public void removeTestRunListener( TestRunListener listener )
547 {
548 testRunListeners.remove( listener );
549 }
550
551 public TestRunListener[] getTestRunListeners()
552 {
553 return testRunListeners.toArray( new TestRunListener[testRunListeners.size()] );
554 }
555
556 public Map<String, TestStep> getTestSteps()
557 {
558 Map<String, TestStep> result = new HashMap<String, TestStep>();
559 for( TestStep testStep : testSteps )
560 result.put( testStep.getName(), testStep );
561
562 return result;
563 }
564
565 public Map<String, LoadTest> getLoadTests()
566 {
567 Map<String, LoadTest> result = new HashMap<String, LoadTest>();
568 for( LoadTest loadTest : loadTests )
569 result.put( loadTest.getName(), loadTest );
570
571 return result;
572 }
573
574 public int getIndexOfTestStep( TestStep step )
575 {
576 return testSteps.indexOf( step );
577 }
578
579 /***
580 * Moves a step by the specified offset, a bit awkward since xmlbeans doesn't
581 * support reordering of arrays, we need to create copies of the contained
582 * XmlObjects
583 *
584 * @param ix
585 * @param offset
586 */
587
588 public void moveTestStep( int ix, int offset )
589 {
590 if( offset == 0 )
591 return;
592 WsdlTestStep step = testSteps.get( ix );
593
594 if( ix + offset >= testSteps.size() )
595 offset = testSteps.size() - ix - 1;
596
597 testSteps.remove( ix );
598 testSteps.add( ix + offset, step );
599
600 TestStepConfig[] configs = new TestStepConfig[testSteps.size()];
601
602 TestCaseConfig conf = getConfig();
603 for( int c = 0; c < testSteps.size(); c++ )
604 {
605 if( offset > 0 )
606 {
607 if( c < ix )
608 configs[c] = (TestStepConfig) conf.getTestStepArray( c ).copy();
609 else if( c < ( ix + offset ) )
610 configs[c] = (TestStepConfig) conf.getTestStepArray( c + 1 ).copy();
611 else if( c == ix + offset )
612 configs[c] = (TestStepConfig) conf.getTestStepArray( ix ).copy();
613 else
614 configs[c] = (TestStepConfig) conf.getTestStepArray( c ).copy();
615 }
616 else
617 {
618 if( c < ix + offset )
619 configs[c] = (TestStepConfig) conf.getTestStepArray( c ).copy();
620 else if( c == ix + offset )
621 configs[c] = (TestStepConfig) conf.getTestStepArray( ix ).copy();
622 else if( c <= ix )
623 configs[c] = (TestStepConfig) conf.getTestStepArray( c - 1 ).copy();
624 else
625 configs[c] = (TestStepConfig) conf.getTestStepArray( c ).copy();
626 }
627 }
628
629 conf.setTestStepArray( configs );
630 for( int c = 0; c < configs.length; c++ )
631 {
632 ( testSteps.get( c ) ).resetConfigOnMove( conf.getTestStepArray( c ) );
633 }
634
635 ( getTestSuite() ).fireTestStepMoved( step, ix, offset );
636 }
637
638 public int getIndexOfLoadTest( LoadTest loadTest )
639 {
640 return loadTests.indexOf( loadTest );
641 }
642
643 public int getTestStepIndexByName( String stepName )
644 {
645 for( int c = 0; c < testSteps.size(); c++ )
646 {
647 if( testSteps.get( c ).getName().equals( stepName ) )
648 return c;
649 }
650
651 return -1;
652 }
653
654 public TestStep findPreviousStepOfType( TestStep referenceStep, Class<? extends TestStep> stepClass )
655 {
656 int currentStepIndex = getIndexOfTestStep( referenceStep );
657 int ix = currentStepIndex - 1;
658 while( ix >= 0 && !getTestStepAt( ix ).getClass().equals( stepClass ) )
659 {
660 ix--;
661 }
662
663 return ix < 0 ? null : getTestStepAt( ix );
664 }
665
666 public TestStep findNextStepOfType( TestStep referenceStep, Class<? extends TestStep> stepClass )
667 {
668 int currentStepIndex = getIndexOfTestStep( referenceStep );
669 int ix = currentStepIndex + 1;
670 while( ix < getTestStepCount() && !getTestStepAt( ix ).getClass().equals( stepClass ) )
671 {
672 ix++;
673 }
674
675 return ix >= getTestStepCount() ? null : getTestStepAt( ix );
676 }
677
678 public List<TestStep> getTestStepList()
679 {
680 List<TestStep> result = new ArrayList<TestStep>();
681 for( TestStep step : testSteps )
682 result.add( step );
683
684 return result;
685 }
686
687 @SuppressWarnings( "unchecked" )
688 public <T extends TestStep> List<T> getTestStepsOfType( Class<T> stepType )
689 {
690 List<T> result = new ArrayList<T>();
691 for( TestStep step : testSteps )
692 if( step.getClass().isAssignableFrom( stepType ) )
693 result.add( (T) step );
694
695 return result;
696 }
697
698 public WsdlTestStep getTestStepByName( String stepName )
699 {
700 return (WsdlTestStep) getWsdlModelItemByName( testSteps, stepName );
701 }
702
703 public WsdlLoadTest cloneLoadTest( WsdlLoadTest loadTest, String name )
704 {
705 loadTest.beforeSave();
706
707 LoadTestConfig loadTestConfig = getConfig().addNewLoadTest();
708 loadTestConfig.set( loadTest.getConfig().copy() );
709
710 WsdlLoadTest newLoadTest = new WsdlLoadTest( this, loadTestConfig );
711 newLoadTest.setName( name );
712 loadTests.add( newLoadTest );
713
714 ( getTestSuite() ).fireLoadTestAdded( newLoadTest );
715
716 return newLoadTest;
717 }
718
719 @Override
720 public void release()
721 {
722 super.release();
723
724 for( WsdlTestStep testStep : testSteps )
725 testStep.release();
726
727 for( WsdlLoadTest loadTest : loadTests )
728 loadTest.release();
729
730 testRunListeners.clear();
731
732 if( setupScriptEngine != null )
733 setupScriptEngine.release();
734
735 if( tearDownScriptEngine != null )
736 tearDownScriptEngine.release();
737 }
738
739 public ActionList getCreateActions()
740 {
741 return createActions;
742 }
743
744 public void resetConfigOnMove( TestCaseConfig testCaseArray )
745 {
746 setConfig( testCaseArray );
747 int mod = 0;
748
749 List<TestStepConfig> configs = getConfig().getTestStepList();
750 for( int c = 0; c < configs.size(); c++ )
751 {
752 if( WsdlTestStepRegistry.getInstance().hasFactory( configs.get( c ) ) )
753 {
754 ( testSteps.get( c - mod ) ).resetConfigOnMove( configs.get( c ) );
755 }
756 else
757 mod++;
758 }
759
760 List<LoadTestConfig> loadTestConfigs = getConfig().getLoadTestList();
761 for( int c = 0; c < loadTestConfigs.size(); c++ )
762 {
763 loadTests.get( c ).resetConfigOnMove( loadTestConfigs.get( c ) );
764 }
765 }
766
767 public List<LoadTest> getLoadTestList()
768 {
769 List<LoadTest> result = new ArrayList<LoadTest>();
770 for( LoadTest loadTest : loadTests )
771 result.add( loadTest );
772
773 return result;
774 }
775
776 public Object runSetupScript( TestRunContext runContext, TestRunner runner ) throws Exception
777 {
778 String script = getSetupScript();
779 if( StringUtils.isNullOrEmpty( script ) )
780 return null;
781
782 if( setupScriptEngine == null )
783 {
784 setupScriptEngine = SoapUIScriptEngineRegistry.create( SoapUIScriptEngineRegistry.GROOVY_ID, this );
785 setupScriptEngine.setScript( script );
786 }
787
788 setupScriptEngine.setVariable( "context", runContext );
789 setupScriptEngine.setVariable( "testRunner", runner );
790 setupScriptEngine.setVariable( "log", SoapUI.ensureGroovyLog() );
791 return setupScriptEngine.run();
792 }
793
794 public Object runTearDownScript( TestRunContext runContext, TestRunner runner ) throws Exception
795 {
796 String script = getTearDownScript();
797 if( StringUtils.isNullOrEmpty( script ) )
798 return null;
799
800 if( tearDownScriptEngine == null )
801 {
802 tearDownScriptEngine = SoapUIScriptEngineRegistry.create( SoapUIScriptEngineRegistry.GROOVY_ID, this );
803 tearDownScriptEngine.setScript( script );
804 }
805
806 tearDownScriptEngine.setVariable( "context", runContext );
807 tearDownScriptEngine.setVariable( "testRunner", runner );
808 tearDownScriptEngine.setVariable( "log", SoapUI.ensureGroovyLog() );
809 return tearDownScriptEngine.run();
810 }
811
812 public List<? extends ModelItem> getChildren()
813 {
814 List<ModelItem> result = new ArrayList<ModelItem>();
815 result.addAll( getTestStepList() );
816 result.addAll( getLoadTestList() );
817 return result;
818 }
819
820 @Override
821 public void setName( String name )
822 {
823 String oldLabel = getLabel();
824
825 super.setName( name );
826
827 String label = getLabel();
828 if( oldLabel != null && !oldLabel.equals( label ) )
829 {
830 notifyPropertyChanged( LABEL_PROPERTY, oldLabel, label );
831 }
832 }
833
834 public String getLabel()
835 {
836 String name = getName();
837 if( isDisabled() )
838 return name + " (disabled)";
839 else
840 return name;
841 }
842
843 public boolean isDisabled()
844 {
845 return getConfig().getDisabled();
846 }
847
848 public void setDisabled( boolean disabled )
849 {
850 String oldLabel = getLabel();
851
852 boolean oldDisabled = isDisabled();
853 if( oldDisabled == disabled )
854 return;
855
856 if( disabled )
857 getConfig().setDisabled( disabled );
858 else if( getConfig().isSetDisabled() )
859 getConfig().unsetDisabled();
860
861 notifyPropertyChanged( DISABLED_PROPERTY, oldDisabled, disabled );
862
863 String label = getLabel();
864 if( !oldLabel.equals( label ) )
865 notifyPropertyChanged( LABEL_PROPERTY, oldLabel, label );
866 }
867
868 public long getTimeout()
869 {
870 return getConfig().getTimeout();
871 }
872
873 public void setTimeout( long timeout )
874 {
875 long old = getTimeout();
876 getConfig().setTimeout( timeout );
877 notifyPropertyChanged( TIMEOUT_PROPERTY, old, timeout );
878 }
879
880 public void exportTestCase( File file )
881 {
882 try
883 {
884 this.getConfig().newCursor().save( file );
885 }
886 catch( IOException e )
887 {
888 e.printStackTrace();
889 }
890
891 }
892 }