1
2
3
4
5
6
7
8
9
10
11
12 package com.eviware.soapui.impl.wsdl.actions.loadtest;
13
14 import java.io.IOException;
15 import java.util.HashMap;
16
17 import com.eviware.soapui.impl.wsdl.actions.project.StartLoadUI;
18 import com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest;
19 import com.eviware.soapui.impl.wsdl.support.HelpUrls;
20 import com.eviware.soapui.integration.loadui.ContextMapping;
21 import com.eviware.soapui.integration.loadui.IntegrationUtils;
22 import com.eviware.soapui.support.StringUtils;
23 import com.eviware.soapui.support.UISupport;
24 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
25 import com.eviware.x.form.XFormDialog;
26 import com.eviware.x.form.XFormField;
27 import com.eviware.x.form.XFormFieldListener;
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.AField.AFieldType;
32
33 public class ConvertToLoadUIAction extends AbstractSoapUIAction<WsdlLoadTest>
34 {
35
36 private XFormDialog dialog;
37 public static final String SOAPUI_ACTION_ID = "ConvertToLoadUIAction";
38
39 public ConvertToLoadUIAction()
40 {
41 super( "Convert to loadUI TestCase", "Convert this LoadTest to a loadUI TestCase" );
42 }
43
44 public void perform( WsdlLoadTest loadTest, 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 if( dialog == null )
55 dialog = ADialogBuilder.buildDialog( Form.class );
56
57 dialog.getFormField( Form.PROJECT ).addFormFieldListener( new XFormFieldListener()
58 {
59
60 public void valueChanged( XFormField sourceField, String newValue, String oldValue )
61 {
62 dialog.setOptions( Form.TESTCASE, IntegrationUtils.getAvailableTestCases( newValue ) );
63 if( dialog.getValue( Form.TESTCASE ).equals( IntegrationUtils.CREATE_ON_PROJECT_LEVEL ) )
64 {
65 dialog.setOptions( Form.SOAPUIRUNNER, IntegrationUtils.getAvailableRunners( newValue,
66 IntegrationUtils.CREATE_ON_PROJECT_LEVEL ) );
67 }
68 }
69 } );
70 dialog.getFormField( Form.TESTCASE ).addFormFieldListener( new XFormFieldListener()
71 {
72
73 public void valueChanged( XFormField sourceField, String newValue, String oldValue )
74 {
75 if( newValue.equals( IntegrationUtils.CREATE_NEW_OPTION ) )
76 {
77 dialog.setOptions( Form.SOAPUIRUNNER, new String[] { IntegrationUtils.CREATE_NEW_OPTION } );
78 }
79 else
80 {
81 dialog.setOptions( Form.SOAPUIRUNNER, IntegrationUtils.getAvailableRunners( dialog
82 .getValue( Form.PROJECT ), newValue ) );
83 }
84 }
85 } );
86
87 dialog.setOptions( Form.PROJECT, IntegrationUtils.getAvailableProjects() );
88 if( !StringUtils.isNullOrEmpty( IntegrationUtils.getOpenedProjectName() ) )
89 {
90 dialog.setValue( Form.PROJECT, IntegrationUtils.getOpenedProjectName() );
91 }
92 else
93 {
94 dialog.setValue( Form.PROJECT, IntegrationUtils.CREATE_NEW_OPTION );
95 }
96 dialog.setOptions( Form.TESTCASE, IntegrationUtils.getAvailableTestCases( dialog.getValue( Form.PROJECT ) ) );
97 if( !dialog.getValue( Form.PROJECT ).equals( IntegrationUtils.getOpenedProjectName() ) )
98 {
99 dialog.setValue( Form.TESTCASE, IntegrationUtils.CREATE_ON_PROJECT_LEVEL );
100 }
101
102 dialog.setOptions( Form.SOAPUIRUNNER, IntegrationUtils.getAvailableRunners( dialog.getValue( Form.PROJECT ),
103 dialog.getValue( Form.TESTCASE ) ) );
104 dialog.setValue( Form.SOAPUIRUNNER, IntegrationUtils.CREATE_NEW_OPTION );
105 if( dialog.show() )
106 {
107 String targetProjectString = dialog.getValue( Form.PROJECT );
108 String targetTestCaseName = !dialog.getValue( Form.TESTCASE )
109 .equals( IntegrationUtils.CREATE_ON_PROJECT_LEVEL ) ? dialog.getValue( Form.TESTCASE ) : null;
110 String targetRunnerName = dialog.getValue( Form.SOAPUIRUNNER );
111 String openedProjectName = IntegrationUtils.getOpenedProjectName();
112 if( !StringUtils.isNullOrEmpty( openedProjectName ) && !targetProjectString.equals( openedProjectName ) )
113 if( UISupport.confirm( "Close currently open [" + IntegrationUtils.getOpenedProjectName()
114 + "] loadUI project", "Close loadUI project" ) )
115 {
116 IntegrationUtils.closeOpenedLoadUIProject();
117 }
118 else
119 {
120 return;
121 }
122 exportToLoadUI( loadTest, targetProjectString, targetTestCaseName, targetRunnerName );
123 }
124 }
125
126 protected void exportToLoadUI( WsdlLoadTest loadTest, String targetProjectString, String targetTestCaseName,
127 String targetRunnerName )
128 {
129
130 HashMap<String, Object> createdRunnerSettings = null;
131 try
132 {
133 createdRunnerSettings = IntegrationUtils.exportLoadTestToLoadUI( loadTest, targetProjectString,
134 targetTestCaseName, targetRunnerName );
135 }
136 catch( IOException e )
137 {
138 UISupport.showInfoMessage( "Error while opening selected loadUI project" );
139 return;
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153
154 }
155
156 @AForm( description = "Specify Items in loadUI for Converting LoadTest", name = "Convert to loadUI", helpUrl = HelpUrls.CLONETESTCASE_HELP_URL, icon = UISupport.CONVERT_TO_LOADUI_ICON_PATH )
157 protected interface Form
158 {
159 @AField( name = "Target Project", description = "The target Project in loadUI", type = AFieldType.ENUMERATION )
160 public final static String PROJECT = "Target Project";
161
162 @AField( name = "Target TestCase", description = "The name of the target TestCase in loadUI", type = AFieldType.ENUMERATION )
163 public final static String TESTCASE = "Target TestCase";
164
165 @AField( name = "Target SoapUIRunner", description = "The target SoapUIRunner in loadUI", type = AFieldType.ENUMERATION )
166 public final static String SOAPUIRUNNER = "Target SoapUIRunner";
167
168 }
169
170 }