You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2016/02/02 22:35:59 UTC
svn commit: r1728220 - in /jmeter/trunk/test/src/org/apache/jmeter/protocol:
http/proxy/ http/sampler/ http/util/ http/util/accesslog/ ldap/config/gui/
tcp/sampler/
Author: pmouawad
Date: Tue Feb 2 21:35:58 2016
New Revision: 1728220
URL: http://svn.apache.org/viewvc?rev=1728220&view=rev
Log:
Bug 58897 - Improve JUnit Test code STEP 4
Part 3 patch by B. Wiart
Bugzilla Id: 58897
Modified:
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestProxyControl.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PostWriterTest.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PutWriterTest.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplers.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPArgument.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPFileArg.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPFileArgs.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/accesslog/TestLogFilter.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/accesslog/TestTCLogParser.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/ldap/config/gui/PackageTest.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImplTest.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/LengthPrefixedBinaryTCPClientImplTest.java
jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/TCPClientDecoratorTest.java
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestHttpRequestHdr.java Tue Feb 2 21:35:58 2016
@@ -18,6 +18,10 @@
package org.apache.jmeter.protocol.http.proxy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URLEncoder;
@@ -33,12 +37,11 @@ import org.apache.jmeter.protocol.http.s
import org.apache.jmeter.protocol.http.util.HTTPArgument;
import org.apache.jmeter.protocol.http.util.HTTPConstants;
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
+import org.junit.Test;
-public class TestHttpRequestHdr extends JMeterTestCase {
- public TestHttpRequestHdr(String name) {
- super(name);
- }
+public class TestHttpRequestHdr extends JMeterTestCase {
+ @Test
public void testRepeatedArguments() throws Exception {
String url = "http://localhost/matrix.html";
// A HTTP GET request
@@ -172,18 +175,20 @@ public class TestHttpRequestHdr extends
checkArgument((HTTPArgument)arguments.getArgument(0), "", postBody, postBody, contentEncoding, false);
}
+ @Test
public void testEncodedArguments() throws Exception {
String url = "http://localhost/matrix.html";
testEncodedArguments(url);
}
+ @Test
public void testEncodedArgumentsIPv6() throws Exception {
String url = "http://[::1]:8080/matrix.html";
testEncodedArguments(url);
}
- public void testEncodedArguments(String url) throws Exception {
+ private void testEncodedArguments(String url) throws Exception {
// A HTTP GET request, with encoding not known
String contentEncoding = "";
String queryString = "abc%3FSPACE=a+b&space=a%20b&query=What%3F";
@@ -273,15 +278,17 @@ public class TestHttpRequestHdr extends
checkArgument((HTTPArgument)arguments.getArgument(2), "query", "What?", "What%3F", contentEncoding, true);
}
+ @Test
public void testGetRequestEncodings() throws Exception {
testGetRequestEncodings("http://localhost/matrix.html");
}
+ @Test
public void testGetRequestEncodingsIPv6() throws Exception {
testGetRequestEncodings("http://[::1]:8080/matrix.html");
}
- public void testGetRequestEncodings(String url) throws Exception {
+ private void testGetRequestEncodings(String url) throws Exception {
// A HTTP GET request, with encoding not known
String contentEncoding = "";
String param1Value = "yes";
@@ -340,6 +347,7 @@ public class TestHttpRequestHdr extends
checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true);
}
+ @Test
public void testPostRequestEncodings() throws Exception {
String url = "http://localhost/matrix.html";
// A HTTP POST request, with encoding not known
@@ -415,6 +423,7 @@ public class TestHttpRequestHdr extends
checkArgument((HTTPArgument)arguments.getArgument(1), "param2", param2Value, param2ValueEncoded, contentEncoding, true);
}
+ @Test
public void testPostMultipartFormData() throws Exception {
String url = "http://localhost/matrix.html";
// A HTTP POST request, multipart/form-data, simple values,
@@ -498,6 +507,7 @@ public class TestHttpRequestHdr extends
checkArgument((HTTPArgument)arguments.getArgument(1), "description", descriptionValue, descriptionValue, contentEncoding, false);
}
+ @Test
public void testParse1() throws Exception {// no space after :
HttpRequestHdr req = new HttpRequestHdr();
ByteArrayInputStream bis = null;
@@ -513,6 +523,7 @@ public class TestHttpRequestHdr extends
}
+ @Test
public void testParse2() throws Exception {// spaces after :
HttpRequestHdr req = new HttpRequestHdr();
ByteArrayInputStream bis = null;
@@ -527,6 +538,7 @@ public class TestHttpRequestHdr extends
assertEquals("value",header.getValue());
}
+ @Test
public void testPostMultipartFileUpload() throws Exception {
String url = "http://localhost/matrix.html";
// A HTTP POST request, multipart/form-data, simple values,
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestProxyControl.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestProxyControl.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestProxyControl.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/proxy/TestProxyControl.java Tue Feb 2 21:35:58 2016
@@ -18,22 +18,23 @@
package org.apache.jmeter.protocol.http.proxy;
-import junit.framework.TestCase;
-
import org.apache.jmeter.samplers.SampleResult;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.apache.jmeter.protocol.http.sampler.HTTPNullSampler;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase;
-public class TestProxyControl extends TestCase {
+public class TestProxyControl {
private HTTPSamplerBase sampler;
private ProxyControl control;
- public TestProxyControl(String name) {
- super(name);
- }
- @Override
+ @Before
public void setUp() {
control = new ProxyControl();
control.addIncludedPattern(".*\\.jsp");
@@ -41,24 +42,28 @@ public class TestProxyControl extends T
sampler = new HTTPNullSampler();
}
+ @Test
public void testFilter1() throws Exception {
sampler.setDomain("jakarta.org");
sampler.setPath("index.jsp");
assertTrue("Should find jakarta.org/index.jsp", control.filterUrl(sampler));
}
+ @Test
public void testFilter2() throws Exception {
sampler.setPath("index.jsp");
sampler.setDomain("www.apache.org");
assertFalse("Should not match www.apache.org", control.filterUrl(sampler));
}
+ @Test
public void testFilter3() throws Exception {
sampler.setPath("header.gif");
sampler.setDomain("jakarta.org");
assertFalse("Should not match header.gif", control.filterUrl(sampler));
}
+ @Test
public void testContentTypeNoFilters() throws Exception {
SampleResult result = new SampleResult();
// No filters
@@ -95,6 +100,7 @@ public class TestProxyControl extends T
assertFalse("Should not allow image/png", control.filterContentType(result));
}
+ @Test
public void testContentTypeInclude() throws Exception {
SampleResult result = new SampleResult();
control.setContentTypeInclude("text/html|text/ascii");
@@ -107,6 +113,7 @@ public class TestProxyControl extends T
assertFalse("Should not allow text/css", control.filterContentType(result));
}
+ @Test
public void testContentTypeExclude() throws Exception {
SampleResult result = new SampleResult();
control.setContentTypeExclude("text/css");
@@ -119,6 +126,7 @@ public class TestProxyControl extends T
assertFalse("Should not allow text/css", control.filterContentType(result));
}
+ @Test
public void testContentTypeIncludeAndExclude() throws Exception {
SampleResult result = new SampleResult();
// Simple inclusion and exclusion filter
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PostWriterTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PostWriterTest.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PostWriterTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PostWriterTest.java Tue Feb 2 21:35:58 2016
@@ -18,6 +18,9 @@
package org.apache.jmeter.protocol.http.sampler;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -31,9 +34,6 @@ import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
-
-import junit.framework.TestCase;
-
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.http.util.HTTPArgument;
import org.apache.jmeter.protocol.http.util.HTTPConstants;
@@ -41,8 +41,11 @@ import org.apache.jmeter.protocol.http.u
import org.apache.jorphan.logging.LoggingManager;
import org.apache.jorphan.util.JOrphanUtils;
import org.apache.log.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
-public class PostWriterTest extends TestCase {
+public class PostWriterTest {
private static final Logger log = LoggingManager.getLoggerForClass();
@@ -56,8 +59,9 @@ public class PostWriterTest extends Test
private File temporaryFile;
private PostWriter postWriter;
- @Override
- protected void setUp() throws Exception {
+
+ @Before
+ public void setUp() throws Exception {
establishConnection();
sampler = new HTTPSampler();// This must be the original (Java) HTTP sampler
postWriter=new PostWriter();
@@ -78,8 +82,8 @@ public class PostWriterTest extends Test
}
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
// delete temporay file
if(!temporaryFile.delete()) {
fail("Could not delete file:"+temporaryFile.getAbsolutePath());
@@ -90,6 +94,7 @@ public class PostWriterTest extends Test
* Test method for 'org.apache.jmeter.protocol.http.sampler.postWriter.sendPostData(URLConnection, HTTPSampler)'
* This method test sending a request which contains both formdata and file content
*/
+ @Test
public void testSendPostData() throws IOException {
sampler.setMethod(HTTPConstants.POST);
setupFilepart(sampler);
@@ -155,6 +160,7 @@ public class PostWriterTest extends Test
* This method test sending a HTTPSampler with form parameters, and only
* the filename of a file.
*/
+ @Test
public void testSendPostData_NoFilename() throws IOException {
setupNoFilename(sampler);
String titleValue = "mytitle";
@@ -197,6 +203,7 @@ public class PostWriterTest extends Test
* Test method for 'org.apache.jmeter.protocol.http.sampler.postWriter.sendPostData(URLConnection, HTTPSampler)'
* This method test sending file content as the only content of the post body
*/
+ @Test
public void testSendPostData_FileAsBody() throws IOException {
setupFilepart(sampler, "", temporaryFile, "");
@@ -248,6 +255,7 @@ public class PostWriterTest extends Test
* Test method for 'org.apache.jmeter.protocol.http.sampler.postWriter.sendPostData(URLConnection, HTTPSampler)'
* This method test sending only a file multipart.
*/
+ @Test
public void testSendFileData_Multipart() throws IOException {
sampler.setMethod(HTTPConstants.POST);
String fileField = "upload";
@@ -302,6 +310,7 @@ public class PostWriterTest extends Test
* Test method for 'org.apache.jmeter.protocol.http.sampler.postWriter.sendPostData(URLConnection, HTTPSampler)'
* This method test sending only a formdata, as a multipart/form-data request.
*/
+ @Test
public void testSendFormData_Multipart() throws IOException {
sampler.setMethod(HTTPConstants.POST);
String titleField = "title";
@@ -391,6 +400,7 @@ public class PostWriterTest extends Test
* Test method for 'org.apache.jmeter.protocol.http.sampler.postWriter.sendPostData(URLConnection, HTTPSampler)'
* This method test sending only a formdata, as urlencoded data
*/
+ @Test
public void testSendFormData_Urlencoded() throws IOException {
String titleValue = "mytitle";
String descriptionValue = "mydescription";
@@ -559,6 +569,7 @@ public class PostWriterTest extends Test
/*
* Test method for 'org.apache.jmeter.protocol.http.sampler.postWriter.setHeaders(URLConnection, HTTPSampler)'
*/
+ @Test
public void testSetHeaders() throws IOException {
sampler.setMethod(HTTPConstants.POST);
setupFilepart(sampler);
@@ -571,6 +582,7 @@ public class PostWriterTest extends Test
/*
* Test method for 'org.apache.jmeter.protocol.http.sampler.postWriter.setHeaders(URLConnection, HTTPSampler)'
*/
+ @Test
public void testSetHeaders_NoFilename() throws IOException {
setupNoFilename(sampler);
setupFormData(sampler);
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PutWriterTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PutWriterTest.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PutWriterTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/PutWriterTest.java Tue Feb 2 21:35:58 2016
@@ -18,18 +18,17 @@
package org.apache.jmeter.protocol.http.sampler;
-import java.net.URLConnection;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import java.net.URLConnection;
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
+import org.junit.Test;
import org.apache.jmeter.protocol.http.util.HTTPConstants;
-public class PutWriterTest extends TestCase {
+public class PutWriterTest {
- public PutWriterTest(String name) {
- super(name);
- }
+ @Test
public void testSetHeaders() throws Exception {
URLConnection uc = new NullURLConnection();
HTTPSampler sampler = new HTTPSampler();
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplers.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplers.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplers.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplers.java Tue Feb 2 21:35:58 2016
@@ -18,19 +18,20 @@
package org.apache.jmeter.protocol.http.sampler;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import org.apache.jmeter.config.Argument;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.http.util.HTTPConstants;
import org.apache.jmeter.protocol.http.util.HTTPFileArg;
-import junit.framework.TestCase;
+import org.junit.Test;
-public class TestHTTPSamplers extends TestCase {
+public class TestHTTPSamplers {
- public TestHTTPSamplers(String arg0) {
- super(arg0);
- }
// Parse arguments singly
+ @Test
public void testParseArguments(){
HTTPSamplerBase sampler = new HTTPNullSampler();
Arguments args;
@@ -74,6 +75,7 @@ public class TestHTTPSamplers extends Te
}
// Parse arguments all at once
+ @Test
public void testParseArguments2(){
HTTPSamplerBase sampler = new HTTPNullSampler();
Arguments args;
@@ -107,6 +109,7 @@ public class TestHTTPSamplers extends Te
assertEquals(0,sampler.getHTTPFileCount());
}
+ @Test
public void testArgumentWithoutEquals() throws Exception {
HTTPSamplerBase sampler = new HTTPNullSampler();
sampler.setProtocol("http");
@@ -116,6 +119,7 @@ public class TestHTTPSamplers extends Te
assertEquals("http://www.apache.org/index.html?pear", sampler.getUrl().toString());
}
+ @Test
public void testMakingUrl() throws Exception {
HTTPSamplerBase config = new HTTPNullSampler();
config.setProtocol("http");
@@ -126,6 +130,7 @@ public class TestHTTPSamplers extends Te
assertEquals("http://www.apache.org/index.html?param1=value1", config.getUrl().toString());
}
+ @Test
public void testRedirect() throws Exception {
HTTPSamplerBase config = new HTTPNullSampler();
config.setProtocol("http");
@@ -150,6 +155,7 @@ public class TestHTTPSamplers extends Te
assertEquals("http://192.168.0.1/", config.getUrl().toString());
}
+ @Test
public void testMakingUrl2() throws Exception {
HTTPSamplerBase config = new HTTPNullSampler();
config.setProtocol("http");
@@ -160,6 +166,7 @@ public class TestHTTPSamplers extends Te
assertEquals("http://192.168.0.1/index.html?param1=value1&p1=p2", config.getUrl().toString());
}
+ @Test
public void testMakingUrl3() throws Exception {
HTTPSamplerBase config = new HTTPNullSampler();
config.setProtocol("http");
@@ -173,6 +180,7 @@ public class TestHTTPSamplers extends Te
// test cases for making Url, and exercise method
// addArgument(String name,String value,String metadata)
+ @Test
public void testMakingUrl4() throws Exception {
HTTPSamplerBase config = new HTTPNullSampler();
config.setProtocol("http");
@@ -183,6 +191,7 @@ public class TestHTTPSamplers extends Te
assertEquals("http://192.168.0.1/index.html?param1=value1", config.getUrl().toString());
}
+ @Test
public void testMakingUrl5() throws Exception {
HTTPSamplerBase config = new HTTPNullSampler();
config.setProtocol("http");
@@ -193,6 +202,7 @@ public class TestHTTPSamplers extends Te
assertEquals("http://192.168.0.1/index.html?param1=", config.getUrl().toString());
}
+ @Test
public void testMakingUrl6() throws Exception {
HTTPSamplerBase config = new HTTPNullSampler();
config.setProtocol("http");
@@ -206,6 +216,7 @@ public class TestHTTPSamplers extends Te
// test cases for making Url, and exercise method
// parseArguments(String queryString)
+ @Test
public void testMakingUrl7() throws Exception {
HTTPSamplerBase config = new HTTPNullSampler();
config.setProtocol("http");
@@ -216,6 +227,7 @@ public class TestHTTPSamplers extends Te
assertEquals("http://192.168.0.1/index.html?param1=value1", config.getUrl().toString());
}
+ @Test
public void testMakingUrl8() throws Exception {
HTTPSamplerBase config = new HTTPNullSampler();
config.setProtocol("http");
@@ -226,6 +238,7 @@ public class TestHTTPSamplers extends Te
assertEquals("http://192.168.0.1/index.html?param1=", config.getUrl().toString());
}
+ @Test
public void testMakingUrl9() throws Exception {
HTTPSamplerBase config = new HTTPNullSampler();
config.setProtocol("http");
@@ -236,6 +249,7 @@ public class TestHTTPSamplers extends Te
assertEquals("http://192.168.0.1/index.html?param1", config.getUrl().toString());
}
+ @Test
public void testMakingUrl10() throws Exception {
HTTPSamplerBase config = new HTTPNullSampler();
config.setProtocol("http");
@@ -246,6 +260,7 @@ public class TestHTTPSamplers extends Te
assertEquals("http://192.168.0.1/index.html", config.getUrl().toString());
}
+ @Test
public void testFileList(){
HTTPSamplerBase config = new HTTPNullSampler();
HTTPFileArg[] arg;
@@ -314,6 +329,7 @@ public class TestHTTPSamplers extends Te
assertEquals(2,arg.length);
}
+ @Test
public void testSetAndGetFileField() {
HTTPSamplerBase sampler = new HTTPNullSampler();
sampler.setHTTPFiles(new HTTPFileArg[]{new HTTPFileArg("","param","")});
@@ -325,6 +341,7 @@ public class TestHTTPSamplers extends Te
assertEquals("param2", file.getParamName());
}
+ @Test
public void testSetAndGetFilename() {
HTTPSamplerBase sampler = new HTTPNullSampler();
sampler.setHTTPFiles(new HTTPFileArg[]{new HTTPFileArg("name","","")});
@@ -336,6 +353,7 @@ public class TestHTTPSamplers extends Te
assertEquals("name2", file.getPath());
}
+ @Test
public void testSetAndGetMimetype() {
HTTPSamplerBase sampler = new HTTPNullSampler();
sampler.setHTTPFiles(new HTTPFileArg[]{new HTTPFileArg("","","mime")});
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/sampler/TestHTTPSamplersAgainstHttpMirrorServer.java Tue Feb 2 21:35:58 2016
@@ -24,12 +24,12 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
import java.net.URL;
+import java.net.URLEncoder;
import java.util.Locale;
import org.apache.jmeter.engine.util.ValueReplacer;
-import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.junit.JMeterTestCaseJUnit3;
import org.apache.jmeter.protocol.http.control.HttpMirrorServer;
import org.apache.jmeter.protocol.http.control.TestHTTPMirrorThread;
import org.apache.jmeter.protocol.http.util.EncoderCache;
@@ -47,16 +47,16 @@ import org.apache.oro.text.regex.Perl5Co
import org.apache.oro.text.regex.Perl5Matcher;
import org.junit.Assert;
+import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestSuite;
-import junit.extensions.TestSetup;
/**
* Class for performing actual samples for HTTPSampler and HTTPSampler2.
* The samples are executed against the HttpMirrorServer, which is
* started when the unit tests are executed.
*/
-public class TestHTTPSamplersAgainstHttpMirrorServer extends JMeterTestCase {
+public class TestHTTPSamplersAgainstHttpMirrorServer extends JMeterTestCaseJUnit3 {
private static final int HTTP_SAMPLER = 0;
private static final int HTTP_SAMPLER2 = 1;
private static final int HTTP_SAMPLER3 = 2;
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPArgument.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPArgument.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPArgument.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPArgument.java Tue Feb 2 21:35:58 2016
@@ -18,16 +18,15 @@
package org.apache.jmeter.protocol.http.util;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.testelement.property.CollectionProperty;
+import org.junit.Test;
-public class TestHTTPArgument extends TestCase {
- public TestHTTPArgument(String name) {
- super(name);
- }
+public class TestHTTPArgument {
+ @Test
public void testCloning() throws Exception {
HTTPArgument arg = new HTTPArgument("name.?", "value_ here");
assertEquals("name.?", arg.getName());
@@ -41,6 +40,7 @@ public class TestHTTPArgument extends Te
assertEquals("value_ here", clone.getValue());
}
+ @Test
public void testConversion() throws Exception {
Arguments args = new Arguments();
args.addArgument("name.?", "value_ here");
@@ -55,6 +55,7 @@ public class TestHTTPArgument extends Te
assertEquals("value_.%2B", httpArg.getEncodedValue());
}
+ @Test
public void testEncoding() throws Exception {
HTTPArgument arg;
arg = new HTTPArgument("name.?", "value_ here", false);
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPFileArg.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPFileArg.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPFileArg.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPFileArg.java Tue Feb 2 21:35:58 2016
@@ -18,13 +18,13 @@
package org.apache.jmeter.protocol.http.util;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
-public class TestHTTPFileArg extends TestCase {
- public TestHTTPFileArg(String name) {
- super(name);
- }
+import org.junit.Test;
+
+public class TestHTTPFileArg {
+ @Test
public void testConstructors() throws Exception {
HTTPFileArg file = new HTTPFileArg();
assertEquals("no parameter failure", "", file.getPath());
@@ -44,6 +44,7 @@ public class TestHTTPFileArg extends Tes
assertEquals("copy constructor failure", "mimetype", file2.getMimeType());
}
+ @Test
public void testGettersSetters() throws Exception {
HTTPFileArg file = new HTTPFileArg();
assertEquals("", file.getPath());
@@ -59,6 +60,7 @@ public class TestHTTPFileArg extends Tes
assertEquals("header", file.getHeader());
}
+ @Test
public void testToString() throws Exception {
HTTPFileArg file = new HTTPFileArg("path1", "param1", "mimetype1");
assertEquals("path:'path1'|param:'param1'|mimetype:'mimetype1'", file.toString());
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPFileArgs.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPFileArgs.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPFileArgs.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPFileArgs.java Tue Feb 2 21:35:58 2016
@@ -19,21 +19,22 @@
package org.apache.jmeter.protocol.http.util;
import java.util.List;
-import java.util.LinkedList;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import java.util.LinkedList;
import org.apache.jmeter.testelement.property.PropertyIterator;
+import org.junit.Test;
-public class TestHTTPFileArgs extends TestCase {
- public TestHTTPFileArgs(String name) {
- super(name);
- }
+public class TestHTTPFileArgs {
+ @Test
public void testConstructors() throws Exception {
HTTPFileArgs files = new HTTPFileArgs();
assertEquals(0, files.getHTTPFileArgCount());
}
+ @Test
public void testAdding() throws Exception {
HTTPFileArgs files = new HTTPFileArgs();
assertEquals(0, files.getHTTPFileArgCount());
@@ -54,6 +55,7 @@ public class TestHTTPFileArgs extends Te
assertEquals("", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
}
+ @Test
public void testSetHTTPFileArgs() throws Exception {
List<HTTPFileArg> newHTTPFileArgs = new LinkedList<>();
newHTTPFileArgs.add(new HTTPFileArg("hede"));
@@ -63,6 +65,7 @@ public class TestHTTPFileArgs extends Te
assertEquals("hede", ((HTTPFileArg) files.iterator().next().getObjectValue()).getPath());
}
+ @Test
public void testRemoving() throws Exception {
HTTPFileArgs files = new HTTPFileArgs();
assertEquals(0, files.getHTTPFileArgCount());
@@ -108,6 +111,7 @@ public class TestHTTPFileArgs extends Te
assertEquals(0, files.getHTTPFileArgCount());
}
+ @Test
public void testToString() throws Exception {
HTTPFileArgs files = new HTTPFileArgs();
files.addHTTPFileArg("file1");
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/TestHTTPUtils.java Tue Feb 2 21:35:58 2016
@@ -18,16 +18,16 @@
package org.apache.jmeter.protocol.http.util;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
import java.net.URI;
import java.net.URL;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-public class TestHTTPUtils extends TestCase {
- public TestHTTPUtils(String name) {
- super(name);
- }
+public class TestHTTPUtils {
+ @Test
public void testgetEncoding() throws Exception {
assertNull(ConversionUtils.getEncodingFromContentType("xyx"));
assertEquals("utf8",ConversionUtils.getEncodingFromContentType("charset=utf8"));
@@ -39,6 +39,7 @@ public class TestHTTPUtils extends TestC
assertNull(ConversionUtils.getEncodingFromContentType(";charset=no-such-charset;"));
}
+ @Test
public void testMakeRelativeURL() throws Exception {
URL base = new URL("http://192.168.0.1/a/b/c"); // Trailing file
assertEquals(new URL("http://192.168.0.1/a/b/d"),ConversionUtils.makeRelativeURL(base,"d"));
@@ -50,6 +51,7 @@ public class TestHTTPUtils extends TestC
assertEquals(new URL("http://192.168.0.1/a/b/d"),ConversionUtils.makeRelativeURL(base,"./d"));
}
+ @Test
public void testMakeRelativeURL2() throws Exception {
URL base = new URL("http://192.168.0.1/a/b/c/"); // Trailing directory
assertEquals(new URL("http://192.168.0.1/a/b/c/d"),ConversionUtils.makeRelativeURL(base,"d"));
@@ -62,6 +64,7 @@ public class TestHTTPUtils extends TestC
}
// Test that location urls with a protocol are passed unchanged
+ @Test
public void testMakeRelativeURL3() throws Exception {
URL base = new URL("http://ahost.invalid/a/b/c");
assertEquals(new URL("http://host.invalid/e"),ConversionUtils.makeRelativeURL(base ,"http://host.invalid/e"));
@@ -70,6 +73,7 @@ public class TestHTTPUtils extends TestC
assertEquals(new URL("https://host.invalid:8081/e"),ConversionUtils.makeRelativeURL(base ,"https://host.invalid:8081/e"));
}
+ @Test
public void testRemoveSlashDotDot()
{
assertEquals("/path/", ConversionUtils.removeSlashDotDot("/path/"));
@@ -91,6 +95,7 @@ public class TestHTTPUtils extends TestC
assertEquals("http://host/../abc", ConversionUtils.removeSlashDotDot("http://host/../abc"));
}
+ @Test
public void testsanitizeUrl() throws Exception {
testSanitizeUrl("http://localhost/", "http://localhost/"); // normal, no encoding needed
testSanitizeUrl("http://localhost/a/b/c%7Cd", "http://localhost/a/b/c|d"); // pipe needs encoding
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/accesslog/TestLogFilter.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/accesslog/TestLogFilter.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/accesslog/TestLogFilter.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/accesslog/TestLogFilter.java Tue Feb 2 21:35:58 2016
@@ -18,7 +18,13 @@
package org.apache.jmeter.protocol.http.util.accesslog;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.apache.jmeter.junit.JMeterTestCase;
+import org.junit.Before;
+import org.junit.Test;
public class TestLogFilter extends JMeterTestCase {
@@ -70,23 +76,26 @@ public class TestLogFilter extends JMete
new TestData("oldindex6.jsp", true, false, false, true),
new TestData("/test/index.htm", true, false, false, true) };
+ @Test
public void testConstruct() {
new LogFilter();
}
private LogFilter testf;
- @Override
+ @Before
public void setUp() {
testf = new LogFilter();
}
+ @Test
public void testReplaceExtension() {
testf.setReplaceExtension("html", "jsp");
testf.isFiltered(TESTSTR,null);// set the required variables
assertEquals(TESTSTROUT, testf.filter(TESTSTR));
}
+ @Test
public void testExcludeFiles() {
testf.excludeFiles(INCL);
for (TestData td : TESTDATA) {
@@ -103,6 +112,7 @@ public class TestLogFilter extends JMete
}
}
+ @Test
public void testIncludeFiles() {
testf.includeFiles(INCL);
for (TestData td : TESTDATA) {
@@ -120,6 +130,7 @@ public class TestLogFilter extends JMete
}
+ @Test
public void testExcludePattern() {
testf.excludePattern(PATTERNS);
for (TestData td : TESTDATA) {
@@ -136,6 +147,7 @@ public class TestLogFilter extends JMete
}
}
+ @Test
public void testIncludePattern() {
testf.includePattern(PATTERNS);
for (TestData td : TESTDATA) {
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/accesslog/TestTCLogParser.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/accesslog/TestTCLogParser.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/accesslog/TestTCLogParser.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/http/util/accesslog/TestTCLogParser.java Tue Feb 2 21:35:58 2016
@@ -18,12 +18,18 @@
package org.apache.jmeter.protocol.http.util.accesslog;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import org.apache.jmeter.junit.JMeterTestCase;
import org.apache.jmeter.protocol.http.sampler.HTTPNullSampler;
+import org.junit.Test;
// TODO - more tests needed
-public class TestTCLogParser extends JMeterTestCase {
+public class TestTCLogParser extends JMeterTestCase {
private static final TCLogParser tclp = new TCLogParser();
private static final String URL1 = "127.0.0.1 - - [08/Jan/2003:07:03:54 -0500] \"GET /addrbook/ HTTP/1.1\" 200 1981";
@@ -32,6 +38,7 @@ public class TestTCLogParser extends JM
private static final String TEST3 = "127.0.0.1 - - [08/Jan/2003:07:03:54 -0500] \"HEAD /addrbook/ HTTP/1.1\" 200 1981";
+ @Test
public void testConstruct() throws Exception {
TCLogParser tcp;
tcp = new TCLogParser();
@@ -42,17 +49,20 @@ public class TestTCLogParser extends JM
assertEquals("Filename should have been saved", file, tcp.FILENAME);
}
+ @Test
public void testcleanURL() throws Exception {
String res = tclp.cleanURL(URL1);
assertEquals("/addrbook/", res);
assertNull(tclp.stripFile(res, new HTTPNullSampler()));
}
+ @Test
public void testcheckURL() throws Exception {
assertFalse("URL does not have a query", tclp.checkURL(URL1));
assertTrue("URL is a query", tclp.checkURL(URL2));
}
+ @Test
public void testHEAD() throws Exception {
String res = tclp.cleanURL(TEST3);
assertEquals("/addrbook/", res);
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/ldap/config/gui/PackageTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/ldap/config/gui/PackageTest.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/ldap/config/gui/PackageTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/ldap/config/gui/PackageTest.java Tue Feb 2 21:35:58 2016
@@ -18,19 +18,12 @@
package org.apache.jmeter.protocol.ldap.config.gui;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
-public class PackageTest extends TestCase {
- /**
- * Create a new test.
- *
- * @param name
- * the name of the test
- */
- public PackageTest(String name) {
- super(name);
- }
+import org.junit.Test;
+public class PackageTest {
+
/**
* Test that adding an argument to the table results in an appropriate
* TestElement being created.
@@ -38,6 +31,7 @@ public class PackageTest extends TestCas
* @throws Exception
* if an exception occurred during the test
*/
+ @Test
public void testLDAPArgumentCreation() throws Exception {
LDAPArgumentsPanel gui = new LDAPArgumentsPanel();
gui.tableModel.addRow(new LDAPArgument());
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImplTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImplTest.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImplTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/BinaryTCPClientImplTest.java Tue Feb 2 21:35:58 2016
@@ -22,16 +22,18 @@
*/
package org.apache.jmeter.protocol.tcp.sampler;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
-
-import junit.framework.TestCase;
-
import org.apache.jorphan.util.JOrphanUtils;
+import org.junit.Test;
-public class BinaryTCPClientImplTest extends TestCase {
+public class BinaryTCPClientImplTest {
+ @Test
public void testHexStringToByteArray() throws Exception {
byte [] ba;
ba = BinaryTCPClientImpl.hexStringToByteArray("");
@@ -63,10 +65,12 @@ public class BinaryTCPClientImplTest ext
}
}
+ @Test
public void testLoopBack() throws Exception {
assertEquals("0f107f8081ff", JOrphanUtils.baToHexString(BinaryTCPClientImpl.hexStringToByteArray("0f107f8081ff")));
}
+ @Test
public void testRoundTrip() throws Exception {
BinaryTCPClientImpl bi = new BinaryTCPClientImpl();
InputStream is = null;
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/LengthPrefixedBinaryTCPClientImplTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/LengthPrefixedBinaryTCPClientImplTest.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/LengthPrefixedBinaryTCPClientImplTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/LengthPrefixedBinaryTCPClientImplTest.java Tue Feb 2 21:35:58 2016
@@ -22,13 +22,16 @@
*/
package org.apache.jmeter.protocol.tcp.sampler;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import org.junit.Test;
-import junit.framework.TestCase;
-
-public class LengthPrefixedBinaryTCPClientImplTest extends TestCase {
+public class LengthPrefixedBinaryTCPClientImplTest {
+ @Test
public void testError() throws Exception {
ByteArrayOutputStream os = null;
ByteArrayInputStream is = null;
@@ -40,6 +43,7 @@ public class LengthPrefixedBinaryTCPClie
}
}
+ @Test
public void testValid() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream();
LengthPrefixedBinaryTCPClientImpl lp = new LengthPrefixedBinaryTCPClientImpl();
Modified: jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/TCPClientDecoratorTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/TCPClientDecoratorTest.java?rev=1728220&r1=1728219&r2=1728220&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/TCPClientDecoratorTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/protocol/tcp/sampler/TCPClientDecoratorTest.java Tue Feb 2 21:35:58 2016
@@ -22,11 +22,15 @@
*/
package org.apache.jmeter.protocol.tcp.sampler;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
-public class TCPClientDecoratorTest extends TestCase {
+import org.junit.Test;
+
+public class TCPClientDecoratorTest {
+ @Test
public void testIntToByteArray() throws Exception {
byte[] ba;
int len = 2;
@@ -166,6 +170,7 @@ public class TCPClientDecoratorTest exte
}
}
+ @Test
public void testByteArrayToInt() throws Exception {
byte[] ba;
@@ -238,6 +243,7 @@ public class TCPClientDecoratorTest exte
}
+ @Test
public void testLoopBack() throws Exception {
assertEquals(Short.MIN_VALUE, TCPClientDecorator.byteArrayToInt(TCPClientDecorator.intToByteArray(Short.MIN_VALUE, 2)));
assertEquals(Short.MAX_VALUE, TCPClientDecorator.byteArrayToInt(TCPClientDecorator.intToByteArray(Short.MAX_VALUE, 2)));