001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.actions.iface;
014:
015: import com.eviware.soapui.SoapUI;
016: import com.eviware.soapui.impl.wsdl.WsdlInterface;
017: import com.eviware.soapui.impl.wsdl.WsdlProject;
018: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep;
019: import com.eviware.soapui.model.testsuite.TestCase;
020: import com.eviware.soapui.model.testsuite.TestSuite;
021: import com.eviware.soapui.support.UISupport;
022: import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
023:
024: /**
025: * Removes a WsdlInterface from a WsdlProject
026: *
027: * @author Ole.Matzura
028: */
029:
030: public class RemoveInterfaceAction extends
031: AbstractSoapUIAction<WsdlInterface> {
032: public RemoveInterfaceAction() {
033: super ("Remove", "Removes this interface from the project");
034: }
035:
036: public void perform(WsdlInterface iface, Object param) {
037: if (hasRunningDependingTests(iface)) {
038: UISupport
039: .showErrorMessage("Cannot remove Interface due to running depending tests");
040: return;
041: }
042:
043: if (UISupport.confirm("Remove interface [" + iface.getName()
044: + "] from project [" + iface.getProject().getName()
045: + "]?", "Remove Interface")) {
046: if (hasDependingTests(iface)) {
047: if (!UISupport
048: .confirm(
049: "Interface has depending Test Steps which will also be removed. Remove anyway?",
050: "Remove Interface"))
051: return;
052: }
053:
054: WsdlProject project = (WsdlProject) iface.getProject();
055: project.removeInterface(iface);
056: }
057: }
058:
059: public static boolean hasRunningDependingTests(WsdlInterface iface) {
060: if (SoapUI.getTestMonitor() == null)
061: return false;
062:
063: for (int c = 0; c < iface.getProject().getTestSuiteCount(); c++) {
064: TestSuite testSuite = iface.getProject().getTestSuiteAt(c);
065: for (int i = 0; i < testSuite.getTestCaseCount(); i++) {
066: TestCase testCase = testSuite.getTestCaseAt(i);
067: if (!SoapUI.getTestMonitor().hasRunningTest(testCase))
068: continue;
069:
070: for (int j = 0; j < testCase.getTestStepCount(); j++) {
071: WsdlTestStep testStep = (WsdlTestStep) testCase
072: .getTestStepAt(j);
073: if (testStep.dependsOn(iface)) {
074: return true;
075: }
076: }
077: }
078: }
079:
080: return false;
081: }
082:
083: public static boolean hasDependingTests(WsdlInterface iface) {
084: for (int c = 0; c < iface.getProject().getTestSuiteCount(); c++) {
085: TestSuite testSuite = iface.getProject().getTestSuiteAt(c);
086: for (int i = 0; i < testSuite.getTestCaseCount(); i++) {
087: TestCase testCase = testSuite.getTestCaseAt(i);
088:
089: for (int j = 0; j < testCase.getTestStepCount(); j++) {
090: WsdlTestStep testStep = (WsdlTestStep) testCase
091: .getTestStepAt(j);
092: if (testStep.dependsOn(iface)) {
093: return true;
094: }
095: }
096: }
097: }
098:
099: return false;
100: }
101: }
|