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.actions.iface;
    14
    15  import com.eviware.soapui.SoapUI;
    16  import com.eviware.soapui.impl.wsdl.WsdlInterface;
    17  import com.eviware.soapui.impl.wsdl.WsdlProject;
    18  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
    19  import com.eviware.soapui.model.testsuite.TestCase;
    20  import com.eviware.soapui.model.testsuite.TestSuite;
    21  import com.eviware.soapui.support.UISupport;
    22  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
    23
    24  /***
    25   * Removes a WsdlInterface from a WsdlProject
    26   *
    27   * @author Ole.Matzura
    28   */
    29
    30  public class RemoveInterfaceAction extends AbstractSoapUIAction<WsdlInterface>
    31  {
    32  	public RemoveInterfaceAction()
    33     {
    34        super( "Remove", "Removes this interface from the project" );
    35     }
    36
    37     public void perform( WsdlInterface iface, Object param )
    38  	{
    39     	if( hasRunningDependingTests( iface ) )
    40     	{
    41     		UISupport.showErrorMessage( "Cannot remove Interface due to running depending tests" );
    42     		return;
    43     	}
    44
    45        if( UISupport.confirm( "Remove interface [" + iface.getName() + "] from project [" +
    46              iface.getProject().getName() + "]?", "Remove Interface" ))
    47        {
    48        	if( hasDependingTests( iface ) )
    49        	{
    50        		if( !UISupport.confirm( "Interface has depending Test Steps which will also be removed. Remove anyway?", "Remove Interface" ))
    51        			return;
    52        	}
    53
    54        	WsdlProject project = (WsdlProject) iface.getProject();
    55           project.removeInterface( iface);
    56        }
    57     }
    58
    59  	public static boolean hasRunningDependingTests( WsdlInterface iface )
    60  	{
    61  		if( SoapUI.getTestMonitor() == null )
    62  			return false;
    63
    64  		for( int c = 0; c < iface.getProject().getTestSuiteCount(); c++ )
    65  		{
    66  			TestSuite testSuite = iface.getProject().getTestSuiteAt( c );
    67  			for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
    68  			{
    69  				TestCase testCase = testSuite.getTestCaseAt( i );
    70  				if( !SoapUI.getTestMonitor().hasRunningTest( testCase ))
    71  					continue;
    72
    73  				for( int j = 0; j < testCase.getTestStepCount(); j++ )
    74  				{
    75  					WsdlTestStep testStep = (WsdlTestStep) testCase.getTestStepAt( j );
    76  					if( testStep.dependsOn( iface ))
    77  					{
    78  						return true;
    79  					}
    80  				}
    81  			}
    82  		}
    83
    84  		return false;
    85  	}
    86
    87  	public static boolean hasDependingTests( WsdlInterface iface )
    88  	{
    89  		for( int c = 0; c < iface.getProject().getTestSuiteCount(); c++ )
    90  		{
    91  			TestSuite testSuite = iface.getProject().getTestSuiteAt( c );
    92  			for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
    93  			{
    94  				TestCase testCase = testSuite.getTestCaseAt( i );
    95
    96  				for( int j = 0; j < testCase.getTestStepCount(); j++ )
    97  				{
    98  					WsdlTestStep testStep = (WsdlTestStep) testCase.getTestStepAt( j );
    99  					if( testStep.dependsOn( iface ))
    100 					{
    101 						return true;
    102 					}
    103 				}
    104 			}
    105 		}
    106
    107 		return false;
    108 	}
    109 }