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 import java.util.Set;
18
19 import com.eviware.soapui.impl.wsdl.WsdlInterface;
20 import com.eviware.soapui.impl.wsdl.WsdlProject;
21 import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
22 import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
23 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
24 import com.eviware.soapui.model.support.ModelSupport;
25 import com.eviware.soapui.support.UISupport;
26
27 public class TestCaseToProjectDropHandler extends AbstractAfterModelItemDropHandler<WsdlTestCase, WsdlProject>
28 {
29 public TestCaseToProjectDropHandler()
30 {
31 super( WsdlTestCase.class, WsdlProject.class );
32 }
33
34 @Override
35 boolean canCopyAfter( WsdlTestCase source, WsdlProject target )
36 {
37 return true;
38 }
39
40 @Override
41 boolean canMoveAfter( WsdlTestCase source, WsdlProject target )
42 {
43 return true;
44 }
45
46 @Override
47 boolean copyAfter( WsdlTestCase testCase, WsdlProject target )
48 {
49 WsdlTestSuite testSuite = getTargetTestSuite( target, "Copy TestCase" );
50 if( testSuite == null )
51 return false;
52
53 testCase = TestCaseToTestSuiteDropHandler.copyTestCase( testCase, testSuite, -1 );
54 if( testCase != null )
55 UISupport.select( testCase );
56
57 return testCase != null;
58 }
59
60 private WsdlTestSuite getTargetTestSuite( WsdlProject target, String title )
61 {
62 String name = "TestSuite 1";
63 if( target.getTestSuiteCount() > 0 )
64 {
65 String[] names = ModelSupport.getNames( target.getTestSuiteList(), new String [] {"<Create New>"} );
66 name = UISupport.prompt( "Specify target TestSuite for TestCase", title, names );
67 if( name == null )
68 return null;
69 }
70
71 WsdlTestSuite testSuite = target.getTestSuiteByName( name );
72 if( testSuite == null )
73 {
74 name = UISupport.prompt( "Specify name for new TestSuite", title, "TestSuite " + (target.getTestSuiteCount()+1));
75 if( name == null )
76 return null;
77
78 testSuite = target.addNewTestSuite( name );
79 }
80
81 Set<WsdlInterface> requiredInterfaces = new HashSet<WsdlInterface>();
82
83 for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
84 {
85 WsdlTestCase testCase = testSuite.getTestCaseAt( i );
86
87 for( int y = 0; y < testCase.getTestStepCount(); y++ )
88 {
89 WsdlTestStep testStep = testCase.getTestStepAt( y );
90 requiredInterfaces.addAll( testStep.getRequiredInterfaces() );
91 }
92 }
93
94 if( !DragAndDropSupport.importRequiredInterfaces( target, requiredInterfaces, title ))
95 return null;
96 else
97 return testSuite;
98 }
99
100 @Override
101 boolean moveAfter( WsdlTestCase testCase, WsdlProject target )
102 {
103 WsdlTestSuite testSuite = getTargetTestSuite( target, "Move TestCase" );
104 if( testSuite == null )
105 return false;
106
107 testCase = TestCaseToTestSuiteDropHandler.moveTestCase( testCase, testSuite, -1 );
108 if( testCase != null )
109 UISupport.select( testCase );
110
111 return testCase != null;
112 }
113
114 @Override
115 String getCopyAfterInfo( WsdlTestCase source, WsdlProject target )
116 {
117 return "Copy TestCase [" + source.getName() + "] to TestSuite in Project [" + target.getName() + "]";
118 }
119
120 @Override
121 String getMoveAfterInfo( WsdlTestCase source, WsdlProject target )
122 {
123 return "Move TestCase [" + source.getName() + "] to TestSuite in Project [" + target.getName() + "]";
124 }
125 }