KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > protocol > http > control > gui > HttpTestSampleGui2


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui2.java,v 1.2 2004/03/20 22:09:29 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.protocol.http.control.gui;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Dimension JavaDoc;
23
24 import javax.swing.BorderFactory JavaDoc;
25 import javax.swing.JCheckBox JavaDoc;
26 import javax.swing.JPanel JavaDoc;
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 /**
39  * @version $Revision: 1.2 $ on $Date: 2004/03/20 22:09:29 $
40  */

41 public class HttpTestSampleGui2 extends AbstractSamplerGui
42 {
43     private UrlConfigGui urlConfigGui;
44     private JCheckBox JavaDoc getImages;
45     private JCheckBox JavaDoc 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         //NOTUSED String testClass = element.getPropertyAsString(TestElement.TEST_CLASS);
57
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     /**
69      * Modifies a given TestElement to mirror the data in the gui components.
70      * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
71      */

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 JavaDoc getStaticLabel()
94     {
95         return super.getStaticLabel()+" HTTPCLient (ALPHA)";
96     }
97     public String JavaDoc getLabelResource()
98     {
99         return "web_testing_title";
100     }
101
102     private void init()
103     {
104         setLayout(new BorderLayout JavaDoc(0, 5));
105         setBorder(makeBorder());
106
107         add(makeTitlePanel(), BorderLayout.NORTH);
108
109         // URL CONFIG
110
urlConfigGui = new MultipartUrlConfigGui();
111         add(urlConfigGui, BorderLayout.CENTER);
112
113         // OPTIONAL TASKS
114
add(createOptionalTasksPanel(), BorderLayout.SOUTH);
115     }
116
117     private JPanel JavaDoc createOptionalTasksPanel()
118     {
119         // OPTIONAL TASKS
120
HorizontalPanel optionalTasksPanel = new HorizontalPanel();
121         optionalTasksPanel.setBorder(
122             BorderFactory.createTitledBorder(
123                 BorderFactory.createEtchedBorder(),
124                 JMeterUtils.getResString("optional_tasks")));
125
126         // RETRIEVE IMAGES
127
JPanel JavaDoc retrieveImagesPanel = new JPanel JavaDoc();
128         getImages =
129             new JCheckBox JavaDoc(
130                 JMeterUtils.getResString("web_testing_retrieve_images"));
131         retrieveImagesPanel.add(getImages);
132         JPanel JavaDoc isMonitorPanel = new JPanel JavaDoc();
133         isMon = new JCheckBox JavaDoc(
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 JavaDoc getPreferredSize()
142     {
143         return getMinimumSize();
144     }
145
146     public static class Test extends TestCase
147     {
148         HttpTestSampleGui2 gui;
149         
150         public Test(String JavaDoc name)
151         {
152             super(name);
153         }
154         
155         public void setUp()
156         {
157             gui = new HttpTestSampleGui2();
158         }
159         
160         public void testCloneSampler() throws Exception JavaDoc
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     /* (non-Javadoc)
175      * @see org.apache.jmeter.gui.JMeterGUIComponent#clear()
176      */

177     public void clear()
178     {
179         super.clear();
180         getImages.setSelected(false);
181         urlConfigGui.clear();
182     }
183 }
184
Popular Tags