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.support;
    14
    15  import java.io.File;
    16
    17  import com.eviware.soapui.impl.wsdl.WsdlProject;
    18  import com.eviware.soapui.model.testsuite.TestRunContext;
    19  import com.eviware.soapui.model.testsuite.TestStep;
    20
    21  public final class GroovyUtils
    22  {
    23  	private final TestRunContext context;
    24
    25  	public GroovyUtils( TestRunContext context )
    26  	{
    27  		this.context = context;
    28  	}
    29
    30  	public String getProjectPath()
    31  	{
    32  		WsdlProject project = ( WsdlProject ) context.getTestCase().getTestSuite().getProject();
    33  		String path = project.getPath();
    34  		int ix = path.lastIndexOf( File.separatorChar );
    35  		return ix == -1 ? path : path.substring( 0, ix );
    36  	}
    37
    38  	public XmlHolder getXmlHolder( String xmlPropertyOrString ) throws Exception
    39  	{
    40  		Object property = context.getProperty( xmlPropertyOrString );
    41  		if( property != null )
    42  			return new XmlHolder( context, xmlPropertyOrString );
    43  		else
    44  			return new XmlHolder( xmlPropertyOrString );
    45  	}
    46
    47  	public void setPropertyValue( String testStep, String property, String value ) throws Exception
    48  	{
    49  		TestStep step = context.getTestCase().getTestStepByName( testStep );
    50  		if( step != null )
    51  		{
    52  			step.setPropertyValue( property, value );
    53  		}
    54  		else
    55  		{
    56  			throw new Exception( "Missing TestStep [" + testStep + "] in TestCase" );
    57  		}
    58  	}
    59  }