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