SetEndpointAction.java :  » Web-Services » soapui-1.7.5 » com » eviware » soapui » impl » wsdl » panels » testcase » actions » Java Open Source

Java Open Source » Web Services » soapui 1.7.5 
soapui 1.7.5 » com » eviware » soapui » impl » wsdl » panels » testcase » actions » SetEndpointAction.java
/*
 *  soapUI, copyright (C) 2004-2007 eviware.com 
 *
 *  soapUI is free software; you can redistribute it and/or modify it under the 
 *  terms of version 2.1 of the GNU Lesser General Public License as published by 
 *  the Free Software Foundation.
 *
 *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
 *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 *  See the GNU Lesser General Public License for more details at gnu.org.
 */

package com.eviware.soapui.impl.wsdl.panels.testcase.actions;

import java.awt.event.ActionEvent;
import java.util.HashSet;
import java.util.Set;

import javax.swing.AbstractAction;
import javax.swing.Action;

import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
import com.eviware.soapui.model.testsuite.TestStep;
import com.eviware.soapui.support.UISupport;

/**
 * Action for setting the endpoint for all requests in a testcase
 * 
 * @author Ole.Matzura
 */

public class SetEndpointAction extends AbstractAction
{
  private static final String USE_CURRENT = "- use current -";
  private final WsdlTestCase testCase;

  public SetEndpointAction( WsdlTestCase testCase )
   {
    this.testCase = testCase;
    putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/set_endpoint.gif"));
      putValue( Action.SHORT_DESCRIPTION, "Sets the endpoint for all requests in this testcase" );
   }
   
  public void actionPerformed(ActionEvent e)
  {
    Set<String> endpointSet = new HashSet<String>();
    Set<String> currentEndpointSet = new HashSet<String>();
    
    endpointSet.add( USE_CURRENT );
    
    for( int c = 0; c < testCase.getTestStepCount(); c++ )
     {
       TestStep step = testCase.getTestStepAt( c );
       if( step instanceof WsdlTestRequestStep )
       {
         WsdlTestRequestStep requestStep = (WsdlTestRequestStep) step;
         String [] endpoints = requestStep.getTestRequest().getOperation().getInterface().getEndpoints();
         for( int i = 0; i < endpoints.length; i++ )
         {
           endpointSet.add( endpoints[i] );
         }
         
         currentEndpointSet.add( requestStep.getTestRequest().getEndpoint() );
       }
     }
    
    String selected = (String) UISupport.prompt(  "Select endpoint to set for all requests", "Set Endpoint", endpointSet.toArray(), 
        currentEndpointSet.size() == 1 ? currentEndpointSet.iterator().next() : USE_CURRENT );
    
    if( selected == null || selected.equals( USE_CURRENT )) return;
    
    int cnt = 0;
    
    for( int c = 0; c < testCase.getTestStepCount(); c++ )
     {
       TestStep step = testCase.getTestStepAt( c );
       if( step instanceof WsdlTestRequestStep )
       {
         WsdlTestRequestStep requestStep = (WsdlTestRequestStep) step;
         WsdlTestRequest testRequest = requestStep.getTestRequest();
         
         if( !testRequest.getEndpoint().equals( selected ))
         {
           testRequest.setEndpoint( selected );
           cnt++;
         }
       }
     }
    
    UISupport.showInfoMessage( "Changed endpoint to [" + selected + "] for " + cnt + " requests" );
   }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.