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.mockservice;
14:
15: import java.util.ArrayList;
16: import java.util.List;
17:
18: import com.eviware.soapui.impl.wsdl.WsdlOperation;
19: import com.eviware.soapui.impl.wsdl.mock.WsdlMockOperation;
20: import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
21: import com.eviware.soapui.impl.wsdl.mock.WsdlMockService;
22: import com.eviware.soapui.model.iface.Interface;
23: import com.eviware.soapui.support.UISupport;
24: import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
25:
26: /**
27: * Adds a new WsdlMockOperation to a WsdlMockService
28: *
29: * @author Ole.Matzura
30: */
31:
32: public class AddNewMockOperationAction extends
33: AbstractSoapUIAction<WsdlMockService> {
34: public final static String SOAPUI_ACTION_ID = "AddNewMockOperationAction";
35:
36: public AddNewMockOperationAction() {
37: super ("New MockOperation",
38: "Creates a new MockOperation for this MockService");
39: }
40:
41: public void perform(WsdlMockService mockService, Object param) {
42: List<OperationWrapper> operations = new ArrayList<OperationWrapper>();
43:
44: for (int c = 0; c < mockService.getProject()
45: .getInterfaceCount(); c++) {
46: Interface iface = mockService.getProject()
47: .getInterfaceAt(c);
48: for (int i = 0; i < iface.getOperationCount(); i++) {
49: if (!mockService.hasMockOperation(iface
50: .getOperationAt(i)))
51: operations.add(new OperationWrapper(
52: (WsdlOperation) iface.getOperationAt(i)));
53: }
54: }
55:
56: if (operations.isEmpty()) {
57: UISupport
58: .showErrorMessage("No unique operations to mock in project!");
59: return;
60: }
61:
62: Object result = UISupport.prompt("Select Operation to Mock",
63: "New MockOperation", operations.toArray());
64: if (result != null) {
65: WsdlMockOperation mockOperation = mockService
66: .addNewMockOperation(((OperationWrapper) result)
67: .getOperation());
68: WsdlMockResponse mockResponse = mockOperation
69: .addNewMockResponse("Response 1", true);
70: UISupport.selectAndShow(mockResponse);
71: }
72: }
73:
74: public class OperationWrapper {
75: private final WsdlOperation operation;
76:
77: public OperationWrapper(WsdlOperation operation) {
78: this .operation = operation;
79: }
80:
81: public WsdlOperation getOperation() {
82: return operation;
83: }
84:
85: public String toString() {
86: return operation.getInterface().getName() + " - "
87: + operation.getName();
88: }
89: }
90: }
|