KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > testelement > TestPlan


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/testelement/TestPlan.java,v 1.11 2004/02/14 03:34:30 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.testelement;
20
21 import java.io.Serializable JavaDoc;
22 import java.util.Collection JavaDoc;
23 import java.util.LinkedList JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.apache.jmeter.config.Arguments;
28 import org.apache.jmeter.config.ConfigElement;
29 import org.apache.jmeter.testelement.property.BooleanProperty;
30 import org.apache.jmeter.testelement.property.CollectionProperty;
31 import org.apache.jmeter.testelement.property.StringProperty;
32 import org.apache.jmeter.testelement.property.TestElementProperty;
33 import org.apache.jmeter.threads.ThreadGroup;
34 import org.apache.jmeter.util.JMeterUtils;
35
36 /**
37  * @author Michael Stover
38  * Created March 13, 2001
39  * @version $Revision: 1.11 $ Last updated: $Date: 2004/02/14 03:34:30 $
40  */

41 public class TestPlan extends AbstractTestElement implements Serializable JavaDoc
42 {
43     public final static String JavaDoc THREAD_GROUPS = "TestPlan.thread_groups";
44     public final static String JavaDoc FUNCTIONAL_MODE = "TestPlan.functional_mode";
45     public final static String JavaDoc USER_DEFINED_VARIABLES =
46         "TestPlan.user_defined_variables";
47     public final static String JavaDoc SERIALIZE_THREADGROUPS =
48         "TestPlan.serialize_threadgroups";
49     public final static String JavaDoc COMMENTS = "TestPlan.comments";
50
51     private List JavaDoc threadGroups = new LinkedList JavaDoc();
52     private List JavaDoc configs = new LinkedList JavaDoc();
53     private static List JavaDoc itemsCanAdd = new LinkedList JavaDoc();
54     private static TestPlan plan;
55     
56     static {
57         // WARNING! This String value must be identical to the String value
58
// returned in org.apache.jmeter.threads.ThreadGroup.getClassLabel()
59
// method. If it's not you will not be able to add a Thread Group
60
// element to a Test Plan.
61
itemsCanAdd.add(JMeterUtils.getResString("threadgroup"));
62     }
63
64     public TestPlan()
65     {
66 // this("Test Plan");
67
// setFunctionalMode(false);
68
// setSerialized(false);
69
}
70
71     public TestPlan(String JavaDoc name)
72     {
73         setName(name);
74 // setFunctionalMode(false);
75
// setSerialized(false);
76
setProperty(new CollectionProperty(THREAD_GROUPS, threadGroups));
77     }
78
79     public boolean isFunctionalMode()
80     {
81         return getPropertyAsBoolean(FUNCTIONAL_MODE);
82     }
83
84     public void setUserDefinedVariables(Arguments vars)
85     {
86         setProperty(new TestElementProperty(USER_DEFINED_VARIABLES, vars));
87     }
88
89     public Map JavaDoc getUserDefinedVariables()
90     {
91         Arguments args = getVariables();
92         return args.getArgumentsAsMap();
93     }
94
95     private Arguments getVariables()
96     {
97         Arguments args =
98             (Arguments) getProperty(USER_DEFINED_VARIABLES).getObjectValue();
99         if (args == null)
100         {
101             args = new Arguments();
102             setUserDefinedVariables(args);
103         }
104         return args;
105     }
106
107     public void setFunctionalMode(boolean funcMode)
108     {
109         setProperty(new BooleanProperty(FUNCTIONAL_MODE, funcMode));
110     }
111     
112     public void setSerialized(boolean serializeTGs)
113     {
114         setProperty(new BooleanProperty(SERIALIZE_THREADGROUPS, serializeTGs));
115     }
116     
117     public boolean isSerialized()
118     {
119         return getPropertyAsBoolean(SERIALIZE_THREADGROUPS);
120     }
121
122     public void addParameter(String JavaDoc name, String JavaDoc value)
123     {
124         getVariables().addArgument(name, value);
125     }
126
127     public static TestPlan createTestPlan(String JavaDoc name)
128     {
129         if (plan == null)
130         {
131             if (name == null)
132             {
133                 plan = new TestPlan();
134             }
135             else
136             {
137                 plan = new TestPlan(name);
138             }
139             plan.setProperty(
140                 new StringProperty(
141                     TestElement.GUI_CLASS,
142                     "org.apache.jmeter.control.gui.TestPlanGui"));
143         }
144         return plan;
145     }
146
147     public void addTestElement(TestElement tg)
148     {
149         super.addTestElement(tg);
150         if (tg instanceof ThreadGroup JavaDoc && !isRunningVersion())
151         {
152             addThreadGroup((ThreadGroup JavaDoc) tg);
153         }
154     }
155
156     public void addJMeterComponent(TestElement child)
157     {
158         if (child instanceof ThreadGroup JavaDoc)
159         {
160             addThreadGroup((ThreadGroup JavaDoc) child);
161         }
162     }
163
164     /**
165      * Gets the ThreadGroups attribute of the TestPlan object.
166      *
167      * @return the ThreadGroups value
168      */

169     public Collection JavaDoc getThreadGroups()
170     {
171         return threadGroups;
172     }
173
174     /**
175      * Adds a feature to the ConfigElement attribute of the TestPlan object.
176      *
177      * @param c the feature to be added to the ConfigElement attribute
178      */

179     public void addConfigElement(ConfigElement c)
180     {
181         configs.add(c);
182     }
183
184     /**
185      * Adds a feature to the ThreadGroup attribute of the TestPlan object.
186      *
187      * @param group the feature to be added to the ThreadGroup attribute
188      */

189     public void addThreadGroup(ThreadGroup JavaDoc group)
190     {
191         threadGroups.add(group);
192     }
193 }
194
Popular Tags