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.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.support.AbstractSubmitContext;
    18  import com.eviware.soapui.model.testsuite.TestCase;
    19  import com.eviware.soapui.model.testsuite.TestRunContext;
    20  import com.eviware.soapui.model.testsuite.TestRunner;
    21  import com.eviware.soapui.model.testsuite.TestStep;
    22
    23  /***
    24   * Dummy TestRunContext used when executing TestSteps one by one
    25   *
    26   * @author ole.matzura
    27   */
    28
    29  public class MockTestRunContext extends AbstractSubmitContext implements TestRunContext
    30  {
    31  	private final MockTestRunner mockTestRunner;
    32  	private final WsdlTestStep testStep;
    33
    34  	public MockTestRunContext(MockTestRunner mockTestRunner, WsdlTestStep testStep )
    35  	{
    36  		this.mockTestRunner = mockTestRunner;
    37  		this.testStep = testStep;
    38  		setProperty( "log", mockTestRunner.getLog() );
    39  	}
    40
    41  	public TestStep getCurrentStep()
    42  	{
    43  		return testStep;
    44  	}
    45
    46  	@Override
    47  	public void setProperty( String name, Object value )
    48  	{
    49  		super.setProperty( name, value, getTestCase() );
    50  	}
    51
    52  	public int getCurrentStepIndex()
    53  	{
    54  		return testStep == null ? -1 : testStep.getTestCase().getIndexOfTestStep( testStep );
    55  	}
    56
    57  	public TestRunner getTestRunner()
    58  	{
    59  		return mockTestRunner;
    60  	}
    61
    62  	@Override
    63  	public Object get( Object key )
    64  	{
    65  		return getProperty( key.toString() );
    66  	}
    67
    68  	@Override
    69  	public Object put( String key, Object value )
    70  	{
    71  		Object oldValue = get( key );
    72  		setProperty( key, value );
    73  		return oldValue;
    74  	}
    75
    76  	public Object getProperty(String name)
    77  	{
    78  		return getProperty( name, testStep, testStep == null ? null : (WsdlTestCase) testStep.getTestCase() );
    79  	}
    80
    81  	public Object getProperty(String testStepName, String propertyName)
    82  	{
    83  		TestStep ts = testStep == null ? null : testStep.getTestCase().getTestStepByName( testStepName );
    84  		return ts == null ? null : ts.getPropertyValue( propertyName );
    85  	}
    86
    87  	public TestCase getTestCase()
    88  	{
    89  		return testStep == null ? null : testStep.getTestCase();
    90  	}
    91  }