hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1397679 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/client/entity/ main/java/org/apache/http/client/methods/ test/java/org/apache/http/client/entity/ test/java/org/apache/http/client/methods/
Date Fri, 12 Oct 2012 18:44:13 GMT
Author: olegk
Date: Fri Oct 12 18:44:13 2012
New Revision: 1397679

URL: http://svn.apache.org/viewvc?rev=1397679&view=rev
Log:
Added constructors to RequestBuilder; added to EntityBuilder

Added:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/EntityBuilder.java
  (with props)
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java
  (with props)
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestEntityBuilder.java
  (with props)
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/EntityBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/EntityBuilder.java?rev=1397679&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/EntityBuilder.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/EntityBuilder.java
Fri Oct 12 18:44:13 2012
@@ -0,0 +1,218 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.entity;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.util.List;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.NameValuePair;
+import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.entity.AbstractHttpEntity;
+import org.apache.http.entity.BasicHttpEntity;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.FileEntity;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.entity.SerializableEntity;
+import org.apache.http.entity.StringEntity;
+
+/**
+ * @since 4.3
+ */
+@NotThreadSafe
+public class EntityBuilder {
+
+    private String text;
+    private byte[] binary;
+    private InputStream stream;
+    private List<NameValuePair> parameters;
+    private Serializable serializable;
+    private File file;
+    private ContentType contentType;
+    private String contentEncoding;
+    private boolean chunked;
+    private boolean gzipCompress;
+
+    EntityBuilder() {
+        super();
+    }
+
+    public static EntityBuilder create() {
+        return new EntityBuilder();
+    }
+
+    public String getText() {
+        return text;
+    }
+
+    private void clearContent() {
+        this.text = null;
+        this.binary = null;
+        this.stream = null;
+        this.parameters = null;
+        this.serializable = null;
+        this.file = null;
+    }
+
+    public EntityBuilder setText(final String text) {
+        clearContent();
+        this.text = text;
+        return this;
+    }
+
+    public byte[] getBinary() {
+        return binary;
+    }
+
+    public EntityBuilder setBinary(final byte[] binary) {
+        clearContent();
+        this.binary = binary;
+        return this;
+    }
+
+    public InputStream getStream() {
+        return stream;
+    }
+
+    public EntityBuilder setStream(final InputStream stream) {
+        clearContent();
+        this.stream = stream;
+        return this;
+    }
+
+    public List<NameValuePair> getParameters() {
+        return parameters;
+    }
+
+    public EntityBuilder setParameters(final List<NameValuePair> parameters) {
+        clearContent();
+        this.parameters = parameters;
+        return this;
+    }
+
+    public Serializable getSerializable() {
+        return serializable;
+    }
+
+    public EntityBuilder setSerializable(final Serializable serializable) {
+        clearContent();
+        this.serializable = serializable;
+        return this;
+    }
+
+    public File getFile() {
+        return file;
+    }
+
+    public EntityBuilder setFile(final File file) {
+        clearContent();
+        this.file = file;
+        return this;
+    }
+
+    public ContentType getContentType() {
+        return contentType;
+    }
+
+    public EntityBuilder setContentType(final ContentType contentType) {
+        this.contentType = contentType;
+        return this;
+    }
+
+    public String getContentEncoding() {
+        return contentEncoding;
+    }
+
+    public EntityBuilder setContentEncoding(final String contentEncoding) {
+        this.contentEncoding = contentEncoding;
+        return this;
+    }
+
+    public boolean isChunked() {
+        return chunked;
+    }
+
+    public EntityBuilder chunked() {
+        this.chunked = true;
+        return this;
+    }
+
+    public boolean isGzipCompress() {
+        return gzipCompress;
+    }
+
+    public EntityBuilder gzipCompress() {
+        this.gzipCompress = true;
+        return this;
+    }
+
+    private ContentType getContentOrDefault(final ContentType def) {
+        return this.contentType != null ? this.contentType : def;
+    }
+
+    public HttpEntity build() {
+        AbstractHttpEntity e;
+        if (this.text != null) {
+            e = new StringEntity(this.text, getContentOrDefault(ContentType.DEFAULT_TEXT));
+        } else if (this.binary != null) {
+            e = new ByteArrayEntity(this.binary, getContentOrDefault(ContentType.DEFAULT_BINARY));
+        } else if (this.stream != null) {
+            e = new InputStreamEntity(this.stream, 1, getContentOrDefault(ContentType.DEFAULT_BINARY));
+        } else if (this.parameters != null) {
+            e = new UrlEncodedFormEntity(this.parameters,
+                    this.contentType != null ? this.contentType.getCharset() : null);
+        } else if (this.serializable != null) {
+            // TODO: replace with constructor from 4.3
+            try {
+                e = new SerializableEntity(this.serializable, false);
+            } catch (IOException never) {
+                throw new IllegalStateException(
+                        "I/O error creating SerializableEntity without buffering");
+            }
+            e.setContentType(ContentType.DEFAULT_BINARY.toString());
+        } else if (this.file != null) {
+            e = new FileEntity(this.file, getContentOrDefault(ContentType.DEFAULT_BINARY));
+        } else {
+            e = new BasicHttpEntity();
+        }
+        if (e.getContentType() != null && this.contentType != null) {
+            e.setContentType(this.contentType.toString());
+        }
+        e.setContentEncoding(this.contentEncoding);
+        e.setChunked(this.chunked);
+        if (this.gzipCompress) {
+            return new GzipCompressingEntity(e);
+        }
+        return e;
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/EntityBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/EntityBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/EntityBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java?rev=1397679&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java
Fri Oct 12 18:44:13 2012
@@ -0,0 +1,89 @@
+package org.apache.http.client.entity;
+
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.zip.GZIPOutputStream;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.HttpEntityWrapper;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.protocol.HTTP;
+
+/**
+ * Wrapping entity that compresses content when {@link #writeTo writing}.
+ *
+ *
+ * @since 4.0
+ */
+public class GzipCompressingEntity extends HttpEntityWrapper {
+
+    private static final String GZIP_CODEC = "gzip";
+
+    public GzipCompressingEntity(final HttpEntity entity) {
+        super(entity);
+    }
+
+    @Override
+    public Header getContentEncoding() {
+        return new BasicHeader(HTTP.CONTENT_ENCODING, GZIP_CODEC);
+    }
+
+    @Override
+    public long getContentLength() {
+        return -1;
+    }
+
+    @Override
+    public boolean isChunked() {
+        // force content chunking
+        return true;
+    }
+
+    @Override
+    public InputStream getContent() throws IOException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void writeTo(final OutputStream outstream) throws IOException {
+        if (outstream == null) {
+            throw new IllegalArgumentException("Output stream may not be null");
+        }
+        GZIPOutputStream gzip = new GZIPOutputStream(outstream);
+        try {
+            wrappedEntity.writeTo(gzip);
+        } finally {
+            gzip.close();
+        }
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/entity/GzipCompressingEntity.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java?rev=1397679&r1=1397678&r2=1397679&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java
Fri Oct 12 18:44:13 2012
@@ -28,7 +28,6 @@
 package org.apache.http.client.methods;
 
 import java.net.URI;
-import java.util.Locale;
 
 import org.apache.http.Header;
 import org.apache.http.HeaderIterator;
@@ -55,12 +54,45 @@ public class RequestBuilder {
     private HttpEntity entity;
     private HttpParams params;
 
-    RequestBuilder() {
+    RequestBuilder(final String method) {
         super();
+        this.method = method;
+    }
+
+    RequestBuilder() {
+        this(null);
+    }
+
+    public static RequestBuilder create(final String method) {
+        return new RequestBuilder(method);
+    }
+
+    public static RequestBuilder createGet() {
+        return new RequestBuilder(HttpGet.METHOD_NAME);
+    }
+
+    public static RequestBuilder createHead() {
+        return new RequestBuilder(HttpHead.METHOD_NAME);
+    }
+
+    public static RequestBuilder createPost() {
+        return new RequestBuilder(HttpPost.METHOD_NAME);
+    }
+
+    public static RequestBuilder createPut() {
+        return new RequestBuilder(HttpPut.METHOD_NAME);
+    }
+
+    public static RequestBuilder createDelete() {
+        return new RequestBuilder(HttpDelete.METHOD_NAME);
+    }
+
+    public static RequestBuilder createTrace() {
+        return new RequestBuilder(HttpTrace.METHOD_NAME);
     }
 
-    public static RequestBuilder create() {
-        return new RequestBuilder();
+    public static RequestBuilder createOptions() {
+        return new RequestBuilder(HttpOptions.METHOD_NAME);
     }
 
     public static RequestBuilder copy(final HttpRequest request) {
@@ -212,8 +244,8 @@ public class RequestBuilder {
     }
 
     private String getMethodName() {
-        return this.method != null ? this.method.toUpperCase(Locale.US) :
-            (this.entity != null ? "POST" : "GET");
+        return this.method != null ? this.method : 
+            (this.entity != null ? HttpPost.METHOD_NAME : HttpGet.METHOD_NAME);
     }
 
     public HttpUriRequest build() {

Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestEntityBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestEntityBuilder.java?rev=1397679&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestEntityBuilder.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestEntityBuilder.java
Fri Oct 12 18:44:13 2012
@@ -0,0 +1,127 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.entity;
+
+import java.io.File;
+import java.io.InputStream;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.ContentType;
+import org.apache.http.util.EntityUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+public class TestEntityBuilder {
+
+    @Test(expected=IllegalStateException.class)
+    public void testBuildEmptyEntity() throws Exception {
+        HttpEntity entity = EntityBuilder.create().build();
+        Assert.assertNotNull(entity);
+        entity.getContent();
+    }
+
+    @Test
+    public void testBuildTextEntity() throws Exception {
+        HttpEntity entity = EntityBuilder.create().setText("stuff").build();
+        Assert.assertNotNull(entity);
+        Assert.assertNotNull(entity.getContent());
+        Assert.assertNotNull(entity.getContentType());
+        Assert.assertEquals("text/plain; charset=ISO-8859-1", entity.getContentType().getValue());
+    }
+
+    @Test
+    public void testBuildBinaryEntity() throws Exception {
+        HttpEntity entity = EntityBuilder.create().setBinary(new byte[] {0, 1, 2}).build();
+        Assert.assertNotNull(entity);
+        Assert.assertNotNull(entity.getContent());
+        Assert.assertNotNull(entity.getContentType());
+        Assert.assertEquals("application/octet-stream", entity.getContentType().getValue());
+    }
+
+    @Test
+    public void testBuildStreamEntity() throws Exception {
+        InputStream in = Mockito.mock(InputStream.class);
+        HttpEntity entity = EntityBuilder.create().setStream(in).build();
+        Assert.assertNotNull(entity);
+        Assert.assertNotNull(entity.getContent());
+        Assert.assertNotNull(entity.getContentType());
+        Assert.assertEquals("application/octet-stream", entity.getContentType().getValue());
+    }
+
+    @Test
+    public void testBuildSerializableEntity() throws Exception {
+        HttpEntity entity = EntityBuilder.create().setSerializable(Boolean.TRUE).build();
+        Assert.assertNotNull(entity);
+        Assert.assertNotNull(entity.getContent());
+        Assert.assertNotNull(entity.getContentType());
+        Assert.assertEquals("application/octet-stream", entity.getContentType().getValue());
+    }
+
+    @Test
+    public void testBuildFileEntity() throws Exception {
+        File file = new File("stuff");
+        HttpEntity entity = EntityBuilder.create().setFile(file).build();
+        Assert.assertNotNull(entity);
+        Assert.assertNotNull(entity.getContentType());
+        Assert.assertEquals("application/octet-stream", entity.getContentType().getValue());
+    }
+
+    @Test
+    public void testExplicitContentProperties() throws Exception {
+        HttpEntity entity = EntityBuilder.create()
+            .setContentType(ContentType.APPLICATION_JSON)
+            .setContentEncoding("identity")
+            .setBinary(new byte[] {0, 1, 2})
+            .setText("{\"stuff\"}").build();
+        Assert.assertNotNull(entity);
+        Assert.assertNotNull(entity.getContentType());
+        Assert.assertEquals("application/json; charset=UTF-8", entity.getContentType().getValue());
+        Assert.assertNotNull(entity.getContentEncoding());
+        Assert.assertEquals("identity", entity.getContentEncoding().getValue());
+        Assert.assertEquals("{\"stuff\"}", EntityUtils.toString(entity));
+    }
+
+    @Test
+    public void testBuildChunked() throws Exception {
+        HttpEntity entity = EntityBuilder.create().setText("stuff").chunked().build();
+        Assert.assertNotNull(entity);
+        Assert.assertTrue(entity.isChunked());
+    }
+
+    @Test
+    public void testBuildGZipped() throws Exception {
+        HttpEntity entity = EntityBuilder.create().setText("stuff").gzipCompress().build();
+        Assert.assertNotNull(entity);
+        Assert.assertNotNull(entity.getContentType());
+        Assert.assertEquals("text/plain; charset=ISO-8859-1", entity.getContentType().getValue());
+        Assert.assertNotNull(entity.getContentEncoding());
+        Assert.assertEquals("gzip", entity.getContentEncoding().getValue());
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestEntityBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestEntityBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestEntityBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java?rev=1397679&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
Fri Oct 12 18:44:13 2012
@@ -0,0 +1,66 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.client.entity;
+
+import java.io.ByteArrayOutputStream;
+
+import junit.framework.Assert;
+
+import org.apache.http.Consts;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.util.EntityUtils;
+import org.junit.Test;
+
+public class TestGZip {
+
+    @Test
+    public void testBasic() throws Exception {
+        String s = "some kind of text";
+        StringEntity e = new StringEntity(s, ContentType.TEXT_PLAIN);
+        e.setChunked(false);
+        GzipCompressingEntity gzipe = new GzipCompressingEntity(e);
+        Assert.assertTrue(gzipe.isChunked());
+        Assert.assertEquals(-1, gzipe.getContentLength());
+        Assert.assertNotNull(gzipe.getContentEncoding());
+        Assert.assertEquals("gzip", gzipe.getContentEncoding().getValue());
+    }
+
+    @Test
+    public void testCompressionDecompression() throws Exception {
+        StringEntity in = new StringEntity("some kind of text", ContentType.TEXT_PLAIN);
+        GzipCompressingEntity gzipe = new GzipCompressingEntity(in);
+        ByteArrayOutputStream buf = new ByteArrayOutputStream();
+        gzipe.writeTo(buf);
+        ByteArrayEntity out = new ByteArrayEntity(buf.toByteArray());
+        GzipDecompressingEntity gunzipe = new GzipDecompressingEntity(out);
+        Assert.assertEquals("some kind of text", EntityUtils.toString(gunzipe, Consts.ASCII));
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestGZip.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java?rev=1397679&r1=1397678&r2=1397679&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java
Fri Oct 12 18:44:13 2012
@@ -45,7 +45,7 @@ public class TestRequestBuilder {
 
     @Test
     public void testBasicGet() throws Exception {
-        HttpUriRequest request = RequestBuilder.create().build();
+        HttpUriRequest request = RequestBuilder.createGet().build();
         Assert.assertNotNull(request);
         Assert.assertEquals("GET", request.getMethod());
         Assert.assertEquals(URI.create("/"), request.getURI());
@@ -54,9 +54,18 @@ public class TestRequestBuilder {
     }
 
     @Test
+    public void testArbitraryMethod() throws Exception {
+        HttpUriRequest request = RequestBuilder.create("Whatever").build();
+        Assert.assertNotNull(request);
+        Assert.assertEquals("Whatever", request.getMethod());
+        Assert.assertEquals(URI.create("/"), request.getURI());
+        Assert.assertEquals(HttpVersion.HTTP_1_1, request.getProtocolVersion());
+    }
+
+    @Test
     public void testBasicWithEntity() throws Exception {
         HttpEntity entity = new BasicHttpEntity();
-        HttpUriRequest request = RequestBuilder.create().setEntity(entity).build();
+        HttpUriRequest request = RequestBuilder.createPost().setEntity(entity).build();
         Assert.assertNotNull(request);
         Assert.assertEquals("POST", request.getMethod());
         Assert.assertEquals(URI.create("/"), request.getURI());
@@ -68,7 +77,7 @@ public class TestRequestBuilder {
     @Test
     public void testGetWithEntity() throws Exception {
         HttpEntity entity = new BasicHttpEntity();
-        HttpUriRequest request = RequestBuilder.create().setMethod("get").setEntity(entity).build();
+        HttpUriRequest request = RequestBuilder.createGet().setEntity(entity).build();
         Assert.assertNotNull(request);
         Assert.assertEquals("GET", request.getMethod());
         Assert.assertEquals(URI.create("/"), request.getURI());
@@ -81,8 +90,7 @@ public class TestRequestBuilder {
     public void testCopy() throws Exception {
         HttpEntity entity = new StringEntity("stuff");
         HttpParams params = new BasicHttpParams();
-        HttpUriRequest request = RequestBuilder.create()
-            .setMethod("put")
+        HttpUriRequest request = RequestBuilder.createPut()
             .setUri(URI.create("/stuff"))
             .setVersion(HttpVersion.HTTP_1_0)
             .addHeader("header1", "stuff")
@@ -108,8 +116,7 @@ public class TestRequestBuilder {
     public void testClone() throws Exception {
         HttpEntity entity = new StringEntity("stuff");
         HttpParams params = new BasicHttpParams();
-        HttpUriRequest request = RequestBuilder.create()
-            .setMethod("put")
+        HttpUriRequest request = RequestBuilder.createPut()
             .setUri(URI.create("/stuff"))
             .setVersion(HttpVersion.HTTP_1_0)
             .addHeader("header1", "stuff")
@@ -147,15 +154,14 @@ public class TestRequestBuilder {
         HttpParams params = new BasicHttpParams();
         Header h1 = new BasicHeader("header1", "stuff");
         Header h2 = new BasicHeader("header1", "more-stuff");
-        RequestBuilder builder = RequestBuilder.create()
-            .setMethod("put")
+        RequestBuilder builder = RequestBuilder.createPut()
             .setUri("/stuff")
             .setVersion(HttpVersion.HTTP_1_0)
             .addHeader(h1)
             .addHeader(h2)
             .setEntity(entity)
             .setParams(params);
-        Assert.assertEquals("put", builder.getMethod());
+        Assert.assertEquals("PUT", builder.getMethod());
         Assert.assertEquals(URI.create("/stuff"), builder.getUri());
         Assert.assertEquals(HttpVersion.HTTP_1_0, builder.getVersion());
         Assert.assertSame(h1, builder.getFirstHeader("header1"));



Mime
View raw message