You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2010/04/27 20:01:50 UTC
svn commit: r938585 [8/8] - in /httpcomponents/httpclient/trunk: ./
httpclient/src/test/java/org/apache/http/auth/
httpclient/src/test/java/org/apache/http/client/methods/
httpclient/src/test/java/org/apache/http/client/protocol/
httpclient/src/test/ja...
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestNetscapeCookieAttribHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestNetscapeCookieAttribHandlers.java?rev=938585&r1=938584&r2=938585&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestNetscapeCookieAttribHandlers.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestNetscapeCookieAttribHandlers.java Tue Apr 27 18:01:48 2010
@@ -27,30 +27,15 @@
package org.apache.http.impl.cookie;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
+import org.junit.Assert;
+import org.junit.Test;
-public class TestNetscapeCookieAttribHandlers extends TestCase {
-
- public TestNetscapeCookieAttribHandlers(String testName) {
- super(testName);
- }
-
- public static Test suite() {
- return new TestSuite(TestNetscapeCookieAttribHandlers.class);
- }
-
- // ------------------------------------------------------------------- Main
- public static void main(String args[]) {
- String[] testCaseName = { TestNetscapeCookieAttribHandlers.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
- }
+public class TestNetscapeCookieAttribHandlers {
+ @Test
public void testNetscapeDomainValidate1() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
@@ -62,12 +47,13 @@ public class TestNetscapeCookieAttribHan
cookie.setDomain("otherhost");
try {
h.validate(cookie, origin);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
}
+ @Test
public void testNetscapeDomainValidate2() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
@@ -79,19 +65,20 @@ public class TestNetscapeCookieAttribHan
cookie.setDomain(".otherdomain.com");
try {
h.validate(cookie, origin);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
cookie.setDomain("www.otherdomain.com");
try {
h.validate(cookie, origin);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
}
+ @Test
public void testNetscapeDomainValidate3() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.a.com", 80, "/", false);
@@ -103,12 +90,13 @@ public class TestNetscapeCookieAttribHan
cookie.setDomain(".com");
try {
h.validate(cookie, origin);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
}
+ @Test
public void testNetscapeDomainValidate4() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.a.b.c", 80, "/", false);
@@ -120,44 +108,47 @@ public class TestNetscapeCookieAttribHan
cookie.setDomain(".b.c");
try {
h.validate(cookie, origin);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
}
+ @Test
public void testNetscapeDomainMatch1() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new NetscapeDomainHandler();
cookie.setDomain(null);
- assertFalse(h.match(cookie, origin));
+ Assert.assertFalse(h.match(cookie, origin));
cookie.setDomain(".somedomain.com");
- assertTrue(h.match(cookie, origin));
+ Assert.assertTrue(h.match(cookie, origin));
}
+ @Test
public void testNetscapeDomainMatch2() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.whatever.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new NetscapeDomainHandler();
cookie.setDomain(".somedomain.com");
- assertTrue(h.match(cookie, origin));
+ Assert.assertTrue(h.match(cookie, origin));
}
+ @Test
public void testNetscapeDomainInvalidInput() throws Exception {
CookieAttributeHandler h = new NetscapeDomainHandler();
try {
h.match(null, null);
- fail("IllegalArgumentException must have been thrown");
+ Assert.fail("IllegalArgumentException must have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
try {
h.match(new BasicClientCookie("name", "value"), null);
- fail("IllegalArgumentException must have been thrown");
+ Assert.fail("IllegalArgumentException must have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestNetscapeDraftHeaderParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestNetscapeDraftHeaderParser.java?rev=938585&r1=938584&r2=938585&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestNetscapeDraftHeaderParser.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestNetscapeDraftHeaderParser.java Tue Apr 27 18:01:48 2010
@@ -31,30 +31,15 @@ import org.apache.http.HeaderElement;
import org.apache.http.NameValuePair;
import org.apache.http.message.ParserCursor;
import org.apache.http.util.CharArrayBuffer;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.Assert;
+import org.junit.Test;
/**
* Unit tests for {@link NetscapeDraftHeaderParser}.
- *
*/
-public class TestNetscapeDraftHeaderParser extends TestCase {
-
- public TestNetscapeDraftHeaderParser(String testName) {
- super(testName);
- }
-
- public static void main(String args[]) {
- String[] testCaseName = { TestNetscapeDraftHeaderParser.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
- }
-
- public static Test suite() {
- return new TestSuite(TestNetscapeDraftHeaderParser.class);
- }
+public class TestNetscapeDraftHeaderParser {
+ @Test
public void testNetscapeCookieParsing() throws Exception {
NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
@@ -65,27 +50,27 @@ public class TestNetscapeDraftHeaderPars
ParserCursor cursor = new ParserCursor(0, s.length());
HeaderElement he = parser.parseHeader(buffer, cursor);
- assertEquals("name", he.getName());
- assertEquals("value", he.getValue());
+ Assert.assertEquals("name", he.getName());
+ Assert.assertEquals("value", he.getValue());
NameValuePair[] params = he.getParameters();
- assertEquals("test", params[0].getName());
- assertEquals(null, params[0].getValue());
- assertEquals("test1", params[1].getName());
- assertEquals("stuff,with,commas", params[1].getValue());
- assertEquals("test2", params[2].getName());
- assertEquals("stuff; stuff", params[2].getValue());
- assertEquals("test3", params[3].getName());
- assertEquals("\"stuff", params[3].getValue());
- assertEquals(s.length(), cursor.getPos());
- assertTrue(cursor.atEnd());
+ Assert.assertEquals("test", params[0].getName());
+ Assert.assertEquals(null, params[0].getValue());
+ Assert.assertEquals("test1", params[1].getName());
+ Assert.assertEquals("stuff,with,commas", params[1].getValue());
+ Assert.assertEquals("test2", params[2].getName());
+ Assert.assertEquals("stuff; stuff", params[2].getValue());
+ Assert.assertEquals("test3", params[3].getName());
+ Assert.assertEquals("\"stuff", params[3].getValue());
+ Assert.assertEquals(s.length(), cursor.getPos());
+ Assert.assertTrue(cursor.atEnd());
s = " ";
buffer = new CharArrayBuffer(16);
buffer.append(s);
cursor = new ParserCursor(0, s.length());
he = parser.parseHeader(buffer, cursor);
- assertEquals("", he.getName());
- assertEquals(null, he.getValue());
+ Assert.assertEquals("", he.getName());
+ Assert.assertEquals(null, he.getValue());
}
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestPublicSuffixListParser.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestPublicSuffixListParser.java?rev=938585&r1=938584&r2=938585&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestPublicSuffixListParser.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestPublicSuffixListParser.java Tue Apr 27 18:01:48 2010
@@ -1,8 +1,4 @@
/*
- * $HeadURL$
- * $Revision$
- * $Date$
- *
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -31,85 +27,75 @@
package org.apache.http.impl.cookie;
-import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import junit.framework.Assert;
import org.apache.http.cookie.CookieOrigin;
+import org.junit.Before;
+import org.junit.Test;
-public class TestPublicSuffixListParser extends TestCase {
+public class TestPublicSuffixListParser {
private static final String LIST_FILE = "/suffixlist.txt";
private PublicSuffixFilter filter;
- public TestPublicSuffixListParser(String testName) {
- super(testName);
- try {
- Reader r = new InputStreamReader(getClass().getResourceAsStream(LIST_FILE), "UTF-8");
- filter = new PublicSuffixFilter(new RFC2109DomainHandler());
- PublicSuffixListParser parser = new PublicSuffixListParser(filter);
- parser.parse(r);
- } catch (IOException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- public static Test suite() {
- return new TestSuite(TestPublicSuffixListParser.class);
- }
-
- public static void main(String args[]) {
- String[] testCaseName = { TestPublicSuffixListParser.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
+ @Before
+ public void setUp() throws Exception {
+ Reader r = new InputStreamReader(getClass().getResourceAsStream(LIST_FILE), "UTF-8");
+ filter = new PublicSuffixFilter(new RFC2109DomainHandler());
+ PublicSuffixListParser parser = new PublicSuffixListParser(filter);
+ parser.parse(r);
}
+ @Test
public void testParse() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
cookie.setDomain(".jp");
- assertFalse(filter.match(cookie, new CookieOrigin("apache.jp", 80, "/stuff", false)));
+ Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.jp", 80, "/stuff", false)));
cookie.setDomain(".ac.jp");
- assertFalse(filter.match(cookie, new CookieOrigin("apache.ac.jp", 80, "/stuff", false)));
+ Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.ac.jp", 80, "/stuff", false)));
cookie.setDomain(".any.tokyo.jp");
- assertFalse(filter.match(cookie, new CookieOrigin("apache.any.tokyo.jp", 80, "/stuff", false)));
+ Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.any.tokyo.jp", 80, "/stuff", false)));
// exception
cookie.setDomain(".metro.tokyo.jp");
- assertTrue(filter.match(cookie, new CookieOrigin("apache.metro.tokyo.jp", 80, "/stuff", false)));
+ Assert.assertTrue(filter.match(cookie, new CookieOrigin("apache.metro.tokyo.jp", 80, "/stuff", false)));
}
+ @Test
public void testUnicode() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
cookie.setDomain(".h\u00E5.no"); // \u00E5 is <aring>
- assertFalse(filter.match(cookie, new CookieOrigin("apache.h\u00E5.no", 80, "/stuff", false)));
+ Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.h\u00E5.no", 80, "/stuff", false)));
cookie.setDomain(".xn--h-2fa.no");
- assertFalse(filter.match(cookie, new CookieOrigin("apache.xn--h-2fa.no", 80, "/stuff", false)));
+ Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.xn--h-2fa.no", 80, "/stuff", false)));
cookie.setDomain(".h\u00E5.no");
- assertFalse(filter.match(cookie, new CookieOrigin("apache.xn--h-2fa.no", 80, "/stuff", false)));
+ Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.xn--h-2fa.no", 80, "/stuff", false)));
cookie.setDomain(".xn--h-2fa.no");
- assertFalse(filter.match(cookie, new CookieOrigin("apache.h\u00E5.no", 80, "/stuff", false)));
+ Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.h\u00E5.no", 80, "/stuff", false)));
}
+ @Test
public void testWhitespace() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
cookie.setDomain(".xx");
- assertFalse(filter.match(cookie, new CookieOrigin("apache.xx", 80, "/stuff", false)));
+ Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.xx", 80, "/stuff", false)));
// yy appears after whitespace
cookie.setDomain(".yy");
- assertTrue(filter.match(cookie, new CookieOrigin("apache.yy", 80, "/stuff", false)));
+ Assert.assertTrue(filter.match(cookie, new CookieOrigin("apache.yy", 80, "/stuff", false)));
// zz is commented
cookie.setDomain(".zz");
- assertTrue(filter.match(cookie, new CookieOrigin("apache.zz", 80, "/stuff", false)));
+ Assert.assertTrue(filter.match(cookie, new CookieOrigin("apache.zz", 80, "/stuff", false)));
}
+
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestRFC2109CookieAttribHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestRFC2109CookieAttribHandlers.java?rev=938585&r1=938584&r2=938585&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestRFC2109CookieAttribHandlers.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/cookie/TestRFC2109CookieAttribHandlers.java Tue Apr 27 18:01:48 2010
@@ -27,51 +27,37 @@
package org.apache.http.impl.cookie;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.apache.http.cookie.CookieAttributeHandler;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.MalformedCookieException;
+import org.junit.Assert;
+import org.junit.Test;
-public class TestRFC2109CookieAttribHandlers extends TestCase {
-
- public TestRFC2109CookieAttribHandlers(String testName) {
- super(testName);
- }
-
- public static Test suite() {
- return new TestSuite(TestRFC2109CookieAttribHandlers.class);
- }
-
- // ------------------------------------------------------------------- Main
- public static void main(String args[]) {
- String[] testCaseName = { TestRFC2109CookieAttribHandlers.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
- }
+public class TestRFC2109CookieAttribHandlers {
+ @Test
public void testRFC2109DomainParse() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieAttributeHandler h = new RFC2109DomainHandler();
h.parse(cookie, "somehost");
- assertEquals("somehost", cookie.getDomain());
+ Assert.assertEquals("somehost", cookie.getDomain());
try {
h.parse(cookie, null);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
try {
h.parse(cookie, " ");
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
}
+ @Test
public void testRFC2109DomainValidate1() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
@@ -83,19 +69,20 @@ public class TestRFC2109CookieAttribHand
cookie.setDomain("otherhost");
try {
h.validate(cookie, origin);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
cookie.setDomain(null);
try {
h.validate(cookie, origin);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
}
+ @Test
public void testRFC2109DomainValidate2() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
@@ -107,19 +94,20 @@ public class TestRFC2109CookieAttribHand
cookie.setDomain(".otherdomain.com");
try {
h.validate(cookie, origin);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
cookie.setDomain("www.otherdomain.com");
try {
h.validate(cookie, origin);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
}
+ @Test
public void testRFC2109DomainValidate3() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.a.com", 80, "/", false);
@@ -131,12 +119,13 @@ public class TestRFC2109CookieAttribHand
cookie.setDomain(".com");
try {
h.validate(cookie, origin);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
}
+ @Test
public void testRFC2109DomainValidate4() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.a.b.c", 80, "/", false);
@@ -148,122 +137,130 @@ public class TestRFC2109CookieAttribHand
cookie.setDomain(".b.c");
try {
h.validate(cookie, origin);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
cookie.setDomain(".a.a.b.c");
try {
h.validate(cookie, origin);
- fail("MalformedCookieException should have been thrown");
+ Assert.fail("MalformedCookieException should have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
}
+ @Test
public void testRFC2109DomainMatch1() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new RFC2109DomainHandler();
cookie.setDomain(null);
- assertFalse(h.match(cookie, origin));
+ Assert.assertFalse(h.match(cookie, origin));
cookie.setDomain(".somedomain.com");
- assertTrue(h.match(cookie, origin));
+ Assert.assertTrue(h.match(cookie, origin));
}
+ @Test
public void testRFC2109DomainMatch2() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.whatever.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new RFC2109DomainHandler();
cookie.setDomain(".somedomain.com");
- assertTrue(h.match(cookie, origin));
+ Assert.assertTrue(h.match(cookie, origin));
}
+ @Test
public void testRFC2109DomainMatch3() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
CookieAttributeHandler h = new RFC2109DomainHandler();
cookie.setDomain("somedomain.com");
- assertTrue(h.match(cookie, origin));
+ Assert.assertTrue(h.match(cookie, origin));
}
+ @Test
public void testRFC2109DomainMatch4() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
CookieAttributeHandler h = new RFC2109DomainHandler();
cookie.setDomain("somedomain.com");
- assertFalse(h.match(cookie, origin));
+ Assert.assertFalse(h.match(cookie, origin));
}
+ @Test
public void testRFC2109DomainInvalidInput() throws Exception {
CookieAttributeHandler h = new RFC2109DomainHandler();
try {
h.parse(null, null);
- fail("IllegalArgumentException must have been thrown");
+ Assert.fail("IllegalArgumentException must have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
try {
h.validate(null, null);
- fail("IllegalArgumentException must have been thrown");
+ Assert.fail("IllegalArgumentException must have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
try {
h.validate(new BasicClientCookie("name", "value"), null);
- fail("IllegalArgumentException must have been thrown");
+ Assert.fail("IllegalArgumentException must have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
try {
h.match(null, null);
- fail("IllegalArgumentException must have been thrown");
+ Assert.fail("IllegalArgumentException must have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
try {
h.match(new BasicClientCookie("name", "value"), null);
- fail("IllegalArgumentException must have been thrown");
+ Assert.fail("IllegalArgumentException must have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
}
+ @Test
public void testRFC2109VersionParse() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieAttributeHandler h = new RFC2109VersionHandler();
h.parse(cookie, "12");
- assertEquals(12, cookie.getVersion());
+ Assert.assertEquals(12, cookie.getVersion());
}
+ @Test
public void testRFC2109VersionParseInvalid() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieAttributeHandler h = new RFC2109VersionHandler();
try {
h.parse(cookie, "garbage");
- fail("MalformedCookieException must have been thrown");
+ Assert.fail("MalformedCookieException must have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
try {
h.parse(cookie, null);
- fail("MalformedCookieException must have been thrown");
+ Assert.fail("MalformedCookieException must have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
try {
h.parse(cookie, " ");
- fail("MalformedCookieException must have been thrown");
+ Assert.fail("MalformedCookieException must have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
}
+ @Test
public void testRFC2109VersionValidate() throws Exception {
BasicClientCookie cookie = new BasicClientCookie("name", "value");
CookieOrigin origin = new CookieOrigin("somedomain.com", 80, "/", false);
@@ -275,23 +272,24 @@ public class TestRFC2109CookieAttribHand
cookie.setVersion(-12);
try {
h.validate(cookie, origin);
- fail("MalformedCookieException must have been thrown");
+ Assert.fail("MalformedCookieException must have been thrown");
} catch (MalformedCookieException ex) {
// expected
}
}
+ @Test
public void testRFC2109VersionInvalidInput() throws Exception {
CookieAttributeHandler h = new RFC2109VersionHandler();
try {
h.parse(null, null);
- fail("IllegalArgumentException must have been thrown");
+ Assert.fail("IllegalArgumentException must have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
try {
h.validate(null, null);
- fail("IllegalArgumentException must have been thrown");
+ Assert.fail("IllegalArgumentException must have been thrown");
} catch (IllegalArgumentException ex) {
// expected
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/BasicServerTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/BasicServerTestBase.java?rev=938585&r1=938584&r2=938585&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/BasicServerTestBase.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/BasicServerTestBase.java Tue Apr 27 18:01:48 2010
@@ -29,25 +29,20 @@ package org.apache.http.localserver;
import java.net.InetSocketAddress;
-import junit.framework.TestCase;
-
import org.apache.http.HttpHost;
+import org.junit.After;
/**
* Base class for tests using {@link LocalTestServer}. The server will not be started
* per default.
*/
-public abstract class BasicServerTestBase extends TestCase {
+public abstract class BasicServerTestBase {
/** The local server for testing. */
protected LocalTestServer localServer;
- protected BasicServerTestBase(String testName) {
- super(testName);
- }
-
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
if (localServer != null) {
localServer.stop();
}
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java?rev=938585&r1=938584&r2=938585&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java Tue Apr 27 18:01:48 2010
@@ -46,6 +46,7 @@ import org.apache.http.protocol.BasicHtt
import org.apache.http.protocol.HttpRequestExecutor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
+import org.junit.Before;
/**
* Base class for tests using {@link LocalTestServer LocalTestServer}.
@@ -72,13 +73,6 @@ public abstract class ServerTestBase ext
/** The request executor for the client side. */
protected HttpRequestExecutor httpExecutor;
-
-
- protected ServerTestBase(String testName) {
- super(testName);
- }
-
-
/**
* Prepares the local server for testing.
* Derived classes that override this method MUST call
@@ -101,8 +95,8 @@ public abstract class ServerTestBase ext
*
* @throws Exception in case of a problem
*/
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
if (defaultParams == null) {
defaultParams = new SyncBasicHttpParams();
@@ -189,5 +183,4 @@ public abstract class ServerTestBase ext
return conn;
}
-
-} // class ServerTestBase
+}
Modified: httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartContentBody.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartContentBody.java?rev=938585&r1=938584&r2=938585&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartContentBody.java (original)
+++ httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartContentBody.java Tue Apr 27 18:01:48 2010
@@ -30,81 +30,65 @@ package org.apache.http.entity.mime;
import java.io.ByteArrayInputStream;
import java.nio.charset.Charset;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.entity.mime.content.StringBody;
+import org.junit.Assert;
+import org.junit.Test;
-public class TestMultipartContentBody extends TestCase {
-
- // ------------------------------------------------------------ Constructor
- public TestMultipartContentBody(final String testName) {
- super(testName);
- }
-
- // ------------------------------------------------------------------- Main
- public static void main(String args[]) {
- String[] testCaseName = { TestMultipartContentBody.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
- }
-
- // ------------------------------------------------------- TestCase Methods
-
- public static Test suite() {
- return new TestSuite(TestMultipartContentBody.class);
- }
+public class TestMultipartContentBody {
+ @Test
public void testStringBody() throws Exception {
StringBody b1 = new StringBody("text");
- assertEquals(4, b1.getContentLength());
+ Assert.assertEquals(4, b1.getContentLength());
Charset defCharset = Charset.defaultCharset();
- assertEquals(defCharset.name(), b1.getCharset());
+ Assert.assertEquals(defCharset.name(), b1.getCharset());
- assertNull(b1.getFilename());
- assertEquals("text/plain", b1.getMimeType());
- assertEquals("text", b1.getMediaType());
- assertEquals("plain", b1.getSubType());
+ Assert.assertNull(b1.getFilename());
+ Assert.assertEquals("text/plain", b1.getMimeType());
+ Assert.assertEquals("text", b1.getMediaType());
+ Assert.assertEquals("plain", b1.getSubType());
- assertEquals(MIME.ENC_8BIT, b1.getTransferEncoding());
+ Assert.assertEquals(MIME.ENC_8BIT, b1.getTransferEncoding());
StringBody b2 = new StringBody("more text", "text/other", MIME.DEFAULT_CHARSET);
- assertEquals(9, b2.getContentLength());
- assertEquals(MIME.DEFAULT_CHARSET.name(), b2.getCharset());
+ Assert.assertEquals(9, b2.getContentLength());
+ Assert.assertEquals(MIME.DEFAULT_CHARSET.name(), b2.getCharset());
- assertNull(b2.getFilename());
- assertEquals("text/other", b2.getMimeType());
- assertEquals("text", b2.getMediaType());
- assertEquals("other", b2.getSubType());
+ Assert.assertNull(b2.getFilename());
+ Assert.assertEquals("text/other", b2.getMimeType());
+ Assert.assertEquals("text", b2.getMediaType());
+ Assert.assertEquals("other", b2.getSubType());
- assertEquals(MIME.ENC_8BIT, b2.getTransferEncoding());
+ Assert.assertEquals(MIME.ENC_8BIT, b2.getTransferEncoding());
}
+ @Test
public void testInputStreamBody() throws Exception {
byte[] stuff = "Stuff".getBytes("US-ASCII");
InputStreamBody b1 = new InputStreamBody(new ByteArrayInputStream(stuff), "stuff");
- assertEquals(-1, b1.getContentLength());
+ Assert.assertEquals(-1, b1.getContentLength());
- assertNull(b1.getCharset());
- assertEquals("stuff", b1.getFilename());
- assertEquals("application/octet-stream", b1.getMimeType());
- assertEquals("application", b1.getMediaType());
- assertEquals("octet-stream", b1.getSubType());
+ Assert.assertNull(b1.getCharset());
+ Assert.assertEquals("stuff", b1.getFilename());
+ Assert.assertEquals("application/octet-stream", b1.getMimeType());
+ Assert.assertEquals("application", b1.getMediaType());
+ Assert.assertEquals("octet-stream", b1.getSubType());
- assertEquals(MIME.ENC_BINARY, b1.getTransferEncoding());
+ Assert.assertEquals(MIME.ENC_BINARY, b1.getTransferEncoding());
InputStreamBody b2 = new InputStreamBody(
new ByteArrayInputStream(stuff), "some/stuff", "stuff");
- assertEquals(-1, b2.getContentLength());
- assertNull(b2.getCharset());
- assertEquals("stuff", b2.getFilename());
- assertEquals("some/stuff", b2.getMimeType());
- assertEquals("some", b2.getMediaType());
- assertEquals("stuff", b2.getSubType());
+ Assert.assertEquals(-1, b2.getContentLength());
+ Assert.assertNull(b2.getCharset());
+ Assert.assertEquals("stuff", b2.getFilename());
+ Assert.assertEquals("some/stuff", b2.getMimeType());
+ Assert.assertEquals("some", b2.getMediaType());
+ Assert.assertEquals("stuff", b2.getSubType());
- assertEquals(MIME.ENC_BINARY, b2.getTransferEncoding());
+ Assert.assertEquals(MIME.ENC_BINARY, b2.getTransferEncoding());
}
+
}
Modified: httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java?rev=938585&r1=938584&r2=938585&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java (original)
+++ httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java Tue Apr 27 18:01:48 2010
@@ -34,36 +34,18 @@ import java.io.FileWriter;
import java.io.Writer;
import java.nio.charset.Charset;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.apache.http.entity.mime.FormBodyPart;
import org.apache.http.entity.mime.HttpMultipart;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.entity.mime.content.StringBody;
+import org.junit.Assert;
+import org.junit.Test;
-public class TestMultipartForm extends TestCase {
-
- // ------------------------------------------------------------ Constructor
- public TestMultipartForm(final String testName) {
- super(testName);
- }
-
- // ------------------------------------------------------------------- Main
- public static void main(String args[]) {
- String[] testCaseName = { TestMultipartForm.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
- }
-
- // ------------------------------------------------------- TestCase Methods
-
- public static Test suite() {
- return new TestSuite(TestMultipartForm.class);
- }
+public class TestMultipartForm {
+ @Test
public void testMultipartFormStringParts() throws Exception {
HttpMultipart multipart = new HttpMultipart("form-data", "foo");
FormBodyPart p1 = new FormBodyPart(
@@ -107,10 +89,11 @@ public class TestMultipartForm extends T
"all kind of stuff\r\n" +
"--foo--\r\n";
String s = out.toString("US-ASCII");
- assertEquals(expected, s);
- assertEquals(s.length(), multipart.getTotalLength());
+ Assert.assertEquals(expected, s);
+ Assert.assertEquals(s.length(), multipart.getTotalLength());
}
+ @Test
public void testMultipartFormBinaryParts() throws Exception {
File tmpfile = File.createTempFile("tmp", ".bin");
tmpfile.deleteOnExit();
@@ -153,12 +136,13 @@ public class TestMultipartForm extends T
"some random whatever\r\n" +
"--foo--\r\n";
String s = out.toString("US-ASCII");
- assertEquals(expected, s);
- assertEquals(-1, multipart.getTotalLength());
+ Assert.assertEquals(expected, s);
+ Assert.assertEquals(-1, multipart.getTotalLength());
tmpfile.delete();
}
+ @Test
public void testMultipartFormBrowserCompatible() throws Exception {
File tmpfile = File.createTempFile("tmp", ".bin");
tmpfile.deleteOnExit();
@@ -214,8 +198,8 @@ public class TestMultipartForm extends T
"some random whatever\r\n" +
"--foo--\r\n";
String s = out.toString("US-ASCII");
- assertEquals(expected, s);
- assertEquals(-1, multipart.getTotalLength());
+ Assert.assertEquals(expected, s);
+ Assert.assertEquals(-1, multipart.getTotalLength());
tmpfile.delete();
}
@@ -239,6 +223,7 @@ public class TestMultipartForm extends T
return buffer.toString();
}
+ @Test
public void testMultipartFormBrowserCompatibleNonASCIIHeaders() throws Exception {
String s1 = constructString(SWISS_GERMAN_HELLO);
String s2 = constructString(RUSSIAN_HELLO);
@@ -282,12 +267,13 @@ public class TestMultipartForm extends T
"some random whatever\r\n" +
"--foo--\r\n";
String s = out.toString("UTF-8");
- assertEquals(expected, s);
- assertEquals(-1, multipart.getTotalLength());
+ Assert.assertEquals(expected, s);
+ Assert.assertEquals(-1, multipart.getTotalLength());
tmpfile.delete();
}
+ @Test
public void testMultipartFormStringPartsMultiCharsets() throws Exception {
String s1 = constructString(SWISS_GERMAN_HELLO);
String s2 = constructString(RUSSIAN_HELLO);
@@ -330,11 +316,11 @@ public class TestMultipartForm extends T
byte[] actual = out1.toByteArray();
byte[] expected = out2.toByteArray();
- assertEquals(expected.length, actual.length);
+ Assert.assertEquals(expected.length, actual.length);
for (int i = 0; i < actual.length; i++) {
- assertEquals(expected[i], actual[i]);
+ Assert.assertEquals(expected[i], actual[i]);
}
- assertEquals(expected.length, multipart.getTotalLength());
+ Assert.assertEquals(expected.length, multipart.getTotalLength());
}
}
Modified: httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartFormHttpEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartFormHttpEntity.java?rev=938585&r1=938584&r2=938585&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartFormHttpEntity.java (original)
+++ httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartFormHttpEntity.java Tue Apr 27 18:01:48 2010
@@ -38,118 +38,103 @@ import org.apache.http.entity.mime.HttpM
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.entity.mime.content.StringBody;
+import org.junit.Assert;
+import org.junit.Test;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-public class TestMultipartFormHttpEntity extends TestCase {
-
- // ------------------------------------------------------------ Constructor
- public TestMultipartFormHttpEntity(final String testName) {
- super(testName);
- }
-
- // ------------------------------------------------------------------- Main
- public static void main(String args[]) {
- String[] testCaseName = { TestMultipartFormHttpEntity.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
- }
-
- // ------------------------------------------------------- TestCase Methods
-
- public static Test suite() {
- return new TestSuite(TestMultipartFormHttpEntity.class);
- }
+public class TestMultipartFormHttpEntity {
+ @Test
public void testExplictContractorParams() throws Exception {
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE,
"whatever",
Charset.forName("UTF-8"));
- assertNull(entity.getContentEncoding());
- assertNotNull(entity.getContentType());
+ Assert.assertNull(entity.getContentEncoding());
+ Assert.assertNotNull(entity.getContentType());
Header header = entity.getContentType();
HeaderElement[] elems = header.getElements();
- assertNotNull(elems);
- assertEquals(1, elems.length);
+ Assert.assertNotNull(elems);
+ Assert.assertEquals(1, elems.length);
HeaderElement elem = elems[0];
- assertEquals("multipart/form-data", elem.getName());
+ Assert.assertEquals("multipart/form-data", elem.getName());
NameValuePair p1 = elem.getParameterByName("boundary");
- assertNotNull(p1);
- assertEquals("whatever", p1.getValue());
+ Assert.assertNotNull(p1);
+ Assert.assertEquals("whatever", p1.getValue());
NameValuePair p2 = elem.getParameterByName("charset");
- assertNotNull(p2);
- assertEquals("UTF-8", p2.getValue());
+ Assert.assertNotNull(p2);
+ Assert.assertEquals("UTF-8", p2.getValue());
}
+ @Test
public void testImplictContractorParams() throws Exception {
MultipartEntity entity = new MultipartEntity();
- assertNull(entity.getContentEncoding());
- assertNotNull(entity.getContentType());
+ Assert.assertNull(entity.getContentEncoding());
+ Assert.assertNotNull(entity.getContentType());
Header header = entity.getContentType();
HeaderElement[] elems = header.getElements();
- assertNotNull(elems);
- assertEquals(1, elems.length);
+ Assert.assertNotNull(elems);
+ Assert.assertEquals(1, elems.length);
HeaderElement elem = elems[0];
- assertEquals("multipart/form-data", elem.getName());
+ Assert.assertEquals("multipart/form-data", elem.getName());
NameValuePair p1 = elem.getParameterByName("boundary");
- assertNotNull(p1);
+ Assert.assertNotNull(p1);
String boundary = p1.getValue();
- assertNotNull(boundary);
+ Assert.assertNotNull(boundary);
- assertTrue(boundary.length() >= 30);
- assertTrue(boundary.length() <= 40);
+ Assert.assertTrue(boundary.length() >= 30);
+ Assert.assertTrue(boundary.length() <= 40);
NameValuePair p2 = elem.getParameterByName("charset");
- assertNull(p2);
+ Assert.assertNull(p2);
}
+ @Test
public void testRepeatable() throws Exception {
MultipartEntity entity = new MultipartEntity();
entity.addPart("p1", new StringBody("blah blah"));
entity.addPart("p2", new StringBody("yada yada"));
- assertTrue(entity.isRepeatable());
- assertFalse(entity.isChunked());
- assertFalse(entity.isStreaming());
+ Assert.assertTrue(entity.isRepeatable());
+ Assert.assertFalse(entity.isChunked());
+ Assert.assertFalse(entity.isStreaming());
long len = entity.getContentLength();
- assertTrue(len == entity.getContentLength());
+ Assert.assertTrue(len == entity.getContentLength());
ByteArrayOutputStream out = new ByteArrayOutputStream();
entity.writeTo(out);
out.close();
byte[] bytes = out.toByteArray();
- assertNotNull(bytes);
- assertTrue(bytes.length == len);
+ Assert.assertNotNull(bytes);
+ Assert.assertTrue(bytes.length == len);
- assertTrue(len == entity.getContentLength());
+ Assert.assertTrue(len == entity.getContentLength());
out = new ByteArrayOutputStream();
entity.writeTo(out);
out.close();
bytes = out.toByteArray();
- assertNotNull(bytes);
- assertTrue(bytes.length == len);
+ Assert.assertNotNull(bytes);
+ Assert.assertTrue(bytes.length == len);
}
+ @Test
public void testNonRepeatable() throws Exception {
MultipartEntity entity = new MultipartEntity();
entity.addPart("p1", new InputStreamBody(
new ByteArrayInputStream("blah blah".getBytes()), null));
entity.addPart("p2", new InputStreamBody(
new ByteArrayInputStream("yada yada".getBytes()), null));
- assertFalse(entity.isRepeatable());
- assertTrue(entity.isChunked());
- assertTrue(entity.isStreaming());
+ Assert.assertFalse(entity.isRepeatable());
+ Assert.assertTrue(entity.isChunked());
+ Assert.assertTrue(entity.isStreaming());
- assertTrue(entity.getContentLength() == -1);
+ Assert.assertTrue(entity.getContentLength() == -1);
}
}
Modified: httpcomponents/httpclient/trunk/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/pom.xml?rev=938585&r1=938584&r2=938585&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/pom.xml (original)
+++ httpcomponents/httpclient/trunk/pom.xml Tue Apr 27 18:01:48 2010
@@ -72,7 +72,7 @@
<commons-logging.version>1.1.1</commons-logging.version>
<commons-codec.version>1.4</commons-codec.version>
<mime4j.version>0.6</mime4j.version>
- <junit.version>3.8.2</junit.version>
+ <junit.version>4.8.1</junit.version>
</properties>
<modules>