KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Header: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java,v 1.19 2004/03/16 13:57:51 woolfel 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.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 /**
39  * @version $Revision: 1.19 $ on $Date: 2004/03/16 13:57:51 $
40  */

41 public class HttpTestSampleGui extends AbstractSamplerGui
42 {
43     private UrlConfigGui urlConfigGui;
44     private JCheckBox JavaDoc getImages;
45     private JCheckBox JavaDoc 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         //NOTUSED String testClass = element.getPropertyAsString(TestElement.TEST_CLASS);
57
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     /**
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             ((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 JavaDoc getLabelResource()
94     {
95         return "web_testing_title";
96     }
97
98     private void init()
99     {
100         setLayout(new BorderLayout JavaDoc(0, 5));
101         setBorder(makeBorder());
102
103         add(makeTitlePanel(), BorderLayout.NORTH);
104
105         // URL CONFIG
106
urlConfigGui = new MultipartUrlConfigGui();
107         add(urlConfigGui, BorderLayout.CENTER);
108
109         // OPTIONAL TASKS
110
add(createOptionalTasksPanel(), BorderLayout.SOUTH);
111     }
112
113     private JPanel JavaDoc createOptionalTasksPanel()
114     {
115         // OPTIONAL TASKS
116
HorizontalPanel optionalTasksPanel = new HorizontalPanel();
117         optionalTasksPanel.setBorder(
118             BorderFactory.createTitledBorder(
119                 BorderFactory.createEtchedBorder(),
120                 JMeterUtils.getResString("optional_tasks")));
121
122         // RETRIEVE IMAGES
123
JPanel JavaDoc retrieveImagesPanel = new JPanel JavaDoc();
124         getImages =
125             new JCheckBox JavaDoc(
126                 JMeterUtils.getResString("web_testing_retrieve_images"));
127         retrieveImagesPanel.add(getImages);
128         JPanel JavaDoc isMonitorPanel = new JPanel JavaDoc();
129         isMon = new JCheckBox JavaDoc(
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 JavaDoc getPreferredSize()
138     {
139         return getMinimumSize();
140     }
141
142     public static class Test extends TestCase
143     {
144         HttpTestSampleGui gui;
145         
146         public Test(String JavaDoc name)
147         {
148             super(name);
149         }
150         
151         public void setUp()
152         {
153             gui = new HttpTestSampleGui();
154         }
155         
156         public void testCloneSampler() throws Exception JavaDoc
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     /* (non-Javadoc)
171      * @see org.apache.jmeter.gui.JMeterGUIComponent#clear()
172      */

173     public void clear()
174     {
175         super.clear();
176         getImages.setSelected(false);
177         urlConfigGui.clear();
178     }
179 }
180
Popular Tags