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  	@Override
    89  	public Object get( Object key )
    90  	{
    91  		return getProperty( key.toString() );
    92  	}
    93
    94  	@Override
    95  	public Object put( String key, Object value )
    96  	{
    97  		Object oldValue = get( key );
    98  		setProperty( key, value );
    99  		return oldValue;
    100 	}
    101
    102 	public Object getProperty(String name)
    103 	{
    104 		WsdlTestCase testCase = (WsdlTestCase) getTestCase();
    105 		TestStep testStep = currentStepIndex >= 0 && currentStepIndex < testCase.getTestStepCount() ?
    106 				testCase.getTestStepAt( currentStepIndex ) : null;
    107
    108 		return getProperty( name, testStep, testCase);
    109 	}
    110
    111 	public void reset()
    112 	{
    113 		resetProperties();
    114 		currentStepIndex = 0;
    115 	}
    116 }