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.teststeps.actions;
14  
15  import java.awt.event.ActionEvent;
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  import javax.swing.AbstractAction;
20  import javax.swing.Action;
21  
22  import com.eviware.soapui.SoapUI;
23  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
24  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
25  import com.eviware.soapui.model.project.Project;
26  import com.eviware.soapui.model.testsuite.TestSuite;
27  import com.eviware.soapui.support.UISupport;
28  
29  /***
30   * Clones a WsdlTestStep
31   * 
32   * @author Ole.Matzura
33   */
34  
35  public class CloneTestStepAction extends AbstractAction
36  {
37     private final WsdlTestStep testStep;
38  	private final String typeName;
39  
40  	public CloneTestStepAction( WsdlTestStep testStep, String typeName )
41     {
42        super( "Clone" );
43  		this.testStep = testStep;
44  		this.typeName = typeName;
45        putValue( Action.SHORT_DESCRIPTION, "Creates a copy of this " + typeName );
46        putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/clone_request.gif"));
47        putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "F9" ));
48     }
49     
50     public void actionPerformed(ActionEvent e)
51  	{
52        WsdlTestCase testCase = (WsdlTestCase) testStep.getTestCase();
53        Project project = testCase.getTestSuite().getProject();
54  
55        List<WsdlTestCase> testCases = new ArrayList<WsdlTestCase>();
56        List<String> options = new ArrayList<String>();
57        
58        for( int c = 0; c < project.getTestSuiteCount(); c++ )
59        {
60        	TestSuite testSuite = project.getTestSuiteAt(c );
61        	for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
62        	{
63        		testCase = (WsdlTestCase) testSuite.getTestCaseAt( i );
64        		testCases.add( testCase );
65        		options.add( testSuite.getName() + " : " + testCase.getName() );
66        	}
67        }
68  
69        if( options.size() > 1 )
70        {
71           String testCaseName = (String) UISupport.prompt( "Select TestCase to clone to", "Clone " + typeName, options.toArray(),
72           		testStep.getTestCase().getTestSuite().getName() + " : " + testStep.getTestCase().getName());
73           if( testCaseName == null )
74           	return;
75           
76           testCase = testCases.get( options.indexOf( testCaseName ));
77        }
78        
79        if( SoapUI.getTestMonitor().hasRunningTest( testCase ))
80        {
81        	UISupport.showErrorMessage( "Cannot clone to running TestCase" );
82        	return;
83        }
84        
85        String name = UISupport.prompt( "Specify name of cloned " + typeName, "Clone " + typeName,
86        		"Copy of " + testStep.getName() );
87        if( name == null ) return;
88        
89        WsdlTestStep newStep = (WsdlTestStep) testCase.cloneStep( testStep, name );
90        
91        UISupport.selectAndShow( newStep );
92     }
93  
94  }