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