View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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  package com.eviware.soapui.impl.wsdl.actions.testcase;
13  
14  import java.io.IOException;
15  
16  import com.eviware.soapui.impl.wsdl.actions.project.StartLoadUI;
17  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
18  import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
19  import com.eviware.soapui.integration.loadui.IntegrationUtils;
20  import com.eviware.soapui.model.support.ModelSupport;
21  import com.eviware.soapui.support.StringUtils;
22  import com.eviware.soapui.support.UISupport;
23  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
24  import com.eviware.x.form.XFormDialog;
25  import com.eviware.x.form.support.ADialogBuilder;
26  import com.eviware.x.form.support.AField;
27  import com.eviware.x.form.support.AForm;
28  import com.eviware.x.form.support.XFormMultiSelectList;
29  import com.eviware.x.form.support.AField.AFieldType;
30  
31  public class ConvertTestCaseLoadTestsToLoadUIAction extends AbstractSoapUIAction<WsdlTestCase>
32  {
33  
34  	public static final String SOAPUI_ACTION_ID = "ConvertTestCaseLoadTestsToLoadUIAction";
35  
36  	public ConvertTestCaseLoadTestsToLoadUIAction()
37  	{
38  		super( "Convert LoadTests to loadUI TestCases", "Select Containing LoadTest to Convert to loadUI TestCases" );
39  	}
40  
41  	@Override
42  	public void perform( WsdlTestCase testCase, Object param )
43  	{
44  		if( !StartLoadUI.testCajoConnection() )
45  		{
46  			if( UISupport.confirm( StartLoadUI.LOADUI_LAUNCH_QUESTION, StartLoadUI.LOADUI_LAUNCH_TITLE ) )
47  			{
48  				StartLoadUI.launchLoadUI();
49  			}
50  			return;
51  		}
52  		XFormDialog dialog = ADialogBuilder.buildDialog( TestCaseForm.class );
53  
54  		dialog.setOptions( TestCaseForm.LOADUIPROJECT, IntegrationUtils.getAvailableProjects() );
55  		if( !StringUtils.isNullOrEmpty( IntegrationUtils.getOpenedProjectName() ) )
56  		{
57  			dialog.setValue( TestCaseForm.LOADUIPROJECT, IntegrationUtils.getOpenedProjectName() );
58  		}
59  		else
60  		{
61  			dialog.setValue( TestCaseForm.LOADUIPROJECT, IntegrationUtils.CREATE_NEW_OPTION );
62  		}
63  		dialog.setOptions( TestCaseForm.LOADTESTS, ModelSupport.getNames( testCase.getLoadTestList() ) );
64  		if( dialog.show() )
65  		{
66  			if( dialog.getReturnValue() == XFormDialog.OK_OPTION )
67  			{
68  				String loadUIProject = dialog.getValue( TestCaseForm.LOADUIPROJECT );
69  				String openedProjectName = IntegrationUtils.getOpenedProjectName();
70  				if( !StringUtils.isNullOrEmpty( openedProjectName ) && !loadUIProject.equals( openedProjectName ) )
71  				{
72  					if( UISupport.confirm( "Close currently open [" + IntegrationUtils.getOpenedProjectName()
73  							+ "] loadUI project", "Close loadUI project" ) )
74  					{
75  						IntegrationUtils.closeOpenedLoadUIProject();
76  					}
77  					else
78  					{
79  						return;
80  					}
81  				}
82  				String[] soapuiLoadTests = StringUtils.toStringArray( ( ( XFormMultiSelectList )dialog
83  						.getFormField( TestCaseForm.LOADTESTS ) ).getSelectedOptions() );
84  				if( soapuiLoadTests.length == 0 )
85  				{
86  					UISupport.showErrorMessage( "No LoadTests selected." );
87  					return;
88  				}
89  				try
90  				{
91  					IntegrationUtils.exportMultipleLoadTestToLoadUI( testCase, soapuiLoadTests, loadUIProject );
92  				}
93  				catch( IOException e )
94  				{
95  					UISupport.showInfoMessage( "Error while opening selected loadUI project" );
96  					return;
97  				}
98  			}
99  		}
100 
101 	}
102 
103 	@AForm( description = "Specify target loadUI Project and select LoadTests to convert", name = "Convert multiple LoadTests to loadUI", helpUrl = HelpUrls.CLONETESTSUITE_HELP_URL, icon = UISupport.CONVERT_TO_LOADUI_ICON_PATH )
104 	public interface TestCaseForm
105 	{
106 		@AField( name = "Target Project", description = "The target loadUI Project to add to", type = AFieldType.ENUMERATION )
107 		public final static String LOADUIPROJECT = "Target Project";
108 
109 		@AField( name = "Source LoadTests", description = "The LoadTests to convert", type = AFieldType.MULTILIST )
110 		public final static String LOADTESTS = "Source LoadTests";
111 
112 	}
113 
114 }