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