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.testsuite;
13  
14  import java.io.IOException;
15  
16  import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
17  import com.eviware.soapui.impl.wsdl.actions.project.StartLoadUI;
18  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
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 GenerateLoadUITestsAction extends AbstractSoapUIAction<WsdlTestSuite>
32  {
33  
34  	public static final String SOAPUI_ACTION_ID = "GenerateLoadUITestsAction";
35  	private WsdlTestSuite testSuite;
36  
37  	public GenerateLoadUITestsAction()
38  	{
39  		super( "Generate loadUI Tests", "Select contained TestCases to run with loadUI" );
40  	}
41  
42  	public void perform( WsdlTestSuite testSuite, 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  		this.testSuite = testSuite;
53  		final String soapUITestSuite = testSuite.getName();
54  		final String soapUIProjectPath = testSuite.getProject().getPath();
55  
56  		XFormDialog dialog = ADialogBuilder.buildDialog( Form.class );
57  
58  		dialog.setOptions( Form.LOADUIPROJECT, IntegrationUtils.getAvailableProjects() );
59  		if( !StringUtils.isNullOrEmpty( IntegrationUtils.getOpenedProjectName() ) )
60  		{
61  			dialog.setValue( Form.LOADUIPROJECT, IntegrationUtils.getOpenedProjectName() );
62  		}
63  		else
64  		{
65  			dialog.setValue( Form.LOADUIPROJECT, IntegrationUtils.CREATE_NEW_OPTION );
66  		}
67  		dialog.setOptions( Form.TESTCASES, ModelSupport.getNames( testSuite.getTestCaseList() ) );
68  		dialog.setValue( Form.LEVEL, "Project Level" );
69  
70  		if( dialog.show() )
71  		{
72  
73  			if( dialog.getReturnValue() == XFormDialog.OK_OPTION )
74  			{
75  				int levelToAdd = dialog.getValueIndex( Form.LEVEL );
76  				String loadUIProject = dialog.getValue( Form.LOADUIPROJECT );
77  				String openedProjectName = IntegrationUtils.getOpenedProjectName();
78  				if( !StringUtils.isNullOrEmpty( openedProjectName ) && !loadUIProject.equals( openedProjectName ) )
79  				{
80  					if( UISupport.confirm( "Close currently open [" + IntegrationUtils.getOpenedProjectName()
81  							+ "] loadUI project", "Close loadUI project" ) )
82  					{
83  						IntegrationUtils.closeOpenedLoadUIProject();
84  					}
85  					else
86  					{
87  						return;
88  					}
89  				}
90  				String[] soapuiTestCases = StringUtils.toStringArray( ( ( XFormMultiSelectList )dialog
91  						.getFormField( Form.TESTCASES ) ).getSelectedOptions() );
92  				if( soapuiTestCases.length == 0 )
93  				{
94  					UISupport.showErrorMessage( "No TestCases selected." );
95  					return;
96  				}
97  				try
98  				{
99  					IntegrationUtils.generateTestSuiteLoadTests( soapUIProjectPath, soapUITestSuite, soapuiTestCases,
100 							loadUIProject, levelToAdd );
101 				}
102 				catch( IOException e )
103 				{
104 					UISupport.showInfoMessage( "Error while opening selected loadUI project" );
105 					return;
106 				}
107 			}
108 		}
109 	}
110 
111 	@AForm( description = "Specify target loadUI Project, select TestCases to add and the loadUI level to add them to", name = "Add multiple TestCases to loadUI", helpUrl = HelpUrls.CLONETESTSUITE_HELP_URL, icon = UISupport.TOOL_ICON_PATH )
112 	public interface Form
113 	{
114 		@AField( name = "Target Project", description = "The target loadUI Project to add to", type = AFieldType.ENUMERATION )
115 		public final static String LOADUIPROJECT = "Target Project";
116 
117 		@AField( name = "Source TestCases", description = "The TestCases to add", type = AFieldType.MULTILIST )
118 		public final static String TESTCASES = "Source TestCases";
119 
120 		@AField( name = "Level", description = "Select the level where to add Samplers", type = AFieldType.RADIOGROUP, values = {
121 				"Project Level", "Single TestCase ", "Separate TestCases" } )
122 		public final static String LEVEL = "Level";
123 
124 	}
125 
126 }