01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.engine;
20:
21: import org.apache.jmeter.config.Argument;
22: import org.apache.jmeter.config.Arguments;
23: import org.apache.jmeter.control.GenericController;
24: import org.apache.jmeter.reporters.ResultCollector;
25: import org.apache.jmeter.testelement.TestPlan;
26: import org.apache.jmeter.testelement.property.CollectionProperty;
27: import org.apache.jmeter.testelement.property.JMeterProperty;
28: import org.apache.jmeter.testelement.property.PropertyIterator;
29: import org.apache.jorphan.collections.ListedHashTree;
30:
31: public class TestTreeCloner extends junit.framework.TestCase {
32: public TestTreeCloner(String name) {
33: super (name);
34: }
35:
36: public void testCloning() throws Exception {
37: ListedHashTree original = new ListedHashTree();
38: GenericController controller = new GenericController();
39: controller.setName("controller");
40: Arguments args = new Arguments();
41: args.setName("args");
42: TestPlan plan = new TestPlan();
43: plan.addParameter("server", "jakarta");
44: original.add(controller, args);
45: original.add(plan);
46: ResultCollector listener = new ResultCollector();
47: listener.setName("Collector");
48: original.add(controller, listener);
49: TreeCloner cloner = new TreeCloner();
50: original.traverse(cloner);
51: ListedHashTree newTree = cloner.getClonedTree();
52: assertTrue(original != newTree);
53: assertEquals(original.size(), newTree.size());
54: assertEquals(original.getTree(original.getArray()[0]).size(),
55: newTree.getTree(newTree.getArray()[0]).size());
56: assertTrue(original.getArray()[0] != newTree.getArray()[0]);
57: assertEquals(((GenericController) original.getArray()[0])
58: .getName(), ((GenericController) newTree.getArray()[0])
59: .getName());
60: assertSame(
61: original.getTree(original.getArray()[0]).getArray()[1],
62: newTree.getTree(newTree.getArray()[0]).getArray()[1]);
63: TestPlan clonedTestPlan = (TestPlan) newTree.getArray()[1];
64: clonedTestPlan.setRunningVersion(true);
65: clonedTestPlan.recoverRunningVersion();
66: assertTrue(!plan.getUserDefinedVariablesAsProperty()
67: .isRunningVersion());
68: assertTrue(clonedTestPlan.getUserDefinedVariablesAsProperty()
69: .isRunningVersion());
70: Arguments vars = (Arguments) plan
71: .getUserDefinedVariablesAsProperty().getObjectValue();
72: PropertyIterator iter = ((CollectionProperty) vars
73: .getProperty(Arguments.ARGUMENTS)).iterator();
74: while (iter.hasNext()) {
75: JMeterProperty argProp = iter.next();
76: assertTrue(!argProp.isRunningVersion());
77: assertTrue(argProp.getObjectValue() instanceof Argument);
78: Argument arg = (Argument) argProp.getObjectValue();
79: arg.setValue("yahoo");
80: assertEquals("yahoo", arg.getValue());
81: }
82: vars = (Arguments) clonedTestPlan
83: .getUserDefinedVariablesAsProperty().getObjectValue();
84: iter = vars.propertyIterator();
85: while (iter.hasNext()) {
86: assertTrue(iter.next().isRunningVersion());
87: }
88: }
89: }
|