Hello Sebb, See: ForeachControlPanel#modifyTestElement, I set null when empty.
Do you want me to change this way ? Also when the 2 fields are empty they are not saved. Regards Philippe On Sat, Nov 10, 2012 at 7:00 PM, sebb <[email protected]> wrote: > On 10 November 2012 16:06, <[email protected]> wrote: > > Author: pmouawad > > Date: Sat Nov 10 16:06:20 2012 > > New Revision: 1407842 > > > > URL: http://svn.apache.org/viewvc?rev=1407842&view=rev > > Log: > > Bug 54131 - ForEach Controller : Add start and end index for looping > over variables > > Bugzilla Id: 54131 > > > > Modified: > > > jmeter/trunk/src/components/org/apache/jmeter/control/ForeachController.java > > > jmeter/trunk/src/components/org/apache/jmeter/control/gui/ForeachControlPanel.java > > jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties > > > jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties > > jmeter/trunk/xdocs/changes.xml > > jmeter/trunk/xdocs/usermanual/component_reference.xml > > > > Modified: > jmeter/trunk/src/components/org/apache/jmeter/control/ForeachController.java > > URL: > http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/control/ForeachController.java?rev=1407842&r1=1407841&r2=1407842&view=diff > > > ============================================================================== > > --- > jmeter/trunk/src/components/org/apache/jmeter/control/ForeachController.java > (original) > > +++ > jmeter/trunk/src/components/org/apache/jmeter/control/ForeachController.java > Sat Nov 10 16:06:20 2012 > > @@ -21,10 +21,10 @@ package org.apache.jmeter.control; > > import java.io.Serializable; > > > > import org.apache.jmeter.samplers.Sampler; > > -import org.apache.jmeter.threads.JMeterContext; > > -import org.apache.jmeter.threads.JMeterVariables; > > import org.apache.jmeter.testelement.property.BooleanProperty; > > import org.apache.jmeter.testelement.property.StringProperty; > > +import org.apache.jmeter.threads.JMeterContext; > > +import org.apache.jmeter.threads.JMeterVariables; > > import org.apache.jorphan.logging.LoggingManager; > > import org.apache.log.Logger; > > > > @@ -35,6 +35,10 @@ public class ForeachController extends G > > > > private static final String INPUTVAL = > "ForeachController.inputVal";// $NON-NLS-1$ > > > > + private static final String START_INDEX = > "ForeachController.startIndex";// $NON-NLS-1$ > > + > > + private static final String END_INDEX = > "ForeachController.endIndex";// $NON-NLS-1$ > > + > > private static final String RETURNVAL = > "ForeachController.returnVal";// $NON-NLS-1$ > > > > private static final String USE_SEPARATOR = > "ForeachController.useSeparator";// $NON-NLS-1$ > > @@ -45,7 +49,51 @@ public class ForeachController extends G > > > > public ForeachController() { > > } > > + > > + > > + /** > > + * @param startIndex Start index of loop > > + */ > > + public void setStartIndex(String startIndex) { > > + setProperty(START_INDEX, startIndex != null ? startIndex : "", > ""); > > + } > > That looks wrong. > I don't think GUI fields can ever be null. > Also, it would be better not to create the property if it is not being > used. > > This is easiest if there is a default that can be shared between get and > set. > > > + /** > > + * @return start index of loop > > + */ > > + public int getStartIndex() { > > + return getPropertyAsInt(START_INDEX, 0); > > + } > > + > > + > > + /** > > + * @return start index of loop as String > > + */ > > + public String getStartIndexAsString() { > > + return getPropertyAsString(START_INDEX, ""); > > + } > > + > > + /** > > + * @param endIndex End index of loop > > + */ > > + public void setEndIndex(String endIndex) { > > + setProperty(END_INDEX, endIndex != null ? endIndex : "", ""); > > + } > > + > > + /** > > + * @return end index of loop > > + */ > > + public int getEndIndex() { > > + return getPropertyAsInt(END_INDEX, Integer.MAX_VALUE); > > + } > > + > > + /** > > + * @return end index of loop > > + */ > > + public String getEndIndexAsString() { > > + return getPropertyAsString(END_INDEX, ""); > > + } > > + > > public void setInputVal(String inputValue) { > > setProperty(new StringProperty(INPUTVAL, inputValue)); > > } > > @@ -89,8 +137,16 @@ public class ForeachController extends G > > */ > > @Override > > public boolean isDone() { > > + if (loopCount >= getEndIndex()) { > > + return true; > > + } > > JMeterContext context = getThreadContext(); > > - String inputVariable = getInputVal() + getSeparator() + > (loopCount + 1); > > + StringBuilder builder = new StringBuilder( > > + getInputVal().length()+getSeparator().length()+3); > > + String inputVariable = > > + builder.append(getInputVal()) > > + .append(getSeparator()) > > + .append(Integer.toString(loopCount+1)).toString(); > > final JMeterVariables variables = context.getVariables(); > > final Object currentVariable = > variables.getObject(inputVariable); > > if (currentVariable != null) { > > @@ -132,7 +188,13 @@ public class ForeachController extends G > > */ > > private boolean emptyList() { > > JMeterContext context = getThreadContext(); > > - String inputVariable = getInputVal() + getSeparator() + "1";// > $NON-NLS-1$ > > + > > + StringBuilder builder = new StringBuilder( > > + getInputVal().length()+getSeparator().length()+3); > > + String inputVariable = > > + builder.append(getInputVal()) > > + .append(getSeparator()) > > + .append(Integer.toString(loopCount+1)).toString(); > > if (context.getVariables().getObject(inputVariable) != null) { > > return false; > > } > > @@ -161,7 +223,7 @@ public class ForeachController extends G > > } > > > > protected void resetLoopCount() { > > - loopCount = 0; > > + loopCount = getStartIndex(); > > } > > > > /** > > @@ -191,4 +253,15 @@ public class ForeachController extends G > > super.triggerEndOfLoop(); > > resetLoopCount(); > > } > > + > > + > > + /** > > + * Reset loopCount to Start index > > + * @see org.apache.jmeter.control.GenericController#initialize() > > + */ > > + @Override > > + public void initialize() { > > + super.initialize(); > > + loopCount = getStartIndex(); > > + } > > } > > \ No newline at end of file > > > > Modified: > jmeter/trunk/src/components/org/apache/jmeter/control/gui/ForeachControlPanel.java > > URL: > http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/control/gui/ForeachControlPanel.java?rev=1407842&r1=1407841&r2=1407842&view=diff > > > ============================================================================== > > --- > jmeter/trunk/src/components/org/apache/jmeter/control/gui/ForeachControlPanel.java > (original) > > +++ > jmeter/trunk/src/components/org/apache/jmeter/control/gui/ForeachControlPanel.java > Sat Nov 10 16:06:20 2012 > > @@ -47,6 +47,16 @@ public class ForeachControlPanel extends > > private JTextField inputVal; > > > > /** > > + * A field allowing the user to specify the indice start of the loop > > + */ > > + private JTextField startIndex; > > + > > + /** > > + * A field allowing the user to specify the indice end of the loop > > + */ > > + private JTextField endIndex; > > + > > + /** > > * A field allowing the user to specify output variable the > controller > > * should return. > > */ > > @@ -68,6 +78,11 @@ public class ForeachControlPanel extends > > /** The name of the loops field component. */ > > private static final String RETURNVAL = "Return Field"; // > $NON-NLS-1$ > > > > + /** The name of the start index field component. */ > > + private static final String START_INDEX = "Start Index Field"; // > $NON-NLS-1$ > > + > > + /** The name of the end index field component. */ > > + private static final String END_INDEX = "End Index Field"; // > $NON-NLS-1$ > > /** > > * Create a new LoopControlPanel as a standalone component. > > */ > > @@ -103,6 +118,8 @@ public class ForeachControlPanel extends > > public void configure(TestElement element) { > > super.configure(element); > > inputVal.setText(((ForeachController) > element).getInputValString()); > > + startIndex.setText(((ForeachController) > element).getStartIndexAsString()); > > + endIndex.setText(((ForeachController) > element).getEndIndexAsString()); > > returnVal.setText(((ForeachController) > element).getReturnValString()); > > useSeparator.setSelected(((ForeachController) > element).getUseSeparator()); > > } > > @@ -123,6 +140,16 @@ public class ForeachControlPanel extends > > } else { > > ((ForeachController) lc).setInputVal(""); // $NON-NLS-1$ > > } > > + if (startIndex.getText().length() > 0) { > > + ((ForeachController) > lc).setStartIndex(startIndex.getText()); > > + } else { > > + ((ForeachController) lc).setStartIndex(null); // > $NON-NLS-1$ > > + } > > + if (endIndex.getText().length() > 0) { > > + ((ForeachController) > lc).setEndIndex(endIndex.getText()); > > + } else { > > + ((ForeachController) lc).setEndIndex(null); // > $NON-NLS-1$ > > + } > > if (returnVal.getText().length() > 0) { > > ((ForeachController) > lc).setReturnVal(returnVal.getText()); > > } else { > > @@ -140,6 +167,8 @@ public class ForeachControlPanel extends > > super.clearGui(); > > > > inputVal.setText(""); // $NON-NLS-1$ > > + startIndex.setText(""); // $NON-NLS-1$ > > + endIndex.setText(""); // $NON-NLS-1$ > > returnVal.setText(""); // $NON-NLS-1$ > > useSeparator.setSelected(true); > > } > > @@ -187,6 +216,8 @@ public class ForeachControlPanel extends > > > > // LOOP LABEL > > JLabel inputValLabel = new > JLabel(JMeterUtils.getResString("foreach_input")); // $NON-NLS-1$ > > + JLabel startIndexLabel = new > JLabel(JMeterUtils.getResString("foreach_start_index")); // $NON-NLS-1$ > > + JLabel endIndexLabel = new > JLabel(JMeterUtils.getResString("foreach_end_index")); // $NON-NLS-1$ > > JLabel returnValLabel = new > JLabel(JMeterUtils.getResString("foreach_output")); // $NON-NLS-1$ > > > > // TEXT FIELD > > @@ -198,6 +229,22 @@ public class ForeachControlPanel extends > > inputValSubPanel.add(inputVal, BorderLayout.CENTER); > > > > // TEXT FIELD > > + JPanel startIndexSubPanel = new JPanel(new BorderLayout(5, 0)); > > + startIndex = new JTextField("", 5); // $NON-NLS-1$ > > + startIndex.setName(START_INDEX); > > + startIndexLabel.setLabelFor(startIndex); > > + startIndexSubPanel.add(startIndexLabel, BorderLayout.WEST); > > + startIndexSubPanel.add(startIndex, BorderLayout.CENTER); > > + > > + // TEXT FIELD > > + JPanel endIndexSubPanel = new JPanel(new BorderLayout(5, 0)); > > + endIndex = new JTextField("", 5); // $NON-NLS-1$ > > + endIndex.setName(END_INDEX); > > + endIndexLabel.setLabelFor(endIndex); > > + endIndexSubPanel.add(endIndexLabel, BorderLayout.WEST); > > + endIndexSubPanel.add(endIndex, BorderLayout.CENTER); > > + > > + // TEXT FIELD > > JPanel returnValSubPanel = new JPanel(new BorderLayout(5, 0)); > > returnVal = new JTextField("", 5); // $NON-NLS-1$ > > returnVal.setName(RETURNVAL); > > @@ -207,8 +254,9 @@ public class ForeachControlPanel extends > > > > // Checkbox > > useSeparator = new > JCheckBox(JMeterUtils.getResString("foreach_use_separator"), true); // > $NON-NLS-1$ > > - > > loopPanel.add(inputValSubPanel); > > + loopPanel.add(startIndexSubPanel); > > + loopPanel.add(endIndexSubPanel); > > loopPanel.add(returnValSubPanel); > > loopPanel.add(useSeparator); > > > > > > Modified: > jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties > > URL: > http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties?rev=1407842&r1=1407841&r2=1407842&view=diff > > > ============================================================================== > > --- > jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties > (original) > > +++ > jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties Sat > Nov 10 16:06:20 2012 > > @@ -288,8 +288,10 @@ fontstyle.bold=Bold > > fontstyle.italic=Italic > > fontstyle.normal=Normal > > foreach_controller_title=ForEach Controller > > +foreach_end_index=End index for loop > > foreach_input=Input variable prefix > > foreach_output=Output variable name > > +foreach_start_index=Start index for loop > > foreach_use_separator=Add "_" before number ? > > format=Number format > > fr=French > > > > Modified: > jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties > > URL: > http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties?rev=1407842&r1=1407841&r2=1407842&view=diff > > > ============================================================================== > > --- > jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties > (original) > > +++ > jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties > Sat Nov 10 16:06:20 2012 > > @@ -282,8 +282,10 @@ fontstyle.bold=Gras > > fontstyle.italic=Italique > > fontstyle.normal=Normal > > foreach_controller_title=Contr\u00F4leur Pour chaque (ForEach) > > +foreach_end_index=Indice de fin de la boucle > > foreach_input=Pr\u00E9fixe de la variable d'entr\u00E9e \: > > foreach_output=Nom de la variable de sortie \: > > +foreach_start_index=Indice de d\u00E9but de la boucle > > foreach_use_separator=Ajouter un soulign\u00E9 "_" avant le nombre ? > > format=Format du nombre \: > > fr=Fran\u00E7ais > > > > Modified: jmeter/trunk/xdocs/changes.xml > > URL: > http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1407842&r1=1407841&r2=1407842&view=diff > > > ============================================================================== > > --- jmeter/trunk/xdocs/changes.xml (original) > > +++ jmeter/trunk/xdocs/changes.xml Sat Nov 10 16:06:20 2012 > > @@ -155,6 +155,7 @@ and right angle bracket (>) in search > > > > <h3>Controllers</h3> > > <ul> > > +<li><bugzilla>54131</bugzilla> - ForEach Controller : Add start and end > index for looping over variables</li> > > </ul> > > > > <h3>Listeners</h3> > > > > Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml > > URL: > http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1407842&r1=1407841&r2=1407842&view=diff > > > ============================================================================== > > --- jmeter/trunk/xdocs/usermanual/component_reference.xml (original) > > +++ jmeter/trunk/xdocs/usermanual/component_reference.xml Sat Nov 10 > 16:06:20 2012 > > @@ -2225,6 +2225,8 @@ This would be the case if the Regular Ex > > <properties> > > <property name="Name" required="No">Descriptive name for this > controller that is shown in the tree.</property> > > <property name="Input variable prefix" required="Yes">Prefix > for the variable names to be used as input.</property> > > + <property name="Start index for loop" required="No">Start index > (inclusive) for loop over variables</property> > > + <property name="End index for loop" required="No">End index > (exclusive) for loop over variables</property> > > <property name="Output variable" required="Yes"> > > The name of the variable which can be used in the loop > for replacement in the samplers</property> > > <property required="Yes" name="Use Separator">If not > checked, the "_" separator is omitted.</property> > > > > > -- Cordialement. Philippe Mouawad.
