You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2005/05/03 01:51:57 UTC
cvs commit: jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/gui HttpTestSampleGui.java HttpTestSampleGui2.java
sebb 2005/05/02 16:51:57
Modified: src/protocol/http/org/apache/jmeter/protocol/http/control/gui
HttpTestSampleGui.java HttpTestSampleGui2.java
Added: src/protocol/http/org/apache/jmeter/protocol/http/sampler
HTTPSamplerFactory.java
Log:
Refactor to reduce code duplication
Revision Changes Path
1.1 jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerFactory.java
Index: HTTPSamplerFactory.java
===================================================================
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.jmeter.protocol.http.sampler;
import org.apache.jmeter.util.JMeterUtils;
/**
* Factory to return the appropriate HTTPSampler for use with classes
* that need an HTTPSampler
*
*/
public class HTTPSamplerFactory {
private static final String HTTP_SAMPLER = "HTTPSampler"; //$NON-NLS-1$
private static final String HTTP_SAMPLER_APACHE = "HTTPSampler2"; //$NON-NLS-1$
private static final String DEFAULT_CLASSNAME =
JMeterUtils.getPropDefault("jmeter.httpsampler",HTTP_SAMPLER); //$NON-NLS-1$
private HTTPSamplerFactory()
{
//Not intended to be instantiated
}
public static HTTPSamplerBase newInstance()
{
return newInstance(DEFAULT_CLASSNAME);
}
public static HTTPSamplerBase newInstance(String classname)
{
if (classname.equals(HTTP_SAMPLER))
{
return new HTTPSampler();
}
if (classname.equals(HTTP_SAMPLER_APACHE))
{
return new HTTPSampler2();
}
throw new UnsupportedOperationException("Cannot create class: "+classname);
}
}
1.20 +15 -15 jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java
Index: HttpTestSampleGui.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- HttpTestSampleGui.java 16 Mar 2004 13:57:51 -0000 1.19
+++ HttpTestSampleGui.java 2 May 2005 23:51:57 -0000 1.20
@@ -1,6 +1,6 @@
// $Header$
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,8 @@
import org.apache.jmeter.gui.util.HorizontalPanel;
import org.apache.jmeter.protocol.http.config.gui.MultipartUrlConfigGui;
import org.apache.jmeter.protocol.http.config.gui.UrlConfigGui;
-import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
+import org.apache.jmeter.protocol.http.sampler.HTTPSamplerFactory;
+import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.JMeterUtils;
@@ -53,14 +54,13 @@
{
super.configure(element);
urlConfigGui.configure(element);
- //NOTUSED String testClass = element.getPropertyAsString(TestElement.TEST_CLASS);
- getImages.setSelected(((HTTPSampler) element).isImageParser());
- isMon.setSelected(((HTTPSampler) element).isMonitor());
+ getImages.setSelected(((HTTPSamplerBase) element).isImageParser());
+ isMon.setSelected(((HTTPSamplerBase) element).isMonitor());
}
public TestElement createTestElement()
{
- HTTPSampler sampler = new HTTPSampler();
+ HTTPSamplerBase sampler = HTTPSamplerFactory.newInstance("HTTPSampler");
modifyTestElement(sampler);
return sampler;
}
@@ -76,16 +76,16 @@
sampler.addTestElement(el);
if (getImages.isSelected())
{
- ((HTTPSampler)sampler).setImageParser(true);
+ ((HTTPSamplerBase)sampler).setImageParser(true);
}
else
{
- ((HTTPSampler)sampler).setImageParser(false);
+ ((HTTPSamplerBase)sampler).setImageParser(false);
}
if (isMon.isSelected()){
- ((HTTPSampler)sampler).setMonitor("true");
+ ((HTTPSamplerBase)sampler).setMonitor("true");
} else {
- ((HTTPSampler)sampler).setMonitor("false");
+ ((HTTPSamplerBase)sampler).setMonitor("false");
}
this.configureTestElement(sampler);
}
@@ -95,7 +95,7 @@
return "web_testing_title";
}
- private void init()
+ protected void init()
{
setLayout(new BorderLayout(0, 5));
setBorder(makeBorder());
@@ -155,9 +155,9 @@
public void testCloneSampler() throws Exception
{
- HTTPSampler sampler = (HTTPSampler)gui.createTestElement();
+ HTTPSamplerBase sampler = (HTTPSamplerBase)gui.createTestElement();
sampler.addArgument("param","value");
- HTTPSampler clonedSampler = (HTTPSampler)sampler.clone();
+ HTTPSamplerBase clonedSampler = (HTTPSamplerBase)sampler.clone();
clonedSampler.setRunningVersion(true);
sampler.getArguments().getArgument(0).setValue("new value");
assertEquals(
1.3 +8 -144 jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui2.java
Index: HttpTestSampleGui2.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/control/gui/HttpTestSampleGui2.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HttpTestSampleGui2.java 20 Mar 2004 22:09:29 -0000 1.2
+++ HttpTestSampleGui2.java 2 May 2005 23:51:57 -0000 1.3
@@ -1,6 +1,6 @@
// $Header$
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,166 +18,30 @@
package org.apache.jmeter.protocol.http.control.gui;
-import java.awt.BorderLayout;
-import java.awt.Dimension;
-
-import javax.swing.BorderFactory;
-import javax.swing.JCheckBox;
-import javax.swing.JPanel;
-
-import junit.framework.TestCase;
-
-import org.apache.jmeter.gui.util.HorizontalPanel;
-import org.apache.jmeter.protocol.http.config.gui.MultipartUrlConfigGui;
-import org.apache.jmeter.protocol.http.config.gui.UrlConfigGui;
-import org.apache.jmeter.protocol.http.sampler.HTTPSampler2;
-import org.apache.jmeter.samplers.gui.AbstractSamplerGui;
+import org.apache.jmeter.protocol.http.sampler.HTTPSamplerFactory;
+import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
import org.apache.jmeter.testelement.TestElement;
-import org.apache.jmeter.util.JMeterUtils;
/**
* @version $Revision$ on $Date$
*/
-public class HttpTestSampleGui2 extends AbstractSamplerGui
+public class HttpTestSampleGui2 extends HttpTestSampleGui
{
- private UrlConfigGui urlConfigGui;
- private JCheckBox getImages;
- private JCheckBox isMon;
public HttpTestSampleGui2()
{
- init();
- }
-
- public void configure(TestElement element)
- {
- super.configure(element);
- urlConfigGui.configure(element);
- //NOTUSED String testClass = element.getPropertyAsString(TestElement.TEST_CLASS);
- getImages.setSelected(((HTTPSampler2) element).isImageParser());
- isMon.setSelected(((HTTPSampler2) element).isMonitor());
+ super.init();
}
public TestElement createTestElement()
{
- HTTPSampler2 sampler = new HTTPSampler2();
+ HTTPSamplerBase sampler = HTTPSamplerFactory.newInstance("HTTPSampler2");
modifyTestElement(sampler);
return sampler;
}
- /**
- * Modifies a given TestElement to mirror the data in the gui components.
- * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
- */
- public void modifyTestElement(TestElement sampler)
- {
- TestElement el = urlConfigGui.createTestElement();
- sampler.clear();
- sampler.addTestElement(el);
- if (getImages.isSelected())
- {
- ((HTTPSampler2)sampler).setImageParser(true);
- }
- else
- {
- ((HTTPSampler2)sampler).setImageParser(false);
- }
- if (isMon.isSelected()){
- ((HTTPSampler2)sampler).setMonitor("true");
- } else {
- ((HTTPSampler2)sampler).setMonitor("false");
- }
- this.configureTestElement(sampler);
- }
-
public String getStaticLabel()
{
return super.getStaticLabel()+" HTTPCLient (ALPHA)";
}
- public String getLabelResource()
- {
- return "web_testing_title";
- }
-
- private void init()
- {
- setLayout(new BorderLayout(0, 5));
- setBorder(makeBorder());
-
- add(makeTitlePanel(), BorderLayout.NORTH);
-
- // URL CONFIG
- urlConfigGui = new MultipartUrlConfigGui();
- add(urlConfigGui, BorderLayout.CENTER);
-
- // OPTIONAL TASKS
- add(createOptionalTasksPanel(), BorderLayout.SOUTH);
- }
-
- private JPanel createOptionalTasksPanel()
- {
- // OPTIONAL TASKS
- HorizontalPanel optionalTasksPanel = new HorizontalPanel();
- optionalTasksPanel.setBorder(
- BorderFactory.createTitledBorder(
- BorderFactory.createEtchedBorder(),
- JMeterUtils.getResString("optional_tasks")));
-
- // RETRIEVE IMAGES
- JPanel retrieveImagesPanel = new JPanel();
- getImages =
- new JCheckBox(
- JMeterUtils.getResString("web_testing_retrieve_images"));
- retrieveImagesPanel.add(getImages);
- JPanel isMonitorPanel = new JPanel();
- isMon = new JCheckBox(
- JMeterUtils.getResString("monitor_is_title"));
- isMonitorPanel.add(isMon);
- optionalTasksPanel.add(retrieveImagesPanel);
- optionalTasksPanel.add(isMonitorPanel);
- return optionalTasksPanel;
- }
-
- public Dimension getPreferredSize()
- {
- return getMinimumSize();
- }
-
- public static class Test extends TestCase
- {
- HttpTestSampleGui2 gui;
-
- public Test(String name)
- {
- super(name);
- }
-
- public void setUp()
- {
- gui = new HttpTestSampleGui2();
- }
-
- public void testCloneSampler() throws Exception
- {
- HTTPSampler2 sampler = (HTTPSampler2)gui.createTestElement();
- sampler.addArgument("param","value");
- HTTPSampler2 clonedSampler = (HTTPSampler2)sampler.clone();
- clonedSampler.setRunningVersion(true);
- sampler.getArguments().getArgument(0).setValue("new value");
- assertEquals(
- "Sampler didn't clone correctly",
- "new value",
- sampler.getArguments().getArgument(0).getValue());
- }
- }
-
- /* (non-Javadoc)
- * @see org.apache.jmeter.gui.JMeterGUIComponent#clear()
- */
- public void clear()
- {
- super.clear();
- getImages.setSelected(false);
- urlConfigGui.clear();
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org