This is an automated email from the ASF dual-hosted git repository.

iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new 534fd24  [dubbo-1689]: Enhance the test coverage part-10 : 
dubbo-plugin module (#1993)
534fd24 is described below

commit 534fd24def03216919ca5ba8160bf5e2350779d8
Author: Ian Luo <[email protected]>
AuthorDate: Wed Jun 27 10:55:30 2018 +0800

    [dubbo-1689]: Enhance the test coverage part-10 : dubbo-plugin module 
(#1993)
    
    *     #1689: Enhance the test coverage part-10 : dubbo-plugin module
    
    *     #1689: Enhance the test coverage part-10 : dubbo-plugin module
    
    * fix unit test failure
    
    *     #1689: Enhance the test coverage part-10 : dubbo-plugin module
    
    *     #1689: Enhance the test coverage part-10 : dubbo-plugin module
---
 .../qos/server/handler/HttpProcessHandlerTest.java | 70 ++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git 
a/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/HttpProcessHandlerTest.java
 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/HttpProcessHandlerTest.java
new file mode 100644
index 0000000..1e9d6a9
--- /dev/null
+++ 
b/dubbo-plugin/dubbo-qos/src/test/java/org/apache/dubbo/qos/server/handler/HttpProcessHandlerTest.java
@@ -0,0 +1,70 @@
+package org.apache.dubbo.qos.server.handler;
+
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.http.FullHttpResponse;
+import io.netty.handler.codec.http.HttpMethod;
+import io.netty.handler.codec.http.HttpRequest;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class HttpProcessHandlerTest {
+    @Test
+    public void test1() throws Exception {
+        ChannelHandlerContext context = mock(ChannelHandlerContext.class);
+        ChannelFuture future = mock(ChannelFuture.class);
+        
when(context.writeAndFlush(any(FullHttpResponse.class))).thenReturn(future);
+        HttpRequest message = Mockito.mock(HttpRequest.class);
+        when(message.getUri()).thenReturn("test");
+        HttpProcessHandler handler = new HttpProcessHandler();
+        handler.channelRead0(context, message);
+        verify(future).addListener(ChannelFutureListener.CLOSE);
+        ArgumentCaptor<FullHttpResponse> captor = 
ArgumentCaptor.forClass(FullHttpResponse.class);
+        verify(context).writeAndFlush(captor.capture());
+        FullHttpResponse response = captor.getValue();
+        assertThat(response.getStatus().code(), equalTo(404));
+    }
+
+    @Test
+    public void test2() throws Exception {
+        ChannelHandlerContext context = mock(ChannelHandlerContext.class);
+        ChannelFuture future = mock(ChannelFuture.class);
+        
when(context.writeAndFlush(any(FullHttpResponse.class))).thenReturn(future);
+        HttpRequest message = Mockito.mock(HttpRequest.class);
+        when(message.getUri()).thenReturn("localhost:80/greeting");
+        when(message.getMethod()).thenReturn(HttpMethod.GET);
+        HttpProcessHandler handler = new HttpProcessHandler();
+        handler.channelRead0(context, message);
+        verify(future).addListener(ChannelFutureListener.CLOSE);
+        ArgumentCaptor<FullHttpResponse> captor = 
ArgumentCaptor.forClass(FullHttpResponse.class);
+        verify(context).writeAndFlush(captor.capture());
+        FullHttpResponse response = captor.getValue();
+        assertThat(response.getStatus().code(), equalTo(200));
+    }
+
+    @Test
+    public void test3() throws Exception {
+        ChannelHandlerContext context = mock(ChannelHandlerContext.class);
+        ChannelFuture future = mock(ChannelFuture.class);
+        
when(context.writeAndFlush(any(FullHttpResponse.class))).thenReturn(future);
+        HttpRequest message = Mockito.mock(HttpRequest.class);
+        when(message.getUri()).thenReturn("localhost:80/test");
+        when(message.getMethod()).thenReturn(HttpMethod.GET);
+        HttpProcessHandler handler = new HttpProcessHandler();
+        handler.channelRead0(context, message);
+        verify(future).addListener(ChannelFutureListener.CLOSE);
+        ArgumentCaptor<FullHttpResponse> captor = 
ArgumentCaptor.forClass(FullHttpResponse.class);
+        verify(context).writeAndFlush(captor.capture());
+        FullHttpResponse response = captor.getValue();
+        assertThat(response.getStatus().code(), equalTo(404));
+    }
+}

Reply via email to