View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.actions.mockservice;
14  
15  import com.eviware.soapui.impl.wsdl.mock.WsdlMockService;
16  import com.eviware.soapui.impl.wsdl.support.HelpUrls;
17  import com.eviware.soapui.model.support.ModelSupport;
18  import com.eviware.soapui.support.UISupport;
19  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
20  import com.eviware.x.form.XFormDialog;
21  import com.eviware.x.form.support.ADialogBuilder;
22  import com.eviware.x.form.support.AField;
23  import com.eviware.x.form.support.AForm;
24  import com.eviware.x.form.support.AField.AFieldType;
25  
26  /***
27   * Displays the options for the specified WsdlMockService
28   * 
29   * @author ole.matzura
30   */
31  
32  public class MockServiceOptionsAction extends AbstractSoapUIAction<WsdlMockService>
33  {
34  	private XFormDialog dialog;
35  
36  	public MockServiceOptionsAction()
37  	{
38  		super( "Options", "Sets options for this MockService" );
39  	}
40  
41  	public void perform( WsdlMockService mockService, Object param )
42  	{
43  		if( mockService.getMockRunner() != null && mockService.getMockRunner().isRunning() )
44  		{
45  			UISupport.showErrorMessage( "Can not set MockService options while running" );
46  			return;
47  		}
48  
49  		if( dialog == null )
50  			dialog = ADialogBuilder.buildDialog( OptionsForm.class );
51  
52  		dialog.setValue( OptionsForm.PATH, mockService.getPath() );
53  		dialog.setValue( OptionsForm.HOST, mockService.getHost() );
54  		dialog.setIntValue( OptionsForm.PORT, mockService.getPort() );
55  		dialog.setBooleanValue( OptionsForm.HOSTONLY, mockService.getBindToHostOnly() );
56  		dialog.setValue( OptionsForm.DOCROOT, mockService.getDocroot() );
57  		dialog.setOptions( OptionsForm.FAULT_OPERATION, ModelSupport.getNames( new String[] { "- none -" }, mockService
58  				.getMockOperationList() ) );
59  		dialog.setValue( OptionsForm.FAULT_OPERATION, String.valueOf( mockService.getFaultMockOperation() ) );
60  
61  		if( dialog.show() )
62  		{
63  			mockService.setPath( dialog.getValue( OptionsForm.PATH ) );
64  			mockService.setPort( dialog.getIntValue( OptionsForm.PORT, mockService.getPort() ) );
65  			mockService.setHost( dialog.getValue( OptionsForm.HOST ) );
66  			mockService.setBindToHostOnly( dialog.getBooleanValue( OptionsForm.HOSTONLY ) );
67  			mockService.setDocroot( dialog.getValue( OptionsForm.DOCROOT ) );
68  			mockService.setFaultMockOperation( mockService.getMockOperationByName( dialog
69  					.getValue( OptionsForm.FAULT_OPERATION ) ) );
70  		}
71  	}
72  
73  	@AForm( name = "MockService Options", description = "Set options for this MockService", helpUrl = HelpUrls.MOCKSERVICEOPTIONS_HELP_URL, icon = UISupport.OPTIONS_ICON_PATH )
74  	private class OptionsForm
75  	{
76  		@AField( name = "Path", description = "The path this MockService will mount on" )
77  		public final static String PATH = "Path";
78  
79  		@AField( name = "Port", description = "The port this MockService will mount on", type = AFieldType.INT )
80  		public final static String PORT = "Port";
81  
82  		@AField( name = "Host", description = "The local host to bind to and use in Port endpoints" )
83  		public final static String HOST = "Host";
84  
85  		@AField( name = "Host Only", description = "Only binds to specified host", type = AFieldType.BOOLEAN )
86  		public final static String HOSTONLY = "Host Only";
87  
88  		@AField( name = "Docroot", description = "The document root to serve (empty = none)", type = AFieldType.FOLDER )
89  		public final static String DOCROOT = "Docroot";
90  
91  		@AField( name = "Fault Operation", description = "The MockOperation that should handle incoming SOAP Faults", type = AFieldType.ENUMERATION )
92  		public final static String FAULT_OPERATION = "Fault Operation";
93  	}
94  }