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.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  /***
    30   * Creates an SOAP Fault response message for WsdlMockResponse
    31   *
    32   * @author ole.matzura
    33   */
    34
    35  public class CreateFaultMockResponseAction extends AbstractAction
    36  {
    37  	private final WsdlMockResponse mockResponse;
    38
    39  	public CreateFaultMockResponseAction( WsdlMockResponse mockResponse )
    40  	{
    41        super( "Create Fault" );
    42  		this.mockResponse = mockResponse;
    43        putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/create_empty_fault.gif"));
    44        putValue( Action.SHORT_DESCRIPTION, "Creates an SOAP Fault response" );
    45  	}
    46
    47  	public void actionPerformed( ActionEvent e )
    48  	{
    49  		WsdlOperation operation = mockResponse.getMockOperation().getOperation();
    50  		if( operation == null )
    51  		{
    52  			UISupport.showErrorMessage( "Missing operation for this mock response" );
    53  			return;
    54  		}
    55
    56  		if( UISupport.confirm( "Overwrite current response with empty Fault message", "Create Fault" ))
    57  		{
    58  			WsdlInterface iface = operation.getInterface();
    59  			MessagePart[] faultParts = operation.getFaultParts();
    60
    61  			if( faultParts != null && faultParts.length > 0 )
    62  			{
    63  				List<String> names = new ArrayList<String>();
    64  				for( int c = 0; c < faultParts.length; c++ )
    65  					names.add( faultParts[0].getName() );
    66
    67  				String faultName = UISupport.prompt( "Select fault detail to generate", "Create Fault", names );
    68  				if( faultName != null )
    69  				{
    70  					FaultPart faultPart = ( FaultPart ) faultParts[names.indexOf( faultName )];
    71  					mockResponse.setResponseContent( iface.getMessageBuilder().buildFault( faultPart ));
    72  				}
    73  			}
    74  			else
    75  			{
    76  				mockResponse.setResponseContent( iface.getMessageBuilder().buildEmptyFault() );
    77  			}
    78  		}
    79  	}
    80  }