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.HashMap;
17 import java.util.HashSet;
18 import java.util.Map;
19 import java.util.Set;
20
21 import com.eviware.soapui.impl.wsdl.WsdlInterface;
22 import com.eviware.soapui.impl.wsdl.WsdlProject;
23 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
24 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
25 import com.eviware.soapui.model.iface.Interface;
26 import com.eviware.soapui.support.UISupport;
27
28 public class DragAndDropSupport
29 {
30
31 public static boolean copyTestStep( WsdlTestStep source, WsdlTestCase target, int defaultPosition )
32 {
33 String name = UISupport.prompt( "Enter name for copied TestStep", "Copy TestStep",
34 target == source.getTestCase() ? "Copy of " + source.getName() : source.getName() );
35 if( name == null)
36 return false;
37
38 WsdlProject sourceProject = source.getTestCase().getTestSuite().getProject();
39 WsdlProject targetProject = target.getTestSuite().getProject();
40
41 if( sourceProject != targetProject )
42 {
43 if( !importRequiredInterfaces( targetProject, new HashSet<WsdlInterface>( source.getRequiredInterfaces() ), "Copy Test Step" ))
44 return false;
45 }
46
47 target.importTestStep( source, name, defaultPosition, true );
48
49 return true;
50 }
51
52 public static boolean importRequiredInterfaces( WsdlProject project, Set<WsdlInterface> requiredInterfaces, String title )
53 {
54 if( requiredInterfaces.size() > 0 && project.getInterfaceCount() > 0 )
55 {
56 Map<String,WsdlInterface> bindings = new HashMap<String,WsdlInterface>();
57 for( WsdlInterface iface : requiredInterfaces )
58 {
59 bindings.put( iface.getTechnicalId(), iface );
60 }
61
62 for( Interface iface : project.getInterfaceList() )
63 {
64 bindings.remove( iface.getTechnicalId());
65 }
66
67 requiredInterfaces.retainAll( bindings.values() );
68 }
69
70 if( requiredInterfaces.size() > 0 )
71 {
72 String msg = "Target project [" + project.getName() +"] is missing required interfaces;\r\n\r\n";
73 for( WsdlInterface iface : requiredInterfaces )
74 {
75 msg += iface.getName() + " [" + iface.getBindingName() + "]\r\n";
76 }
77 msg += "\r\nThese will be cloned to the target project as well";
78
79 if( !UISupport.confirm( msg, title))
80 return false;
81
82 for( WsdlInterface iface : requiredInterfaces )
83 {
84 project.importInterface( iface, true, true );
85 }
86 }
87
88 return true;
89 }
90
91 public static boolean moveTestStep( WsdlTestStep source, WsdlTestCase target, int defaultPosition )
92 {
93 if( source.getTestCase() == target )
94 {
95 int ix = target.getIndexOfTestStep( source );
96
97 if( defaultPosition == -1 )
98 {
99 target.moveTestStep( ix, target.getTestStepCount()-ix );
100 }
101 else if( ix >= 0 && defaultPosition != ix )
102 {
103 int offset = defaultPosition - ix;
104 if( offset > 0 )
105 offset--;
106 target.moveTestStep( ix, offset);
107 }
108 }
109 else
110 {
111 String name = UISupport.prompt( "Enter name for moved TestStep", "Move TestStep", source.getName() );
112 if( name == null)
113 return false;
114
115 WsdlProject sourceProject = source.getTestCase().getTestSuite().getProject();
116 WsdlProject targetProject = target.getTestSuite().getProject();
117
118 if( sourceProject != targetProject )
119 {
120 if( !importRequiredInterfaces( targetProject, new HashSet<WsdlInterface>( source.getRequiredInterfaces() ), "Move Test Step" ))
121 return false;
122 }
123
124 target.importTestStep( source, name, defaultPosition, false );
125 source.getTestCase().removeTestStep( source );
126 }
127
128 return true;
129 }
130
131 }