Bug 59967 - CSS/JQuery Extractor : Allow empty default value

Bugzilla Id: 59967

git-svn-id: https://svn.apache.org/repos/asf/jmeter/trunk@1755820 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Philippe Mouawad 2016-08-10 19:55:50 +00:00
parent 55c484b92b
commit 6b5160c08d
6 changed files with 62 additions and 6 deletions

View File

@ -76,6 +76,8 @@ public class HtmlExtractor extends AbstractScopedTestElement implements PostProc
private static final String UNDERSCORE = "_"; // $NON-NLS-1$
private static final String DEFAULT_EMPTY_VALUE = "HtmlExtractor.default_empty_value"; // $NON-NLS-1$
private Extractor extractor;
/**
@ -102,7 +104,7 @@ public class HtmlExtractor extends AbstractScopedTestElement implements PostProc
int matchNumber = getMatchNumber();
final String defaultValue = getDefaultValue();
if (defaultValue.length() > 0){// Only replace default if it is provided
if (defaultValue.length() > 0 || isEmptyDefaultValue()){// Only replace default if it is provided or empty default value is explicitly requested
vars.put(refName, defaultValue);
}
@ -306,6 +308,13 @@ public class HtmlExtractor extends AbstractScopedTestElement implements PostProc
setProperty(DEFAULT, defaultValue);
}
/**
* @param defaultEmptyValue boolean set value to "" if not found
*/
public void setDefaultEmptyValue(boolean defaultEmptyValue) {
setProperty(DEFAULT_EMPTY_VALUE, defaultEmptyValue);
}
/**
* Get the default value for the variable if no matches are found
* @return The default value for the variable
@ -313,4 +322,11 @@ public class HtmlExtractor extends AbstractScopedTestElement implements PostProc
public String getDefaultValue() {
return getPropertyAsString(DEFAULT);
}
/**
* @return boolean set value to "" if not found
*/
public boolean isEmptyDefaultValue() {
return getPropertyAsBoolean(DEFAULT_EMPTY_VALUE);
}
}

View File

