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