forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpResponseStreamHandlerTest.java
More file actions
53 lines (43 loc) · 1.61 KB
/
Copy pathHttpResponseStreamHandlerTest.java
File metadata and controls
53 lines (43 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.github.dockerjava.netty.handler;
import static org.testng.Assert.assertTrue;
import java.io.InputStream;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import org.apache.commons.io.IOUtils;
import org.mockito.Mockito;
import org.testng.annotations.Test;
import com.github.dockerjava.core.async.ResultCallbackTemplate;
/**
* @author Alexander Koshevoy
*/
public class HttpResponseStreamHandlerTest {
@Test
public void testNoBytesSkipped() throws Exception {
ResultCallbackTest callback = new ResultCallbackTest();
HttpResponseStreamHandler streamHandler = new HttpResponseStreamHandler(callback);
ChannelHandlerContext ctx = Mockito.mock(ChannelHandlerContext.class);
ByteBuf buffer = generateByteBuf();
streamHandler.channelRead0(ctx, buffer);
streamHandler.channelReadComplete(ctx);
assertTrue(IOUtils.contentEquals(callback.getInputStream(), new ByteBufInputStream(buffer)));
}
private ByteBuf generateByteBuf() {
byte[] array = new byte[256];
for (int i = 0; i < array.length; i++) {
array[i] = (byte) i;
}
return Unpooled.copiedBuffer(array);
}
private static class ResultCallbackTest extends ResultCallbackTemplate<ResultCallbackTest, InputStream> {
private InputStream stream;
@Override
public void onNext(InputStream stream) {
this.stream = stream;
}
public InputStream getInputStream() {
return stream;
}
}
}