/** {@inheritDoc} */ @Override public void addProperty(JMeterProperty prop) { addProperty(prop.getName(), prop); }
private String getKeyForURL(HTTPSamplerBase newUrl) { PropertyIterator it = newUrl.propertyIterator(); StringBuilder ret = new StringBuilder(); while (it.hasNext()) { JMeterProperty p = it.next(); ret.append(p.getName()).append("=").append(p.getStringValue()).append("\t"); } return ret.toString(); } }
@Override public void setProperty(JMeterProperty property) { if (isRunningVersion()) { if (getProperty(property.getName()) instanceof NullProperty) { addProperty(property); } else { getProperty(property.getName()).setObjectValue(property.getObjectValue()); } } else { propMap.put(property.getName(), property); } }
private QueryGenerator getQueryGenerator() { if (Objects.isNull(queryGenerator)) { String queryGeneratorClassName = getQueryGeneratorClassName(); try { Map<String, String> map = new HashMap<>(); String queryGeneratorProperties = QueryGenerator.class.getName() + "."; propertyIterator().forEachRemaining(property -> { if (property.getName().startsWith(queryGeneratorProperties)) { map.put(property.getName().substring(queryGeneratorProperties.length()), property.getStringValue()); } }); queryGenerator = (QueryGenerator) Class.forName(queryGeneratorClassName).newInstance(); queryGenerator.setUp(map); logger.debug("Using query generator " + queryGenerator.getClass()); } catch (Throwable e) { logger.error("Error creating QueryGenerator!", e); Throwables.propagate(e); } } return queryGenerator; }
private Map<String, JMeterProperty> cloneMap() { try { @SuppressWarnings("unchecked") // value is the correct class Map<String, JMeterProperty> newCol = value.getClass().newInstance(); PropertyIterator iter = valueIterator(); while (iter.hasNext()) { JMeterProperty item = iter.next(); newCol.put(item.getName(), item.clone()); } return newCol; } catch (Exception e) { log.error("Couldn't clone map", e); return value; } }
@Override public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException { String input = prop.getStringValue(); for (Map.Entry<String, String> entry : getVariables().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); input = StringUtilities.substitute(input, "${" + key + "}", value); } return new StringProperty(prop.getName(), input); } }
/** * Determines if the two objects are equal by comparing names and values * * @return true if names are equal and values are equal (or both null) */ @Override public boolean equals(Object o) { if (!(o instanceof JMeterProperty)) { return false; } if (this == o) { return true; } JMeterProperty jpo = (JMeterProperty) o; if (!name.equals(jpo.getName())) { return false; } Object o1 = getObjectValue(); Object o2 = jpo.getObjectValue(); return o1 == null ? o2 == null : o1.equals(o2); }
private void formatPropertyIterator(StringBuilder sb, PropertyIterator iter) { Map<String, String> map = new HashMap<>(); while (iter.hasNext()) { JMeterProperty item = iter.next(); map.put(item.getName(), item.getStringValue()); } formatSet(sb, map.entrySet()); }
/** * {@inheritDoc}} */ @Override public List<String> getSearchableTokens() { List<String> result = new ArrayList<>(25); PropertyIterator iterator = propertyIterator(); while(iterator.hasNext()) { JMeterProperty jMeterProperty = iterator.next(); result.add(jMeterProperty.getName()); result.add(jMeterProperty.getStringValue()); } return result; }
/** * Add to result the values of propertyNames * @param result List of values of propertyNames * @param propertyNames Set of names of properties to extract */ protected final void addPropertiesValues(List<String> result, Set<String> propertyNames) { PropertyIterator iterator = propertyIterator(); while(iterator.hasNext()) { JMeterProperty jMeterProperty = iterator.next(); if(propertyNames.contains(jMeterProperty.getName())) { result.add(jMeterProperty.getStringValue()); } } } }
public void remove(String prop) { PropertyIterator iter = iterator(); while (iter.hasNext()) { if (iter.next().getName().equals(prop)) { iter.remove(); } } }
/** {@inheritDoc} */ @Override public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext context) { TestElement el = (TestElement) arg0; ConversionHelp.saveSpecialProperties(el,writer); PropertyIterator iter = el.propertyIterator(); while (iter.hasNext()) { JMeterProperty jmp=iter.next(); // Skip special properties if required if (!ConversionHelp.isSpecialProperty(jmp.getName())) { // Don't save empty comments - except for the TestPlan (to maintain compatibility) if (!( TestElement.COMMENTS.equals(jmp.getName()) && jmp.getStringValue().length()==0 && !el.getClass().equals(TestPlan.class) )) { writeItem(jmp, context, writer); } } } }
/** * Log the properties of the test element * * @see TestElement#setProperty(JMeterProperty) */ protected void logProperties() { if (log.isDebugEnabled()) { PropertyIterator iter = propertyIterator(); while (iter.hasNext()) { JMeterProperty prop = iter.next(); log.debug("Property {} is temp? {} and is a {}", prop.getName(), isTemporary(prop), prop.getObjectValue()); } } }
/** * Add property to test element * @param property {@link JMeterProperty} to add to current Test Element * @param clone clone property */ protected void addProperty(JMeterProperty property, boolean clone) { JMeterProperty propertyToPut = property; if(clone) { propertyToPut = property.clone(); } if (isRunningVersion()) { setTemporary(propertyToPut); } else { clearTemporary(property); } JMeterProperty prop = getProperty(property.getName()); if (prop instanceof NullProperty || (prop instanceof StringProperty && prop.getStringValue().isEmpty())) { propMap.put(property.getName(), propertyToPut); } else { prop.mergeIn(propertyToPut); } }
/** {@inheritDoc} */ @Override public void marshal(Object arg0, HierarchicalStreamWriter writer, MarshallingContext context) { TestElementProperty prop = (TestElementProperty) arg0; writer.addAttribute(ConversionHelp.ATT_NAME, ConversionHelp.encode(prop.getName())); Class<?> clazz = prop.getObjectValue().getClass(); writer.addAttribute(ConversionHelp.ATT_ELEMENT_TYPE, mapper().serializedClass(clazz)); TestElement te = (TestElement)prop.getObjectValue(); ConversionHelp.saveSpecialProperties(te,writer); for (JMeterProperty jmp : prop) { // Skip special properties if required if (!ConversionHelp.isSpecialProperty(jmp.getName())) { // Don't save empty comments if (!(TestElement.COMMENTS.equals(jmp.getName()) && jmp.getStringValue().isEmpty())) { writeItem(jmp, context, writer); } } } //TODO clazz is probably always the same as testclass }
@Override public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException { PatternMatcher pm = JMeterUtils.getMatcher(); PatternCompiler compiler = new Perl5Compiler(); String input = prop.getStringValue(); if(input == null) { return prop; } for(Entry<String, String> entry : getVariables().entrySet()){ String key = entry.getKey(); String value = entry.getValue(); if (regexMatch) { try { Pattern pattern = compiler.compile(constructPattern(value)); input = Util.substitute(pm, pattern, new StringSubstitution(FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX), input, Util.SUBSTITUTE_ALL); } catch (MalformedPatternException e) { log.warn("Malformed pattern: {}", value); } } else { input = StringUtilities.substitute(input, value, FUNCTION_REF_PREFIX + key + FUNCTION_REF_SUFFIX); } } return new StringProperty(prop.getName(), input); }
/** * Get values from element to fill propertyMap and setup customizer * @param element TestElement */ private void setValues(TestElement element) { // Copy all property values into the map: for (PropertyIterator jprops = element.propertyIterator(); jprops.hasNext();) { JMeterProperty jprop = jprops.next(); propertyMap.put(jprop.getName(), jprop.getObjectValue()); } if (customizer != null) { customizer.setObject(propertyMap); } else { if (initialized){ remove(customizerIndexInPanel); } Customizer c = customizers.get(element); if (c == null) { c = createCustomizer(); c.setObject(propertyMap); customizers.put(element, c); } add((Component) c, BorderLayout.CENTER); } }
@Override public JMeterProperty transformValue(JMeterProperty prop) throws InvalidVariableException { JMeterProperty newValue = prop; getMasterFunction().clear(); getMasterFunction().setParameters(prop.getStringValue()); if (getMasterFunction().hasFunction()) { newValue = new FunctionProperty(prop.getName(), getMasterFunction().getFunction()); } return newValue; }
if (subProp != null) { // could be null if it has been deleted via NameUpdater if (isHeader) { String name = subProp.getName(); if (TestElement.NAME.equals(name)) { subProp.setName("Header.name");// $NON-NLS-1$
/** * A newly created component can be initialized with the contents of a Test * Element object by calling this method. The component is responsible for * querying the Test Element object for the relevant information to display * in its GUI. * <p> * This implementation retrieves all key/value pairs from the TestElement * object and sets these values in the GUI. * * @param el * the TestElement to configure */ @Override public void configure(TestElement el) { super.configure(el); tableModel.clearData(); PropertyIterator iter = el.propertyIterator(); while (iter.hasNext()) { JMeterProperty prop = iter.next(); tableModel.addRow(new Object[] { prop.getName(), prop.getStringValue() }); } checkDeleteStatus(); }