View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 eviware.com
    3    *
    4    *  soapUI is free software; you can redistribute it and/or modify it under the
    5    *  terms of version 2.1 of the GNU Lesser General Public License as published by
    6    *  the Free Software Foundation.
    7    *
    8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
    9    *  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 TestRunContext
    29  {
    30  	private final TestRunner testRunner;
    31  	private int currentStepIndex;
    32  	private TestCase testCase;
    33
    34  	public WsdlTestRunContext( TestRunner testRunner, PropertiesMap properties )
    35  	{
    36  		super( properties );
    37  		this.testRunner = testRunner;
    38  	}
    39
    40  	public WsdlTestRunContext( TestStep testStep )
    41  	{
    42  		this( null, null );
    43
    44  		testCase = testStep.getTestCase();
    45  		currentStepIndex = testCase.getIndexOfTestStep( testStep );
    46  	}
    47
    48  	public TestStep getCurrentStep()
    49  	{
    50  		if( currentStepIndex < 0 || currentStepIndex >= getTestCase().getTestStepCount() )
    51  			return null;
    52
    53  		return getTestCase().getTestStepAt( currentStepIndex );
    54  	}
    55
    56  	@Override
    57  	public void setProperty( String name, Object value )
    58  	{
    59  		super.setProperty( name, value, getTestCase() );
    60  	}
    61
    62  	public int getCurrentStepIndex()
    63  	{
    64  		return currentStepIndex;
    65  	}
    66
    67  	public void setCurrentStep( int index )
    68  	{
    69  		currentStepIndex = index;
    70  	}
    71
    72  	public TestRunner getTestRunner()
    73  	{
    74  		return testRunner;
    75  	}
    76
    77  	public Object getProperty(String testStepName, String propertyName)
    78  	{
    79  		TestStep testStep = getTestCase().getTestStepByName( testStepName );
    80  		return testStep == null ? null : testStep.getPropertyValue( propertyName );
    81  	}
    82
    83  	public TestCase getTestCase()
    84  	{
    85  		return testRunner == null ? testCase : testRunner.getTestCase();
    86  	}
    87
    88  	public Object getProperty(String name)
    89  	{
    90  		WsdlTestCase testCase = (WsdlTestCase) getTestCase();
    91  		TestStep testStep = currentStepIndex >= 0 && currentStepIndex < testCase.getTestStepCount() ?
    92  				testCase.getTestStepAt( currentStepIndex ) : null;
    93
    94  		return getProperty( name, testStep, testCase);
    95  	}
    96
    97  	public void reset()
    98  	{
    99  		resetProperties();
    100 		currentStepIndex = 0;
    101 	}
    102 }