hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1417343 [3/3] - in /httpcomponents/httpclient/trunk/httpclient-cache/src: main/java/org/apache/http/impl/client/cache/ test/java/org/apache/http/impl/client/cache/
Date Wed, 05 Dec 2012 10:34:48 GMT
Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRequestProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRequestProtocolCompliance.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRequestProtocolCompliance.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRequestProtocolCompliance.java
Wed Dec  5 10:34:46 2012
@@ -32,6 +32,7 @@ import org.apache.http.HttpEntityEnclosi
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolVersion;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.message.BasicHttpEntityEnclosingRequest;
 import org.apache.http.message.BasicHttpRequest;
 import org.junit.Before;
@@ -41,7 +42,6 @@ public class TestRequestProtocolComplian
 
     private RequestProtocolCompliance impl;
     private HttpRequest req;
-    private HttpRequest result;
 
     @Before
     public void setUp() {
@@ -51,8 +51,9 @@ public class TestRequestProtocolComplian
 
     @Test
     public void doesNotModifyACompliantRequest() throws Exception {
-       result = impl.makeRequestCompliant(req);
-       assertTrue(HttpTestUtils.equivalent(req, result));
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
+        impl.makeRequestCompliant(wrapper);
+        assertTrue(HttpTestUtils.equivalent(req, wrapper));
     }
 
     @Test
@@ -60,70 +61,78 @@ public class TestRequestProtocolComplian
         HttpEntityEnclosingRequest req =
             new BasicHttpEntityEnclosingRequest("TRACE", "/", HttpVersion.HTTP_1_1);
         req.setEntity(HttpTestUtils.makeBody(50));
-        result = impl.makeRequestCompliant(req);
-        if (result instanceof HttpEntityEnclosingRequest) {
-            assertNull(((HttpEntityEnclosingRequest)result).getEntity());
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
+        impl.makeRequestCompliant(wrapper);
+        if (wrapper instanceof HttpEntityEnclosingRequest) {
+            assertNull(((HttpEntityEnclosingRequest) wrapper).getEntity());
         }
     }
 
     @Test
     public void upgrades1_0RequestTo1_1() throws Exception {
         req = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_0);
-        result = impl.makeRequestCompliant(req);
-        assertEquals(HttpVersion.HTTP_1_1, result.getProtocolVersion());
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
+        impl.makeRequestCompliant(wrapper);
+        assertEquals(HttpVersion.HTTP_1_1, wrapper.getProtocolVersion());
     }
 
     @Test
     public void downgrades1_2RequestTo1_1() throws Exception {
         ProtocolVersion HTTP_1_2 = new ProtocolVersion("HTTP", 1, 2);
         req = new BasicHttpRequest("GET", "/", HTTP_1_2);
-        result = impl.makeRequestCompliant(req);
-        assertEquals(HttpVersion.HTTP_1_1, result.getProtocolVersion());
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
+        impl.makeRequestCompliant(wrapper);
+        assertEquals(HttpVersion.HTTP_1_1, wrapper.getProtocolVersion());
     }
 
     @Test
     public void stripsMinFreshFromRequestIfNoCachePresent()
         throws Exception {
         req.setHeader("Cache-Control", "no-cache, min-fresh=10");
-        result = impl.makeRequestCompliant(req);
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
+        impl.makeRequestCompliant(wrapper);
         assertEquals("no-cache",
-                result.getFirstHeader("Cache-Control").getValue());
+                wrapper.getFirstHeader("Cache-Control").getValue());
     }
 
     @Test
     public void stripsMaxFreshFromRequestIfNoCachePresent()
         throws Exception {
         req.setHeader("Cache-Control", "no-cache, max-stale=10");
-        result = impl.makeRequestCompliant(req);
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
+        impl.makeRequestCompliant(wrapper);
         assertEquals("no-cache",
-                result.getFirstHeader("Cache-Control").getValue());
+                wrapper.getFirstHeader("Cache-Control").getValue());
     }
 
     @Test
     public void stripsMaxAgeFromRequestIfNoCachePresent()
         throws Exception {
         req.setHeader("Cache-Control", "no-cache, max-age=10");
-        result = impl.makeRequestCompliant(req);
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
+        impl.makeRequestCompliant(wrapper);
         assertEquals("no-cache",
-                result.getFirstHeader("Cache-Control").getValue());
+                wrapper.getFirstHeader("Cache-Control").getValue());
     }
 
     @Test
     public void doesNotStripMinFreshFromRequestWithoutNoCache()
         throws Exception {
         req.setHeader("Cache-Control", "min-fresh=10");
-        result = impl.makeRequestCompliant(req);
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
+        impl.makeRequestCompliant(wrapper);
         assertEquals("min-fresh=10",
-                result.getFirstHeader("Cache-Control").getValue());
+                wrapper.getFirstHeader("Cache-Control").getValue());
     }
 
     @Test
     public void correctlyStripsMinFreshFromMiddleIfNoCache()
         throws Exception {
         req.setHeader("Cache-Control", "no-cache,min-fresh=10,no-store");
-        result = impl.makeRequestCompliant(req);
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
+        impl.makeRequestCompliant(wrapper);
         assertEquals("no-cache,no-store",
-                result.getFirstHeader("Cache-Control").getValue());
+                wrapper.getFirstHeader("Cache-Control").getValue());
     }
 
 }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestResponseProtocolCompliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestResponseProtocolCompliance.java?rev=1417343&r1=1417342&r2=1417343&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestResponseProtocolCompliance.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestResponseProtocolCompliance.java
