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.impl.wsdl.testcase.WsdlTestCase;
24  import com.eviware.soapui.support.UISupport;
25  import com.eviware.soapui.support.action.SoapUIAction;
26  
27  public class RequestToTestCaseDropHandler extends AbstractBeforeAfterModelItemDropHandler<WsdlRequest, WsdlTestCase>
28  {
29  	public RequestToTestCaseDropHandler()
30  	{
31  		super( WsdlRequest.class, WsdlTestCase.class );
32  	}
33  	
34  	@Override
35  	boolean canCopyAfter( WsdlRequest source, WsdlTestCase target )
36  	{
37  		return true;
38  	}
39  
40  	@Override
41  	boolean canMoveAfter( WsdlRequest source, WsdlTestCase target )
42  	{
43  		return true;
44  	}
45  
46  	@Override
47  	boolean copyAfter( WsdlRequest source, WsdlTestCase target )
48  	{
49  		return addRequestToTestCase( source, target, -1);
50  	}
51  
52  	private boolean addRequestToTestCase( WsdlRequest source, WsdlTestCase target, int index )
53  	{
54  		if( !UISupport.confirm( "Add Request [" + source.getName() + "] to TestCase [" + target.getName() +"]", "Add Request to TestCase" ))
55  			return false;
56  		
57  		WsdlProject targetProject = target.getTestSuite().getProject();
58  		if( targetProject != source.getOperation().getInterface().getProject() )
59  		{
60  			HashSet<WsdlInterface> requiredInterfaces = new HashSet<WsdlInterface>();
61  			requiredInterfaces.add( source.getOperation().getInterface() );
62  			
63  			if( !DragAndDropSupport.importRequiredInterfaces( targetProject,  
64  						requiredInterfaces, "Add Request to TestCase" ))
65  			{
66  				return false;
67  			}
68  		}
69  		
70  		SoapUIAction<WsdlRequest> action = SoapUI.getActionRegistry().getAction( AddRequestToTestCaseAction.SOAPUI_ACTION_ID );
71  		return (( AddRequestToTestCaseAction ) action).addRequest( target, source, index ) != null;
72  	}
73  
74  	@Override
75  	boolean moveAfter( WsdlRequest source, WsdlTestCase target )
76  	{
77  		return addRequestToTestCase( source, target, -1);
78  	}
79  
80  	@Override
81  	String getCopyAfterInfo( WsdlRequest source, WsdlTestCase target )
82  	{
83  		return "Add Request [" + source.getName() + "] to TestCase [" + target.getName() +"]";
84  	}
85  
86  	@Override
87  	String getMoveAfterInfo( WsdlRequest source, WsdlTestCase target )
88  	{
89  		return getCopyAfterInfo( source, target );
90  	}
91  
92  	@Override
93  	boolean canCopyBefore( WsdlRequest source, WsdlTestCase target )
94  	{
95  		return true;
96  	}
97  
98  	@Override
99  	boolean canMoveBefore( WsdlRequest source, WsdlTestCase target )
100 	{
101 		return true;
102 	}
103 
104 	@Override
105 	boolean copyBefore( WsdlRequest source, WsdlTestCase target )
106 	{
107 		return addRequestToTestCase( source, target, 0);
108 	}
109 
110 	@Override
111 	String getCopyBeforeInfo( WsdlRequest source, WsdlTestCase target )
112 	{
113 		return getCopyAfterInfo( source, target );
114 	}
115 
116 	@Override
117 	String getMoveBeforeInfo( WsdlRequest source, WsdlTestCase target )
118 	{
119 		return getCopyAfterInfo( source, target );
120 	}
121 
122 	@Override
123 	boolean moveBefore( WsdlRequest source, WsdlTestCase target )
124 	{
125 		return addRequestToTestCase( source, target, 0);
126 	}
127 }