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 String getName()
84     {
85        return config.getName();
86     }
87  
88     public ImageIcon getIcon()
89     {
90        return testSuiteIcon;
91     }
92  
93     public void setName(String name)
94     {
95        String old = getName();
96        config.setName( name );
97        notifyPropertyChanged(NAME_PROPERTY, old, name);
98     }
99     
100    public WsdlTestCase addNewTestCase( String name )
101    {
102       WsdlTestCase testCase = new WsdlTestCase( this, config.addNewTestCase());
103       testCase.setName( name );
104       testCases.add( testCase );
105       notifyTestCaseAdded( testCase );
106 
107       return testCase;
108    }
109    
110    public void removeTestCase(WsdlTestCase testCase )
111    {
112       int ix = testCases.indexOf( testCase );
113 
114       notifyTestCaseRemoved( testCase );
115 
116       testCases.remove( ix );
117       config.removeTestCase( ix );
118    }
119 
120    protected SoapUITreeNode createTreeNode()
121    {
122       return new TestSuiteTreeNode( this );
123    }
124    
125    public void notifyTestCaseAdded( WsdlTestCase testCase )
126    {
127       TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
128       
129       for (int c = 0; c < a.length; c++ )
130       {
131          a[c].testCaseAdded( testCase );
132       }
133    }
134    
135    public void notifyTestCaseRemoved( WsdlTestCase testCase )
136    {
137    	TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
138       
139       for (int c = 0; c < a.length; c++ )
140       {
141          a[c].testCaseRemoved( testCase );
142       }
143    } 
144 
145    public void notifyTestStepAdded( WsdlTestStep testStep, int index )
146    {
147    	TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
148       
149       for (int c = 0; c < a.length; c++ )
150       {
151          a[c].testStepAdded( testStep, index );
152       }
153    }
154    
155    public void notifyTestStepRemoved( WsdlTestStep testStep, int ix )
156    {
157    	TestSuiteListener[] a = listeners.toArray( new TestSuiteListener[listeners.size()] );
158       
159       for (int c = 0; c < a.length; c++ )
160       {
161          a[c].testStepRemoved( testStep, ix );
162       }
163    } 
164    
165 	public void addTestSuiteListener(TestSuiteListener listener)
166 	{
167 		listeners.add( listener );
168 	}
169 
170 	public void removeTestSuiteListener(TestSuiteListener listener)
171 	{
172 		listeners.remove( listener );
173 	} 
174    
175 
176 }