1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.support;
14
15 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
16 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
17 import com.eviware.soapui.model.ModelItem;
18 import com.eviware.soapui.model.settings.Settings;
19 import com.eviware.soapui.model.support.AbstractSubmitContext;
20 import com.eviware.soapui.model.testsuite.TestCase;
21 import com.eviware.soapui.model.testsuite.TestCaseRunContext;
22 import com.eviware.soapui.model.testsuite.TestCaseRunner;
23 import com.eviware.soapui.model.testsuite.TestStep;
24
25 /***
26 * Dummy TestRunContext used when executing TestSteps one by one
27 *
28 * @author ole.matzura
29 */
30
31 public class MockTestRunContext extends AbstractSubmitContext<ModelItem> implements TestCaseRunContext
32 {
33 private final MockTestRunner mockTestRunner;
34 private final WsdlTestStep testStep;
35
36 public MockTestRunContext( MockTestRunner mockTestRunner, WsdlTestStep testStep )
37 {
38 super( testStep == null ? mockTestRunner.getTestCase() : testStep );
39 this.mockTestRunner = mockTestRunner;
40 this.testStep = testStep;
41 setProperty( "log", mockTestRunner.getLog() );
42 mockTestRunner.setMockRunContext( this );
43 }
44
45 public TestStep getCurrentStep()
46 {
47 return testStep;
48 }
49
50 @Override
51 public void setProperty( String name, Object value )
52 {
53 super.setProperty( name, value, getTestCase() );
54 }
55
56 public int getCurrentStepIndex()
57 {
58 return testStep == null ? -1 : testStep.getTestCase().getIndexOfTestStep( testStep );
59 }
60
61 public TestCaseRunner getTestRunner()
62 {
63 return mockTestRunner;
64 }
65
66 @Override
67 public Object get( Object key )
68 {
69 if( "currentStep".equals( key ) )
70 return getCurrentStep();
71
72 if( "currentStepIndex".equals( key ) )
73 return getCurrentStepIndex();
74
75 if( "settings".equals( key ) )
76 return getSettings();
77
78 if( "testCase".equals( key ) )
79 return getTestCase();
80
81 if( "testRunner".equals( key ) )
82 return getTestRunner();
83
84 Object result = getProperty( key.toString() );
85
86 if( result == null )
87 {
88 result = super.get( key );
89 }
90
91 return result;
92 }
93
94 @Override
95 public Object put( String key, Object value )
96 {
97 Object oldValue = get( key );
98 setProperty( key, value );
99 return oldValue;
100 }
101
102 public Object getProperty( String name )
103 {
104 return getProperty( name, testStep, testStep == null ? null : ( WsdlTestCase )testStep.getTestCase() );
105 }
106
107 public Object getProperty( String testStepName, String propertyName )
108 {
109 TestStep ts = testStep == null ? null : testStep.getTestCase().getTestStepByName( testStepName );
110 return ts == null ? null : ts.getPropertyValue( propertyName );
111 }
112
113 public TestCase getTestCase()
114 {
115 return testStep == null ? null : testStep.getTestCase();
116 }
117
118 public Settings getSettings()
119 {
120 return testStep == null ? null : testStep.getSettings();
121 }
122 }