Search in sources :

Example 1 with JavaSamplerClient

use of org.apache.jmeter.protocol.java.sampler.JavaSamplerClient in project jmeter by apache.

the class JavaConfigGui method configureClassName.

/**
     * 
     */
private void configureClassName() {
    String className = classNameLabeledChoice.getText().trim();
    try {
        JavaSamplerClient client = (JavaSamplerClient) 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("JavaSamplerClient 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);
        warningLabel.setVisible(false);
    } catch (Exception e) {
        log.error("Error getting argument list for " + className, e);
        warningLabel.setVisible(true);
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) Arguments(org.apache.jmeter.config.Arguments) JavaSamplerClient(org.apache.jmeter.protocol.java.sampler.JavaSamplerClient)

Example 2 with JavaSamplerClient

use of org.apache.jmeter.protocol.java.sampler.JavaSamplerClient in project jmeter by apache.

the class JavaConfigGui method createClassnamePanel.

/**
     * Create a panel with GUI components allowing the user to select a test
     * class.
     *
     * @return a panel containing the relevant components
     */
private JPanel createClassnamePanel() {
    List<String> possibleClasses = new ArrayList<>();
    try {
        // Find all the classes which implement the JavaSamplerClient
        // interface.
        possibleClasses = ClassFinder.findClassesThatExtend(JMeterUtils.getSearchPaths(), new Class[] { JavaSamplerClient.class });
        // Remove the JavaConfig class from the list since it only
        // implements the interface for error conditions.
        possibleClasses.remove(JavaSampler.class.getName() + "$ErrorSamplerClient");
    } catch (Exception e) {
        log.debug("Exception getting interfaces.", e);
    }
    classNameLabeledChoice = new JLabeledChoice(JMeterUtils.getResString("protocol_java_classname"), possibleClasses.toArray(ArrayUtils.EMPTY_STRING_ARRAY), true, false);
    classNameLabeledChoice.addChangeListener(this);
    warningLabel.setForeground(Color.RED);
    Font font = warningLabel.getFont();
    warningLabel.setFont(new Font(font.getFontName(), Font.BOLD, (int) (font.getSize() * 1.1)));
    warningLabel.setVisible(false);
    VerticalPanel panel = new VerticalPanel();
    panel.add(classNameLabeledChoice);
    panel.add(warningLabel);
    return panel;
}
Also used : VerticalPanel(org.apache.jmeter.gui.util.VerticalPanel) JLabeledChoice(org.apache.jorphan.gui.JLabeledChoice) ArrayList(java.util.ArrayList) JavaSamplerClient(org.apache.jmeter.protocol.java.sampler.JavaSamplerClient) Font(java.awt.Font)

Aggregations

JavaSamplerClient (org.apache.jmeter.protocol.java.sampler.JavaSamplerClient)2 Font (java.awt.Font)1 ArrayList (java.util.ArrayList)1 Argument (org.apache.jmeter.config.Argument)1 Arguments (org.apache.jmeter.config.Arguments)1 VerticalPanel (org.apache.jmeter.gui.util.VerticalPanel)1 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)1 JLabeledChoice (org.apache.jorphan.gui.JLabeledChoice)1