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.actions.mockresponse;
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.WsdlMockResponse;
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 WsdlMockResponse
25: *
26: * @author ole.matzura
27: */
28:
29: public class OpenRequestForMockResponseAction extends
30: AbstractSoapUIAction<WsdlMockResponse> {
31: public static final String SOAPUI_ACTION_ID = "OpenRequestForMockResponseAction";
32:
33: public OpenRequestForMockResponseAction() {
34: super ("Open Request",
35: "Opens/Creates a request for this MockOperation with correct endpoint");
36: }
37:
38: public void perform(WsdlMockResponse mockResponse, Object param) {
39: WsdlOperation operation = mockResponse.getMockOperation()
40: .getOperation();
41: if (operation == null) {
42: UISupport
43: .showErrorMessage("Missing operation for this mock response");
44: return;
45: }
46:
47: String[] names = ModelSupport.getNames(operation.getRequests(),
48: new String[] { "-> Create New" });
49:
50: String name = (String) UISupport.prompt(
51: "Select Request for Operation [" + operation.getName()
52: + "] " + "to open or create", "Open Request",
53: names);
54: if (name != null) {
55: WsdlRequest request = operation.getRequestByName(name);
56: if (request == null) {
57: name = UISupport.prompt("Specify name of new request",
58: "Open Request", "Request "
59: + (operation.getRequestCount() + 1));
60: if (name == null)
61: return;
62:
63: boolean createOptional = operation
64: .getSettings()
65: .getBoolean(
66: WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS);
67: if (!createOptional)
68: createOptional = UISupport.confirm(
69: "Create optional elements from schema?",
70: "Create Request");
71:
72: request = operation.addNewRequest(name);
73: String requestContent = operation
74: .createRequest(createOptional);
75: if (requestContent != null) {
76: request.setRequestContent(requestContent);
77: }
78: }
79:
80: request.setEndpoint(mockResponse.getMockOperation()
81: .getMockService().getLocalEndpoint());
82: UISupport.selectAndShow(request);
83: }
84: }
85: }
|