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.model.TestModelItem;
17 import com.eviware.soapui.model.propertyexpansion.PropertyExpander;
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 import com.eviware.soapui.support.types.StringToObjectMap;
25
26 /***
27 * TestRunContext for WsdlTestCase runners
28 *
29 * @author Ole.Matzura
30 */
31
32 public class WsdlTestRunContext extends AbstractSubmitContext<TestModelItem> implements TestCaseRunContext
33 {
34 private final TestCaseRunner testRunner;
35 private int currentStepIndex;
36 private TestCase testCase;
37
38 public WsdlTestRunContext( TestCaseRunner testRunner, StringToObjectMap properties )
39 {
40 super( testRunner.getTestCase(), properties );
41 this.testRunner = testRunner;
42 }
43
44 public WsdlTestRunContext( TestStep testStep )
45 {
46 super( testStep );
47
48 testRunner = null;
49 testCase = testStep.getTestCase();
50 currentStepIndex = testCase.getIndexOfTestStep( testStep );
51 }
52
53 public TestStep getCurrentStep()
54 {
55 if( currentStepIndex < 0 || currentStepIndex >= getTestCase().getTestStepCount() )
56 return null;
57
58 return getTestCase().getTestStepAt( currentStepIndex );
59 }
60
61 @Override
62 public void setProperty( String name, Object value )
63 {
64 super.setProperty( name, value, getTestCase() );
65 }
66
67 public int getCurrentStepIndex()
68 {
69 return currentStepIndex;
70 }
71
72 public void setCurrentStep( int index )
73 {
74 currentStepIndex = index;
75 }
76
77 public TestCaseRunner getTestRunner()
78 {
79 return testRunner;
80 }
81
82 public Object getProperty( String testStepName, String propertyName )
83 {
84 TestStep testStep = getTestCase().getTestStepByName( testStepName );
85 return testStep == null ? null : testStep.getPropertyValue( propertyName );
86 }
87
88 public TestCase getTestCase()
89 {
90 return testRunner == null ? testCase : testRunner.getTestCase();
91 }
92
93 @Override
94 public Object get( Object key )
95 {
96 if( "currentStep".equals( key ) )
97 return getCurrentStep();
98
99 if( "currentStepIndex".equals( key ) )
100 return getCurrentStepIndex();
101
102 if( "settings".equals( key ) )
103 return getSettings();
104
105 if( "testCase".equals( key ) )
106 return getTestCase();
107
108 if( "testRunner".equals( key ) )
109 return getTestRunner();
110
111 Object result = getProperty( key.toString() );
112
113 if( result == null )
114 {
115 result = super.get( key );
116 }
117
118 return result;
119 }
120
121 @Override
122 public Object put( String key, Object value )
123 {
124 Object oldValue = get( key );
125 setProperty( key, value );
126 return oldValue;
127 }
128
129 public Object getProperty( String name )
130 {
131 WsdlTestCase testCase = ( WsdlTestCase )getTestCase();
132 TestStep testStep = currentStepIndex >= 0 && currentStepIndex < testCase.getTestStepCount() ? testCase
133 .getTestStepAt( currentStepIndex ) : null;
134
135 return getProperty( name, testStep, testCase );
136 }
137
138 public void reset()
139 {
140 resetProperties();
141 currentStepIndex = 0;
142 }
143
144 public String expand( String content )
145 {
146 return PropertyExpander.expandProperties( this, content );
147 }
148
149 public Settings getSettings()
150 {
151 return testCase == null ? SoapUI.getSettings() : testCase.getSettings();
152 }
153 }