1 18 19 package org.apache.jmeter.testelement; 20 21 import java.io.Serializable ; 22 import java.util.Collection ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 import java.util.Map ; 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 41 public class TestPlan extends AbstractTestElement implements Serializable 42 { 43 public final static String THREAD_GROUPS = "TestPlan.thread_groups"; 44 public final static String FUNCTIONAL_MODE = "TestPlan.functional_mode"; 45 public final static String USER_DEFINED_VARIABLES = 46 "TestPlan.user_defined_variables"; 47 public final static String SERIALIZE_THREADGROUPS = 48 "TestPlan.serialize_threadgroups"; 49 public final static String COMMENTS = "TestPlan.comments"; 50 51 private List threadGroups = new LinkedList (); 52 private List configs = new LinkedList (); 53 private static List itemsCanAdd = new LinkedList (); 54 private static TestPlan plan; 55 56 static { 57 itemsCanAdd.add(JMeterUtils.getResString("threadgroup")); 62 } 63 64 public TestPlan() 65 { 66 } 70 71 public TestPlan(String name) 72 { 73 setName(name); 74 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 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 name, String value) 123 { 124 getVariables().addArgument(name, value); 125 } 126 127 public static TestPlan createTestPlan(String 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 && !isRunningVersion()) 151 { 152 addThreadGroup((ThreadGroup ) tg); 153 } 154 } 155 156 public void addJMeterComponent(TestElement child) 157 { 158 if (child instanceof ThreadGroup ) 159 { 160 addThreadGroup((ThreadGroup ) child); 161 } 162 } 163 164 169 public Collection getThreadGroups() 170 { 171 return threadGroups; 172 } 173 174 179 public void addConfigElement(ConfigElement c) 180 { 181 configs.add(c); 182 } 183 184 189 public void addThreadGroup(ThreadGroup group) 190 { 191 threadGroups.add(group); 192 } 193 } 194 | Popular Tags |