1
2
3
4
5
6
7
8
9
10
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 {
36 private static final String USE_CURRENT = "- use current -";
37 private final WsdlTestCase testCase;
38
39 public SetEndpointAction( WsdlTestCase testCase )
40 {
41 this.testCase = testCase;
42 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/set_endpoint.gif"));
43 putValue( Action.SHORT_DESCRIPTION, "Sets the endpoint for all requests in this testcase" );
44 }
45
46 public void actionPerformed(ActionEvent e)
47 {
48 Set<String> endpointSet = new HashSet<String>();
49 Set<String> currentEndpointSet = new HashSet<String>();
50
51 endpointSet.add( USE_CURRENT );
52
53 for( int c = 0; c < testCase.getTestStepCount(); c++ )
54 {
55 TestStep step = testCase.getTestStepAt( c );
56 if( step instanceof WsdlTestRequestStep )
57 {
58 WsdlTestRequestStep requestStep = (WsdlTestRequestStep) step;
59 String [] endpoints = requestStep.getTestRequest().getOperation().getInterface().getEndpoints();
60 for( int i = 0; i < endpoints.length; i++ )
61 {
62 endpointSet.add( endpoints[i] );
63 }
64
65 currentEndpointSet.add( requestStep.getTestRequest().getEndpoint() );
66 }
67 }
68
69 String selected = (String) UISupport.prompt( "Select endpoint to set for all requests", "Set Endpoint", endpointSet.toArray(),
70 currentEndpointSet.size() == 1 ? currentEndpointSet.iterator().next() : USE_CURRENT );
71
72 if( selected == null || selected.equals( USE_CURRENT )) return;
73
74 int cnt = 0;
75
76 for( int c = 0; c < testCase.getTestStepCount(); c++ )
77 {
78 TestStep step = testCase.getTestStepAt( c );
79 if( step instanceof WsdlTestRequestStep )
80 {
81 WsdlTestRequestStep requestStep = (WsdlTestRequestStep) step;
82 WsdlTestRequest testRequest = requestStep.getTestRequest();
83
84 if( testRequest.getEndpoint() == null || !testRequest.getEndpoint().equals( selected ))
85 {
86 testRequest.setEndpoint( selected );
87 cnt++;
88 }
89 }
90 }
91
92 UISupport.showInfoMessage( "Changed endpoint to [" + selected + "] for " + cnt + " requests" );
93 }
94 }