01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: * See the GNU Lesser General Public License for more details at gnu.org.
11: */
12:
13: package com.eviware.soapui.impl.wsdl.testcase;
14:
15: import com.eviware.soapui.model.support.AbstractSubmitContext;
16: import com.eviware.soapui.model.support.PropertiesMap;
17: import com.eviware.soapui.model.testsuite.TestCase;
18: import com.eviware.soapui.model.testsuite.TestRunContext;
19: import com.eviware.soapui.model.testsuite.TestRunner;
20: import com.eviware.soapui.model.testsuite.TestStep;
21:
22: /**
23: * TestRunContext for WsdlTestCase runners
24: *
25: * @author Ole.Matzura
26: */
27:
28: public class WsdlTestRunContext extends AbstractSubmitContext implements
29: TestRunContext {
30: private final TestRunner testRunner;
31: private int currentStepIndex;
32: private TestCase testCase;
33:
34: public WsdlTestRunContext(TestRunner testRunner,
35: PropertiesMap properties) {
36: super (properties);
37: this .testRunner = testRunner;
38: }
39:
40: public WsdlTestRunContext(TestStep testStep) {
41: this (null, null);
42:
43: testCase = testStep.getTestCase();
44: currentStepIndex = testCase.getIndexOfTestStep(testStep);
45: }
46:
47: public TestStep getCurrentStep() {
48: if (currentStepIndex < 0
49: || currentStepIndex >= getTestCase().getTestStepCount())
50: return null;
51:
52: return getTestCase().getTestStepAt(currentStepIndex);
53: }
54:
55: @Override
56: public void setProperty(String name, Object value) {
57: super .setProperty(name, value, getTestCase());
58: }
59:
60: public int getCurrentStepIndex() {
61: return currentStepIndex;
62: }
63:
64: public void setCurrentStep(int index) {
65: currentStepIndex = index;
66: }
67:
68: public TestRunner getTestRunner() {
69: return testRunner;
70: }
71:
72: public Object getProperty(String testStepName, String propertyName) {
73: TestStep testStep = getTestCase().getTestStepByName(
74: testStepName);
75: return testStep == null ? null : testStep
76: .getPropertyValue(propertyName);
77: }
78:
79: public TestCase getTestCase() {
80: return testRunner == null ? testCase : testRunner.getTestCase();
81: }
82:
83: public Object getProperty(String name) {
84: WsdlTestCase testCase = (WsdlTestCase) getTestCase();
85: TestStep testStep = currentStepIndex >= 0
86: && currentStepIndex < testCase.getTestStepCount() ? testCase
87: .getTestStepAt(currentStepIndex)
88: : null;
89:
90: return getProperty(name, testStep, testCase);
91: }
92:
93: public void reset() {
94: resetProperties();
95: currentStepIndex = 0;
96: }
97: }
|