View Javadoc

1   /*
2    *  soapui, copyright (C) 2005 Ole Matzura / eviware.com 
3    *
4    *  SoapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of the GNU Lesser General Public License as published by the Free Software Foundation; 
6    *  either version 2.1 of the License, or (at your option) any later version.
7    *
8    *  SoapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl;
14  
15  import java.util.ArrayList;
16  import java.util.HashSet;
17  import java.util.List;
18  import java.util.Set;
19  
20  import javax.swing.ImageIcon;
21  
22  import com.eviware.soapui.SoapUI;
23  import com.eviware.soapui.config.TestCaseConfig;
24  import com.eviware.soapui.config.TestSuiteConfig;
25  import com.eviware.soapui.impl.wsdl.actions.testsuite.AddNewTestCaseAction;
26  import com.eviware.soapui.impl.wsdl.actions.testsuite.RemoveTestSuiteAction;
27  import com.eviware.soapui.impl.wsdl.actions.testsuite.RenameTestSuiteAction;
28  import com.eviware.soapui.model.project.Project;
29  import com.eviware.soapui.model.testsuite.TestCase;
30  import com.eviware.soapui.model.testsuite.TestSuite;
31  import com.eviware.soapui.model.testsuite.TestSuiteListener;
32  import com.eviware.soapui.model.testsuite.TestCase.TestStatus;
33  import com.eviware.soapui.model.tree.SoapUITreeNode;
34  import com.eviware.soapui.model.tree.nodes.TestSuiteTreeNode;
35  
36  /***
37   * TestSuite implementation for WSDL projects.
38   * 
39   * @author Ole.Matzura
40   */
41  
42  public class WsdlTestSuite extends AbstractWsdlModelItem implements TestSuite
43  {
44     private final WsdlProject project;
45     private final TestSuiteConfig config;
46     private List<WsdlTestCase> testCases = new ArrayList<WsdlTestCase>();
47     private ImageIcon testSuiteIcon;
48     private Set<TestSuiteListener> listeners = new HashSet<TestSuiteListener>();
49  
50     public WsdlTestSuite(WsdlProject project, TestSuiteConfig config)
51     {
52        this.project = project;
53        this.config = config;
54        
55        TestCaseConfig [] testCaseConfigs = config.getTestCaseArray();
56        for (int i = 0; i < testCaseConfigs.length; i++)
57        {
58           testCases.add( new WsdlTestCase( this, testCaseConfigs[i] ));
59        }
60        
61        testSuiteIcon = SoapUI.createImageIcon("/testSuite.gif");
62        
63        addAction( new AddNewTestCaseAction( this ) );
64        addAction( new RenameTestSuiteAction( this ) );
65        addAction( new RemoveTestSuiteAction( this ) );
66     }
67  
68     public Project getProject()
69     {
70        return project;
71     }
72  
73     public int getTestCaseCount()
74     {
75        return testCases.size();
76     }
77  
78     public TestCase getTestCaseAt(int index)
79     {
80        return testCases.get( index );
81     }
82  
83     public TestStatus getStatus()
84     {
85        return TestStatus.UNKNOWN;
86     }
87  
88     public String getName()
89     {
90        return config.getName();
91     }
92  
93     public ImageIcon getIcon()
94     {
95        return testSuiteIcon;
96     }
97  
98     public void setName(String name)
99     {
100       String old = getName();
101       config.setName( name );
102       notifyPropertyChanged(NAME_PROPERTY, old, name);
103    }
104    
105    public WsdlTestCase addNewTestCase( String name )
106    {
107       WsdlTestCase testCase = new WsdlTestCase( this, config.addNewTestCase());
108       testCase.setName( name );
109       testCases.add( testCase );
110       notifyTestCaseAdded( testCase );
111 
112       return testCase;
113    }
114    
115    public void removeTestCase(WsdlTestCase testCase )
116    {
117       int ix = testCases.indexOf( testCase );
118 
119       notifyTestCaseRemoved( testCase );
120 
121       testCases.remove( ix );
122       config.removeTestCase( ix );
123    }
124 
125    protected SoapUITreeNode createTreeNode()
126    {
127       return new TestSuiteTreeNode( this );
128    }
129    
130    public void notifyTestCaseAdded( WsdlTestCase testCase )
131    {
132       TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
133       
134       for (int c = 0; c < a.length; c++ )
135       {
136          a[c].testCaseAdded( testCase );
137       }
138    }
139    
140    public void notifyTestCaseRemoved( WsdlTestCase testCase )
141    {
142    	TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
143       
144       for (int c = 0; c < a.length; c++ )
145       {
146          a[c].testCaseRemoved( testCase );
147       }
148    } 
149 
150    public void notifyTestStepAdded( WsdlTestStep testStep, int index )
151    {
152    	TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
153       
154       for (int c = 0; c < a.length; c++ )
155       {
156          a[c].testStepAdded( testStep, index );
157       }
158    }
159    
160    public void notifyTestStepRemoved( WsdlTestStep testStep, int ix )
161    {
162    	TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
163       
164       for (int c = 0; c < a.length; c++ )
165       {
166          a[c].testStepRemoved( testStep, ix );
167       }
168    } 
169    
170 	public void addTestSuiteListener(TestSuiteListener listener)
171 	{
172 		listeners.add( listener );
173 	}
174 
175 	public void removeTestSuiteListener(TestSuiteListener listener)
176 	{
177 		listeners.remove( listener );
178 	} 
179    
180 
181 }