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