View Javadoc

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