Author: sebb
Date: Mon Feb 27 16:46:51 2006
New Revision: 381509
URL: http://svn.apache.org/viewcvs?rev=381509&view=rev
Log:
Move all AnchorModifier tests to same class; add new Base64 test
Removed:
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/junit/protocol/http/parser/HtmlParserTester.java
Modified:
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/protocol/http/modifier/TestAnchorModifier.java
Modified:
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/protocol/http/modifier/TestAnchorModifier.java
URL:
http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/protocol/http/modifier/TestAnchorModifier.java?rev=381509&r1=381508&r2=381509&view=diff
==============================================================================
---
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/protocol/http/modifier/TestAnchorModifier.java
(original)
+++
jakarta/jmeter/branches/rel-2-1/test/src/org/apache/jmeter/protocol/http/modifier/TestAnchorModifier.java
Mon Feb 27 16:46:51 2006
@@ -18,21 +18,26 @@
package org.apache.jmeter.protocol.http.modifier;
import java.io.FileInputStream;
+import java.net.MalformedURLException;
import java.net.URL;
+import org.apache.commons.codec.binary.Base64;
import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.protocol.http.sampler.HTTPNullSampler;
import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.threads.JMeterContext;
import org.apache.jmeter.threads.JMeterContextService;
import org.apache.jorphan.io.TextFile;
+import org.apache.jorphan.util.JOrphanUtils;
/**
* @author Michael Stover
* @version $Revision$
*/
public class TestAnchorModifier extends JMeterTestCase {
+ private AnchorModifier parser = new AnchorModifier();
public TestAnchorModifier(String name) {
super(name);
}
@@ -41,6 +46,7 @@
public void setUp() {
jmctx = JMeterContextService.getContext();
+ parser.setThreadContext(jmctx);
}
public void testProcessingHTMLFile(String HTMLFileName) throws
Exception {
@@ -93,4 +99,239 @@
testProcessingHTMLFile("/testfiles/jmeter_home_page_with_base_href.html");
}
// */
+ /**
+ * A unit test for JUnit.
+ */
+ public void testSimpleParse() throws Exception {
+ HTTPSamplerBase config = makeUrlConfig(".*/index\\.html");
+ HTTPSamplerBase context =
makeContext("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>";
+ HTTPSampleResult result = new HTTPSampleResult();
+ jmctx.setCurrentSampler(context);
+ jmctx.setCurrentSampler(config);
+ result.setResponseData(responseText.getBytes());
+ result.setSampleLabel(context.toString());
+ result.setSamplerData(context.toString());
+ result.setURL(context.getUrl());
+ jmctx.setPreviousResult(result);
+ parser.process();
+ assertEquals("http://www.apache.org/subdir/index.html",
config.getUrl().toString());
+ }
+
+ public void testSimpleParse2() throws Exception {
+ HTTPSamplerBase config = makeUrlConfig("/index\\.html");
+ HTTPSamplerBase context =
makeContext("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>";
+ HTTPSampleResult result = new HTTPSampleResult();
+ result.setResponseData(responseText.getBytes());
+ result.setSampleLabel(context.toString());
+ result.setURL(context.getUrl());
+ jmctx.setCurrentSampler(context);
+ jmctx.setCurrentSampler(config);
+ jmctx.setPreviousResult(result);
+ parser.process();
+ String newUrl = config.getUrl().toString();
+ assertTrue("http://www.apache.org/index.html".equals(newUrl)
+ ||
"http://www.apache.org/subdir/lowerdir/index.html".equals(newUrl));
+ }
+
+ public void testSimpleParse3() throws Exception {
+ HTTPSamplerBase config = makeUrlConfig(".*index.*");
+ config.getArguments().addArgument("param1", "value1");
+ HTTPSamplerBase context =
makeContext("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>";
+ HTTPSampleResult result = new HTTPSampleResult();
+ result.setResponseData(responseText.getBytes());
+ result.setSampleLabel(context.toString());
+ result.setURL(context.getUrl());
+ jmctx.setCurrentSampler(context);
+ jmctx.setCurrentSampler(config);
+ jmctx.setPreviousResult(result);
+ parser.process();
+ String newUrl = config.getUrl().toString();
+
assertEquals("http://www.apache.org/home/index.html?param1=value1", newUrl);
+ }
+
+ public void testSimpleParse4() throws Exception {
+ HTTPSamplerBase config = makeUrlConfig("/subdir/index\\..*");
+ HTTPSamplerBase context =
makeContext("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>";
+ HTTPSampleResult result = new HTTPSampleResult();
+ result.setResponseData(responseText.getBytes());
+ result.setSampleLabel(context.toString());
+ result.setURL(context.getUrl());
+ jmctx.setCurrentSampler(context);
+ jmctx.setCurrentSampler(config);
+ jmctx.setPreviousResult(result);
+ parser.process();
+ String newUrl = config.getUrl().toString();
+ assertEquals("http://www.apache.org/subdir/index.html", newUrl);
+ }
+
+ public void testSimpleParse5() throws Exception {
+ HTTPSamplerBase config = makeUrlConfig("/subdir/index\\.h.*");
+ HTTPSamplerBase context =
makeContext("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>";
+ HTTPSampleResult result = new HTTPSampleResult();
+ result.setResponseData(responseText.getBytes());
+ result.setSampleLabel(context.toString());
+ result.setURL(context.getUrl());
+ jmctx.setCurrentSampler(context);
+ jmctx.setCurrentSampler(config);
+ jmctx.setPreviousResult(result);
+ parser.process();
+ String newUrl = config.getUrl().toString();
+ assertEquals("http://www.apache.org/subdir/index.html", newUrl);
+ }
+
+ public void testFailSimpleParse1() throws Exception {
+ HTTPSamplerBase config = makeUrlConfig(".*index.*?param2=.+1");
+ HTTPSamplerBase context =
makeContext("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>";
+ HTTPSampleResult result = new HTTPSampleResult();
+ String newUrl = config.getUrl().toString();
+ result.setResponseData(responseText.getBytes());
+ result.setSampleLabel(context.toString());
+ result.setURL(context.getUrl());
+ jmctx.setCurrentSampler(context);
+ jmctx.setCurrentSampler(config);
+ jmctx.setPreviousResult(result);
+ parser.process();
+ assertEquals(newUrl, config.getUrl().toString());
+ }
+
+ public void testFailSimpleParse3() throws Exception {
+ HTTPSamplerBase config = makeUrlConfig("/home/index.html");
+ HTTPSamplerBase context =
makeContext("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>";
+ HTTPSampleResult result = new HTTPSampleResult();
+ String newUrl = config.getUrl().toString();
+ result.setResponseData(responseText.getBytes());
+ result.setSampleLabel(context.toString());
+ result.setURL(context.getUrl());
+ jmctx.setCurrentSampler(context);
+ jmctx.setCurrentSampler(config);
+ jmctx.setPreviousResult(result);
+ parser.process();
+ assertEquals(newUrl + "?param1=value1",
config.getUrl().toString());
+ }
+
+ public void testFailSimpleParse2() throws Exception {
+ HTTPSamplerBase config = makeUrlConfig(".*login\\.html");
+ HTTPSamplerBase context =
makeContext("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>";
+ HTTPSampleResult result = new HTTPSampleResult();
+ result.setResponseData(responseText.getBytes());
+ result.setSampleLabel(context.toString());
+ result.setURL(context.getUrl());
+ jmctx.setCurrentSampler(context);
+ jmctx.setPreviousResult(result);
+ parser.process();
+ String newUrl = config.getUrl().toString();
+
assertTrue(!"http://www.apache.org/home/index.html?param1=value1".equals(newUrl));
+ assertEquals(config.getUrl().toString(), newUrl);
+ }
+
+ public void testSimpleFormParse() throws Exception {
+ HTTPSamplerBase config = makeUrlConfig(".*index.html");
+ config.addArgument("test", "g.*");
+ config.setMethod(HTTPSamplerBase.POST);
+ HTTPSamplerBase context =
makeContext("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>";
+ HTTPSampleResult result = new HTTPSampleResult();
+ result.setResponseData(responseText.getBytes());
+ result.setSampleLabel(context.toString());
+ result.setURL(context.getUrl());
+ jmctx.setCurrentSampler(context);
+ jmctx.setCurrentSampler(config);
+ jmctx.setPreviousResult(result);
+ parser.process();
+ assertEquals("http://www.apache.org/subdir/index.html",
config.getUrl().toString());
+ assertEquals("test=goto", config.getQueryString());
+ }
+
+ public void testBadCharParse() throws Exception {
+ HTTPSamplerBase config = makeUrlConfig(".*index.html");
+ config.addArgument("te$st", "g.*");
+ config.setMethod(HTTPSamplerBase.POST);
+ HTTPSamplerBase context =
makeContext("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=\"te$st\""
+ + " value=\"goto\">Goto index page</form></body></html>";
+ HTTPSampleResult result = new HTTPSampleResult();
+ result.setResponseData(responseText.getBytes());
+ result.setSampleLabel(context.toString());
+ result.setURL(context.getUrl());
+ jmctx.setCurrentSampler(context);
+ jmctx.setCurrentSampler(config);
+ jmctx.setPreviousResult(result);
+ parser.process();
+ assertEquals("http://www.apache.org/subdir/index.html",
config.getUrl().toString());
+ assertEquals("te%24st=goto", config.getQueryString());
+ }
+
+ public void testBase64Parse() throws Exception {
+ String base64Fixture =
Base64.encodeBase64("foo+bar=foobar".getBytes()).toString();
+ String htmlEncodedFixture = JOrphanUtils.encode(base64Fixture,
"UTF-8");
+ testLog.info("base64Fixture= " + base64Fixture);
+ testLog.info("htmlEncodedFixture= " + htmlEncodedFixture);
+
+ HTTPSamplerBase config = makeUrlConfig(".*index.html");
+ config.addArgument("test", ".*");
+ config.setMethod(HTTPSamplerBase.POST);
+ HTTPSamplerBase context =
makeContext("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=\"hidden\" name=\"test\""
+ + " value=\"" + htmlEncodedFixture + "\">Goto index
page</form></body></html>";
+
+ testLog.info("responseText= " + responseText);
+
+ HTTPSampleResult result = new HTTPSampleResult();
+ result.setResponseData(responseText.getBytes());
+ result.setSampleLabel(context.toString());
+ result.setURL(context.getUrl());
+ jmctx.setCurrentSampler(context);
+ jmctx.setCurrentSampler(config);
+ jmctx.setPreviousResult(result);
+ parser.process();
+ assertEquals("http://www.apache.org/subdir/index.html",
config.getUrl().toString());
+
+ testLog.info("config.getQueryString() " + config.getQueryString());
+ testLog.info("double encoded base64Fixture=" +
JOrphanUtils.encode(JOrphanUtils.encode(base64Fixture, "UTF-8"),"UTF-8"));
+
+ assertEquals("test=" + htmlEncodedFixture, config.getQueryString());
+ }
+
+
+ private HTTPSamplerBase makeContext(String url) throws
MalformedURLException {
+ URL u = new URL(url);
+ HTTPSamplerBase context = new HTTPNullSampler();
+ context.setDomain(u.getHost());
+ context.setPath(u.getPath());
+ context.setPort(u.getPort());
+ context.setProtocol(u.getProtocol());
+ context.parseArguments(u.getQuery());
+ return context;
+ }
+
+ private HTTPSamplerBase makeUrlConfig(String path) {
+ HTTPSamplerBase config = new HTTPNullSampler();
+ config.setDomain("www.apache.org");
+ config.setMethod(HTTPSamplerBase.GET);
+ config.setPath(path);
+ config.setPort(80);
+ config.setProtocol("http");
+ return config;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]