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 ms...@apache.org on 2002/04/19 04:24:10 UTC
cvs commit: jakarta-jmeter/src_1/org/apache/jmeter/junit/protocol/http/parser HtmlParserTester.java
mstover1 02/04/18 19:24:10
Added: src_1/org/apache/jmeter NewDriver.java NonGuiDriver.java
src_1/org/apache/jmeter/junit AllTests.java JMeterTest.java
src_1/org/apache/jmeter/junit/protocol/http/config
HttpConfigSuite.java UrlConfigTest.java
src_1/org/apache/jmeter/junit/protocol/http/parser
HtmlParserTester.java
Log:
Revision Changes Path
1.1 jakarta-jmeter/src_1/org/apache/jmeter/NewDriver.java
Index: NewDriver.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter;
import java.io.*;
import org.apache.jmeter.gui.*;
import org.apache.jmeter.gui.action.ActionRouter;
import org.apache.jmeter.gui.tree.*;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.gui.util.ComponentUtil;
/************************************************************
* Title: JMeter Description: Copyright: Copyright (c) 2000 Company: Apache
*
*@author Michael Stover
*@created March 13, 2001
*@version 1.0
***********************************************************/
public class NewDriver
{
/************************************************************
* The main program for the NewDriver class
*
*@param args The command line arguments
***********************************************************/
public static void main(String[] args)
{
if(args.length > 0 && args[0] != null)
{
JMeterUtils.getProperties(args[0]);
}
JMeterTreeModel treeModel = new JMeterTreeModel();
JMeterTreeListener treeLis = new JMeterTreeListener(treeModel);
MainFrame main = new MainFrame(ActionRouter.getInstance(),
treeModel, treeLis);
GuiPackage guiPack = GuiPackage.getInstance(main,
treeLis, treeModel);
main.setTitle("Apache JMeter");
main.setIconImage(JMeterUtils.getImage("jmeter.jpg").getImage());
treeLis.setActionHandler(ActionRouter.getInstance());
ComponentUtil.centerComponentInWindow(main,80);
main.show();
}
}
1.1 jakarta-jmeter/src_1/org/apache/jmeter/NonGuiDriver.java
Index: NonGuiDriver.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter;
import java.io.File;
import java.io.FileInputStream;
import java.util.*;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.testelement.TestPlan;
import org.apache.jmeter.threads.ThreadGroup;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.util.ListedHashTree;
import org.apache.jmeter.save.SaveService;
/****************************************
* Title: JMeter Description: Copyright: Copyright (c) 2000 Company: Apache This
* class uses a JMeter file that has been saved using
* org.apache.jmeter.NewDriver (The GUI version of the program). It eliminates
* the need for Swing components while running JMeter tests and hence can be run
* from non window clients. Usage: java org.apache.jmeter.NonGuiDriver <propery
* file>
*
* <source file>
*
*@author Tushar Bhatia
*@created June 18, 2001
*@version 1.0
*@see org.apache.jmeter.gui.tree.NonGuiTree
***************************************/
public class NonGuiDriver
{
/****************************************
* !ToDo (Method description)
*
*@param arg !ToDo (Parameter description)
***************************************/
public static void main(String arg[])
{
if(arg.length != 2)
{
System.out.println("Non GUI Driver for JMeter Run. \nUsage:java org.apache.jmeter.NonGuiDriver <propery file> <source file>");
System.exit(1);
}
JMeterUtils.getProperties(arg[0]);
NonGuiDriver driver = new NonGuiDriver();
driver.run(arg[1]);
}
private static void println(String str)
{
System.out.println(str);
}
private void run(String fileName)
{
FileInputStream reader = null;
try
{
File f = new File(fileName);
if(!f.exists() || !f.isFile())
{
println("Could not open " + fileName);
return;
}
reader = new FileInputStream(f);
ListedHashTree tree = SaveService.loadSubTree(reader);
println("Created the tree successfully");
StandardJMeterEngine engine = new StandardJMeterEngine();
engine.configure(tree);
println("Starting the test");
engine.runTest();
}
catch(Exception e)
{
System.out.println("Error in NonGUIDriver" + e.getMessage());
e.printStackTrace();
}
}
}
1.1 jakarta-jmeter/src_1/org/apache/jmeter/junit/AllTests.java
Index: AllTests.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.junit;
import java.io.*;
import java.util.*;
import junit.framework.*;
import org.apache.jmeter.util.ClassFinder;
import org.apache.jmeter.util.JMeterUtils;
/************************************************************
* Title: Apache JMeter Description: Copyright: Copyright (c) 2000 Company:
* Apache Foundation
*
*@author Michael Stover
*@created $Date: 2002/04/19 02:24:09 $
*@version 1.0
***********************************************************/
public class AllTests
{
/************************************************************
* Constructor for the AllTests object
***********************************************************/
public AllTests()
{
}
/************************************************************
* The main program for the AllTests class
*
*@param args The command line arguments
***********************************************************/
public static void main(String[] args)
{
if (args.length < 1)
{
System.out.println("Need an argument specifying the jmeter property file");
System.exit(0);
}
JMeterUtils.getProperties(args[0]);
// end : added - 11 July 2001
try
{
TestSuite suite = suite();
PrintStream out = new PrintStream(new FileOutputStream("testresults.txt"));
junit.textui.TestRunner runner = new junit.textui.TestRunner(out);
runner.run(suite);
out.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
System.exit(0);
}
/************************************************************
* A unit test suite for JUnit
*
*@return The test suite
***********************************************************/
public static TestSuite suite()
{
TestSuite suite = new TestSuite();
try
{
Iterator classes = ClassFinder.findClassesThatExtend(new Class[]{TestCase.class},true).iterator();
while (classes.hasNext())
{
String name = (String)classes.next();
try
{
suite.addTest(new TestSuite(Class.forName(name)));
}
catch (Exception ex)
{
System.out.println("error adding test :"+ex);
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
return suite;
}
}
1.1 jakarta-jmeter/src_1/org/apache/jmeter/junit/JMeterTest.java
Index: JMeterTest.java
===================================================================
package org.apache.jmeter.junit;
import java.util.*;
import junit.framework.TestCase;
import org.apache.jmeter.gui.JMeterGUIComponent;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.util.ClassFinder;
import java.io.Serializable;
import org.apache.jmeter.gui.tree.JMeterTreeNode;
/****************************************
* Title: JMeter Description: Copyright: Copyright (c) 2000 Company: Apache
*
*@author Michael Stover
*@created $Date: 2002/04/19 02:24:09 $
*@version 1.0
***************************************/
public class JMeterTest extends TestCase
{
/****************************************
* !ToDo (Constructor description)
*
*@param name !ToDo (Parameter description)
***************************************/
public JMeterTest(String name)
{
super(name);
}
/****************************************
* !ToDo
*
*@exception Exception !ToDo (Exception description)
***************************************/
public void testGUIComponents() throws Exception
{
Iterator iter = getObjects(JMeterGUIComponent.class).iterator();
while(iter.hasNext())
{
JMeterGUIComponent item = (JMeterGUIComponent)iter.next();
if(item instanceof JMeterTreeNode)
{
continue;
}
this.assertEquals("Failed on " + item.getClass().getName(), item.getStaticLabel(), item.getName());
TestElement el = item.createTestElement();
assertEquals("GUI-CLASS: Failed on " + item.getClass().getName(), item.getClass().getName(),
el.getProperty(TestElement.GUI_CLASS));
assertEquals("NAME: Failed on " + item.getClass().getName(), item.getName(),
el.getProperty(TestElement.NAME));
assertEquals("TEST-CLASS: Failed on " + item.getClass().getName(),
el.getClass().getName(), el.getProperty(TestElement.TEST_CLASS));
el.setProperty(TestElement.NAME, "hey, new name!:");
item.configure(el);
assertEquals("CONFIGURE-TEST: Failed on " + item.getClass().getName(),
el.getProperty(TestElement.NAME), item.getName());
}
}
/****************************************
* !ToDo
*
*@exception Exception !ToDo (Exception description)
***************************************/
public void testTestElements() throws Exception
{
Iterator iter = getObjects(TestElement.class).iterator();
while(iter.hasNext())
{
TestElement item = (TestElement)iter.next();
checkElementCloning(item);
assertTrue(item.getClass().getName()+" must implement Serializable",
item instanceof Serializable);
}
}
/****************************************
* !ToDoo (Method description)
*
*@param extendsClass !ToDo (Parameter description)
*@return !ToDo (Return description)
*@exception Exception !ToDo (Exception description)
***************************************/
protected Collection getObjects(Class extendsClass) throws Exception
{
Iterator classes = ClassFinder.findClassesThatExtend(new Class[]{extendsClass}).iterator();
List objects = new LinkedList();
while(classes.hasNext())
{
objects.add(Class.forName((String)classes.next()).newInstance());
}
return objects;
}
private void cloneTesting(TestElement item, TestElement clonedItem)
{
this.assertTrue(item != clonedItem);
this.assertEquals("CLONE-SAME-CLASS: testing " + item.getClass().getName(),
item.getClass().getName(), clonedItem.getClass().getName());
}
private void checkElementCloning(TestElement item)
{
TestElement clonedItem = (TestElement)item.clone();
cloneTesting(item, clonedItem);
Iterator iter2 = item.getPropertyNames().iterator();
while(iter2.hasNext())
{
Object item2 = iter2.next();
if(item2 instanceof TestElement)
{
checkElementCloning((TestElement)item2);
}
}
}
}
1.1 jakarta-jmeter/src_1/org/apache/jmeter/junit/protocol/http/config/HttpConfigSuite.java
Index: HttpConfigSuite.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.junit.protocol.http.config;
import junit.framework.*;
/**
* Title: Apache JMeter
* Description:
* Copyright: Copyright (c) 2000
* Company: Apache Foundation
* @author Michael Stover
* @version 1.0
*/
public class HttpConfigSuite
{
public static TestSuite suite()
{
TestSuite test = new TestSuite(UrlConfigTest.class);
return test;
}
}
1.1 jakarta-jmeter/src_1/org/apache/jmeter/junit/protocol/http/config/UrlConfigTest.java
Index: UrlConfigTest.java
===================================================================
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache JMeter" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache JMeter", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jmeter.junit.protocol.http.config;
import junit.framework.TestCase;
import org.apache.jmeter.protocol.http.config.UrlConfig;
import org.apache.jmeter.config.Arguments;
/**
* Title: Apache JMeter
* Description:
* Copyright: Copyright (c) 2000
* Company: Apache Foundation
* @author Michael Stover
* @version 1.0
*/
public class UrlConfigTest extends TestCase
{
UrlConfig config;
UrlConfig defaultConfig;
UrlConfig partialConfig;
public UrlConfigTest(String name)
{
super(name);
}
protected void setUp()
{
Arguments args = new Arguments();
args.addArgument("username","mstover");
args.addArgument("password","pass");
args.addArgument("action","login");
config = new UrlConfig();
config.setName("Full Config");
config.setProperty(config.DOMAIN,"www.lazer.com");
config.setProperty(config.PATH,"login.jsp");
config.setProperty(config.METHOD,config.POST);
config.setProperty(config.ARGUMENTS,args);
defaultConfig = new UrlConfig();
defaultConfig.setName("default");
defaultConfig.setProperty(config.DOMAIN,"www.xerox.com");
defaultConfig.setProperty(config.PATH,"default.html");
partialConfig = new UrlConfig();
partialConfig.setProperty(config.PATH,"main.jsp");
partialConfig.setProperty(config.METHOD,config.GET);
}
public void testSimpleConfig()
{
assertTrue(config.getName().equals("Full Config"));
assertEquals(config.getDomain(),"www.lazer.com");
}
public void testOverRide()
{
this.assertNull(partialConfig.getProperty(config.DOMAIN));
partialConfig.addTestElement(defaultConfig);
assertEquals(partialConfig.getProperty(config.DOMAIN),"www.xerox.com");
assertEquals(partialConfig.getProperty(config.PATH),"main.jsp");
}
public static void main(String[] args)
{
}
}
1.1 jakarta-jmeter/src_1/org/apache/jmeter/junit/protocol/http/parser/HtmlParserTester.java
Index: HtmlParserTester.java
===================================================================
package org.apache.jmeter.junit.protocol.http.parser;
import java.net.*;
import junit.framework.TestCase;
import org.apache.jmeter.protocol.http.config.UrlConfig;
import org.apache.jmeter.protocol.http.modifier.AnchorModifier;
import org.apache.jmeter.protocol.http.sampler.HTTPSampler;
import org.apache.jmeter.samplers.*;
/************************************************************
* Title: Description: Copyright: Copyright (c) 2001 Company:
*
*@author
*@created June 14, 2001
*@version 1.0
***********************************************************/
public class HtmlParserTester extends TestCase
{
AnchorModifier parser = new AnchorModifier();
/************************************************************
* Constructor for the HtmlParserTester object
*
*@param name Description of Parameter
***********************************************************/
public HtmlParserTester(String name)
{
super(name);
}
/************************************************************
* A unit test for JUnit
*
*@exception Exception Description of Exception
***********************************************************/
public void testSimpleParse() throws Exception
{
HTTPSampler config = makeUrlConfig(".*/index\\.html");
URL context = new URL("http://www.apache.org/subdir/previous.html");
String responseText = "<html><head><title>Test page</title></head><body>" +
"<a href=\"index.html\">Goto index page</a></body></html>";
SampleResult result = new SampleResult();
result.putValue(SampleResult.TEXT_RESPONSE,responseText.getBytes());
result.putValue(HTTPSampler.URL,context);
parser.modifyEntry(config, result);
assertEquals("http://www.apache.org:80/subdir/index.html",
config.getUrl().toString());
}
public void testSimpleParse2() throws Exception
{
HTTPSampler config = makeUrlConfig("/index\\.html");
URL context = new URL("http://www.apache.org/subdir/previous.html");
String responseText = "<html><head><title>Test page</title></head><body>" +
"<a href=\"/index.html\">Goto index page</a>hfdfjiudfjdfjkjfkdjf"+
"<b>bold text</b><a href=lowerdir/index.html>lower</a></body></html>";
SampleResult result = new SampleResult();
result.putValue(SampleResult.TEXT_RESPONSE,responseText.getBytes());
result.putValue(HTTPSampler.URL,context);
parser.modifyEntry(config, result);
String newUrl = config.getUrl().toString();
assertTrue("http://www.apache.org:80/index.html".equals(newUrl)
|| "http://www.apache.org:80/subdir/lowerdir/index.html".equals(newUrl));
}
public void testSimpleParse3() throws Exception
{
HTTPSampler config = makeUrlConfig(".*index.*");
config.getArguments().addArgument("param1","value1");
URL context = new URL("http://www.apache.org/subdir/previous.html");
String responseText = "<html><head><title>Test page</title></head><body>" +
"<a href=\"/home/index.html?param1=value1\">Goto index page</a></body></html>";
SampleResult result = new SampleResult();
result.putValue(SampleResult.TEXT_RESPONSE,responseText.getBytes());
result.putValue(HTTPSampler.URL,context);
parser.modifyEntry(config, result);
String newUrl = config.getUrl().toString();
assertEquals("http://www.apache.org:80/home/index.html?param1=value1",newUrl);
}
public void testSimpleParse4() throws Exception
{
HTTPSampler config = makeUrlConfig("/subdir/index\\..*");
URL context = new URL("http://www.apache.org/subdir/previous.html");
String responseText = "<html><head><title>Test page</title></head><body>" +
"<A HREF=\"index.html\">Goto index page</A></body></html>";
SampleResult result = new SampleResult();
result.putValue(SampleResult.TEXT_RESPONSE,responseText.getBytes());
result.putValue(HTTPSampler.URL,context);
parser.modifyEntry(config, result);
String newUrl = config.getUrl().toString();
assertEquals("http://www.apache.org:80/subdir/index.html",newUrl);
}
public void testSimpleParse5() throws Exception
{
HTTPSampler config = makeUrlConfig("/subdir/index\\.h.*");
URL context = new URL("http://www.apache.org/subdir/one/previous.html");
String responseText = "<html><head><title>Test page</title></head><body>" +
"<a href=\"../index.html\">Goto index page</a></body></html>";
SampleResult result = new SampleResult();
result.putValue(SampleResult.TEXT_RESPONSE,responseText.getBytes());
result.putValue(HTTPSampler.URL,context);
parser.modifyEntry(config, result);
String newUrl = config.getUrl().toString();
assertEquals("http://www.apache.org:80/subdir/index.html",newUrl);
}
public void testFailSimpleParse1() throws Exception
{
HTTPSampler config = makeUrlConfig(".*index.*param2=.+1");
URL context = new URL("http://www.apache.org/subdir/previous.html");
String responseText = "<html><head><title>Test page</title></head><body>" +
"<a href=\"/home/index.html?param1=value1\">Goto index page</a></body></html>";
SampleResult result = new SampleResult();
result.putValue(SampleResult.TEXT_RESPONSE,responseText.getBytes());
result.putValue(HTTPSampler.URL,context);
parser.modifyEntry(config, result);
String newUrl = config.getUrl().toString();
assertEquals(config.getUrl().toString(),newUrl);
}
public void testFailSimpleParse2() throws Exception
{
HTTPSampler config = makeUrlConfig(".*login\\.html");
URL context = new URL("http://www.apache.org/subdir/previous.html");
String responseText = "<html><head><title>Test page</title></head><body>" +
"<a href=\"/home/index.html?param1=value1\">Goto index page</a></body></html>";
SampleResult result = new SampleResult();
result.putValue(SampleResult.TEXT_RESPONSE,responseText.getBytes());
result.putValue(HTTPSampler.URL,context);
parser.modifyEntry(config, result);
String newUrl = config.getUrl().toString();
this.assertTrue(!"http://www.apache.org:80/home/index.html?param1=value1".equals(newUrl));
assertEquals(config.getUrl().toString(),newUrl);
}
/************************************************************
* A unit test for JUnit
*
*@exception Exception Description of Exception
***********************************************************/
public void testSimpleFormParse() throws Exception
{
HTTPSampler config = makeUrlConfig(".*index.html");
config.getArguments().addArgument("test","g.*");
config.setMethod(UrlConfig.POST);
URL context = new URL("http://www.apache.org/subdir/previous.html");
String responseText = "<html><head><title>Test page</title></head><body>" +
"<form action=\"index.html\" method=\"POST\"><input type=\"checkbox\" name=\"test\""+
" value=\"goto\">Goto index page</form></body></html>";
SampleResult result = new SampleResult();
result.putValue(SampleResult.TEXT_RESPONSE,responseText.getBytes());
result.putValue(HTTPSampler.URL,context);
parser.modifyEntry(config, result);
assertEquals("http://www.apache.org:80/subdir/index.html",
config.getUrl().toString());
assertEquals("test=goto",config.getQueryString());
}
private HTTPSampler makeUrlConfig(String path)
{
HTTPSampler config = new HTTPSampler();
config.setDomain("www.apache.org");
config.setMethod(config.GET);
config.setPath(path);
config.setPort(80);
config.setProtocol("http");
return config;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>