View Javadoc

1   /*
2    *  soapui, copyright (C) 2005 Ole Matzura / eviware.com 
3    *
4    *  SoapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
7    *
8    *  SoapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  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  import javax.swing.JOptionPane;
22  
23  import com.eviware.soapui.SoapUI;
24  import com.eviware.soapui.impl.wsdl.WsdlTestCase;
25  import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
26  import com.eviware.soapui.model.testsuite.TestStep;
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 final WsdlTestCase testCase;
37  
38  	public SetEndpointAction( WsdlTestCase testCase )
39     {
40  		this.testCase = testCase;
41  		putValue( Action.SMALL_ICON, SoapUI.createImageIcon( "/set_endpoint.gif"));
42        putValue( Action.SHORT_DESCRIPTION, "Sets the endpoint for all requests in this testcase" );
43     }
44     
45  	public void actionPerformed(ActionEvent e)
46  	{
47  		Set<String> endpointSet = new HashSet<String>();
48  		
49  		for( int c = 0; c < testCase.getTestStepCount(); c++ )
50     	{
51     		TestStep step = testCase.getTestStepAt( c );
52     		if( step instanceof WsdlTestRequestStep )
53     		{
54     			WsdlTestRequestStep requestStep = (WsdlTestRequestStep) step;
55     			String [] endpoints = requestStep.getTestRequest().getOperation().getInterface().getEndpoints();
56     			for( int i = 0; i < endpoints.length; i++ )
57     			{
58     				endpointSet.add( endpoints[i] );
59     			}
60     		}
61     	}
62  		
63  		String selected = (String) JOptionPane.showInputDialog( SoapUI.getInstance().getFrame(), 
64  				"Select endpoint to set for all requests", "Set endpoint", 
65  				JOptionPane.QUESTION_MESSAGE, null, endpointSet.toArray(), null );
66  		
67  		if( selected == null ) return;
68  		
69  		for( int c = 0; c < testCase.getTestStepCount(); c++ )
70     	{
71     		TestStep step = testCase.getTestStepAt( c );
72     		if( step instanceof WsdlTestRequestStep )
73     		{
74     			WsdlTestRequestStep requestStep = (WsdlTestRequestStep) step;
75     			requestStep.getTestRequest().setEndpoint( selected );
76     		}
77     	}
78     }
79  }