View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2007 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.mockoperation;
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.WsdlMockOperation;
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 WsdlMockOperation
25   * 
26   * @author ole.matzura
27   */
28  
29  public class OpenRequestForMockOperationAction extends AbstractSoapUIAction<WsdlMockOperation>
30  {
31  	public static final String SOAPUI_ACTION_ID = "OpenRequestForMockOperationAction";
32  
33  	public OpenRequestForMockOperationAction()
34  	{
35  		super( "Open Request", "Opens/Creates a request for this MockOperation with correct endpoint" );
36  	}
37  
38  	public void perform( WsdlMockOperation mockOperation, Object param )
39  	{
40  		WsdlOperation operation = mockOperation.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.getRequests(), 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 " + (operation.getRequestCount()+1 ));
57  				if( name == null )
58  					return;
59  				
60  			   boolean createOptional = operation.getSettings().getBoolean(WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS);
61  		      if (!createOptional)
62  		    	  createOptional =  UISupport.confirm(	"Create optional elements from schema?", "Create Request" );
63  		      
64  		      request = operation.addNewRequest( name );
65  		      String requestContent = operation.createRequest( createOptional );
66  		      if(requestContent != null)
67  		      {
68  		      	request.setRequestContent( requestContent );
69  		      }
70  			}
71  			
72  			request.setEndpoint( mockOperation.getMockService().getLocalEndpoint() );
73  			UISupport.selectAndShow( request );
74  		}
75  	}
76  }