The change you want to do probably requires changes in the JMeter engine. I created a "User Defined Variables" element to define variables outside of the Test Plan and that's what I had to do. I'm attaching the CVS message for my changes for your reference. If you use latest CVS code, you may be able to subclass my component in some way...
Good luck,
Jordi.
En/na Sonam Chauhan ha escrit:
I tried this code earlier for setting JMeter variable (say, '${var}' -------------- public void modifyTestElement(TestElement el) { el.setProperty( new StringProperty("var","REPLACED")); --------------
Since that didn't work, I tried manipulating the context (saw this type
of coding in RegexExtractor.java):
--------------
public void modifyTestElement(TestElement el)
{
JMeterVariables jmv = new JMeterVariables();
jmv.put("var", "REPLACED");
JMeterContext context = JMeterContextService.getContext();
context.setVariables(jmv);
--------------
It didn't work either. "${var}" stays un-substituted.
If someone could help, that would be great - the Javadoc and the
extension documentation isn't descriptive enough.
With regards, Sonam Chauhan
--- Begin Message ---jsalvata 2003/12/15 09:28:55Modified: src/core/org/apache/jmeter/engine PreCompiler.java src/core/org/apache/jmeter/config/gui ArgumentsPanel.java xdocs/usermanual component_reference.xml src/protocol/java/org/apache/jmeter/protocol/java/config/gui JavaConfigGui.java Added: xdocs/images/screenshots user_defined_variables.png Log: New "User Defined Variables" component will complement those in the Test Plan -- with the advantage that these can be enabled/disabled. Revision Changes Path 1.18 +21 -6 jakarta-jmeter/src/core/org/apache/jmeter/engine/PreCompiler.java Index: PreCompiler.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/engine/PreCompiler.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- PreCompiler.java 19 Oct 2003 22:22:22 -0000 1.17 +++ PreCompiler.java 15 Dec 2003 17:28:55 -0000 1.18 @@ -1,5 +1,9 @@ package org.apache.jmeter.engine; +import java.util.Iterator; +import java.util.Map; + +import org.apache.jmeter.config.Arguments; import org.apache.jmeter.engine.util.ValueReplacer; import org.apache.jmeter.functions.InvalidVariableException; import org.apache.jmeter.testelement.TestElement; @@ -32,13 +36,13 @@ { if (node instanceof TestPlan) { - replacer.setUserDefinedVariables( - ((TestPlan) node).getUserDefinedVariables()); - JMeterVariables vars = new JMeterVariables(); - vars.putAll(((TestPlan) node).getUserDefinedVariables()); + Map args= ((TestPlan)node).getUserDefinedVariables(); + replacer.setUserDefinedVariables(args); + JMeterVariables vars= new JMeterVariables(); + vars.putAll(args); JMeterContextService.getContext().setVariables(vars); } - if (node instanceof TestElement) + else if (node instanceof TestElement) { try { @@ -49,6 +53,17 @@ { log.error("invalid variables", e); } + } + + if (node instanceof Arguments) + { + Map args= ((Arguments)node).getArgumentsAsMap(); + for (Iterator a= args.entrySet().iterator(); a.hasNext(); ) + { + Map.Entry e= (Map.Entry)a.next(); + replacer.addVariable((String)e.getKey(), (String)e.getValue()); + } + JMeterContextService.getContext().getVariables().putAll(args); } } 1.22 +49 -28 jakarta-jmeter/src/core/org/apache/jmeter/config/gui/ArgumentsPanel.java Index: ArgumentsPanel.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/config/gui/ArgumentsPanel.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- ArgumentsPanel.java 5 Oct 2003 01:05:31 -0000 1.21 +++ ArgumentsPanel.java 15 Dec 2003 17:28:55 -0000 1.22 @@ -108,6 +108,12 @@ /** A button for removing arguments from the table. */ private JButton delete; + /** + * Boolean indicating whether this component is a standalong component or + * it is intended to be used as a subpanel for another component. + */ + private boolean standalone = true; + /** Command for adding a row to the table. */ private static final String ADD = "add"; @@ -122,41 +128,51 @@ }; /** - * Create a new ArgumentsPanel, using the default title. + * Create a new ArgumentsPanel as a standalone component. */ public ArgumentsPanel() { - this(JMeterUtils.getResString("paramtable")); + tableLabel= new JLabel(JMeterUtils.getResString("user_defined_variables")); + standalone = true; + init(); } /** - * Create a new ArgumentsPanel, using the specified title. - * - * @param label the title of the component + * Create a new ArgumentsPanel as an embedded component, using the specified + * title. + * + * @param label the title for the component. */ public ArgumentsPanel(String label) { tableLabel = new JLabel(label); + standalone = false; init(); } /** * This is the list of menu categories this gui component will be available - * under. The ArgumentsPanel is not intended to be used as a standalone - * component, so this inplementation returns null. + * under. * * @return a Collection of Strings, where each element is one of the * constants defined in MenuFactory */ public Collection getMenuCategories() { - return null; - } - + if (standalone) + { + return super.getMenuCategories(); + } + else + { + return null; + } + } + /* Implements JMeterGUIComponent.getStaticLabel() */ public String getStaticLabel() { - return "Argument List"; + return JMeterUtils.getResString("user_defined_variables"); } /* Implements JMeterGUIComponent.createTestElement() */ @@ -164,9 +180,7 @@ { Arguments args = new Arguments(); modifyTestElement(args); - // TODO: Why do we clone the return value? This is the only reference - // to it (right?) so we shouldn't need a separate copy. - return (TestElement) args.clone(); + return args; } /* Implements JMeterGUIComponent.modifyTestElement(TestElement) */ @@ -419,14 +433,6 @@ { initializeTableModel(); table = new JTable(tableModel); - //table.addFocusListener(this); - // use default editor/renderer to fix bug #16058 - // TextAreaTableCellEditor editor = new TextAreaTableCellEditor(); - // table.setDefaultEditor(String.class, editor); - // editor.addCellEditorListener(this); - // TextAreaCellRenderer renderer = new TextAreaCellRenderer(); - // table.setRowHeight(renderer.getPreferredHeight()); - // table.setDefaultRenderer(String.class,renderer); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); return makeScrollPane(table); } @@ -473,13 +479,28 @@ */ private void init() { - setLayout(new BorderLayout()); + JPanel p= this; + + if (standalone) + { + setLayout(new BorderLayout(0,5)); + setBorder(makeBorder()); + add(makeTitlePanel(), BorderLayout.NORTH); + p= new JPanel(); + } + + p.setLayout(new BorderLayout()); - add(makeLabelPanel(), BorderLayout.NORTH); - add(makeMainPanel(), BorderLayout.CENTER); + p.add(makeLabelPanel(), BorderLayout.NORTH); + p.add(makeMainPanel(), BorderLayout.CENTER); // Force a minimum table height of 70 pixels - add(Box.createVerticalStrut(70), BorderLayout.WEST); - add(makeButtonPanel(), BorderLayout.SOUTH); + p.add(Box.createVerticalStrut(70), BorderLayout.WEST); + p.add(makeButtonPanel(), BorderLayout.SOUTH); + + if (standalone) + { + add(p, BorderLayout.CENTER); + } table.revalidate(); sizeColumns(table); 1.66 +70 -3 jakarta-jmeter/xdocs/usermanual/component_reference.xml Index: component_reference.xml =================================================================== RCS file: /home/cvs/jakarta-jmeter/xdocs/usermanual/component_reference.xml,v retrieving revision 1.65 retrieving revision 1.66 diff -u -r1.65 -r1.66 --- component_reference.xml 3 Dec 2003 12:33:29 -0000 1.65 +++ component_reference.xml 15 Dec 2003 17:28:55 -0000 1.66 @@ -1,4 +1,58 @@ <?xml version="1.0"?> +<!-- + * ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache JMeter" must not be used to endorse or promote products + * derived from this software without prior written permission. For + * written permission, please contact [EMAIL PROTECTED] + * + * 5. Products derived from this software may not be called "Apache", + * "Apache JMeter", nor may "Apache" appear in their name, without + * prior written permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + --> <document index="yes" index-level-2="yes" colbreak="13.5" prev="boss.html" next="functions.html" date="$Date$"> @@ -99,8 +153,8 @@ a multipart form request.</property> <property name="Parameter Name" required="No (Yes if Filename filled in)">Name of the web request parameter.</property> <property name="MIME Type" required="No (Yes if Filename filled in)">MIME type (for example, text/plain).</property> - <property name="Retrieve All Images and Java Applets" required="No">Tell JMeter to parse the HTML file -and send HTTP/HTTPS requests for all images and Java applets referenced in the file.</property> + <property name="Retrieve All Embedded Resources from HTML Files" required="No">Tell JMeter to parse the HTML file +and send HTTP/HTTPS requests for all images, Java applets, JavaScript files, CSSs, etc. referenced in the file.</property> </properties> <links> @@ -1108,6 +1162,19 @@ <description><p>The Java Request Defaults component lets you set default values for Java testing. See the <complink name="Java Request"/>.</p> </description> +</component> + +<component index="13.4.14" name="User Defined Variables" screenshot="user_defined_variables.png"> +<description><p>The User Defined Variables lets you define variables for use in other test elements, just as in the <complink name="Test Plan"/>. +The variables in User Defined Variables components will take precedence over those defined closer to the tree root -- including those defined in the Test Plan.</p> +<p>Note that the variable's values have to be static: you can't currently use other variables in their definition.</p> +</description> +<properties> + <property name="Name" required="">Descriptive name for this element that is shown in the tree.</property> + <property name="User Defined Variables" required="">Variable name/value pairs. The string under the "Name" + column is what you'll need to place inside the brackets in ${...} constructs to use the variables later on. The + whole ${...} will then be replaced by the string in the "Value" column.</property> +</properties> </component> </section> 1.16 +2 -2 jakarta-jmeter/src/protocol/java/org/apache/jmeter/protocol/java/config/gui/JavaConfigGui.java Index: JavaConfigGui.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/protocol/java/org/apache/jmeter/protocol/java/config/gui/JavaConfigGui.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- JavaConfigGui.java 7 Sep 2003 18:58:17 -0000 1.15 +++ JavaConfigGui.java 15 Dec 2003 17:28:55 -0000 1.16 @@ -285,7 +285,7 @@ */ private JPanel createParameterPanel() { - argsPanel = new ArgumentsPanel(); + argsPanel = new ArgumentsPanel(JMeterUtils.getResString("paramtable")); return argsPanel; } 1.1 jakarta-jmeter/xdocs/images/screenshots/user_defined_variables.png <<Binary file>> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--- End Message ---
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
