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.propertyexpansion.PropertyExpansionUtils;
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.TestRunContext;
22 import com.eviware.soapui.model.testsuite.TestRunner;
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 implements TestRunContext
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 }
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 Object result = getProperty( key.toString() );
69
70 if( result == null )
71 {
72 result = super.get( key );
73 }
74
75 return result;
76 }
77
78 @Override
79 public Object put( String key, Object value )
80 {
81 Object oldValue = get( key );
82 setProperty( key, value );
83 return oldValue;
84 }
85
86 public Object getProperty(String name)
87 {
88 return getProperty( name, testStep, testStep == null ? null : (WsdlTestCase) testStep.getTestCase() );
89 }
90
91 public Object getProperty(String testStepName, String propertyName)
92 {
93 TestStep ts = testStep == null ? null : testStep.getTestCase().getTestStepByName( testStepName );
94 return ts == null ? null : ts.getPropertyValue( propertyName );
95 }
96
97 public TestCase getTestCase()
98 {
99 return testStep == null ? null : testStep.getTestCase();
100 }
101
102 public Settings getSettings()
103 {
104 return testStep == null ? null : testStep.getSettings();
105 }
106
107 public String expand( String content )
108 {
109 return PropertyExpansionUtils.expandProperties( this, content );
110 }
111 }