View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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.testcase;
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.WsdlTestSuite;
24  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
25  import com.eviware.soapui.model.project.Project;
26  import com.eviware.soapui.support.UISupport;
27  
28  /***
29   * Clones a WsdlTestCase
30   * 
31   * @author Ole.Matzura
32   */
33  
34  public class CloneTestCaseAction extends AbstractAction
35  {
36  	private final WsdlTestCase testCase;
37  
38  	public CloneTestCaseAction( WsdlTestCase testCase ) 
39     {
40        super( "Clone TestCase" );
41  		this.testCase = testCase;
42        putValue( Action.SHORT_DESCRIPTION, "Clones this TestCase" );
43        putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "F9" ));
44     }
45     
46     public void actionPerformed(ActionEvent e)
47  	{
48        String name = UISupport.prompt( "Specify name of cloned TestCase", "Clone TestCase", "Copy of " + testCase.getName() );
49        if( name == null ) return;
50        
51        Project project = testCase.getTestSuite().getProject();
52        if( project.getTestSuiteCount() > 1 )
53        {
54        	// ask which testsuite to clone to
55        	List<String> names = new ArrayList<String>();
56        	for( int c = 0; c < project.getTestSuiteCount(); c++ )
57        	{
58        		names.add( project.getTestSuiteAt( c ).getName() );
59        	}
60        	
61        	String testSuite = (String) UISupport.prompt( "Select target TestSuite", "Clone TestCase", names.toArray(), 
62        			testCase.getTestSuite().getName() );
63        	
64        	if( testSuite == null )
65        		return;
66        	
67        	WsdlTestSuite targetSuite = (WsdlTestSuite) project.getTestSuiteAt( names.indexOf( testSuite ));
68  		   WsdlTestCase newTestCase = targetSuite.cloneTestCase( testCase, name );
69  		   SoapUI.selectModelItem( newTestCase );
70        }
71        else
72        {
73  		   WsdlTestCase newTestCase = ((WsdlTestSuite)testCase.getTestSuite()).cloneTestCase( testCase, name );
74  		   SoapUI.selectModelItem( newTestCase );
75        }
76     }
77  }