1 18 19 package org.apache.jmeter.protocol.http.control.gui; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Dimension ; 23 24 import javax.swing.BorderFactory ; 25 import javax.swing.JCheckBox ; 26 import javax.swing.JPanel ; 27 28 import junit.framework.TestCase; 29 30 import org.apache.jmeter.gui.util.HorizontalPanel; 31 import org.apache.jmeter.protocol.http.config.gui.MultipartUrlConfigGui; 32 import org.apache.jmeter.protocol.http.config.gui.UrlConfigGui; 33 import org.apache.jmeter.protocol.http.sampler.HTTPSampler; 34 import org.apache.jmeter.samplers.gui.AbstractSamplerGui; 35 import org.apache.jmeter.testelement.TestElement; 36 import org.apache.jmeter.util.JMeterUtils; 37 38 41 public class HttpTestSampleGui extends AbstractSamplerGui 42 { 43 private UrlConfigGui urlConfigGui; 44 private JCheckBox getImages; 45 private JCheckBox isMon; 46 47 public HttpTestSampleGui() 48 { 49 init(); 50 } 51 52 public void configure(TestElement element) 53 { 54 super.configure(element); 55 urlConfigGui.configure(element); 56 getImages.setSelected(((HTTPSampler) element).isImageParser()); 58 isMon.setSelected(((HTTPSampler) element).isMonitor()); 59 } 60 61 public TestElement createTestElement() 62 { 63 HTTPSampler sampler = new HTTPSampler(); 64 modifyTestElement(sampler); 65 return sampler; 66 } 67 68 72 public void modifyTestElement(TestElement sampler) 73 { 74 TestElement el = urlConfigGui.createTestElement(); 75 sampler.clear(); 76 sampler.addTestElement(el); 77 if (getImages.isSelected()) 78 { 79 ((HTTPSampler)sampler).setImageParser(true); 80 } 81 else 82 { 83 ((HTTPSampler)sampler).setImageParser(false); 84 } 85 if (isMon.isSelected()){ 86 ((HTTPSampler)sampler).setMonitor("true"); 87 } else { 88 ((HTTPSampler)sampler).setMonitor("false"); 89 } 90 this.configureTestElement(sampler); 91 } 92 93 public String getLabelResource() 94 { 95 return "web_testing_title"; 96 } 97 98 private void init() 99 { 100 setLayout(new BorderLayout (0, 5)); 101 setBorder(makeBorder()); 102 103 add(makeTitlePanel(), BorderLayout.NORTH); 104 105 urlConfigGui = new MultipartUrlConfigGui(); 107 add(urlConfigGui, BorderLayout.CENTER); 108 109 add(createOptionalTasksPanel(), BorderLayout.SOUTH); 111 } 112 113 private JPanel createOptionalTasksPanel() 114 { 115 HorizontalPanel optionalTasksPanel = new HorizontalPanel(); 117 optionalTasksPanel.setBorder( 118 BorderFactory.createTitledBorder( 119 BorderFactory.createEtchedBorder(), 120 JMeterUtils.getResString("optional_tasks"))); 121 122 JPanel retrieveImagesPanel = new JPanel (); 124 getImages = 125 new JCheckBox ( 126 JMeterUtils.getResString("web_testing_retrieve_images")); 127 retrieveImagesPanel.add(getImages); 128 JPanel isMonitorPanel = new JPanel (); 129 isMon = new JCheckBox ( 130 JMeterUtils.getResString("monitor_is_title")); 131 isMonitorPanel.add(isMon); 132 optionalTasksPanel.add(retrieveImagesPanel); 133 optionalTasksPanel.add(isMonitorPanel); 134 return optionalTasksPanel; 135 } 136 137 public Dimension getPreferredSize() 138 { 139 return getMinimumSize(); 140 } 141 142 public static class Test extends TestCase 143 { 144 HttpTestSampleGui gui; 145 146 public Test(String name) 147 { 148 super(name); 149 } 150 151 public void setUp() 152 { 153 gui = new HttpTestSampleGui(); 154 } 155 156 public void testCloneSampler() throws Exception 157 { 158 HTTPSampler sampler = (HTTPSampler)gui.createTestElement(); 159 sampler.addArgument("param","value"); 160 HTTPSampler clonedSampler = (HTTPSampler)sampler.clone(); 161 clonedSampler.setRunningVersion(true); 162 sampler.getArguments().getArgument(0).setValue("new value"); 163 assertEquals( 164 "Sampler didn't clone correctly", 165 "new value", 166 sampler.getArguments().getArgument(0).getValue()); 167 } 168 } 169 170 173 public void clear() 174 { 175 super.clear(); 176 getImages.setSelected(false); 177 urlConfigGui.clear(); 178 } 179 } 180 | Popular Tags |