Wed Dec  5 10:34:46 2012
@@ -33,13 +33,13 @@ import java.util.Date;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
-import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpHead;
+import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.impl.cookie.DateUtils;
@@ -87,7 +87,7 @@ public class TestResponseProtocolComplia
 
     @Test
     public void consumesBodyIfOriginSendsOneInResponseToHEAD() throws Exception {
-        HttpRequest req = new HttpHead("http://foo.example.com/");
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(new HttpHead("http://foo.example.com/"));
         int nbytes = 128;
         HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
"OK");
         setMinimalResponseHeaders(resp);
@@ -97,24 +97,24 @@ public class TestResponseProtocolComplia
         ByteArrayInputStream bais = makeTrackableBody(nbytes, closed);
         resp.setEntity(new InputStreamEntity(bais, -1));
 
-        impl.ensureProtocolCompliance(req, resp);
+        impl.ensureProtocolCompliance(wrapper, resp);
         assertNull(resp.getEntity());
         assertTrue(closed.set || bais.read() == -1);
     }
 
     @Test(expected=ClientProtocolException.class)
     public void throwsExceptionIfOriginReturnsPartialResponseWhenNotRequested() throws Exception
{
-        HttpRequest req = new HttpGet("http://foo.example.com/");
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         int nbytes = 128;
         HttpResponse resp = makePartialResponse(nbytes);
         resp.setEntity(HttpTestUtils.makeBody(nbytes));
 
-        impl.ensureProtocolCompliance(req, resp);
+        impl.ensureProtocolCompliance(wrapper, resp);
     }
 
     @Test
     public void consumesPartialContentFromOriginEvenIfNotRequested() throws Exception {
-        HttpRequest req = new HttpGet("http://foo.example.com/");
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(new HttpGet("http://foo.example.com/"));
         int nbytes = 128;
         HttpResponse resp = makePartialResponse(nbytes);
 
@@ -123,7 +123,7 @@ public class TestResponseProtocolComplia
         resp.setEntity(new InputStreamEntity(bais, -1));
 
         try {
-            impl.ensureProtocolCompliance(req, resp);
+            impl.ensureProtocolCompliance(wrapper, resp);
         } catch (ClientProtocolException expected) {
         }
         assertTrue(closed.set || bais.read() == -1);
@@ -137,6 +137,7 @@ public class TestResponseProtocolComplia
         req.setHeader("Content-Type", "application/octet-stream");
         HttpEntity postBody = new ByteArrayEntity(HttpTestUtils.getRandomBytes(nbytes));
         req.setEntity(postBody);
+        HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
 
         HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_CONTINUE,
"Continue");
         final Flag closed = new Flag();
@@ -144,7 +145,7 @@ public class TestResponseProtocolComplia
         resp.setEntity(new InputStreamEntity(bais, -1));
 
         try {
-            impl.ensureProtocolCompliance(req, resp);
+            impl.ensureProtocolCompliance(wrapper, resp);
         } catch (ClientProtocolException expected) {
         }
         assertTrue(closed.set || bais.read() == -1);



Mime
View raw message