View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 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.AField.AFieldType;
24  import com.eviware.x.form.support.AForm;
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.getMockOperationList() ));
58        dialog.setValue( OptionsForm.FAULT_OPERATION, String.valueOf(mockService.getFaultMockOperation()) );
59  		
60  		if( dialog.show() )
61  		{
62  			mockService.setPath( dialog.getValue( OptionsForm.PATH ) );
63  			mockService.setPort( dialog.getIntValue( OptionsForm.PORT, mockService.getPort() ) );
64  			mockService.setHost(  dialog.getValue( OptionsForm.HOST ) );
65  			mockService.setBindToHostOnly( dialog.getBooleanValue( OptionsForm.HOSTONLY ) );
66  			mockService.setDocroot(dialog.getValue( OptionsForm.DOCROOT ));
67           mockService.setFaultMockOperation( mockService.getMockOperationByName( dialog.getValue(OptionsForm.FAULT_OPERATION )));
68  		}
69  	}
70  
71  	@AForm( name="MockService Options", description="Set options for this MockService",
72  				helpUrl=HelpUrls.MOCKSERVICEOPTIONS_HELP_URL, icon=UISupport.OPTIONS_ICON_PATH )
73  	private class OptionsForm
74  	{
75  		@AField( name="Path", description="The path this MockService will mount on")
76  		public final static String PATH = "Path";
77  
78  		@AField( name="Port", description="The port this MockService will mount on", type=AFieldType.INT )
79  		public final static String PORT = "Port";
80  
81  		@AField( name="Host", description="The local host to bind to and use in Port endpoints")
82  		public final static String HOST = "Host";
83  
84  		@AField( name="Host Only", description="Only binds to specified host", type=AFieldType.BOOLEAN )
85  		public final static String HOSTONLY = "Host Only";
86  
87  		@AField( name="Docroot", description="The document root to serve (empty = none)", type=AFieldType.FOLDER )
88  		public final static String DOCROOT = "Docroot";
89  
90        @AField( name="Fault Operation", description="The MockOperation that should handle incoming SOAP Faults", type=AFieldType.ENUMERATION )
91        public final static String FAULT_OPERATION = "Fault Operation";
92  	}
93  }