View Javadoc

1   /*
2    *  soapUI, copyright (C) 2006 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
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.panels.mockoperation.actions;
14  
15  import java.awt.event.ActionEvent;
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  import javax.swing.AbstractAction;
20  import javax.swing.Action;
21  
22  import com.eviware.soapui.impl.wsdl.WsdlInterface;
23  import com.eviware.soapui.impl.wsdl.WsdlOperation;
24  import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
25  import com.eviware.soapui.model.iface.MessagePart;
26  import com.eviware.soapui.model.iface.MessagePart.FaultPart;
27  import com.eviware.soapui.support.UISupport;
28  
29  public class CreateFaultMockResponseAction extends AbstractAction
30  {
31  	private final WsdlMockResponse mockResponse;
32  
33  	public CreateFaultMockResponseAction( WsdlMockResponse mockResponse )
34  	{
35        super( "Create Fault" );
36  		this.mockResponse = mockResponse;
37        putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/create_empty_fault.gif"));
38        putValue( Action.SHORT_DESCRIPTION, "Creates an SOAP Fault response" );
39  	}
40  
41  	public void actionPerformed( ActionEvent e )
42  	{
43  		WsdlOperation operation = mockResponse.getMockOperation().getOperation();
44  		if( operation == null )
45  		{
46  			UISupport.showErrorMessage( "Missing operation for this mock response" );
47  			return;
48  		}
49  		
50  		if( UISupport.confirm( "Overwrite current response with empty Fault message", "Create Fault" ))
51  		{
52  			WsdlInterface iface = operation.getInterface();
53  			MessagePart[] faultParts = operation.getFaultParts();
54  			
55  			if( faultParts != null && faultParts.length > 0 )
56  			{
57  				List<String> names = new ArrayList<String>();
58  				for( int c = 0; c < faultParts.length; c++ )
59  					names.add( faultParts[0].getName() );
60  				
61  				String faultName = UISupport.prompt( "Select fault detail to generate", "Create Fault", names );
62  				if( faultName != null )
63  				{
64  					FaultPart faultPart = ( FaultPart ) faultParts[names.indexOf( faultName )];
65  					mockResponse.setResponseContent( iface.getMessageBuilder().buildFault( faultPart ));	
66  				}
67  			}
68  			else
69  			{
70  				mockResponse.setResponseContent( iface.getMessageBuilder().buildEmptyFault() );	
71  			}
72  		}
73  	}
74  }