-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #230 (FlatResponseOperator does not emit any item if there is n…
…o content.) Also, fixed the test failure for previous PR
- Loading branch information
Nitesh Kant
committed
Sep 7, 2014
1 parent
447f3f3
commit 24be8a7
Showing
4 changed files
with
133 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
rx-netty/src/test/java/io/reactivex/netty/protocol/http/client/FlatResponseOperatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2014 Netflix, Inc. | ||
* | ||
* Licensed 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. | ||
*/ | ||
package io.reactivex.netty.protocol.http.client; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
import io.netty.handler.codec.http.DefaultHttpResponse; | ||
import io.netty.handler.codec.http.HttpResponseStatus; | ||
import io.netty.handler.codec.http.HttpVersion; | ||
import io.reactivex.netty.protocol.http.UnicastContentSubject; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import rx.Observable; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author Nitesh Kant | ||
*/ | ||
public class FlatResponseOperatorTest { | ||
|
||
@Test | ||
public void testContent() throws Exception { | ||
DefaultHttpResponse nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, | ||
HttpResponseStatus.NO_CONTENT); | ||
UnicastContentSubject<ByteBuf> contentSubject = UnicastContentSubject.createWithoutNoSubscriptionTimeout(); | ||
contentSubject.onNext(Unpooled.buffer()); | ||
contentSubject.onCompleted(); | ||
|
||
ResponseHolder<ByteBuf> holder = Observable.just(new HttpClientResponse<ByteBuf>(nettyResponse, contentSubject)) | ||
.lift(FlatResponseOperator.<ByteBuf>flatResponse()) | ||
.toBlocking().toFuture().get(1, TimeUnit.MINUTES); | ||
|
||
Assert.assertEquals("Unexpected http response status", HttpResponseStatus.NO_CONTENT, | ||
holder.getResponse().getStatus()); | ||
Assert.assertTrue("Response holder does not have content.", holder.hasContent()); | ||
|
||
} | ||
|
||
@Test | ||
public void testNoContent() throws Exception { | ||
DefaultHttpResponse nettyResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, | ||
HttpResponseStatus.NO_CONTENT); | ||
UnicastContentSubject<ByteBuf> contentSubject = UnicastContentSubject.createWithoutNoSubscriptionTimeout(); | ||
contentSubject.onCompleted(); | ||
|
||
ResponseHolder<ByteBuf> holder = Observable.just(new HttpClientResponse<ByteBuf>(nettyResponse, contentSubject)) | ||
.lift(FlatResponseOperator.<ByteBuf>flatResponse()) | ||
.toBlocking().toFuture().get(1, TimeUnit.MINUTES); | ||
Assert.assertEquals("Unexpected http response status", HttpResponseStatus.NO_CONTENT, | ||
holder.getResponse().getStatus()); | ||
Assert.assertFalse("Response holder has content.", holder.hasContent()); | ||
|
||
} | ||
} |