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.testcase.actions;
14:
15: import java.awt.event.ActionEvent;
16: import java.util.HashSet;
17: import java.util.Set;
18:
19: import javax.swing.AbstractAction;
20: import javax.swing.Action;
21:
22: import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
23: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
24: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
25: import com.eviware.soapui.model.testsuite.TestStep;
26: import com.eviware.soapui.support.UISupport;
27:
28: /**
29: * Action for setting the endpoint for all requests in a testcase
30: *
31: * @author Ole.Matzura
32: */
33:
34: public class SetEndpointAction extends AbstractAction {
35: private static final String USE_CURRENT = "- use current -";
36: private final WsdlTestCase testCase;
37:
38: public SetEndpointAction(WsdlTestCase testCase) {
39: this .testCase = testCase;
40: putValue(Action.SMALL_ICON, UISupport
41: .createImageIcon("/set_endpoint.gif"));
42: putValue(Action.SHORT_DESCRIPTION,
43: "Sets the endpoint for all requests in this testcase");
44: }
45:
46: public void actionPerformed(ActionEvent e) {
47: Set<String> endpointSet = new HashSet<String>();
48: Set<String> currentEndpointSet = new HashSet<String>();
49:
50: endpointSet.add(USE_CURRENT);
51:
52: for (int c = 0; c < testCase.getTestStepCount(); c++) {
53: TestStep step = testCase.getTestStepAt(c);
54: if (step instanceof WsdlTestRequestStep) {
55: WsdlTestRequestStep requestStep = (WsdlTestRequestStep) step;
56: String[] endpoints = requestStep.getTestRequest()
57: .getOperation().getInterface().getEndpoints();
58: for (int i = 0; i < endpoints.length; i++) {
59: endpointSet.add(endpoints[i]);
60: }
61:
62: currentEndpointSet.add(requestStep.getTestRequest()
63: .getEndpoint());
64: }
65: }
66:
67: String selected = (String) UISupport.prompt(
68: "Select endpoint to set for all requests",
69: "Set Endpoint", endpointSet.toArray(),
70: currentEndpointSet.size() == 1 ? currentEndpointSet
71: .iterator().next() : USE_CURRENT);
72:
73: if (selected == null || selected.equals(USE_CURRENT))
74: return;
75:
76: int cnt = 0;
77:
78: for (int c = 0; c < testCase.getTestStepCount(); c++) {
79: TestStep step = testCase.getTestStepAt(c);
80: if (step instanceof WsdlTestRequestStep) {
81: WsdlTestRequestStep requestStep = (WsdlTestRequestStep) step;
82: WsdlTestRequest testRequest = requestStep
83: .getTestRequest();
84:
85: if (!testRequest.getEndpoint().equals(selected)) {
86: testRequest.setEndpoint(selected);
87: cnt++;
88: }
89: }
90: }
91:
92: UISupport.showInfoMessage("Changed endpoint to [" + selected
93: + "] for " + cnt + " requests");
94: }
95: }
|