use of org.apache.jmeter.report.core.ConvertException in project jmeter by apache.
the class CustomGraphConsumer method createGroupInfos.
/*
* (non-Javadoc)
*
* @see org.apache.jmeter.report.csv.processor.impl.AbstractGraphConsumer#
* createGroupInfos()
*/
@Override
protected Map<String, GroupInfo> createGroupInfos() {
AbstractSeriesSelector seriesSelector = new AbstractSeriesSelector() {
@Override
public Iterable<String> select(Sample sample) {
return Collections.singletonList(sampleVariableName);
}
};
GraphValueSelector graphValueSelector = (series, sample) -> {
String value;
if (isNativeSampleVariableName) {
value = sample.getData(sampleVariableName);
} else {
value = sample.getData(CSVSaveService.VARIABLE_NAME_QUOTE_CHAR + sampleVariableName + CSVSaveService.VARIABLE_NAME_QUOTE_CHAR);
}
if (StringUtils.isEmpty(value) || "null".equals(value)) {
return null;
}
try {
return Converters.convert(Double.class, value);
} catch (ConvertException e) {
throw new IllegalArgumentException("Double converter failed", e);
}
};
return Collections.singletonMap(AbstractGraphConsumer.DEFAULT_GROUP, new GroupInfo(new MeanAggregatorFactory(), seriesSelector, // We ignore Transaction Controller results
graphValueSelector, false, false));
}
use of org.apache.jmeter.report.core.ConvertException in project jmeter by apache.
the class ReportGenerator method setProperty.
/**
* Try to set a property on an object by reflection.
*
* @param className name of the objects class
* @param obj the object on which the property should be set
* @param methods methods of the object to be searched for the property setter
* @param propertyName name of the property to be set
* @param propertyValue value to be set
* @param setterName name of the property setter that should be used to set the
* property
* @throws IllegalAccessException if reflection throws an IllegalAccessException
* @throws GenerationException if conversion of the property value fails or reflection
* throws an InvocationTargetException
*/
private void setProperty(String className, Object obj, Method[] methods, String propertyName, String propertyValue, String setterName) throws IllegalAccessException, GenerationException {
try {
int i = 0;
while (i < methods.length) {
Method method = methods[i];
if (method.getName().equals(setterName)) {
Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length == 1) {
Class<?> parameterType = parameterTypes[0];
if (parameterType.isAssignableFrom(String.class)) {
method.invoke(obj, propertyValue);
} else {
StringConverter<?> converter = Converters.getConverter(parameterType);
if (converter == null) {
throw new GenerationException(String.format("Not supported conversion to \"%s\"", parameterType.getName()));
}
method.invoke(obj, converter.convert(propertyValue));
}
return;
}
}
i++;
}
log.warn("'{}' is not a valid property for class '{}', skip it", propertyName, className);
} catch (InvocationTargetException | ConvertException ex) {
String message = String.format("Cannot assign \"%s\" to property \"%s\" (mapped as \"%s\"), skip it", propertyValue, propertyName, setterName);
log.error(message, ex);
throw new GenerationException(message, ex);
}
}
Aggregations