View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
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  
14  package com.eviware.soapui.support.dnd.handlers;
15  
16  import java.util.HashSet;
17  
18  import com.eviware.soapui.SoapUI;
19  import com.eviware.soapui.impl.wsdl.WsdlInterface;
20  import com.eviware.soapui.impl.wsdl.WsdlProject;
21  import com.eviware.soapui.impl.wsdl.WsdlRequest;
22  import com.eviware.soapui.impl.wsdl.actions.request.AddRequestToTestCaseAction;
23  import com.eviware.soapui.model.tree.nodes.support.WsdlTestStepsModelItem;
24  import com.eviware.soapui.support.UISupport;
25  import com.eviware.soapui.support.action.SoapUIAction;
26  
27  public class RequestToTestStepsDropHandler extends AbstractAfterModelItemDropHandler<WsdlRequest, WsdlTestStepsModelItem>
28  {
29  	public RequestToTestStepsDropHandler()
30  	{
31  		super( WsdlRequest.class, WsdlTestStepsModelItem.class );
32  	}
33  	
34  	@Override
35  	boolean canCopyAfter( WsdlRequest source, WsdlTestStepsModelItem target )
36  	{
37  		return true;
38  	}
39  
40  	@Override
41  	boolean canMoveAfter( WsdlRequest source, WsdlTestStepsModelItem target )
42  	{
43  		return true;
44  	}
45  
46  	@Override
47  	boolean copyAfter( WsdlRequest source, WsdlTestStepsModelItem target )
48  	{
49  		return addRequestToTestCase( source, target);
50  	}
51  
52  	private boolean addRequestToTestCase( WsdlRequest source, WsdlTestStepsModelItem target )
53  	{
54  		if( !UISupport.confirm( "Add Request [" + source.getName() + "] to TestCase [" + 
55  					target.getTestCase().getName() +"]", "Add Request to TestCase" ))
56  			return false;
57  		
58  		WsdlProject targetProject = target.getTestCase().getTestSuite().getProject();
59  		if( targetProject != source.getOperation().getInterface().getProject() )
60  		{
61  			HashSet<WsdlInterface> requiredInterfaces = new HashSet<WsdlInterface>();
62  			requiredInterfaces.add( source.getOperation().getInterface() );
63  			
64  			if( !DragAndDropSupport.importRequiredInterfaces( targetProject,  
65  						requiredInterfaces, "Add Request to TestCase" ))
66  			{
67  				return false;
68  			}
69  		}
70  		
71  		SoapUIAction<WsdlRequest> action = SoapUI.getActionRegistry().getAction( AddRequestToTestCaseAction.SOAPUI_ACTION_ID );
72  		return (( AddRequestToTestCaseAction ) action).addRequest( target.getTestCase(), source, 0 ) != null;
73  	}
74  
75  	@Override
76  	boolean moveAfter( WsdlRequest source, WsdlTestStepsModelItem target )
77  	{
78  		return addRequestToTestCase( source, target);
79  	}
80  	
81  	@Override
82  	String getCopyAfterInfo( WsdlRequest source, WsdlTestStepsModelItem target )
83  	{
84  		return "Add Request [" + source.getName() + "] to TestCase [" + target.getTestCase().getName() +"]";
85  	}
86  
87  	@Override
88  	String getMoveAfterInfo( WsdlRequest source, WsdlTestStepsModelItem target )
89  	{
90  		return getCopyAfterInfo( source, target );
91  	}
92  }