Coverage Report - kg.apc.jmeter.samplers.DummySamplerGui
 
Classes in this File Line Coverage Branch Coverage Complexity
DummySamplerGui
100%
90/90
50%
1/2
1.1
 
 1  
 // TODO: resolve scrolling issue here and in all other samplers
 2  
 package kg.apc.jmeter.samplers;
 3  
 
 4  
 import kg.apc.jmeter.JMeterPluginsUtils;
 5  
 import kg.apc.jmeter.gui.GuiBuilderHelper;
 6  
 import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
 7  
 import org.apache.jmeter.testelement.TestElement;
 8  
 
 9  
 import javax.swing.*;
 10  
 import java.awt.*;
 11  
 
 12  
 public class DummySamplerGui
 13  
         extends AbstractSamplerGui {
 14  
 
 15  
     public static final String WIKIPAGE = "DummySampler";
 16  
     private JCheckBox isSuccessful;
 17  
     private JTextField responseCode;
 18  
     private JTextField responseMessage;
 19  
     private JTextField responseTime;
 20  
     private JTextArea responseData;
 21  
     private JTextArea requestData;
 22  
     private JCheckBox isWaiting;
 23  
     private JTextField latency;
 24  
     private JTextField connect;
 25  
 
 26  
 
 27  6
     public DummySamplerGui() {
 28  6
         init();
 29  6
     }
 30  
 
 31  
     @Override
 32  
     public String getStaticLabel() {
 33  14
         return JMeterPluginsUtils.prefixLabel("Dummy Sampler");
 34  
     }
 35  
 
 36  
     @Override
 37  
     public void configure(TestElement element) {
 38  1
         super.configure(element);
 39  
 
 40  1
         isSuccessful.setSelected(element.getPropertyAsBoolean(DummySampler.IS_SUCCESSFUL));
 41  1
         isWaiting.setSelected(element.getPropertyAsBoolean(DummySampler.IS_WAITING));
 42  1
         responseCode.setText(element.getPropertyAsString(DummySampler.RESPONSE_CODE));
 43  1
         responseMessage.setText(element.getPropertyAsString(DummySampler.RESPONSE_MESSAGE));
 44  1
         requestData.setText(element.getPropertyAsString(DummySampler.REQUEST_DATA));
 45  1
         responseData.setText(element.getPropertyAsString(DummySampler.RESPONSE_DATA));
 46  1
         responseTime.setText(element.getPropertyAsString(DummySampler.RESPONSE_TIME));
 47  1
         latency.setText(element.getPropertyAsString(DummySampler.LATENCY));
 48  1
         connect.setText(element.getPropertyAsString(DummySampler.CONNECT));
 49  1
     }
 50  
 
 51  
     @Override
 52  
     public TestElement createTestElement() {
 53  1
         DummySampler sampler = new DummySampler();
 54  1
         modifyTestElement(sampler);
 55  1
         sampler.setComment(JMeterPluginsUtils.getWikiLinkText(WIKIPAGE));
 56  1
         return sampler;
 57  
     }
 58  
 
 59  
     /**
 60  
      * Modifies a given TestElement to mirror the data in the gui components.
 61  
      *
 62  
      * @param sampler Sampler
 63  
      * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
 64  
      */
 65  
     @Override
 66  
     public void modifyTestElement(TestElement sampler) {
 67  2
         super.configureTestElement(sampler);
 68  
 
 69  2
         if (sampler instanceof DummySampler) {
 70  2
             DummySampler dummySampler = (DummySampler) sampler;
 71  2
             dummySampler.setSimulateWaiting(isWaiting.isSelected());
 72  2
             dummySampler.setSuccessful(isSuccessful.isSelected());
 73  2
             dummySampler.setResponseCode(responseCode.getText());
 74  2
             dummySampler.setResponseMessage(responseMessage.getText());
 75  2
             dummySampler.setRequestData(requestData.getText());
 76  2
             dummySampler.setResponseData(responseData.getText());
 77  2
             dummySampler.setResponseTime(responseTime.getText());
 78  2
             dummySampler.setLatency(latency.getText());
 79  2
             dummySampler.setConnectTime(connect.getText());
 80  
         }
 81  2
     }
 82  
 
 83  
     @Override
 84  
     public void clearGui() {
 85  1
         super.clearGui();
 86  1
         initFields();
 87  1
     }
 88  
 
 89  
     private void initFields() {
 90  1
         isSuccessful.setSelected(true);
 91  1
         isWaiting.setSelected(true);
 92  1
         responseCode.setText("200");
 93  1
         responseMessage.setText("OK");
 94  1
         requestData.setText("Dummy Sampler used to simulate requests and responses\nwithout actual network activity. This helps debugging tests.");
 95  1
         responseData.setText("Dummy Sampler used to simulate requests and responses\nwithout actual network activity. This helps debugging tests.");
 96  1
         responseTime.setText("${__Random(50,500)}");
 97  1
         latency.setText("${__Random(1,50)}");
 98  1
         connect.setText("${__Random(1,5)}");
 99  1
     }
 100  
 
 101  
     @Override
 102  
     public String getLabelResource() {
 103  1
         return this.getClass().getSimpleName();
 104  
     }
 105  
 
 106  
     private void init() {
 107  6
         setLayout(new BorderLayout(0, 5));
 108  6
         setBorder(makeBorder());
 109  
 
 110  6
         add(JMeterPluginsUtils.addHelpLinkToPanel(makeTitlePanel(), WIKIPAGE), BorderLayout.NORTH);
 111  
 
 112  6
         JPanel mainPanel = new JPanel(new GridBagLayout());
 113  
 
 114  6
         GridBagConstraints labelConstraints = new GridBagConstraints();
 115  6
         labelConstraints.anchor = GridBagConstraints.FIRST_LINE_END;
 116  
 
 117  6
         GridBagConstraints editConstraints = new GridBagConstraints();
 118  6
         editConstraints.anchor = GridBagConstraints.FIRST_LINE_START;
 119  6
         editConstraints.weightx = 1.0;
 120  6
         editConstraints.fill = GridBagConstraints.HORIZONTAL;
 121  
 
 122  6
         addToPanel(mainPanel, labelConstraints, 0, 0, new JLabel("Successfull sample: ", JLabel.RIGHT));
 123  6
         addToPanel(mainPanel, editConstraints, 1, 0, isSuccessful = new JCheckBox());
 124  6
         addToPanel(mainPanel, labelConstraints, 0, 1, new JLabel("Response Code (eg 200): ", JLabel.RIGHT));
 125  6
         addToPanel(mainPanel, editConstraints, 1, 1, responseCode = new JTextField(20));
 126  
 
 127  6
         editConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
 128  6
         labelConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
 129  
 
 130  6
         addToPanel(mainPanel, labelConstraints, 0, 2, new JLabel("Response Message (eg OK): ", JLabel.RIGHT));
 131  6
         addToPanel(mainPanel, editConstraints, 1, 2, responseMessage = new JTextField(20));
 132  6
         addToPanel(mainPanel, labelConstraints, 0, 3, new JLabel("Connect Time (milliseconds): ", JLabel.RIGHT));
 133  6
         addToPanel(mainPanel, editConstraints, 1, 3, connect = new JTextField(20));
 134  6
         addToPanel(mainPanel, labelConstraints, 0, 4, new JLabel("Latency (milliseconds): ", JLabel.RIGHT));
 135  6
         addToPanel(mainPanel, editConstraints, 1, 4, latency = new JTextField(20));
 136  6
         addToPanel(mainPanel, labelConstraints, 0, 5, new JLabel("Response Time (milliseconds): ", JLabel.RIGHT));
 137  6
         addToPanel(mainPanel, editConstraints, 1, 5, responseTime = new JTextField(20));
 138  6
         addToPanel(mainPanel, labelConstraints, 0, 6, new JLabel("Simulate Response Time (sleep): ", JLabel.RIGHT));
 139  6
         addToPanel(mainPanel, editConstraints, 1, 6, isWaiting = new JCheckBox());
 140  
 
 141  6
         editConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
 142  6
         labelConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
 143  
 
 144  6
         addToPanel(mainPanel, labelConstraints, 0, 7, new JLabel("Request Data: ", JLabel.RIGHT));
 145  6
         editConstraints.fill = GridBagConstraints.BOTH;
 146  6
         requestData = new JTextArea();
 147  6
         addToPanel(mainPanel, editConstraints, 1, 7, GuiBuilderHelper.getTextAreaScrollPaneContainer(requestData, 10));
 148  
 
 149  6
         addToPanel(mainPanel, labelConstraints, 0, 8, new JLabel("Response Data: ", JLabel.RIGHT));
 150  6
         editConstraints.fill = GridBagConstraints.BOTH;
 151  
 
 152  6
         responseData = new JTextArea();
 153  6
         addToPanel(mainPanel, editConstraints, 1, 8, GuiBuilderHelper.getTextAreaScrollPaneContainer(responseData, 10));
 154  
 
 155  6
         JPanel container = new JPanel(new BorderLayout());
 156  6
         container.add(mainPanel, BorderLayout.NORTH);
 157  6
         add(container, BorderLayout.CENTER);
 158  6
     }
 159  
 
 160  
     private void addToPanel(JPanel panel, GridBagConstraints constraints, int col, int row, JComponent component) {
 161  108
         constraints.gridx = col;
 162  108
         constraints.gridy = row;
 163  108
         panel.add(component, constraints);
 164  108
     }
 165  
 }