public void perform(WsdlInterface iface, Object param) {
generateMockService(iface, false);
}
public void generateMockService(WsdlInterface iface, boolean atCreation) {
XFormDialog dialog = ADialogBuilder.buildDialog(Form.class);
dialog.setBooleanValue(Form.ADD_ENDPOINT, true);
String[] names = ModelSupport.getNames(iface.getOperationList());
dialog.setOptions(Form.OPERATIONS, names);
XFormOptionsField operationsFormField = (XFormOptionsField) dialog.getFormField(Form.OPERATIONS);
operationsFormField.setSelectedOptions(names);
dialog.getFormField(Form.START_MOCKSERVICE).setEnabled(!atCreation);
WsdlProject project = iface.getProject();
String[] mockServices = ModelSupport.getNames(new String[]{CREATE_MOCKSUITE_OPTION},
project.getMockServiceList());
dialog.setOptions(Form.MOCKSERVICE, mockServices);
dialog.setValue(Form.PATH, "/mock" + iface.getName());
dialog.setValue(Form.PORT, "8088");
if (dialog.show()) {
List<String> operations = StringUtils.toStringList(operationsFormField.getSelectedOptions());
if (operations.size() == 0) {
UISupport.showErrorMessage("No Operations selected..");
return;
}
String mockServiceName = dialog.getValue(Form.MOCKSERVICE);
MockService mockService = getMockService(iface, project, mockServiceName);
if (mockService == null) {
return;
}
mockService.setPath(dialog.getValue(Form.PATH));
try {
mockService.setPort(Integer.parseInt(dialog.getValue(Form.PORT)));
} catch (NumberFormatException e1) {
}
for (int i = 0; i < iface.getOperationCount(); i++) {
Operation operation = iface.getOperationAt(i);
if (!operations.contains(operation.getName())) {
continue;
}
MockOperation mockOperation = mockService.addNewMockOperation(operation);
if (mockOperation != null) {
mockOperation.addNewMockResponse("Response 1");
}
}
if (dialog.getBooleanValue(Form.ADD_ENDPOINT)) {
iface.addEndpoint(mockService.getLocalEndpoint());
}
if (!atCreation) {
WsdlMockServiceDesktopPanel desktopPanel = (WsdlMockServiceDesktopPanel) UISupport
.showDesktopPanel(mockService);
if (dialog.getBooleanValue(Form.START_MOCKSERVICE)) {
desktopPanel.startMockService();
SoapUI.getDesktop().minimize(desktopPanel);
}
}
}