hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1165855 - in /httpcomponents/httpcore/trunk/httpcore-nio/src: main/java/org/apache/http/nio/protocol/BasicAsyncRequestProducer.java test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java
Date Tue, 06 Sep 2011 21:20:59 GMT
Author: olegk
Date: Tue Sep  6 21:20:58 2011
New Revision: 1165855

URL: http://svn.apache.org/viewvc?rev=1165855&view=rev
Log:
HTTPCORE-275: No Null Check for Target in BasicAsyncRequestProducer Constructor
Contributed by William R. Speirs <bill.speirs at gmail.com>

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java
  (with props)
Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestProducer.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestProducer.java?rev=1165855&r1=1165854&r2=1165855&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestProducer.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestProducer.java
Tue Sep  6 21:20:58 2011
@@ -65,6 +65,9 @@ public class BasicAsyncRequestProducer i
     }
 
     public BasicAsyncRequestProducer(final HttpHost target, final HttpRequest request) {
+        if (target == null) {
+            throw new IllegalArgumentException("HTTP host may not be null");
+        }
         if (request == null) {
             throw new IllegalArgumentException("HTTP request may not be null");
         }

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java?rev=1165855&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java
(added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java
Tue Sep  6 21:20:58 2011
@@ -0,0 +1,106 @@
+package org.apache.http.nio.protocol;
+
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import junit.framework.Assert;
+
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.nio.ContentEncoder;
+import org.apache.http.nio.entity.ProducingNHttpEntity;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class TestBasicAsyncRequestProducer {
+
+    private BasicAsyncRequestProducer producer;
+    private HttpHost target;
+    @Mock private ProducingNHttpEntity entity;
+    @Mock private HttpEntityEnclosingRequest request;
+    @Mock private ContentEncoder encoder;
+
+    @Before
+    public void setUp() throws Exception {
+        MockitoAnnotations.initMocks(this);
+
+        when(request.getEntity()).thenReturn(entity);
+
+        target = new HttpHost("localhost");
+
+        producer = new BasicAsyncRequestProducer(target, request, entity);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testNullTarget3ArgConstructor() throws Exception {
+        producer = new BasicAsyncRequestProducer(null, request, entity);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testNullRequest3ArgConstructor() throws Exception {
+        producer = new BasicAsyncRequestProducer(target, null, entity);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testNullTarget2ArgConstructor() throws Exception {
+        producer = new BasicAsyncRequestProducer(null, request);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void testNullRequest2ArgConstructor() throws Exception {
+        producer = new BasicAsyncRequestProducer(target, null);
+    }
+
+    @Test
+    public void testGenerateRequest() {
+        HttpRequest res = producer.generateRequest();
+
+        Assert.assertEquals(request, res);
+    }
+
+    @Test
+    public void testGetTarget() {
+        HttpHost res = producer.getTarget();
+
+        Assert.assertEquals(target, res);
+    }
+
+    @Test
+    public void testProduceContentEncoderCompleted() throws Exception {
+        when(encoder.isCompleted()).thenReturn(true);
+
+        producer.produceContent(encoder,  null);
+
+        verify(entity, times(1)).finish();
+    }
+
+    @Test
+    public void testProduceContentEncoderNotCompleted() throws Exception {
+        when(encoder.isCompleted()).thenReturn(false);
+
+        producer.produceContent(encoder,  null);
+
+        verify(entity, times(0)).finish();
+    }
+
+    @Test
+    public void testResetRequest() throws Exception {
+        producer.resetRequest();
+        verify(entity, times(1)).finish();
+    }
+
+    @Test
+    public void testClose() throws Exception {
+        producer.close();
+        verify(entity, times(1)).finish();
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncRequestProducer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message