alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

JMeter example source code file (DurationAssertionGui.java)

This example JMeter source code file (DurationAssertionGui.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - JMeter tags/keywords

abstractassertiongui, awt, borderlayout, durationassertion, durationassertion, durationassertiongui, gui, jpanel, jpanel, jtextfield, non-nls-1, non-nls-1, override, string, swing, verticalpanel, verticalpanel

The JMeter DurationAssertionGui.java source code

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.apache.jmeter.assertions.gui;

import java.awt.BorderLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.apache.jmeter.assertions.DurationAssertion;
import org.apache.jmeter.gui.util.VerticalPanel;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;

/**
 * GUI for {@link DurationAssertion}
 */
public class DurationAssertionGui extends AbstractAssertionGui {

    private static final long serialVersionUID = 240L;

    private JTextField duration;

    public DurationAssertionGui() {
        init();
    }

    public String getLabelResource() {
        return "duration_assertion_title"; // $NON-NLS-1$
    }

    public String getDurationAttributesTitle() {
        return JMeterUtils.getResString("duration_assertion_duration_test"); // $NON-NLS-1$
    }

    public TestElement createTestElement() {
        DurationAssertion el = new DurationAssertion();
        modifyTestElement(el);
        return el;
    }

    /**
     * Modifies a given TestElement to mirror the data in the gui components.
     *
     * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
     */
    public void modifyTestElement(TestElement el) {
        configureTestElement(el);
        if (el instanceof DurationAssertion) {
            DurationAssertion assertion = (DurationAssertion) el;
            assertion.setProperty(DurationAssertion.DURATION_KEY,duration.getText());
            saveScopeSettings(assertion);
        }
    }

    /**
     * Implements JMeterGUIComponent.clearGui
     */
    @Override
    public void clearGui() {
        super.clearGui();

        duration.setText(""); //$NON-NLS-1$
    }

    @Override
    public void configure(TestElement el) {
        super.configure(el);
        if (el instanceof DurationAssertion){
            DurationAssertion da = (DurationAssertion) el;
            duration.setText(da.getPropertyAsString(DurationAssertion.DURATION_KEY));
            showScopeSettings(da);
        }
    }

    private void init() {
        setLayout(new BorderLayout(0, 10));
        setBorder(makeBorder());

        add(makeTitlePanel(), BorderLayout.NORTH);

        JPanel mainPanel = new VerticalPanel();
        mainPanel.add(createScopePanel());

        // USER_INPUT
        VerticalPanel durationPanel = new VerticalPanel();
        durationPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
                getDurationAttributesTitle()));

        JPanel labelPanel = new JPanel(new BorderLayout(5, 0));
        JLabel durationLabel =
            new JLabel(JMeterUtils.getResString("duration_assertion_label")); // $NON-NLS-1$
        labelPanel.add(durationLabel, BorderLayout.WEST);

        duration = new JTextField();
        labelPanel.add(duration, BorderLayout.CENTER);
        durationLabel.setLabelFor(duration);
        durationPanel.add(labelPanel);

        mainPanel.add(durationPanel);
        add(mainPanel, BorderLayout.CENTER);
    }
}

Other JMeter examples (source code examples)

Here is a short list of links related to this JMeter DurationAssertionGui.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.