01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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: private final WsdlMockResponse mockResponse;
37:
38: public CreateFaultMockResponseAction(WsdlMockResponse mockResponse) {
39: super ("Create Fault");
40: this .mockResponse = mockResponse;
41: putValue(Action.SMALL_ICON, UISupport
42: .createImageIcon("/create_empty_fault.gif"));
43: putValue(Action.SHORT_DESCRIPTION,
44: "Creates an SOAP Fault response");
45: }
46:
47: public void actionPerformed(ActionEvent e) {
48: WsdlOperation operation = mockResponse.getMockOperation()
49: .getOperation();
50: if (operation == null) {
51: UISupport
52: .showErrorMessage("Missing operation for this mock response");
53: return;
54: }
55:
56: if (UISupport.confirm(
57: "Overwrite current response with empty Fault message",
58: "Create Fault")) {
59: WsdlInterface iface = operation.getInterface();
60: MessagePart[] faultParts = operation.getFaultParts();
61:
62: if (faultParts != null && faultParts.length > 0) {
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(
68: "Select fault detail to generate",
69: "Create Fault", names);
70: if (faultName != null) {
71: FaultPart faultPart = (FaultPart) faultParts[names
72: .indexOf(faultName)];
73: mockResponse.setResponseContent(iface
74: .getMessageBuilder().buildFault(faultPart));
75: }
76: } else {
77: mockResponse.setResponseContent(iface
78: .getMessageBuilder().buildEmptyFault());
79: }
80: }
81: }
82: }
|