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.HTTPSampler2; 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 HttpTestSampleGui2 extends AbstractSamplerGui 42 { 43 private UrlConfigGui urlConfigGui; 44 private JCheckBox getImages; 45 private JCheckBox isMon; 46 47 public HttpTestSampleGui2() 48 { 49 init(); 50 } 51 52 public void configure(TestElement element) 53 { 54 super.configure(element); 55 urlConfigGui.configure(element); 56 getImages.setSelected(((HTTPSampler2) element).isImageParser()); 58 isMon.setSelected(((HTTPSampler2) element).isMonitor()); 59 } 60 61 public TestElement createTestElement() 62 { 63 HTTPSampler2 sampler = new HTTPSampler2(); 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 ((HTTPSampler2)sampler).setImageParser(true); 80 } 81 else 82 { 83 ((HTTPSampler2)sampler).setImageParser(false); 84 } 85 if (isMon.isSelected()){ 86 ((HTTPSampler2)sampler).setMonitor("true"); 87 } else { 88 ((HTTPSampler2)sampler).setMonitor("false"); 89 } 90 this.configureTestElement(sampler); 91 } 92 93 public String getStaticLabel() 94 { 95 return super.getStaticLabel()+" HTTPCLient (ALPHA)"; 96 } 97 public String getLabelResource() 98 { 99 return "web_testing_title"; 100 } 101 102 private void init() 103 { 104 setLayout(new BorderLayout (0, 5)); 105 setBorder(makeBorder()); 106 107 add(makeTitlePanel(), BorderLayout.NORTH); 108 109 urlConfigGui = new MultipartUrlConfigGui(); 111 add(urlConfigGui, BorderLayout.CENTER); 112 113 add(createOptionalTasksPanel(), BorderLayout.SOUTH); 115 } 116 117 private JPanel createOptionalTasksPanel() 118 { 119 HorizontalPanel optionalTasksPanel = new HorizontalPanel(); 121 optionalTasksPanel.setBorder( 122 BorderFactory.createTitledBorder( 123 BorderFactory.createEtchedBorder(), 124 JMeterUtils.getResString("optional_tasks"))); 125 126 JPanel retrieveImagesPanel = new JPanel (); 128 getImages = 129 new JCheckBox ( 130 JMeterUtils.getResString("web_testing_retrieve_images")); 131 retrieveImagesPanel.add(getImages); 132 JPanel isMonitorPanel = new JPanel (); 133 isMon = new JCheckBox ( 134 JMeterUtils.getResString("monitor_is_title")); 135 isMonitorPanel.add(isMon); 136 optionalTasksPanel.add(retrieveImagesPanel); 137 optionalTasksPanel.add(isMonitorPanel); 138 return optionalTasksPanel; 139 } 140 141 public Dimension getPreferredSize() 142 { 143 return getMinimumSize(); 144 } 145 146 public static class Test extends TestCase 147 { 148 HttpTestSampleGui2 gui; 149 150 public Test(String name) 151 { 152 super(name); 153 } 154 155 public void setUp() 156 { 157 gui = new HttpTestSampleGui2(); 158 } 159 160 public void testCloneSampler() throws Exception 161 { 162 HTTPSampler2 sampler = (HTTPSampler2)gui.createTestElement(); 163 sampler.addArgument("param","value"); 164 HTTPSampler2 clonedSampler = (HTTPSampler2)sampler.clone(); 165 clonedSampler.setRunningVersion(true); 166 sampler.getArguments().getArgument(0).setValue("new value"); 167 assertEquals( 168 "Sampler didn't clone correctly", 169 "new value", 170 sampler.getArguments().getArgument(0).getValue()); 171 } 172 } 173 174 177 public void clear() 178 { 179 super.clear(); 180 getImages.setSelected(false); 181 urlConfigGui.clear(); 182 } 183 } 184 | Popular Tags |