@ -22,11 +22,14 @@ import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
@ -64,7 +67,8 @@ public class HtmlExtractorGui extends AbstractPostProcessorGui {
private JComboBox<String> extractorImplName;
private JCheckBox emptyDefaultValue;
public HtmlExtractorGui() {
super();
init();
@ -84,6 +88,7 @@ public class HtmlExtractorGui extends AbstractPostProcessorGui {
expressionField.setText(htmlExtractor.getExpression());
attributeField.setText(htmlExtractor.getAttribute());
defaultField.setText(htmlExtractor.getDefaultValue());
emptyDefaultValue.setSelected(htmlExtractor.isEmptyDefaultValue());
matchNumberField.setText(htmlExtractor.getMatchNumberAsString());
refNameField.setText(htmlExtractor.getRefName());
extractorImplName.setSelectedItem(htmlExtractor.getExtractor());
@ -115,6 +120,7 @@ public class HtmlExtractorGui extends AbstractPostProcessorGui {
htmlExtractor.setExpression(expressionField.getText());
htmlExtractor.setAttribute(attributeField.getText());
htmlExtractor.setDefaultValue(defaultField.getText());
htmlExtractor.setDefaultEmptyValue(emptyDefaultValue.isSelected());
htmlExtractor.setMatchNumber(matchNumberField.getText());
if(extractorImplName.getSelectedIndex()< HtmlExtractor.getImplementations().length) {
htmlExtractor.setExtractor(HtmlExtractor.getImplementations()[extractorImplName.getSelectedIndex()]);
@ -136,6 +142,7 @@ public class HtmlExtractorGui extends AbstractPostProcessorGui {
attributeField.setText(""); //$NON-NLS-1$
defaultField.setText(""); //$NON-NLS-1$
refNameField.setText(""); //$NON-NLS-1$
emptyDefaultValue.setSelected(false);
matchNumberField.setText(""); //$NON-NLS-1$
}
@ -174,7 +181,6 @@ public class HtmlExtractorGui extends AbstractPostProcessorGui {
private JPanel makeParameterPanel() {
expressionField = new JLabeledTextField(JMeterUtils.getResString("expression_field")); //$NON-NLS-1$
attributeField = new JLabeledTextField(JMeterUtils.getResString("attribute_field")); //$NON-NLS-1$
defaultField = new JLabeledTextField(JMeterUtils.getResString("default_value_field")); //$NON-NLS-1$
refNameField = new JLabeledTextField(JMeterUtils.getResString("ref_name_field")); //$NON-NLS-1$
matchNumberField = new JLabeledTextField(JMeterUtils.getResString("match_num_field")); //$NON-NLS-1$
@ -190,7 +196,28 @@ public class HtmlExtractorGui extends AbstractPostProcessorGui {
addField(panel, matchNumberField, gbc);
resetContraints(gbc);
gbc.weighty = 1;
addField(panel, defaultField, gbc);
defaultField = new JLabeledTextField(JMeterUtils.getResString("default_value_field")); //$NON-NLS-1$
List<JComponent> item = defaultField.getComponentList();
panel.add(item.get(0), gbc.clone());
JPanel p = new JPanel(new BorderLayout());
p.add(item.get(1), BorderLayout.WEST);
emptyDefaultValue = new JCheckBox(JMeterUtils.getResString("cssjquery_empty_default_value"));
emptyDefaultValue.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if(emptyDefaultValue.isSelected()) {
defaultField.setText("");
}
defaultField.setEnabled(!emptyDefaultValue.isSelected());
}
});
p.add(emptyDefaultValue, BorderLayout.CENTER);
gbc.gridx++;
gbc.weightx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
panel.add(p, gbc.clone());
return panel;
}

View File

@ -214,6 +214,7 @@ countlim=Size limit
critical_section_controller_label=Lock name
critical_section_controller_title=Critical Section Controller
cssjquery_attribute=Attribute\:
cssjquery_empty_default_value=Use empty default value
cssjquery_tester_error=An error occured evaluating expression:{0}, error:{1}
cssjquery_impl=CSS/JQuery implementation\:
cssjquery_render_no_text=Data response result isn't text.

View File

@ -207,6 +207,7 @@ countlim=Limiter le nombre d'\u00E9l\u00E9ments retourn\u00E9s \u00E0
critical_section_controller_label=Nom du verrou
critical_section_controller_title=Contr\u00F4leur Section critique
cssjquery_attribute=Attribut
cssjquery_empty_default_value=Utiliser la cha\u00EEne vide comme valeur par d\u00E9faut
cssjquery_impl=Impl\u00E9mentation CSS/JQuery\:
cssjquery_render_no_text=Les donn\u00E9es de r\u00E9ponse ne sont pas du texte.
cssjquery_tester_button_test=Tester
@ -219,9 +220,9 @@ cut_paste_function=Fonction de copier/coller de cha\u00EEne de caract\u00E8re
database_conn_pool_max_usage=Utilisation max pour chaque connexion\:
database_conn_pool_props=Pool de connexions \u221A\u2020 la base de donn\u221A\u00A9es
database_conn_pool_size=Nombre de Connexions dans le Pool\:
database_conn_pool_title=Valeurs par d\u221A\u00A9faut du Pool de connexions JDBC
database_conn_pool_title=Valeurs par d\u00E9faut du Pool de connexions JDBC
database_driver_class=Classe du Driver\:
database_login_title=Valeurs par d\u221A\u00A9faut de la base de donn\u221A\u00A9es JDBC
database_login_title=Valeurs par d\u00E9faut de la base de donn\u221A\u00A9es JDBC
database_sql_query_string=Requ\u00EAte SQL \:
database_sql_query_title=Requ\u00EAte SQL JDBC par d\u00E9faut
database_testing_title=Requ\u221A\u2122te JDBC

View File

@ -106,6 +106,7 @@ Summary
<li><pr>212</pr>Allow multiple selection and delete in HTTP Authorization Manager. Based on a patch by Benoit Wiart (b.wiart at ubik-ingenierie.com)</li>
<li><bug>59816</bug><pr>213</pr>Allow multiple selection and delete in HTTP Header Manager.
Based on a patch by Benoit Wiart (b.wiart at ubik-ingenierie.com)</li>
<li><bug>59967</bug>CSS/JQuery Extractor : Allow empty default value. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
</ul>
<h3>Functions</h3>

View File

@ -5656,6 +5656,11 @@ generate the template string, and store the result into the given variable name.
In this case, remove the default value once debugging is complete.
</p>
</property>
<property name="Use empty default value" required="No">
If the checkbox is checked and <code>Default Value</code> is empty, then JMeter will set the variable to empty string instead of not setting it.
Thus when you will for example use <code>${var}</code> (if <code>Reference Name</code> is var) in your Test Plan, if the extracted value is not found then
<code>${var}</code> will be equal to empty string instead of containing <code>${var}</code> which may be useful if extracted value is optional.
</property>
</properties>
<p>
If the match number is set to a non-negative number, and a match occurs, the variables are set as follows:
@ -5765,6 +5770,11 @@ extracting the node as text or attribute value and store the result into the giv
In this case, remove the default value once debugging is complete.
</p>
</property>
<property name="Use empty default value" required="No">
If the checkbox is checked and <code>Default Value</code> is empty, then JMeter will set the variable to empty string instead of not setting it.
Thus when you will for example use <code>${var}</code> (if <code>Reference Name</code> is var) in your Test Plan, if the extracted value is not found then
<code>${var}</code> will be equal to empty string instead of containing <code>${var}</code> which may be useful if extracted value is optional.
</property>
</properties>
<p>
If the match number is set to a non-negative number, and a match occurs, the variables are set as follows: