1
2
3
4
5
6
7
8
9
10
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 }