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.mockresponse;
14  
15  import com.eviware.soapui.impl.wsdl.WsdlOperation;
16  import com.eviware.soapui.impl.wsdl.WsdlRequest;
17  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
18  import com.eviware.soapui.model.support.ModelSupport;
19  import com.eviware.soapui.settings.WsdlSettings;
20  import com.eviware.soapui.support.UISupport;
21  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
22  
23  /***
24   * Prompts to open an existing request for the specified WsdlMockResponse
25   * 
26   * @author ole.matzura
27   */
28  
29  public class OpenRequestForMockResponseAction extends AbstractSoapUIAction<WsdlMockResponse>
30  {
31  	public static final String SOAPUI_ACTION_ID = "OpenRequestForMockResponseAction";
32  
33  	public OpenRequestForMockResponseAction()
34  	{
35  		super( "Open Request", "Opens/Creates a request for this MockOperation with correct endpoint" );
36  	}
37  
38  	public void perform( WsdlMockResponse mockResponse, Object param )
39  	{
40  		WsdlOperation operation = mockResponse.getMockOperation().getOperation();
41  		if( operation == null )
42  		{
43  			UISupport.showErrorMessage( "Missing operation for this mock response" );
44  			return;
45  		}
46  
47  		String[] names = ModelSupport.getNames( operation.getRequestList(), new String[] { "-> Create New" } );
48  
49  		String name = ( String )UISupport.prompt( "Select Request for Operation [" + operation.getName() + "] "
50  				+ "to open or create", "Open Request", names );
51  		if( name != null )
52  		{
53  			WsdlRequest request = operation.getRequestByName( name );
54  			if( request == null )
55  			{
56  				name = UISupport.prompt( "Specify name of new request", "Open Request", "Request "
57  						+ ( operation.getRequestCount() + 1 ) );
58  				if( name == null )
59  					return;
60  
61  				boolean createOptional = operation.getSettings().getBoolean(
62  						WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS );
63  				if( !createOptional )
64  					createOptional = UISupport.confirm( "Create optional elements from schema?", "Create Request" );
65  
66  				request = operation.addNewRequest( name );
67  				String requestContent = operation.createRequest( createOptional );
68  				if( requestContent != null )
69  				{
70  					request.setRequestContent( requestContent );
71  				}
72  			}
73  
74  			request.setEndpoint( mockResponse.getMockOperation().getMockService().getLocalEndpoint() );
75  			UISupport.selectAndShow( request );
76  		}
77  	}
78  }