1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.iface;
14
15 import com.eviware.soapui.SoapUI;
16 import com.eviware.soapui.impl.wsdl.WsdlInterface;
17 import com.eviware.soapui.impl.wsdl.WsdlProject;
18 import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
19 import com.eviware.soapui.model.mock.MockOperation;
20 import com.eviware.soapui.model.mock.MockService;
21 import com.eviware.soapui.model.testsuite.TestCase;
22 import com.eviware.soapui.model.testsuite.TestSuite;
23 import com.eviware.soapui.support.UISupport;
24 import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
25
26 /***
27 * Removes a WsdlInterface from a WsdlProject
28 *
29 * @author Ole.Matzura
30 */
31
32 public class RemoveInterfaceAction extends AbstractSoapUIAction<WsdlInterface>
33 {
34 public RemoveInterfaceAction()
35 {
36 super( "Remove", "Removes this interface from the project" );
37 }
38
39 public void perform( WsdlInterface iface, Object param )
40 {
41 if( hasRunningDependingTests( iface ) )
42 {
43 UISupport.showErrorMessage( "Cannot remove Interface due to running depending tests" );
44 return;
45 }
46
47 if( UISupport.confirm( "Remove interface [" + iface.getName() + "] from project [" +
48 iface.getProject().getName() + "]?", "Remove Interface" ))
49 {
50 if( hasDependingTests( iface ) )
51 {
52 if( !UISupport.confirm( "Interface has depending TestSteps which will also be removed. Remove anyway?", "Remove Interface" ))
53 return;
54 }
55
56 if( hasDependingMockOperations( iface ) )
57 {
58 if( !UISupport.confirm( "Interface has depending MockOperations which will also be removed. Remove anyway?", "Remove Interface" ))
59 return;
60 }
61
62 WsdlProject project = (WsdlProject) iface.getProject();
63 project.removeInterface( iface);
64 }
65 }
66
67 public static boolean hasRunningDependingTests( WsdlInterface iface )
68 {
69 if( SoapUI.getTestMonitor() == null )
70 return false;
71
72 for( int c = 0; c < iface.getProject().getTestSuiteCount(); c++ )
73 {
74 TestSuite testSuite = iface.getProject().getTestSuiteAt( c );
75 for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
76 {
77 TestCase testCase = testSuite.getTestCaseAt( i );
78 if( !SoapUI.getTestMonitor().hasRunningTest( testCase ))
79 continue;
80
81 for( int j = 0; j < testCase.getTestStepCount(); j++ )
82 {
83 WsdlTestStep testStep = (WsdlTestStep) testCase.getTestStepAt( j );
84 if( testStep.dependsOn( iface ))
85 {
86 return true;
87 }
88 }
89 }
90 }
91
92 return false;
93 }
94
95 public static boolean hasDependingTests( WsdlInterface iface )
96 {
97 for( int c = 0; c < iface.getProject().getTestSuiteCount(); c++ )
98 {
99 TestSuite testSuite = iface.getProject().getTestSuiteAt( c );
100 for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
101 {
102 TestCase testCase = testSuite.getTestCaseAt( i );
103
104 for( int j = 0; j < testCase.getTestStepCount(); j++ )
105 {
106 WsdlTestStep testStep = (WsdlTestStep) testCase.getTestStepAt( j );
107 if( testStep.dependsOn( iface ))
108 {
109 return true;
110 }
111 }
112 }
113 }
114
115 return false;
116 }
117
118 public static boolean hasDependingMockOperations( WsdlInterface iface )
119 {
120 for( int c = 0; c < iface.getProject().getMockServiceCount(); c++ )
121 {
122 MockService mockService = iface.getProject().getMockServiceAt( c );
123 for( int i = 0; i < mockService.getMockOperationCount(); i++ )
124 {
125 MockOperation mockOperation = mockService.getMockOperationAt( i );
126 if( mockOperation.getOperation().getInterface() == iface )
127 return true;
128 }
129 }
130
131 return false;
132 }
133 }