use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class TestBeanHelper method prepare.
/**
* Prepare the bean for work by populating the bean's properties from the
* property value map.
* <p>
*
* @param el the TestElement to be prepared
*/
public static void prepare(TestElement el) {
if (!(el instanceof TestBean)) {
return;
}
try {
BeanInfo beanInfo = Introspector.getBeanInfo(el.getClass());
PropertyDescriptor[] descs = beanInfo.getPropertyDescriptors();
if (log.isDebugEnabled()) {
log.debug("Preparing {}", el.getClass());
}
for (PropertyDescriptor desc : descs) {
if (isDescriptorIgnored(desc)) {
if (log.isDebugEnabled()) {
log.debug("Ignoring property '{}' in {}", desc.getName(), el.getClass().getCanonicalName());
}
continue;
}
// Obtain a value of the appropriate type for this property.
JMeterProperty jprop = el.getProperty(desc.getName());
Class<?> type = desc.getPropertyType();
Object value = unwrapProperty(desc, jprop, type);
if (log.isDebugEnabled()) {
log.debug("Setting {}={}", jprop.getName(), value);
}
// Set the bean's property to the value we just obtained:
if (value != null || !type.isPrimitive()) // We can't assign null to primitive types.
{
Method writeMethod = desc.getWriteMethod();
if (writeMethod != null) {
invokeOrBailOut(el, writeMethod, new Object[] { value });
}
}
}
} catch (IntrospectionException e) {
log.error("Couldn't set properties for {}", el.getClass(), e);
} catch (UnsatisfiedLinkError ule) {
// Can occur running headless on Jenkins
log.error("Couldn't set properties for {}", el.getClass());
throw ule;
}
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class TestBeanGUI method setPropertyInElement.
/**
* @param element
* @param name
*/
private void setPropertyInElement(TestElement element, String name, Object value) {
JMeterProperty jprop = AbstractProperty.createProperty(value);
jprop.setName(name);
element.setProperty(jprop);
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class TestElementConverter method unmarshal.
/** {@inheritDoc} */
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
String classAttribute = reader.getAttribute(ConversionHelp.ATT_CLASS);
Class<?> type;
if (classAttribute == null) {
type = mapper().realClass(reader.getNodeName());
} else {
type = mapper().realClass(classAttribute);
}
// Update the test class name if necessary (Bug 52466)
String inputName = type.getName();
String targetName = inputName;
String guiClassName = SaveService.aliasToClass(reader.getAttribute(ConversionHelp.ATT_TE_GUICLASS));
targetName = NameUpdater.getCurrentTestName(inputName, guiClassName);
if (!targetName.equals(inputName)) {
// remap the class name
type = mapper().realClass(targetName);
}
// needed by property converters (Bug 52466)
context.put(SaveService.TEST_CLASS_NAME, targetName);
try {
TestElement el = (TestElement) type.newInstance();
// No need to check version, just process the attributes if present
ConversionHelp.restoreSpecialProperties(el, reader);
// Slight hack - we need to ensure the TestClass is not reset by the previous call
el.setProperty(TestElement.TEST_CLASS, targetName);
while (reader.hasMoreChildren()) {
reader.moveDown();
JMeterProperty prop = (JMeterProperty) readItem(reader, context, el);
if (prop != null) {
// could be null if it has been deleted via NameUpdater
el.setProperty(prop);
}
reader.moveUp();
}
return el;
} catch (InstantiationException | IllegalAccessException e) {
log.error("TestElement not instantiable: {}", type, e);
return null;
}
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class BackendListenerGui method actionPerformed.
/**
* Handle action events for this component. This method currently handles
* events for the classname combo box.
*
* @param event
* the ActionEvent to be handled
*/
@Override
public void actionPerformed(ActionEvent event) {
if (event.getSource() == classnameCombo) {
String className = ((String) classnameCombo.getSelectedItem()).trim();
try {
BackendListenerClient client = (BackendListenerClient) Class.forName(className, true, Thread.currentThread().getContextClassLoader()).newInstance();
Arguments currArgs = new Arguments();
argsPanel.modifyTestElement(currArgs);
Map<String, String> currArgsMap = currArgs.getArgumentsAsMap();
Arguments newArgs = new Arguments();
Arguments testParams = null;
try {
testParams = client.getDefaultParameters();
} catch (AbstractMethodError e) {
log.warn("BackendListenerClient doesn't implement " + "getDefaultParameters. Default parameters won't " + "be shown. Please update your client class: {}", className);
}
if (testParams != null) {
for (JMeterProperty jMeterProperty : testParams.getArguments()) {
Argument arg = (Argument) jMeterProperty.getObjectValue();
String name = arg.getName();
String value = arg.getValue();
// values that they did in the original test.
if (currArgsMap.containsKey(name)) {
String newVal = currArgsMap.get(name);
if (newVal != null && newVal.length() > 0) {
value = newVal;
}
}
newArgs.addArgument(name, value);
}
}
argsPanel.configure(newArgs);
} catch (Exception e) {
log.error("Error getting argument list for {}", className, e);
}
}
}
use of org.apache.jmeter.testelement.property.JMeterProperty in project jmeter by apache.
the class UrlConfigGui method computePostBody.
/**
* Compute body data from arguments
* @param arguments {@link Arguments}
* @param crlfToLF whether to convert CRLF to LF
* @return {@link String}
*/
private static String computePostBody(Arguments arguments, boolean crlfToLF) {
StringBuilder postBody = new StringBuilder();
for (JMeterProperty argument : arguments) {
HTTPArgument arg = (HTTPArgument) argument.getObjectValue();
String value = arg.getValue();
if (crlfToLF) {
// See modifyTestElement
value = value.replaceAll("\r\n", "\n");
}
postBody.append(value);
}
return postBody.toString();
}
Aggregations