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 [" + iface.getProject().getName()
49 + "]?", "Remove Interface" ) )
50 {
51 if( hasDependingTests( iface ) )
52 {
53 if( !UISupport.confirm( "Interface has depending TestSteps which will also be removed. Remove anyway?",
54 "Remove Interface" ) )
55 return;
56 }
57
58 if( hasDependingMockOperations( iface ) )
59 {
60 if( !UISupport.confirm(
61 "Interface has depending MockOperations which will also be removed. Remove anyway?",
62 "Remove Interface" ) )
63 return;
64 }
65
66 WsdlProject project = ( WsdlProject )iface.getProject();
67 project.removeInterface( iface );
68 }
69 }
70
71 public static boolean hasRunningDependingTests( AbstractInterface<?> iface )
72 {
73 if( SoapUI.getTestMonitor() == null )
74 return false;
75
76 for( int c = 0; c < iface.getProject().getTestSuiteCount(); c++ )
77 {
78 TestSuite testSuite = iface.getProject().getTestSuiteAt( c );
79 for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
80 {
81 TestCase testCase = testSuite.getTestCaseAt( i );
82 if( !SoapUI.getTestMonitor().hasRunningTest( testCase ) )
83 continue;
84
85 for( int j = 0; j < testCase.getTestStepCount(); j++ )
86 {
87 WsdlTestStep testStep = ( WsdlTestStep )testCase.getTestStepAt( j );
88 if( testStep.dependsOn( iface ) )
89 {
90 return true;
91 }
92 }
93 }
94 }
95
96 return false;
97 }
98
99 public static boolean hasDependingTests( AbstractInterface<?> iface )
100 {
101 for( int c = 0; c < iface.getProject().getTestSuiteCount(); c++ )
102 {
103 TestSuite testSuite = iface.getProject().getTestSuiteAt( c );
104 for( int i = 0; i < testSuite.getTestCaseCount(); i++ )
105 {
106 TestCase testCase = testSuite.getTestCaseAt( i );
107
108 for( int j = 0; j < testCase.getTestStepCount(); j++ )
109 {
110 WsdlTestStep testStep = ( WsdlTestStep )testCase.getTestStepAt( j );
111 if( testStep.dependsOn( iface ) )
112 {
113 return true;
114 }
115 }
116 }
117 }
118
119 return false;
120 }
121
122 public static boolean hasDependingMockOperations( WsdlInterface iface )
123 {
124 for( int c = 0; c < iface.getProject().getMockServiceCount(); c++ )
125 {
126 MockService mockService = iface.getProject().getMockServiceAt( c );
127 for( int i = 0; i < mockService.getMockOperationCount(); i++ )
128 {
129 MockOperation mockOperation = mockService.getMockOperationAt( i );
130 if( mockOperation.getOperation().getInterface() == iface )
131 return true;
132 }
133 }
134
135 return false;
136 }
137 }