1
2
3
4
5
6
7
8
9
10
11
12 package com.eviware.soapui.impl.wsdl.actions.testsuite;
13
14 import java.io.IOException;
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
19 import com.eviware.soapui.impl.wsdl.actions.project.StartLoadUI;
20 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
21 import com.eviware.soapui.integration.loadui.IntegrationUtils;
22 import com.eviware.soapui.model.testsuite.LoadTest;
23 import com.eviware.soapui.model.testsuite.TestCase;
24 import com.eviware.soapui.support.StringUtils;
25 import com.eviware.soapui.support.UISupport;
26 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
27 import com.eviware.x.form.XFormDialog;
28 import com.eviware.x.form.support.ADialogBuilder;
29 import com.eviware.x.form.support.AField;
30 import com.eviware.x.form.support.AForm;
31 import com.eviware.x.form.support.XFormMultiSelectList;
32 import com.eviware.x.form.support.AField.AFieldType;
33
34 public class ConvertTestSuiteLoadTestsToLoadUIAction extends AbstractSoapUIAction<WsdlTestSuite>
35 {
36 public static final String SOAPUI_ACTION_ID = "ConvertTestSuiteLoadTestsToLoadUIAction";
37
38 public ConvertTestSuiteLoadTestsToLoadUIAction()
39 {
40 super( "Convert LoadTests to loadUI TestCases", "Select Containing LoadTest to Convert to loadUI TestCases" );
41 }
42
43 @Override
44 public void perform( WsdlTestSuite testSuite, Object param )
45 {
46 if( !StartLoadUI.testCajoConnection() )
47 {
48 if( UISupport.confirm( StartLoadUI.LOADUI_LAUNCH_QUESTION, StartLoadUI.LOADUI_LAUNCH_TITLE ) )
49 {
50 StartLoadUI.launchLoadUI();
51 }
52 return;
53 }
54 XFormDialog dialog = ADialogBuilder.buildDialog( TestSuiteForm.class );
55
56 dialog.setOptions( TestSuiteForm.LOADUIPROJECT, IntegrationUtils.getAvailableProjects() );
57 if( !StringUtils.isNullOrEmpty( IntegrationUtils.getOpenedProjectName() ) )
58 {
59 dialog.setValue( TestSuiteForm.LOADUIPROJECT, IntegrationUtils.getOpenedProjectName() );
60 }
61 else
62 {
63 dialog.setValue( TestSuiteForm.LOADUIPROJECT, IntegrationUtils.CREATE_NEW_OPTION );
64 }
65 List<String> testSuiteLoadTests = new ArrayList<String>();
66 for( TestCase testCase : testSuite.getTestCaseList() )
67 {
68 for( LoadTest loadTest : testCase.getLoadTestList() )
69 {
70 testSuiteLoadTests.add( testCase.getName() + " - " + loadTest.getName() );
71 }
72 }
73 String[] names = new String[testSuiteLoadTests.size()];
74 for( int c = 0; c < names.length; c++ )
75 {
76 names[c] = testSuiteLoadTests.get( c );
77 }
78 dialog.setOptions( TestSuiteForm.LOADTESTS, names );
79 if( dialog.show() )
80 {
81 if( dialog.getReturnValue() == XFormDialog.OK_OPTION )
82 {
83 String loadUIProject = dialog.getValue( TestSuiteForm.LOADUIPROJECT );
84 String openedProjectName = IntegrationUtils.getOpenedProjectName();
85 if( !StringUtils.isNullOrEmpty( openedProjectName ) && !loadUIProject.equals( openedProjectName ) )
86 {
87 if( UISupport.confirm( "Close currently open [" + IntegrationUtils.getOpenedProjectName()
88 + "] loadUI project", "Close loadUI project" ) )
89 {
90 IntegrationUtils.closeOpenedLoadUIProject();
91 }
92 else
93 {
94 return;
95 }
96 }
97 String[] soapuiLoadTests = StringUtils.toStringArray( ( ( XFormMultiSelectList )dialog
98 .getFormField( TestSuiteForm.LOADTESTS ) ).getSelectedOptions() );
99 if( soapuiLoadTests.length == 0 )
100 {
101 UISupport.showErrorMessage( "No LoadTests selected." );
102 return;
103 }
104 try
105 {
106 IntegrationUtils.exportMultipleLoadTestToLoadUI( testSuite, soapuiLoadTests, loadUIProject );
107 }
108 catch( IOException e )
109 {
110 UISupport.showInfoMessage( "Error while opening selected loadUI project" );
111 return;
112 }
113 }
114 }
115 }
116
117 @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 )
118 public interface TestSuiteForm
119 {
120 @AField( name = "Target Project", description = "The target loadUI Project to add to", type = AFieldType.ENUMERATION )
121 public final static String LOADUIPROJECT = "Target Project";
122
123 @AField( name = "Source LoadTests", description = "The LoadTests to convert", type = AFieldType.MULTILIST )
124 public final static String LOADTESTS = "Source LoadTests";
125
126 }
127
128 }