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