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