generateMockService( iface, false );
}
public WsdlMockService 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 = ( WsdlProject )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 null;
}
String mockServiceName = dialog.getValue( Form.MOCKSERVICE );
WsdlMockService mockService = ( WsdlMockService )project.getMockServiceByName( mockServiceName );
if( mockService == null || mockServiceName.equals( CREATE_MOCKSUITE_OPTION ) )
{
mockServiceName = UISupport.prompt( "Specify name of MockService to create", getName(), iface.getName()
+ " MockService" );
if( mockServiceName == null )
return null;
mockService = ( WsdlMockService )project.addNewMockService( mockServiceName );
}
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++ )
{
WsdlOperation operation = ( WsdlOperation )iface.getOperationAt( i );
if( !operations.contains( operation.getName() ) )
continue;
WsdlMockOperation mockOperation = ( WsdlMockOperation )mockService.addNewMockOperation( operation );
if( mockOperation != null )
mockOperation.addNewMockResponse( "Response 1", true );
}
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 );
}
}