1
2
3
4
5 package com.eviware.soapui.support.dnd.handlers;
6
7 import java.util.HashSet;
8
9 import com.eviware.soapui.SoapUI;
10 import com.eviware.soapui.impl.wsdl.WsdlInterface;
11 import com.eviware.soapui.impl.wsdl.WsdlProject;
12 import com.eviware.soapui.impl.wsdl.WsdlRequest;
13 import com.eviware.soapui.impl.wsdl.actions.request.AddRequestToTestCaseAction;
14 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
15 import com.eviware.soapui.support.UISupport;
16 import com.eviware.soapui.support.action.SoapUIAction;
17
18 public class RequestToTestStepDropHandler extends AbstractAfterModelItemDropHandler<WsdlRequest, WsdlTestStep>
19 {
20 public RequestToTestStepDropHandler()
21 {
22 super( WsdlRequest.class, WsdlTestStep.class );
23 }
24
25 @Override
26 boolean canCopyAfter( WsdlRequest source, WsdlTestStep target )
27 {
28 return true;
29 }
30
31 @Override
32 boolean canMoveAfter( WsdlRequest source, WsdlTestStep target )
33 {
34 return true;
35 }
36
37 @Override
38 boolean copyAfter( WsdlRequest source, WsdlTestStep target )
39 {
40 return addRequestToTestCase( source, target);
41 }
42
43 private boolean addRequestToTestCase( WsdlRequest source, WsdlTestStep target )
44 {
45 if( !UISupport.confirm( "Add Request [" + source.getName() + "] to TestCase [" +
46 target.getTestCase().getName() +"]", "Add Request to TestCase" ))
47 return false;
48
49 WsdlProject targetProject = target.getTestCase().getTestSuite().getProject();
50 if( targetProject != source.getOperation().getInterface().getProject() )
51 {
52 HashSet<WsdlInterface> requiredInterfaces = new HashSet<WsdlInterface>();
53 requiredInterfaces.add( source.getOperation().getInterface() );
54
55 if( !DragAndDropSupport.importRequiredInterfaces( targetProject,
56 requiredInterfaces, "Add Request to TestCase" ))
57 {
58 return false;
59 }
60 }
61
62 SoapUIAction<WsdlRequest> action = SoapUI.getActionRegistry().getAction( AddRequestToTestCaseAction.SOAPUI_ACTION_ID );
63 return (( AddRequestToTestCaseAction ) action).addRequest( target.getTestCase(),
64 source, target.getTestCase().getIndexOfTestStep( target )+1 ) != null;
65 }
66
67 @Override
68 boolean moveAfter( WsdlRequest source, WsdlTestStep target )
69 {
70 return addRequestToTestCase( source, target);
71 }
72
73 @Override
74 String getCopyAfterInfo( WsdlRequest source, WsdlTestStep target )
75 {
76 return "Add Request [" + source.getName() + "] to TestCase [" + target.getTestCase().getName() +"]";
77 }
78
79 @Override
80 String getMoveAfterInfo( WsdlRequest source, WsdlTestStep target )
81 {
82 return getCopyAfterInfo( source, target );
83 }
84 }