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 org.apache.xmlbeans.XmlException;
    18  import org.apache.xmlbeans.XmlObject;
    19  import org.w3c.dom.Node;
    20
    21  import com.eviware.soapui.impl.wsdl.WsdlProject;
    22  import com.eviware.soapui.impl.wsdl.submit.filters.PropertyExpansionRequestFilter;
    23  import com.eviware.soapui.model.testsuite.TestRunContext;
    24  import com.eviware.soapui.model.testsuite.TestStep;
    25
    26  public final class GroovyUtils
    27  {
    28  	private final TestRunContext context;
    29
    30  	public GroovyUtils( TestRunContext context )
    31  	{
    32  		this.context = context;
    33  	}
    34
    35  	public String getProjectPath()
    36  	{
    37  		WsdlProject project = ( WsdlProject ) context.getTestCase().getTestSuite().getProject();
    38  		String path = project.getPath();
    39  		int ix = path.lastIndexOf( File.separatorChar );
    40  		return ix == -1 ? path : path.substring( 0, ix );
    41  	}
    42
    43  	public XmlHolder getXmlHolder( String xmlPropertyOrString ) throws Exception
    44  	{
    45  		Object property = context.getProperty( xmlPropertyOrString );
    46  		if( property != null )
    47  			return new XmlHolder( context, xmlPropertyOrString );
    48  		else
    49  			return new XmlHolder( xmlPropertyOrString );
    50  	}
    51
    52  	public String expand( String property )
    53  	{
    54  		return PropertyExpansionRequestFilter.expandProperties( context, property );
    55  	}
    56
    57  	public void setPropertyValue( String testStep, String property, String value ) throws Exception
    58  	{
    59  		TestStep step = context.getTestCase().getTestStepByName( testStep );
    60  		if( step != null )
    61  		{
    62  			step.setPropertyValue( property, value );
    63  		}
    64  		else
    65  		{
    66  			throw new Exception( "Missing TestStep [" + testStep + "] in TestCase" );
    67  		}
    68  	}
    69
    70  	public String getXml( Node node ) throws XmlException
    71  	{
    72  		return XmlObject.Factory.parse( node ).xmlText();
    73  	}
    74  }